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 | 6926afd1 | 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: |
| 155 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 156 | case -NFS4ERR_BADOWNER: |
| 157 | case -NFS4ERR_BADNAME: |
| 158 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 159 | case -NFS4ERR_SHARE_DENIED: |
| 160 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 161 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 162 | return -EPROTONOSUPPORT; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 163 | case -NFS4ERR_ACCESS: |
| 164 | return -EACCES; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 165 | case -NFS4ERR_FILE_OPEN: |
| 166 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 167 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 169 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 170 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 172 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | /* |
| 176 | * This is our standard bitmap for GETATTR requests. |
| 177 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 178 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | FATTR4_WORD0_TYPE |
| 180 | | FATTR4_WORD0_CHANGE |
| 181 | | FATTR4_WORD0_SIZE |
| 182 | | FATTR4_WORD0_FSID |
| 183 | | FATTR4_WORD0_FILEID, |
| 184 | FATTR4_WORD1_MODE |
| 185 | | FATTR4_WORD1_NUMLINKS |
| 186 | | FATTR4_WORD1_OWNER |
| 187 | | FATTR4_WORD1_OWNER_GROUP |
| 188 | | FATTR4_WORD1_RAWDEV |
| 189 | | FATTR4_WORD1_SPACE_USED |
| 190 | | FATTR4_WORD1_TIME_ACCESS |
| 191 | | FATTR4_WORD1_TIME_METADATA |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 192 | | FATTR4_WORD1_TIME_MODIFY, |
| 193 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 194 | FATTR4_WORD2_SECURITY_LABEL |
| 195 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | }; |
| 197 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 198 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 199 | FATTR4_WORD0_TYPE |
| 200 | | FATTR4_WORD0_CHANGE |
| 201 | | FATTR4_WORD0_SIZE |
| 202 | | FATTR4_WORD0_FSID |
| 203 | | FATTR4_WORD0_FILEID, |
| 204 | FATTR4_WORD1_MODE |
| 205 | | FATTR4_WORD1_NUMLINKS |
| 206 | | FATTR4_WORD1_OWNER |
| 207 | | FATTR4_WORD1_OWNER_GROUP |
| 208 | | FATTR4_WORD1_RAWDEV |
| 209 | | FATTR4_WORD1_SPACE_USED |
| 210 | | FATTR4_WORD1_TIME_ACCESS |
| 211 | | FATTR4_WORD1_TIME_METADATA |
| 212 | | FATTR4_WORD1_TIME_MODIFY, |
| 213 | FATTR4_WORD2_MDSTHRESHOLD |
| 214 | }; |
| 215 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 216 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 217 | FATTR4_WORD0_TYPE |
| 218 | | FATTR4_WORD0_CHANGE |
| 219 | | FATTR4_WORD0_FILEID, |
| 220 | }; |
| 221 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 222 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | FATTR4_WORD0_FILES_AVAIL |
| 224 | | FATTR4_WORD0_FILES_FREE |
| 225 | | FATTR4_WORD0_FILES_TOTAL, |
| 226 | FATTR4_WORD1_SPACE_AVAIL |
| 227 | | FATTR4_WORD1_SPACE_FREE |
| 228 | | FATTR4_WORD1_SPACE_TOTAL |
| 229 | }; |
| 230 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 231 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | FATTR4_WORD0_MAXLINK |
| 233 | | FATTR4_WORD0_MAXNAME, |
| 234 | 0 |
| 235 | }; |
| 236 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 237 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | | FATTR4_WORD0_MAXREAD |
| 239 | | FATTR4_WORD0_MAXWRITE |
| 240 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 241 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 242 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 243 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | }; |
| 245 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 246 | const u32 nfs4_fs_locations_bitmap[3] = { |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 247 | FATTR4_WORD0_TYPE |
| 248 | | FATTR4_WORD0_CHANGE |
| 249 | | FATTR4_WORD0_SIZE |
| 250 | | FATTR4_WORD0_FSID |
| 251 | | FATTR4_WORD0_FILEID |
| 252 | | FATTR4_WORD0_FS_LOCATIONS, |
| 253 | FATTR4_WORD1_MODE |
| 254 | | FATTR4_WORD1_NUMLINKS |
| 255 | | FATTR4_WORD1_OWNER |
| 256 | | FATTR4_WORD1_OWNER_GROUP |
| 257 | | FATTR4_WORD1_RAWDEV |
| 258 | | FATTR4_WORD1_SPACE_USED |
| 259 | | FATTR4_WORD1_TIME_ACCESS |
| 260 | | FATTR4_WORD1_TIME_METADATA |
| 261 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 262 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 263 | }; |
| 264 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 265 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | struct nfs4_readdir_arg *readdir) |
| 267 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 268 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 271 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | readdir->cookie = 0; |
| 277 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 278 | if (cookie == 2) |
| 279 | return; |
| 280 | |
| 281 | /* |
| 282 | * NFSv4 servers do not return entries for '.' and '..' |
| 283 | * Therefore, we fake these entries here. We let '.' |
| 284 | * have cookie 0 and '..' have cookie 1. Note that |
| 285 | * when talking to the server, we always send cookie 0 |
| 286 | * instead of 1 or 2. |
| 287 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 288 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | |
| 290 | if (cookie == 0) { |
| 291 | *p++ = xdr_one; /* next */ |
| 292 | *p++ = xdr_zero; /* cookie, first word */ |
| 293 | *p++ = xdr_one; /* cookie, second word */ |
| 294 | *p++ = xdr_one; /* entry len */ |
| 295 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 296 | p++; |
| 297 | *p++ = xdr_one; /* bitmap length */ |
| 298 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 299 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 300 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | *p++ = xdr_one; /* next */ |
| 304 | *p++ = xdr_zero; /* cookie, first word */ |
| 305 | *p++ = xdr_two; /* cookie, second word */ |
| 306 | *p++ = xdr_two; /* entry len */ |
| 307 | memcpy(p, "..\0\0", 4); /* entry */ |
| 308 | p++; |
| 309 | *p++ = xdr_one; /* bitmap length */ |
| 310 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 311 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 312 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
| 314 | readdir->pgbase = (char *)p - (char *)start; |
| 315 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 316 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 319 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 320 | { |
| 321 | int res = 0; |
| 322 | |
| 323 | might_sleep(); |
| 324 | |
| 325 | if (*timeout <= 0) |
| 326 | *timeout = NFS4_POLL_RETRY_MIN; |
| 327 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 328 | *timeout = NFS4_POLL_RETRY_MAX; |
Colin Cross | 416ad3c | 2013-05-06 23:50:06 +0000 | [diff] [blame] | 329 | freezable_schedule_timeout_killable_unsafe(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 330 | if (fatal_signal_pending(current)) |
| 331 | res = -ERESTARTSYS; |
| 332 | *timeout <<= 1; |
| 333 | return res; |
| 334 | } |
| 335 | |
| 336 | /* This is the error handling routine for processes that are allowed |
| 337 | * to sleep. |
| 338 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 339 | 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] | 340 | { |
| 341 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 342 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 343 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 344 | int ret = errorcode; |
| 345 | |
| 346 | exception->retry = 0; |
| 347 | switch(errorcode) { |
| 348 | case 0: |
| 349 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 350 | case -NFS4ERR_OPENMODE: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 351 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 352 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 353 | exception->retry = 1; |
| 354 | return 0; |
| 355 | } |
| 356 | if (state == NULL) |
| 357 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 358 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 359 | if (ret < 0) |
| 360 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 361 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 362 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 363 | case -NFS4ERR_ADMIN_REVOKED: |
| 364 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | b570a97 | 2013-04-12 15:04:51 -0400 | [diff] [blame] | 365 | if (inode != NULL && nfs4_have_delegation(inode, FMODE_READ)) { |
| 366 | nfs_remove_bad_delegation(inode); |
| 367 | exception->retry = 1; |
| 368 | break; |
| 369 | } |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 370 | if (state == NULL) |
| 371 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 372 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 373 | if (ret < 0) |
| 374 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 375 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 376 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 377 | if (state != NULL) { |
| 378 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 379 | if (ret < 0) |
| 380 | break; |
| 381 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 382 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 383 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 384 | nfs4_schedule_lease_recovery(clp); |
| 385 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 386 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 387 | case -NFS4ERR_BADSESSION: |
| 388 | case -NFS4ERR_BADSLOT: |
| 389 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 390 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 391 | case -NFS4ERR_DEADSESSION: |
| 392 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 393 | case -NFS4ERR_SEQ_MISORDERED: |
| 394 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 395 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 396 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 397 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 398 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 399 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 400 | if (exception->timeout > HZ) { |
| 401 | /* We have retried a decent amount, time to |
| 402 | * fail |
| 403 | */ |
| 404 | ret = -EBUSY; |
| 405 | break; |
| 406 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 407 | case -NFS4ERR_GRACE: |
| 408 | case -NFS4ERR_DELAY: |
| 409 | ret = nfs4_delay(server->client, &exception->timeout); |
| 410 | if (ret != 0) |
| 411 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 412 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 413 | case -NFS4ERR_OLD_STATEID: |
| 414 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 415 | break; |
| 416 | case -NFS4ERR_BADOWNER: |
| 417 | /* The following works around a Linux server bug! */ |
| 418 | case -NFS4ERR_BADNAME: |
| 419 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 420 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 421 | exception->retry = 1; |
| 422 | printk(KERN_WARNING "NFS: v4 server %s " |
| 423 | "does not accept raw " |
| 424 | "uid/gids. " |
| 425 | "Reenabling the idmapper.\n", |
| 426 | server->nfs_client->cl_hostname); |
| 427 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 428 | } |
| 429 | /* We failed to handle the error */ |
| 430 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 431 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 432 | ret = nfs4_wait_clnt_recover(clp); |
| 433 | if (ret == 0) |
| 434 | exception->retry = 1; |
| 435 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 439 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | spin_lock(&clp->cl_lock); |
| 442 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 443 | clp->cl_last_renewal = timestamp; |
| 444 | spin_unlock(&clp->cl_lock); |
| 445 | } |
| 446 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 447 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 448 | { |
| 449 | do_renew_lease(server->nfs_client, timestamp); |
| 450 | } |
| 451 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 452 | #if defined(CONFIG_NFS_V4_1) |
| 453 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 454 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 455 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 456 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 457 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 458 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 459 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 460 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 461 | /* just wake up the next guy waiting since |
| 462 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 463 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 464 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 465 | } |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 466 | tbl = res->sr_slot->table; |
| 467 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 468 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 469 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 470 | /* Be nice to the server: try to ensure that the last transmitted |
| 471 | * value for highest_user_slotid <= target_highest_slotid |
| 472 | */ |
| 473 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 474 | send_new_highest_used_slotid = true; |
| 475 | |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 476 | if (nfs41_wake_and_assign_slot(tbl, res->sr_slot)) { |
| 477 | send_new_highest_used_slotid = false; |
| 478 | goto out_unlock; |
| 479 | } |
Trond Myklebust | f4af6e2a | 2012-11-20 14:17:32 -0500 | [diff] [blame] | 480 | nfs4_free_slot(tbl, res->sr_slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 481 | |
| 482 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 483 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 484 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 485 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 486 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 487 | if (send_new_highest_used_slotid) |
| 488 | nfs41_server_notify_highest_slotid_update(session->clp); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 489 | } |
| 490 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 491 | 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] | 492 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 493 | struct nfs4_session *session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 494 | struct nfs4_slot *slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 495 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 496 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 497 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 498 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 499 | /* don't increment the sequence number if the task wasn't sent */ |
| 500 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 501 | goto out; |
| 502 | |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 503 | slot = res->sr_slot; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 504 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 505 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 506 | if (slot->interrupted) { |
| 507 | slot->interrupted = 0; |
| 508 | interrupted = true; |
| 509 | } |
| 510 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 511 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 512 | switch (res->sr_status) { |
| 513 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 514 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 515 | ++slot->seq_nr; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 516 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 517 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 518 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 519 | if (res->sr_status_flags != 0) |
| 520 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 521 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 522 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 523 | case 1: |
| 524 | /* |
| 525 | * sr_status remains 1 if an RPC level error occurred. |
| 526 | * The server may or may not have processed the sequence |
| 527 | * operation.. |
| 528 | * Mark the slot as having hosted an interrupted RPC call. |
| 529 | */ |
| 530 | slot->interrupted = 1; |
| 531 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 532 | case -NFS4ERR_DELAY: |
| 533 | /* The server detected a resend of the RPC call and |
| 534 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 535 | * of RFC5661. |
| 536 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 537 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 538 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 539 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 540 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 541 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 542 | case -NFS4ERR_BADSLOT: |
| 543 | /* |
| 544 | * The slot id we used was probably retired. Try again |
| 545 | * using a different slot id. |
| 546 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 547 | goto retry_nowait; |
| 548 | case -NFS4ERR_SEQ_MISORDERED: |
| 549 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 550 | * Was the last operation on this sequence interrupted? |
| 551 | * If so, retry after bumping the sequence number. |
| 552 | */ |
| 553 | if (interrupted) { |
| 554 | ++slot->seq_nr; |
| 555 | goto retry_nowait; |
| 556 | } |
| 557 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 558 | * Could this slot have been previously retired? |
| 559 | * If so, then the server may be expecting seq_nr = 1! |
| 560 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 561 | if (slot->seq_nr != 1) { |
| 562 | slot->seq_nr = 1; |
| 563 | goto retry_nowait; |
| 564 | } |
| 565 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 566 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 567 | ++slot->seq_nr; |
| 568 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 569 | default: |
| 570 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 571 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 572 | } |
| 573 | out: |
| 574 | /* The session may be reset by one of the error handlers. */ |
| 575 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 576 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 577 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 578 | retry_nowait: |
| 579 | if (rpc_restart_call_prepare(task)) { |
| 580 | task->tk_status = 0; |
| 581 | ret = 0; |
| 582 | } |
| 583 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 584 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 585 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 586 | goto out; |
| 587 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 588 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 589 | } |
| 590 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 591 | static int nfs4_sequence_done(struct rpc_task *task, |
| 592 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 593 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 594 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 595 | return 1; |
| 596 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 597 | } |
| 598 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 599 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 600 | struct nfs4_sequence_res *res, int cache_reply) |
| 601 | { |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 602 | args->sa_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 603 | args->sa_cache_this = 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 604 | args->sa_privileged = 0; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 605 | if (cache_reply) |
| 606 | args->sa_cache_this = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 607 | res->sr_slot = NULL; |
| 608 | } |
| 609 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 610 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 611 | { |
| 612 | args->sa_privileged = 1; |
| 613 | } |
| 614 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 615 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 616 | struct nfs4_sequence_args *args, |
| 617 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 618 | struct rpc_task *task) |
| 619 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 620 | struct nfs4_slot *slot; |
| 621 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 622 | |
| 623 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 624 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 625 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 626 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 627 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 628 | tbl = &session->fc_slot_table; |
| 629 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 630 | task->tk_timeout = 0; |
| 631 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 632 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 633 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 634 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 635 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 636 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 637 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 638 | } |
| 639 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 640 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 641 | if (IS_ERR(slot)) { |
| 642 | /* If out of memory, try again in 1/4 second */ |
| 643 | if (slot == ERR_PTR(-ENOMEM)) |
| 644 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 645 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 646 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 647 | } |
| 648 | spin_unlock(&tbl->slot_tbl_lock); |
| 649 | |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 650 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 651 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 652 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, |
| 653 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 654 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 655 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 656 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 657 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 658 | /* |
| 659 | * sr_status is only set in decode_sequence, and so will remain |
| 660 | * set to 1 if an rpc level failure occurs. |
| 661 | */ |
| 662 | res->sr_status = 1; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 663 | out_success: |
| 664 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 665 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 666 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 667 | /* Privileged tasks are queued with top priority */ |
| 668 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 669 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 670 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 671 | else |
| 672 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 673 | spin_unlock(&tbl->slot_tbl_lock); |
| 674 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 675 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 676 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 677 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 678 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 679 | struct nfs4_sequence_args *args, |
| 680 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 681 | struct rpc_task *task) |
| 682 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 683 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 684 | int ret = 0; |
| 685 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 686 | if (session == NULL) { |
| 687 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 688 | goto out; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 689 | } |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 690 | |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 691 | dprintk("--> %s clp %p session %p sr_slot %d\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 692 | __func__, session->clp, session, res->sr_slot ? |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 693 | res->sr_slot->slot_nr : -1); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 694 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 695 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 696 | out: |
| 697 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 698 | return ret; |
| 699 | } |
| 700 | |
| 701 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 702 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 703 | struct nfs4_sequence_args *seq_args; |
| 704 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 705 | }; |
| 706 | |
| 707 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 708 | { |
| 709 | struct nfs41_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 710 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 711 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 712 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 713 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 714 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 715 | } |
| 716 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 717 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 718 | { |
| 719 | struct nfs41_call_sync_data *data = calldata; |
| 720 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 721 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 722 | } |
| 723 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 724 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 725 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 726 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 727 | }; |
| 728 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 729 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 730 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 731 | struct rpc_message *msg, |
| 732 | struct nfs4_sequence_args *args, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 733 | struct nfs4_sequence_res *res) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 734 | { |
| 735 | int ret; |
| 736 | struct rpc_task *task; |
| 737 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 738 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 739 | .seq_args = args, |
| 740 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 741 | }; |
| 742 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 743 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 744 | .rpc_message = msg, |
| 745 | .callback_ops = &nfs41_call_sync_ops, |
| 746 | .callback_data = &data |
| 747 | }; |
| 748 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 749 | task = rpc_run_task(&task_setup); |
| 750 | if (IS_ERR(task)) |
| 751 | ret = PTR_ERR(task); |
| 752 | else { |
| 753 | ret = task->tk_status; |
| 754 | rpc_put_task(task); |
| 755 | } |
| 756 | return ret; |
| 757 | } |
| 758 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 759 | #else |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 760 | static |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 761 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 762 | struct nfs4_sequence_res *res, int cache_reply) |
| 763 | { |
| 764 | } |
| 765 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 766 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 767 | { |
| 768 | } |
| 769 | |
| 770 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 771 | static int nfs4_sequence_done(struct rpc_task *task, |
| 772 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 773 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 774 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 775 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 776 | #endif /* CONFIG_NFS_V4_1 */ |
| 777 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 778 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 779 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 780 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 781 | struct rpc_message *msg, |
| 782 | struct nfs4_sequence_args *args, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 783 | struct nfs4_sequence_res *res) |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 784 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 785 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 786 | } |
| 787 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 788 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 789 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 790 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 791 | struct rpc_message *msg, |
| 792 | struct nfs4_sequence_args *args, |
| 793 | struct nfs4_sequence_res *res, |
| 794 | int cache_reply) |
| 795 | { |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 796 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 797 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 798 | args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 799 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 800 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 801 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 803 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 805 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 806 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 807 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 808 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 809 | dir->i_version = cinfo->after; |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 810 | nfs_fscache_invalidate(dir); |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 811 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | } |
| 813 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 814 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 815 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 816 | struct nfs_openargs o_arg; |
| 817 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 818 | struct nfs_open_confirmargs c_arg; |
| 819 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 820 | struct nfs4_string owner_name; |
| 821 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 822 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 823 | struct nfs4_label *f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 824 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 825 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 826 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 827 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 828 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 829 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 830 | unsigned int rpc_done : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 831 | unsigned int is_recover : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 832 | int rpc_status; |
| 833 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 834 | }; |
| 835 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 836 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 837 | int err, struct nfs4_exception *exception) |
| 838 | { |
| 839 | if (err != -EINVAL) |
| 840 | return false; |
| 841 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 842 | return false; |
| 843 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 844 | exception->retry = 1; |
| 845 | return true; |
| 846 | } |
| 847 | |
| 848 | static enum open_claim_type4 |
| 849 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 850 | enum open_claim_type4 claim) |
| 851 | { |
| 852 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 853 | return claim; |
| 854 | switch (claim) { |
| 855 | default: |
| 856 | return claim; |
| 857 | case NFS4_OPEN_CLAIM_FH: |
| 858 | return NFS4_OPEN_CLAIM_NULL; |
| 859 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 860 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 861 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 862 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 863 | } |
| 864 | } |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 865 | |
| 866 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 867 | { |
| 868 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 869 | p->o_res.f_label = p->f_label; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 870 | p->o_res.seqid = p->o_arg.seqid; |
| 871 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 872 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 873 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 874 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 875 | 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] | 876 | } |
| 877 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 878 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 879 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 880 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 881 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 882 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 883 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 884 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 885 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 886 | struct inode *dir = parent->d_inode; |
| 887 | struct nfs_server *server = NFS_SERVER(dir); |
| 888 | struct nfs4_opendata *p; |
| 889 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 890 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 891 | if (p == NULL) |
| 892 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 893 | |
| 894 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 895 | if (IS_ERR(p->f_label)) |
| 896 | goto err_free_p; |
| 897 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 898 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 899 | if (p->o_arg.seqid == NULL) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 900 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 901 | nfs_sb_active(dentry->d_sb); |
| 902 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 903 | p->dir = parent; |
| 904 | p->owner = sp; |
| 905 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 906 | p->o_arg.open_flags = flags; |
| 907 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 908 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 909 | * will return permission denied for all bits until close */ |
| 910 | if (!(flags & O_EXCL)) { |
| 911 | /* ask server to check for all possible rights as results |
| 912 | * are cached */ |
| 913 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 914 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 915 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 916 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 917 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 918 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 919 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 920 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 921 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 922 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 923 | p->o_arg.label = label; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 924 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 925 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 926 | case NFS4_OPEN_CLAIM_NULL: |
| 927 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 928 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 929 | p->o_arg.fh = NFS_FH(dir); |
| 930 | break; |
| 931 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 932 | case NFS4_OPEN_CLAIM_FH: |
| 933 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 934 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 935 | p->o_arg.fh = NFS_FH(dentry->d_inode); |
| 936 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 937 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 938 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 939 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 940 | p->o_arg.u.attrs = &p->attrs; |
| 941 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 942 | |
| 943 | verf[0] = jiffies; |
| 944 | verf[1] = current->pid; |
| 945 | memcpy(p->o_arg.u.verifier.data, verf, |
| 946 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 947 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 948 | p->c_arg.fh = &p->o_res.fh; |
| 949 | p->c_arg.stateid = &p->o_res.stateid; |
| 950 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 951 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 952 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 953 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 954 | |
| 955 | err_free_label: |
| 956 | nfs4_label_free(p->f_label); |
| 957 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 958 | kfree(p); |
| 959 | err: |
| 960 | dput(parent); |
| 961 | return NULL; |
| 962 | } |
| 963 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 964 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 965 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 966 | struct nfs4_opendata *p = container_of(kref, |
| 967 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 968 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 969 | |
| 970 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 971 | if (p->state != NULL) |
| 972 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 973 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 974 | |
| 975 | nfs4_label_free(p->f_label); |
| 976 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 977 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 978 | dput(p->dentry); |
| 979 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 980 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 981 | kfree(p); |
| 982 | } |
| 983 | |
| 984 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 985 | { |
| 986 | if (p != NULL) |
| 987 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 988 | } |
| 989 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 990 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 991 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 992 | int ret; |
| 993 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 994 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 995 | return ret; |
| 996 | } |
| 997 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 998 | 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] | 999 | { |
| 1000 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1001 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1002 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1003 | goto out; |
| 1004 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1005 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1006 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1007 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1008 | break; |
| 1009 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1010 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1011 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1012 | break; |
| 1013 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1014 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1015 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1016 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1017 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1018 | return ret; |
| 1019 | } |
| 1020 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1021 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1022 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1023 | if (delegation == NULL) |
| 1024 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1025 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1026 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1027 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1028 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1029 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1030 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1031 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1032 | return 1; |
| 1033 | } |
| 1034 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1035 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1036 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1037 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1038 | case FMODE_WRITE: |
| 1039 | state->n_wronly++; |
| 1040 | break; |
| 1041 | case FMODE_READ: |
| 1042 | state->n_rdonly++; |
| 1043 | break; |
| 1044 | case FMODE_READ|FMODE_WRITE: |
| 1045 | state->n_rdwr++; |
| 1046 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1047 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1048 | } |
| 1049 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1050 | 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] | 1051 | { |
| 1052 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1053 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1054 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 92b40e9 | 2013-04-20 01:25:45 -0400 | [diff] [blame] | 1055 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1056 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1057 | case FMODE_READ: |
| 1058 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1059 | break; |
| 1060 | case FMODE_WRITE: |
| 1061 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1062 | break; |
| 1063 | case FMODE_READ|FMODE_WRITE: |
| 1064 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1065 | } |
| 1066 | } |
| 1067 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1068 | 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] | 1069 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1070 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1071 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1072 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1073 | } |
| 1074 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1075 | 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] | 1076 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1077 | /* |
| 1078 | * Protect the call to nfs4_state_set_mode_locked and |
| 1079 | * serialise the stateid update |
| 1080 | */ |
| 1081 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1082 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1083 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1084 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1085 | } |
| 1086 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1087 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1088 | write_sequnlock(&state->seqlock); |
| 1089 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1090 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1091 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | } |
| 1093 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1094 | 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] | 1095 | { |
| 1096 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1097 | struct nfs_delegation *deleg_cur; |
| 1098 | int ret = 0; |
| 1099 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1100 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1101 | |
| 1102 | rcu_read_lock(); |
| 1103 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1104 | if (deleg_cur == NULL) |
| 1105 | goto no_delegation; |
| 1106 | |
| 1107 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1108 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1109 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1110 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1111 | goto no_delegation_unlock; |
| 1112 | |
| 1113 | if (delegation == NULL) |
| 1114 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1115 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1116 | goto no_delegation_unlock; |
| 1117 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1118 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1119 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1120 | ret = 1; |
| 1121 | no_delegation_unlock: |
| 1122 | spin_unlock(&deleg_cur->lock); |
| 1123 | no_delegation: |
| 1124 | rcu_read_unlock(); |
| 1125 | |
| 1126 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1127 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1128 | ret = 1; |
| 1129 | } |
| 1130 | |
| 1131 | return ret; |
| 1132 | } |
| 1133 | |
| 1134 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1135 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1136 | { |
| 1137 | struct nfs_delegation *delegation; |
| 1138 | |
| 1139 | rcu_read_lock(); |
| 1140 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1141 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1142 | rcu_read_unlock(); |
| 1143 | return; |
| 1144 | } |
| 1145 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1146 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1147 | } |
| 1148 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1149 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1150 | { |
| 1151 | struct nfs4_state *state = opendata->state; |
| 1152 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1153 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1154 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1155 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1156 | nfs4_stateid stateid; |
| 1157 | int ret = -EAGAIN; |
| 1158 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1159 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1160 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1161 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1162 | if (can_open_cached(state, fmode, open_mode)) { |
| 1163 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1164 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1165 | goto out_return_state; |
| 1166 | } |
| 1167 | spin_unlock(&state->owner->so_lock); |
| 1168 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1169 | rcu_read_lock(); |
| 1170 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1171 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1172 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1173 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1174 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1175 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1176 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1177 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1178 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1179 | if (!opendata->is_recover) { |
| 1180 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1181 | if (ret != 0) |
| 1182 | goto out; |
| 1183 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1184 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1185 | |
| 1186 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1187 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1188 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1189 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1190 | out: |
| 1191 | return ERR_PTR(ret); |
| 1192 | out_return_state: |
| 1193 | atomic_inc(&state->count); |
| 1194 | return state; |
| 1195 | } |
| 1196 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1197 | static void |
| 1198 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1199 | { |
| 1200 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1201 | struct nfs_delegation *delegation; |
| 1202 | int delegation_flags = 0; |
| 1203 | |
| 1204 | rcu_read_lock(); |
| 1205 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1206 | if (delegation) |
| 1207 | delegation_flags = delegation->flags; |
| 1208 | rcu_read_unlock(); |
| 1209 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1210 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1211 | "returning a delegation for " |
| 1212 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1213 | clp->cl_hostname); |
| 1214 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1215 | nfs_inode_set_delegation(state->inode, |
| 1216 | data->owner->so_cred, |
| 1217 | &data->o_res); |
| 1218 | else |
| 1219 | nfs_inode_reclaim_delegation(state->inode, |
| 1220 | data->owner->so_cred, |
| 1221 | &data->o_res); |
| 1222 | } |
| 1223 | |
| 1224 | /* |
| 1225 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1226 | * and update the nfs4_state. |
| 1227 | */ |
| 1228 | static struct nfs4_state * |
| 1229 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1230 | { |
| 1231 | struct inode *inode = data->state->inode; |
| 1232 | struct nfs4_state *state = data->state; |
| 1233 | int ret; |
| 1234 | |
| 1235 | if (!data->rpc_done) { |
| 1236 | ret = data->rpc_status; |
| 1237 | goto err; |
| 1238 | } |
| 1239 | |
| 1240 | ret = -ESTALE; |
| 1241 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || |
| 1242 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || |
| 1243 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) |
| 1244 | goto err; |
| 1245 | |
| 1246 | ret = -ENOMEM; |
| 1247 | state = nfs4_get_open_state(inode, data->owner); |
| 1248 | if (state == NULL) |
| 1249 | goto err; |
| 1250 | |
| 1251 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1252 | if (ret) |
| 1253 | goto err; |
| 1254 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1255 | nfs_setsecurity(inode, &data->f_attr, data->f_label); |
| 1256 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1257 | if (data->o_res.delegation_type != 0) |
| 1258 | nfs4_opendata_check_deleg(data, state); |
| 1259 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1260 | data->o_arg.fmode); |
| 1261 | |
| 1262 | return state; |
| 1263 | err: |
| 1264 | return ERR_PTR(ret); |
| 1265 | |
| 1266 | } |
| 1267 | |
| 1268 | static struct nfs4_state * |
| 1269 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1270 | { |
| 1271 | struct inode *inode; |
| 1272 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1273 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1274 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1275 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1276 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1277 | goto out; |
| 1278 | } |
| 1279 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1280 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1281 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1282 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1283 | 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] | 1284 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1285 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1286 | goto err; |
| 1287 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1288 | state = nfs4_get_open_state(inode, data->owner); |
| 1289 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1290 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1291 | if (data->o_res.delegation_type != 0) |
| 1292 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1293 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1294 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1295 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1296 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1297 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1298 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1299 | err_put_inode: |
| 1300 | iput(inode); |
| 1301 | err: |
| 1302 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1303 | } |
| 1304 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1305 | static struct nfs4_state * |
| 1306 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1307 | { |
| 1308 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1309 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1310 | return _nfs4_opendata_to_nfs4_state(data); |
| 1311 | } |
| 1312 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1313 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1314 | { |
| 1315 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1316 | struct nfs_open_context *ctx; |
| 1317 | |
| 1318 | spin_lock(&state->inode->i_lock); |
| 1319 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1320 | if (ctx->state != state) |
| 1321 | continue; |
| 1322 | get_nfs_open_context(ctx); |
| 1323 | spin_unlock(&state->inode->i_lock); |
| 1324 | return ctx; |
| 1325 | } |
| 1326 | spin_unlock(&state->inode->i_lock); |
| 1327 | return ERR_PTR(-ENOENT); |
| 1328 | } |
| 1329 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1330 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1331 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1332 | { |
| 1333 | struct nfs4_opendata *opendata; |
| 1334 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1335 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1336 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1337 | if (opendata == NULL) |
| 1338 | return ERR_PTR(-ENOMEM); |
| 1339 | opendata->state = state; |
| 1340 | atomic_inc(&state->count); |
| 1341 | return opendata; |
| 1342 | } |
| 1343 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1344 | 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] | 1345 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1346 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1347 | int ret; |
| 1348 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1349 | opendata->o_arg.open_flags = 0; |
| 1350 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1351 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1352 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1353 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1354 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1355 | if (ret != 0) |
| 1356 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1357 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1358 | if (IS_ERR(newstate)) |
| 1359 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1360 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1361 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1362 | return 0; |
| 1363 | } |
| 1364 | |
| 1365 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1366 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1367 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1368 | int ret; |
| 1369 | |
| 1370 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1371 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1372 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1373 | smp_rmb(); |
| 1374 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1375 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1376 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1377 | if (ret != 0) |
| 1378 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1379 | if (newstate != state) |
| 1380 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1381 | } |
| 1382 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1383 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1384 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1385 | if (ret != 0) |
| 1386 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1387 | if (newstate != state) |
| 1388 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1389 | } |
| 1390 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1391 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1392 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1393 | if (ret != 0) |
| 1394 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1395 | if (newstate != state) |
| 1396 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1397 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1398 | /* |
| 1399 | * We may have performed cached opens for all three recoveries. |
| 1400 | * Check if we need to update the current stateid. |
| 1401 | */ |
| 1402 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1403 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1404 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1405 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1406 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1407 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1408 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1409 | return 0; |
| 1410 | } |
| 1411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | /* |
| 1413 | * OPEN_RECLAIM: |
| 1414 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1416 | 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] | 1417 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1418 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1419 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1420 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | int status; |
| 1422 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1423 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1424 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1425 | if (IS_ERR(opendata)) |
| 1426 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1427 | rcu_read_lock(); |
| 1428 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1429 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1430 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1431 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1432 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1433 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1434 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | return status; |
| 1436 | } |
| 1437 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1438 | 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] | 1439 | { |
| 1440 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1441 | struct nfs4_exception exception = { }; |
| 1442 | int err; |
| 1443 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1444 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1445 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1446 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1447 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1448 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1449 | break; |
| 1450 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | } while (exception.retry); |
| 1452 | return err; |
| 1453 | } |
| 1454 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1455 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1456 | { |
| 1457 | struct nfs_open_context *ctx; |
| 1458 | int ret; |
| 1459 | |
| 1460 | ctx = nfs4_state_find_open_context(state); |
| 1461 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1462 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1463 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1464 | put_nfs_open_context(ctx); |
| 1465 | return ret; |
| 1466 | } |
| 1467 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1468 | 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] | 1469 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1470 | switch (err) { |
| 1471 | default: |
| 1472 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1473 | "%d.\n", __func__, err); |
| 1474 | case 0: |
| 1475 | case -ENOENT: |
| 1476 | case -ESTALE: |
| 1477 | break; |
| 1478 | case -NFS4ERR_BADSESSION: |
| 1479 | case -NFS4ERR_BADSLOT: |
| 1480 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1481 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1482 | case -NFS4ERR_DEADSESSION: |
| 1483 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1484 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1485 | return -EAGAIN; |
| 1486 | case -NFS4ERR_STALE_CLIENTID: |
| 1487 | case -NFS4ERR_STALE_STATEID: |
| 1488 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1489 | case -NFS4ERR_EXPIRED: |
| 1490 | /* Don't recall a delegation if it was lost */ |
| 1491 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1492 | return -EAGAIN; |
| 1493 | case -NFS4ERR_DELEG_REVOKED: |
| 1494 | case -NFS4ERR_ADMIN_REVOKED: |
| 1495 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1496 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1497 | nfs_inode_find_state_and_recover(state->inode, |
| 1498 | stateid); |
| 1499 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1500 | return 0; |
| 1501 | case -NFS4ERR_DELAY: |
| 1502 | case -NFS4ERR_GRACE: |
| 1503 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1504 | ssleep(1); |
| 1505 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1506 | case -ENOMEM: |
| 1507 | case -NFS4ERR_DENIED: |
| 1508 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1509 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1510 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | return err; |
| 1512 | } |
| 1513 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1514 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
| 1515 | { |
| 1516 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1517 | struct nfs4_opendata *opendata; |
| 1518 | int err; |
| 1519 | |
| 1520 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1521 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1522 | if (IS_ERR(opendata)) |
| 1523 | return PTR_ERR(opendata); |
| 1524 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
| 1525 | err = nfs4_open_recover(opendata, state); |
| 1526 | nfs4_opendata_put(opendata); |
| 1527 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1528 | } |
| 1529 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1530 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1531 | { |
| 1532 | struct nfs4_opendata *data = calldata; |
| 1533 | |
| 1534 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1535 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1536 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1537 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1538 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1539 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1540 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | static void nfs4_open_confirm_release(void *calldata) |
| 1544 | { |
| 1545 | struct nfs4_opendata *data = calldata; |
| 1546 | struct nfs4_state *state = NULL; |
| 1547 | |
| 1548 | /* If this request hasn't been cancelled, do nothing */ |
| 1549 | if (data->cancelled == 0) |
| 1550 | goto out_free; |
| 1551 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1552 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1553 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1554 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1555 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1556 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1557 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1558 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1562 | .rpc_call_done = nfs4_open_confirm_done, |
| 1563 | .rpc_release = nfs4_open_confirm_release, |
| 1564 | }; |
| 1565 | |
| 1566 | /* |
| 1567 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1568 | */ |
| 1569 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1570 | { |
| 1571 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1572 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1573 | struct rpc_message msg = { |
| 1574 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1575 | .rpc_argp = &data->c_arg, |
| 1576 | .rpc_resp = &data->c_res, |
| 1577 | .rpc_cred = data->owner->so_cred, |
| 1578 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1579 | struct rpc_task_setup task_setup_data = { |
| 1580 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1581 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1582 | .callback_ops = &nfs4_open_confirm_ops, |
| 1583 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1584 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1585 | .flags = RPC_TASK_ASYNC, |
| 1586 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | int status; |
| 1588 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1589 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1590 | data->rpc_done = 0; |
| 1591 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1592 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1593 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1594 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1595 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1596 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1597 | if (status != 0) { |
| 1598 | data->cancelled = 1; |
| 1599 | smp_wmb(); |
| 1600 | } else |
| 1601 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1602 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | return status; |
| 1604 | } |
| 1605 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1606 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1608 | struct nfs4_opendata *data = calldata; |
| 1609 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1610 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1611 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1612 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1613 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1614 | /* |
| 1615 | * Check if we still need to send an OPEN call, or if we can use |
| 1616 | * a delegation instead. |
| 1617 | */ |
| 1618 | if (data->state != NULL) { |
| 1619 | struct nfs_delegation *delegation; |
| 1620 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1621 | 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] | 1622 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1623 | rcu_read_lock(); |
| 1624 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1625 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
Trond Myklebust | cd4c9be | 2013-04-23 14:46:25 -0400 | [diff] [blame] | 1626 | data->o_arg.claim != NFS4_OPEN_CLAIM_DELEG_CUR_FH && |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1627 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1628 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1629 | rcu_read_unlock(); |
| 1630 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1631 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1632 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1633 | switch (data->o_arg.claim) { |
| 1634 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1635 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1636 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1637 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1638 | case NFS4_OPEN_CLAIM_FH: |
| 1639 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1640 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1641 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1642 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1643 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1644 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1645 | &data->o_res.seq_res, |
| 1646 | task) != 0) |
| 1647 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1648 | |
| 1649 | /* Set the create mode (note dependency on the session type) */ |
| 1650 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 1651 | if (data->o_arg.open_flags & O_EXCL) { |
| 1652 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 1653 | if (nfs4_has_persistent_session(clp)) |
| 1654 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 1655 | else if (clp->cl_mvops->minor_version > 0) |
| 1656 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 1657 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1658 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1659 | unlock_no_action: |
| 1660 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1661 | out_no_action: |
| 1662 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1663 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1664 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1665 | } |
| 1666 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1667 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1668 | { |
| 1669 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1671 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1672 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1673 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1674 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1675 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1676 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1677 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1678 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1679 | case S_IFREG: |
| 1680 | break; |
| 1681 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1682 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1683 | break; |
| 1684 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1685 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1686 | break; |
| 1687 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1688 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1689 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1690 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1691 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1692 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1693 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1694 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1695 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1696 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1697 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1698 | static void nfs4_open_release(void *calldata) |
| 1699 | { |
| 1700 | struct nfs4_opendata *data = calldata; |
| 1701 | struct nfs4_state *state = NULL; |
| 1702 | |
| 1703 | /* If this request hasn't been cancelled, do nothing */ |
| 1704 | if (data->cancelled == 0) |
| 1705 | goto out_free; |
| 1706 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1707 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1708 | goto out_free; |
| 1709 | /* In case we need an open_confirm, no cleanup! */ |
| 1710 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1711 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1712 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1713 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1714 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1715 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1716 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1720 | .rpc_call_prepare = nfs4_open_prepare, |
| 1721 | .rpc_call_done = nfs4_open_done, |
| 1722 | .rpc_release = nfs4_open_release, |
| 1723 | }; |
| 1724 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1725 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1726 | { |
| 1727 | struct inode *dir = data->dir->d_inode; |
| 1728 | struct nfs_server *server = NFS_SERVER(dir); |
| 1729 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1730 | struct nfs_openres *o_res = &data->o_res; |
| 1731 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1732 | struct rpc_message msg = { |
| 1733 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1734 | .rpc_argp = o_arg, |
| 1735 | .rpc_resp = o_res, |
| 1736 | .rpc_cred = data->owner->so_cred, |
| 1737 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1738 | struct rpc_task_setup task_setup_data = { |
| 1739 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1740 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1741 | .callback_ops = &nfs4_open_ops, |
| 1742 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1743 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1744 | .flags = RPC_TASK_ASYNC, |
| 1745 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1746 | int status; |
| 1747 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1748 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1749 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1750 | data->rpc_done = 0; |
| 1751 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1752 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1753 | data->is_recover = 0; |
| 1754 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1755 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1756 | data->is_recover = 1; |
| 1757 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1758 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1759 | if (IS_ERR(task)) |
| 1760 | return PTR_ERR(task); |
| 1761 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1762 | if (status != 0) { |
| 1763 | data->cancelled = 1; |
| 1764 | smp_wmb(); |
| 1765 | } else |
| 1766 | status = data->rpc_status; |
| 1767 | rpc_put_task(task); |
| 1768 | |
| 1769 | return status; |
| 1770 | } |
| 1771 | |
| 1772 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1773 | { |
| 1774 | struct inode *dir = data->dir->d_inode; |
| 1775 | struct nfs_openres *o_res = &data->o_res; |
| 1776 | int status; |
| 1777 | |
| 1778 | status = nfs4_run_open_task(data, 1); |
| 1779 | if (status != 0 || !data->rpc_done) |
| 1780 | return status; |
| 1781 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1782 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1783 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1784 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1785 | status = _nfs4_proc_open_confirm(data); |
| 1786 | if (status != 0) |
| 1787 | return status; |
| 1788 | } |
| 1789 | |
| 1790 | return status; |
| 1791 | } |
| 1792 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1793 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1794 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1795 | struct nfs4_state *state, fmode_t fmode, |
| 1796 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1797 | { |
| 1798 | struct nfs_access_entry cache; |
| 1799 | u32 mask; |
| 1800 | |
| 1801 | /* access call failed or for some reason the server doesn't |
| 1802 | * support any access modes -- defer access call until later */ |
| 1803 | if (opendata->o_res.access_supported == 0) |
| 1804 | return 0; |
| 1805 | |
| 1806 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1807 | /* 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] | 1808 | * write mode bits, but POSIX allows the creating process to write. |
| 1809 | * use openflags to check for exec, because fmode won't |
| 1810 | * always have FMODE_EXEC set when file open for exec. */ |
| 1811 | if (openflags & __FMODE_EXEC) { |
| 1812 | /* ONLY check for exec rights */ |
| 1813 | mask = MAY_EXEC; |
| 1814 | } else if (fmode & FMODE_READ) |
| 1815 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1816 | |
| 1817 | cache.cred = cred; |
| 1818 | cache.jiffies = jiffies; |
| 1819 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1820 | nfs_access_add_cache(state->inode, &cache); |
| 1821 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1822 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1823 | return 0; |
| 1824 | |
| 1825 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1826 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1827 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1828 | } |
| 1829 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1830 | /* |
| 1831 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1832 | */ |
| 1833 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1834 | { |
| 1835 | struct inode *dir = data->dir->d_inode; |
| 1836 | struct nfs_server *server = NFS_SERVER(dir); |
| 1837 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1838 | struct nfs_openres *o_res = &data->o_res; |
| 1839 | int status; |
| 1840 | |
| 1841 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1842 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1843 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1844 | if (status != 0) { |
| 1845 | if (status == -NFS4ERR_BADNAME && |
| 1846 | !(o_arg->open_flags & O_CREAT)) |
| 1847 | return -ENOENT; |
| 1848 | return status; |
| 1849 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1850 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1851 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1852 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1853 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1854 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1855 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1856 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1858 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1860 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | } |
| 1862 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1863 | _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] | 1864 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | } |
| 1866 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1867 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1868 | { |
| 1869 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1870 | } |
| 1871 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | /* |
| 1873 | * OPEN_EXPIRED: |
| 1874 | * reclaim state on the server after a network partition. |
| 1875 | * Assumes caller holds the appropriate lock |
| 1876 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1877 | 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] | 1878 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1879 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1880 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1882 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1883 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1884 | if (IS_ERR(opendata)) |
| 1885 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1886 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1887 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1888 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1889 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1890 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | } |
| 1892 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1893 | 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] | 1894 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1895 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1896 | struct nfs4_exception exception = { }; |
| 1897 | int err; |
| 1898 | |
| 1899 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1900 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1901 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1902 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1903 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1904 | switch (err) { |
| 1905 | default: |
| 1906 | goto out; |
| 1907 | case -NFS4ERR_GRACE: |
| 1908 | case -NFS4ERR_DELAY: |
| 1909 | nfs4_handle_exception(server, err, &exception); |
| 1910 | err = 0; |
| 1911 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1912 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1913 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1914 | return err; |
| 1915 | } |
| 1916 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1918 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1920 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1922 | ctx = nfs4_state_find_open_context(state); |
| 1923 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1924 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1925 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1926 | put_nfs_open_context(ctx); |
| 1927 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | } |
| 1929 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1930 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1931 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1932 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1933 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1934 | nfs4_stateid *stateid = &state->stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1935 | struct nfs_delegation *delegation; |
| 1936 | struct rpc_cred *cred = NULL; |
| 1937 | int status = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1938 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1939 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1940 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1941 | return; |
| 1942 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1943 | /* Get the delegation credential for use by test/free_stateid */ |
| 1944 | rcu_read_lock(); |
| 1945 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1946 | if (delegation != NULL && |
| 1947 | nfs4_stateid_match(&delegation->stateid, stateid)) { |
| 1948 | cred = get_rpccred(delegation->cred); |
| 1949 | rcu_read_unlock(); |
| 1950 | status = nfs41_test_stateid(server, stateid, cred); |
| 1951 | } else |
| 1952 | rcu_read_unlock(); |
| 1953 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1954 | if (status != NFS_OK) { |
| 1955 | /* Free the stateid unless the server explicitly |
| 1956 | * informs us the stateid is unrecognized. */ |
| 1957 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1958 | nfs41_free_stateid(server, stateid, cred); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1959 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1960 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1961 | write_seqlock(&state->seqlock); |
| 1962 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1963 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1964 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1965 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1966 | |
| 1967 | if (cred != NULL) |
| 1968 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | /** |
| 1972 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1973 | * |
| 1974 | * @state: NFSv4 state for an inode |
| 1975 | * |
| 1976 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1977 | * Otherwise a negative NFS4ERR value is returned. |
| 1978 | */ |
| 1979 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1980 | { |
| 1981 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1982 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1983 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1984 | int status; |
| 1985 | |
| 1986 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1987 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1988 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1989 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1990 | return -NFS4ERR_BAD_STATEID; |
| 1991 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1992 | status = nfs41_test_stateid(server, stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1993 | if (status != NFS_OK) { |
| 1994 | /* Free the stateid unless the server explicitly |
| 1995 | * informs us the stateid is unrecognized. */ |
| 1996 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1997 | nfs41_free_stateid(server, stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1998 | |
| 1999 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2000 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2001 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2002 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2003 | } |
| 2004 | return status; |
| 2005 | } |
| 2006 | |
| 2007 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2008 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2009 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2010 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2011 | nfs41_clear_delegation_stateid(state); |
| 2012 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2013 | if (status != NFS_OK) |
| 2014 | status = nfs4_open_expired(sp, state); |
| 2015 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2016 | } |
| 2017 | #endif |
| 2018 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2020 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2021 | * fields corresponding to attributes that were used to store the verifier. |
| 2022 | * Make sure we clobber those fields in the later setattr call |
| 2023 | */ |
| 2024 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 2025 | { |
| 2026 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 2027 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2028 | sattr->ia_valid |= ATTR_ATIME; |
| 2029 | |
| 2030 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 2031 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2032 | sattr->ia_valid |= ATTR_MTIME; |
| 2033 | } |
| 2034 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2035 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2036 | fmode_t fmode, |
| 2037 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2038 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2039 | { |
| 2040 | struct nfs4_state_owner *sp = opendata->owner; |
| 2041 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2042 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2043 | struct nfs4_state *state; |
| 2044 | unsigned int seq; |
| 2045 | int ret; |
| 2046 | |
| 2047 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2048 | |
| 2049 | ret = _nfs4_proc_open(opendata); |
| 2050 | if (ret != 0) |
| 2051 | goto out; |
| 2052 | |
| 2053 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2054 | ret = PTR_ERR(state); |
| 2055 | if (IS_ERR(state)) |
| 2056 | goto out; |
| 2057 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2058 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 2059 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2060 | dentry = opendata->dentry; |
| 2061 | if (dentry->d_inode == NULL) { |
| 2062 | /* FIXME: Is this d_drop() ever needed? */ |
| 2063 | d_drop(dentry); |
| 2064 | dentry = d_add_unique(dentry, igrab(state->inode)); |
| 2065 | if (dentry == NULL) { |
| 2066 | dentry = opendata->dentry; |
| 2067 | } else if (dentry != ctx->dentry) { |
| 2068 | dput(ctx->dentry); |
| 2069 | ctx->dentry = dget(dentry); |
| 2070 | } |
| 2071 | nfs_set_verifier(dentry, |
| 2072 | nfs_save_change_attribute(opendata->dir->d_inode)); |
| 2073 | } |
| 2074 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2075 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2076 | if (ret != 0) |
| 2077 | goto out; |
| 2078 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2079 | ctx->state = state; |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2080 | if (dentry->d_inode == state->inode) { |
| 2081 | nfs_inode_attach_open_context(ctx); |
| 2082 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2083 | nfs4_schedule_stateid_recovery(server, state); |
| 2084 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2085 | out: |
| 2086 | return ret; |
| 2087 | } |
| 2088 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2089 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2090 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2092 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2093 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2094 | int flags, |
| 2095 | struct iattr *sattr, |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2096 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | { |
| 2098 | struct nfs4_state_owner *sp; |
| 2099 | struct nfs4_state *state = NULL; |
| 2100 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2101 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2102 | struct dentry *dentry = ctx->dentry; |
| 2103 | struct rpc_cred *cred = ctx->cred; |
| 2104 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2105 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2106 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2107 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2108 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | |
| 2110 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2112 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2113 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2115 | goto out_err; |
| 2116 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2117 | status = nfs4_recover_expired_lease(server); |
| 2118 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2119 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2120 | if (dentry->d_inode != NULL) |
| 2121 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2122 | status = -ENOMEM; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2123 | if (dentry->d_inode) |
| 2124 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2125 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2126 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2127 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2128 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2130 | if (label) { |
| 2131 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2132 | if (IS_ERR(olabel)) { |
| 2133 | status = PTR_ERR(olabel); |
| 2134 | goto err_opendata_put; |
| 2135 | } |
| 2136 | } |
| 2137 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2138 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2139 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2140 | if (!opendata->f_attr.mdsthreshold) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2141 | goto err_free_label; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2142 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2143 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2144 | if (dentry->d_inode != NULL) |
| 2145 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2146 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2147 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2148 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2149 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2150 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2151 | |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2152 | if ((opendata->o_arg.open_flags & O_EXCL) && |
| 2153 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2154 | nfs4_exclusive_attrset(opendata, sattr); |
| 2155 | |
| 2156 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2157 | status = nfs4_do_setattr(state->inode, cred, |
| 2158 | opendata->o_res.f_attr, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2159 | state, label, olabel); |
| 2160 | if (status == 0) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2161 | nfs_setattr_update_inode(state->inode, sattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2162 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2163 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2164 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2165 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2166 | |
| 2167 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 2168 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 2169 | else |
| 2170 | kfree(opendata->f_attr.mdsthreshold); |
| 2171 | opendata->f_attr.mdsthreshold = NULL; |
| 2172 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2173 | nfs4_label_free(olabel); |
| 2174 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2175 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2178 | err_free_label: |
| 2179 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2180 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2181 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2182 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2183 | err_put_state_owner: |
| 2184 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | return status; |
| 2187 | } |
| 2188 | |
| 2189 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2190 | static struct nfs4_state *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 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2196 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | struct nfs4_exception exception = { }; |
| 2198 | struct nfs4_state *res; |
| 2199 | int status; |
| 2200 | |
| 2201 | do { |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2202 | status = _nfs4_do_open(dir, ctx, flags, sattr, label); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2203 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2204 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | if (status == 0) |
| 2206 | break; |
| 2207 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2208 | * book-keeping w.r.t. state-changing operations |
| 2209 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2210 | * It is actually a sign of a bug on the client or on the server. |
| 2211 | * |
| 2212 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2213 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | * have unhashed the old state_owner for us, and that we can |
| 2215 | * therefore safely retry using a new one. We should still warn |
| 2216 | * the user though... |
| 2217 | */ |
| 2218 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2219 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2220 | " returned a bad sequence-id error!\n", |
| 2221 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | exception.retry = 1; |
| 2223 | continue; |
| 2224 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2225 | /* |
| 2226 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2227 | * state before it received the OPEN_CONFIRM. |
| 2228 | * Recover by retrying the request as per the discussion |
| 2229 | * on Page 181 of RFC3530. |
| 2230 | */ |
| 2231 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2232 | exception.retry = 1; |
| 2233 | continue; |
| 2234 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2235 | if (status == -EAGAIN) { |
| 2236 | /* We must have found a delegation */ |
| 2237 | exception.retry = 1; |
| 2238 | continue; |
| 2239 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2240 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2241 | continue; |
| 2242 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | status, &exception)); |
| 2244 | } while (exception.retry); |
| 2245 | return res; |
| 2246 | } |
| 2247 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2248 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2249 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2250 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2251 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2252 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2253 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2254 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2255 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | .iap = sattr, |
| 2257 | .server = server, |
| 2258 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2259 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | }; |
| 2261 | struct nfs_setattrres res = { |
| 2262 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2263 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2264 | .server = server, |
| 2265 | }; |
| 2266 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2267 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2268 | .rpc_argp = &arg, |
| 2269 | .rpc_resp = &res, |
| 2270 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2272 | unsigned long timestamp = jiffies; |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2273 | fmode_t fmode; |
| 2274 | bool truncate; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2275 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2277 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2278 | if (ilabel) |
| 2279 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2280 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2281 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2283 | /* Servers should only apply open mode checks for file size changes */ |
| 2284 | truncate = (sattr->ia_valid & ATTR_SIZE) ? true : false; |
| 2285 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2286 | |
| 2287 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) { |
| 2288 | /* Use that stateid */ |
| 2289 | } else if (truncate && state != NULL && nfs4_valid_open_stateid(state)) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2290 | struct nfs_lockowner lockowner = { |
| 2291 | .l_owner = current->files, |
| 2292 | .l_pid = current->tgid, |
| 2293 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2294 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2295 | &lockowner); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2296 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2297 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2299 | 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] | 2300 | if (status == 0 && state != NULL) |
| 2301 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2302 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | } |
| 2304 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2305 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2306 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2307 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2308 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2310 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2311 | struct nfs4_exception exception = { |
| 2312 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2313 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2314 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | int err; |
| 2316 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2317 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state, ilabel, olabel); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 2318 | trace_nfs4_setattr(inode, err); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2319 | switch (err) { |
| 2320 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2321 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2322 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2323 | "applying open mode checks to " |
| 2324 | "a SETATTR that is not " |
| 2325 | "changing file size.\n", |
| 2326 | server->nfs_client->cl_hostname); |
| 2327 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2328 | if (state && !(state->state & FMODE_WRITE)) { |
| 2329 | err = -EBADF; |
| 2330 | if (sattr->ia_valid & ATTR_OPEN) |
| 2331 | err = -EACCES; |
| 2332 | goto out; |
| 2333 | } |
| 2334 | } |
| 2335 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2337 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 | return err; |
| 2339 | } |
| 2340 | |
| 2341 | struct nfs4_closedata { |
| 2342 | struct inode *inode; |
| 2343 | struct nfs4_state *state; |
| 2344 | struct nfs_closeargs arg; |
| 2345 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2346 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2347 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2348 | bool roc; |
| 2349 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | }; |
| 2351 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2352 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2353 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2354 | struct nfs4_closedata *calldata = data; |
| 2355 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2356 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2357 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2358 | if (calldata->roc) |
| 2359 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2360 | nfs4_put_open_state(calldata->state); |
| 2361 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2362 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2363 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2364 | kfree(calldata); |
| 2365 | } |
| 2366 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2367 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2368 | fmode_t fmode) |
| 2369 | { |
| 2370 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2371 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2372 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 2373 | case FMODE_WRITE: |
| 2374 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2375 | break; |
| 2376 | case FMODE_READ: |
| 2377 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2378 | break; |
| 2379 | case 0: |
| 2380 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2381 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2382 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 2383 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2384 | spin_unlock(&state->owner->so_lock); |
| 2385 | } |
| 2386 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2387 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2389 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2392 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2393 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2394 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2395 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2396 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | /* hmm. we are done with the inode, and in the process of freeing |
| 2398 | * the state_owner. we keep this around to process errors |
| 2399 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2400 | switch (task->tk_status) { |
| 2401 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2402 | if (calldata->roc) |
| 2403 | pnfs_roc_set_barrier(state->inode, |
| 2404 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2405 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2406 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2407 | nfs4_close_clear_stateid_flags(state, |
| 2408 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | break; |
| 2410 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2411 | case -NFS4ERR_OLD_STATEID: |
| 2412 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2413 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2414 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2415 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2417 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2418 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2420 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2421 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2422 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | } |
| 2424 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2425 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2427 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2428 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2429 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2430 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2431 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2432 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2433 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2434 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2435 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2436 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2437 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2438 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2439 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2440 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2441 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2442 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2443 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2444 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2445 | } |
| 2446 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2447 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2448 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2449 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2450 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2451 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2452 | if (!nfs4_valid_open_stateid(state)) |
| 2453 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2454 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2455 | |
| 2456 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2457 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2458 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2459 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2460 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2461 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2462 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2463 | if (calldata->roc && |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2464 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) { |
| 2465 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2466 | goto out_wait; |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2467 | } |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2468 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2469 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2470 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2471 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2472 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2473 | &calldata->arg.seq_args, |
| 2474 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2475 | task) != 0) |
| 2476 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2477 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2478 | return; |
| 2479 | out_no_action: |
| 2480 | task->tk_action = NULL; |
| 2481 | out_wait: |
| 2482 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2483 | } |
| 2484 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2485 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2486 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2487 | .rpc_call_done = nfs4_close_done, |
| 2488 | .rpc_release = nfs4_free_closedata, |
| 2489 | }; |
| 2490 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | /* |
| 2492 | * It is possible for data to be read/written from a mem-mapped file |
| 2493 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2494 | * This means that we can't safely call nfsv4 close on a file until |
| 2495 | * the inode is cleared. This in turn means that we are not good |
| 2496 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2497 | * share state even when we are done with one of the three share |
| 2498 | * stateid's in the inode. |
| 2499 | * |
| 2500 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2501 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2502 | 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] | 2503 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2504 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2505 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2506 | struct nfs4_state_owner *sp = state->owner; |
| 2507 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2508 | struct rpc_message msg = { |
| 2509 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2510 | .rpc_cred = state->owner->so_cred, |
| 2511 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2512 | struct rpc_task_setup task_setup_data = { |
| 2513 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2514 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2515 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2516 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2517 | .flags = RPC_TASK_ASYNC, |
| 2518 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2519 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2521 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2522 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2523 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2524 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2525 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2526 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2527 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2528 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2529 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2530 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2531 | if (calldata->arg.seqid == NULL) |
| 2532 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2533 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2534 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2535 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2536 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2537 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2538 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2539 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2540 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2541 | msg.rpc_argp = &calldata->arg; |
| 2542 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2543 | task_setup_data.callback_data = calldata; |
| 2544 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2545 | if (IS_ERR(task)) |
| 2546 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2547 | status = 0; |
| 2548 | if (wait) |
| 2549 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2550 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2551 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2552 | out_free_calldata: |
| 2553 | kfree(calldata); |
| 2554 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2555 | nfs4_put_open_state(state); |
| 2556 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2557 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | } |
| 2559 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2560 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2561 | 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] | 2562 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2563 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2564 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 2565 | |
| 2566 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2567 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2568 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2569 | state = nfs4_do_open(dir, ctx, open_flags, attr, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2570 | |
| 2571 | nfs4_label_release_security(label); |
| 2572 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2573 | if (IS_ERR(state)) |
| 2574 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2575 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | } |
| 2577 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2578 | 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] | 2579 | { |
| 2580 | if (ctx->state == NULL) |
| 2581 | return; |
| 2582 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2583 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2584 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2585 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2586 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2587 | |
| 2588 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2589 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2590 | struct nfs4_server_caps_arg args = { |
| 2591 | .fhandle = fhandle, |
| 2592 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | struct nfs4_server_caps_res res = {}; |
| 2594 | struct rpc_message msg = { |
| 2595 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2596 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2597 | .rpc_resp = &res, |
| 2598 | }; |
| 2599 | int status; |
| 2600 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2601 | 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] | 2602 | if (status == 0) { |
| 2603 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2604 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2605 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2606 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2607 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2608 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2609 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2610 | server->caps |= NFS_CAP_ACLS; |
| 2611 | if (res.has_links != 0) |
| 2612 | server->caps |= NFS_CAP_HARDLINKS; |
| 2613 | if (res.has_symlinks != 0) |
| 2614 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2615 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2616 | server->caps |= NFS_CAP_FILEID; |
| 2617 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2618 | server->caps |= NFS_CAP_MODE; |
| 2619 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2620 | server->caps |= NFS_CAP_NLINK; |
| 2621 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2622 | server->caps |= NFS_CAP_OWNER; |
| 2623 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2624 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2625 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2626 | server->caps |= NFS_CAP_ATIME; |
| 2627 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2628 | server->caps |= NFS_CAP_CTIME; |
| 2629 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2630 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2631 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 2632 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2633 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 2634 | #endif |
| 2635 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 2636 | sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2637 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2638 | if (server->caps & NFS_CAP_SECURITY_LABEL) { |
| 2639 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2640 | res.attr_bitmask[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2641 | } |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2642 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2643 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2644 | 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] | 2645 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2646 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2648 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | return status; |
| 2650 | } |
| 2651 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2652 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | { |
| 2654 | struct nfs4_exception exception = { }; |
| 2655 | int err; |
| 2656 | do { |
| 2657 | err = nfs4_handle_exception(server, |
| 2658 | _nfs4_server_capabilities(server, fhandle), |
| 2659 | &exception); |
| 2660 | } while (exception.retry); |
| 2661 | return err; |
| 2662 | } |
| 2663 | |
| 2664 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2665 | struct nfs_fsinfo *info) |
| 2666 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2667 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2669 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | }; |
| 2671 | struct nfs4_lookup_res res = { |
| 2672 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2673 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2674 | .fh = fhandle, |
| 2675 | }; |
| 2676 | struct rpc_message msg = { |
| 2677 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2678 | .rpc_argp = &args, |
| 2679 | .rpc_resp = &res, |
| 2680 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2681 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2682 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 2683 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 2684 | /* |
| 2685 | * Process the label in the upcoming getfattr |
| 2686 | */ |
| 2687 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 2688 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2689 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2690 | 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] | 2691 | } |
| 2692 | |
| 2693 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2694 | struct nfs_fsinfo *info) |
| 2695 | { |
| 2696 | struct nfs4_exception exception = { }; |
| 2697 | int err; |
| 2698 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2699 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2700 | switch (err) { |
| 2701 | case 0: |
| 2702 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2703 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2704 | default: |
| 2705 | err = nfs4_handle_exception(server, err, &exception); |
| 2706 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2708 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2709 | return err; |
| 2710 | } |
| 2711 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2712 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2713 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2714 | { |
| 2715 | struct rpc_auth *auth; |
| 2716 | int ret; |
| 2717 | |
| 2718 | auth = rpcauth_create(flavor, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2719 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 2720 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2721 | goto out; |
| 2722 | } |
| 2723 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2724 | out: |
| 2725 | return ret; |
| 2726 | } |
| 2727 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2728 | /* |
| 2729 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 2730 | * |
| 2731 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 2732 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 2733 | * |
| 2734 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 2735 | * negative errno value. |
| 2736 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2737 | 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] | 2738 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2740 | /* Per 3530bis 15.33.5 */ |
| 2741 | static const rpc_authflavor_t flav_array[] = { |
| 2742 | RPC_AUTH_GSS_KRB5P, |
| 2743 | RPC_AUTH_GSS_KRB5I, |
| 2744 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 2745 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2746 | RPC_AUTH_NULL, |
| 2747 | }; |
| 2748 | int status = -EPERM; |
| 2749 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2751 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2752 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2753 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2754 | continue; |
| 2755 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2756 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2757 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2758 | /* |
| 2759 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2760 | * to access the mount. It could also mean that we tried to mount |
| 2761 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2762 | * existing mount programs don't handle -EACCES very well so it should |
| 2763 | * be mapped to -EPERM instead. |
| 2764 | */ |
| 2765 | if (status == -EACCES) |
| 2766 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2767 | return status; |
| 2768 | } |
| 2769 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2770 | static int nfs4_do_find_root_sec(struct nfs_server *server, |
| 2771 | struct nfs_fh *fhandle, struct nfs_fsinfo *info) |
| 2772 | { |
| 2773 | int mv = server->nfs_client->cl_minorversion; |
| 2774 | return nfs_v4_minor_ops[mv]->find_root_sec(server, fhandle, info); |
| 2775 | } |
| 2776 | |
| 2777 | /** |
| 2778 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 2779 | * @server: initialized nfs_server handle |
| 2780 | * @fhandle: we fill in the pseudo-fs root file handle |
| 2781 | * @info: we fill in an FSINFO struct |
| 2782 | * |
| 2783 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2784 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2785 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2786 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2787 | { |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2788 | int status; |
| 2789 | |
| 2790 | status = nfs4_lookup_root(server, fhandle, info); |
| 2791 | if ((status == -NFS4ERR_WRONGSEC) && |
| 2792 | !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2793 | status = nfs4_do_find_root_sec(server, fhandle, info); |
| 2794 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2795 | if (status == 0) |
| 2796 | status = nfs4_server_capabilities(server, fhandle); |
| 2797 | if (status == 0) |
| 2798 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2799 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2800 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | } |
| 2802 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2803 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2804 | struct nfs_fsinfo *info) |
| 2805 | { |
| 2806 | int error; |
| 2807 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2808 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2809 | |
| 2810 | error = nfs4_server_capabilities(server, mntfh); |
| 2811 | if (error < 0) { |
| 2812 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2813 | return error; |
| 2814 | } |
| 2815 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2816 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 2817 | if (IS_ERR(label)) |
| 2818 | return PTR_ERR(label); |
| 2819 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2820 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2821 | if (error < 0) { |
| 2822 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2823 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2824 | } |
| 2825 | |
| 2826 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2827 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2828 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2829 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2830 | err_free_label: |
| 2831 | nfs4_label_free(label); |
| 2832 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2833 | return error; |
| 2834 | } |
| 2835 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2836 | /* |
| 2837 | * Get locations and (maybe) other attributes of a referral. |
| 2838 | * Note that we'll actually follow the referral later when |
| 2839 | * we detect fsid mismatch in inode revalidation |
| 2840 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2841 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2842 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2843 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2844 | { |
| 2845 | int status = -ENOMEM; |
| 2846 | struct page *page = NULL; |
| 2847 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2848 | |
| 2849 | page = alloc_page(GFP_KERNEL); |
| 2850 | if (page == NULL) |
| 2851 | goto out; |
| 2852 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2853 | if (locations == NULL) |
| 2854 | goto out; |
| 2855 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2856 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2857 | if (status != 0) |
| 2858 | goto out; |
| 2859 | /* Make sure server returned a different fsid for the referral */ |
| 2860 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2861 | dprintk("%s: server did not return a different fsid for" |
| 2862 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2863 | status = -EIO; |
| 2864 | goto out; |
| 2865 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2866 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2867 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2868 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2869 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2870 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2871 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2872 | out: |
| 2873 | if (page) |
| 2874 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2875 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2876 | return status; |
| 2877 | } |
| 2878 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2879 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2880 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2881 | { |
| 2882 | struct nfs4_getattr_arg args = { |
| 2883 | .fh = fhandle, |
| 2884 | .bitmask = server->attr_bitmask, |
| 2885 | }; |
| 2886 | struct nfs4_getattr_res res = { |
| 2887 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2888 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | .server = server, |
| 2890 | }; |
| 2891 | struct rpc_message msg = { |
| 2892 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2893 | .rpc_argp = &args, |
| 2894 | .rpc_resp = &res, |
| 2895 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2896 | |
| 2897 | args.bitmask = nfs4_bitmask(server, label); |
| 2898 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2899 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2900 | 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] | 2901 | } |
| 2902 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2903 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2904 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2905 | { |
| 2906 | struct nfs4_exception exception = { }; |
| 2907 | int err; |
| 2908 | do { |
| 2909 | err = nfs4_handle_exception(server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2910 | _nfs4_proc_getattr(server, fhandle, fattr, label), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2911 | &exception); |
| 2912 | } while (exception.retry); |
| 2913 | return err; |
| 2914 | } |
| 2915 | |
| 2916 | /* |
| 2917 | * The file is not closed if it is opened due to the a request to change |
| 2918 | * the size of the file. The open call will not be needed once the |
| 2919 | * VFS layer lookup-intents are implemented. |
| 2920 | * |
| 2921 | * Close is called when the inode is destroyed. |
| 2922 | * If we haven't opened the file for O_WRONLY, we |
| 2923 | * need to in the size_change case to obtain a stateid. |
| 2924 | * |
| 2925 | * Got race? |
| 2926 | * Because OPEN is always done by name in nfsv4, it is |
| 2927 | * possible that we opened a different file by the same |
| 2928 | * name. We can recognize this race condition, but we |
| 2929 | * can't do anything about it besides returning an error. |
| 2930 | * |
| 2931 | * This will be fixed with VFS changes (lookup-intent). |
| 2932 | */ |
| 2933 | static int |
| 2934 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2935 | struct iattr *sattr) |
| 2936 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2937 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2938 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2939 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2940 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | int status; |
| 2942 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2943 | if (pnfs_ld_layoutret_on_setattr(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 2944 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2945 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2946 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2948 | /* Deal with open(O_TRUNC) */ |
| 2949 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 2950 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2951 | |
| 2952 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 2953 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2954 | return 0; |
| 2955 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2956 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2957 | if (sattr->ia_valid & ATTR_FILE) { |
| 2958 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2959 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2960 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2961 | if (ctx) { |
| 2962 | cred = ctx->cred; |
| 2963 | state = ctx->state; |
| 2964 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2965 | } |
| 2966 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2967 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 2968 | if (IS_ERR(label)) |
| 2969 | return PTR_ERR(label); |
| 2970 | |
| 2971 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2972 | if (status == 0) { |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2973 | nfs_setattr_update_inode(inode, sattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2974 | nfs_setsecurity(inode, fattr, label); |
| 2975 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2976 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | return status; |
| 2978 | } |
| 2979 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2980 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2981 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2982 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2983 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2984 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2985 | int status; |
| 2986 | struct nfs4_lookup_arg args = { |
| 2987 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2988 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2989 | .name = name, |
| 2990 | }; |
| 2991 | struct nfs4_lookup_res res = { |
| 2992 | .server = server, |
| 2993 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2994 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2995 | .fh = fhandle, |
| 2996 | }; |
| 2997 | struct rpc_message msg = { |
| 2998 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2999 | .rpc_argp = &args, |
| 3000 | .rpc_resp = &res, |
| 3001 | }; |
| 3002 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3003 | args.bitmask = nfs4_bitmask(server, label); |
| 3004 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3005 | nfs_fattr_init(fattr); |
| 3006 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3007 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3008 | 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] | 3009 | dprintk("NFS reply lookup: %d\n", status); |
| 3010 | return status; |
| 3011 | } |
| 3012 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3013 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3014 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3015 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3016 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3017 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3018 | fattr->nlink = 2; |
| 3019 | } |
| 3020 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3021 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 3022 | struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3023 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3024 | { |
| 3025 | struct nfs4_exception exception = { }; |
| 3026 | struct rpc_clnt *client = *clnt; |
| 3027 | int err; |
| 3028 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3029 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3030 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3031 | switch (err) { |
| 3032 | case -NFS4ERR_BADNAME: |
| 3033 | err = -ENOENT; |
| 3034 | goto out; |
| 3035 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3036 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3037 | goto out; |
| 3038 | case -NFS4ERR_WRONGSEC: |
| 3039 | err = -EPERM; |
| 3040 | if (client != *clnt) |
| 3041 | goto out; |
| 3042 | |
| 3043 | client = nfs4_create_sec_client(client, dir, name); |
| 3044 | if (IS_ERR(client)) |
| 3045 | return PTR_ERR(client); |
| 3046 | |
| 3047 | exception.retry = 1; |
| 3048 | break; |
| 3049 | default: |
| 3050 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3051 | } |
| 3052 | } while (exception.retry); |
| 3053 | |
| 3054 | out: |
| 3055 | if (err == 0) |
| 3056 | *clnt = client; |
| 3057 | else if (client != *clnt) |
| 3058 | rpc_shutdown_client(client); |
| 3059 | |
| 3060 | return err; |
| 3061 | } |
| 3062 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 3063 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3064 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3065 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3066 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3067 | int status; |
| 3068 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3069 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3070 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3071 | if (client != NFS_CLIENT(dir)) { |
| 3072 | rpc_shutdown_client(client); |
| 3073 | nfs_fixup_secinfo_attributes(fattr); |
| 3074 | } |
| 3075 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | } |
| 3077 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3078 | struct rpc_clnt * |
| 3079 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 3080 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3081 | { |
| 3082 | int status; |
| 3083 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 3084 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3085 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3086 | if (status < 0) { |
| 3087 | rpc_shutdown_client(client); |
| 3088 | return ERR_PTR(status); |
| 3089 | } |
| 3090 | return client; |
| 3091 | } |
| 3092 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3093 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3094 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3095 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3096 | struct nfs4_accessargs args = { |
| 3097 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3098 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3099 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3100 | struct nfs4_accessres res = { |
| 3101 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3102 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | struct rpc_message msg = { |
| 3104 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3105 | .rpc_argp = &args, |
| 3106 | .rpc_resp = &res, |
| 3107 | .rpc_cred = entry->cred, |
| 3108 | }; |
| 3109 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3110 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3111 | |
| 3112 | /* |
| 3113 | * Determine which access bits we want to ask for... |
| 3114 | */ |
| 3115 | if (mode & MAY_READ) |
| 3116 | args.access |= NFS4_ACCESS_READ; |
| 3117 | if (S_ISDIR(inode->i_mode)) { |
| 3118 | if (mode & MAY_WRITE) |
| 3119 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3120 | if (mode & MAY_EXEC) |
| 3121 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3122 | } else { |
| 3123 | if (mode & MAY_WRITE) |
| 3124 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3125 | if (mode & MAY_EXEC) |
| 3126 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3127 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3128 | |
| 3129 | res.fattr = nfs_alloc_fattr(); |
| 3130 | if (res.fattr == NULL) |
| 3131 | return -ENOMEM; |
| 3132 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3133 | 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] | 3134 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3135 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3136 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3137 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3138 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | return status; |
| 3140 | } |
| 3141 | |
| 3142 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3143 | { |
| 3144 | struct nfs4_exception exception = { }; |
| 3145 | int err; |
| 3146 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3147 | err = _nfs4_proc_access(inode, entry); |
| 3148 | trace_nfs4_access(inode, err); |
| 3149 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | &exception); |
| 3151 | } while (exception.retry); |
| 3152 | return err; |
| 3153 | } |
| 3154 | |
| 3155 | /* |
| 3156 | * TODO: For the time being, we don't try to get any attributes |
| 3157 | * along with any of the zero-copy operations READ, READDIR, |
| 3158 | * READLINK, WRITE. |
| 3159 | * |
| 3160 | * In the case of the first three, we want to put the GETATTR |
| 3161 | * after the read-type operation -- this is because it is hard |
| 3162 | * to predict the length of a GETATTR response in v4, and thus |
| 3163 | * align the READ data correctly. This means that the GETATTR |
| 3164 | * may end up partially falling into the page cache, and we should |
| 3165 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3166 | * To do this efficiently, we need to know the total length |
| 3167 | * of data received, which doesn't seem to be available outside |
| 3168 | * of the RPC layer. |
| 3169 | * |
| 3170 | * In the case of WRITE, we also want to put the GETATTR after |
| 3171 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3172 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | * |
| 3174 | * Both of these changes to the XDR layer would in fact be quite |
| 3175 | * minor, but I decided to leave them for a subsequent patch. |
| 3176 | */ |
| 3177 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3178 | unsigned int pgbase, unsigned int pglen) |
| 3179 | { |
| 3180 | struct nfs4_readlink args = { |
| 3181 | .fh = NFS_FH(inode), |
| 3182 | .pgbase = pgbase, |
| 3183 | .pglen = pglen, |
| 3184 | .pages = &page, |
| 3185 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3186 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3187 | struct rpc_message msg = { |
| 3188 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3189 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3190 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | }; |
| 3192 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3193 | 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] | 3194 | } |
| 3195 | |
| 3196 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3197 | unsigned int pgbase, unsigned int pglen) |
| 3198 | { |
| 3199 | struct nfs4_exception exception = { }; |
| 3200 | int err; |
| 3201 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3202 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3203 | trace_nfs4_readlink(inode, err); |
| 3204 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3205 | &exception); |
| 3206 | } while (exception.retry); |
| 3207 | return err; |
| 3208 | } |
| 3209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3211 | * 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] | 3212 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | static int |
| 3214 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3215 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3217 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3218 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | int status = 0; |
| 3221 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3222 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3223 | if (IS_ERR(ctx)) |
| 3224 | return PTR_ERR(ctx); |
| 3225 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3226 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3227 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3228 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 3229 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3230 | if (IS_ERR(state)) { |
| 3231 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3232 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3233 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3234 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3235 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3236 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3237 | return status; |
| 3238 | } |
| 3239 | |
| 3240 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3241 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3242 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3243 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3244 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3245 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3247 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3248 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3249 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3251 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3252 | .rpc_argp = &args, |
| 3253 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3255 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3256 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3257 | 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] | 3258 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3259 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | return status; |
| 3261 | } |
| 3262 | |
| 3263 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3264 | { |
| 3265 | struct nfs4_exception exception = { }; |
| 3266 | int err; |
| 3267 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3268 | err = _nfs4_proc_remove(dir, name); |
| 3269 | trace_nfs4_remove(dir, name, err); |
| 3270 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3271 | &exception); |
| 3272 | } while (exception.retry); |
| 3273 | return err; |
| 3274 | } |
| 3275 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3276 | 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] | 3277 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3278 | struct nfs_server *server = NFS_SERVER(dir); |
| 3279 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3280 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3281 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3282 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3284 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3285 | |
| 3286 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3287 | } |
| 3288 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3289 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3290 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3291 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 3292 | &data->args.seq_args, |
| 3293 | &data->res.seq_res, |
| 3294 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3295 | } |
| 3296 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3297 | 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] | 3298 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3299 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 3300 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3301 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3302 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3303 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3304 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3305 | return 0; |
| 3306 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3307 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | } |
| 3309 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3310 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3311 | { |
| 3312 | struct nfs_server *server = NFS_SERVER(dir); |
| 3313 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3314 | struct nfs_renameres *res = msg->rpc_resp; |
| 3315 | |
| 3316 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3317 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3318 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3319 | } |
| 3320 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3321 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3322 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3323 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3324 | &data->args.seq_args, |
| 3325 | &data->res.seq_res, |
| 3326 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3327 | } |
| 3328 | |
| 3329 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3330 | struct inode *new_dir) |
| 3331 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame^] | 3332 | struct nfs_renamedata *data = task->tk_calldata; |
| 3333 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3334 | |
| 3335 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3336 | return 0; |
| 3337 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 3338 | return 0; |
| 3339 | |
| 3340 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3341 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3342 | return 1; |
| 3343 | } |
| 3344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3346 | struct inode *new_dir, struct qstr *new_name) |
| 3347 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3348 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 3349 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | .old_dir = NFS_FH(old_dir), |
| 3351 | .new_dir = NFS_FH(new_dir), |
| 3352 | .old_name = old_name, |
| 3353 | .new_name = new_name, |
| 3354 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3355 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3356 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3357 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3358 | struct rpc_message msg = { |
| 3359 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3360 | .rpc_argp = &arg, |
| 3361 | .rpc_resp = &res, |
| 3362 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3363 | int status = -ENOMEM; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3364 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3365 | 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] | 3366 | if (!status) { |
| 3367 | update_changeattr(old_dir, &res.old_cinfo); |
| 3368 | update_changeattr(new_dir, &res.new_cinfo); |
| 3369 | } |
| 3370 | return status; |
| 3371 | } |
| 3372 | |
| 3373 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3374 | struct inode *new_dir, struct qstr *new_name) |
| 3375 | { |
| 3376 | struct nfs4_exception exception = { }; |
| 3377 | int err; |
| 3378 | do { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame^] | 3379 | err = _nfs4_proc_rename(old_dir, old_name, |
| 3380 | new_dir, new_name); |
| 3381 | trace_nfs4_rename(old_dir, old_name, new_dir, new_name, err); |
| 3382 | err = nfs4_handle_exception(NFS_SERVER(old_dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3383 | &exception); |
| 3384 | } while (exception.retry); |
| 3385 | return err; |
| 3386 | } |
| 3387 | |
| 3388 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3389 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3390 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3391 | struct nfs4_link_arg arg = { |
| 3392 | .fh = NFS_FH(inode), |
| 3393 | .dir_fh = NFS_FH(dir), |
| 3394 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3395 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3397 | struct nfs4_link_res res = { |
| 3398 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3399 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3400 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3401 | struct rpc_message msg = { |
| 3402 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3403 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3404 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3405 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3406 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3407 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3408 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3409 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3410 | goto out; |
| 3411 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3412 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3413 | if (IS_ERR(res.label)) { |
| 3414 | status = PTR_ERR(res.label); |
| 3415 | goto out; |
| 3416 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3417 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3418 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3419 | 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] | 3420 | if (!status) { |
| 3421 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3422 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 3423 | if (!status) |
| 3424 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3425 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3426 | |
| 3427 | |
| 3428 | nfs4_label_free(res.label); |
| 3429 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3430 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3431 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3432 | return status; |
| 3433 | } |
| 3434 | |
| 3435 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3436 | { |
| 3437 | struct nfs4_exception exception = { }; |
| 3438 | int err; |
| 3439 | do { |
| 3440 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3441 | _nfs4_proc_link(inode, dir, name), |
| 3442 | &exception); |
| 3443 | } while (exception.retry); |
| 3444 | return err; |
| 3445 | } |
| 3446 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3447 | struct nfs4_createdata { |
| 3448 | struct rpc_message msg; |
| 3449 | struct nfs4_create_arg arg; |
| 3450 | struct nfs4_create_res res; |
| 3451 | struct nfs_fh fh; |
| 3452 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3453 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3454 | }; |
| 3455 | |
| 3456 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3457 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3458 | { |
| 3459 | struct nfs4_createdata *data; |
| 3460 | |
| 3461 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3462 | if (data != NULL) { |
| 3463 | struct nfs_server *server = NFS_SERVER(dir); |
| 3464 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3465 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3466 | if (IS_ERR(data->label)) |
| 3467 | goto out_free; |
| 3468 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3469 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3470 | data->msg.rpc_argp = &data->arg; |
| 3471 | data->msg.rpc_resp = &data->res; |
| 3472 | data->arg.dir_fh = NFS_FH(dir); |
| 3473 | data->arg.server = server; |
| 3474 | data->arg.name = name; |
| 3475 | data->arg.attrs = sattr; |
| 3476 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3477 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3478 | data->res.server = server; |
| 3479 | data->res.fh = &data->fh; |
| 3480 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3481 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3482 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3483 | } |
| 3484 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3485 | out_free: |
| 3486 | kfree(data); |
| 3487 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3488 | } |
| 3489 | |
| 3490 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3491 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3492 | 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] | 3493 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3494 | if (status == 0) { |
| 3495 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3496 | 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] | 3497 | } |
| 3498 | return status; |
| 3499 | } |
| 3500 | |
| 3501 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3502 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3503 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3504 | kfree(data); |
| 3505 | } |
| 3506 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3507 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3508 | struct page *page, unsigned int len, struct iattr *sattr, |
| 3509 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3510 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3511 | struct nfs4_createdata *data; |
| 3512 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3513 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3514 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3515 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3516 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3517 | status = -ENOMEM; |
| 3518 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3519 | if (data == NULL) |
| 3520 | goto out; |
| 3521 | |
| 3522 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3523 | data->arg.u.symlink.pages = &page; |
| 3524 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3525 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3526 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3527 | status = nfs4_do_create(dir, dentry, data); |
| 3528 | |
| 3529 | nfs4_free_createdata(data); |
| 3530 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3531 | return status; |
| 3532 | } |
| 3533 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3534 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3535 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3536 | { |
| 3537 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3538 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3539 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3540 | |
| 3541 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3542 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3543 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3544 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 3545 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 3546 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3547 | &exception); |
| 3548 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3549 | |
| 3550 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3551 | return err; |
| 3552 | } |
| 3553 | |
| 3554 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3555 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3556 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3557 | struct nfs4_createdata *data; |
| 3558 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3559 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3560 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3561 | if (data == NULL) |
| 3562 | goto out; |
| 3563 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3564 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3565 | status = nfs4_do_create(dir, dentry, data); |
| 3566 | |
| 3567 | nfs4_free_createdata(data); |
| 3568 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3569 | return status; |
| 3570 | } |
| 3571 | |
| 3572 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3573 | struct iattr *sattr) |
| 3574 | { |
| 3575 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3576 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3578 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3579 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3580 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3581 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3582 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3583 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 3584 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 3585 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3586 | &exception); |
| 3587 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3588 | nfs4_label_release_security(label); |
| 3589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | return err; |
| 3591 | } |
| 3592 | |
| 3593 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3594 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | { |
| 3596 | struct inode *dir = dentry->d_inode; |
| 3597 | struct nfs4_readdir_arg args = { |
| 3598 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3599 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3600 | .pgbase = 0, |
| 3601 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3602 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3603 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3604 | }; |
| 3605 | struct nfs4_readdir_res res; |
| 3606 | struct rpc_message msg = { |
| 3607 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3608 | .rpc_argp = &args, |
| 3609 | .rpc_resp = &res, |
| 3610 | .rpc_cred = cred, |
| 3611 | }; |
| 3612 | int status; |
| 3613 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3614 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3615 | dentry->d_parent->d_name.name, |
| 3616 | dentry->d_name.name, |
| 3617 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3618 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3620 | 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] | 3621 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3622 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3623 | status += args.pgbase; |
| 3624 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3625 | |
| 3626 | nfs_invalidate_atime(dir); |
| 3627 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3628 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3629 | return status; |
| 3630 | } |
| 3631 | |
| 3632 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3633 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3634 | { |
| 3635 | struct nfs4_exception exception = { }; |
| 3636 | int err; |
| 3637 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3638 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 3639 | pages, count, plus); |
| 3640 | trace_nfs4_readdir(dentry->d_inode, err); |
| 3641 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3642 | &exception); |
| 3643 | } while (exception.retry); |
| 3644 | return err; |
| 3645 | } |
| 3646 | |
| 3647 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3648 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3649 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3650 | struct nfs4_createdata *data; |
| 3651 | int mode = sattr->ia_mode; |
| 3652 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3653 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3654 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3655 | if (data == NULL) |
| 3656 | goto out; |
| 3657 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3658 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3659 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3661 | data->arg.ftype = NF4BLK; |
| 3662 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3663 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3664 | } |
| 3665 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3666 | data->arg.ftype = NF4CHR; |
| 3667 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3668 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3669 | } else if (!S_ISSOCK(mode)) { |
| 3670 | status = -EINVAL; |
| 3671 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3672 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3673 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3674 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3675 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3676 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3677 | nfs4_free_createdata(data); |
| 3678 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3679 | return status; |
| 3680 | } |
| 3681 | |
| 3682 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3683 | struct iattr *sattr, dev_t rdev) |
| 3684 | { |
| 3685 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3686 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3687 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3688 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3689 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3690 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3691 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3692 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3693 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 3694 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 3695 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | &exception); |
| 3697 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3698 | |
| 3699 | nfs4_label_release_security(label); |
| 3700 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3701 | return err; |
| 3702 | } |
| 3703 | |
| 3704 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3705 | struct nfs_fsstat *fsstat) |
| 3706 | { |
| 3707 | struct nfs4_statfs_arg args = { |
| 3708 | .fh = fhandle, |
| 3709 | .bitmask = server->attr_bitmask, |
| 3710 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3711 | struct nfs4_statfs_res res = { |
| 3712 | .fsstat = fsstat, |
| 3713 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3714 | struct rpc_message msg = { |
| 3715 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3716 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3717 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3718 | }; |
| 3719 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3720 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3721 | 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] | 3722 | } |
| 3723 | |
| 3724 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3725 | { |
| 3726 | struct nfs4_exception exception = { }; |
| 3727 | int err; |
| 3728 | do { |
| 3729 | err = nfs4_handle_exception(server, |
| 3730 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3731 | &exception); |
| 3732 | } while (exception.retry); |
| 3733 | return err; |
| 3734 | } |
| 3735 | |
| 3736 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3737 | struct nfs_fsinfo *fsinfo) |
| 3738 | { |
| 3739 | struct nfs4_fsinfo_arg args = { |
| 3740 | .fh = fhandle, |
| 3741 | .bitmask = server->attr_bitmask, |
| 3742 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3743 | struct nfs4_fsinfo_res res = { |
| 3744 | .fsinfo = fsinfo, |
| 3745 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3746 | struct rpc_message msg = { |
| 3747 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3748 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3749 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3750 | }; |
| 3751 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3752 | 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] | 3753 | } |
| 3754 | |
| 3755 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3756 | { |
| 3757 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3758 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3759 | int err; |
| 3760 | |
| 3761 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3762 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3763 | if (err == 0) { |
| 3764 | struct nfs_client *clp = server->nfs_client; |
| 3765 | |
| 3766 | spin_lock(&clp->cl_lock); |
| 3767 | clp->cl_lease_time = fsinfo->lease_time * HZ; |
| 3768 | clp->cl_last_renewal = now; |
| 3769 | spin_unlock(&clp->cl_lock); |
| 3770 | break; |
| 3771 | } |
| 3772 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3773 | } while (exception.retry); |
| 3774 | return err; |
| 3775 | } |
| 3776 | |
| 3777 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3778 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3779 | int error; |
| 3780 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3781 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3782 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3783 | if (error == 0) { |
| 3784 | /* block layout checks this! */ |
| 3785 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3786 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3787 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3788 | |
| 3789 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3790 | } |
| 3791 | |
| 3792 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3793 | struct nfs_pathconf *pathconf) |
| 3794 | { |
| 3795 | struct nfs4_pathconf_arg args = { |
| 3796 | .fh = fhandle, |
| 3797 | .bitmask = server->attr_bitmask, |
| 3798 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3799 | struct nfs4_pathconf_res res = { |
| 3800 | .pathconf = pathconf, |
| 3801 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3802 | struct rpc_message msg = { |
| 3803 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3804 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3805 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | }; |
| 3807 | |
| 3808 | /* None of the pathconf attributes are mandatory to implement */ |
| 3809 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3810 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3811 | return 0; |
| 3812 | } |
| 3813 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3814 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3815 | 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] | 3816 | } |
| 3817 | |
| 3818 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3819 | struct nfs_pathconf *pathconf) |
| 3820 | { |
| 3821 | struct nfs4_exception exception = { }; |
| 3822 | int err; |
| 3823 | |
| 3824 | do { |
| 3825 | err = nfs4_handle_exception(server, |
| 3826 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3827 | &exception); |
| 3828 | } while (exception.retry); |
| 3829 | return err; |
| 3830 | } |
| 3831 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3832 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3833 | const struct nfs_open_context *ctx, |
| 3834 | const struct nfs_lock_context *l_ctx, |
| 3835 | fmode_t fmode) |
| 3836 | { |
| 3837 | const struct nfs_lockowner *lockowner = NULL; |
| 3838 | |
| 3839 | if (l_ctx != NULL) |
| 3840 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3841 | return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3842 | } |
| 3843 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 3844 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3845 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 3846 | const struct nfs_open_context *ctx, |
| 3847 | const struct nfs_lock_context *l_ctx, |
| 3848 | fmode_t fmode) |
| 3849 | { |
| 3850 | nfs4_stateid current_stateid; |
| 3851 | |
| 3852 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode)) |
| 3853 | return false; |
| 3854 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 3855 | } |
| 3856 | |
| 3857 | static bool nfs4_error_stateid_expired(int err) |
| 3858 | { |
| 3859 | switch (err) { |
| 3860 | case -NFS4ERR_DELEG_REVOKED: |
| 3861 | case -NFS4ERR_ADMIN_REVOKED: |
| 3862 | case -NFS4ERR_BAD_STATEID: |
| 3863 | case -NFS4ERR_STALE_STATEID: |
| 3864 | case -NFS4ERR_OLD_STATEID: |
| 3865 | case -NFS4ERR_OPENMODE: |
| 3866 | case -NFS4ERR_EXPIRED: |
| 3867 | return true; |
| 3868 | } |
| 3869 | return false; |
| 3870 | } |
| 3871 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3872 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3873 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3874 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3875 | } |
| 3876 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3877 | 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] | 3878 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3879 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3880 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3881 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3882 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3883 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3884 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3885 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3886 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3887 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3888 | renew_lease(server, data->timestamp); |
| 3889 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3890 | } |
| 3891 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3892 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
| 3893 | struct nfs_readargs *args) |
| 3894 | { |
| 3895 | |
| 3896 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3897 | nfs4_stateid_is_current(&args->stateid, |
| 3898 | args->context, |
| 3899 | args->lock_context, |
| 3900 | FMODE_READ)) |
| 3901 | return false; |
| 3902 | rpc_restart_call_prepare(task); |
| 3903 | return true; |
| 3904 | } |
| 3905 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3906 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3907 | { |
| 3908 | |
| 3909 | dprintk("--> %s\n", __func__); |
| 3910 | |
| 3911 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3912 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3913 | if (nfs4_read_stateid_changed(task, &data->args)) |
| 3914 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3915 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3916 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3917 | } |
| 3918 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3919 | 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] | 3920 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3921 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3922 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3923 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3924 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3925 | } |
| 3926 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3927 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3928 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3929 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3930 | &data->args.seq_args, |
| 3931 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3932 | task)) |
| 3933 | return; |
| 3934 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 3935 | data->args.lock_context, FMODE_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3936 | } |
| 3937 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3938 | 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] | 3939 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3940 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3941 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3942 | 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] | 3943 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3944 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3945 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3946 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3947 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3948 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3949 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3950 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3951 | } |
| 3952 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3953 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
| 3954 | struct nfs_writeargs *args) |
| 3955 | { |
| 3956 | |
| 3957 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3958 | nfs4_stateid_is_current(&args->stateid, |
| 3959 | args->context, |
| 3960 | args->lock_context, |
| 3961 | FMODE_WRITE)) |
| 3962 | return false; |
| 3963 | rpc_restart_call_prepare(task); |
| 3964 | return true; |
| 3965 | } |
| 3966 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3967 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3968 | { |
| 3969 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3970 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3971 | if (nfs4_write_stateid_changed(task, &data->args)) |
| 3972 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3973 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3974 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3975 | } |
| 3976 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3977 | static |
| 3978 | 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] | 3979 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3980 | const struct nfs_pgio_header *hdr = data->header; |
| 3981 | |
| 3982 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3983 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3984 | return false; |
| 3985 | /* Otherwise, request attributes if and only if we don't hold |
| 3986 | * a delegation |
| 3987 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3988 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3989 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3990 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3991 | 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] | 3992 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3993 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3994 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3995 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3996 | data->args.bitmask = NULL; |
| 3997 | data->res.fattr = NULL; |
| 3998 | } else |
| 3999 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4000 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4001 | if (!data->write_done_cb) |
| 4002 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4003 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4004 | data->timestamp = jiffies; |
| 4005 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4006 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4007 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4008 | } |
| 4009 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 4010 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 4011 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4012 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4013 | &data->args.seq_args, |
| 4014 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4015 | task)) |
| 4016 | return; |
| 4017 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 4018 | data->args.lock_context, FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4019 | } |
| 4020 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4021 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4022 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4023 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4024 | &data->args.seq_args, |
| 4025 | &data->res.seq_res, |
| 4026 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | } |
| 4028 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4029 | 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] | 4030 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4031 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4032 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4033 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4034 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4035 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4036 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4037 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4038 | } |
| 4039 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4040 | 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] | 4041 | { |
| 4042 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4043 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4044 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4045 | } |
| 4046 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4047 | 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] | 4048 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4049 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4050 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4051 | if (data->commit_done_cb == NULL) |
| 4052 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4053 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4054 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4055 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4056 | } |
| 4057 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4058 | struct nfs4_renewdata { |
| 4059 | struct nfs_client *client; |
| 4060 | unsigned long timestamp; |
| 4061 | }; |
| 4062 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4063 | /* |
| 4064 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4065 | * standalone procedure for queueing an asynchronous RENEW. |
| 4066 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4067 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4068 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4069 | struct nfs4_renewdata *data = calldata; |
| 4070 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4071 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4072 | if (atomic_read(&clp->cl_count) > 1) |
| 4073 | nfs4_schedule_state_renewal(clp); |
| 4074 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4075 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4076 | } |
| 4077 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4078 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4079 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4080 | struct nfs4_renewdata *data = calldata; |
| 4081 | struct nfs_client *clp = data->client; |
| 4082 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4083 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4084 | trace_nfs4_renew_async(clp, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4085 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4086 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4087 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4088 | return; |
| 4089 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4090 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4091 | return; |
| 4092 | } |
| 4093 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4094 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4095 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | } |
| 4097 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4098 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4099 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4100 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4101 | }; |
| 4102 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4103 | 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] | 4104 | { |
| 4105 | struct rpc_message msg = { |
| 4106 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4107 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4108 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4109 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4110 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4111 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4112 | if (renew_flags == 0) |
| 4113 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4114 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4115 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4116 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4117 | if (data == NULL) |
| 4118 | return -ENOMEM; |
| 4119 | data->client = clp; |
| 4120 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4121 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4122 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4123 | } |
| 4124 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4125 | 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] | 4126 | { |
| 4127 | struct rpc_message msg = { |
| 4128 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4129 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4130 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4131 | }; |
| 4132 | unsigned long now = jiffies; |
| 4133 | int status; |
| 4134 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4135 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4136 | if (status < 0) |
| 4137 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4138 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4139 | return 0; |
| 4140 | } |
| 4141 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4142 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4143 | { |
| 4144 | return (server->caps & NFS_CAP_ACLS) |
| 4145 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 4146 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 4147 | } |
| 4148 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4149 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4150 | * 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] | 4151 | * the stack. |
| 4152 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4153 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4154 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4155 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 4156 | struct page **pages, unsigned int *pgbase) |
| 4157 | { |
| 4158 | struct page *newpage, **spages; |
| 4159 | int rc = 0; |
| 4160 | size_t len; |
| 4161 | spages = pages; |
| 4162 | |
| 4163 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4164 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4165 | newpage = alloc_page(GFP_KERNEL); |
| 4166 | |
| 4167 | if (newpage == NULL) |
| 4168 | goto unwind; |
| 4169 | memcpy(page_address(newpage), buf, len); |
| 4170 | buf += len; |
| 4171 | buflen -= len; |
| 4172 | *pages++ = newpage; |
| 4173 | rc++; |
| 4174 | } while (buflen != 0); |
| 4175 | |
| 4176 | return rc; |
| 4177 | |
| 4178 | unwind: |
| 4179 | for(; rc > 0; rc--) |
| 4180 | __free_page(spages[rc-1]); |
| 4181 | return -ENOMEM; |
| 4182 | } |
| 4183 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4184 | struct nfs4_cached_acl { |
| 4185 | int cached; |
| 4186 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4187 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4188 | }; |
| 4189 | |
| 4190 | 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] | 4191 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4192 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4193 | |
| 4194 | spin_lock(&inode->i_lock); |
| 4195 | kfree(nfsi->nfs4_acl); |
| 4196 | nfsi->nfs4_acl = acl; |
| 4197 | spin_unlock(&inode->i_lock); |
| 4198 | } |
| 4199 | |
| 4200 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4201 | { |
| 4202 | nfs4_set_cached_acl(inode, NULL); |
| 4203 | } |
| 4204 | |
| 4205 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4206 | { |
| 4207 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4208 | struct nfs4_cached_acl *acl; |
| 4209 | int ret = -ENOENT; |
| 4210 | |
| 4211 | spin_lock(&inode->i_lock); |
| 4212 | acl = nfsi->nfs4_acl; |
| 4213 | if (acl == NULL) |
| 4214 | goto out; |
| 4215 | if (buf == NULL) /* user is just asking for length */ |
| 4216 | goto out_len; |
| 4217 | if (acl->cached == 0) |
| 4218 | goto out; |
| 4219 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4220 | if (acl->len > buflen) |
| 4221 | goto out; |
| 4222 | memcpy(buf, acl->data, acl->len); |
| 4223 | out_len: |
| 4224 | ret = acl->len; |
| 4225 | out: |
| 4226 | spin_unlock(&inode->i_lock); |
| 4227 | return ret; |
| 4228 | } |
| 4229 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4230 | 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] | 4231 | { |
| 4232 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4233 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4234 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4235 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4236 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4237 | if (acl == NULL) |
| 4238 | goto out; |
| 4239 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4240 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4241 | } else { |
| 4242 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4243 | if (acl == NULL) |
| 4244 | goto out; |
| 4245 | acl->cached = 0; |
| 4246 | } |
| 4247 | acl->len = acl_len; |
| 4248 | out: |
| 4249 | nfs4_set_cached_acl(inode, acl); |
| 4250 | } |
| 4251 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4252 | /* |
| 4253 | * The getxattr API returns the required buffer length when called with a |
| 4254 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4255 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4256 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4257 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4258 | * the cache. If not so, we throw away the page, and cache the required |
| 4259 | * length. The next getxattr call will then produce another round trip to |
| 4260 | * the server, this time with the input buf of the required size. |
| 4261 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4262 | 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] | 4263 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4264 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4265 | struct nfs_getaclargs args = { |
| 4266 | .fh = NFS_FH(inode), |
| 4267 | .acl_pages = pages, |
| 4268 | .acl_len = buflen, |
| 4269 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4270 | struct nfs_getaclres res = { |
| 4271 | .acl_len = buflen, |
| 4272 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4273 | struct rpc_message msg = { |
| 4274 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4275 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4276 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4277 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4278 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4279 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4280 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4281 | /* As long as we're doing a round trip to the server anyway, |
| 4282 | * let's be prepared for a page of acl data. */ |
| 4283 | if (npages == 0) |
| 4284 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4285 | if (npages > ARRAY_SIZE(pages)) |
| 4286 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4287 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4288 | for (i = 0; i < npages; i++) { |
| 4289 | pages[i] = alloc_page(GFP_KERNEL); |
| 4290 | if (!pages[i]) |
| 4291 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4292 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4293 | |
| 4294 | /* for decoding across pages */ |
| 4295 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4296 | if (!res.acl_scratch) |
| 4297 | goto out_free; |
| 4298 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4299 | args.acl_len = npages * PAGE_SIZE; |
| 4300 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4301 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4302 | 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] | 4303 | __func__, buf, buflen, npages, args.acl_len); |
| 4304 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4305 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4306 | if (ret) |
| 4307 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4308 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4309 | /* Handle the case where the passed-in buffer is too short */ |
| 4310 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4311 | /* Did the user only issue a request for the acl length? */ |
| 4312 | if (buf == NULL) |
| 4313 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4314 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4315 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4316 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4317 | 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] | 4318 | if (buf) { |
| 4319 | if (res.acl_len > buflen) { |
| 4320 | ret = -ERANGE; |
| 4321 | goto out_free; |
| 4322 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4323 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4324 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4325 | out_ok: |
| 4326 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4327 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4328 | for (i = 0; i < npages; i++) |
| 4329 | if (pages[i]) |
| 4330 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4331 | if (res.acl_scratch) |
| 4332 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4333 | return ret; |
| 4334 | } |
| 4335 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4336 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4337 | { |
| 4338 | struct nfs4_exception exception = { }; |
| 4339 | ssize_t ret; |
| 4340 | do { |
| 4341 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4342 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4343 | if (ret >= 0) |
| 4344 | break; |
| 4345 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4346 | } while (exception.retry); |
| 4347 | return ret; |
| 4348 | } |
| 4349 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4350 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4351 | { |
| 4352 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4353 | int ret; |
| 4354 | |
| 4355 | if (!nfs4_server_supports_acls(server)) |
| 4356 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4357 | ret = nfs_revalidate_inode(server, inode); |
| 4358 | if (ret < 0) |
| 4359 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4360 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4361 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4362 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4363 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4364 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4365 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4366 | return ret; |
| 4367 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4368 | } |
| 4369 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4370 | 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] | 4371 | { |
| 4372 | struct nfs_server *server = NFS_SERVER(inode); |
| 4373 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4374 | struct nfs_setaclargs arg = { |
| 4375 | .fh = NFS_FH(inode), |
| 4376 | .acl_pages = pages, |
| 4377 | .acl_len = buflen, |
| 4378 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4379 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4380 | struct rpc_message msg = { |
| 4381 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4382 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4383 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4384 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4385 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4386 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4387 | |
| 4388 | if (!nfs4_server_supports_acls(server)) |
| 4389 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4390 | if (npages > ARRAY_SIZE(pages)) |
| 4391 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4392 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4393 | if (i < 0) |
| 4394 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4395 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4396 | 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] | 4397 | |
| 4398 | /* |
| 4399 | * Free each page after tx, so the only ref left is |
| 4400 | * held by the network stack |
| 4401 | */ |
| 4402 | for (; i > 0; i--) |
| 4403 | put_page(pages[i-1]); |
| 4404 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4405 | /* |
| 4406 | * Acl update can result in inode attribute update. |
| 4407 | * so mark the attribute cache invalid. |
| 4408 | */ |
| 4409 | spin_lock(&inode->i_lock); |
| 4410 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4411 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4412 | nfs_access_zap_cache(inode); |
| 4413 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4414 | return ret; |
| 4415 | } |
| 4416 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4417 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4418 | { |
| 4419 | struct nfs4_exception exception = { }; |
| 4420 | int err; |
| 4421 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4422 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 4423 | trace_nfs4_set_acl(inode, err); |
| 4424 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4425 | &exception); |
| 4426 | } while (exception.retry); |
| 4427 | return err; |
| 4428 | } |
| 4429 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4430 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 4431 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 4432 | size_t buflen) |
| 4433 | { |
| 4434 | struct nfs_server *server = NFS_SERVER(inode); |
| 4435 | struct nfs_fattr fattr; |
| 4436 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 4437 | |
| 4438 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
| 4439 | struct nfs4_getattr_arg args = { |
| 4440 | .fh = NFS_FH(inode), |
| 4441 | .bitmask = bitmask, |
| 4442 | }; |
| 4443 | struct nfs4_getattr_res res = { |
| 4444 | .fattr = &fattr, |
| 4445 | .label = &label, |
| 4446 | .server = server, |
| 4447 | }; |
| 4448 | struct rpc_message msg = { |
| 4449 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 4450 | .rpc_argp = &args, |
| 4451 | .rpc_resp = &res, |
| 4452 | }; |
| 4453 | int ret; |
| 4454 | |
| 4455 | nfs_fattr_init(&fattr); |
| 4456 | |
| 4457 | ret = rpc_call_sync(server->client, &msg, 0); |
| 4458 | if (ret) |
| 4459 | return ret; |
| 4460 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 4461 | return -ENOENT; |
| 4462 | if (buflen < label.len) |
| 4463 | return -ERANGE; |
| 4464 | return 0; |
| 4465 | } |
| 4466 | |
| 4467 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 4468 | size_t buflen) |
| 4469 | { |
| 4470 | struct nfs4_exception exception = { }; |
| 4471 | int err; |
| 4472 | |
| 4473 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4474 | return -EOPNOTSUPP; |
| 4475 | |
| 4476 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4477 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 4478 | trace_nfs4_get_security_label(inode, err); |
| 4479 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4480 | &exception); |
| 4481 | } while (exception.retry); |
| 4482 | return err; |
| 4483 | } |
| 4484 | |
| 4485 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 4486 | struct nfs4_label *ilabel, |
| 4487 | struct nfs_fattr *fattr, |
| 4488 | struct nfs4_label *olabel) |
| 4489 | { |
| 4490 | |
| 4491 | struct iattr sattr = {0}; |
| 4492 | struct nfs_server *server = NFS_SERVER(inode); |
| 4493 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
| 4494 | struct nfs_setattrargs args = { |
| 4495 | .fh = NFS_FH(inode), |
| 4496 | .iap = &sattr, |
| 4497 | .server = server, |
| 4498 | .bitmask = bitmask, |
| 4499 | .label = ilabel, |
| 4500 | }; |
| 4501 | struct nfs_setattrres res = { |
| 4502 | .fattr = fattr, |
| 4503 | .label = olabel, |
| 4504 | .server = server, |
| 4505 | }; |
| 4506 | struct rpc_message msg = { |
| 4507 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 4508 | .rpc_argp = &args, |
| 4509 | .rpc_resp = &res, |
| 4510 | }; |
| 4511 | int status; |
| 4512 | |
| 4513 | nfs4_stateid_copy(&args.stateid, &zero_stateid); |
| 4514 | |
| 4515 | status = rpc_call_sync(server->client, &msg, 0); |
| 4516 | if (status) |
| 4517 | dprintk("%s failed: %d\n", __func__, status); |
| 4518 | |
| 4519 | return status; |
| 4520 | } |
| 4521 | |
| 4522 | static int nfs4_do_set_security_label(struct inode *inode, |
| 4523 | struct nfs4_label *ilabel, |
| 4524 | struct nfs_fattr *fattr, |
| 4525 | struct nfs4_label *olabel) |
| 4526 | { |
| 4527 | struct nfs4_exception exception = { }; |
| 4528 | int err; |
| 4529 | |
| 4530 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4531 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 4532 | fattr, olabel); |
| 4533 | trace_nfs4_set_security_label(inode, err); |
| 4534 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4535 | &exception); |
| 4536 | } while (exception.retry); |
| 4537 | return err; |
| 4538 | } |
| 4539 | |
| 4540 | static int |
| 4541 | nfs4_set_security_label(struct dentry *dentry, const void *buf, size_t buflen) |
| 4542 | { |
| 4543 | struct nfs4_label ilabel, *olabel = NULL; |
| 4544 | struct nfs_fattr fattr; |
| 4545 | struct rpc_cred *cred; |
| 4546 | struct inode *inode = dentry->d_inode; |
| 4547 | int status; |
| 4548 | |
| 4549 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4550 | return -EOPNOTSUPP; |
| 4551 | |
| 4552 | nfs_fattr_init(&fattr); |
| 4553 | |
| 4554 | ilabel.pi = 0; |
| 4555 | ilabel.lfs = 0; |
| 4556 | ilabel.label = (char *)buf; |
| 4557 | ilabel.len = buflen; |
| 4558 | |
| 4559 | cred = rpc_lookup_cred(); |
| 4560 | if (IS_ERR(cred)) |
| 4561 | return PTR_ERR(cred); |
| 4562 | |
| 4563 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 4564 | if (IS_ERR(olabel)) { |
| 4565 | status = -PTR_ERR(olabel); |
| 4566 | goto out; |
| 4567 | } |
| 4568 | |
| 4569 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 4570 | if (status == 0) |
| 4571 | nfs_setsecurity(inode, &fattr, olabel); |
| 4572 | |
| 4573 | nfs4_label_free(olabel); |
| 4574 | out: |
| 4575 | put_rpccred(cred); |
| 4576 | return status; |
| 4577 | } |
| 4578 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 4579 | |
| 4580 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4581 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4582 | 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] | 4583 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4584 | struct nfs_client *clp = server->nfs_client; |
| 4585 | |
| 4586 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4587 | return 0; |
| 4588 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4589 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4590 | case -NFS4ERR_ADMIN_REVOKED: |
| 4591 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 4592 | if (state == NULL) |
| 4593 | break; |
| 4594 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4595 | case -NFS4ERR_OPENMODE: |
| 4596 | if (state == NULL) |
| 4597 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4598 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4599 | goto stateid_invalid; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4600 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4601 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4602 | if (state != NULL) { |
| 4603 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4604 | goto stateid_invalid; |
| 4605 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4606 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4607 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4608 | nfs4_schedule_lease_recovery(clp); |
| 4609 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4610 | #if defined(CONFIG_NFS_V4_1) |
| 4611 | case -NFS4ERR_BADSESSION: |
| 4612 | case -NFS4ERR_BADSLOT: |
| 4613 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4614 | case -NFS4ERR_DEADSESSION: |
| 4615 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4616 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4617 | case -NFS4ERR_SEQ_MISORDERED: |
| 4618 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4619 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4620 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4621 | task->tk_status = 0; |
| 4622 | return -EAGAIN; |
| 4623 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4624 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4625 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4626 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4627 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 4628 | task->tk_status = 0; |
| 4629 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4630 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4631 | case -NFS4ERR_OLD_STATEID: |
| 4632 | task->tk_status = 0; |
| 4633 | return -EAGAIN; |
| 4634 | } |
| 4635 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4636 | return 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4637 | stateid_invalid: |
| 4638 | task->tk_status = -EIO; |
| 4639 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4640 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4641 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4642 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4643 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 4644 | task->tk_status = 0; |
| 4645 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4646 | } |
| 4647 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4648 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4649 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4650 | { |
| 4651 | __be32 verf[2]; |
| 4652 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4653 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4654 | /* An impossible timestamp guarantees this value |
| 4655 | * will never match a generated boot time. */ |
| 4656 | verf[0] = 0; |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 4657 | verf[1] = cpu_to_be32(NSEC_PER_SEC + 1); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4658 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4659 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 4660 | verf[0] = cpu_to_be32(nn->boot_time.tv_sec); |
| 4661 | verf[1] = cpu_to_be32(nn->boot_time.tv_nsec); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4662 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4663 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4664 | } |
| 4665 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4666 | static unsigned int |
| 4667 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4668 | char *buf, size_t len) |
| 4669 | { |
| 4670 | unsigned int result; |
| 4671 | |
| 4672 | rcu_read_lock(); |
| 4673 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4674 | clp->cl_ipaddr, |
| 4675 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4676 | RPC_DISPLAY_ADDR), |
| 4677 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4678 | RPC_DISPLAY_PROTO)); |
| 4679 | rcu_read_unlock(); |
| 4680 | return result; |
| 4681 | } |
| 4682 | |
| 4683 | static unsigned int |
| 4684 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4685 | char *buf, size_t len) |
| 4686 | { |
Trond Myklebust | 55b5929 | 2013-07-24 16:36:35 -0400 | [diff] [blame] | 4687 | const char *nodename = clp->cl_rpcclient->cl_nodename; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4688 | |
| 4689 | if (nfs4_client_id_uniquifier[0] != '\0') |
Trond Myklebust | 55b5929 | 2013-07-24 16:36:35 -0400 | [diff] [blame] | 4690 | return scnprintf(buf, len, "Linux NFSv%u.%u %s/%s", |
| 4691 | clp->rpc_ops->version, |
| 4692 | clp->cl_minorversion, |
| 4693 | nfs4_client_id_uniquifier, |
| 4694 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4695 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4696 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4697 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4698 | } |
| 4699 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4700 | /** |
| 4701 | * nfs4_proc_setclientid - Negotiate client ID |
| 4702 | * @clp: state data structure |
| 4703 | * @program: RPC program for NFSv4 callback service |
| 4704 | * @port: IP port number for NFS4 callback service |
| 4705 | * @cred: RPC credential to use for this call |
| 4706 | * @res: where to place the result |
| 4707 | * |
| 4708 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4709 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4710 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4711 | unsigned short port, struct rpc_cred *cred, |
| 4712 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4713 | { |
| 4714 | nfs4_verifier sc_verifier; |
| 4715 | struct nfs4_setclientid setclientid = { |
| 4716 | .sc_verifier = &sc_verifier, |
| 4717 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4718 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4719 | }; |
| 4720 | struct rpc_message msg = { |
| 4721 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4722 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4723 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4724 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4725 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4726 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4727 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4728 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4729 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4730 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4731 | setclientid.sc_name_len = |
| 4732 | nfs4_init_uniform_client_string(clp, |
| 4733 | setclientid.sc_name, |
| 4734 | sizeof(setclientid.sc_name)); |
| 4735 | else |
| 4736 | setclientid.sc_name_len = |
| 4737 | nfs4_init_nonuniform_client_string(clp, |
| 4738 | setclientid.sc_name, |
| 4739 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4740 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4741 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4742 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Djalal Harouni | fe2d539 | 2013-06-18 17:58:12 +0100 | [diff] [blame] | 4743 | sizeof(setclientid.sc_netid), "%s", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4744 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4745 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4746 | rcu_read_unlock(); |
| 4747 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4748 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4749 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4750 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4751 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4752 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4753 | setclientid.sc_name_len, setclientid.sc_name); |
| 4754 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4755 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4756 | dprintk("NFS reply setclientid: %d\n", status); |
| 4757 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4758 | } |
| 4759 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4760 | /** |
| 4761 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4762 | * @clp: state data structure |
| 4763 | * @res: result of a previous SETCLIENTID |
| 4764 | * @cred: RPC credential to use for this call |
| 4765 | * |
| 4766 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4767 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4768 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4769 | struct nfs4_setclientid_res *arg, |
| 4770 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4771 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4772 | struct rpc_message msg = { |
| 4773 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4774 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4775 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4776 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4777 | int status; |
| 4778 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4779 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4780 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4781 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4782 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4783 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4784 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4785 | return status; |
| 4786 | } |
| 4787 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4788 | struct nfs4_delegreturndata { |
| 4789 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4790 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4791 | struct nfs_fh fh; |
| 4792 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4793 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4794 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4795 | int rpc_status; |
| 4796 | }; |
| 4797 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4798 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4799 | { |
| 4800 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4801 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4802 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4803 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4804 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4805 | switch (task->tk_status) { |
| 4806 | case -NFS4ERR_STALE_STATEID: |
| 4807 | case -NFS4ERR_EXPIRED: |
| 4808 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4809 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4810 | break; |
| 4811 | default: |
| 4812 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4813 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4814 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4815 | return; |
| 4816 | } |
| 4817 | } |
| 4818 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4819 | } |
| 4820 | |
| 4821 | static void nfs4_delegreturn_release(void *calldata) |
| 4822 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4823 | kfree(calldata); |
| 4824 | } |
| 4825 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4826 | #if defined(CONFIG_NFS_V4_1) |
| 4827 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4828 | { |
| 4829 | struct nfs4_delegreturndata *d_data; |
| 4830 | |
| 4831 | d_data = (struct nfs4_delegreturndata *)data; |
| 4832 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4833 | nfs4_setup_sequence(d_data->res.server, |
| 4834 | &d_data->args.seq_args, |
| 4835 | &d_data->res.seq_res, |
| 4836 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4837 | } |
| 4838 | #endif /* CONFIG_NFS_V4_1 */ |
| 4839 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4840 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4841 | #if defined(CONFIG_NFS_V4_1) |
| 4842 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4843 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4844 | .rpc_call_done = nfs4_delegreturn_done, |
| 4845 | .rpc_release = nfs4_delegreturn_release, |
| 4846 | }; |
| 4847 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4848 | 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] | 4849 | { |
| 4850 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4851 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4852 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4853 | struct rpc_message msg = { |
| 4854 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4855 | .rpc_cred = cred, |
| 4856 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4857 | struct rpc_task_setup task_setup_data = { |
| 4858 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4859 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4860 | .callback_ops = &nfs4_delegreturn_ops, |
| 4861 | .flags = RPC_TASK_ASYNC, |
| 4862 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4863 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4864 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4865 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4866 | if (data == NULL) |
| 4867 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4868 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4869 | data->args.fhandle = &data->fh; |
| 4870 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4871 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4872 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4873 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4874 | data->res.fattr = &data->fattr; |
| 4875 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4876 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4877 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4878 | data->rpc_status = 0; |
| 4879 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4880 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4881 | msg.rpc_argp = &data->args; |
| 4882 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4883 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4884 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4885 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4886 | if (!issync) |
| 4887 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4888 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4889 | if (status != 0) |
| 4890 | goto out; |
| 4891 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4892 | if (status == 0) |
| 4893 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4894 | else |
| 4895 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4896 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4897 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4898 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4899 | } |
| 4900 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4901 | 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] | 4902 | { |
| 4903 | struct nfs_server *server = NFS_SERVER(inode); |
| 4904 | struct nfs4_exception exception = { }; |
| 4905 | int err; |
| 4906 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4907 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4908 | switch (err) { |
| 4909 | case -NFS4ERR_STALE_STATEID: |
| 4910 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4911 | case 0: |
| 4912 | return 0; |
| 4913 | } |
| 4914 | err = nfs4_handle_exception(server, err, &exception); |
| 4915 | } while (exception.retry); |
| 4916 | return err; |
| 4917 | } |
| 4918 | |
| 4919 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4920 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4921 | |
| 4922 | /* |
| 4923 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4924 | */ |
| 4925 | static unsigned long |
| 4926 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4927 | { |
Colin Cross | 416ad3c | 2013-05-06 23:50:06 +0000 | [diff] [blame] | 4928 | freezable_schedule_timeout_killable_unsafe(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4929 | timeout <<= 1; |
| 4930 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4931 | return NFS4_LOCK_MAXTIMEOUT; |
| 4932 | return timeout; |
| 4933 | } |
| 4934 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4935 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4936 | { |
| 4937 | struct inode *inode = state->inode; |
| 4938 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4939 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4940 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4941 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4942 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4943 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4944 | struct nfs_lockt_res res = { |
| 4945 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4946 | }; |
| 4947 | struct rpc_message msg = { |
| 4948 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4949 | .rpc_argp = &arg, |
| 4950 | .rpc_resp = &res, |
| 4951 | .rpc_cred = state->owner->so_cred, |
| 4952 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4953 | struct nfs4_lock_state *lsp; |
| 4954 | int status; |
| 4955 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4956 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4957 | status = nfs4_set_lock_state(state, request); |
| 4958 | if (status != 0) |
| 4959 | goto out; |
| 4960 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4961 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4962 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4963 | 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] | 4964 | switch (status) { |
| 4965 | case 0: |
| 4966 | request->fl_type = F_UNLCK; |
| 4967 | break; |
| 4968 | case -NFS4ERR_DENIED: |
| 4969 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4970 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4971 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4972 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4973 | return status; |
| 4974 | } |
| 4975 | |
| 4976 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4977 | { |
| 4978 | struct nfs4_exception exception = { }; |
| 4979 | int err; |
| 4980 | |
| 4981 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 4982 | err = _nfs4_proc_getlk(state, cmd, request); |
| 4983 | trace_nfs4_get_lock(request, state, cmd, err); |
| 4984 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4985 | &exception); |
| 4986 | } while (exception.retry); |
| 4987 | return err; |
| 4988 | } |
| 4989 | |
| 4990 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4991 | { |
| 4992 | int res = 0; |
| 4993 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4994 | case FL_POSIX: |
| 4995 | res = posix_lock_file_wait(file, fl); |
| 4996 | break; |
| 4997 | case FL_FLOCK: |
| 4998 | res = flock_lock_file_wait(file, fl); |
| 4999 | break; |
| 5000 | default: |
| 5001 | BUG(); |
| 5002 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5003 | return res; |
| 5004 | } |
| 5005 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5006 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5007 | struct nfs_locku_args arg; |
| 5008 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5009 | struct nfs4_lock_state *lsp; |
| 5010 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5011 | struct file_lock fl; |
| 5012 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5013 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5014 | }; |
| 5015 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5016 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5017 | struct nfs_open_context *ctx, |
| 5018 | struct nfs4_lock_state *lsp, |
| 5019 | struct nfs_seqid *seqid) |
| 5020 | { |
| 5021 | struct nfs4_unlockdata *p; |
| 5022 | struct inode *inode = lsp->ls_state->inode; |
| 5023 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5024 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5025 | if (p == NULL) |
| 5026 | return NULL; |
| 5027 | p->arg.fh = NFS_FH(inode); |
| 5028 | p->arg.fl = &p->fl; |
| 5029 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5030 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5031 | p->arg.stateid = &lsp->ls_stateid; |
| 5032 | p->lsp = lsp; |
| 5033 | atomic_inc(&lsp->ls_count); |
| 5034 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5035 | p->ctx = get_nfs_open_context(ctx); |
| 5036 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5037 | p->server = NFS_SERVER(inode); |
| 5038 | return p; |
| 5039 | } |
| 5040 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5041 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5042 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5043 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5044 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5045 | nfs4_put_lock_state(calldata->lsp); |
| 5046 | put_nfs_open_context(calldata->ctx); |
| 5047 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5048 | } |
| 5049 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5050 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5051 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5052 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5053 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5054 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5055 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5056 | switch (task->tk_status) { |
| 5057 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5058 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 5059 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5060 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5061 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5062 | case -NFS4ERR_BAD_STATEID: |
| 5063 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5064 | case -NFS4ERR_STALE_STATEID: |
| 5065 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5066 | break; |
| 5067 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5068 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5069 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5070 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5071 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5072 | } |
| 5073 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5074 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5075 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5076 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5077 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5078 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5079 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5080 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5081 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5082 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5083 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5084 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5085 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5086 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5087 | &calldata->res.seq_res, |
| 5088 | task) != 0) |
| 5089 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5090 | return; |
| 5091 | out_no_action: |
| 5092 | task->tk_action = NULL; |
| 5093 | out_wait: |
| 5094 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5095 | } |
| 5096 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5097 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5098 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5099 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5100 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5101 | }; |
| 5102 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5103 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5104 | struct nfs_open_context *ctx, |
| 5105 | struct nfs4_lock_state *lsp, |
| 5106 | struct nfs_seqid *seqid) |
| 5107 | { |
| 5108 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5109 | struct rpc_message msg = { |
| 5110 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5111 | .rpc_cred = ctx->cred, |
| 5112 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5113 | struct rpc_task_setup task_setup_data = { |
| 5114 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5115 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5116 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5117 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5118 | .flags = RPC_TASK_ASYNC, |
| 5119 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5120 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5121 | /* Ensure this is an unlock - when canceling a lock, the |
| 5122 | * canceled lock is passed in, and it won't be an unlock. |
| 5123 | */ |
| 5124 | fl->fl_type = F_UNLCK; |
| 5125 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5126 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5127 | if (data == NULL) { |
| 5128 | nfs_free_seqid(seqid); |
| 5129 | return ERR_PTR(-ENOMEM); |
| 5130 | } |
| 5131 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5132 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5133 | msg.rpc_argp = &data->arg; |
| 5134 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5135 | task_setup_data.callback_data = data; |
| 5136 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5137 | } |
| 5138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5139 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5140 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5141 | struct inode *inode = state->inode; |
| 5142 | struct nfs4_state_owner *sp = state->owner; |
| 5143 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5144 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5145 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5146 | struct rpc_task *task; |
| 5147 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5148 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5149 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5150 | status = nfs4_set_lock_state(state, request); |
| 5151 | /* Unlock _before_ we do the RPC call */ |
| 5152 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5153 | /* Exclude nfs_delegation_claim_locks() */ |
| 5154 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5155 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5156 | down_read(&nfsi->rwsem); |
| 5157 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 5158 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5159 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5160 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5161 | } |
| 5162 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5163 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5164 | if (status != 0) |
| 5165 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5166 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5167 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5168 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5169 | goto out; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5170 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5171 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5172 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5173 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5174 | 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] | 5175 | status = PTR_ERR(task); |
| 5176 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5177 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5178 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5179 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5180 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5181 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5182 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5183 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5184 | } |
| 5185 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5186 | struct nfs4_lockdata { |
| 5187 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5188 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5189 | struct nfs4_lock_state *lsp; |
| 5190 | struct nfs_open_context *ctx; |
| 5191 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5192 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5193 | int rpc_status; |
| 5194 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5195 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5196 | }; |
| 5197 | |
| 5198 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5199 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5200 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5201 | { |
| 5202 | struct nfs4_lockdata *p; |
| 5203 | struct inode *inode = lsp->ls_state->inode; |
| 5204 | struct nfs_server *server = NFS_SERVER(inode); |
| 5205 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5206 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5207 | if (p == NULL) |
| 5208 | return NULL; |
| 5209 | |
| 5210 | p->arg.fh = NFS_FH(inode); |
| 5211 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5212 | 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] | 5213 | if (p->arg.open_seqid == NULL) |
| 5214 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5215 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5216 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5217 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5218 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5219 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5220 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5221 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5222 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5223 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5224 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5225 | atomic_inc(&lsp->ls_count); |
| 5226 | p->ctx = get_nfs_open_context(ctx); |
| 5227 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5228 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5229 | out_free_seqid: |
| 5230 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5231 | out_free: |
| 5232 | kfree(p); |
| 5233 | return NULL; |
| 5234 | } |
| 5235 | |
| 5236 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 5237 | { |
| 5238 | struct nfs4_lockdata *data = calldata; |
| 5239 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5240 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5241 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5242 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5243 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5244 | /* Do we need to do an open_to_lock_owner? */ |
| 5245 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5246 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5247 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5248 | } |
Trond Myklebust | 8e472f3 | 2013-04-20 01:30:53 -0400 | [diff] [blame] | 5249 | data->arg.open_stateid = &state->open_stateid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5250 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5251 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5252 | } else |
| 5253 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5254 | if (!nfs4_valid_open_stateid(state)) { |
| 5255 | data->rpc_status = -EBADF; |
| 5256 | task->tk_action = NULL; |
| 5257 | goto out_release_open_seqid; |
| 5258 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5259 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5260 | if (nfs4_setup_sequence(data->server, |
| 5261 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5262 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5263 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5264 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5265 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5266 | nfs_release_seqid(data->arg.open_seqid); |
| 5267 | out_release_lock_seqid: |
| 5268 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5269 | out_wait: |
| 5270 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5271 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5272 | } |
| 5273 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5274 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 5275 | { |
| 5276 | struct nfs4_lockdata *data = calldata; |
| 5277 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5278 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5279 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5280 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5281 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5282 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5283 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5284 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5285 | if (data->rpc_status == 0) |
| 5286 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 5287 | else |
| 5288 | goto out; |
| 5289 | } |
| 5290 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5291 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5292 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 5293 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5294 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5295 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5296 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5297 | } |
| 5298 | |
| 5299 | static void nfs4_lock_release(void *calldata) |
| 5300 | { |
| 5301 | struct nfs4_lockdata *data = calldata; |
| 5302 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5303 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5304 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5305 | if (data->cancelled != 0) { |
| 5306 | struct rpc_task *task; |
| 5307 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 5308 | data->arg.lock_seqid); |
| 5309 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5310 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5311 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5312 | } else |
| 5313 | nfs_free_seqid(data->arg.lock_seqid); |
| 5314 | nfs4_put_lock_state(data->lsp); |
| 5315 | put_nfs_open_context(data->ctx); |
| 5316 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5317 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5318 | } |
| 5319 | |
| 5320 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 5321 | .rpc_call_prepare = nfs4_lock_prepare, |
| 5322 | .rpc_call_done = nfs4_lock_done, |
| 5323 | .rpc_release = nfs4_lock_release, |
| 5324 | }; |
| 5325 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5326 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 5327 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5328 | switch (error) { |
| 5329 | case -NFS4ERR_ADMIN_REVOKED: |
| 5330 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5331 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5332 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5333 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5334 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5335 | break; |
| 5336 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5337 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5338 | case -NFS4ERR_EXPIRED: |
| 5339 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5340 | }; |
| 5341 | } |
| 5342 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5343 | 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] | 5344 | { |
| 5345 | struct nfs4_lockdata *data; |
| 5346 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5347 | struct rpc_message msg = { |
| 5348 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 5349 | .rpc_cred = state->owner->so_cred, |
| 5350 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5351 | struct rpc_task_setup task_setup_data = { |
| 5352 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5353 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5354 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5355 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5356 | .flags = RPC_TASK_ASYNC, |
| 5357 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5358 | int ret; |
| 5359 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5360 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5361 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5362 | fl->fl_u.nfs4_fl.owner, |
| 5363 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5364 | if (data == NULL) |
| 5365 | return -ENOMEM; |
| 5366 | if (IS_SETLKW(cmd)) |
| 5367 | data->arg.block = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5368 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5369 | msg.rpc_argp = &data->arg; |
| 5370 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5371 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5372 | if (recovery_type > NFS_LOCK_NEW) { |
| 5373 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 5374 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 5375 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
| 5376 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5377 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5378 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5379 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5380 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 5381 | if (ret == 0) { |
| 5382 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5383 | if (ret) |
| 5384 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 5385 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5386 | } else |
| 5387 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5388 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5389 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5390 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5391 | } |
| 5392 | |
| 5393 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 5394 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5395 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5396 | struct nfs4_exception exception = { |
| 5397 | .inode = state->inode, |
| 5398 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5399 | int err; |
| 5400 | |
| 5401 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5402 | /* Cache the lock if possible... */ |
| 5403 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5404 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5405 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5406 | trace_nfs4_lock_reclaim(request, state, F_SETLK, err); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5407 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5408 | break; |
| 5409 | nfs4_handle_exception(server, err, &exception); |
| 5410 | } while (exception.retry); |
| 5411 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5412 | } |
| 5413 | |
| 5414 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5415 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5416 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5417 | struct nfs4_exception exception = { |
| 5418 | .inode = state->inode, |
| 5419 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5420 | int err; |
| 5421 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5422 | err = nfs4_set_lock_state(state, request); |
| 5423 | if (err != 0) |
| 5424 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5425 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5426 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5427 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5428 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5429 | trace_nfs4_lock_expired(request, state, F_SETLK, err); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5430 | switch (err) { |
| 5431 | default: |
| 5432 | goto out; |
| 5433 | case -NFS4ERR_GRACE: |
| 5434 | case -NFS4ERR_DELAY: |
| 5435 | nfs4_handle_exception(server, err, &exception); |
| 5436 | err = 0; |
| 5437 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5438 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5439 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5440 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5441 | } |
| 5442 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5443 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5444 | /** |
| 5445 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 5446 | * |
| 5447 | * @state: NFSv4 state for an inode |
| 5448 | * |
| 5449 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 5450 | * Otherwise a negative NFS4ERR value is returned. |
| 5451 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5452 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5453 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5454 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5455 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5456 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5457 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5458 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5459 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5460 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 5461 | |
| 5462 | status = nfs41_test_stateid(server, |
| 5463 | &lsp->ls_stateid, |
| 5464 | cred); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5465 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5466 | /* Free the stateid unless the server |
| 5467 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 5468 | if (status != -NFS4ERR_BAD_STATEID) |
| 5469 | nfs41_free_stateid(server, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5470 | &lsp->ls_stateid, |
| 5471 | cred); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5472 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5473 | ret = status; |
| 5474 | } |
| 5475 | } |
| 5476 | }; |
| 5477 | |
| 5478 | return ret; |
| 5479 | } |
| 5480 | |
| 5481 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5482 | { |
| 5483 | int status = NFS_OK; |
| 5484 | |
| 5485 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 5486 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5487 | if (status != NFS_OK) |
| 5488 | status = nfs4_lock_expired(state, request); |
| 5489 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5490 | } |
| 5491 | #endif |
| 5492 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5493 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5494 | { |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5495 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5496 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5497 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5498 | unsigned int seq; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5499 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5500 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5501 | if ((fl_flags & FL_POSIX) && |
| 5502 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 5503 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5504 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5505 | status = nfs4_set_lock_state(state, request); |
| 5506 | if (status != 0) |
| 5507 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5508 | request->fl_flags |= FL_ACCESS; |
| 5509 | status = do_vfs_lock(request->fl_file, request); |
| 5510 | if (status < 0) |
| 5511 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5512 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5513 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5514 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5515 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5516 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 5517 | status = do_vfs_lock(request->fl_file, request); |
| 5518 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5519 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5520 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 5521 | up_read(&nfsi->rwsem); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5522 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5523 | if (status != 0) |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5524 | goto out; |
| 5525 | down_read(&nfsi->rwsem); |
| 5526 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { |
| 5527 | status = -NFS4ERR_DELAY; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5528 | goto out_unlock; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5529 | } |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5530 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5531 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5532 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5533 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 5534 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5535 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5536 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5537 | out: |
| 5538 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5539 | return status; |
| 5540 | } |
| 5541 | |
| 5542 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5543 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5544 | struct nfs4_exception exception = { |
| 5545 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5546 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5547 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5548 | int err; |
| 5549 | |
| 5550 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5551 | err = _nfs4_proc_setlk(state, cmd, request); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5552 | trace_nfs4_set_lock(request, state, cmd, err); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5553 | if (err == -NFS4ERR_DENIED) |
| 5554 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5555 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5556 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5557 | } while (exception.retry); |
| 5558 | return err; |
| 5559 | } |
| 5560 | |
| 5561 | static int |
| 5562 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 5563 | { |
| 5564 | struct nfs_open_context *ctx; |
| 5565 | struct nfs4_state *state; |
| 5566 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 5567 | int status; |
| 5568 | |
| 5569 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5570 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5571 | state = ctx->state; |
| 5572 | |
| 5573 | if (request->fl_start < 0 || request->fl_end < 0) |
| 5574 | return -EINVAL; |
| 5575 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5576 | if (IS_GETLK(cmd)) { |
| 5577 | if (state != NULL) |
| 5578 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 5579 | return 0; |
| 5580 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5581 | |
| 5582 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 5583 | return -EINVAL; |
| 5584 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5585 | if (request->fl_type == F_UNLCK) { |
| 5586 | if (state != NULL) |
| 5587 | return nfs4_proc_unlck(state, cmd, request); |
| 5588 | return 0; |
| 5589 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5590 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5591 | if (state == NULL) |
| 5592 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5593 | /* |
| 5594 | * Don't rely on the VFS having checked the file open mode, |
| 5595 | * since it won't do this for flock() locks. |
| 5596 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5597 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5598 | case F_RDLCK: |
| 5599 | if (!(filp->f_mode & FMODE_READ)) |
| 5600 | return -EBADF; |
| 5601 | break; |
| 5602 | case F_WRLCK: |
| 5603 | if (!(filp->f_mode & FMODE_WRITE)) |
| 5604 | return -EBADF; |
| 5605 | } |
| 5606 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5607 | do { |
| 5608 | status = nfs4_proc_setlk(state, cmd, request); |
| 5609 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 5610 | break; |
| 5611 | timeout = nfs4_set_lock_task_retry(timeout); |
| 5612 | status = -ERESTARTSYS; |
| 5613 | if (signalled()) |
| 5614 | break; |
| 5615 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5616 | return status; |
| 5617 | } |
| 5618 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5619 | 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] | 5620 | { |
| 5621 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5622 | int err; |
| 5623 | |
| 5624 | err = nfs4_set_lock_state(state, fl); |
| 5625 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5626 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 5627 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5628 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5629 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5630 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5631 | struct nfs_release_lockowner_data { |
| 5632 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5633 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5634 | struct nfs_release_lockowner_args args; |
| 5635 | }; |
| 5636 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5637 | static void nfs4_release_lockowner_release(void *calldata) |
| 5638 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5639 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5640 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5641 | kfree(calldata); |
| 5642 | } |
| 5643 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5644 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5645 | .rpc_release = nfs4_release_lockowner_release, |
| 5646 | }; |
| 5647 | |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 5648 | 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] | 5649 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5650 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5651 | struct rpc_message msg = { |
| 5652 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5653 | }; |
| 5654 | |
| 5655 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5656 | return -EINVAL; |
| 5657 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5658 | if (!data) |
| 5659 | return -ENOMEM; |
| 5660 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5661 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5662 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5663 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5664 | data->args.lock_owner.s_dev = server->s_dev; |
| 5665 | msg.rpc_argp = &data->args; |
| 5666 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5667 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5668 | } |
| 5669 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5670 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5671 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5672 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5673 | const void *buf, size_t buflen, |
| 5674 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5675 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5676 | if (strcmp(key, "") != 0) |
| 5677 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5678 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5679 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5680 | } |
| 5681 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5682 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5683 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5684 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5685 | if (strcmp(key, "") != 0) |
| 5686 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5687 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5688 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5689 | } |
| 5690 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5691 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5692 | size_t list_len, const char *name, |
| 5693 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5694 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5695 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5696 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5697 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5698 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5699 | |
| 5700 | if (list && len <= list_len) |
| 5701 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5702 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5703 | } |
| 5704 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 5705 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5706 | static inline int nfs4_server_supports_labels(struct nfs_server *server) |
| 5707 | { |
| 5708 | return server->caps & NFS_CAP_SECURITY_LABEL; |
| 5709 | } |
| 5710 | |
| 5711 | static int nfs4_xattr_set_nfs4_label(struct dentry *dentry, const char *key, |
| 5712 | const void *buf, size_t buflen, |
| 5713 | int flags, int type) |
| 5714 | { |
| 5715 | if (security_ismaclabel(key)) |
| 5716 | return nfs4_set_security_label(dentry, buf, buflen); |
| 5717 | |
| 5718 | return -EOPNOTSUPP; |
| 5719 | } |
| 5720 | |
| 5721 | static int nfs4_xattr_get_nfs4_label(struct dentry *dentry, const char *key, |
| 5722 | void *buf, size_t buflen, int type) |
| 5723 | { |
| 5724 | if (security_ismaclabel(key)) |
| 5725 | return nfs4_get_security_label(dentry->d_inode, buf, buflen); |
| 5726 | return -EOPNOTSUPP; |
| 5727 | } |
| 5728 | |
| 5729 | static size_t nfs4_xattr_list_nfs4_label(struct dentry *dentry, char *list, |
| 5730 | size_t list_len, const char *name, |
| 5731 | size_t name_len, int type) |
| 5732 | { |
| 5733 | size_t len = 0; |
| 5734 | |
| 5735 | if (nfs_server_capable(dentry->d_inode, NFS_CAP_SECURITY_LABEL)) { |
| 5736 | len = security_inode_listsecurity(dentry->d_inode, NULL, 0); |
| 5737 | if (list && len <= list_len) |
| 5738 | security_inode_listsecurity(dentry->d_inode, list, len); |
| 5739 | } |
| 5740 | return len; |
| 5741 | } |
| 5742 | |
| 5743 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 5744 | .prefix = XATTR_SECURITY_PREFIX, |
| 5745 | .list = nfs4_xattr_list_nfs4_label, |
| 5746 | .get = nfs4_xattr_get_nfs4_label, |
| 5747 | .set = nfs4_xattr_set_nfs4_label, |
| 5748 | }; |
| 5749 | #endif |
| 5750 | |
| 5751 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5752 | /* |
| 5753 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5754 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5755 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5756 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5757 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5758 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5759 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5760 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5761 | return; |
| 5762 | |
| 5763 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5764 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5765 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5766 | fattr->nlink = 2; |
| 5767 | } |
| 5768 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5769 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5770 | const struct qstr *name, |
| 5771 | struct nfs4_fs_locations *fs_locations, |
| 5772 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5773 | { |
| 5774 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 5775 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5776 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5777 | }; |
| 5778 | struct nfs4_fs_locations_arg args = { |
| 5779 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5780 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5781 | .page = page, |
| 5782 | .bitmask = bitmask, |
| 5783 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5784 | struct nfs4_fs_locations_res res = { |
| 5785 | .fs_locations = fs_locations, |
| 5786 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5787 | struct rpc_message msg = { |
| 5788 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5789 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5790 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5791 | }; |
| 5792 | int status; |
| 5793 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5794 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5795 | |
| 5796 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5797 | * is not supported */ |
| 5798 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5799 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5800 | else |
| 5801 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5802 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5803 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5804 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5805 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5806 | 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] | 5807 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5808 | return status; |
| 5809 | } |
| 5810 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5811 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5812 | const struct qstr *name, |
| 5813 | struct nfs4_fs_locations *fs_locations, |
| 5814 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5815 | { |
| 5816 | struct nfs4_exception exception = { }; |
| 5817 | int err; |
| 5818 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 5819 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 5820 | fs_locations, page); |
| 5821 | trace_nfs4_get_fs_locations(dir, name, err); |
| 5822 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5823 | &exception); |
| 5824 | } while (exception.retry); |
| 5825 | return err; |
| 5826 | } |
| 5827 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 5828 | /** |
| 5829 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 5830 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 5831 | */ |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5832 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5833 | { |
| 5834 | int status; |
| 5835 | struct nfs4_secinfo_arg args = { |
| 5836 | .dir_fh = NFS_FH(dir), |
| 5837 | .name = name, |
| 5838 | }; |
| 5839 | struct nfs4_secinfo_res res = { |
| 5840 | .flavors = flavors, |
| 5841 | }; |
| 5842 | struct rpc_message msg = { |
| 5843 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5844 | .rpc_argp = &args, |
| 5845 | .rpc_resp = &res, |
| 5846 | }; |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 5847 | struct rpc_clnt *clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5848 | |
| 5849 | dprintk("NFS call secinfo %s\n", name->name); |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 5850 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5851 | dprintk("NFS reply secinfo: %d\n", status); |
| 5852 | return status; |
| 5853 | } |
| 5854 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5855 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5856 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5857 | { |
| 5858 | struct nfs4_exception exception = { }; |
| 5859 | int err; |
| 5860 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 5861 | err = _nfs4_proc_secinfo(dir, name, flavors); |
| 5862 | trace_nfs4_secinfo(dir, name, err); |
| 5863 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5864 | &exception); |
| 5865 | } while (exception.retry); |
| 5866 | return err; |
| 5867 | } |
| 5868 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5869 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5870 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5871 | * Check the exchange flags returned by the server for invalid flags, having |
| 5872 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5873 | * DS flags set. |
| 5874 | */ |
| 5875 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5876 | { |
| 5877 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5878 | goto out_inval; |
| 5879 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5880 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5881 | goto out_inval; |
| 5882 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5883 | goto out_inval; |
| 5884 | return NFS_OK; |
| 5885 | out_inval: |
| 5886 | return -NFS4ERR_INVAL; |
| 5887 | } |
| 5888 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5889 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5890 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5891 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5892 | { |
| 5893 | if (a->server_scope_sz == b->server_scope_sz && |
| 5894 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5895 | return true; |
| 5896 | |
| 5897 | return false; |
| 5898 | } |
| 5899 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5900 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5901 | * nfs4_proc_bind_conn_to_session() |
| 5902 | * |
| 5903 | * The 4.1 client currently uses the same TCP connection for the |
| 5904 | * fore and backchannel. |
| 5905 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5906 | 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] | 5907 | { |
| 5908 | int status; |
| 5909 | struct nfs41_bind_conn_to_session_res res; |
| 5910 | struct rpc_message msg = { |
| 5911 | .rpc_proc = |
| 5912 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5913 | .rpc_argp = clp, |
| 5914 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5915 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5916 | }; |
| 5917 | |
| 5918 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5919 | |
| 5920 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5921 | if (unlikely(res.session == NULL)) { |
| 5922 | status = -ENOMEM; |
| 5923 | goto out; |
| 5924 | } |
| 5925 | |
| 5926 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5927 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5928 | if (status == 0) { |
| 5929 | if (memcmp(res.session->sess_id.data, |
| 5930 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5931 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5932 | status = -EIO; |
| 5933 | goto out_session; |
| 5934 | } |
| 5935 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5936 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5937 | __func__); |
| 5938 | status = -EIO; |
| 5939 | goto out_session; |
| 5940 | } |
| 5941 | if (res.use_conn_in_rdma_mode) { |
| 5942 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5943 | __func__); |
| 5944 | status = -EIO; |
| 5945 | goto out_session; |
| 5946 | } |
| 5947 | } |
| 5948 | out_session: |
| 5949 | kfree(res.session); |
| 5950 | out: |
| 5951 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5952 | return status; |
| 5953 | } |
| 5954 | |
| 5955 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5956 | * nfs4_proc_exchange_id() |
| 5957 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5958 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5959 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5960 | * Since the clientid has expired, all compounds using sessions |
| 5961 | * associated with the stale clientid will be returning |
| 5962 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5963 | * be in some phase of session reset. |
| 5964 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5965 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5966 | { |
| 5967 | nfs4_verifier verifier; |
| 5968 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5969 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5970 | .client = clp, |
Trond Myklebust | 4f0b429 | 2013-05-20 12:24:03 -0400 | [diff] [blame] | 5971 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 5972 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5973 | }; |
| 5974 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5975 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5976 | }; |
| 5977 | int status; |
| 5978 | struct rpc_message msg = { |
| 5979 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5980 | .rpc_argp = &args, |
| 5981 | .rpc_resp = &res, |
| 5982 | .rpc_cred = cred, |
| 5983 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5984 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5985 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5986 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 5987 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5988 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5989 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5990 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5991 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5992 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5993 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5994 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5995 | status = -ENOMEM; |
| 5996 | goto out; |
| 5997 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5998 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5999 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6000 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6001 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6002 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6003 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6004 | } |
| 6005 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6006 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6007 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6008 | status = -ENOMEM; |
| 6009 | goto out_server_scope; |
| 6010 | } |
| 6011 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6012 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6013 | trace_nfs4_exchange_id(clp, status); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6014 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6015 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6016 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6017 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6018 | clp->cl_clientid = res.clientid; |
| 6019 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 6020 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 6021 | clp->cl_seqid = res.seqid; |
| 6022 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6023 | kfree(clp->cl_serverowner); |
| 6024 | clp->cl_serverowner = res.server_owner; |
| 6025 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6026 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6027 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 6028 | kfree(clp->cl_implid); |
| 6029 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6030 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6031 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6032 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6033 | res.server_scope)) { |
| 6034 | dprintk("%s: server_scope mismatch detected\n", |
| 6035 | __func__); |
| 6036 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6037 | kfree(clp->cl_serverscope); |
| 6038 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6039 | } |
| 6040 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6041 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6042 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6043 | goto out; |
| 6044 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6045 | } else |
| 6046 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6047 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6048 | out_server_owner: |
| 6049 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6050 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6051 | kfree(res.server_scope); |
| 6052 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6053 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6054 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6055 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6056 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 6057 | clp->cl_implid->date.seconds, |
| 6058 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6059 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6060 | return status; |
| 6061 | } |
| 6062 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6063 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 6064 | struct rpc_cred *cred) |
| 6065 | { |
| 6066 | struct rpc_message msg = { |
| 6067 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 6068 | .rpc_argp = clp, |
| 6069 | .rpc_cred = cred, |
| 6070 | }; |
| 6071 | int status; |
| 6072 | |
| 6073 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6074 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6075 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 6076 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6077 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 6078 | return status; |
| 6079 | } |
| 6080 | |
| 6081 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 6082 | struct rpc_cred *cred) |
| 6083 | { |
| 6084 | unsigned int loop; |
| 6085 | int ret; |
| 6086 | |
| 6087 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 6088 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 6089 | switch (ret) { |
| 6090 | case -NFS4ERR_DELAY: |
| 6091 | case -NFS4ERR_CLIENTID_BUSY: |
| 6092 | ssleep(1); |
| 6093 | break; |
| 6094 | default: |
| 6095 | return ret; |
| 6096 | } |
| 6097 | } |
| 6098 | return 0; |
| 6099 | } |
| 6100 | |
| 6101 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 6102 | { |
| 6103 | struct rpc_cred *cred; |
| 6104 | int ret = 0; |
| 6105 | |
| 6106 | if (clp->cl_mvops->minor_version < 1) |
| 6107 | goto out; |
| 6108 | if (clp->cl_exchange_flags == 0) |
| 6109 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6110 | if (clp->cl_preserve_clid) |
| 6111 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 6112 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6113 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 6114 | if (cred) |
| 6115 | put_rpccred(cred); |
| 6116 | switch (ret) { |
| 6117 | case 0: |
| 6118 | case -NFS4ERR_STALE_CLIENTID: |
| 6119 | clp->cl_exchange_flags = 0; |
| 6120 | } |
| 6121 | out: |
| 6122 | return ret; |
| 6123 | } |
| 6124 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6125 | struct nfs4_get_lease_time_data { |
| 6126 | struct nfs4_get_lease_time_args *args; |
| 6127 | struct nfs4_get_lease_time_res *res; |
| 6128 | struct nfs_client *clp; |
| 6129 | }; |
| 6130 | |
| 6131 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 6132 | void *calldata) |
| 6133 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6134 | struct nfs4_get_lease_time_data *data = |
| 6135 | (struct nfs4_get_lease_time_data *)calldata; |
| 6136 | |
| 6137 | dprintk("--> %s\n", __func__); |
| 6138 | /* just setup sequence, do not trigger session recovery |
| 6139 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6140 | nfs41_setup_sequence(data->clp->cl_session, |
| 6141 | &data->args->la_seq_args, |
| 6142 | &data->res->lr_seq_res, |
| 6143 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6144 | dprintk("<-- %s\n", __func__); |
| 6145 | } |
| 6146 | |
| 6147 | /* |
| 6148 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 6149 | * from sequence operation or clientid errors. |
| 6150 | */ |
| 6151 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 6152 | { |
| 6153 | struct nfs4_get_lease_time_data *data = |
| 6154 | (struct nfs4_get_lease_time_data *)calldata; |
| 6155 | |
| 6156 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6157 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 6158 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6159 | switch (task->tk_status) { |
| 6160 | case -NFS4ERR_DELAY: |
| 6161 | case -NFS4ERR_GRACE: |
| 6162 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 6163 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 6164 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6165 | /* fall through */ |
| 6166 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6167 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6168 | return; |
| 6169 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6170 | dprintk("<-- %s\n", __func__); |
| 6171 | } |
| 6172 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6173 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6174 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 6175 | .rpc_call_done = nfs4_get_lease_time_done, |
| 6176 | }; |
| 6177 | |
| 6178 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 6179 | { |
| 6180 | struct rpc_task *task; |
| 6181 | struct nfs4_get_lease_time_args args; |
| 6182 | struct nfs4_get_lease_time_res res = { |
| 6183 | .lr_fsinfo = fsinfo, |
| 6184 | }; |
| 6185 | struct nfs4_get_lease_time_data data = { |
| 6186 | .args = &args, |
| 6187 | .res = &res, |
| 6188 | .clp = clp, |
| 6189 | }; |
| 6190 | struct rpc_message msg = { |
| 6191 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 6192 | .rpc_argp = &args, |
| 6193 | .rpc_resp = &res, |
| 6194 | }; |
| 6195 | struct rpc_task_setup task_setup = { |
| 6196 | .rpc_client = clp->cl_rpcclient, |
| 6197 | .rpc_message = &msg, |
| 6198 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6199 | .callback_data = &data, |
| 6200 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6201 | }; |
| 6202 | int status; |
| 6203 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6204 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6205 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6206 | dprintk("--> %s\n", __func__); |
| 6207 | task = rpc_run_task(&task_setup); |
| 6208 | |
| 6209 | if (IS_ERR(task)) |
| 6210 | status = PTR_ERR(task); |
| 6211 | else { |
| 6212 | status = task->tk_status; |
| 6213 | rpc_put_task(task); |
| 6214 | } |
| 6215 | dprintk("<-- %s return %d\n", __func__, status); |
| 6216 | |
| 6217 | return status; |
| 6218 | } |
| 6219 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6220 | /* |
| 6221 | * Initialize the values to be used by the client in CREATE_SESSION |
| 6222 | * If nfs4_init_session set the fore channel request and response sizes, |
| 6223 | * use them. |
| 6224 | * |
| 6225 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 6226 | * always set csa_cachethis to FALSE because the current implementation |
| 6227 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 6228 | */ |
| 6229 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 6230 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 6231 | unsigned int max_rqst_sz, max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6232 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 6233 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 6234 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 6235 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6236 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 6237 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 6238 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6239 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 6240 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6241 | |
| 6242 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 6243 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6244 | __func__, |
| 6245 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 6246 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6247 | |
| 6248 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6249 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 6250 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 6251 | args->bc_attrs.max_resp_sz_cached = 0; |
| 6252 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 6253 | args->bc_attrs.max_reqs = 1; |
| 6254 | |
| 6255 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 6256 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 6257 | __func__, |
| 6258 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 6259 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 6260 | args->bc_attrs.max_reqs); |
| 6261 | } |
| 6262 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6263 | 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] | 6264 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6265 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 6266 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 6267 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6268 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 6269 | return -EINVAL; |
| 6270 | /* |
| 6271 | * Our requested max_ops is the minimum we need; we're not |
| 6272 | * prepared to break up compounds into smaller pieces than that. |
| 6273 | * So, no point even trying to continue if the server won't |
| 6274 | * cooperate: |
| 6275 | */ |
| 6276 | if (rcvd->max_ops < sent->max_ops) |
| 6277 | return -EINVAL; |
| 6278 | if (rcvd->max_reqs == 0) |
| 6279 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6280 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 6281 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6282 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6283 | } |
| 6284 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6285 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 6286 | { |
| 6287 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 6288 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6289 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6290 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 6291 | return -EINVAL; |
| 6292 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 6293 | return -EINVAL; |
| 6294 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 6295 | return -EINVAL; |
| 6296 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6297 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6298 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6299 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6300 | return -EINVAL; |
| 6301 | return 0; |
| 6302 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6303 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6304 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 6305 | struct nfs4_session *session) |
| 6306 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6307 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6308 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6309 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 6310 | if (ret) |
| 6311 | return ret; |
| 6312 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6313 | } |
| 6314 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6315 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 6316 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6317 | { |
| 6318 | struct nfs4_session *session = clp->cl_session; |
| 6319 | struct nfs41_create_session_args args = { |
| 6320 | .client = clp, |
| 6321 | .cb_program = NFS4_CALLBACK, |
| 6322 | }; |
| 6323 | struct nfs41_create_session_res res = { |
| 6324 | .client = clp, |
| 6325 | }; |
| 6326 | struct rpc_message msg = { |
| 6327 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 6328 | .rpc_argp = &args, |
| 6329 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6330 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6331 | }; |
| 6332 | int status; |
| 6333 | |
| 6334 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 6335 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6336 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6337 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6338 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6339 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 6340 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6341 | /* Verify the session's negotiated channel_attrs values */ |
| 6342 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6343 | /* Increment the clientid slot sequence id */ |
| 6344 | clp->cl_seqid++; |
| 6345 | } |
| 6346 | |
| 6347 | return status; |
| 6348 | } |
| 6349 | |
| 6350 | /* |
| 6351 | * Issues a CREATE_SESSION operation to the server. |
| 6352 | * It is the responsibility of the caller to verify the session is |
| 6353 | * expired before calling this routine. |
| 6354 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6355 | 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] | 6356 | { |
| 6357 | int status; |
| 6358 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6359 | struct nfs4_session *session = clp->cl_session; |
| 6360 | |
| 6361 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 6362 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6363 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6364 | if (status) |
| 6365 | goto out; |
| 6366 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 6367 | /* Init or reset the session slot tables */ |
| 6368 | status = nfs4_setup_session_slot_tables(session); |
| 6369 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6370 | if (status) |
| 6371 | goto out; |
| 6372 | |
| 6373 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 6374 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 6375 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6376 | out: |
| 6377 | dprintk("<-- %s\n", __func__); |
| 6378 | return status; |
| 6379 | } |
| 6380 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6381 | /* |
| 6382 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 6383 | * The caller must serialize access to this routine. |
| 6384 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6385 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 6386 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6387 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6388 | struct rpc_message msg = { |
| 6389 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 6390 | .rpc_argp = session, |
| 6391 | .rpc_cred = cred, |
| 6392 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6393 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6394 | |
| 6395 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 6396 | |
| 6397 | /* session is still being setup */ |
| 6398 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 6399 | return status; |
| 6400 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6401 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6402 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6403 | |
| 6404 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 6405 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6406 | "Session has been destroyed regardless...\n", status); |
| 6407 | |
| 6408 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 6409 | return status; |
| 6410 | } |
| 6411 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6412 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6413 | * Renew the cl_session lease. |
| 6414 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6415 | struct nfs4_sequence_data { |
| 6416 | struct nfs_client *clp; |
| 6417 | struct nfs4_sequence_args args; |
| 6418 | struct nfs4_sequence_res res; |
| 6419 | }; |
| 6420 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6421 | static void nfs41_sequence_release(void *data) |
| 6422 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6423 | struct nfs4_sequence_data *calldata = data; |
| 6424 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6425 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6426 | if (atomic_read(&clp->cl_count) > 1) |
| 6427 | nfs4_schedule_state_renewal(clp); |
| 6428 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6429 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6430 | } |
| 6431 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6432 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6433 | { |
| 6434 | switch(task->tk_status) { |
| 6435 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6436 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 6437 | return -EAGAIN; |
| 6438 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6439 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6440 | } |
| 6441 | return 0; |
| 6442 | } |
| 6443 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6444 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6445 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6446 | struct nfs4_sequence_data *calldata = data; |
| 6447 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6448 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6449 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 6450 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6451 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6452 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6453 | if (task->tk_status < 0) { |
| 6454 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6455 | if (atomic_read(&clp->cl_count) == 1) |
| 6456 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6457 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6458 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 6459 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6460 | return; |
| 6461 | } |
| 6462 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6463 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6464 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6465 | dprintk("<-- %s\n", __func__); |
| 6466 | } |
| 6467 | |
| 6468 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 6469 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6470 | struct nfs4_sequence_data *calldata = data; |
| 6471 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6472 | struct nfs4_sequence_args *args; |
| 6473 | struct nfs4_sequence_res *res; |
| 6474 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6475 | args = task->tk_msg.rpc_argp; |
| 6476 | res = task->tk_msg.rpc_resp; |
| 6477 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6478 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6479 | } |
| 6480 | |
| 6481 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 6482 | .rpc_call_done = nfs41_sequence_call_done, |
| 6483 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6484 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6485 | }; |
| 6486 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6487 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 6488 | struct rpc_cred *cred, |
| 6489 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6490 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6491 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6492 | struct rpc_message msg = { |
| 6493 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 6494 | .rpc_cred = cred, |
| 6495 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6496 | struct rpc_task_setup task_setup_data = { |
| 6497 | .rpc_client = clp->cl_rpcclient, |
| 6498 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6499 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 6500 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6501 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6502 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6503 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6504 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 6505 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6506 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6507 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6508 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6509 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6510 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6511 | if (is_privileged) |
| 6512 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6513 | msg.rpc_argp = &calldata->args; |
| 6514 | msg.rpc_resp = &calldata->res; |
| 6515 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6516 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6517 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6518 | return rpc_run_task(&task_setup_data); |
| 6519 | } |
| 6520 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6521 | 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] | 6522 | { |
| 6523 | struct rpc_task *task; |
| 6524 | int ret = 0; |
| 6525 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6526 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 6527 | return 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6528 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6529 | if (IS_ERR(task)) |
| 6530 | ret = PTR_ERR(task); |
| 6531 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6532 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6533 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6534 | return ret; |
| 6535 | } |
| 6536 | |
| 6537 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 6538 | { |
| 6539 | struct rpc_task *task; |
| 6540 | int ret; |
| 6541 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6542 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6543 | if (IS_ERR(task)) { |
| 6544 | ret = PTR_ERR(task); |
| 6545 | goto out; |
| 6546 | } |
| 6547 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6548 | if (!ret) { |
| 6549 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 6550 | |
| 6551 | if (task->tk_status == 0) |
| 6552 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6553 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6554 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6555 | rpc_put_task(task); |
| 6556 | out: |
| 6557 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6558 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6559 | } |
| 6560 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6561 | struct nfs4_reclaim_complete_data { |
| 6562 | struct nfs_client *clp; |
| 6563 | struct nfs41_reclaim_complete_args arg; |
| 6564 | struct nfs41_reclaim_complete_res res; |
| 6565 | }; |
| 6566 | |
| 6567 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 6568 | { |
| 6569 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6570 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6571 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 6572 | &calldata->arg.seq_args, |
| 6573 | &calldata->res.seq_res, |
| 6574 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6575 | } |
| 6576 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6577 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6578 | { |
| 6579 | switch(task->tk_status) { |
| 6580 | case 0: |
| 6581 | case -NFS4ERR_COMPLETE_ALREADY: |
| 6582 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 6583 | break; |
| 6584 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6585 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6586 | /* fall through */ |
| 6587 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6588 | return -EAGAIN; |
| 6589 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6590 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6591 | } |
| 6592 | return 0; |
| 6593 | } |
| 6594 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6595 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 6596 | { |
| 6597 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6598 | struct nfs_client *clp = calldata->clp; |
| 6599 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 6600 | |
| 6601 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6602 | if (!nfs41_sequence_done(task, res)) |
| 6603 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6604 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6605 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6606 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 6607 | rpc_restart_call_prepare(task); |
| 6608 | return; |
| 6609 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6610 | dprintk("<-- %s\n", __func__); |
| 6611 | } |
| 6612 | |
| 6613 | static void nfs4_free_reclaim_complete_data(void *data) |
| 6614 | { |
| 6615 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6616 | |
| 6617 | kfree(calldata); |
| 6618 | } |
| 6619 | |
| 6620 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 6621 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 6622 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 6623 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 6624 | }; |
| 6625 | |
| 6626 | /* |
| 6627 | * Issue a global reclaim complete. |
| 6628 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 6629 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 6630 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6631 | { |
| 6632 | struct nfs4_reclaim_complete_data *calldata; |
| 6633 | struct rpc_task *task; |
| 6634 | struct rpc_message msg = { |
| 6635 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 6636 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6637 | }; |
| 6638 | struct rpc_task_setup task_setup_data = { |
| 6639 | .rpc_client = clp->cl_rpcclient, |
| 6640 | .rpc_message = &msg, |
| 6641 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 6642 | .flags = RPC_TASK_ASYNC, |
| 6643 | }; |
| 6644 | int status = -ENOMEM; |
| 6645 | |
| 6646 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6647 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6648 | if (calldata == NULL) |
| 6649 | goto out; |
| 6650 | calldata->clp = clp; |
| 6651 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6652 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6653 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6654 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6655 | msg.rpc_argp = &calldata->arg; |
| 6656 | msg.rpc_resp = &calldata->res; |
| 6657 | task_setup_data.callback_data = calldata; |
| 6658 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6659 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6660 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6661 | goto out; |
| 6662 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6663 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6664 | if (status == 0) |
| 6665 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6666 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6667 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6668 | out: |
| 6669 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6670 | return status; |
| 6671 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6672 | |
| 6673 | static void |
| 6674 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6675 | { |
| 6676 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6677 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6678 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6679 | |
| 6680 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6681 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6682 | * right now covering the LAYOUTGET we are about to send. |
| 6683 | * However, that is not so catastrophic, and there seems |
| 6684 | * to be no way to prevent it completely. |
| 6685 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6686 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6687 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6688 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6689 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6690 | NFS_I(lgp->args.inode)->layout, |
| 6691 | lgp->args.ctx->state)) { |
| 6692 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6693 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6694 | } |
| 6695 | |
| 6696 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6697 | { |
| 6698 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6699 | struct inode *inode = lgp->args.inode; |
| 6700 | struct nfs_server *server = NFS_SERVER(inode); |
| 6701 | struct pnfs_layout_hdr *lo; |
| 6702 | struct nfs4_state *state = NULL; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6703 | unsigned long timeo, giveup; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6704 | |
| 6705 | dprintk("--> %s\n", __func__); |
| 6706 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6707 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6708 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6709 | |
| 6710 | switch (task->tk_status) { |
| 6711 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6712 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6713 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6714 | case -NFS4ERR_RECALLCONFLICT: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6715 | timeo = rpc_get_timeout(task->tk_client); |
| 6716 | giveup = lgp->args.timestamp + timeo; |
| 6717 | if (time_after(giveup, jiffies)) |
| 6718 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6719 | break; |
| 6720 | case -NFS4ERR_EXPIRED: |
| 6721 | case -NFS4ERR_BAD_STATEID: |
| 6722 | spin_lock(&inode->i_lock); |
| 6723 | lo = NFS_I(inode)->layout; |
| 6724 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6725 | spin_unlock(&inode->i_lock); |
| 6726 | /* If the open stateid was bad, then recover it. */ |
| 6727 | state = lgp->args.ctx->state; |
| 6728 | } else { |
| 6729 | LIST_HEAD(head); |
| 6730 | |
| 6731 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6732 | spin_unlock(&inode->i_lock); |
| 6733 | /* Mark the bad layout state as invalid, then |
| 6734 | * retry using the open stateid. */ |
| 6735 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6736 | } |
| 6737 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6738 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6739 | rpc_restart_call_prepare(task); |
| 6740 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6741 | dprintk("<-- %s\n", __func__); |
| 6742 | } |
| 6743 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6744 | static size_t max_response_pages(struct nfs_server *server) |
| 6745 | { |
| 6746 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6747 | return nfs_page_array_len(0, max_resp_sz); |
| 6748 | } |
| 6749 | |
| 6750 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6751 | { |
| 6752 | int i; |
| 6753 | |
| 6754 | if (!pages) |
| 6755 | return; |
| 6756 | |
| 6757 | for (i = 0; i < size; i++) { |
| 6758 | if (!pages[i]) |
| 6759 | break; |
| 6760 | __free_page(pages[i]); |
| 6761 | } |
| 6762 | kfree(pages); |
| 6763 | } |
| 6764 | |
| 6765 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6766 | { |
| 6767 | struct page **pages; |
| 6768 | int i; |
| 6769 | |
| 6770 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6771 | if (!pages) { |
| 6772 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6773 | return NULL; |
| 6774 | } |
| 6775 | |
| 6776 | for (i = 0; i < size; i++) { |
| 6777 | pages[i] = alloc_page(gfp_flags); |
| 6778 | if (!pages[i]) { |
| 6779 | dprintk("%s: failed to allocate page\n", __func__); |
| 6780 | nfs4_free_pages(pages, size); |
| 6781 | return NULL; |
| 6782 | } |
| 6783 | } |
| 6784 | |
| 6785 | return pages; |
| 6786 | } |
| 6787 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6788 | static void nfs4_layoutget_release(void *calldata) |
| 6789 | { |
| 6790 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6791 | struct inode *inode = lgp->args.inode; |
| 6792 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6793 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6794 | |
| 6795 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6796 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6797 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6798 | put_nfs_open_context(lgp->args.ctx); |
| 6799 | kfree(calldata); |
| 6800 | dprintk("<-- %s\n", __func__); |
| 6801 | } |
| 6802 | |
| 6803 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6804 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6805 | .rpc_call_done = nfs4_layoutget_done, |
| 6806 | .rpc_release = nfs4_layoutget_release, |
| 6807 | }; |
| 6808 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6809 | struct pnfs_layout_segment * |
| 6810 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6811 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6812 | struct inode *inode = lgp->args.inode; |
| 6813 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6814 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6815 | struct rpc_task *task; |
| 6816 | struct rpc_message msg = { |
| 6817 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6818 | .rpc_argp = &lgp->args, |
| 6819 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 6820 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6821 | }; |
| 6822 | struct rpc_task_setup task_setup_data = { |
| 6823 | .rpc_client = server->client, |
| 6824 | .rpc_message = &msg, |
| 6825 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6826 | .callback_data = lgp, |
| 6827 | .flags = RPC_TASK_ASYNC, |
| 6828 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6829 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6830 | int status = 0; |
| 6831 | |
| 6832 | dprintk("--> %s\n", __func__); |
| 6833 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6834 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6835 | if (!lgp->args.layout.pages) { |
| 6836 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6837 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6838 | } |
| 6839 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6840 | lgp->args.timestamp = jiffies; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6841 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6842 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6843 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6844 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6845 | |
| 6846 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 6847 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 6848 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6849 | task = rpc_run_task(&task_setup_data); |
| 6850 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6851 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6852 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6853 | if (status == 0) |
| 6854 | status = task->tk_status; |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 6855 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 6856 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6857 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6858 | rpc_put_task(task); |
| 6859 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6860 | if (status) |
| 6861 | return ERR_PTR(status); |
| 6862 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6863 | } |
| 6864 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6865 | static void |
| 6866 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6867 | { |
| 6868 | struct nfs4_layoutreturn *lrp = calldata; |
| 6869 | |
| 6870 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6871 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 6872 | &lrp->args.seq_args, |
| 6873 | &lrp->res.seq_res, |
| 6874 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6875 | } |
| 6876 | |
| 6877 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6878 | { |
| 6879 | struct nfs4_layoutreturn *lrp = calldata; |
| 6880 | struct nfs_server *server; |
| 6881 | |
| 6882 | dprintk("--> %s\n", __func__); |
| 6883 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6884 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6885 | return; |
| 6886 | |
| 6887 | server = NFS_SERVER(lrp->args.inode); |
| 6888 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6889 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6890 | return; |
| 6891 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6892 | dprintk("<-- %s\n", __func__); |
| 6893 | } |
| 6894 | |
| 6895 | static void nfs4_layoutreturn_release(void *calldata) |
| 6896 | { |
| 6897 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6898 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6899 | |
| 6900 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6901 | spin_lock(&lo->plh_inode->i_lock); |
| 6902 | if (lrp->res.lrs_present) |
| 6903 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6904 | lo->plh_block_lgets--; |
| 6905 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6906 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6907 | kfree(calldata); |
| 6908 | dprintk("<-- %s\n", __func__); |
| 6909 | } |
| 6910 | |
| 6911 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6912 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6913 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6914 | .rpc_release = nfs4_layoutreturn_release, |
| 6915 | }; |
| 6916 | |
| 6917 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6918 | { |
| 6919 | struct rpc_task *task; |
| 6920 | struct rpc_message msg = { |
| 6921 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6922 | .rpc_argp = &lrp->args, |
| 6923 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 6924 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6925 | }; |
| 6926 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 6927 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6928 | .rpc_message = &msg, |
| 6929 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6930 | .callback_data = lrp, |
| 6931 | }; |
| 6932 | int status; |
| 6933 | |
| 6934 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6935 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6936 | task = rpc_run_task(&task_setup_data); |
| 6937 | if (IS_ERR(task)) |
| 6938 | return PTR_ERR(task); |
| 6939 | status = task->tk_status; |
| 6940 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6941 | rpc_put_task(task); |
| 6942 | return status; |
| 6943 | } |
| 6944 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6945 | /* |
| 6946 | * Retrieve the list of Data Server devices from the MDS. |
| 6947 | */ |
| 6948 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6949 | const struct nfs_fh *fh, |
| 6950 | struct pnfs_devicelist *devlist) |
| 6951 | { |
| 6952 | struct nfs4_getdevicelist_args args = { |
| 6953 | .fh = fh, |
| 6954 | .layoutclass = server->pnfs_curr_ld->id, |
| 6955 | }; |
| 6956 | struct nfs4_getdevicelist_res res = { |
| 6957 | .devlist = devlist, |
| 6958 | }; |
| 6959 | struct rpc_message msg = { |
| 6960 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6961 | .rpc_argp = &args, |
| 6962 | .rpc_resp = &res, |
| 6963 | }; |
| 6964 | int status; |
| 6965 | |
| 6966 | dprintk("--> %s\n", __func__); |
| 6967 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6968 | &res.seq_res, 0); |
| 6969 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6970 | return status; |
| 6971 | } |
| 6972 | |
| 6973 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6974 | const struct nfs_fh *fh, |
| 6975 | struct pnfs_devicelist *devlist) |
| 6976 | { |
| 6977 | struct nfs4_exception exception = { }; |
| 6978 | int err; |
| 6979 | |
| 6980 | do { |
| 6981 | err = nfs4_handle_exception(server, |
| 6982 | _nfs4_getdevicelist(server, fh, devlist), |
| 6983 | &exception); |
| 6984 | } while (exception.retry); |
| 6985 | |
| 6986 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6987 | err, devlist->num_devs); |
| 6988 | |
| 6989 | return err; |
| 6990 | } |
| 6991 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6992 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6993 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 6994 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 6995 | struct pnfs_device *pdev, |
| 6996 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6997 | { |
| 6998 | struct nfs4_getdeviceinfo_args args = { |
| 6999 | .pdev = pdev, |
| 7000 | }; |
| 7001 | struct nfs4_getdeviceinfo_res res = { |
| 7002 | .pdev = pdev, |
| 7003 | }; |
| 7004 | struct rpc_message msg = { |
| 7005 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 7006 | .rpc_argp = &args, |
| 7007 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7008 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7009 | }; |
| 7010 | int status; |
| 7011 | |
| 7012 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 7013 | 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] | 7014 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7015 | |
| 7016 | return status; |
| 7017 | } |
| 7018 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7019 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 7020 | struct pnfs_device *pdev, |
| 7021 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7022 | { |
| 7023 | struct nfs4_exception exception = { }; |
| 7024 | int err; |
| 7025 | |
| 7026 | do { |
| 7027 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7028 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7029 | &exception); |
| 7030 | } while (exception.retry); |
| 7031 | return err; |
| 7032 | } |
| 7033 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 7034 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7035 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 7036 | { |
| 7037 | struct nfs4_layoutcommit_data *data = calldata; |
| 7038 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7039 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7040 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7041 | nfs41_setup_sequence(session, |
| 7042 | &data->args.seq_args, |
| 7043 | &data->res.seq_res, |
| 7044 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7045 | } |
| 7046 | |
| 7047 | static void |
| 7048 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 7049 | { |
| 7050 | struct nfs4_layoutcommit_data *data = calldata; |
| 7051 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 7052 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7053 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7054 | return; |
| 7055 | |
| 7056 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7057 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 7058 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 7059 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 7060 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7061 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7062 | break; |
| 7063 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7064 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 7065 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7066 | break; |
| 7067 | default: |
| 7068 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 7069 | rpc_restart_call_prepare(task); |
| 7070 | return; |
| 7071 | } |
| 7072 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7073 | } |
| 7074 | |
| 7075 | static void nfs4_layoutcommit_release(void *calldata) |
| 7076 | { |
| 7077 | struct nfs4_layoutcommit_data *data = calldata; |
| 7078 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 7079 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7080 | put_rpccred(data->cred); |
| 7081 | kfree(data); |
| 7082 | } |
| 7083 | |
| 7084 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 7085 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 7086 | .rpc_call_done = nfs4_layoutcommit_done, |
| 7087 | .rpc_release = nfs4_layoutcommit_release, |
| 7088 | }; |
| 7089 | |
| 7090 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 7091 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7092 | { |
| 7093 | struct rpc_message msg = { |
| 7094 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 7095 | .rpc_argp = &data->args, |
| 7096 | .rpc_resp = &data->res, |
| 7097 | .rpc_cred = data->cred, |
| 7098 | }; |
| 7099 | struct rpc_task_setup task_setup_data = { |
| 7100 | .task = &data->task, |
| 7101 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 7102 | .rpc_message = &msg, |
| 7103 | .callback_ops = &nfs4_layoutcommit_ops, |
| 7104 | .callback_data = data, |
| 7105 | .flags = RPC_TASK_ASYNC, |
| 7106 | }; |
| 7107 | struct rpc_task *task; |
| 7108 | int status = 0; |
| 7109 | |
| 7110 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 7111 | "lbw: %llu inode %lu\n", |
| 7112 | data->task.tk_pid, sync, |
| 7113 | data->args.lastbytewritten, |
| 7114 | data->args.inode->i_ino); |
| 7115 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 7116 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7117 | task = rpc_run_task(&task_setup_data); |
| 7118 | if (IS_ERR(task)) |
| 7119 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 7120 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7121 | goto out; |
| 7122 | status = nfs4_wait_for_completion_rpc_task(task); |
| 7123 | if (status != 0) |
| 7124 | goto out; |
| 7125 | status = task->tk_status; |
| 7126 | out: |
| 7127 | dprintk("%s: status %d\n", __func__, status); |
| 7128 | rpc_put_task(task); |
| 7129 | return status; |
| 7130 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7131 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 7132 | /** |
| 7133 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 7134 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 7135 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7136 | static int |
| 7137 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 7138 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 7139 | { |
| 7140 | struct nfs41_secinfo_no_name_args args = { |
| 7141 | .style = SECINFO_STYLE_CURRENT_FH, |
| 7142 | }; |
| 7143 | struct nfs4_secinfo_res res = { |
| 7144 | .flavors = flavors, |
| 7145 | }; |
| 7146 | struct rpc_message msg = { |
| 7147 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 7148 | .rpc_argp = &args, |
| 7149 | .rpc_resp = &res, |
| 7150 | }; |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 7151 | return nfs4_call_sync(server->nfs_client->cl_rpcclient, server, &msg, |
| 7152 | &args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7153 | } |
| 7154 | |
| 7155 | static int |
| 7156 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 7157 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 7158 | { |
| 7159 | struct nfs4_exception exception = { }; |
| 7160 | int err; |
| 7161 | do { |
| 7162 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 7163 | switch (err) { |
| 7164 | case 0: |
| 7165 | case -NFS4ERR_WRONGSEC: |
| 7166 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 7167 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7168 | default: |
| 7169 | err = nfs4_handle_exception(server, err, &exception); |
| 7170 | } |
| 7171 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 7172 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7173 | return err; |
| 7174 | } |
| 7175 | |
| 7176 | static int |
| 7177 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 7178 | struct nfs_fsinfo *info) |
| 7179 | { |
| 7180 | int err; |
| 7181 | struct page *page; |
| 7182 | rpc_authflavor_t flavor; |
| 7183 | struct nfs4_secinfo_flavors *flavors; |
| 7184 | |
| 7185 | page = alloc_page(GFP_KERNEL); |
| 7186 | if (!page) { |
| 7187 | err = -ENOMEM; |
| 7188 | goto out; |
| 7189 | } |
| 7190 | |
| 7191 | flavors = page_address(page); |
| 7192 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 7193 | |
| 7194 | /* |
| 7195 | * Fall back on "guess and check" method if |
| 7196 | * the server doesn't support SECINFO_NO_NAME |
| 7197 | */ |
| 7198 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 7199 | err = nfs4_find_root_sec(server, fhandle, info); |
| 7200 | goto out_freepage; |
| 7201 | } |
| 7202 | if (err) |
| 7203 | goto out_freepage; |
| 7204 | |
| 7205 | flavor = nfs_find_best_sec(flavors); |
| 7206 | if (err == 0) |
| 7207 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 7208 | |
| 7209 | out_freepage: |
| 7210 | put_page(page); |
| 7211 | if (err == -EACCES) |
| 7212 | return -EPERM; |
| 7213 | out: |
| 7214 | return err; |
| 7215 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7216 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7217 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 7218 | nfs4_stateid *stateid, |
| 7219 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7220 | { |
| 7221 | int status; |
| 7222 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7223 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7224 | }; |
| 7225 | struct nfs41_test_stateid_res res; |
| 7226 | struct rpc_message msg = { |
| 7227 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 7228 | .rpc_argp = &args, |
| 7229 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7230 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7231 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7232 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7233 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 7234 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7235 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7236 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
| 7237 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7238 | if (status != NFS_OK) { |
| 7239 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7240 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7241 | } |
| 7242 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7243 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7244 | } |
| 7245 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7246 | /** |
| 7247 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 7248 | * |
| 7249 | * @server: server / transport on which to perform the operation |
| 7250 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7251 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7252 | * |
| 7253 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 7254 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 7255 | * failed or the state ID is not currently valid. |
| 7256 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7257 | static int nfs41_test_stateid(struct nfs_server *server, |
| 7258 | nfs4_stateid *stateid, |
| 7259 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7260 | { |
| 7261 | struct nfs4_exception exception = { }; |
| 7262 | int err; |
| 7263 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7264 | err = _nfs41_test_stateid(server, stateid, cred); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7265 | if (err != -NFS4ERR_DELAY) |
| 7266 | break; |
| 7267 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7268 | } while (exception.retry); |
| 7269 | return err; |
| 7270 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7271 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7272 | struct nfs_free_stateid_data { |
| 7273 | struct nfs_server *server; |
| 7274 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7275 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7276 | }; |
| 7277 | |
| 7278 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 7279 | { |
| 7280 | struct nfs_free_stateid_data *data = calldata; |
| 7281 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 7282 | &data->args.seq_args, |
| 7283 | &data->res.seq_res, |
| 7284 | task); |
| 7285 | } |
| 7286 | |
| 7287 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 7288 | { |
| 7289 | struct nfs_free_stateid_data *data = calldata; |
| 7290 | |
| 7291 | nfs41_sequence_done(task, &data->res.seq_res); |
| 7292 | |
| 7293 | switch (task->tk_status) { |
| 7294 | case -NFS4ERR_DELAY: |
| 7295 | if (nfs4_async_handle_error(task, data->server, NULL) == -EAGAIN) |
| 7296 | rpc_restart_call_prepare(task); |
| 7297 | } |
| 7298 | } |
| 7299 | |
| 7300 | static void nfs41_free_stateid_release(void *calldata) |
| 7301 | { |
| 7302 | kfree(calldata); |
| 7303 | } |
| 7304 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 7305 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7306 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 7307 | .rpc_call_done = nfs41_free_stateid_done, |
| 7308 | .rpc_release = nfs41_free_stateid_release, |
| 7309 | }; |
| 7310 | |
| 7311 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
| 7312 | nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7313 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7314 | bool privileged) |
| 7315 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7316 | struct rpc_message msg = { |
| 7317 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7318 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7319 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7320 | struct rpc_task_setup task_setup = { |
| 7321 | .rpc_client = server->client, |
| 7322 | .rpc_message = &msg, |
| 7323 | .callback_ops = &nfs41_free_stateid_ops, |
| 7324 | .flags = RPC_TASK_ASYNC, |
| 7325 | }; |
| 7326 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7327 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7328 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7329 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 7330 | if (!data) |
| 7331 | return ERR_PTR(-ENOMEM); |
| 7332 | data->server = server; |
| 7333 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 7334 | |
| 7335 | task_setup.callback_data = data; |
| 7336 | |
| 7337 | msg.rpc_argp = &data->args; |
| 7338 | msg.rpc_resp = &data->res; |
| 7339 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
| 7340 | if (privileged) |
| 7341 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 7342 | |
| 7343 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7344 | } |
| 7345 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7346 | /** |
| 7347 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 7348 | * |
| 7349 | * @server: server / transport on which to perform the operation |
| 7350 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7351 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7352 | * |
| 7353 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 7354 | * negative NFS4ERR value is returned. |
| 7355 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7356 | static int nfs41_free_stateid(struct nfs_server *server, |
| 7357 | nfs4_stateid *stateid, |
| 7358 | struct rpc_cred *cred) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7359 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7360 | struct rpc_task *task; |
| 7361 | int ret; |
| 7362 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7363 | task = _nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7364 | if (IS_ERR(task)) |
| 7365 | return PTR_ERR(task); |
| 7366 | ret = rpc_wait_for_completion_task(task); |
| 7367 | if (!ret) |
| 7368 | ret = task->tk_status; |
| 7369 | rpc_put_task(task); |
| 7370 | return ret; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7371 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7372 | |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7373 | static int nfs41_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp) |
| 7374 | { |
| 7375 | struct rpc_task *task; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7376 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7377 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7378 | task = _nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7379 | nfs4_free_lock_state(server, lsp); |
| 7380 | if (IS_ERR(task)) |
| 7381 | return PTR_ERR(task); |
| 7382 | rpc_put_task(task); |
| 7383 | return 0; |
| 7384 | } |
| 7385 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7386 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 7387 | const nfs4_stateid *s2) |
| 7388 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7389 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7390 | return false; |
| 7391 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7392 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7393 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7394 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7395 | return true; |
| 7396 | |
| 7397 | return false; |
| 7398 | } |
| 7399 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7400 | #endif /* CONFIG_NFS_V4_1 */ |
| 7401 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7402 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 7403 | const nfs4_stateid *s2) |
| 7404 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7405 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7406 | } |
| 7407 | |
| 7408 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7409 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7410 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7411 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7412 | .recover_open = nfs4_open_reclaim, |
| 7413 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7414 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7415 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7416 | }; |
| 7417 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7418 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7419 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7420 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 7421 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 7422 | .recover_open = nfs4_open_reclaim, |
| 7423 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7424 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7425 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7426 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7427 | }; |
| 7428 | #endif /* CONFIG_NFS_V4_1 */ |
| 7429 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7430 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7431 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7432 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7433 | .recover_open = nfs4_open_expired, |
| 7434 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7435 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7436 | }; |
| 7437 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7438 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7439 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7440 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 7441 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7442 | .recover_open = nfs41_open_expired, |
| 7443 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7444 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7445 | }; |
| 7446 | #endif /* CONFIG_NFS_V4_1 */ |
| 7447 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7448 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7449 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7450 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7451 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7452 | }; |
| 7453 | |
| 7454 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7455 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7456 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7457 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7458 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7459 | }; |
| 7460 | #endif |
| 7461 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7462 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 7463 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 7464 | .init_caps = NFS_CAP_READDIRPLUS |
| 7465 | | NFS_CAP_ATOMIC_OPEN |
| 7466 | | NFS_CAP_CHANGE_ATTR |
| 7467 | | NFS_CAP_POSIX_LOCK, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7468 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7469 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7470 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7471 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7472 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 7473 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 7474 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7475 | }; |
| 7476 | |
| 7477 | #if defined(CONFIG_NFS_V4_1) |
| 7478 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 7479 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 7480 | .init_caps = NFS_CAP_READDIRPLUS |
| 7481 | | NFS_CAP_ATOMIC_OPEN |
| 7482 | | NFS_CAP_CHANGE_ATTR |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 7483 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 7484 | | NFS_CAP_STATEID_NFSV41 |
| 7485 | | NFS_CAP_ATOMIC_OPEN_V1, |
Bryan Schumaker | 104287c | 2012-11-12 14:13:13 -0500 | [diff] [blame] | 7486 | .call_sync = nfs4_call_sync_sequence, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7487 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7488 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7489 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7490 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 7491 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 7492 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7493 | }; |
| 7494 | #endif |
| 7495 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7496 | #if defined(CONFIG_NFS_V4_2) |
| 7497 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 7498 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 7499 | .init_caps = NFS_CAP_READDIRPLUS |
| 7500 | | NFS_CAP_ATOMIC_OPEN |
| 7501 | | NFS_CAP_CHANGE_ATTR |
| 7502 | | NFS_CAP_POSIX_LOCK |
| 7503 | | NFS_CAP_STATEID_NFSV41 |
| 7504 | | NFS_CAP_ATOMIC_OPEN_V1, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7505 | .call_sync = nfs4_call_sync_sequence, |
| 7506 | .match_stateid = nfs41_match_stateid, |
| 7507 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 7508 | .free_lock_state = nfs41_free_lock_state, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7509 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 7510 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 7511 | .state_renewal_ops = &nfs41_state_renewal_ops, |
| 7512 | }; |
| 7513 | #endif |
| 7514 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7515 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 7516 | [0] = &nfs_v4_0_minor_ops, |
| 7517 | #if defined(CONFIG_NFS_V4_1) |
| 7518 | [1] = &nfs_v4_1_minor_ops, |
| 7519 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7520 | #if defined(CONFIG_NFS_V4_2) |
| 7521 | [2] = &nfs_v4_2_minor_ops, |
| 7522 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7523 | }; |
| 7524 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 7525 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 7526 | .create = nfs_create, |
| 7527 | .lookup = nfs_lookup, |
| 7528 | .atomic_open = nfs_atomic_open, |
| 7529 | .link = nfs_link, |
| 7530 | .unlink = nfs_unlink, |
| 7531 | .symlink = nfs_symlink, |
| 7532 | .mkdir = nfs_mkdir, |
| 7533 | .rmdir = nfs_rmdir, |
| 7534 | .mknod = nfs_mknod, |
| 7535 | .rename = nfs_rename, |
| 7536 | .permission = nfs_permission, |
| 7537 | .getattr = nfs_getattr, |
| 7538 | .setattr = nfs_setattr, |
| 7539 | .getxattr = generic_getxattr, |
| 7540 | .setxattr = generic_setxattr, |
| 7541 | .listxattr = generic_listxattr, |
| 7542 | .removexattr = generic_removexattr, |
| 7543 | }; |
| 7544 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 7545 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7546 | .permission = nfs_permission, |
| 7547 | .getattr = nfs_getattr, |
| 7548 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7549 | .getxattr = generic_getxattr, |
| 7550 | .setxattr = generic_setxattr, |
| 7551 | .listxattr = generic_listxattr, |
| 7552 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7553 | }; |
| 7554 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 7555 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7556 | .version = 4, /* protocol version */ |
| 7557 | .dentry_ops = &nfs4_dentry_operations, |
| 7558 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7559 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 7560 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7561 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 7562 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 7563 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7564 | .getattr = nfs4_proc_getattr, |
| 7565 | .setattr = nfs4_proc_setattr, |
| 7566 | .lookup = nfs4_proc_lookup, |
| 7567 | .access = nfs4_proc_access, |
| 7568 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7569 | .create = nfs4_proc_create, |
| 7570 | .remove = nfs4_proc_remove, |
| 7571 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 7572 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7573 | .unlink_done = nfs4_proc_unlink_done, |
| 7574 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7575 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 7576 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7577 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7578 | .link = nfs4_proc_link, |
| 7579 | .symlink = nfs4_proc_symlink, |
| 7580 | .mkdir = nfs4_proc_mkdir, |
| 7581 | .rmdir = nfs4_proc_remove, |
| 7582 | .readdir = nfs4_proc_readdir, |
| 7583 | .mknod = nfs4_proc_mknod, |
| 7584 | .statfs = nfs4_proc_statfs, |
| 7585 | .fsinfo = nfs4_proc_fsinfo, |
| 7586 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 7587 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7588 | .decode_dirent = nfs4_decode_dirent, |
| 7589 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 7590 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 7591 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7592 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7593 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 7594 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 7595 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7596 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7597 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 7598 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7599 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7600 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 7601 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 7602 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 7603 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 7604 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 7605 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 7606 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 7607 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 7608 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 7609 | .create_server = nfs4_create_server, |
| 7610 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7611 | }; |
| 7612 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7613 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 7614 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 7615 | .list = nfs4_xattr_list_nfs4_acl, |
| 7616 | .get = nfs4_xattr_get_nfs4_acl, |
| 7617 | .set = nfs4_xattr_set_nfs4_acl, |
| 7618 | }; |
| 7619 | |
| 7620 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 7621 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7622 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 7623 | &nfs4_xattr_nfs4_label_handler, |
| 7624 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7625 | NULL |
| 7626 | }; |
| 7627 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7628 | /* |
| 7629 | * Local variables: |
| 7630 | * c-basic-offset: 8 |
| 7631 | * End: |
| 7632 | */ |