Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
| 46 | #include <linux/nfs.h> |
| 47 | #include <linux/nfs4.h> |
| 48 | #include <linux/nfs_fs.h> |
| 49 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 50 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 52 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 53 | #include <linux/module.h> |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 54 | #include <linux/nfs_idmap.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 55 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 56 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 57 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 59 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 61 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 62 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 63 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 64 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 65 | #include "netns.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 66 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 67 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame^] | 69 | #include "nfs4trace.h" |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 72 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 73 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 75 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 76 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 77 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 78 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 80 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 81 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 82 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label); |
| 83 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 84 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 85 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 86 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 87 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 88 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 89 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 90 | struct rpc_cred *); |
| 91 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *, |
| 92 | struct rpc_cred *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 93 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 94 | |
| 95 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 96 | static inline struct nfs4_label * |
| 97 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 98 | struct iattr *sattr, struct nfs4_label *label) |
| 99 | { |
| 100 | int err; |
| 101 | |
| 102 | if (label == NULL) |
| 103 | return NULL; |
| 104 | |
| 105 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 106 | return NULL; |
| 107 | |
| 108 | if (NFS_SERVER(dir)->nfs_client->cl_minorversion < 2) |
| 109 | return NULL; |
| 110 | |
| 111 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 112 | &dentry->d_name, (void **)&label->label, &label->len); |
| 113 | if (err == 0) |
| 114 | return label; |
| 115 | |
| 116 | return NULL; |
| 117 | } |
| 118 | static inline void |
| 119 | nfs4_label_release_security(struct nfs4_label *label) |
| 120 | { |
| 121 | if (label) |
| 122 | security_release_secctx(label->label, label->len); |
| 123 | } |
| 124 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 125 | { |
| 126 | if (label) |
| 127 | return server->attr_bitmask; |
| 128 | |
| 129 | return server->attr_bitmask_nl; |
| 130 | } |
| 131 | #else |
| 132 | static inline struct nfs4_label * |
| 133 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 134 | struct iattr *sattr, struct nfs4_label *l) |
| 135 | { return NULL; } |
| 136 | static inline void |
| 137 | nfs4_label_release_security(struct nfs4_label *label) |
| 138 | { return; } |
| 139 | static inline u32 * |
| 140 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 141 | { return server->attr_bitmask; } |
| 142 | #endif |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 145 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 147 | if (err >= -1000) |
| 148 | return err; |
| 149 | switch (err) { |
| 150 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 151 | case -NFS4ERR_LAYOUTTRYLATER: |
| 152 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 153 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 154 | case -NFS4ERR_WRONGSEC: |
| 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 | 6926afd | 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 | 6926afd | 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 | 6926afd | 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 | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1445 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1446 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1447 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1448 | break; |
| 1449 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | } while (exception.retry); |
| 1451 | return err; |
| 1452 | } |
| 1453 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1454 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1455 | { |
| 1456 | struct nfs_open_context *ctx; |
| 1457 | int ret; |
| 1458 | |
| 1459 | ctx = nfs4_state_find_open_context(state); |
| 1460 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1461 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1462 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1463 | put_nfs_open_context(ctx); |
| 1464 | return ret; |
| 1465 | } |
| 1466 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1467 | 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] | 1468 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1469 | switch (err) { |
| 1470 | default: |
| 1471 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1472 | "%d.\n", __func__, err); |
| 1473 | case 0: |
| 1474 | case -ENOENT: |
| 1475 | case -ESTALE: |
| 1476 | break; |
| 1477 | case -NFS4ERR_BADSESSION: |
| 1478 | case -NFS4ERR_BADSLOT: |
| 1479 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1480 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1481 | case -NFS4ERR_DEADSESSION: |
| 1482 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1483 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1484 | return -EAGAIN; |
| 1485 | case -NFS4ERR_STALE_CLIENTID: |
| 1486 | case -NFS4ERR_STALE_STATEID: |
| 1487 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1488 | case -NFS4ERR_EXPIRED: |
| 1489 | /* Don't recall a delegation if it was lost */ |
| 1490 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1491 | return -EAGAIN; |
| 1492 | case -NFS4ERR_DELEG_REVOKED: |
| 1493 | case -NFS4ERR_ADMIN_REVOKED: |
| 1494 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1495 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1496 | nfs_inode_find_state_and_recover(state->inode, |
| 1497 | stateid); |
| 1498 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1499 | return 0; |
| 1500 | case -NFS4ERR_DELAY: |
| 1501 | case -NFS4ERR_GRACE: |
| 1502 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1503 | ssleep(1); |
| 1504 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1505 | case -ENOMEM: |
| 1506 | case -NFS4ERR_DENIED: |
| 1507 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1508 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1509 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | return err; |
| 1511 | } |
| 1512 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1513 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
| 1514 | { |
| 1515 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1516 | struct nfs4_opendata *opendata; |
| 1517 | int err; |
| 1518 | |
| 1519 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1520 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1521 | if (IS_ERR(opendata)) |
| 1522 | return PTR_ERR(opendata); |
| 1523 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
| 1524 | err = nfs4_open_recover(opendata, state); |
| 1525 | nfs4_opendata_put(opendata); |
| 1526 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1527 | } |
| 1528 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1529 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1530 | { |
| 1531 | struct nfs4_opendata *data = calldata; |
| 1532 | |
| 1533 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1534 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1535 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1536 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1537 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1538 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1539 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | static void nfs4_open_confirm_release(void *calldata) |
| 1543 | { |
| 1544 | struct nfs4_opendata *data = calldata; |
| 1545 | struct nfs4_state *state = NULL; |
| 1546 | |
| 1547 | /* If this request hasn't been cancelled, do nothing */ |
| 1548 | if (data->cancelled == 0) |
| 1549 | goto out_free; |
| 1550 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1551 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1552 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1553 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1554 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1555 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1556 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1557 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1561 | .rpc_call_done = nfs4_open_confirm_done, |
| 1562 | .rpc_release = nfs4_open_confirm_release, |
| 1563 | }; |
| 1564 | |
| 1565 | /* |
| 1566 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1567 | */ |
| 1568 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1569 | { |
| 1570 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1571 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1572 | struct rpc_message msg = { |
| 1573 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1574 | .rpc_argp = &data->c_arg, |
| 1575 | .rpc_resp = &data->c_res, |
| 1576 | .rpc_cred = data->owner->so_cred, |
| 1577 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1578 | struct rpc_task_setup task_setup_data = { |
| 1579 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1580 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1581 | .callback_ops = &nfs4_open_confirm_ops, |
| 1582 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1583 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1584 | .flags = RPC_TASK_ASYNC, |
| 1585 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | int status; |
| 1587 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1588 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1589 | data->rpc_done = 0; |
| 1590 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1591 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1592 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1593 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1594 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1595 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1596 | if (status != 0) { |
| 1597 | data->cancelled = 1; |
| 1598 | smp_wmb(); |
| 1599 | } else |
| 1600 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1601 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | return status; |
| 1603 | } |
| 1604 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1605 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1607 | struct nfs4_opendata *data = calldata; |
| 1608 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1609 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1610 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1611 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1612 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1613 | /* |
| 1614 | * Check if we still need to send an OPEN call, or if we can use |
| 1615 | * a delegation instead. |
| 1616 | */ |
| 1617 | if (data->state != NULL) { |
| 1618 | struct nfs_delegation *delegation; |
| 1619 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1620 | 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] | 1621 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1622 | rcu_read_lock(); |
| 1623 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1624 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
Trond Myklebust | cd4c9be | 2013-04-23 14:46:25 -0400 | [diff] [blame] | 1625 | data->o_arg.claim != NFS4_OPEN_CLAIM_DELEG_CUR_FH && |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1626 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1627 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1628 | rcu_read_unlock(); |
| 1629 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1630 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1631 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1632 | switch (data->o_arg.claim) { |
| 1633 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1634 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1635 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1636 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1637 | case NFS4_OPEN_CLAIM_FH: |
| 1638 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1639 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1640 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1641 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1642 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1643 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1644 | &data->o_res.seq_res, |
| 1645 | task) != 0) |
| 1646 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1647 | |
| 1648 | /* Set the create mode (note dependency on the session type) */ |
| 1649 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 1650 | if (data->o_arg.open_flags & O_EXCL) { |
| 1651 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 1652 | if (nfs4_has_persistent_session(clp)) |
| 1653 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 1654 | else if (clp->cl_mvops->minor_version > 0) |
| 1655 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 1656 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1657 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1658 | unlock_no_action: |
| 1659 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1660 | out_no_action: |
| 1661 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1662 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1663 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1664 | } |
| 1665 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1666 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1667 | { |
| 1668 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1670 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1671 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1672 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1673 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1674 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1675 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1676 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1677 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1678 | case S_IFREG: |
| 1679 | break; |
| 1680 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1681 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1682 | break; |
| 1683 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1684 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1685 | break; |
| 1686 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1687 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1688 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1689 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1690 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1691 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1692 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1693 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1694 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1695 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1696 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1697 | static void nfs4_open_release(void *calldata) |
| 1698 | { |
| 1699 | struct nfs4_opendata *data = calldata; |
| 1700 | struct nfs4_state *state = NULL; |
| 1701 | |
| 1702 | /* If this request hasn't been cancelled, do nothing */ |
| 1703 | if (data->cancelled == 0) |
| 1704 | goto out_free; |
| 1705 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1706 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1707 | goto out_free; |
| 1708 | /* In case we need an open_confirm, no cleanup! */ |
| 1709 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1710 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1711 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1712 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1713 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1714 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1715 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1716 | } |
| 1717 | |
| 1718 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1719 | .rpc_call_prepare = nfs4_open_prepare, |
| 1720 | .rpc_call_done = nfs4_open_done, |
| 1721 | .rpc_release = nfs4_open_release, |
| 1722 | }; |
| 1723 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1724 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1725 | { |
| 1726 | struct inode *dir = data->dir->d_inode; |
| 1727 | struct nfs_server *server = NFS_SERVER(dir); |
| 1728 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1729 | struct nfs_openres *o_res = &data->o_res; |
| 1730 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1731 | struct rpc_message msg = { |
| 1732 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1733 | .rpc_argp = o_arg, |
| 1734 | .rpc_resp = o_res, |
| 1735 | .rpc_cred = data->owner->so_cred, |
| 1736 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1737 | struct rpc_task_setup task_setup_data = { |
| 1738 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1739 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1740 | .callback_ops = &nfs4_open_ops, |
| 1741 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1742 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1743 | .flags = RPC_TASK_ASYNC, |
| 1744 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1745 | int status; |
| 1746 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1747 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1748 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1749 | data->rpc_done = 0; |
| 1750 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1751 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1752 | data->is_recover = 0; |
| 1753 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1754 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1755 | data->is_recover = 1; |
| 1756 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1757 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1758 | if (IS_ERR(task)) |
| 1759 | return PTR_ERR(task); |
| 1760 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1761 | if (status != 0) { |
| 1762 | data->cancelled = 1; |
| 1763 | smp_wmb(); |
| 1764 | } else |
| 1765 | status = data->rpc_status; |
| 1766 | rpc_put_task(task); |
| 1767 | |
| 1768 | return status; |
| 1769 | } |
| 1770 | |
| 1771 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1772 | { |
| 1773 | struct inode *dir = data->dir->d_inode; |
| 1774 | struct nfs_openres *o_res = &data->o_res; |
| 1775 | int status; |
| 1776 | |
| 1777 | status = nfs4_run_open_task(data, 1); |
| 1778 | if (status != 0 || !data->rpc_done) |
| 1779 | return status; |
| 1780 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1781 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1782 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1783 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1784 | status = _nfs4_proc_open_confirm(data); |
| 1785 | if (status != 0) |
| 1786 | return status; |
| 1787 | } |
| 1788 | |
| 1789 | return status; |
| 1790 | } |
| 1791 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1792 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1793 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1794 | struct nfs4_state *state, fmode_t fmode, |
| 1795 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1796 | { |
| 1797 | struct nfs_access_entry cache; |
| 1798 | u32 mask; |
| 1799 | |
| 1800 | /* access call failed or for some reason the server doesn't |
| 1801 | * support any access modes -- defer access call until later */ |
| 1802 | if (opendata->o_res.access_supported == 0) |
| 1803 | return 0; |
| 1804 | |
| 1805 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1806 | /* 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] | 1807 | * write mode bits, but POSIX allows the creating process to write. |
| 1808 | * use openflags to check for exec, because fmode won't |
| 1809 | * always have FMODE_EXEC set when file open for exec. */ |
| 1810 | if (openflags & __FMODE_EXEC) { |
| 1811 | /* ONLY check for exec rights */ |
| 1812 | mask = MAY_EXEC; |
| 1813 | } else if (fmode & FMODE_READ) |
| 1814 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1815 | |
| 1816 | cache.cred = cred; |
| 1817 | cache.jiffies = jiffies; |
| 1818 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1819 | nfs_access_add_cache(state->inode, &cache); |
| 1820 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1821 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1822 | return 0; |
| 1823 | |
| 1824 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1825 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1826 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1827 | } |
| 1828 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1829 | /* |
| 1830 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1831 | */ |
| 1832 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1833 | { |
| 1834 | struct inode *dir = data->dir->d_inode; |
| 1835 | struct nfs_server *server = NFS_SERVER(dir); |
| 1836 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1837 | struct nfs_openres *o_res = &data->o_res; |
| 1838 | int status; |
| 1839 | |
| 1840 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1841 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1842 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1843 | if (status != 0) { |
| 1844 | if (status == -NFS4ERR_BADNAME && |
| 1845 | !(o_arg->open_flags & O_CREAT)) |
| 1846 | return -ENOENT; |
| 1847 | return status; |
| 1848 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1849 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1850 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1851 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1852 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1853 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1854 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1855 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1857 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1859 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | } |
| 1861 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1862 | _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] | 1863 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | } |
| 1865 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1866 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1867 | { |
| 1868 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1869 | } |
| 1870 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1871 | /* |
| 1872 | * OPEN_EXPIRED: |
| 1873 | * reclaim state on the server after a network partition. |
| 1874 | * Assumes caller holds the appropriate lock |
| 1875 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1876 | 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] | 1877 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1878 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1879 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1881 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1882 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1883 | if (IS_ERR(opendata)) |
| 1884 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1885 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1886 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1887 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1888 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1889 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | } |
| 1891 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1892 | 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] | 1893 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1894 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1895 | struct nfs4_exception exception = { }; |
| 1896 | int err; |
| 1897 | |
| 1898 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1899 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1900 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1901 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1902 | switch (err) { |
| 1903 | default: |
| 1904 | goto out; |
| 1905 | case -NFS4ERR_GRACE: |
| 1906 | case -NFS4ERR_DELAY: |
| 1907 | nfs4_handle_exception(server, err, &exception); |
| 1908 | err = 0; |
| 1909 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1910 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1911 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1912 | return err; |
| 1913 | } |
| 1914 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1916 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1918 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1920 | ctx = nfs4_state_find_open_context(state); |
| 1921 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1922 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1923 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1924 | put_nfs_open_context(ctx); |
| 1925 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | } |
| 1927 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1928 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1929 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1930 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1931 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1932 | nfs4_stateid *stateid = &state->stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1933 | struct nfs_delegation *delegation; |
| 1934 | struct rpc_cred *cred = NULL; |
| 1935 | int status = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1936 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1937 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1938 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1939 | return; |
| 1940 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1941 | /* Get the delegation credential for use by test/free_stateid */ |
| 1942 | rcu_read_lock(); |
| 1943 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1944 | if (delegation != NULL && |
| 1945 | nfs4_stateid_match(&delegation->stateid, stateid)) { |
| 1946 | cred = get_rpccred(delegation->cred); |
| 1947 | rcu_read_unlock(); |
| 1948 | status = nfs41_test_stateid(server, stateid, cred); |
| 1949 | } else |
| 1950 | rcu_read_unlock(); |
| 1951 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1952 | if (status != NFS_OK) { |
| 1953 | /* Free the stateid unless the server explicitly |
| 1954 | * informs us the stateid is unrecognized. */ |
| 1955 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1956 | nfs41_free_stateid(server, stateid, cred); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1957 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1958 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1959 | write_seqlock(&state->seqlock); |
| 1960 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1961 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1962 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1963 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1964 | |
| 1965 | if (cred != NULL) |
| 1966 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | /** |
| 1970 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1971 | * |
| 1972 | * @state: NFSv4 state for an inode |
| 1973 | * |
| 1974 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1975 | * Otherwise a negative NFS4ERR value is returned. |
| 1976 | */ |
| 1977 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1978 | { |
| 1979 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1980 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1981 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1982 | int status; |
| 1983 | |
| 1984 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1985 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1986 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1987 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1988 | return -NFS4ERR_BAD_STATEID; |
| 1989 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1990 | status = nfs41_test_stateid(server, stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1991 | if (status != NFS_OK) { |
| 1992 | /* Free the stateid unless the server explicitly |
| 1993 | * informs us the stateid is unrecognized. */ |
| 1994 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1995 | nfs41_free_stateid(server, stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1996 | |
| 1997 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1998 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1999 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2000 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2001 | } |
| 2002 | return status; |
| 2003 | } |
| 2004 | |
| 2005 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2006 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2007 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2008 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2009 | nfs41_clear_delegation_stateid(state); |
| 2010 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2011 | if (status != NFS_OK) |
| 2012 | status = nfs4_open_expired(sp, state); |
| 2013 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2014 | } |
| 2015 | #endif |
| 2016 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2018 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2019 | * fields corresponding to attributes that were used to store the verifier. |
| 2020 | * Make sure we clobber those fields in the later setattr call |
| 2021 | */ |
| 2022 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 2023 | { |
| 2024 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 2025 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2026 | sattr->ia_valid |= ATTR_ATIME; |
| 2027 | |
| 2028 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 2029 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2030 | sattr->ia_valid |= ATTR_MTIME; |
| 2031 | } |
| 2032 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2033 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2034 | fmode_t fmode, |
| 2035 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2036 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2037 | { |
| 2038 | struct nfs4_state_owner *sp = opendata->owner; |
| 2039 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2040 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2041 | struct nfs4_state *state; |
| 2042 | unsigned int seq; |
| 2043 | int ret; |
| 2044 | |
| 2045 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2046 | |
| 2047 | ret = _nfs4_proc_open(opendata); |
| 2048 | if (ret != 0) |
| 2049 | goto out; |
| 2050 | |
| 2051 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2052 | ret = PTR_ERR(state); |
| 2053 | if (IS_ERR(state)) |
| 2054 | goto out; |
| 2055 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2056 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 2057 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2058 | dentry = opendata->dentry; |
| 2059 | if (dentry->d_inode == NULL) { |
| 2060 | /* FIXME: Is this d_drop() ever needed? */ |
| 2061 | d_drop(dentry); |
| 2062 | dentry = d_add_unique(dentry, igrab(state->inode)); |
| 2063 | if (dentry == NULL) { |
| 2064 | dentry = opendata->dentry; |
| 2065 | } else if (dentry != ctx->dentry) { |
| 2066 | dput(ctx->dentry); |
| 2067 | ctx->dentry = dget(dentry); |
| 2068 | } |
| 2069 | nfs_set_verifier(dentry, |
| 2070 | nfs_save_change_attribute(opendata->dir->d_inode)); |
| 2071 | } |
| 2072 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2073 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2074 | if (ret != 0) |
| 2075 | goto out; |
| 2076 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2077 | ctx->state = state; |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2078 | if (dentry->d_inode == state->inode) { |
| 2079 | nfs_inode_attach_open_context(ctx); |
| 2080 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2081 | nfs4_schedule_stateid_recovery(server, state); |
| 2082 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2083 | out: |
| 2084 | return ret; |
| 2085 | } |
| 2086 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2087 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2088 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2090 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2091 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2092 | int flags, |
| 2093 | struct iattr *sattr, |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2094 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | { |
| 2096 | struct nfs4_state_owner *sp; |
| 2097 | struct nfs4_state *state = NULL; |
| 2098 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2099 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2100 | struct dentry *dentry = ctx->dentry; |
| 2101 | struct rpc_cred *cred = ctx->cred; |
| 2102 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2103 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2104 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2105 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2106 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | |
| 2108 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2110 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2111 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2113 | goto out_err; |
| 2114 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2115 | status = nfs4_recover_expired_lease(server); |
| 2116 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2117 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2118 | if (dentry->d_inode != NULL) |
| 2119 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2120 | status = -ENOMEM; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2121 | if (dentry->d_inode) |
| 2122 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2123 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2124 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2125 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2126 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2128 | if (label) { |
| 2129 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2130 | if (IS_ERR(olabel)) { |
| 2131 | status = PTR_ERR(olabel); |
| 2132 | goto err_opendata_put; |
| 2133 | } |
| 2134 | } |
| 2135 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2136 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2137 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2138 | if (!opendata->f_attr.mdsthreshold) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2139 | goto err_free_label; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2140 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2141 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2142 | if (dentry->d_inode != NULL) |
| 2143 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2144 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2145 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2146 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2147 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2148 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2149 | |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2150 | if ((opendata->o_arg.open_flags & O_EXCL) && |
| 2151 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2152 | nfs4_exclusive_attrset(opendata, sattr); |
| 2153 | |
| 2154 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2155 | status = nfs4_do_setattr(state->inode, cred, |
| 2156 | opendata->o_res.f_attr, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2157 | state, label, olabel); |
| 2158 | if (status == 0) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2159 | nfs_setattr_update_inode(state->inode, sattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2160 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2161 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2162 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2163 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2164 | |
| 2165 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 2166 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 2167 | else |
| 2168 | kfree(opendata->f_attr.mdsthreshold); |
| 2169 | opendata->f_attr.mdsthreshold = NULL; |
| 2170 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2171 | nfs4_label_free(olabel); |
| 2172 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2173 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2176 | err_free_label: |
| 2177 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2178 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2179 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2180 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2181 | err_put_state_owner: |
| 2182 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | return status; |
| 2185 | } |
| 2186 | |
| 2187 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2188 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2189 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2190 | int flags, |
| 2191 | struct iattr *sattr, |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2192 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2194 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | struct nfs4_exception exception = { }; |
| 2196 | struct nfs4_state *res; |
| 2197 | int status; |
| 2198 | |
| 2199 | do { |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2200 | status = _nfs4_do_open(dir, ctx, flags, sattr, label); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2201 | res = ctx->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | if (status == 0) |
| 2203 | break; |
| 2204 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2205 | * book-keeping w.r.t. state-changing operations |
| 2206 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2207 | * It is actually a sign of a bug on the client or on the server. |
| 2208 | * |
| 2209 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2210 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | * have unhashed the old state_owner for us, and that we can |
| 2212 | * therefore safely retry using a new one. We should still warn |
| 2213 | * the user though... |
| 2214 | */ |
| 2215 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2216 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2217 | " returned a bad sequence-id error!\n", |
| 2218 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | exception.retry = 1; |
| 2220 | continue; |
| 2221 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2222 | /* |
| 2223 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2224 | * state before it received the OPEN_CONFIRM. |
| 2225 | * Recover by retrying the request as per the discussion |
| 2226 | * on Page 181 of RFC3530. |
| 2227 | */ |
| 2228 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2229 | exception.retry = 1; |
| 2230 | continue; |
| 2231 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2232 | if (status == -EAGAIN) { |
| 2233 | /* We must have found a delegation */ |
| 2234 | exception.retry = 1; |
| 2235 | continue; |
| 2236 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2237 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2238 | continue; |
| 2239 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2240 | status, &exception)); |
| 2241 | } while (exception.retry); |
| 2242 | return res; |
| 2243 | } |
| 2244 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2245 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2246 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2247 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2248 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2249 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2250 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2252 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | .iap = sattr, |
| 2254 | .server = server, |
| 2255 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2256 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2257 | }; |
| 2258 | struct nfs_setattrres res = { |
| 2259 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2260 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2261 | .server = server, |
| 2262 | }; |
| 2263 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2264 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2265 | .rpc_argp = &arg, |
| 2266 | .rpc_resp = &res, |
| 2267 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2269 | unsigned long timestamp = jiffies; |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2270 | fmode_t fmode; |
| 2271 | bool truncate; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2272 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2274 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2275 | if (ilabel) |
| 2276 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2277 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2278 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2280 | /* Servers should only apply open mode checks for file size changes */ |
| 2281 | truncate = (sattr->ia_valid & ATTR_SIZE) ? true : false; |
| 2282 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2283 | |
| 2284 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) { |
| 2285 | /* Use that stateid */ |
| 2286 | } else if (truncate && state != NULL && nfs4_valid_open_stateid(state)) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2287 | struct nfs_lockowner lockowner = { |
| 2288 | .l_owner = current->files, |
| 2289 | .l_pid = current->tgid, |
| 2290 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2291 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2292 | &lockowner); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2293 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2294 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2296 | 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] | 2297 | if (status == 0 && state != NULL) |
| 2298 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2299 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | } |
| 2301 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2302 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2303 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2304 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2305 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2307 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2308 | struct nfs4_exception exception = { |
| 2309 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2310 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2311 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | int err; |
| 2313 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2314 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state, ilabel, olabel); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2315 | switch (err) { |
| 2316 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2317 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2318 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2319 | "applying open mode checks to " |
| 2320 | "a SETATTR that is not " |
| 2321 | "changing file size.\n", |
| 2322 | server->nfs_client->cl_hostname); |
| 2323 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2324 | if (state && !(state->state & FMODE_WRITE)) { |
| 2325 | err = -EBADF; |
| 2326 | if (sattr->ia_valid & ATTR_OPEN) |
| 2327 | err = -EACCES; |
| 2328 | goto out; |
| 2329 | } |
| 2330 | } |
| 2331 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2332 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2333 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | return err; |
| 2335 | } |
| 2336 | |
| 2337 | struct nfs4_closedata { |
| 2338 | struct inode *inode; |
| 2339 | struct nfs4_state *state; |
| 2340 | struct nfs_closeargs arg; |
| 2341 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2342 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2343 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2344 | bool roc; |
| 2345 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | }; |
| 2347 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2348 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2349 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2350 | struct nfs4_closedata *calldata = data; |
| 2351 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2352 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2353 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2354 | if (calldata->roc) |
| 2355 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2356 | nfs4_put_open_state(calldata->state); |
| 2357 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2358 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2359 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2360 | kfree(calldata); |
| 2361 | } |
| 2362 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2363 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2364 | fmode_t fmode) |
| 2365 | { |
| 2366 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2367 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2368 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 2369 | case FMODE_WRITE: |
| 2370 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2371 | break; |
| 2372 | case FMODE_READ: |
| 2373 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2374 | break; |
| 2375 | case 0: |
| 2376 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2377 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2378 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 2379 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2380 | spin_unlock(&state->owner->so_lock); |
| 2381 | } |
| 2382 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2383 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2385 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2388 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2389 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2390 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2391 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | /* hmm. we are done with the inode, and in the process of freeing |
| 2393 | * the state_owner. we keep this around to process errors |
| 2394 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | switch (task->tk_status) { |
| 2396 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2397 | if (calldata->roc) |
| 2398 | pnfs_roc_set_barrier(state->inode, |
| 2399 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2400 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2401 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2402 | nfs4_close_clear_stateid_flags(state, |
| 2403 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | break; |
| 2405 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2406 | case -NFS4ERR_OLD_STATEID: |
| 2407 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2409 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2410 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2411 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2412 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2413 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2415 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2416 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2417 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | } |
| 2419 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2420 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2421 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2422 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2423 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2424 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2425 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2426 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2427 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2428 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2429 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2430 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2431 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2432 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2433 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2434 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2435 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2436 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2437 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2438 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2439 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2440 | } |
| 2441 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2442 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2443 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2444 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2445 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2446 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2447 | if (!nfs4_valid_open_stateid(state)) |
| 2448 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2449 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2450 | |
| 2451 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2452 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2453 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2454 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2455 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2456 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2457 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2458 | if (calldata->roc && |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2459 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) { |
| 2460 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2461 | goto out_wait; |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2462 | } |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2463 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2464 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2465 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2466 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2467 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2468 | &calldata->arg.seq_args, |
| 2469 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2470 | task) != 0) |
| 2471 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2472 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2473 | return; |
| 2474 | out_no_action: |
| 2475 | task->tk_action = NULL; |
| 2476 | out_wait: |
| 2477 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | } |
| 2479 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2480 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2481 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2482 | .rpc_call_done = nfs4_close_done, |
| 2483 | .rpc_release = nfs4_free_closedata, |
| 2484 | }; |
| 2485 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2486 | /* |
| 2487 | * It is possible for data to be read/written from a mem-mapped file |
| 2488 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2489 | * This means that we can't safely call nfsv4 close on a file until |
| 2490 | * the inode is cleared. This in turn means that we are not good |
| 2491 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2492 | * share state even when we are done with one of the three share |
| 2493 | * stateid's in the inode. |
| 2494 | * |
| 2495 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2496 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2497 | 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] | 2498 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2499 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2501 | struct nfs4_state_owner *sp = state->owner; |
| 2502 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2503 | struct rpc_message msg = { |
| 2504 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2505 | .rpc_cred = state->owner->so_cred, |
| 2506 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2507 | struct rpc_task_setup task_setup_data = { |
| 2508 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2509 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2510 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2511 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2512 | .flags = RPC_TASK_ASYNC, |
| 2513 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2514 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2515 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2516 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2518 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2519 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2520 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2522 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2523 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2525 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2526 | if (calldata->arg.seqid == NULL) |
| 2527 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2528 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2529 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2530 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2531 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2532 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2533 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2534 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2535 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2536 | msg.rpc_argp = &calldata->arg; |
| 2537 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2538 | task_setup_data.callback_data = calldata; |
| 2539 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2540 | if (IS_ERR(task)) |
| 2541 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2542 | status = 0; |
| 2543 | if (wait) |
| 2544 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2545 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2546 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2547 | out_free_calldata: |
| 2548 | kfree(calldata); |
| 2549 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2550 | nfs4_put_open_state(state); |
| 2551 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2552 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 | } |
| 2554 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2555 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2556 | 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] | 2557 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2559 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 2560 | |
| 2561 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2563 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2564 | state = nfs4_do_open(dir, ctx, open_flags, attr, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2565 | |
| 2566 | nfs4_label_release_security(label); |
| 2567 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2568 | if (IS_ERR(state)) |
| 2569 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2570 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2571 | } |
| 2572 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2573 | 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] | 2574 | { |
| 2575 | if (ctx->state == NULL) |
| 2576 | return; |
| 2577 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2578 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2579 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2580 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2581 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2582 | |
| 2583 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2584 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2585 | struct nfs4_server_caps_arg args = { |
| 2586 | .fhandle = fhandle, |
| 2587 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2588 | struct nfs4_server_caps_res res = {}; |
| 2589 | struct rpc_message msg = { |
| 2590 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2591 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | .rpc_resp = &res, |
| 2593 | }; |
| 2594 | int status; |
| 2595 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2596 | 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] | 2597 | if (status == 0) { |
| 2598 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2599 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2600 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2601 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2602 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2603 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2604 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2605 | server->caps |= NFS_CAP_ACLS; |
| 2606 | if (res.has_links != 0) |
| 2607 | server->caps |= NFS_CAP_HARDLINKS; |
| 2608 | if (res.has_symlinks != 0) |
| 2609 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2610 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2611 | server->caps |= NFS_CAP_FILEID; |
| 2612 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2613 | server->caps |= NFS_CAP_MODE; |
| 2614 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2615 | server->caps |= NFS_CAP_NLINK; |
| 2616 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2617 | server->caps |= NFS_CAP_OWNER; |
| 2618 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2619 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2620 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2621 | server->caps |= NFS_CAP_ATIME; |
| 2622 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2623 | server->caps |= NFS_CAP_CTIME; |
| 2624 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2625 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2626 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 2627 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2628 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 2629 | #endif |
| 2630 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 2631 | sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2632 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2633 | if (server->caps & NFS_CAP_SECURITY_LABEL) { |
| 2634 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2635 | res.attr_bitmask[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2636 | } |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2637 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2638 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2639 | 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] | 2640 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2641 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2642 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | return status; |
| 2645 | } |
| 2646 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2647 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | { |
| 2649 | struct nfs4_exception exception = { }; |
| 2650 | int err; |
| 2651 | do { |
| 2652 | err = nfs4_handle_exception(server, |
| 2653 | _nfs4_server_capabilities(server, fhandle), |
| 2654 | &exception); |
| 2655 | } while (exception.retry); |
| 2656 | return err; |
| 2657 | } |
| 2658 | |
| 2659 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2660 | struct nfs_fsinfo *info) |
| 2661 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2662 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2664 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2665 | }; |
| 2666 | struct nfs4_lookup_res res = { |
| 2667 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2668 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2669 | .fh = fhandle, |
| 2670 | }; |
| 2671 | struct rpc_message msg = { |
| 2672 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2673 | .rpc_argp = &args, |
| 2674 | .rpc_resp = &res, |
| 2675 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2676 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2677 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 2678 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 2679 | /* |
| 2680 | * Process the label in the upcoming getfattr |
| 2681 | */ |
| 2682 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 2683 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2684 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2685 | 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] | 2686 | } |
| 2687 | |
| 2688 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2689 | struct nfs_fsinfo *info) |
| 2690 | { |
| 2691 | struct nfs4_exception exception = { }; |
| 2692 | int err; |
| 2693 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2694 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2695 | switch (err) { |
| 2696 | case 0: |
| 2697 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2698 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2699 | default: |
| 2700 | err = nfs4_handle_exception(server, err, &exception); |
| 2701 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2703 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | return err; |
| 2705 | } |
| 2706 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2707 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2708 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2709 | { |
| 2710 | struct rpc_auth *auth; |
| 2711 | int ret; |
| 2712 | |
| 2713 | auth = rpcauth_create(flavor, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2714 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 2715 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2716 | goto out; |
| 2717 | } |
| 2718 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2719 | out: |
| 2720 | return ret; |
| 2721 | } |
| 2722 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2723 | /* |
| 2724 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 2725 | * |
| 2726 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 2727 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 2728 | * |
| 2729 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 2730 | * negative errno value. |
| 2731 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2732 | 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] | 2733 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2734 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2735 | /* Per 3530bis 15.33.5 */ |
| 2736 | static const rpc_authflavor_t flav_array[] = { |
| 2737 | RPC_AUTH_GSS_KRB5P, |
| 2738 | RPC_AUTH_GSS_KRB5I, |
| 2739 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 2740 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2741 | RPC_AUTH_NULL, |
| 2742 | }; |
| 2743 | int status = -EPERM; |
| 2744 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2746 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2747 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2748 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2749 | continue; |
| 2750 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2751 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2752 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2753 | /* |
| 2754 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2755 | * to access the mount. It could also mean that we tried to mount |
| 2756 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2757 | * existing mount programs don't handle -EACCES very well so it should |
| 2758 | * be mapped to -EPERM instead. |
| 2759 | */ |
| 2760 | if (status == -EACCES) |
| 2761 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2762 | return status; |
| 2763 | } |
| 2764 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2765 | static int nfs4_do_find_root_sec(struct nfs_server *server, |
| 2766 | struct nfs_fh *fhandle, struct nfs_fsinfo *info) |
| 2767 | { |
| 2768 | int mv = server->nfs_client->cl_minorversion; |
| 2769 | return nfs_v4_minor_ops[mv]->find_root_sec(server, fhandle, info); |
| 2770 | } |
| 2771 | |
| 2772 | /** |
| 2773 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 2774 | * @server: initialized nfs_server handle |
| 2775 | * @fhandle: we fill in the pseudo-fs root file handle |
| 2776 | * @info: we fill in an FSINFO struct |
| 2777 | * |
| 2778 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2779 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2780 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2781 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2782 | { |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2783 | int status; |
| 2784 | |
| 2785 | status = nfs4_lookup_root(server, fhandle, info); |
| 2786 | if ((status == -NFS4ERR_WRONGSEC) && |
| 2787 | !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2788 | status = nfs4_do_find_root_sec(server, fhandle, info); |
| 2789 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 | if (status == 0) |
| 2791 | status = nfs4_server_capabilities(server, fhandle); |
| 2792 | if (status == 0) |
| 2793 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2794 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2795 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | } |
| 2797 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2798 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2799 | struct nfs_fsinfo *info) |
| 2800 | { |
| 2801 | int error; |
| 2802 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2803 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2804 | |
| 2805 | error = nfs4_server_capabilities(server, mntfh); |
| 2806 | if (error < 0) { |
| 2807 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2808 | return error; |
| 2809 | } |
| 2810 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2811 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 2812 | if (IS_ERR(label)) |
| 2813 | return PTR_ERR(label); |
| 2814 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2815 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2816 | if (error < 0) { |
| 2817 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2818 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2819 | } |
| 2820 | |
| 2821 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2822 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2823 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2824 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2825 | err_free_label: |
| 2826 | nfs4_label_free(label); |
| 2827 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2828 | return error; |
| 2829 | } |
| 2830 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2831 | /* |
| 2832 | * Get locations and (maybe) other attributes of a referral. |
| 2833 | * Note that we'll actually follow the referral later when |
| 2834 | * we detect fsid mismatch in inode revalidation |
| 2835 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2836 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2837 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2838 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2839 | { |
| 2840 | int status = -ENOMEM; |
| 2841 | struct page *page = NULL; |
| 2842 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2843 | |
| 2844 | page = alloc_page(GFP_KERNEL); |
| 2845 | if (page == NULL) |
| 2846 | goto out; |
| 2847 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2848 | if (locations == NULL) |
| 2849 | goto out; |
| 2850 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2851 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2852 | if (status != 0) |
| 2853 | goto out; |
| 2854 | /* Make sure server returned a different fsid for the referral */ |
| 2855 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2856 | dprintk("%s: server did not return a different fsid for" |
| 2857 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2858 | status = -EIO; |
| 2859 | goto out; |
| 2860 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2861 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2862 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2863 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2864 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2865 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2866 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2867 | out: |
| 2868 | if (page) |
| 2869 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2870 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2871 | return status; |
| 2872 | } |
| 2873 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2874 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2875 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2876 | { |
| 2877 | struct nfs4_getattr_arg args = { |
| 2878 | .fh = fhandle, |
| 2879 | .bitmask = server->attr_bitmask, |
| 2880 | }; |
| 2881 | struct nfs4_getattr_res res = { |
| 2882 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2883 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | .server = server, |
| 2885 | }; |
| 2886 | struct rpc_message msg = { |
| 2887 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2888 | .rpc_argp = &args, |
| 2889 | .rpc_resp = &res, |
| 2890 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2891 | |
| 2892 | args.bitmask = nfs4_bitmask(server, label); |
| 2893 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2894 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2895 | 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] | 2896 | } |
| 2897 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2898 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2899 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | { |
| 2901 | struct nfs4_exception exception = { }; |
| 2902 | int err; |
| 2903 | do { |
| 2904 | err = nfs4_handle_exception(server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2905 | _nfs4_proc_getattr(server, fhandle, fattr, label), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | &exception); |
| 2907 | } while (exception.retry); |
| 2908 | return err; |
| 2909 | } |
| 2910 | |
| 2911 | /* |
| 2912 | * The file is not closed if it is opened due to the a request to change |
| 2913 | * the size of the file. The open call will not be needed once the |
| 2914 | * VFS layer lookup-intents are implemented. |
| 2915 | * |
| 2916 | * Close is called when the inode is destroyed. |
| 2917 | * If we haven't opened the file for O_WRONLY, we |
| 2918 | * need to in the size_change case to obtain a stateid. |
| 2919 | * |
| 2920 | * Got race? |
| 2921 | * Because OPEN is always done by name in nfsv4, it is |
| 2922 | * possible that we opened a different file by the same |
| 2923 | * name. We can recognize this race condition, but we |
| 2924 | * can't do anything about it besides returning an error. |
| 2925 | * |
| 2926 | * This will be fixed with VFS changes (lookup-intent). |
| 2927 | */ |
| 2928 | static int |
| 2929 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2930 | struct iattr *sattr) |
| 2931 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2932 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2933 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2934 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2935 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | int status; |
| 2937 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2938 | if (pnfs_ld_layoutret_on_setattr(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 2939 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2940 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2941 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2943 | /* Deal with open(O_TRUNC) */ |
| 2944 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 2945 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2946 | |
| 2947 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 2948 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2949 | return 0; |
| 2950 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2951 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2952 | if (sattr->ia_valid & ATTR_FILE) { |
| 2953 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2954 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2955 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2956 | if (ctx) { |
| 2957 | cred = ctx->cred; |
| 2958 | state = ctx->state; |
| 2959 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2960 | } |
| 2961 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2962 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 2963 | if (IS_ERR(label)) |
| 2964 | return PTR_ERR(label); |
| 2965 | |
| 2966 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2967 | if (status == 0) { |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2968 | nfs_setattr_update_inode(inode, sattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2969 | nfs_setsecurity(inode, fattr, label); |
| 2970 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2971 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | return status; |
| 2973 | } |
| 2974 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2975 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2976 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2977 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2978 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2979 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2980 | int status; |
| 2981 | struct nfs4_lookup_arg args = { |
| 2982 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2983 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2984 | .name = name, |
| 2985 | }; |
| 2986 | struct nfs4_lookup_res res = { |
| 2987 | .server = server, |
| 2988 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2989 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2990 | .fh = fhandle, |
| 2991 | }; |
| 2992 | struct rpc_message msg = { |
| 2993 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2994 | .rpc_argp = &args, |
| 2995 | .rpc_resp = &res, |
| 2996 | }; |
| 2997 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2998 | args.bitmask = nfs4_bitmask(server, label); |
| 2999 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3000 | nfs_fattr_init(fattr); |
| 3001 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3003 | 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] | 3004 | dprintk("NFS reply lookup: %d\n", status); |
| 3005 | return status; |
| 3006 | } |
| 3007 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3008 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3009 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3010 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3011 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3012 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3013 | fattr->nlink = 2; |
| 3014 | } |
| 3015 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3016 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 3017 | struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3018 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3019 | { |
| 3020 | struct nfs4_exception exception = { }; |
| 3021 | struct rpc_clnt *client = *clnt; |
| 3022 | int err; |
| 3023 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3024 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3025 | switch (err) { |
| 3026 | case -NFS4ERR_BADNAME: |
| 3027 | err = -ENOENT; |
| 3028 | goto out; |
| 3029 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3030 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3031 | goto out; |
| 3032 | case -NFS4ERR_WRONGSEC: |
| 3033 | err = -EPERM; |
| 3034 | if (client != *clnt) |
| 3035 | goto out; |
| 3036 | |
| 3037 | client = nfs4_create_sec_client(client, dir, name); |
| 3038 | if (IS_ERR(client)) |
| 3039 | return PTR_ERR(client); |
| 3040 | |
| 3041 | exception.retry = 1; |
| 3042 | break; |
| 3043 | default: |
| 3044 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3045 | } |
| 3046 | } while (exception.retry); |
| 3047 | |
| 3048 | out: |
| 3049 | if (err == 0) |
| 3050 | *clnt = client; |
| 3051 | else if (client != *clnt) |
| 3052 | rpc_shutdown_client(client); |
| 3053 | |
| 3054 | return err; |
| 3055 | } |
| 3056 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 3057 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3058 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3059 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3061 | int status; |
| 3062 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3063 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3064 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3065 | if (client != NFS_CLIENT(dir)) { |
| 3066 | rpc_shutdown_client(client); |
| 3067 | nfs_fixup_secinfo_attributes(fattr); |
| 3068 | } |
| 3069 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | } |
| 3071 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3072 | struct rpc_clnt * |
| 3073 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 3074 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3075 | { |
| 3076 | int status; |
| 3077 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 3078 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3079 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3080 | if (status < 0) { |
| 3081 | rpc_shutdown_client(client); |
| 3082 | return ERR_PTR(status); |
| 3083 | } |
| 3084 | return client; |
| 3085 | } |
| 3086 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3087 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3088 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3089 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3090 | struct nfs4_accessargs args = { |
| 3091 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3092 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3093 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3094 | struct nfs4_accessres res = { |
| 3095 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3096 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3097 | struct rpc_message msg = { |
| 3098 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3099 | .rpc_argp = &args, |
| 3100 | .rpc_resp = &res, |
| 3101 | .rpc_cred = entry->cred, |
| 3102 | }; |
| 3103 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3104 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3105 | |
| 3106 | /* |
| 3107 | * Determine which access bits we want to ask for... |
| 3108 | */ |
| 3109 | if (mode & MAY_READ) |
| 3110 | args.access |= NFS4_ACCESS_READ; |
| 3111 | if (S_ISDIR(inode->i_mode)) { |
| 3112 | if (mode & MAY_WRITE) |
| 3113 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3114 | if (mode & MAY_EXEC) |
| 3115 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3116 | } else { |
| 3117 | if (mode & MAY_WRITE) |
| 3118 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3119 | if (mode & MAY_EXEC) |
| 3120 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3121 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3122 | |
| 3123 | res.fattr = nfs_alloc_fattr(); |
| 3124 | if (res.fattr == NULL) |
| 3125 | return -ENOMEM; |
| 3126 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3127 | 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] | 3128 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3129 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3130 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3132 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | return status; |
| 3134 | } |
| 3135 | |
| 3136 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3137 | { |
| 3138 | struct nfs4_exception exception = { }; |
| 3139 | int err; |
| 3140 | do { |
| 3141 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3142 | _nfs4_proc_access(inode, entry), |
| 3143 | &exception); |
| 3144 | } while (exception.retry); |
| 3145 | return err; |
| 3146 | } |
| 3147 | |
| 3148 | /* |
| 3149 | * TODO: For the time being, we don't try to get any attributes |
| 3150 | * along with any of the zero-copy operations READ, READDIR, |
| 3151 | * READLINK, WRITE. |
| 3152 | * |
| 3153 | * In the case of the first three, we want to put the GETATTR |
| 3154 | * after the read-type operation -- this is because it is hard |
| 3155 | * to predict the length of a GETATTR response in v4, and thus |
| 3156 | * align the READ data correctly. This means that the GETATTR |
| 3157 | * may end up partially falling into the page cache, and we should |
| 3158 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3159 | * To do this efficiently, we need to know the total length |
| 3160 | * of data received, which doesn't seem to be available outside |
| 3161 | * of the RPC layer. |
| 3162 | * |
| 3163 | * In the case of WRITE, we also want to put the GETATTR after |
| 3164 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3165 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | * |
| 3167 | * Both of these changes to the XDR layer would in fact be quite |
| 3168 | * minor, but I decided to leave them for a subsequent patch. |
| 3169 | */ |
| 3170 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3171 | unsigned int pgbase, unsigned int pglen) |
| 3172 | { |
| 3173 | struct nfs4_readlink args = { |
| 3174 | .fh = NFS_FH(inode), |
| 3175 | .pgbase = pgbase, |
| 3176 | .pglen = pglen, |
| 3177 | .pages = &page, |
| 3178 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3179 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3180 | struct rpc_message msg = { |
| 3181 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3182 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3183 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | }; |
| 3185 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3186 | 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] | 3187 | } |
| 3188 | |
| 3189 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3190 | unsigned int pgbase, unsigned int pglen) |
| 3191 | { |
| 3192 | struct nfs4_exception exception = { }; |
| 3193 | int err; |
| 3194 | do { |
| 3195 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3196 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 3197 | &exception); |
| 3198 | } while (exception.retry); |
| 3199 | return err; |
| 3200 | } |
| 3201 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3202 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3203 | * 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] | 3204 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3205 | static int |
| 3206 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3207 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3209 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3210 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3211 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | int status = 0; |
| 3213 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3214 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3215 | if (IS_ERR(ctx)) |
| 3216 | return PTR_ERR(ctx); |
| 3217 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3218 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3219 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3220 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 3221 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3222 | if (IS_ERR(state)) { |
| 3223 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3224 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3227 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3228 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | return status; |
| 3230 | } |
| 3231 | |
| 3232 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3233 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3234 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3235 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3237 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3238 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3239 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3240 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3241 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3243 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3244 | .rpc_argp = &args, |
| 3245 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3247 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3248 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3249 | 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] | 3250 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3251 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3252 | return status; |
| 3253 | } |
| 3254 | |
| 3255 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3256 | { |
| 3257 | struct nfs4_exception exception = { }; |
| 3258 | int err; |
| 3259 | do { |
| 3260 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3261 | _nfs4_proc_remove(dir, name), |
| 3262 | &exception); |
| 3263 | } while (exception.retry); |
| 3264 | return err; |
| 3265 | } |
| 3266 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3267 | 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] | 3268 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3269 | struct nfs_server *server = NFS_SERVER(dir); |
| 3270 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3271 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3273 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3275 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3276 | |
| 3277 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3278 | } |
| 3279 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3280 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3281 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3282 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 3283 | &data->args.seq_args, |
| 3284 | &data->res.seq_res, |
| 3285 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3286 | } |
| 3287 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3288 | 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] | 3289 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3290 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 3291 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3292 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3293 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3294 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3295 | return 0; |
| 3296 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3297 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3298 | } |
| 3299 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3300 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3301 | { |
| 3302 | struct nfs_server *server = NFS_SERVER(dir); |
| 3303 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3304 | struct nfs_renameres *res = msg->rpc_resp; |
| 3305 | |
| 3306 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3307 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3308 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3309 | } |
| 3310 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3311 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3312 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3313 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3314 | &data->args.seq_args, |
| 3315 | &data->res.seq_res, |
| 3316 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3317 | } |
| 3318 | |
| 3319 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3320 | struct inode *new_dir) |
| 3321 | { |
| 3322 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 3323 | |
| 3324 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3325 | return 0; |
| 3326 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 3327 | return 0; |
| 3328 | |
| 3329 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3330 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3331 | return 1; |
| 3332 | } |
| 3333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3334 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3335 | struct inode *new_dir, struct qstr *new_name) |
| 3336 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3337 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 3338 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | .old_dir = NFS_FH(old_dir), |
| 3340 | .new_dir = NFS_FH(new_dir), |
| 3341 | .old_name = old_name, |
| 3342 | .new_name = new_name, |
| 3343 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3344 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3345 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3346 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3347 | struct rpc_message msg = { |
| 3348 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3349 | .rpc_argp = &arg, |
| 3350 | .rpc_resp = &res, |
| 3351 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3352 | int status = -ENOMEM; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3353 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3354 | 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] | 3355 | if (!status) { |
| 3356 | update_changeattr(old_dir, &res.old_cinfo); |
| 3357 | update_changeattr(new_dir, &res.new_cinfo); |
| 3358 | } |
| 3359 | return status; |
| 3360 | } |
| 3361 | |
| 3362 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3363 | struct inode *new_dir, struct qstr *new_name) |
| 3364 | { |
| 3365 | struct nfs4_exception exception = { }; |
| 3366 | int err; |
| 3367 | do { |
| 3368 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3369 | _nfs4_proc_rename(old_dir, old_name, |
| 3370 | new_dir, new_name), |
| 3371 | &exception); |
| 3372 | } while (exception.retry); |
| 3373 | return err; |
| 3374 | } |
| 3375 | |
| 3376 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3377 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3378 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | struct nfs4_link_arg arg = { |
| 3380 | .fh = NFS_FH(inode), |
| 3381 | .dir_fh = NFS_FH(dir), |
| 3382 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3383 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3384 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3385 | struct nfs4_link_res res = { |
| 3386 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3387 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3388 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | struct rpc_message msg = { |
| 3390 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3391 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3392 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3394 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3395 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3396 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3397 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3398 | goto out; |
| 3399 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3400 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3401 | if (IS_ERR(res.label)) { |
| 3402 | status = PTR_ERR(res.label); |
| 3403 | goto out; |
| 3404 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3405 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3406 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3407 | 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] | 3408 | if (!status) { |
| 3409 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3410 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 3411 | if (!status) |
| 3412 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3413 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3414 | |
| 3415 | |
| 3416 | nfs4_label_free(res.label); |
| 3417 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3418 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3419 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | return status; |
| 3421 | } |
| 3422 | |
| 3423 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3424 | { |
| 3425 | struct nfs4_exception exception = { }; |
| 3426 | int err; |
| 3427 | do { |
| 3428 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3429 | _nfs4_proc_link(inode, dir, name), |
| 3430 | &exception); |
| 3431 | } while (exception.retry); |
| 3432 | return err; |
| 3433 | } |
| 3434 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3435 | struct nfs4_createdata { |
| 3436 | struct rpc_message msg; |
| 3437 | struct nfs4_create_arg arg; |
| 3438 | struct nfs4_create_res res; |
| 3439 | struct nfs_fh fh; |
| 3440 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3441 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3442 | }; |
| 3443 | |
| 3444 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3445 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3446 | { |
| 3447 | struct nfs4_createdata *data; |
| 3448 | |
| 3449 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3450 | if (data != NULL) { |
| 3451 | struct nfs_server *server = NFS_SERVER(dir); |
| 3452 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3453 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3454 | if (IS_ERR(data->label)) |
| 3455 | goto out_free; |
| 3456 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3457 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3458 | data->msg.rpc_argp = &data->arg; |
| 3459 | data->msg.rpc_resp = &data->res; |
| 3460 | data->arg.dir_fh = NFS_FH(dir); |
| 3461 | data->arg.server = server; |
| 3462 | data->arg.name = name; |
| 3463 | data->arg.attrs = sattr; |
| 3464 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3465 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3466 | data->res.server = server; |
| 3467 | data->res.fh = &data->fh; |
| 3468 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3469 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3470 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3471 | } |
| 3472 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3473 | out_free: |
| 3474 | kfree(data); |
| 3475 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3476 | } |
| 3477 | |
| 3478 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3479 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3480 | 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] | 3481 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3482 | if (status == 0) { |
| 3483 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3484 | 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] | 3485 | } |
| 3486 | return status; |
| 3487 | } |
| 3488 | |
| 3489 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3490 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3491 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3492 | kfree(data); |
| 3493 | } |
| 3494 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3495 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3496 | struct page *page, unsigned int len, struct iattr *sattr, |
| 3497 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3498 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3499 | struct nfs4_createdata *data; |
| 3500 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3501 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3502 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3503 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3504 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3505 | status = -ENOMEM; |
| 3506 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3507 | if (data == NULL) |
| 3508 | goto out; |
| 3509 | |
| 3510 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3511 | data->arg.u.symlink.pages = &page; |
| 3512 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3513 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3514 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3515 | status = nfs4_do_create(dir, dentry, data); |
| 3516 | |
| 3517 | nfs4_free_createdata(data); |
| 3518 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3519 | return status; |
| 3520 | } |
| 3521 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3522 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3523 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3524 | { |
| 3525 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3526 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3527 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3528 | |
| 3529 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3530 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3531 | do { |
| 3532 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3533 | _nfs4_proc_symlink(dir, dentry, page, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3534 | len, sattr, label), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | &exception); |
| 3536 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3537 | |
| 3538 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3539 | return err; |
| 3540 | } |
| 3541 | |
| 3542 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3543 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3544 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3545 | struct nfs4_createdata *data; |
| 3546 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3547 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3548 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3549 | if (data == NULL) |
| 3550 | goto out; |
| 3551 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3552 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3553 | status = nfs4_do_create(dir, dentry, data); |
| 3554 | |
| 3555 | nfs4_free_createdata(data); |
| 3556 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3557 | return status; |
| 3558 | } |
| 3559 | |
| 3560 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3561 | struct iattr *sattr) |
| 3562 | { |
| 3563 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3564 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3565 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3566 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3567 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3568 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3569 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | do { |
| 3571 | err = nfs4_handle_exception(NFS_SERVER(dir), |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3572 | _nfs4_proc_mkdir(dir, dentry, sattr, label), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3573 | &exception); |
| 3574 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3575 | nfs4_label_release_security(label); |
| 3576 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | return err; |
| 3578 | } |
| 3579 | |
| 3580 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3581 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3582 | { |
| 3583 | struct inode *dir = dentry->d_inode; |
| 3584 | struct nfs4_readdir_arg args = { |
| 3585 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3586 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3587 | .pgbase = 0, |
| 3588 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3589 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3590 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3591 | }; |
| 3592 | struct nfs4_readdir_res res; |
| 3593 | struct rpc_message msg = { |
| 3594 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3595 | .rpc_argp = &args, |
| 3596 | .rpc_resp = &res, |
| 3597 | .rpc_cred = cred, |
| 3598 | }; |
| 3599 | int status; |
| 3600 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3601 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3602 | dentry->d_parent->d_name.name, |
| 3603 | dentry->d_name.name, |
| 3604 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3605 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3606 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3607 | 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] | 3608 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3609 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3610 | status += args.pgbase; |
| 3611 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3612 | |
| 3613 | nfs_invalidate_atime(dir); |
| 3614 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3615 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3616 | return status; |
| 3617 | } |
| 3618 | |
| 3619 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3620 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3621 | { |
| 3622 | struct nfs4_exception exception = { }; |
| 3623 | int err; |
| 3624 | do { |
| 3625 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3626 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3627 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3628 | &exception); |
| 3629 | } while (exception.retry); |
| 3630 | return err; |
| 3631 | } |
| 3632 | |
| 3633 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3634 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3635 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3636 | struct nfs4_createdata *data; |
| 3637 | int mode = sattr->ia_mode; |
| 3638 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3639 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3640 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3641 | if (data == NULL) |
| 3642 | goto out; |
| 3643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3644 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3645 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3646 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3647 | data->arg.ftype = NF4BLK; |
| 3648 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3649 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | } |
| 3651 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3652 | data->arg.ftype = NF4CHR; |
| 3653 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3654 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3655 | } else if (!S_ISSOCK(mode)) { |
| 3656 | status = -EINVAL; |
| 3657 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3658 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3659 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3660 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3661 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3662 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3663 | nfs4_free_createdata(data); |
| 3664 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3665 | return status; |
| 3666 | } |
| 3667 | |
| 3668 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3669 | struct iattr *sattr, dev_t rdev) |
| 3670 | { |
| 3671 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3672 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3673 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3674 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3675 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3676 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3677 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3678 | do { |
| 3679 | err = nfs4_handle_exception(NFS_SERVER(dir), |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3680 | _nfs4_proc_mknod(dir, dentry, sattr, label, rdev), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3681 | &exception); |
| 3682 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3683 | |
| 3684 | nfs4_label_release_security(label); |
| 3685 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3686 | return err; |
| 3687 | } |
| 3688 | |
| 3689 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3690 | struct nfs_fsstat *fsstat) |
| 3691 | { |
| 3692 | struct nfs4_statfs_arg args = { |
| 3693 | .fh = fhandle, |
| 3694 | .bitmask = server->attr_bitmask, |
| 3695 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3696 | struct nfs4_statfs_res res = { |
| 3697 | .fsstat = fsstat, |
| 3698 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3699 | struct rpc_message msg = { |
| 3700 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3701 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3702 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3703 | }; |
| 3704 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3705 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3706 | 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] | 3707 | } |
| 3708 | |
| 3709 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3710 | { |
| 3711 | struct nfs4_exception exception = { }; |
| 3712 | int err; |
| 3713 | do { |
| 3714 | err = nfs4_handle_exception(server, |
| 3715 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3716 | &exception); |
| 3717 | } while (exception.retry); |
| 3718 | return err; |
| 3719 | } |
| 3720 | |
| 3721 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3722 | struct nfs_fsinfo *fsinfo) |
| 3723 | { |
| 3724 | struct nfs4_fsinfo_arg args = { |
| 3725 | .fh = fhandle, |
| 3726 | .bitmask = server->attr_bitmask, |
| 3727 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3728 | struct nfs4_fsinfo_res res = { |
| 3729 | .fsinfo = fsinfo, |
| 3730 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3731 | struct rpc_message msg = { |
| 3732 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3733 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3734 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | }; |
| 3736 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3737 | 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] | 3738 | } |
| 3739 | |
| 3740 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3741 | { |
| 3742 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3743 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3744 | int err; |
| 3745 | |
| 3746 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3747 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3748 | if (err == 0) { |
| 3749 | struct nfs_client *clp = server->nfs_client; |
| 3750 | |
| 3751 | spin_lock(&clp->cl_lock); |
| 3752 | clp->cl_lease_time = fsinfo->lease_time * HZ; |
| 3753 | clp->cl_last_renewal = now; |
| 3754 | spin_unlock(&clp->cl_lock); |
| 3755 | break; |
| 3756 | } |
| 3757 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3758 | } while (exception.retry); |
| 3759 | return err; |
| 3760 | } |
| 3761 | |
| 3762 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3763 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3764 | int error; |
| 3765 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3766 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3767 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3768 | if (error == 0) { |
| 3769 | /* block layout checks this! */ |
| 3770 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3771 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3772 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3773 | |
| 3774 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | } |
| 3776 | |
| 3777 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3778 | struct nfs_pathconf *pathconf) |
| 3779 | { |
| 3780 | struct nfs4_pathconf_arg args = { |
| 3781 | .fh = fhandle, |
| 3782 | .bitmask = server->attr_bitmask, |
| 3783 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3784 | struct nfs4_pathconf_res res = { |
| 3785 | .pathconf = pathconf, |
| 3786 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3787 | struct rpc_message msg = { |
| 3788 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3789 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3790 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3791 | }; |
| 3792 | |
| 3793 | /* None of the pathconf attributes are mandatory to implement */ |
| 3794 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3795 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3796 | return 0; |
| 3797 | } |
| 3798 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3799 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3800 | 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] | 3801 | } |
| 3802 | |
| 3803 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3804 | struct nfs_pathconf *pathconf) |
| 3805 | { |
| 3806 | struct nfs4_exception exception = { }; |
| 3807 | int err; |
| 3808 | |
| 3809 | do { |
| 3810 | err = nfs4_handle_exception(server, |
| 3811 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3812 | &exception); |
| 3813 | } while (exception.retry); |
| 3814 | return err; |
| 3815 | } |
| 3816 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3817 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3818 | const struct nfs_open_context *ctx, |
| 3819 | const struct nfs_lock_context *l_ctx, |
| 3820 | fmode_t fmode) |
| 3821 | { |
| 3822 | const struct nfs_lockowner *lockowner = NULL; |
| 3823 | |
| 3824 | if (l_ctx != NULL) |
| 3825 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3826 | return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3827 | } |
| 3828 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 3829 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3830 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 3831 | const struct nfs_open_context *ctx, |
| 3832 | const struct nfs_lock_context *l_ctx, |
| 3833 | fmode_t fmode) |
| 3834 | { |
| 3835 | nfs4_stateid current_stateid; |
| 3836 | |
| 3837 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode)) |
| 3838 | return false; |
| 3839 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 3840 | } |
| 3841 | |
| 3842 | static bool nfs4_error_stateid_expired(int err) |
| 3843 | { |
| 3844 | switch (err) { |
| 3845 | case -NFS4ERR_DELEG_REVOKED: |
| 3846 | case -NFS4ERR_ADMIN_REVOKED: |
| 3847 | case -NFS4ERR_BAD_STATEID: |
| 3848 | case -NFS4ERR_STALE_STATEID: |
| 3849 | case -NFS4ERR_OLD_STATEID: |
| 3850 | case -NFS4ERR_OPENMODE: |
| 3851 | case -NFS4ERR_EXPIRED: |
| 3852 | return true; |
| 3853 | } |
| 3854 | return false; |
| 3855 | } |
| 3856 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3857 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3858 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3859 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3860 | } |
| 3861 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3862 | 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] | 3863 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3864 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3865 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3866 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3867 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3868 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3869 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3870 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3871 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3872 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3873 | renew_lease(server, data->timestamp); |
| 3874 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3875 | } |
| 3876 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3877 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
| 3878 | struct nfs_readargs *args) |
| 3879 | { |
| 3880 | |
| 3881 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3882 | nfs4_stateid_is_current(&args->stateid, |
| 3883 | args->context, |
| 3884 | args->lock_context, |
| 3885 | FMODE_READ)) |
| 3886 | return false; |
| 3887 | rpc_restart_call_prepare(task); |
| 3888 | return true; |
| 3889 | } |
| 3890 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3891 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3892 | { |
| 3893 | |
| 3894 | dprintk("--> %s\n", __func__); |
| 3895 | |
| 3896 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3897 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3898 | if (nfs4_read_stateid_changed(task, &data->args)) |
| 3899 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3900 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3901 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3902 | } |
| 3903 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3904 | 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] | 3905 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3906 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3907 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3908 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3909 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3910 | } |
| 3911 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3912 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3913 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3914 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3915 | &data->args.seq_args, |
| 3916 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3917 | task)) |
| 3918 | return; |
| 3919 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 3920 | data->args.lock_context, FMODE_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3921 | } |
| 3922 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3923 | 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] | 3924 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3925 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3926 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3927 | 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] | 3928 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3929 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3930 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3931 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3932 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3933 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3934 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3935 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3936 | } |
| 3937 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3938 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
| 3939 | struct nfs_writeargs *args) |
| 3940 | { |
| 3941 | |
| 3942 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3943 | nfs4_stateid_is_current(&args->stateid, |
| 3944 | args->context, |
| 3945 | args->lock_context, |
| 3946 | FMODE_WRITE)) |
| 3947 | return false; |
| 3948 | rpc_restart_call_prepare(task); |
| 3949 | return true; |
| 3950 | } |
| 3951 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3952 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3953 | { |
| 3954 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3955 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3956 | if (nfs4_write_stateid_changed(task, &data->args)) |
| 3957 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3958 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3959 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3960 | } |
| 3961 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3962 | static |
| 3963 | 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] | 3964 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3965 | const struct nfs_pgio_header *hdr = data->header; |
| 3966 | |
| 3967 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3968 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3969 | return false; |
| 3970 | /* Otherwise, request attributes if and only if we don't hold |
| 3971 | * a delegation |
| 3972 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3973 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3974 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3975 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3976 | 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] | 3977 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3978 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3979 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3980 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3981 | data->args.bitmask = NULL; |
| 3982 | data->res.fattr = NULL; |
| 3983 | } else |
| 3984 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3985 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3986 | if (!data->write_done_cb) |
| 3987 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3988 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3989 | data->timestamp = jiffies; |
| 3990 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3991 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3992 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3993 | } |
| 3994 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3995 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3996 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3997 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3998 | &data->args.seq_args, |
| 3999 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4000 | task)) |
| 4001 | return; |
| 4002 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 4003 | data->args.lock_context, FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4004 | } |
| 4005 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4006 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4007 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4008 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4009 | &data->args.seq_args, |
| 4010 | &data->res.seq_res, |
| 4011 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4012 | } |
| 4013 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4014 | 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] | 4015 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4016 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4017 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4018 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4019 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4020 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4021 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4022 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4023 | } |
| 4024 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4025 | 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] | 4026 | { |
| 4027 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4028 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4029 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4030 | } |
| 4031 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4032 | 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] | 4033 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4034 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4035 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4036 | if (data->commit_done_cb == NULL) |
| 4037 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4038 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4039 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4040 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4041 | } |
| 4042 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4043 | struct nfs4_renewdata { |
| 4044 | struct nfs_client *client; |
| 4045 | unsigned long timestamp; |
| 4046 | }; |
| 4047 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4048 | /* |
| 4049 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4050 | * standalone procedure for queueing an asynchronous RENEW. |
| 4051 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4052 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4053 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4054 | struct nfs4_renewdata *data = calldata; |
| 4055 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4056 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4057 | if (atomic_read(&clp->cl_count) > 1) |
| 4058 | nfs4_schedule_state_renewal(clp); |
| 4059 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4060 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4061 | } |
| 4062 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4063 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4065 | struct nfs4_renewdata *data = calldata; |
| 4066 | struct nfs_client *clp = data->client; |
| 4067 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4068 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame^] | 4069 | trace_nfs4_renew_async(clp, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4070 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4071 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4072 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4073 | return; |
| 4074 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4075 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4076 | return; |
| 4077 | } |
| 4078 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4079 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4080 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4081 | } |
| 4082 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4083 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4084 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4085 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4086 | }; |
| 4087 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4088 | 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] | 4089 | { |
| 4090 | struct rpc_message msg = { |
| 4091 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4092 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4093 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4094 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4095 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4097 | if (renew_flags == 0) |
| 4098 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4099 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4100 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4101 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4102 | if (data == NULL) |
| 4103 | return -ENOMEM; |
| 4104 | data->client = clp; |
| 4105 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4106 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4107 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4108 | } |
| 4109 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4110 | 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] | 4111 | { |
| 4112 | struct rpc_message msg = { |
| 4113 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4114 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4115 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4116 | }; |
| 4117 | unsigned long now = jiffies; |
| 4118 | int status; |
| 4119 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4120 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4121 | if (status < 0) |
| 4122 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4123 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | return 0; |
| 4125 | } |
| 4126 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4127 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4128 | { |
| 4129 | return (server->caps & NFS_CAP_ACLS) |
| 4130 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 4131 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 4132 | } |
| 4133 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4134 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4135 | * 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] | 4136 | * the stack. |
| 4137 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4138 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4139 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4140 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 4141 | struct page **pages, unsigned int *pgbase) |
| 4142 | { |
| 4143 | struct page *newpage, **spages; |
| 4144 | int rc = 0; |
| 4145 | size_t len; |
| 4146 | spages = pages; |
| 4147 | |
| 4148 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4149 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4150 | newpage = alloc_page(GFP_KERNEL); |
| 4151 | |
| 4152 | if (newpage == NULL) |
| 4153 | goto unwind; |
| 4154 | memcpy(page_address(newpage), buf, len); |
| 4155 | buf += len; |
| 4156 | buflen -= len; |
| 4157 | *pages++ = newpage; |
| 4158 | rc++; |
| 4159 | } while (buflen != 0); |
| 4160 | |
| 4161 | return rc; |
| 4162 | |
| 4163 | unwind: |
| 4164 | for(; rc > 0; rc--) |
| 4165 | __free_page(spages[rc-1]); |
| 4166 | return -ENOMEM; |
| 4167 | } |
| 4168 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4169 | struct nfs4_cached_acl { |
| 4170 | int cached; |
| 4171 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4172 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4173 | }; |
| 4174 | |
| 4175 | 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] | 4176 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4177 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4178 | |
| 4179 | spin_lock(&inode->i_lock); |
| 4180 | kfree(nfsi->nfs4_acl); |
| 4181 | nfsi->nfs4_acl = acl; |
| 4182 | spin_unlock(&inode->i_lock); |
| 4183 | } |
| 4184 | |
| 4185 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4186 | { |
| 4187 | nfs4_set_cached_acl(inode, NULL); |
| 4188 | } |
| 4189 | |
| 4190 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4191 | { |
| 4192 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4193 | struct nfs4_cached_acl *acl; |
| 4194 | int ret = -ENOENT; |
| 4195 | |
| 4196 | spin_lock(&inode->i_lock); |
| 4197 | acl = nfsi->nfs4_acl; |
| 4198 | if (acl == NULL) |
| 4199 | goto out; |
| 4200 | if (buf == NULL) /* user is just asking for length */ |
| 4201 | goto out_len; |
| 4202 | if (acl->cached == 0) |
| 4203 | goto out; |
| 4204 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4205 | if (acl->len > buflen) |
| 4206 | goto out; |
| 4207 | memcpy(buf, acl->data, acl->len); |
| 4208 | out_len: |
| 4209 | ret = acl->len; |
| 4210 | out: |
| 4211 | spin_unlock(&inode->i_lock); |
| 4212 | return ret; |
| 4213 | } |
| 4214 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4215 | 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] | 4216 | { |
| 4217 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4218 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4219 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4220 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4221 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4222 | if (acl == NULL) |
| 4223 | goto out; |
| 4224 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4225 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4226 | } else { |
| 4227 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4228 | if (acl == NULL) |
| 4229 | goto out; |
| 4230 | acl->cached = 0; |
| 4231 | } |
| 4232 | acl->len = acl_len; |
| 4233 | out: |
| 4234 | nfs4_set_cached_acl(inode, acl); |
| 4235 | } |
| 4236 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4237 | /* |
| 4238 | * The getxattr API returns the required buffer length when called with a |
| 4239 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4240 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4241 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4242 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4243 | * the cache. If not so, we throw away the page, and cache the required |
| 4244 | * length. The next getxattr call will then produce another round trip to |
| 4245 | * the server, this time with the input buf of the required size. |
| 4246 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4247 | 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] | 4248 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4249 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4250 | struct nfs_getaclargs args = { |
| 4251 | .fh = NFS_FH(inode), |
| 4252 | .acl_pages = pages, |
| 4253 | .acl_len = buflen, |
| 4254 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4255 | struct nfs_getaclres res = { |
| 4256 | .acl_len = buflen, |
| 4257 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4258 | struct rpc_message msg = { |
| 4259 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4260 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4261 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4262 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4263 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4264 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4265 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4266 | /* As long as we're doing a round trip to the server anyway, |
| 4267 | * let's be prepared for a page of acl data. */ |
| 4268 | if (npages == 0) |
| 4269 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4270 | if (npages > ARRAY_SIZE(pages)) |
| 4271 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4272 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4273 | for (i = 0; i < npages; i++) { |
| 4274 | pages[i] = alloc_page(GFP_KERNEL); |
| 4275 | if (!pages[i]) |
| 4276 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4277 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4278 | |
| 4279 | /* for decoding across pages */ |
| 4280 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4281 | if (!res.acl_scratch) |
| 4282 | goto out_free; |
| 4283 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4284 | args.acl_len = npages * PAGE_SIZE; |
| 4285 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4286 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4287 | 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] | 4288 | __func__, buf, buflen, npages, args.acl_len); |
| 4289 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4290 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4291 | if (ret) |
| 4292 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4293 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4294 | /* Handle the case where the passed-in buffer is too short */ |
| 4295 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4296 | /* Did the user only issue a request for the acl length? */ |
| 4297 | if (buf == NULL) |
| 4298 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4299 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4300 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4301 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4302 | 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] | 4303 | if (buf) { |
| 4304 | if (res.acl_len > buflen) { |
| 4305 | ret = -ERANGE; |
| 4306 | goto out_free; |
| 4307 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4308 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4309 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4310 | out_ok: |
| 4311 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4312 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4313 | for (i = 0; i < npages; i++) |
| 4314 | if (pages[i]) |
| 4315 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4316 | if (res.acl_scratch) |
| 4317 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4318 | return ret; |
| 4319 | } |
| 4320 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4321 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4322 | { |
| 4323 | struct nfs4_exception exception = { }; |
| 4324 | ssize_t ret; |
| 4325 | do { |
| 4326 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 4327 | if (ret >= 0) |
| 4328 | break; |
| 4329 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4330 | } while (exception.retry); |
| 4331 | return ret; |
| 4332 | } |
| 4333 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4334 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4335 | { |
| 4336 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4337 | int ret; |
| 4338 | |
| 4339 | if (!nfs4_server_supports_acls(server)) |
| 4340 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4341 | ret = nfs_revalidate_inode(server, inode); |
| 4342 | if (ret < 0) |
| 4343 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4344 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4345 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4346 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4347 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4348 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4349 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4350 | return ret; |
| 4351 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4352 | } |
| 4353 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4354 | 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] | 4355 | { |
| 4356 | struct nfs_server *server = NFS_SERVER(inode); |
| 4357 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4358 | struct nfs_setaclargs arg = { |
| 4359 | .fh = NFS_FH(inode), |
| 4360 | .acl_pages = pages, |
| 4361 | .acl_len = buflen, |
| 4362 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4363 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4364 | struct rpc_message msg = { |
| 4365 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4366 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4367 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4368 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4369 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4370 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4371 | |
| 4372 | if (!nfs4_server_supports_acls(server)) |
| 4373 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4374 | if (npages > ARRAY_SIZE(pages)) |
| 4375 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4376 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4377 | if (i < 0) |
| 4378 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4379 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4380 | 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] | 4381 | |
| 4382 | /* |
| 4383 | * Free each page after tx, so the only ref left is |
| 4384 | * held by the network stack |
| 4385 | */ |
| 4386 | for (; i > 0; i--) |
| 4387 | put_page(pages[i-1]); |
| 4388 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4389 | /* |
| 4390 | * Acl update can result in inode attribute update. |
| 4391 | * so mark the attribute cache invalid. |
| 4392 | */ |
| 4393 | spin_lock(&inode->i_lock); |
| 4394 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4395 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4396 | nfs_access_zap_cache(inode); |
| 4397 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4398 | return ret; |
| 4399 | } |
| 4400 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4401 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4402 | { |
| 4403 | struct nfs4_exception exception = { }; |
| 4404 | int err; |
| 4405 | do { |
| 4406 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4407 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 4408 | &exception); |
| 4409 | } while (exception.retry); |
| 4410 | return err; |
| 4411 | } |
| 4412 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4413 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 4414 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 4415 | size_t buflen) |
| 4416 | { |
| 4417 | struct nfs_server *server = NFS_SERVER(inode); |
| 4418 | struct nfs_fattr fattr; |
| 4419 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 4420 | |
| 4421 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
| 4422 | struct nfs4_getattr_arg args = { |
| 4423 | .fh = NFS_FH(inode), |
| 4424 | .bitmask = bitmask, |
| 4425 | }; |
| 4426 | struct nfs4_getattr_res res = { |
| 4427 | .fattr = &fattr, |
| 4428 | .label = &label, |
| 4429 | .server = server, |
| 4430 | }; |
| 4431 | struct rpc_message msg = { |
| 4432 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 4433 | .rpc_argp = &args, |
| 4434 | .rpc_resp = &res, |
| 4435 | }; |
| 4436 | int ret; |
| 4437 | |
| 4438 | nfs_fattr_init(&fattr); |
| 4439 | |
| 4440 | ret = rpc_call_sync(server->client, &msg, 0); |
| 4441 | if (ret) |
| 4442 | return ret; |
| 4443 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 4444 | return -ENOENT; |
| 4445 | if (buflen < label.len) |
| 4446 | return -ERANGE; |
| 4447 | return 0; |
| 4448 | } |
| 4449 | |
| 4450 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 4451 | size_t buflen) |
| 4452 | { |
| 4453 | struct nfs4_exception exception = { }; |
| 4454 | int err; |
| 4455 | |
| 4456 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4457 | return -EOPNOTSUPP; |
| 4458 | |
| 4459 | do { |
| 4460 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4461 | _nfs4_get_security_label(inode, buf, buflen), |
| 4462 | &exception); |
| 4463 | } while (exception.retry); |
| 4464 | return err; |
| 4465 | } |
| 4466 | |
| 4467 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 4468 | struct nfs4_label *ilabel, |
| 4469 | struct nfs_fattr *fattr, |
| 4470 | struct nfs4_label *olabel) |
| 4471 | { |
| 4472 | |
| 4473 | struct iattr sattr = {0}; |
| 4474 | struct nfs_server *server = NFS_SERVER(inode); |
| 4475 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
| 4476 | struct nfs_setattrargs args = { |
| 4477 | .fh = NFS_FH(inode), |
| 4478 | .iap = &sattr, |
| 4479 | .server = server, |
| 4480 | .bitmask = bitmask, |
| 4481 | .label = ilabel, |
| 4482 | }; |
| 4483 | struct nfs_setattrres res = { |
| 4484 | .fattr = fattr, |
| 4485 | .label = olabel, |
| 4486 | .server = server, |
| 4487 | }; |
| 4488 | struct rpc_message msg = { |
| 4489 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 4490 | .rpc_argp = &args, |
| 4491 | .rpc_resp = &res, |
| 4492 | }; |
| 4493 | int status; |
| 4494 | |
| 4495 | nfs4_stateid_copy(&args.stateid, &zero_stateid); |
| 4496 | |
| 4497 | status = rpc_call_sync(server->client, &msg, 0); |
| 4498 | if (status) |
| 4499 | dprintk("%s failed: %d\n", __func__, status); |
| 4500 | |
| 4501 | return status; |
| 4502 | } |
| 4503 | |
| 4504 | static int nfs4_do_set_security_label(struct inode *inode, |
| 4505 | struct nfs4_label *ilabel, |
| 4506 | struct nfs_fattr *fattr, |
| 4507 | struct nfs4_label *olabel) |
| 4508 | { |
| 4509 | struct nfs4_exception exception = { }; |
| 4510 | int err; |
| 4511 | |
| 4512 | do { |
| 4513 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4514 | _nfs4_do_set_security_label(inode, ilabel, |
| 4515 | fattr, olabel), |
| 4516 | &exception); |
| 4517 | } while (exception.retry); |
| 4518 | return err; |
| 4519 | } |
| 4520 | |
| 4521 | static int |
| 4522 | nfs4_set_security_label(struct dentry *dentry, const void *buf, size_t buflen) |
| 4523 | { |
| 4524 | struct nfs4_label ilabel, *olabel = NULL; |
| 4525 | struct nfs_fattr fattr; |
| 4526 | struct rpc_cred *cred; |
| 4527 | struct inode *inode = dentry->d_inode; |
| 4528 | int status; |
| 4529 | |
| 4530 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4531 | return -EOPNOTSUPP; |
| 4532 | |
| 4533 | nfs_fattr_init(&fattr); |
| 4534 | |
| 4535 | ilabel.pi = 0; |
| 4536 | ilabel.lfs = 0; |
| 4537 | ilabel.label = (char *)buf; |
| 4538 | ilabel.len = buflen; |
| 4539 | |
| 4540 | cred = rpc_lookup_cred(); |
| 4541 | if (IS_ERR(cred)) |
| 4542 | return PTR_ERR(cred); |
| 4543 | |
| 4544 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 4545 | if (IS_ERR(olabel)) { |
| 4546 | status = -PTR_ERR(olabel); |
| 4547 | goto out; |
| 4548 | } |
| 4549 | |
| 4550 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 4551 | if (status == 0) |
| 4552 | nfs_setsecurity(inode, &fattr, olabel); |
| 4553 | |
| 4554 | nfs4_label_free(olabel); |
| 4555 | out: |
| 4556 | put_rpccred(cred); |
| 4557 | return status; |
| 4558 | } |
| 4559 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 4560 | |
| 4561 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4562 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4563 | 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] | 4564 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4565 | struct nfs_client *clp = server->nfs_client; |
| 4566 | |
| 4567 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4568 | return 0; |
| 4569 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4570 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4571 | case -NFS4ERR_ADMIN_REVOKED: |
| 4572 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 4573 | if (state == NULL) |
| 4574 | break; |
| 4575 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4576 | case -NFS4ERR_OPENMODE: |
| 4577 | if (state == NULL) |
| 4578 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4579 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4580 | goto stateid_invalid; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4581 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4582 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4583 | if (state != NULL) { |
| 4584 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4585 | goto stateid_invalid; |
| 4586 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4587 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4588 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4589 | nfs4_schedule_lease_recovery(clp); |
| 4590 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4591 | #if defined(CONFIG_NFS_V4_1) |
| 4592 | case -NFS4ERR_BADSESSION: |
| 4593 | case -NFS4ERR_BADSLOT: |
| 4594 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4595 | case -NFS4ERR_DEADSESSION: |
| 4596 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4597 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4598 | case -NFS4ERR_SEQ_MISORDERED: |
| 4599 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4600 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4601 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4602 | task->tk_status = 0; |
| 4603 | return -EAGAIN; |
| 4604 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4605 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4606 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4607 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4608 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 4609 | task->tk_status = 0; |
| 4610 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4611 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4612 | case -NFS4ERR_OLD_STATEID: |
| 4613 | task->tk_status = 0; |
| 4614 | return -EAGAIN; |
| 4615 | } |
| 4616 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4617 | return 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4618 | stateid_invalid: |
| 4619 | task->tk_status = -EIO; |
| 4620 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4621 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4622 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4623 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4624 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 4625 | task->tk_status = 0; |
| 4626 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4627 | } |
| 4628 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4629 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4630 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4631 | { |
| 4632 | __be32 verf[2]; |
| 4633 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4634 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4635 | /* An impossible timestamp guarantees this value |
| 4636 | * will never match a generated boot time. */ |
| 4637 | verf[0] = 0; |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 4638 | verf[1] = cpu_to_be32(NSEC_PER_SEC + 1); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4639 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4640 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 4641 | verf[0] = cpu_to_be32(nn->boot_time.tv_sec); |
| 4642 | verf[1] = cpu_to_be32(nn->boot_time.tv_nsec); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4643 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4644 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4645 | } |
| 4646 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4647 | static unsigned int |
| 4648 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4649 | char *buf, size_t len) |
| 4650 | { |
| 4651 | unsigned int result; |
| 4652 | |
| 4653 | rcu_read_lock(); |
| 4654 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4655 | clp->cl_ipaddr, |
| 4656 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4657 | RPC_DISPLAY_ADDR), |
| 4658 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4659 | RPC_DISPLAY_PROTO)); |
| 4660 | rcu_read_unlock(); |
| 4661 | return result; |
| 4662 | } |
| 4663 | |
| 4664 | static unsigned int |
| 4665 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4666 | char *buf, size_t len) |
| 4667 | { |
Trond Myklebust | 55b5929 | 2013-07-24 16:36:35 -0400 | [diff] [blame] | 4668 | const char *nodename = clp->cl_rpcclient->cl_nodename; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4669 | |
| 4670 | if (nfs4_client_id_uniquifier[0] != '\0') |
Trond Myklebust | 55b5929 | 2013-07-24 16:36:35 -0400 | [diff] [blame] | 4671 | return scnprintf(buf, len, "Linux NFSv%u.%u %s/%s", |
| 4672 | clp->rpc_ops->version, |
| 4673 | clp->cl_minorversion, |
| 4674 | nfs4_client_id_uniquifier, |
| 4675 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4676 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4677 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4678 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4679 | } |
| 4680 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4681 | /** |
| 4682 | * nfs4_proc_setclientid - Negotiate client ID |
| 4683 | * @clp: state data structure |
| 4684 | * @program: RPC program for NFSv4 callback service |
| 4685 | * @port: IP port number for NFS4 callback service |
| 4686 | * @cred: RPC credential to use for this call |
| 4687 | * @res: where to place the result |
| 4688 | * |
| 4689 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4690 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4691 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4692 | unsigned short port, struct rpc_cred *cred, |
| 4693 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4694 | { |
| 4695 | nfs4_verifier sc_verifier; |
| 4696 | struct nfs4_setclientid setclientid = { |
| 4697 | .sc_verifier = &sc_verifier, |
| 4698 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4699 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4700 | }; |
| 4701 | struct rpc_message msg = { |
| 4702 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4703 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4704 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4705 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4706 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4707 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4708 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4709 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4710 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4711 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4712 | setclientid.sc_name_len = |
| 4713 | nfs4_init_uniform_client_string(clp, |
| 4714 | setclientid.sc_name, |
| 4715 | sizeof(setclientid.sc_name)); |
| 4716 | else |
| 4717 | setclientid.sc_name_len = |
| 4718 | nfs4_init_nonuniform_client_string(clp, |
| 4719 | setclientid.sc_name, |
| 4720 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4721 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4722 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4723 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Djalal Harouni | fe2d539 | 2013-06-18 17:58:12 +0100 | [diff] [blame] | 4724 | sizeof(setclientid.sc_netid), "%s", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4725 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4726 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4727 | rcu_read_unlock(); |
| 4728 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4729 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4730 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4731 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4732 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4733 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4734 | setclientid.sc_name_len, setclientid.sc_name); |
| 4735 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame^] | 4736 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4737 | dprintk("NFS reply setclientid: %d\n", status); |
| 4738 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4739 | } |
| 4740 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4741 | /** |
| 4742 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4743 | * @clp: state data structure |
| 4744 | * @res: result of a previous SETCLIENTID |
| 4745 | * @cred: RPC credential to use for this call |
| 4746 | * |
| 4747 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4748 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4749 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4750 | struct nfs4_setclientid_res *arg, |
| 4751 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4752 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4753 | struct rpc_message msg = { |
| 4754 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4755 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4756 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4757 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4758 | int status; |
| 4759 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4760 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4761 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4762 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4763 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame^] | 4764 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4765 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4766 | return status; |
| 4767 | } |
| 4768 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4769 | struct nfs4_delegreturndata { |
| 4770 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4771 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4772 | struct nfs_fh fh; |
| 4773 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4774 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4775 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4776 | int rpc_status; |
| 4777 | }; |
| 4778 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4779 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4780 | { |
| 4781 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4782 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4783 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4784 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4785 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4786 | switch (task->tk_status) { |
| 4787 | case -NFS4ERR_STALE_STATEID: |
| 4788 | case -NFS4ERR_EXPIRED: |
| 4789 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4790 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4791 | break; |
| 4792 | default: |
| 4793 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4794 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4795 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4796 | return; |
| 4797 | } |
| 4798 | } |
| 4799 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4800 | } |
| 4801 | |
| 4802 | static void nfs4_delegreturn_release(void *calldata) |
| 4803 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4804 | kfree(calldata); |
| 4805 | } |
| 4806 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4807 | #if defined(CONFIG_NFS_V4_1) |
| 4808 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4809 | { |
| 4810 | struct nfs4_delegreturndata *d_data; |
| 4811 | |
| 4812 | d_data = (struct nfs4_delegreturndata *)data; |
| 4813 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4814 | nfs4_setup_sequence(d_data->res.server, |
| 4815 | &d_data->args.seq_args, |
| 4816 | &d_data->res.seq_res, |
| 4817 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4818 | } |
| 4819 | #endif /* CONFIG_NFS_V4_1 */ |
| 4820 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4821 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4822 | #if defined(CONFIG_NFS_V4_1) |
| 4823 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4824 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4825 | .rpc_call_done = nfs4_delegreturn_done, |
| 4826 | .rpc_release = nfs4_delegreturn_release, |
| 4827 | }; |
| 4828 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4829 | 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] | 4830 | { |
| 4831 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4832 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4833 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4834 | struct rpc_message msg = { |
| 4835 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4836 | .rpc_cred = cred, |
| 4837 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4838 | struct rpc_task_setup task_setup_data = { |
| 4839 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4840 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4841 | .callback_ops = &nfs4_delegreturn_ops, |
| 4842 | .flags = RPC_TASK_ASYNC, |
| 4843 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4844 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4845 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4846 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4847 | if (data == NULL) |
| 4848 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4849 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4850 | data->args.fhandle = &data->fh; |
| 4851 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4852 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4853 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4854 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4855 | data->res.fattr = &data->fattr; |
| 4856 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4857 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4858 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4859 | data->rpc_status = 0; |
| 4860 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4861 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4862 | msg.rpc_argp = &data->args; |
| 4863 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4864 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4865 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4866 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4867 | if (!issync) |
| 4868 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4869 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4870 | if (status != 0) |
| 4871 | goto out; |
| 4872 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4873 | if (status == 0) |
| 4874 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4875 | else |
| 4876 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4877 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4878 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4879 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4880 | } |
| 4881 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4882 | 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] | 4883 | { |
| 4884 | struct nfs_server *server = NFS_SERVER(inode); |
| 4885 | struct nfs4_exception exception = { }; |
| 4886 | int err; |
| 4887 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4888 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4889 | switch (err) { |
| 4890 | case -NFS4ERR_STALE_STATEID: |
| 4891 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4892 | case 0: |
| 4893 | return 0; |
| 4894 | } |
| 4895 | err = nfs4_handle_exception(server, err, &exception); |
| 4896 | } while (exception.retry); |
| 4897 | return err; |
| 4898 | } |
| 4899 | |
| 4900 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4901 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4902 | |
| 4903 | /* |
| 4904 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4905 | */ |
| 4906 | static unsigned long |
| 4907 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4908 | { |
Colin Cross | 416ad3c | 2013-05-06 23:50:06 +0000 | [diff] [blame] | 4909 | freezable_schedule_timeout_killable_unsafe(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4910 | timeout <<= 1; |
| 4911 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4912 | return NFS4_LOCK_MAXTIMEOUT; |
| 4913 | return timeout; |
| 4914 | } |
| 4915 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4916 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4917 | { |
| 4918 | struct inode *inode = state->inode; |
| 4919 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4920 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4921 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4922 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4923 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4924 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4925 | struct nfs_lockt_res res = { |
| 4926 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4927 | }; |
| 4928 | struct rpc_message msg = { |
| 4929 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4930 | .rpc_argp = &arg, |
| 4931 | .rpc_resp = &res, |
| 4932 | .rpc_cred = state->owner->so_cred, |
| 4933 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4934 | struct nfs4_lock_state *lsp; |
| 4935 | int status; |
| 4936 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4937 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4938 | status = nfs4_set_lock_state(state, request); |
| 4939 | if (status != 0) |
| 4940 | goto out; |
| 4941 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4942 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4943 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4944 | 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] | 4945 | switch (status) { |
| 4946 | case 0: |
| 4947 | request->fl_type = F_UNLCK; |
| 4948 | break; |
| 4949 | case -NFS4ERR_DENIED: |
| 4950 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4951 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4952 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4953 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4954 | return status; |
| 4955 | } |
| 4956 | |
| 4957 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4958 | { |
| 4959 | struct nfs4_exception exception = { }; |
| 4960 | int err; |
| 4961 | |
| 4962 | do { |
| 4963 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4964 | _nfs4_proc_getlk(state, cmd, request), |
| 4965 | &exception); |
| 4966 | } while (exception.retry); |
| 4967 | return err; |
| 4968 | } |
| 4969 | |
| 4970 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4971 | { |
| 4972 | int res = 0; |
| 4973 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4974 | case FL_POSIX: |
| 4975 | res = posix_lock_file_wait(file, fl); |
| 4976 | break; |
| 4977 | case FL_FLOCK: |
| 4978 | res = flock_lock_file_wait(file, fl); |
| 4979 | break; |
| 4980 | default: |
| 4981 | BUG(); |
| 4982 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4983 | return res; |
| 4984 | } |
| 4985 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4986 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4987 | struct nfs_locku_args arg; |
| 4988 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4989 | struct nfs4_lock_state *lsp; |
| 4990 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4991 | struct file_lock fl; |
| 4992 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4993 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4994 | }; |
| 4995 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4996 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4997 | struct nfs_open_context *ctx, |
| 4998 | struct nfs4_lock_state *lsp, |
| 4999 | struct nfs_seqid *seqid) |
| 5000 | { |
| 5001 | struct nfs4_unlockdata *p; |
| 5002 | struct inode *inode = lsp->ls_state->inode; |
| 5003 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5004 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5005 | if (p == NULL) |
| 5006 | return NULL; |
| 5007 | p->arg.fh = NFS_FH(inode); |
| 5008 | p->arg.fl = &p->fl; |
| 5009 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5010 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5011 | p->arg.stateid = &lsp->ls_stateid; |
| 5012 | p->lsp = lsp; |
| 5013 | atomic_inc(&lsp->ls_count); |
| 5014 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5015 | p->ctx = get_nfs_open_context(ctx); |
| 5016 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5017 | p->server = NFS_SERVER(inode); |
| 5018 | return p; |
| 5019 | } |
| 5020 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5021 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5022 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5023 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5024 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5025 | nfs4_put_lock_state(calldata->lsp); |
| 5026 | put_nfs_open_context(calldata->ctx); |
| 5027 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5028 | } |
| 5029 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5030 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5031 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5032 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5033 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5034 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5035 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5036 | switch (task->tk_status) { |
| 5037 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5038 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 5039 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5040 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5041 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5042 | case -NFS4ERR_BAD_STATEID: |
| 5043 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5044 | case -NFS4ERR_STALE_STATEID: |
| 5045 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5046 | break; |
| 5047 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5048 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5049 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5050 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5051 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5052 | } |
| 5053 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5054 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5055 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5056 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5057 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5058 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5059 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5060 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5061 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5062 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5063 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5064 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5065 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5066 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5067 | &calldata->res.seq_res, |
| 5068 | task) != 0) |
| 5069 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5070 | return; |
| 5071 | out_no_action: |
| 5072 | task->tk_action = NULL; |
| 5073 | out_wait: |
| 5074 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5075 | } |
| 5076 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5077 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5078 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5079 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5080 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5081 | }; |
| 5082 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5083 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5084 | struct nfs_open_context *ctx, |
| 5085 | struct nfs4_lock_state *lsp, |
| 5086 | struct nfs_seqid *seqid) |
| 5087 | { |
| 5088 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5089 | struct rpc_message msg = { |
| 5090 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5091 | .rpc_cred = ctx->cred, |
| 5092 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5093 | struct rpc_task_setup task_setup_data = { |
| 5094 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5095 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5096 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5097 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5098 | .flags = RPC_TASK_ASYNC, |
| 5099 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5100 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5101 | /* Ensure this is an unlock - when canceling a lock, the |
| 5102 | * canceled lock is passed in, and it won't be an unlock. |
| 5103 | */ |
| 5104 | fl->fl_type = F_UNLCK; |
| 5105 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5106 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5107 | if (data == NULL) { |
| 5108 | nfs_free_seqid(seqid); |
| 5109 | return ERR_PTR(-ENOMEM); |
| 5110 | } |
| 5111 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5112 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5113 | msg.rpc_argp = &data->arg; |
| 5114 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5115 | task_setup_data.callback_data = data; |
| 5116 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5117 | } |
| 5118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5119 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5120 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5121 | struct inode *inode = state->inode; |
| 5122 | struct nfs4_state_owner *sp = state->owner; |
| 5123 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5124 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5125 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5126 | struct rpc_task *task; |
| 5127 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5128 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5129 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5130 | status = nfs4_set_lock_state(state, request); |
| 5131 | /* Unlock _before_ we do the RPC call */ |
| 5132 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5133 | /* Exclude nfs_delegation_claim_locks() */ |
| 5134 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5135 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5136 | down_read(&nfsi->rwsem); |
| 5137 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 5138 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5139 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5140 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5141 | } |
| 5142 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5143 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5144 | if (status != 0) |
| 5145 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5146 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5147 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5148 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5149 | goto out; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5150 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5151 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5152 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5153 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5154 | 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] | 5155 | status = PTR_ERR(task); |
| 5156 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5157 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5158 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5159 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5160 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5161 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5162 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5163 | } |
| 5164 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5165 | struct nfs4_lockdata { |
| 5166 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5167 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5168 | struct nfs4_lock_state *lsp; |
| 5169 | struct nfs_open_context *ctx; |
| 5170 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5171 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5172 | int rpc_status; |
| 5173 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5174 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5175 | }; |
| 5176 | |
| 5177 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5178 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5179 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5180 | { |
| 5181 | struct nfs4_lockdata *p; |
| 5182 | struct inode *inode = lsp->ls_state->inode; |
| 5183 | struct nfs_server *server = NFS_SERVER(inode); |
| 5184 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5185 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5186 | if (p == NULL) |
| 5187 | return NULL; |
| 5188 | |
| 5189 | p->arg.fh = NFS_FH(inode); |
| 5190 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5191 | 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] | 5192 | if (p->arg.open_seqid == NULL) |
| 5193 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5194 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5195 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5196 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5197 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5198 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5199 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5200 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5201 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5202 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5203 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5204 | atomic_inc(&lsp->ls_count); |
| 5205 | p->ctx = get_nfs_open_context(ctx); |
| 5206 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5207 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5208 | out_free_seqid: |
| 5209 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5210 | out_free: |
| 5211 | kfree(p); |
| 5212 | return NULL; |
| 5213 | } |
| 5214 | |
| 5215 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 5216 | { |
| 5217 | struct nfs4_lockdata *data = calldata; |
| 5218 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5219 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5220 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5221 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5222 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5223 | /* Do we need to do an open_to_lock_owner? */ |
| 5224 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5225 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5226 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5227 | } |
Trond Myklebust | 8e472f3 | 2013-04-20 01:30:53 -0400 | [diff] [blame] | 5228 | data->arg.open_stateid = &state->open_stateid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5229 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5230 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5231 | } else |
| 5232 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5233 | if (!nfs4_valid_open_stateid(state)) { |
| 5234 | data->rpc_status = -EBADF; |
| 5235 | task->tk_action = NULL; |
| 5236 | goto out_release_open_seqid; |
| 5237 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5238 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5239 | if (nfs4_setup_sequence(data->server, |
| 5240 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5241 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5242 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5243 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5244 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5245 | nfs_release_seqid(data->arg.open_seqid); |
| 5246 | out_release_lock_seqid: |
| 5247 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5248 | out_wait: |
| 5249 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5250 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5251 | } |
| 5252 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5253 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 5254 | { |
| 5255 | struct nfs4_lockdata *data = calldata; |
| 5256 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5257 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5258 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5259 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5260 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5261 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5262 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5263 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5264 | if (data->rpc_status == 0) |
| 5265 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 5266 | else |
| 5267 | goto out; |
| 5268 | } |
| 5269 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5270 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5271 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 5272 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5273 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5274 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5275 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5276 | } |
| 5277 | |
| 5278 | static void nfs4_lock_release(void *calldata) |
| 5279 | { |
| 5280 | struct nfs4_lockdata *data = calldata; |
| 5281 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5282 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5283 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5284 | if (data->cancelled != 0) { |
| 5285 | struct rpc_task *task; |
| 5286 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 5287 | data->arg.lock_seqid); |
| 5288 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5289 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5290 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5291 | } else |
| 5292 | nfs_free_seqid(data->arg.lock_seqid); |
| 5293 | nfs4_put_lock_state(data->lsp); |
| 5294 | put_nfs_open_context(data->ctx); |
| 5295 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5296 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5297 | } |
| 5298 | |
| 5299 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 5300 | .rpc_call_prepare = nfs4_lock_prepare, |
| 5301 | .rpc_call_done = nfs4_lock_done, |
| 5302 | .rpc_release = nfs4_lock_release, |
| 5303 | }; |
| 5304 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5305 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 5306 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5307 | switch (error) { |
| 5308 | case -NFS4ERR_ADMIN_REVOKED: |
| 5309 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5310 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5311 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5312 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5313 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5314 | break; |
| 5315 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5316 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5317 | case -NFS4ERR_EXPIRED: |
| 5318 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5319 | }; |
| 5320 | } |
| 5321 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5322 | 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] | 5323 | { |
| 5324 | struct nfs4_lockdata *data; |
| 5325 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5326 | struct rpc_message msg = { |
| 5327 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 5328 | .rpc_cred = state->owner->so_cred, |
| 5329 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5330 | struct rpc_task_setup task_setup_data = { |
| 5331 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5332 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5333 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5334 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5335 | .flags = RPC_TASK_ASYNC, |
| 5336 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5337 | int ret; |
| 5338 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5339 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5340 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5341 | fl->fl_u.nfs4_fl.owner, |
| 5342 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5343 | if (data == NULL) |
| 5344 | return -ENOMEM; |
| 5345 | if (IS_SETLKW(cmd)) |
| 5346 | data->arg.block = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5347 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5348 | msg.rpc_argp = &data->arg; |
| 5349 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5350 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5351 | if (recovery_type > NFS_LOCK_NEW) { |
| 5352 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 5353 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 5354 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
| 5355 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5356 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5357 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5358 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5359 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 5360 | if (ret == 0) { |
| 5361 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5362 | if (ret) |
| 5363 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 5364 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5365 | } else |
| 5366 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5367 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5368 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5369 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5370 | } |
| 5371 | |
| 5372 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 5373 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5374 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5375 | struct nfs4_exception exception = { |
| 5376 | .inode = state->inode, |
| 5377 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5378 | int err; |
| 5379 | |
| 5380 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5381 | /* Cache the lock if possible... */ |
| 5382 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5383 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5384 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5385 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5386 | break; |
| 5387 | nfs4_handle_exception(server, err, &exception); |
| 5388 | } while (exception.retry); |
| 5389 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5390 | } |
| 5391 | |
| 5392 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5393 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5394 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5395 | struct nfs4_exception exception = { |
| 5396 | .inode = state->inode, |
| 5397 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5398 | int err; |
| 5399 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5400 | err = nfs4_set_lock_state(state, request); |
| 5401 | if (err != 0) |
| 5402 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5403 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5404 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5405 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5406 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5407 | switch (err) { |
| 5408 | default: |
| 5409 | goto out; |
| 5410 | case -NFS4ERR_GRACE: |
| 5411 | case -NFS4ERR_DELAY: |
| 5412 | nfs4_handle_exception(server, err, &exception); |
| 5413 | err = 0; |
| 5414 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5415 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5416 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5417 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5418 | } |
| 5419 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5420 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5421 | /** |
| 5422 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 5423 | * |
| 5424 | * @state: NFSv4 state for an inode |
| 5425 | * |
| 5426 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 5427 | * Otherwise a negative NFS4ERR value is returned. |
| 5428 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5429 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5430 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5431 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5432 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5433 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5434 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5435 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5436 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5437 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 5438 | |
| 5439 | status = nfs41_test_stateid(server, |
| 5440 | &lsp->ls_stateid, |
| 5441 | cred); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5442 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5443 | /* Free the stateid unless the server |
| 5444 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 5445 | if (status != -NFS4ERR_BAD_STATEID) |
| 5446 | nfs41_free_stateid(server, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5447 | &lsp->ls_stateid, |
| 5448 | cred); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5449 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5450 | ret = status; |
| 5451 | } |
| 5452 | } |
| 5453 | }; |
| 5454 | |
| 5455 | return ret; |
| 5456 | } |
| 5457 | |
| 5458 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5459 | { |
| 5460 | int status = NFS_OK; |
| 5461 | |
| 5462 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 5463 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5464 | if (status != NFS_OK) |
| 5465 | status = nfs4_lock_expired(state, request); |
| 5466 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5467 | } |
| 5468 | #endif |
| 5469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5470 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5471 | { |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5472 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5473 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5474 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5475 | unsigned int seq; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5476 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5477 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5478 | if ((fl_flags & FL_POSIX) && |
| 5479 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 5480 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5481 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5482 | status = nfs4_set_lock_state(state, request); |
| 5483 | if (status != 0) |
| 5484 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5485 | request->fl_flags |= FL_ACCESS; |
| 5486 | status = do_vfs_lock(request->fl_file, request); |
| 5487 | if (status < 0) |
| 5488 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5489 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5490 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5491 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5492 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5493 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 5494 | status = do_vfs_lock(request->fl_file, request); |
| 5495 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5496 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5497 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 5498 | up_read(&nfsi->rwsem); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5499 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5500 | if (status != 0) |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5501 | goto out; |
| 5502 | down_read(&nfsi->rwsem); |
| 5503 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { |
| 5504 | status = -NFS4ERR_DELAY; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5505 | goto out_unlock; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5506 | } |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5507 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5508 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5509 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5510 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 5511 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5512 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5513 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5514 | out: |
| 5515 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5516 | return status; |
| 5517 | } |
| 5518 | |
| 5519 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5520 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5521 | struct nfs4_exception exception = { |
| 5522 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5523 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5524 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5525 | int err; |
| 5526 | |
| 5527 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5528 | err = _nfs4_proc_setlk(state, cmd, request); |
| 5529 | if (err == -NFS4ERR_DENIED) |
| 5530 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5531 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5532 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5533 | } while (exception.retry); |
| 5534 | return err; |
| 5535 | } |
| 5536 | |
| 5537 | static int |
| 5538 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 5539 | { |
| 5540 | struct nfs_open_context *ctx; |
| 5541 | struct nfs4_state *state; |
| 5542 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 5543 | int status; |
| 5544 | |
| 5545 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5546 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5547 | state = ctx->state; |
| 5548 | |
| 5549 | if (request->fl_start < 0 || request->fl_end < 0) |
| 5550 | return -EINVAL; |
| 5551 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5552 | if (IS_GETLK(cmd)) { |
| 5553 | if (state != NULL) |
| 5554 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 5555 | return 0; |
| 5556 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5557 | |
| 5558 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 5559 | return -EINVAL; |
| 5560 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5561 | if (request->fl_type == F_UNLCK) { |
| 5562 | if (state != NULL) |
| 5563 | return nfs4_proc_unlck(state, cmd, request); |
| 5564 | return 0; |
| 5565 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5566 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5567 | if (state == NULL) |
| 5568 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5569 | /* |
| 5570 | * Don't rely on the VFS having checked the file open mode, |
| 5571 | * since it won't do this for flock() locks. |
| 5572 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5573 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5574 | case F_RDLCK: |
| 5575 | if (!(filp->f_mode & FMODE_READ)) |
| 5576 | return -EBADF; |
| 5577 | break; |
| 5578 | case F_WRLCK: |
| 5579 | if (!(filp->f_mode & FMODE_WRITE)) |
| 5580 | return -EBADF; |
| 5581 | } |
| 5582 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5583 | do { |
| 5584 | status = nfs4_proc_setlk(state, cmd, request); |
| 5585 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 5586 | break; |
| 5587 | timeout = nfs4_set_lock_task_retry(timeout); |
| 5588 | status = -ERESTARTSYS; |
| 5589 | if (signalled()) |
| 5590 | break; |
| 5591 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5592 | return status; |
| 5593 | } |
| 5594 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5595 | 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] | 5596 | { |
| 5597 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5598 | int err; |
| 5599 | |
| 5600 | err = nfs4_set_lock_state(state, fl); |
| 5601 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5602 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 5603 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5604 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5605 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5606 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5607 | struct nfs_release_lockowner_data { |
| 5608 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5609 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5610 | struct nfs_release_lockowner_args args; |
| 5611 | }; |
| 5612 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5613 | static void nfs4_release_lockowner_release(void *calldata) |
| 5614 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5615 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5616 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5617 | kfree(calldata); |
| 5618 | } |
| 5619 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5620 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5621 | .rpc_release = nfs4_release_lockowner_release, |
| 5622 | }; |
| 5623 | |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 5624 | 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] | 5625 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5626 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5627 | struct rpc_message msg = { |
| 5628 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5629 | }; |
| 5630 | |
| 5631 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5632 | return -EINVAL; |
| 5633 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5634 | if (!data) |
| 5635 | return -ENOMEM; |
| 5636 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5637 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5638 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5639 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5640 | data->args.lock_owner.s_dev = server->s_dev; |
| 5641 | msg.rpc_argp = &data->args; |
| 5642 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5643 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5644 | } |
| 5645 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5646 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5647 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5648 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5649 | const void *buf, size_t buflen, |
| 5650 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5651 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5652 | if (strcmp(key, "") != 0) |
| 5653 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5654 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5655 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5656 | } |
| 5657 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5658 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5659 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5660 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5661 | if (strcmp(key, "") != 0) |
| 5662 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5663 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5664 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5665 | } |
| 5666 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5667 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5668 | size_t list_len, const char *name, |
| 5669 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5670 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5671 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5672 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5673 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5674 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5675 | |
| 5676 | if (list && len <= list_len) |
| 5677 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5678 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5679 | } |
| 5680 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 5681 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5682 | static inline int nfs4_server_supports_labels(struct nfs_server *server) |
| 5683 | { |
| 5684 | return server->caps & NFS_CAP_SECURITY_LABEL; |
| 5685 | } |
| 5686 | |
| 5687 | static int nfs4_xattr_set_nfs4_label(struct dentry *dentry, const char *key, |
| 5688 | const void *buf, size_t buflen, |
| 5689 | int flags, int type) |
| 5690 | { |
| 5691 | if (security_ismaclabel(key)) |
| 5692 | return nfs4_set_security_label(dentry, buf, buflen); |
| 5693 | |
| 5694 | return -EOPNOTSUPP; |
| 5695 | } |
| 5696 | |
| 5697 | static int nfs4_xattr_get_nfs4_label(struct dentry *dentry, const char *key, |
| 5698 | void *buf, size_t buflen, int type) |
| 5699 | { |
| 5700 | if (security_ismaclabel(key)) |
| 5701 | return nfs4_get_security_label(dentry->d_inode, buf, buflen); |
| 5702 | return -EOPNOTSUPP; |
| 5703 | } |
| 5704 | |
| 5705 | static size_t nfs4_xattr_list_nfs4_label(struct dentry *dentry, char *list, |
| 5706 | size_t list_len, const char *name, |
| 5707 | size_t name_len, int type) |
| 5708 | { |
| 5709 | size_t len = 0; |
| 5710 | |
| 5711 | if (nfs_server_capable(dentry->d_inode, NFS_CAP_SECURITY_LABEL)) { |
| 5712 | len = security_inode_listsecurity(dentry->d_inode, NULL, 0); |
| 5713 | if (list && len <= list_len) |
| 5714 | security_inode_listsecurity(dentry->d_inode, list, len); |
| 5715 | } |
| 5716 | return len; |
| 5717 | } |
| 5718 | |
| 5719 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 5720 | .prefix = XATTR_SECURITY_PREFIX, |
| 5721 | .list = nfs4_xattr_list_nfs4_label, |
| 5722 | .get = nfs4_xattr_get_nfs4_label, |
| 5723 | .set = nfs4_xattr_set_nfs4_label, |
| 5724 | }; |
| 5725 | #endif |
| 5726 | |
| 5727 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5728 | /* |
| 5729 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5730 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5731 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5732 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5733 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5734 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5735 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5736 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5737 | return; |
| 5738 | |
| 5739 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5740 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5741 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5742 | fattr->nlink = 2; |
| 5743 | } |
| 5744 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5745 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5746 | const struct qstr *name, |
| 5747 | struct nfs4_fs_locations *fs_locations, |
| 5748 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5749 | { |
| 5750 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 5751 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5752 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5753 | }; |
| 5754 | struct nfs4_fs_locations_arg args = { |
| 5755 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5756 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5757 | .page = page, |
| 5758 | .bitmask = bitmask, |
| 5759 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5760 | struct nfs4_fs_locations_res res = { |
| 5761 | .fs_locations = fs_locations, |
| 5762 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5763 | struct rpc_message msg = { |
| 5764 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5765 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5766 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5767 | }; |
| 5768 | int status; |
| 5769 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5770 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5771 | |
| 5772 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5773 | * is not supported */ |
| 5774 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5775 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5776 | else |
| 5777 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5778 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5779 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5780 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5781 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5782 | 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] | 5783 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5784 | return status; |
| 5785 | } |
| 5786 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5787 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5788 | const struct qstr *name, |
| 5789 | struct nfs4_fs_locations *fs_locations, |
| 5790 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5791 | { |
| 5792 | struct nfs4_exception exception = { }; |
| 5793 | int err; |
| 5794 | do { |
| 5795 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5796 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5797 | &exception); |
| 5798 | } while (exception.retry); |
| 5799 | return err; |
| 5800 | } |
| 5801 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 5802 | /** |
| 5803 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 5804 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 5805 | */ |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5806 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5807 | { |
| 5808 | int status; |
| 5809 | struct nfs4_secinfo_arg args = { |
| 5810 | .dir_fh = NFS_FH(dir), |
| 5811 | .name = name, |
| 5812 | }; |
| 5813 | struct nfs4_secinfo_res res = { |
| 5814 | .flavors = flavors, |
| 5815 | }; |
| 5816 | struct rpc_message msg = { |
| 5817 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5818 | .rpc_argp = &args, |
| 5819 | .rpc_resp = &res, |
| 5820 | }; |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 5821 | struct rpc_clnt *clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5822 | |
| 5823 | dprintk("NFS call secinfo %s\n", name->name); |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 5824 | 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] | 5825 | dprintk("NFS reply secinfo: %d\n", status); |
| 5826 | return status; |
| 5827 | } |
| 5828 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5829 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5830 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5831 | { |
| 5832 | struct nfs4_exception exception = { }; |
| 5833 | int err; |
| 5834 | do { |
| 5835 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5836 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5837 | &exception); |
| 5838 | } while (exception.retry); |
| 5839 | return err; |
| 5840 | } |
| 5841 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5842 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5843 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5844 | * Check the exchange flags returned by the server for invalid flags, having |
| 5845 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5846 | * DS flags set. |
| 5847 | */ |
| 5848 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5849 | { |
| 5850 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5851 | goto out_inval; |
| 5852 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5853 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5854 | goto out_inval; |
| 5855 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5856 | goto out_inval; |
| 5857 | return NFS_OK; |
| 5858 | out_inval: |
| 5859 | return -NFS4ERR_INVAL; |
| 5860 | } |
| 5861 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5862 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5863 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5864 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5865 | { |
| 5866 | if (a->server_scope_sz == b->server_scope_sz && |
| 5867 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5868 | return true; |
| 5869 | |
| 5870 | return false; |
| 5871 | } |
| 5872 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5873 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5874 | * nfs4_proc_bind_conn_to_session() |
| 5875 | * |
| 5876 | * The 4.1 client currently uses the same TCP connection for the |
| 5877 | * fore and backchannel. |
| 5878 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5879 | 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] | 5880 | { |
| 5881 | int status; |
| 5882 | struct nfs41_bind_conn_to_session_res res; |
| 5883 | struct rpc_message msg = { |
| 5884 | .rpc_proc = |
| 5885 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5886 | .rpc_argp = clp, |
| 5887 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5888 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5889 | }; |
| 5890 | |
| 5891 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5892 | |
| 5893 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5894 | if (unlikely(res.session == NULL)) { |
| 5895 | status = -ENOMEM; |
| 5896 | goto out; |
| 5897 | } |
| 5898 | |
| 5899 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame^] | 5900 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5901 | if (status == 0) { |
| 5902 | if (memcmp(res.session->sess_id.data, |
| 5903 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5904 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5905 | status = -EIO; |
| 5906 | goto out_session; |
| 5907 | } |
| 5908 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5909 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5910 | __func__); |
| 5911 | status = -EIO; |
| 5912 | goto out_session; |
| 5913 | } |
| 5914 | if (res.use_conn_in_rdma_mode) { |
| 5915 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5916 | __func__); |
| 5917 | status = -EIO; |
| 5918 | goto out_session; |
| 5919 | } |
| 5920 | } |
| 5921 | out_session: |
| 5922 | kfree(res.session); |
| 5923 | out: |
| 5924 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5925 | return status; |
| 5926 | } |
| 5927 | |
| 5928 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5929 | * nfs4_proc_exchange_id() |
| 5930 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5931 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5932 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5933 | * Since the clientid has expired, all compounds using sessions |
| 5934 | * associated with the stale clientid will be returning |
| 5935 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5936 | * be in some phase of session reset. |
| 5937 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5938 | 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] | 5939 | { |
| 5940 | nfs4_verifier verifier; |
| 5941 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5942 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5943 | .client = clp, |
Trond Myklebust | 4f0b429 | 2013-05-20 12:24:03 -0400 | [diff] [blame] | 5944 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 5945 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5946 | }; |
| 5947 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5948 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5949 | }; |
| 5950 | int status; |
| 5951 | struct rpc_message msg = { |
| 5952 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5953 | .rpc_argp = &args, |
| 5954 | .rpc_resp = &res, |
| 5955 | .rpc_cred = cred, |
| 5956 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5957 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5958 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5959 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 5960 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5961 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5962 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5963 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5964 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5965 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5966 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5967 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5968 | status = -ENOMEM; |
| 5969 | goto out; |
| 5970 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5971 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5972 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5973 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5974 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5975 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5976 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5977 | } |
| 5978 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5979 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5980 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5981 | status = -ENOMEM; |
| 5982 | goto out_server_scope; |
| 5983 | } |
| 5984 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5985 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame^] | 5986 | trace_nfs4_exchange_id(clp, status); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5987 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5988 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5989 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5990 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5991 | clp->cl_clientid = res.clientid; |
| 5992 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5993 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5994 | clp->cl_seqid = res.seqid; |
| 5995 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5996 | kfree(clp->cl_serverowner); |
| 5997 | clp->cl_serverowner = res.server_owner; |
| 5998 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5999 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6000 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 6001 | kfree(clp->cl_implid); |
| 6002 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6003 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6004 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6005 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6006 | res.server_scope)) { |
| 6007 | dprintk("%s: server_scope mismatch detected\n", |
| 6008 | __func__); |
| 6009 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6010 | kfree(clp->cl_serverscope); |
| 6011 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6012 | } |
| 6013 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6014 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6015 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6016 | goto out; |
| 6017 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6018 | } else |
| 6019 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6020 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6021 | out_server_owner: |
| 6022 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6023 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6024 | kfree(res.server_scope); |
| 6025 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6026 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6027 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6028 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6029 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 6030 | clp->cl_implid->date.seconds, |
| 6031 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6032 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6033 | return status; |
| 6034 | } |
| 6035 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6036 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 6037 | struct rpc_cred *cred) |
| 6038 | { |
| 6039 | struct rpc_message msg = { |
| 6040 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 6041 | .rpc_argp = clp, |
| 6042 | .rpc_cred = cred, |
| 6043 | }; |
| 6044 | int status; |
| 6045 | |
| 6046 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame^] | 6047 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6048 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 6049 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6050 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 6051 | return status; |
| 6052 | } |
| 6053 | |
| 6054 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 6055 | struct rpc_cred *cred) |
| 6056 | { |
| 6057 | unsigned int loop; |
| 6058 | int ret; |
| 6059 | |
| 6060 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 6061 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 6062 | switch (ret) { |
| 6063 | case -NFS4ERR_DELAY: |
| 6064 | case -NFS4ERR_CLIENTID_BUSY: |
| 6065 | ssleep(1); |
| 6066 | break; |
| 6067 | default: |
| 6068 | return ret; |
| 6069 | } |
| 6070 | } |
| 6071 | return 0; |
| 6072 | } |
| 6073 | |
| 6074 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 6075 | { |
| 6076 | struct rpc_cred *cred; |
| 6077 | int ret = 0; |
| 6078 | |
| 6079 | if (clp->cl_mvops->minor_version < 1) |
| 6080 | goto out; |
| 6081 | if (clp->cl_exchange_flags == 0) |
| 6082 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6083 | if (clp->cl_preserve_clid) |
| 6084 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 6085 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6086 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 6087 | if (cred) |
| 6088 | put_rpccred(cred); |
| 6089 | switch (ret) { |
| 6090 | case 0: |
| 6091 | case -NFS4ERR_STALE_CLIENTID: |
| 6092 | clp->cl_exchange_flags = 0; |
| 6093 | } |
| 6094 | out: |
| 6095 | return ret; |
| 6096 | } |
| 6097 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6098 | struct nfs4_get_lease_time_data { |
| 6099 | struct nfs4_get_lease_time_args *args; |
| 6100 | struct nfs4_get_lease_time_res *res; |
| 6101 | struct nfs_client *clp; |
| 6102 | }; |
| 6103 | |
| 6104 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 6105 | void *calldata) |
| 6106 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6107 | struct nfs4_get_lease_time_data *data = |
| 6108 | (struct nfs4_get_lease_time_data *)calldata; |
| 6109 | |
| 6110 | dprintk("--> %s\n", __func__); |
| 6111 | /* just setup sequence, do not trigger session recovery |
| 6112 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6113 | nfs41_setup_sequence(data->clp->cl_session, |
| 6114 | &data->args->la_seq_args, |
| 6115 | &data->res->lr_seq_res, |
| 6116 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6117 | dprintk("<-- %s\n", __func__); |
| 6118 | } |
| 6119 | |
| 6120 | /* |
| 6121 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 6122 | * from sequence operation or clientid errors. |
| 6123 | */ |
| 6124 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 6125 | { |
| 6126 | struct nfs4_get_lease_time_data *data = |
| 6127 | (struct nfs4_get_lease_time_data *)calldata; |
| 6128 | |
| 6129 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6130 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 6131 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6132 | switch (task->tk_status) { |
| 6133 | case -NFS4ERR_DELAY: |
| 6134 | case -NFS4ERR_GRACE: |
| 6135 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 6136 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 6137 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6138 | /* fall through */ |
| 6139 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6140 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6141 | return; |
| 6142 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6143 | dprintk("<-- %s\n", __func__); |
| 6144 | } |
| 6145 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6146 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6147 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 6148 | .rpc_call_done = nfs4_get_lease_time_done, |
| 6149 | }; |
| 6150 | |
| 6151 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 6152 | { |
| 6153 | struct rpc_task *task; |
| 6154 | struct nfs4_get_lease_time_args args; |
| 6155 | struct nfs4_get_lease_time_res res = { |
| 6156 | .lr_fsinfo = fsinfo, |
| 6157 | }; |
| 6158 | struct nfs4_get_lease_time_data data = { |
| 6159 | .args = &args, |
| 6160 | .res = &res, |
| 6161 | .clp = clp, |
| 6162 | }; |
| 6163 | struct rpc_message msg = { |
| 6164 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 6165 | .rpc_argp = &args, |
| 6166 | .rpc_resp = &res, |
| 6167 | }; |
| 6168 | struct rpc_task_setup task_setup = { |
| 6169 | .rpc_client = clp->cl_rpcclient, |
| 6170 | .rpc_message = &msg, |
| 6171 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6172 | .callback_data = &data, |
| 6173 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6174 | }; |
| 6175 | int status; |
| 6176 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6177 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6178 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6179 | dprintk("--> %s\n", __func__); |
| 6180 | task = rpc_run_task(&task_setup); |
| 6181 | |
| 6182 | if (IS_ERR(task)) |
| 6183 | status = PTR_ERR(task); |
| 6184 | else { |
| 6185 | status = task->tk_status; |
| 6186 | rpc_put_task(task); |
| 6187 | } |
| 6188 | dprintk("<-- %s return %d\n", __func__, status); |
| 6189 | |
| 6190 | return status; |
| 6191 | } |
| 6192 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6193 | /* |
| 6194 | * Initialize the values to be used by the client in CREATE_SESSION |
| 6195 | * If nfs4_init_session set the fore channel request and response sizes, |
| 6196 | * use them. |
| 6197 | * |
| 6198 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 6199 | * always set csa_cachethis to FALSE because the current implementation |
| 6200 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 6201 | */ |
| 6202 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 6203 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 6204 | unsigned int max_rqst_sz, max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6205 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 6206 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 6207 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 6208 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6209 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 6210 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 6211 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6212 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 6213 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6214 | |
| 6215 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 6216 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6217 | __func__, |
| 6218 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 6219 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6220 | |
| 6221 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6222 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 6223 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 6224 | args->bc_attrs.max_resp_sz_cached = 0; |
| 6225 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 6226 | args->bc_attrs.max_reqs = 1; |
| 6227 | |
| 6228 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 6229 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 6230 | __func__, |
| 6231 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 6232 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 6233 | args->bc_attrs.max_reqs); |
| 6234 | } |
| 6235 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6236 | 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] | 6237 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6238 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 6239 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 6240 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6241 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 6242 | return -EINVAL; |
| 6243 | /* |
| 6244 | * Our requested max_ops is the minimum we need; we're not |
| 6245 | * prepared to break up compounds into smaller pieces than that. |
| 6246 | * So, no point even trying to continue if the server won't |
| 6247 | * cooperate: |
| 6248 | */ |
| 6249 | if (rcvd->max_ops < sent->max_ops) |
| 6250 | return -EINVAL; |
| 6251 | if (rcvd->max_reqs == 0) |
| 6252 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6253 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 6254 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6255 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6256 | } |
| 6257 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6258 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 6259 | { |
| 6260 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 6261 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6262 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6263 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 6264 | return -EINVAL; |
| 6265 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 6266 | return -EINVAL; |
| 6267 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 6268 | return -EINVAL; |
| 6269 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6270 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6271 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6272 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6273 | return -EINVAL; |
| 6274 | return 0; |
| 6275 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6276 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6277 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 6278 | struct nfs4_session *session) |
| 6279 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6280 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6281 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6282 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 6283 | if (ret) |
| 6284 | return ret; |
| 6285 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6286 | } |
| 6287 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6288 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 6289 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6290 | { |
| 6291 | struct nfs4_session *session = clp->cl_session; |
| 6292 | struct nfs41_create_session_args args = { |
| 6293 | .client = clp, |
| 6294 | .cb_program = NFS4_CALLBACK, |
| 6295 | }; |
| 6296 | struct nfs41_create_session_res res = { |
| 6297 | .client = clp, |
| 6298 | }; |
| 6299 | struct rpc_message msg = { |
| 6300 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 6301 | .rpc_argp = &args, |
| 6302 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6303 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6304 | }; |
| 6305 | int status; |
| 6306 | |
| 6307 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 6308 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6309 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6310 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame^] | 6311 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6312 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 6313 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6314 | /* Verify the session's negotiated channel_attrs values */ |
| 6315 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6316 | /* Increment the clientid slot sequence id */ |
| 6317 | clp->cl_seqid++; |
| 6318 | } |
| 6319 | |
| 6320 | return status; |
| 6321 | } |
| 6322 | |
| 6323 | /* |
| 6324 | * Issues a CREATE_SESSION operation to the server. |
| 6325 | * It is the responsibility of the caller to verify the session is |
| 6326 | * expired before calling this routine. |
| 6327 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6328 | 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] | 6329 | { |
| 6330 | int status; |
| 6331 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6332 | struct nfs4_session *session = clp->cl_session; |
| 6333 | |
| 6334 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 6335 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6336 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6337 | if (status) |
| 6338 | goto out; |
| 6339 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 6340 | /* Init or reset the session slot tables */ |
| 6341 | status = nfs4_setup_session_slot_tables(session); |
| 6342 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6343 | if (status) |
| 6344 | goto out; |
| 6345 | |
| 6346 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 6347 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 6348 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6349 | out: |
| 6350 | dprintk("<-- %s\n", __func__); |
| 6351 | return status; |
| 6352 | } |
| 6353 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6354 | /* |
| 6355 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 6356 | * The caller must serialize access to this routine. |
| 6357 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6358 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 6359 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6360 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6361 | struct rpc_message msg = { |
| 6362 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 6363 | .rpc_argp = session, |
| 6364 | .rpc_cred = cred, |
| 6365 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6366 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6367 | |
| 6368 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 6369 | |
| 6370 | /* session is still being setup */ |
| 6371 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 6372 | return status; |
| 6373 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6374 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame^] | 6375 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6376 | |
| 6377 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 6378 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6379 | "Session has been destroyed regardless...\n", status); |
| 6380 | |
| 6381 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 6382 | return status; |
| 6383 | } |
| 6384 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6385 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6386 | * Renew the cl_session lease. |
| 6387 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6388 | struct nfs4_sequence_data { |
| 6389 | struct nfs_client *clp; |
| 6390 | struct nfs4_sequence_args args; |
| 6391 | struct nfs4_sequence_res res; |
| 6392 | }; |
| 6393 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6394 | static void nfs41_sequence_release(void *data) |
| 6395 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6396 | struct nfs4_sequence_data *calldata = data; |
| 6397 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6398 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6399 | if (atomic_read(&clp->cl_count) > 1) |
| 6400 | nfs4_schedule_state_renewal(clp); |
| 6401 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6402 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6403 | } |
| 6404 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6405 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6406 | { |
| 6407 | switch(task->tk_status) { |
| 6408 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6409 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 6410 | return -EAGAIN; |
| 6411 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6412 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6413 | } |
| 6414 | return 0; |
| 6415 | } |
| 6416 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6417 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6418 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6419 | struct nfs4_sequence_data *calldata = data; |
| 6420 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6421 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6422 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 6423 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6424 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame^] | 6425 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6426 | if (task->tk_status < 0) { |
| 6427 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6428 | if (atomic_read(&clp->cl_count) == 1) |
| 6429 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6430 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6431 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 6432 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6433 | return; |
| 6434 | } |
| 6435 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6436 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6437 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6438 | dprintk("<-- %s\n", __func__); |
| 6439 | } |
| 6440 | |
| 6441 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 6442 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6443 | struct nfs4_sequence_data *calldata = data; |
| 6444 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6445 | struct nfs4_sequence_args *args; |
| 6446 | struct nfs4_sequence_res *res; |
| 6447 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6448 | args = task->tk_msg.rpc_argp; |
| 6449 | res = task->tk_msg.rpc_resp; |
| 6450 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6451 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6452 | } |
| 6453 | |
| 6454 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 6455 | .rpc_call_done = nfs41_sequence_call_done, |
| 6456 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6457 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6458 | }; |
| 6459 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6460 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 6461 | struct rpc_cred *cred, |
| 6462 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6463 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6464 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6465 | struct rpc_message msg = { |
| 6466 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 6467 | .rpc_cred = cred, |
| 6468 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6469 | struct rpc_task_setup task_setup_data = { |
| 6470 | .rpc_client = clp->cl_rpcclient, |
| 6471 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6472 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 6473 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6474 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6475 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6476 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6477 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 6478 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6479 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6480 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6481 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6482 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6483 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6484 | if (is_privileged) |
| 6485 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6486 | msg.rpc_argp = &calldata->args; |
| 6487 | msg.rpc_resp = &calldata->res; |
| 6488 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6489 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6490 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6491 | return rpc_run_task(&task_setup_data); |
| 6492 | } |
| 6493 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6494 | 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] | 6495 | { |
| 6496 | struct rpc_task *task; |
| 6497 | int ret = 0; |
| 6498 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6499 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 6500 | return 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6501 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6502 | if (IS_ERR(task)) |
| 6503 | ret = PTR_ERR(task); |
| 6504 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6505 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6506 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6507 | return ret; |
| 6508 | } |
| 6509 | |
| 6510 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 6511 | { |
| 6512 | struct rpc_task *task; |
| 6513 | int ret; |
| 6514 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6515 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6516 | if (IS_ERR(task)) { |
| 6517 | ret = PTR_ERR(task); |
| 6518 | goto out; |
| 6519 | } |
| 6520 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6521 | if (!ret) { |
| 6522 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 6523 | |
| 6524 | if (task->tk_status == 0) |
| 6525 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6526 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6527 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6528 | rpc_put_task(task); |
| 6529 | out: |
| 6530 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6531 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6532 | } |
| 6533 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6534 | struct nfs4_reclaim_complete_data { |
| 6535 | struct nfs_client *clp; |
| 6536 | struct nfs41_reclaim_complete_args arg; |
| 6537 | struct nfs41_reclaim_complete_res res; |
| 6538 | }; |
| 6539 | |
| 6540 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 6541 | { |
| 6542 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6543 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6544 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 6545 | &calldata->arg.seq_args, |
| 6546 | &calldata->res.seq_res, |
| 6547 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6548 | } |
| 6549 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6550 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6551 | { |
| 6552 | switch(task->tk_status) { |
| 6553 | case 0: |
| 6554 | case -NFS4ERR_COMPLETE_ALREADY: |
| 6555 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 6556 | break; |
| 6557 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6558 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6559 | /* fall through */ |
| 6560 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6561 | return -EAGAIN; |
| 6562 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6563 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6564 | } |
| 6565 | return 0; |
| 6566 | } |
| 6567 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6568 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 6569 | { |
| 6570 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6571 | struct nfs_client *clp = calldata->clp; |
| 6572 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 6573 | |
| 6574 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6575 | if (!nfs41_sequence_done(task, res)) |
| 6576 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6577 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame^] | 6578 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6579 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 6580 | rpc_restart_call_prepare(task); |
| 6581 | return; |
| 6582 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6583 | dprintk("<-- %s\n", __func__); |
| 6584 | } |
| 6585 | |
| 6586 | static void nfs4_free_reclaim_complete_data(void *data) |
| 6587 | { |
| 6588 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6589 | |
| 6590 | kfree(calldata); |
| 6591 | } |
| 6592 | |
| 6593 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 6594 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 6595 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 6596 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 6597 | }; |
| 6598 | |
| 6599 | /* |
| 6600 | * Issue a global reclaim complete. |
| 6601 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 6602 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 6603 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6604 | { |
| 6605 | struct nfs4_reclaim_complete_data *calldata; |
| 6606 | struct rpc_task *task; |
| 6607 | struct rpc_message msg = { |
| 6608 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 6609 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6610 | }; |
| 6611 | struct rpc_task_setup task_setup_data = { |
| 6612 | .rpc_client = clp->cl_rpcclient, |
| 6613 | .rpc_message = &msg, |
| 6614 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 6615 | .flags = RPC_TASK_ASYNC, |
| 6616 | }; |
| 6617 | int status = -ENOMEM; |
| 6618 | |
| 6619 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6620 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6621 | if (calldata == NULL) |
| 6622 | goto out; |
| 6623 | calldata->clp = clp; |
| 6624 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6625 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6626 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6627 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6628 | msg.rpc_argp = &calldata->arg; |
| 6629 | msg.rpc_resp = &calldata->res; |
| 6630 | task_setup_data.callback_data = calldata; |
| 6631 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6632 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6633 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6634 | goto out; |
| 6635 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6636 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6637 | if (status == 0) |
| 6638 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6639 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6640 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6641 | out: |
| 6642 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6643 | return status; |
| 6644 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6645 | |
| 6646 | static void |
| 6647 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6648 | { |
| 6649 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6650 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6651 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6652 | |
| 6653 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6654 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6655 | * right now covering the LAYOUTGET we are about to send. |
| 6656 | * However, that is not so catastrophic, and there seems |
| 6657 | * to be no way to prevent it completely. |
| 6658 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6659 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6660 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6661 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6662 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6663 | NFS_I(lgp->args.inode)->layout, |
| 6664 | lgp->args.ctx->state)) { |
| 6665 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6666 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6667 | } |
| 6668 | |
| 6669 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6670 | { |
| 6671 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6672 | struct inode *inode = lgp->args.inode; |
| 6673 | struct nfs_server *server = NFS_SERVER(inode); |
| 6674 | struct pnfs_layout_hdr *lo; |
| 6675 | struct nfs4_state *state = NULL; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6676 | unsigned long timeo, giveup; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6677 | |
| 6678 | dprintk("--> %s\n", __func__); |
| 6679 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6680 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6681 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6682 | |
| 6683 | switch (task->tk_status) { |
| 6684 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6685 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6686 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6687 | case -NFS4ERR_RECALLCONFLICT: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6688 | timeo = rpc_get_timeout(task->tk_client); |
| 6689 | giveup = lgp->args.timestamp + timeo; |
| 6690 | if (time_after(giveup, jiffies)) |
| 6691 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6692 | break; |
| 6693 | case -NFS4ERR_EXPIRED: |
| 6694 | case -NFS4ERR_BAD_STATEID: |
| 6695 | spin_lock(&inode->i_lock); |
| 6696 | lo = NFS_I(inode)->layout; |
| 6697 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6698 | spin_unlock(&inode->i_lock); |
| 6699 | /* If the open stateid was bad, then recover it. */ |
| 6700 | state = lgp->args.ctx->state; |
| 6701 | } else { |
| 6702 | LIST_HEAD(head); |
| 6703 | |
| 6704 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6705 | spin_unlock(&inode->i_lock); |
| 6706 | /* Mark the bad layout state as invalid, then |
| 6707 | * retry using the open stateid. */ |
| 6708 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6709 | } |
| 6710 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6711 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6712 | rpc_restart_call_prepare(task); |
| 6713 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6714 | dprintk("<-- %s\n", __func__); |
| 6715 | } |
| 6716 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6717 | static size_t max_response_pages(struct nfs_server *server) |
| 6718 | { |
| 6719 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6720 | return nfs_page_array_len(0, max_resp_sz); |
| 6721 | } |
| 6722 | |
| 6723 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6724 | { |
| 6725 | int i; |
| 6726 | |
| 6727 | if (!pages) |
| 6728 | return; |
| 6729 | |
| 6730 | for (i = 0; i < size; i++) { |
| 6731 | if (!pages[i]) |
| 6732 | break; |
| 6733 | __free_page(pages[i]); |
| 6734 | } |
| 6735 | kfree(pages); |
| 6736 | } |
| 6737 | |
| 6738 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6739 | { |
| 6740 | struct page **pages; |
| 6741 | int i; |
| 6742 | |
| 6743 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6744 | if (!pages) { |
| 6745 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6746 | return NULL; |
| 6747 | } |
| 6748 | |
| 6749 | for (i = 0; i < size; i++) { |
| 6750 | pages[i] = alloc_page(gfp_flags); |
| 6751 | if (!pages[i]) { |
| 6752 | dprintk("%s: failed to allocate page\n", __func__); |
| 6753 | nfs4_free_pages(pages, size); |
| 6754 | return NULL; |
| 6755 | } |
| 6756 | } |
| 6757 | |
| 6758 | return pages; |
| 6759 | } |
| 6760 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6761 | static void nfs4_layoutget_release(void *calldata) |
| 6762 | { |
| 6763 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6764 | struct inode *inode = lgp->args.inode; |
| 6765 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6766 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6767 | |
| 6768 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6769 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6770 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6771 | put_nfs_open_context(lgp->args.ctx); |
| 6772 | kfree(calldata); |
| 6773 | dprintk("<-- %s\n", __func__); |
| 6774 | } |
| 6775 | |
| 6776 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6777 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6778 | .rpc_call_done = nfs4_layoutget_done, |
| 6779 | .rpc_release = nfs4_layoutget_release, |
| 6780 | }; |
| 6781 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6782 | struct pnfs_layout_segment * |
| 6783 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6784 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6785 | struct inode *inode = lgp->args.inode; |
| 6786 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6787 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6788 | struct rpc_task *task; |
| 6789 | struct rpc_message msg = { |
| 6790 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6791 | .rpc_argp = &lgp->args, |
| 6792 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 6793 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6794 | }; |
| 6795 | struct rpc_task_setup task_setup_data = { |
| 6796 | .rpc_client = server->client, |
| 6797 | .rpc_message = &msg, |
| 6798 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6799 | .callback_data = lgp, |
| 6800 | .flags = RPC_TASK_ASYNC, |
| 6801 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6802 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6803 | int status = 0; |
| 6804 | |
| 6805 | dprintk("--> %s\n", __func__); |
| 6806 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6807 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6808 | if (!lgp->args.layout.pages) { |
| 6809 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6810 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6811 | } |
| 6812 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6813 | lgp->args.timestamp = jiffies; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6814 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6815 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6816 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6817 | 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] | 6818 | |
| 6819 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 6820 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 6821 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6822 | task = rpc_run_task(&task_setup_data); |
| 6823 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6824 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6825 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6826 | if (status == 0) |
| 6827 | status = task->tk_status; |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 6828 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 6829 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6830 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6831 | rpc_put_task(task); |
| 6832 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6833 | if (status) |
| 6834 | return ERR_PTR(status); |
| 6835 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6836 | } |
| 6837 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6838 | static void |
| 6839 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6840 | { |
| 6841 | struct nfs4_layoutreturn *lrp = calldata; |
| 6842 | |
| 6843 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6844 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 6845 | &lrp->args.seq_args, |
| 6846 | &lrp->res.seq_res, |
| 6847 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6848 | } |
| 6849 | |
| 6850 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6851 | { |
| 6852 | struct nfs4_layoutreturn *lrp = calldata; |
| 6853 | struct nfs_server *server; |
| 6854 | |
| 6855 | dprintk("--> %s\n", __func__); |
| 6856 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6857 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6858 | return; |
| 6859 | |
| 6860 | server = NFS_SERVER(lrp->args.inode); |
| 6861 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6862 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6863 | return; |
| 6864 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6865 | dprintk("<-- %s\n", __func__); |
| 6866 | } |
| 6867 | |
| 6868 | static void nfs4_layoutreturn_release(void *calldata) |
| 6869 | { |
| 6870 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6871 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6872 | |
| 6873 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6874 | spin_lock(&lo->plh_inode->i_lock); |
| 6875 | if (lrp->res.lrs_present) |
| 6876 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6877 | lo->plh_block_lgets--; |
| 6878 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6879 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6880 | kfree(calldata); |
| 6881 | dprintk("<-- %s\n", __func__); |
| 6882 | } |
| 6883 | |
| 6884 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6885 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6886 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6887 | .rpc_release = nfs4_layoutreturn_release, |
| 6888 | }; |
| 6889 | |
| 6890 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6891 | { |
| 6892 | struct rpc_task *task; |
| 6893 | struct rpc_message msg = { |
| 6894 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6895 | .rpc_argp = &lrp->args, |
| 6896 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 6897 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6898 | }; |
| 6899 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 6900 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6901 | .rpc_message = &msg, |
| 6902 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6903 | .callback_data = lrp, |
| 6904 | }; |
| 6905 | int status; |
| 6906 | |
| 6907 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6908 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6909 | task = rpc_run_task(&task_setup_data); |
| 6910 | if (IS_ERR(task)) |
| 6911 | return PTR_ERR(task); |
| 6912 | status = task->tk_status; |
| 6913 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6914 | rpc_put_task(task); |
| 6915 | return status; |
| 6916 | } |
| 6917 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6918 | /* |
| 6919 | * Retrieve the list of Data Server devices from the MDS. |
| 6920 | */ |
| 6921 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6922 | const struct nfs_fh *fh, |
| 6923 | struct pnfs_devicelist *devlist) |
| 6924 | { |
| 6925 | struct nfs4_getdevicelist_args args = { |
| 6926 | .fh = fh, |
| 6927 | .layoutclass = server->pnfs_curr_ld->id, |
| 6928 | }; |
| 6929 | struct nfs4_getdevicelist_res res = { |
| 6930 | .devlist = devlist, |
| 6931 | }; |
| 6932 | struct rpc_message msg = { |
| 6933 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6934 | .rpc_argp = &args, |
| 6935 | .rpc_resp = &res, |
| 6936 | }; |
| 6937 | int status; |
| 6938 | |
| 6939 | dprintk("--> %s\n", __func__); |
| 6940 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6941 | &res.seq_res, 0); |
| 6942 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6943 | return status; |
| 6944 | } |
| 6945 | |
| 6946 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6947 | const struct nfs_fh *fh, |
| 6948 | struct pnfs_devicelist *devlist) |
| 6949 | { |
| 6950 | struct nfs4_exception exception = { }; |
| 6951 | int err; |
| 6952 | |
| 6953 | do { |
| 6954 | err = nfs4_handle_exception(server, |
| 6955 | _nfs4_getdevicelist(server, fh, devlist), |
| 6956 | &exception); |
| 6957 | } while (exception.retry); |
| 6958 | |
| 6959 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6960 | err, devlist->num_devs); |
| 6961 | |
| 6962 | return err; |
| 6963 | } |
| 6964 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6965 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6966 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 6967 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 6968 | struct pnfs_device *pdev, |
| 6969 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6970 | { |
| 6971 | struct nfs4_getdeviceinfo_args args = { |
| 6972 | .pdev = pdev, |
| 6973 | }; |
| 6974 | struct nfs4_getdeviceinfo_res res = { |
| 6975 | .pdev = pdev, |
| 6976 | }; |
| 6977 | struct rpc_message msg = { |
| 6978 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6979 | .rpc_argp = &args, |
| 6980 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 6981 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6982 | }; |
| 6983 | int status; |
| 6984 | |
| 6985 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6986 | 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] | 6987 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6988 | |
| 6989 | return status; |
| 6990 | } |
| 6991 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 6992 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 6993 | struct pnfs_device *pdev, |
| 6994 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6995 | { |
| 6996 | struct nfs4_exception exception = { }; |
| 6997 | int err; |
| 6998 | |
| 6999 | do { |
| 7000 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7001 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7002 | &exception); |
| 7003 | } while (exception.retry); |
| 7004 | return err; |
| 7005 | } |
| 7006 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 7007 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7008 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 7009 | { |
| 7010 | struct nfs4_layoutcommit_data *data = calldata; |
| 7011 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7012 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7013 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7014 | nfs41_setup_sequence(session, |
| 7015 | &data->args.seq_args, |
| 7016 | &data->res.seq_res, |
| 7017 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7018 | } |
| 7019 | |
| 7020 | static void |
| 7021 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 7022 | { |
| 7023 | struct nfs4_layoutcommit_data *data = calldata; |
| 7024 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 7025 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7026 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7027 | return; |
| 7028 | |
| 7029 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7030 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 7031 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 7032 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 7033 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7034 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7035 | break; |
| 7036 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7037 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 7038 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7039 | break; |
| 7040 | default: |
| 7041 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 7042 | rpc_restart_call_prepare(task); |
| 7043 | return; |
| 7044 | } |
| 7045 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7046 | } |
| 7047 | |
| 7048 | static void nfs4_layoutcommit_release(void *calldata) |
| 7049 | { |
| 7050 | struct nfs4_layoutcommit_data *data = calldata; |
| 7051 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 7052 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7053 | put_rpccred(data->cred); |
| 7054 | kfree(data); |
| 7055 | } |
| 7056 | |
| 7057 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 7058 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 7059 | .rpc_call_done = nfs4_layoutcommit_done, |
| 7060 | .rpc_release = nfs4_layoutcommit_release, |
| 7061 | }; |
| 7062 | |
| 7063 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 7064 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7065 | { |
| 7066 | struct rpc_message msg = { |
| 7067 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 7068 | .rpc_argp = &data->args, |
| 7069 | .rpc_resp = &data->res, |
| 7070 | .rpc_cred = data->cred, |
| 7071 | }; |
| 7072 | struct rpc_task_setup task_setup_data = { |
| 7073 | .task = &data->task, |
| 7074 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 7075 | .rpc_message = &msg, |
| 7076 | .callback_ops = &nfs4_layoutcommit_ops, |
| 7077 | .callback_data = data, |
| 7078 | .flags = RPC_TASK_ASYNC, |
| 7079 | }; |
| 7080 | struct rpc_task *task; |
| 7081 | int status = 0; |
| 7082 | |
| 7083 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 7084 | "lbw: %llu inode %lu\n", |
| 7085 | data->task.tk_pid, sync, |
| 7086 | data->args.lastbytewritten, |
| 7087 | data->args.inode->i_ino); |
| 7088 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 7089 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7090 | task = rpc_run_task(&task_setup_data); |
| 7091 | if (IS_ERR(task)) |
| 7092 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 7093 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7094 | goto out; |
| 7095 | status = nfs4_wait_for_completion_rpc_task(task); |
| 7096 | if (status != 0) |
| 7097 | goto out; |
| 7098 | status = task->tk_status; |
| 7099 | out: |
| 7100 | dprintk("%s: status %d\n", __func__, status); |
| 7101 | rpc_put_task(task); |
| 7102 | return status; |
| 7103 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7104 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 7105 | /** |
| 7106 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 7107 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 7108 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7109 | static int |
| 7110 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 7111 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 7112 | { |
| 7113 | struct nfs41_secinfo_no_name_args args = { |
| 7114 | .style = SECINFO_STYLE_CURRENT_FH, |
| 7115 | }; |
| 7116 | struct nfs4_secinfo_res res = { |
| 7117 | .flavors = flavors, |
| 7118 | }; |
| 7119 | struct rpc_message msg = { |
| 7120 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 7121 | .rpc_argp = &args, |
| 7122 | .rpc_resp = &res, |
| 7123 | }; |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 7124 | return nfs4_call_sync(server->nfs_client->cl_rpcclient, server, &msg, |
| 7125 | &args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7126 | } |
| 7127 | |
| 7128 | static int |
| 7129 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 7130 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 7131 | { |
| 7132 | struct nfs4_exception exception = { }; |
| 7133 | int err; |
| 7134 | do { |
| 7135 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 7136 | switch (err) { |
| 7137 | case 0: |
| 7138 | case -NFS4ERR_WRONGSEC: |
| 7139 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 7140 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7141 | default: |
| 7142 | err = nfs4_handle_exception(server, err, &exception); |
| 7143 | } |
| 7144 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 7145 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7146 | return err; |
| 7147 | } |
| 7148 | |
| 7149 | static int |
| 7150 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 7151 | struct nfs_fsinfo *info) |
| 7152 | { |
| 7153 | int err; |
| 7154 | struct page *page; |
| 7155 | rpc_authflavor_t flavor; |
| 7156 | struct nfs4_secinfo_flavors *flavors; |
| 7157 | |
| 7158 | page = alloc_page(GFP_KERNEL); |
| 7159 | if (!page) { |
| 7160 | err = -ENOMEM; |
| 7161 | goto out; |
| 7162 | } |
| 7163 | |
| 7164 | flavors = page_address(page); |
| 7165 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 7166 | |
| 7167 | /* |
| 7168 | * Fall back on "guess and check" method if |
| 7169 | * the server doesn't support SECINFO_NO_NAME |
| 7170 | */ |
| 7171 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 7172 | err = nfs4_find_root_sec(server, fhandle, info); |
| 7173 | goto out_freepage; |
| 7174 | } |
| 7175 | if (err) |
| 7176 | goto out_freepage; |
| 7177 | |
| 7178 | flavor = nfs_find_best_sec(flavors); |
| 7179 | if (err == 0) |
| 7180 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 7181 | |
| 7182 | out_freepage: |
| 7183 | put_page(page); |
| 7184 | if (err == -EACCES) |
| 7185 | return -EPERM; |
| 7186 | out: |
| 7187 | return err; |
| 7188 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7189 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7190 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 7191 | nfs4_stateid *stateid, |
| 7192 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7193 | { |
| 7194 | int status; |
| 7195 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7196 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7197 | }; |
| 7198 | struct nfs41_test_stateid_res res; |
| 7199 | struct rpc_message msg = { |
| 7200 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 7201 | .rpc_argp = &args, |
| 7202 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7203 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7204 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7205 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7206 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 7207 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7208 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7209 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
| 7210 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7211 | if (status != NFS_OK) { |
| 7212 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7213 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7214 | } |
| 7215 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7216 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7217 | } |
| 7218 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7219 | /** |
| 7220 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 7221 | * |
| 7222 | * @server: server / transport on which to perform the operation |
| 7223 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7224 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7225 | * |
| 7226 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 7227 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 7228 | * failed or the state ID is not currently valid. |
| 7229 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7230 | static int nfs41_test_stateid(struct nfs_server *server, |
| 7231 | nfs4_stateid *stateid, |
| 7232 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7233 | { |
| 7234 | struct nfs4_exception exception = { }; |
| 7235 | int err; |
| 7236 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7237 | err = _nfs41_test_stateid(server, stateid, cred); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7238 | if (err != -NFS4ERR_DELAY) |
| 7239 | break; |
| 7240 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7241 | } while (exception.retry); |
| 7242 | return err; |
| 7243 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7244 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7245 | struct nfs_free_stateid_data { |
| 7246 | struct nfs_server *server; |
| 7247 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7248 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7249 | }; |
| 7250 | |
| 7251 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 7252 | { |
| 7253 | struct nfs_free_stateid_data *data = calldata; |
| 7254 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 7255 | &data->args.seq_args, |
| 7256 | &data->res.seq_res, |
| 7257 | task); |
| 7258 | } |
| 7259 | |
| 7260 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 7261 | { |
| 7262 | struct nfs_free_stateid_data *data = calldata; |
| 7263 | |
| 7264 | nfs41_sequence_done(task, &data->res.seq_res); |
| 7265 | |
| 7266 | switch (task->tk_status) { |
| 7267 | case -NFS4ERR_DELAY: |
| 7268 | if (nfs4_async_handle_error(task, data->server, NULL) == -EAGAIN) |
| 7269 | rpc_restart_call_prepare(task); |
| 7270 | } |
| 7271 | } |
| 7272 | |
| 7273 | static void nfs41_free_stateid_release(void *calldata) |
| 7274 | { |
| 7275 | kfree(calldata); |
| 7276 | } |
| 7277 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 7278 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7279 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 7280 | .rpc_call_done = nfs41_free_stateid_done, |
| 7281 | .rpc_release = nfs41_free_stateid_release, |
| 7282 | }; |
| 7283 | |
| 7284 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
| 7285 | nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7286 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7287 | bool privileged) |
| 7288 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7289 | struct rpc_message msg = { |
| 7290 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7291 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7292 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7293 | struct rpc_task_setup task_setup = { |
| 7294 | .rpc_client = server->client, |
| 7295 | .rpc_message = &msg, |
| 7296 | .callback_ops = &nfs41_free_stateid_ops, |
| 7297 | .flags = RPC_TASK_ASYNC, |
| 7298 | }; |
| 7299 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7300 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7301 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7302 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 7303 | if (!data) |
| 7304 | return ERR_PTR(-ENOMEM); |
| 7305 | data->server = server; |
| 7306 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 7307 | |
| 7308 | task_setup.callback_data = data; |
| 7309 | |
| 7310 | msg.rpc_argp = &data->args; |
| 7311 | msg.rpc_resp = &data->res; |
| 7312 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
| 7313 | if (privileged) |
| 7314 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 7315 | |
| 7316 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7317 | } |
| 7318 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7319 | /** |
| 7320 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 7321 | * |
| 7322 | * @server: server / transport on which to perform the operation |
| 7323 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7324 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7325 | * |
| 7326 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 7327 | * negative NFS4ERR value is returned. |
| 7328 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7329 | static int nfs41_free_stateid(struct nfs_server *server, |
| 7330 | nfs4_stateid *stateid, |
| 7331 | struct rpc_cred *cred) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7332 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7333 | struct rpc_task *task; |
| 7334 | int ret; |
| 7335 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7336 | task = _nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7337 | if (IS_ERR(task)) |
| 7338 | return PTR_ERR(task); |
| 7339 | ret = rpc_wait_for_completion_task(task); |
| 7340 | if (!ret) |
| 7341 | ret = task->tk_status; |
| 7342 | rpc_put_task(task); |
| 7343 | return ret; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7344 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7345 | |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7346 | static int nfs41_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp) |
| 7347 | { |
| 7348 | struct rpc_task *task; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7349 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7350 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7351 | task = _nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7352 | nfs4_free_lock_state(server, lsp); |
| 7353 | if (IS_ERR(task)) |
| 7354 | return PTR_ERR(task); |
| 7355 | rpc_put_task(task); |
| 7356 | return 0; |
| 7357 | } |
| 7358 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7359 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 7360 | const nfs4_stateid *s2) |
| 7361 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7362 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7363 | return false; |
| 7364 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7365 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7366 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7367 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7368 | return true; |
| 7369 | |
| 7370 | return false; |
| 7371 | } |
| 7372 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7373 | #endif /* CONFIG_NFS_V4_1 */ |
| 7374 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7375 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 7376 | const nfs4_stateid *s2) |
| 7377 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7378 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7379 | } |
| 7380 | |
| 7381 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7382 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7383 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7384 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7385 | .recover_open = nfs4_open_reclaim, |
| 7386 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7387 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7388 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7389 | }; |
| 7390 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7391 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7392 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7393 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 7394 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 7395 | .recover_open = nfs4_open_reclaim, |
| 7396 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7397 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7398 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7399 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7400 | }; |
| 7401 | #endif /* CONFIG_NFS_V4_1 */ |
| 7402 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7403 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7404 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7405 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7406 | .recover_open = nfs4_open_expired, |
| 7407 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7408 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7409 | }; |
| 7410 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7411 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7412 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7413 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 7414 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7415 | .recover_open = nfs41_open_expired, |
| 7416 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7417 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7418 | }; |
| 7419 | #endif /* CONFIG_NFS_V4_1 */ |
| 7420 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7421 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7422 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7423 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7424 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7425 | }; |
| 7426 | |
| 7427 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7428 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7429 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7430 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7431 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7432 | }; |
| 7433 | #endif |
| 7434 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7435 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 7436 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 7437 | .init_caps = NFS_CAP_READDIRPLUS |
| 7438 | | NFS_CAP_ATOMIC_OPEN |
| 7439 | | NFS_CAP_CHANGE_ATTR |
| 7440 | | NFS_CAP_POSIX_LOCK, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7441 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7442 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7443 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7444 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7445 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 7446 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 7447 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7448 | }; |
| 7449 | |
| 7450 | #if defined(CONFIG_NFS_V4_1) |
| 7451 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 7452 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 7453 | .init_caps = NFS_CAP_READDIRPLUS |
| 7454 | | NFS_CAP_ATOMIC_OPEN |
| 7455 | | NFS_CAP_CHANGE_ATTR |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 7456 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 7457 | | NFS_CAP_STATEID_NFSV41 |
| 7458 | | NFS_CAP_ATOMIC_OPEN_V1, |
Bryan Schumaker | 104287c | 2012-11-12 14:13:13 -0500 | [diff] [blame] | 7459 | .call_sync = nfs4_call_sync_sequence, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7460 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7461 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7462 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7463 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 7464 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 7465 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7466 | }; |
| 7467 | #endif |
| 7468 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7469 | #if defined(CONFIG_NFS_V4_2) |
| 7470 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 7471 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 7472 | .init_caps = NFS_CAP_READDIRPLUS |
| 7473 | | NFS_CAP_ATOMIC_OPEN |
| 7474 | | NFS_CAP_CHANGE_ATTR |
| 7475 | | NFS_CAP_POSIX_LOCK |
| 7476 | | NFS_CAP_STATEID_NFSV41 |
| 7477 | | NFS_CAP_ATOMIC_OPEN_V1, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7478 | .call_sync = nfs4_call_sync_sequence, |
| 7479 | .match_stateid = nfs41_match_stateid, |
| 7480 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 7481 | .free_lock_state = nfs41_free_lock_state, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7482 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 7483 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 7484 | .state_renewal_ops = &nfs41_state_renewal_ops, |
| 7485 | }; |
| 7486 | #endif |
| 7487 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7488 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 7489 | [0] = &nfs_v4_0_minor_ops, |
| 7490 | #if defined(CONFIG_NFS_V4_1) |
| 7491 | [1] = &nfs_v4_1_minor_ops, |
| 7492 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7493 | #if defined(CONFIG_NFS_V4_2) |
| 7494 | [2] = &nfs_v4_2_minor_ops, |
| 7495 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7496 | }; |
| 7497 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 7498 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 7499 | .create = nfs_create, |
| 7500 | .lookup = nfs_lookup, |
| 7501 | .atomic_open = nfs_atomic_open, |
| 7502 | .link = nfs_link, |
| 7503 | .unlink = nfs_unlink, |
| 7504 | .symlink = nfs_symlink, |
| 7505 | .mkdir = nfs_mkdir, |
| 7506 | .rmdir = nfs_rmdir, |
| 7507 | .mknod = nfs_mknod, |
| 7508 | .rename = nfs_rename, |
| 7509 | .permission = nfs_permission, |
| 7510 | .getattr = nfs_getattr, |
| 7511 | .setattr = nfs_setattr, |
| 7512 | .getxattr = generic_getxattr, |
| 7513 | .setxattr = generic_setxattr, |
| 7514 | .listxattr = generic_listxattr, |
| 7515 | .removexattr = generic_removexattr, |
| 7516 | }; |
| 7517 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 7518 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7519 | .permission = nfs_permission, |
| 7520 | .getattr = nfs_getattr, |
| 7521 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7522 | .getxattr = generic_getxattr, |
| 7523 | .setxattr = generic_setxattr, |
| 7524 | .listxattr = generic_listxattr, |
| 7525 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7526 | }; |
| 7527 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 7528 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7529 | .version = 4, /* protocol version */ |
| 7530 | .dentry_ops = &nfs4_dentry_operations, |
| 7531 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7532 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 7533 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7534 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 7535 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 7536 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7537 | .getattr = nfs4_proc_getattr, |
| 7538 | .setattr = nfs4_proc_setattr, |
| 7539 | .lookup = nfs4_proc_lookup, |
| 7540 | .access = nfs4_proc_access, |
| 7541 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7542 | .create = nfs4_proc_create, |
| 7543 | .remove = nfs4_proc_remove, |
| 7544 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 7545 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7546 | .unlink_done = nfs4_proc_unlink_done, |
| 7547 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7548 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 7549 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7550 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7551 | .link = nfs4_proc_link, |
| 7552 | .symlink = nfs4_proc_symlink, |
| 7553 | .mkdir = nfs4_proc_mkdir, |
| 7554 | .rmdir = nfs4_proc_remove, |
| 7555 | .readdir = nfs4_proc_readdir, |
| 7556 | .mknod = nfs4_proc_mknod, |
| 7557 | .statfs = nfs4_proc_statfs, |
| 7558 | .fsinfo = nfs4_proc_fsinfo, |
| 7559 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 7560 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7561 | .decode_dirent = nfs4_decode_dirent, |
| 7562 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 7563 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 7564 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7565 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7566 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 7567 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 7568 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7569 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7570 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 7571 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7572 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7573 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 7574 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 7575 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 7576 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 7577 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 7578 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 7579 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 7580 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7eced | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 7581 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 7582 | .create_server = nfs4_create_server, |
| 7583 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7584 | }; |
| 7585 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7586 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 7587 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 7588 | .list = nfs4_xattr_list_nfs4_acl, |
| 7589 | .get = nfs4_xattr_get_nfs4_acl, |
| 7590 | .set = nfs4_xattr_set_nfs4_acl, |
| 7591 | }; |
| 7592 | |
| 7593 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 7594 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7595 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 7596 | &nfs4_xattr_nfs4_label_handler, |
| 7597 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7598 | NULL |
| 7599 | }; |
| 7600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7601 | /* |
| 7602 | * Local variables: |
| 7603 | * c-basic-offset: 8 |
| 7604 | * End: |
| 7605 | */ |