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 | |
| 69 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 70 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 71 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 73 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 74 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 75 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 76 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | 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] | 78 | 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] | 79 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 80 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label); |
| 81 | 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] | 82 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 83 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 84 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 85 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 86 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 87 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 88 | struct rpc_cred *); |
| 89 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *, |
| 90 | struct rpc_cred *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 91 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 92 | |
| 93 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 94 | static inline struct nfs4_label * |
| 95 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 96 | struct iattr *sattr, struct nfs4_label *label) |
| 97 | { |
| 98 | int err; |
| 99 | |
| 100 | if (label == NULL) |
| 101 | return NULL; |
| 102 | |
| 103 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 104 | return NULL; |
| 105 | |
| 106 | if (NFS_SERVER(dir)->nfs_client->cl_minorversion < 2) |
| 107 | return NULL; |
| 108 | |
| 109 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 110 | &dentry->d_name, (void **)&label->label, &label->len); |
| 111 | if (err == 0) |
| 112 | return label; |
| 113 | |
| 114 | return NULL; |
| 115 | } |
| 116 | static inline void |
| 117 | nfs4_label_release_security(struct nfs4_label *label) |
| 118 | { |
| 119 | if (label) |
| 120 | security_release_secctx(label->label, label->len); |
| 121 | } |
| 122 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 123 | { |
| 124 | if (label) |
| 125 | return server->attr_bitmask; |
| 126 | |
| 127 | return server->attr_bitmask_nl; |
| 128 | } |
| 129 | #else |
| 130 | static inline struct nfs4_label * |
| 131 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 132 | struct iattr *sattr, struct nfs4_label *l) |
| 133 | { return NULL; } |
| 134 | static inline void |
| 135 | nfs4_label_release_security(struct nfs4_label *label) |
| 136 | { return; } |
| 137 | static inline u32 * |
| 138 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 139 | { return server->attr_bitmask; } |
| 140 | #endif |
| 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 143 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 145 | if (err >= -1000) |
| 146 | return err; |
| 147 | switch (err) { |
| 148 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 149 | case -NFS4ERR_LAYOUTTRYLATER: |
| 150 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 151 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 152 | case -NFS4ERR_WRONGSEC: |
| 153 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 154 | case -NFS4ERR_BADOWNER: |
| 155 | case -NFS4ERR_BADNAME: |
| 156 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 157 | case -NFS4ERR_SHARE_DENIED: |
| 158 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 159 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 160 | return -EPROTONOSUPPORT; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 161 | case -NFS4ERR_ACCESS: |
| 162 | return -EACCES; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 163 | case -NFS4ERR_FILE_OPEN: |
| 164 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 165 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 167 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 168 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 170 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /* |
| 174 | * This is our standard bitmap for GETATTR requests. |
| 175 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 176 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | FATTR4_WORD0_TYPE |
| 178 | | FATTR4_WORD0_CHANGE |
| 179 | | FATTR4_WORD0_SIZE |
| 180 | | FATTR4_WORD0_FSID |
| 181 | | FATTR4_WORD0_FILEID, |
| 182 | FATTR4_WORD1_MODE |
| 183 | | FATTR4_WORD1_NUMLINKS |
| 184 | | FATTR4_WORD1_OWNER |
| 185 | | FATTR4_WORD1_OWNER_GROUP |
| 186 | | FATTR4_WORD1_RAWDEV |
| 187 | | FATTR4_WORD1_SPACE_USED |
| 188 | | FATTR4_WORD1_TIME_ACCESS |
| 189 | | FATTR4_WORD1_TIME_METADATA |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 190 | | FATTR4_WORD1_TIME_MODIFY, |
| 191 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 192 | FATTR4_WORD2_SECURITY_LABEL |
| 193 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | }; |
| 195 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 196 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 197 | FATTR4_WORD0_TYPE |
| 198 | | FATTR4_WORD0_CHANGE |
| 199 | | FATTR4_WORD0_SIZE |
| 200 | | FATTR4_WORD0_FSID |
| 201 | | FATTR4_WORD0_FILEID, |
| 202 | FATTR4_WORD1_MODE |
| 203 | | FATTR4_WORD1_NUMLINKS |
| 204 | | FATTR4_WORD1_OWNER |
| 205 | | FATTR4_WORD1_OWNER_GROUP |
| 206 | | FATTR4_WORD1_RAWDEV |
| 207 | | FATTR4_WORD1_SPACE_USED |
| 208 | | FATTR4_WORD1_TIME_ACCESS |
| 209 | | FATTR4_WORD1_TIME_METADATA |
| 210 | | FATTR4_WORD1_TIME_MODIFY, |
| 211 | FATTR4_WORD2_MDSTHRESHOLD |
| 212 | }; |
| 213 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 214 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 215 | FATTR4_WORD0_TYPE |
| 216 | | FATTR4_WORD0_CHANGE |
| 217 | | FATTR4_WORD0_FILEID, |
| 218 | }; |
| 219 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 220 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | FATTR4_WORD0_FILES_AVAIL |
| 222 | | FATTR4_WORD0_FILES_FREE |
| 223 | | FATTR4_WORD0_FILES_TOTAL, |
| 224 | FATTR4_WORD1_SPACE_AVAIL |
| 225 | | FATTR4_WORD1_SPACE_FREE |
| 226 | | FATTR4_WORD1_SPACE_TOTAL |
| 227 | }; |
| 228 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 229 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | FATTR4_WORD0_MAXLINK |
| 231 | | FATTR4_WORD0_MAXNAME, |
| 232 | 0 |
| 233 | }; |
| 234 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 235 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | | FATTR4_WORD0_MAXREAD |
| 237 | | FATTR4_WORD0_MAXWRITE |
| 238 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 239 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 240 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 241 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | }; |
| 243 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 244 | const u32 nfs4_fs_locations_bitmap[3] = { |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 245 | FATTR4_WORD0_TYPE |
| 246 | | FATTR4_WORD0_CHANGE |
| 247 | | FATTR4_WORD0_SIZE |
| 248 | | FATTR4_WORD0_FSID |
| 249 | | FATTR4_WORD0_FILEID |
| 250 | | FATTR4_WORD0_FS_LOCATIONS, |
| 251 | FATTR4_WORD1_MODE |
| 252 | | FATTR4_WORD1_NUMLINKS |
| 253 | | FATTR4_WORD1_OWNER |
| 254 | | FATTR4_WORD1_OWNER_GROUP |
| 255 | | FATTR4_WORD1_RAWDEV |
| 256 | | FATTR4_WORD1_SPACE_USED |
| 257 | | FATTR4_WORD1_TIME_ACCESS |
| 258 | | FATTR4_WORD1_TIME_METADATA |
| 259 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 260 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 261 | }; |
| 262 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 263 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | struct nfs4_readdir_arg *readdir) |
| 265 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 266 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 269 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 271 | return; |
| 272 | } |
| 273 | |
| 274 | readdir->cookie = 0; |
| 275 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 276 | if (cookie == 2) |
| 277 | return; |
| 278 | |
| 279 | /* |
| 280 | * NFSv4 servers do not return entries for '.' and '..' |
| 281 | * Therefore, we fake these entries here. We let '.' |
| 282 | * have cookie 0 and '..' have cookie 1. Note that |
| 283 | * when talking to the server, we always send cookie 0 |
| 284 | * instead of 1 or 2. |
| 285 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 286 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
| 288 | if (cookie == 0) { |
| 289 | *p++ = xdr_one; /* next */ |
| 290 | *p++ = xdr_zero; /* cookie, first word */ |
| 291 | *p++ = xdr_one; /* cookie, second word */ |
| 292 | *p++ = xdr_one; /* entry len */ |
| 293 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 294 | p++; |
| 295 | *p++ = xdr_one; /* bitmap length */ |
| 296 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 297 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 298 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | *p++ = xdr_one; /* next */ |
| 302 | *p++ = xdr_zero; /* cookie, first word */ |
| 303 | *p++ = xdr_two; /* cookie, second word */ |
| 304 | *p++ = xdr_two; /* entry len */ |
| 305 | memcpy(p, "..\0\0", 4); /* entry */ |
| 306 | p++; |
| 307 | *p++ = xdr_one; /* bitmap length */ |
| 308 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 309 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 310 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
| 312 | readdir->pgbase = (char *)p - (char *)start; |
| 313 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 314 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 317 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 318 | { |
| 319 | int res = 0; |
| 320 | |
| 321 | might_sleep(); |
| 322 | |
| 323 | if (*timeout <= 0) |
| 324 | *timeout = NFS4_POLL_RETRY_MIN; |
| 325 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 326 | *timeout = NFS4_POLL_RETRY_MAX; |
Colin Cross | 416ad3c | 2013-05-06 23:50:06 +0000 | [diff] [blame] | 327 | freezable_schedule_timeout_killable_unsafe(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 328 | if (fatal_signal_pending(current)) |
| 329 | res = -ERESTARTSYS; |
| 330 | *timeout <<= 1; |
| 331 | return res; |
| 332 | } |
| 333 | |
| 334 | /* This is the error handling routine for processes that are allowed |
| 335 | * to sleep. |
| 336 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 337 | 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] | 338 | { |
| 339 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 340 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 341 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 342 | int ret = errorcode; |
| 343 | |
| 344 | exception->retry = 0; |
| 345 | switch(errorcode) { |
| 346 | case 0: |
| 347 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 348 | case -NFS4ERR_OPENMODE: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 349 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 350 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 351 | exception->retry = 1; |
| 352 | return 0; |
| 353 | } |
| 354 | if (state == NULL) |
| 355 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 356 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 357 | if (ret < 0) |
| 358 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 359 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 360 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 361 | case -NFS4ERR_ADMIN_REVOKED: |
| 362 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | b570a97 | 2013-04-12 15:04:51 -0400 | [diff] [blame] | 363 | if (inode != NULL && nfs4_have_delegation(inode, FMODE_READ)) { |
| 364 | nfs_remove_bad_delegation(inode); |
| 365 | exception->retry = 1; |
| 366 | break; |
| 367 | } |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 368 | if (state == NULL) |
| 369 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 370 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 371 | if (ret < 0) |
| 372 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 373 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 374 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 375 | if (state != NULL) { |
| 376 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 377 | if (ret < 0) |
| 378 | break; |
| 379 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 380 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 381 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 382 | nfs4_schedule_lease_recovery(clp); |
| 383 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 384 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 385 | case -NFS4ERR_BADSESSION: |
| 386 | case -NFS4ERR_BADSLOT: |
| 387 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 388 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 389 | case -NFS4ERR_DEADSESSION: |
| 390 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 391 | case -NFS4ERR_SEQ_MISORDERED: |
| 392 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 393 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 394 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 395 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 396 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 397 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 398 | if (exception->timeout > HZ) { |
| 399 | /* We have retried a decent amount, time to |
| 400 | * fail |
| 401 | */ |
| 402 | ret = -EBUSY; |
| 403 | break; |
| 404 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 405 | case -NFS4ERR_GRACE: |
| 406 | case -NFS4ERR_DELAY: |
| 407 | ret = nfs4_delay(server->client, &exception->timeout); |
| 408 | if (ret != 0) |
| 409 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 410 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 411 | case -NFS4ERR_OLD_STATEID: |
| 412 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 413 | break; |
| 414 | case -NFS4ERR_BADOWNER: |
| 415 | /* The following works around a Linux server bug! */ |
| 416 | case -NFS4ERR_BADNAME: |
| 417 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 418 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 419 | exception->retry = 1; |
| 420 | printk(KERN_WARNING "NFS: v4 server %s " |
| 421 | "does not accept raw " |
| 422 | "uid/gids. " |
| 423 | "Reenabling the idmapper.\n", |
| 424 | server->nfs_client->cl_hostname); |
| 425 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 426 | } |
| 427 | /* We failed to handle the error */ |
| 428 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 429 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 430 | ret = nfs4_wait_clnt_recover(clp); |
| 431 | if (ret == 0) |
| 432 | exception->retry = 1; |
| 433 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 437 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | spin_lock(&clp->cl_lock); |
| 440 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 441 | clp->cl_last_renewal = timestamp; |
| 442 | spin_unlock(&clp->cl_lock); |
| 443 | } |
| 444 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 445 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 446 | { |
| 447 | do_renew_lease(server->nfs_client, timestamp); |
| 448 | } |
| 449 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 450 | #if defined(CONFIG_NFS_V4_1) |
| 451 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 452 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 453 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 454 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 455 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 456 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 457 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 458 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 459 | /* just wake up the next guy waiting since |
| 460 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 461 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 462 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 463 | } |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 464 | tbl = res->sr_slot->table; |
| 465 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 466 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 467 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 468 | /* Be nice to the server: try to ensure that the last transmitted |
| 469 | * value for highest_user_slotid <= target_highest_slotid |
| 470 | */ |
| 471 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 472 | send_new_highest_used_slotid = true; |
| 473 | |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 474 | if (nfs41_wake_and_assign_slot(tbl, res->sr_slot)) { |
| 475 | send_new_highest_used_slotid = false; |
| 476 | goto out_unlock; |
| 477 | } |
Trond Myklebust | f4af6e2a | 2012-11-20 14:17:32 -0500 | [diff] [blame] | 478 | nfs4_free_slot(tbl, res->sr_slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 479 | |
| 480 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 481 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 482 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 483 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 484 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 485 | if (send_new_highest_used_slotid) |
| 486 | nfs41_server_notify_highest_slotid_update(session->clp); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 487 | } |
| 488 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 489 | 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] | 490 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 491 | struct nfs4_session *session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 492 | struct nfs4_slot *slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 493 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 494 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 495 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 496 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 497 | /* don't increment the sequence number if the task wasn't sent */ |
| 498 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 499 | goto out; |
| 500 | |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 501 | slot = res->sr_slot; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 502 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 503 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 504 | if (slot->interrupted) { |
| 505 | slot->interrupted = 0; |
| 506 | interrupted = true; |
| 507 | } |
| 508 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 509 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 510 | switch (res->sr_status) { |
| 511 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 512 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 513 | ++slot->seq_nr; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 514 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 515 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 516 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 517 | if (res->sr_status_flags != 0) |
| 518 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 519 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 520 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 521 | case 1: |
| 522 | /* |
| 523 | * sr_status remains 1 if an RPC level error occurred. |
| 524 | * The server may or may not have processed the sequence |
| 525 | * operation.. |
| 526 | * Mark the slot as having hosted an interrupted RPC call. |
| 527 | */ |
| 528 | slot->interrupted = 1; |
| 529 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 530 | case -NFS4ERR_DELAY: |
| 531 | /* The server detected a resend of the RPC call and |
| 532 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 533 | * of RFC5661. |
| 534 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 535 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 536 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 537 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 538 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 539 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 540 | case -NFS4ERR_BADSLOT: |
| 541 | /* |
| 542 | * The slot id we used was probably retired. Try again |
| 543 | * using a different slot id. |
| 544 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 545 | goto retry_nowait; |
| 546 | case -NFS4ERR_SEQ_MISORDERED: |
| 547 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 548 | * Was the last operation on this sequence interrupted? |
| 549 | * If so, retry after bumping the sequence number. |
| 550 | */ |
| 551 | if (interrupted) { |
| 552 | ++slot->seq_nr; |
| 553 | goto retry_nowait; |
| 554 | } |
| 555 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 556 | * Could this slot have been previously retired? |
| 557 | * If so, then the server may be expecting seq_nr = 1! |
| 558 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 559 | if (slot->seq_nr != 1) { |
| 560 | slot->seq_nr = 1; |
| 561 | goto retry_nowait; |
| 562 | } |
| 563 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 564 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 565 | ++slot->seq_nr; |
| 566 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 567 | default: |
| 568 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 569 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 570 | } |
| 571 | out: |
| 572 | /* The session may be reset by one of the error handlers. */ |
| 573 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 574 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 575 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 576 | retry_nowait: |
| 577 | if (rpc_restart_call_prepare(task)) { |
| 578 | task->tk_status = 0; |
| 579 | ret = 0; |
| 580 | } |
| 581 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 582 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 583 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 584 | goto out; |
| 585 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 586 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 587 | } |
| 588 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 589 | static int nfs4_sequence_done(struct rpc_task *task, |
| 590 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 591 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 592 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 593 | return 1; |
| 594 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 595 | } |
| 596 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 597 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 598 | struct nfs4_sequence_res *res, int cache_reply) |
| 599 | { |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 600 | args->sa_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 601 | args->sa_cache_this = 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 602 | args->sa_privileged = 0; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 603 | if (cache_reply) |
| 604 | args->sa_cache_this = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 605 | res->sr_slot = NULL; |
| 606 | } |
| 607 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 608 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 609 | { |
| 610 | args->sa_privileged = 1; |
| 611 | } |
| 612 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 613 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 614 | struct nfs4_sequence_args *args, |
| 615 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 616 | struct rpc_task *task) |
| 617 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 618 | struct nfs4_slot *slot; |
| 619 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 620 | |
| 621 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 622 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 623 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 624 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 625 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 626 | tbl = &session->fc_slot_table; |
| 627 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 628 | task->tk_timeout = 0; |
| 629 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 630 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 631 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 632 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 633 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 634 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 635 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 636 | } |
| 637 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 638 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 639 | if (IS_ERR(slot)) { |
| 640 | /* If out of memory, try again in 1/4 second */ |
| 641 | if (slot == ERR_PTR(-ENOMEM)) |
| 642 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 643 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 644 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 645 | } |
| 646 | spin_unlock(&tbl->slot_tbl_lock); |
| 647 | |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 648 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 649 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 650 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, |
| 651 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 652 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 653 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 654 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 655 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 656 | /* |
| 657 | * sr_status is only set in decode_sequence, and so will remain |
| 658 | * set to 1 if an rpc level failure occurs. |
| 659 | */ |
| 660 | res->sr_status = 1; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 661 | out_success: |
| 662 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 663 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 664 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 665 | /* Privileged tasks are queued with top priority */ |
| 666 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 667 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 668 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 669 | else |
| 670 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 671 | spin_unlock(&tbl->slot_tbl_lock); |
| 672 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 673 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 674 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 675 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 676 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 677 | struct nfs4_sequence_args *args, |
| 678 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 679 | struct rpc_task *task) |
| 680 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 681 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 682 | int ret = 0; |
| 683 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 684 | if (session == NULL) { |
| 685 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 686 | goto out; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 687 | } |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 688 | |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 689 | dprintk("--> %s clp %p session %p sr_slot %d\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 690 | __func__, session->clp, session, res->sr_slot ? |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 691 | res->sr_slot->slot_nr : -1); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 692 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 693 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 694 | out: |
| 695 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 696 | return ret; |
| 697 | } |
| 698 | |
| 699 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 700 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 701 | struct nfs4_sequence_args *seq_args; |
| 702 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 703 | }; |
| 704 | |
| 705 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 706 | { |
| 707 | struct nfs41_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 708 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 709 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 710 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 711 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 712 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 713 | } |
| 714 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 715 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 716 | { |
| 717 | struct nfs41_call_sync_data *data = calldata; |
| 718 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 719 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 720 | } |
| 721 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 722 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 723 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 724 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 725 | }; |
| 726 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 727 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 728 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 729 | struct rpc_message *msg, |
| 730 | struct nfs4_sequence_args *args, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 731 | struct nfs4_sequence_res *res) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 732 | { |
| 733 | int ret; |
| 734 | struct rpc_task *task; |
| 735 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 736 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 737 | .seq_args = args, |
| 738 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 739 | }; |
| 740 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 741 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 742 | .rpc_message = msg, |
| 743 | .callback_ops = &nfs41_call_sync_ops, |
| 744 | .callback_data = &data |
| 745 | }; |
| 746 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 747 | task = rpc_run_task(&task_setup); |
| 748 | if (IS_ERR(task)) |
| 749 | ret = PTR_ERR(task); |
| 750 | else { |
| 751 | ret = task->tk_status; |
| 752 | rpc_put_task(task); |
| 753 | } |
| 754 | return ret; |
| 755 | } |
| 756 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 757 | #else |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 758 | static |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 759 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 760 | struct nfs4_sequence_res *res, int cache_reply) |
| 761 | { |
| 762 | } |
| 763 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 764 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 765 | { |
| 766 | } |
| 767 | |
| 768 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 769 | static int nfs4_sequence_done(struct rpc_task *task, |
| 770 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 771 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 772 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 773 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 774 | #endif /* CONFIG_NFS_V4_1 */ |
| 775 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 776 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 777 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 778 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 779 | struct rpc_message *msg, |
| 780 | struct nfs4_sequence_args *args, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 781 | struct nfs4_sequence_res *res) |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 782 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 783 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 784 | } |
| 785 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 786 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 787 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 788 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 789 | struct rpc_message *msg, |
| 790 | struct nfs4_sequence_args *args, |
| 791 | struct nfs4_sequence_res *res, |
| 792 | int cache_reply) |
| 793 | { |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 794 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 795 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 796 | args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 797 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 798 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 799 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 801 | struct nfs_inode *nfsi = NFS_I(dir); |
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 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 804 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 805 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 806 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 807 | dir->i_version = cinfo->after; |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 808 | nfs_fscache_invalidate(dir); |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 809 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 812 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 813 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 814 | struct nfs_openargs o_arg; |
| 815 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 816 | struct nfs_open_confirmargs c_arg; |
| 817 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 818 | struct nfs4_string owner_name; |
| 819 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 820 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 821 | struct nfs4_label *f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 822 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 823 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 824 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 825 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 826 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 827 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 828 | unsigned int rpc_done : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 829 | unsigned int is_recover : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 830 | int rpc_status; |
| 831 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 832 | }; |
| 833 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 834 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 835 | int err, struct nfs4_exception *exception) |
| 836 | { |
| 837 | if (err != -EINVAL) |
| 838 | return false; |
| 839 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 840 | return false; |
| 841 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 842 | exception->retry = 1; |
| 843 | return true; |
| 844 | } |
| 845 | |
| 846 | static enum open_claim_type4 |
| 847 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 848 | enum open_claim_type4 claim) |
| 849 | { |
| 850 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 851 | return claim; |
| 852 | switch (claim) { |
| 853 | default: |
| 854 | return claim; |
| 855 | case NFS4_OPEN_CLAIM_FH: |
| 856 | return NFS4_OPEN_CLAIM_NULL; |
| 857 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 858 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 859 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 860 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 861 | } |
| 862 | } |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 863 | |
| 864 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 865 | { |
| 866 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 867 | p->o_res.f_label = p->f_label; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 868 | p->o_res.seqid = p->o_arg.seqid; |
| 869 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 870 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 871 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 872 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 873 | 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] | 874 | } |
| 875 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 876 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 877 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 878 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 879 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 880 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 881 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 882 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 883 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 884 | struct inode *dir = parent->d_inode; |
| 885 | struct nfs_server *server = NFS_SERVER(dir); |
| 886 | struct nfs4_opendata *p; |
| 887 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 888 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 889 | if (p == NULL) |
| 890 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 891 | |
| 892 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 893 | if (IS_ERR(p->f_label)) |
| 894 | goto err_free_p; |
| 895 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 896 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 897 | if (p->o_arg.seqid == NULL) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 898 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 899 | nfs_sb_active(dentry->d_sb); |
| 900 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 901 | p->dir = parent; |
| 902 | p->owner = sp; |
| 903 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 904 | p->o_arg.open_flags = flags; |
| 905 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 906 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 907 | * will return permission denied for all bits until close */ |
| 908 | if (!(flags & O_EXCL)) { |
| 909 | /* ask server to check for all possible rights as results |
| 910 | * are cached */ |
| 911 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 912 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 913 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 914 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 915 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 916 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 917 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 918 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 919 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 920 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 921 | p->o_arg.label = label; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 922 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 923 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 924 | case NFS4_OPEN_CLAIM_NULL: |
| 925 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 926 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 927 | p->o_arg.fh = NFS_FH(dir); |
| 928 | break; |
| 929 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 930 | case NFS4_OPEN_CLAIM_FH: |
| 931 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 932 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 933 | p->o_arg.fh = NFS_FH(dentry->d_inode); |
| 934 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 935 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 936 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 937 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 938 | p->o_arg.u.attrs = &p->attrs; |
| 939 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 940 | |
| 941 | verf[0] = jiffies; |
| 942 | verf[1] = current->pid; |
| 943 | memcpy(p->o_arg.u.verifier.data, verf, |
| 944 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 945 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 946 | p->c_arg.fh = &p->o_res.fh; |
| 947 | p->c_arg.stateid = &p->o_res.stateid; |
| 948 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 949 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 950 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 951 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 952 | |
| 953 | err_free_label: |
| 954 | nfs4_label_free(p->f_label); |
| 955 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 956 | kfree(p); |
| 957 | err: |
| 958 | dput(parent); |
| 959 | return NULL; |
| 960 | } |
| 961 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 962 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 963 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 964 | struct nfs4_opendata *p = container_of(kref, |
| 965 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 966 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 967 | |
| 968 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 969 | if (p->state != NULL) |
| 970 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 971 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 972 | |
| 973 | nfs4_label_free(p->f_label); |
| 974 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 975 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 976 | dput(p->dentry); |
| 977 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 978 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 979 | kfree(p); |
| 980 | } |
| 981 | |
| 982 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 983 | { |
| 984 | if (p != NULL) |
| 985 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 986 | } |
| 987 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 988 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 989 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 990 | int ret; |
| 991 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 992 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 993 | return ret; |
| 994 | } |
| 995 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 996 | 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] | 997 | { |
| 998 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 999 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1000 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1001 | goto out; |
| 1002 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1003 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1004 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1005 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1006 | break; |
| 1007 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1008 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1009 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1010 | break; |
| 1011 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1012 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1013 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1014 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1015 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1016 | return ret; |
| 1017 | } |
| 1018 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1019 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1020 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1021 | if (delegation == NULL) |
| 1022 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1023 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1024 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1025 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1026 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1027 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1028 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1029 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1030 | return 1; |
| 1031 | } |
| 1032 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1033 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1034 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1035 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1036 | case FMODE_WRITE: |
| 1037 | state->n_wronly++; |
| 1038 | break; |
| 1039 | case FMODE_READ: |
| 1040 | state->n_rdonly++; |
| 1041 | break; |
| 1042 | case FMODE_READ|FMODE_WRITE: |
| 1043 | state->n_rdwr++; |
| 1044 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1045 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1046 | } |
| 1047 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1048 | 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] | 1049 | { |
| 1050 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1051 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1052 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 92b40e9 | 2013-04-20 01:25:45 -0400 | [diff] [blame] | 1053 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1054 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1055 | case FMODE_READ: |
| 1056 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1057 | break; |
| 1058 | case FMODE_WRITE: |
| 1059 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1060 | break; |
| 1061 | case FMODE_READ|FMODE_WRITE: |
| 1062 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1063 | } |
| 1064 | } |
| 1065 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1066 | 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] | 1067 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1068 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1069 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1070 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1071 | } |
| 1072 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1073 | 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] | 1074 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1075 | /* |
| 1076 | * Protect the call to nfs4_state_set_mode_locked and |
| 1077 | * serialise the stateid update |
| 1078 | */ |
| 1079 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1080 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1081 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1082 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1083 | } |
| 1084 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1085 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1086 | write_sequnlock(&state->seqlock); |
| 1087 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1088 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1089 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1092 | 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] | 1093 | { |
| 1094 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1095 | struct nfs_delegation *deleg_cur; |
| 1096 | int ret = 0; |
| 1097 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1098 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1099 | |
| 1100 | rcu_read_lock(); |
| 1101 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1102 | if (deleg_cur == NULL) |
| 1103 | goto no_delegation; |
| 1104 | |
| 1105 | spin_lock(&deleg_cur->lock); |
| 1106 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1107 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1108 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1109 | goto no_delegation_unlock; |
| 1110 | |
| 1111 | if (delegation == NULL) |
| 1112 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1113 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1114 | goto no_delegation_unlock; |
| 1115 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1116 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1117 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1118 | ret = 1; |
| 1119 | no_delegation_unlock: |
| 1120 | spin_unlock(&deleg_cur->lock); |
| 1121 | no_delegation: |
| 1122 | rcu_read_unlock(); |
| 1123 | |
| 1124 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1125 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1126 | ret = 1; |
| 1127 | } |
| 1128 | |
| 1129 | return ret; |
| 1130 | } |
| 1131 | |
| 1132 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1133 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1134 | { |
| 1135 | struct nfs_delegation *delegation; |
| 1136 | |
| 1137 | rcu_read_lock(); |
| 1138 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1139 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1140 | rcu_read_unlock(); |
| 1141 | return; |
| 1142 | } |
| 1143 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1144 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1145 | } |
| 1146 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1147 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1148 | { |
| 1149 | struct nfs4_state *state = opendata->state; |
| 1150 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1151 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1152 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1153 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1154 | nfs4_stateid stateid; |
| 1155 | int ret = -EAGAIN; |
| 1156 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1157 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1158 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1159 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1160 | if (can_open_cached(state, fmode, open_mode)) { |
| 1161 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1162 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1163 | goto out_return_state; |
| 1164 | } |
| 1165 | spin_unlock(&state->owner->so_lock); |
| 1166 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1167 | rcu_read_lock(); |
| 1168 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1169 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1170 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1171 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1172 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1173 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1174 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1175 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1176 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1177 | if (!opendata->is_recover) { |
| 1178 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1179 | if (ret != 0) |
| 1180 | goto out; |
| 1181 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1182 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1183 | |
| 1184 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1185 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1186 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1187 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1188 | out: |
| 1189 | return ERR_PTR(ret); |
| 1190 | out_return_state: |
| 1191 | atomic_inc(&state->count); |
| 1192 | return state; |
| 1193 | } |
| 1194 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1195 | static void |
| 1196 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1197 | { |
| 1198 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1199 | struct nfs_delegation *delegation; |
| 1200 | int delegation_flags = 0; |
| 1201 | |
| 1202 | rcu_read_lock(); |
| 1203 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1204 | if (delegation) |
| 1205 | delegation_flags = delegation->flags; |
| 1206 | rcu_read_unlock(); |
| 1207 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1208 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1209 | "returning a delegation for " |
| 1210 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1211 | clp->cl_hostname); |
| 1212 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1213 | nfs_inode_set_delegation(state->inode, |
| 1214 | data->owner->so_cred, |
| 1215 | &data->o_res); |
| 1216 | else |
| 1217 | nfs_inode_reclaim_delegation(state->inode, |
| 1218 | data->owner->so_cred, |
| 1219 | &data->o_res); |
| 1220 | } |
| 1221 | |
| 1222 | /* |
| 1223 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1224 | * and update the nfs4_state. |
| 1225 | */ |
| 1226 | static struct nfs4_state * |
| 1227 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1228 | { |
| 1229 | struct inode *inode = data->state->inode; |
| 1230 | struct nfs4_state *state = data->state; |
| 1231 | int ret; |
| 1232 | |
| 1233 | if (!data->rpc_done) { |
| 1234 | ret = data->rpc_status; |
| 1235 | goto err; |
| 1236 | } |
| 1237 | |
| 1238 | ret = -ESTALE; |
| 1239 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || |
| 1240 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || |
| 1241 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) |
| 1242 | goto err; |
| 1243 | |
| 1244 | ret = -ENOMEM; |
| 1245 | state = nfs4_get_open_state(inode, data->owner); |
| 1246 | if (state == NULL) |
| 1247 | goto err; |
| 1248 | |
| 1249 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1250 | if (ret) |
| 1251 | goto err; |
| 1252 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1253 | nfs_setsecurity(inode, &data->f_attr, data->f_label); |
| 1254 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1255 | if (data->o_res.delegation_type != 0) |
| 1256 | nfs4_opendata_check_deleg(data, state); |
| 1257 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1258 | data->o_arg.fmode); |
| 1259 | |
| 1260 | return state; |
| 1261 | err: |
| 1262 | return ERR_PTR(ret); |
| 1263 | |
| 1264 | } |
| 1265 | |
| 1266 | static struct nfs4_state * |
| 1267 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1268 | { |
| 1269 | struct inode *inode; |
| 1270 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1271 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1272 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1273 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1274 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1275 | goto out; |
| 1276 | } |
| 1277 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1278 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1279 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1280 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1281 | 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] | 1282 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1283 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1284 | goto err; |
| 1285 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1286 | state = nfs4_get_open_state(inode, data->owner); |
| 1287 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1288 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1289 | if (data->o_res.delegation_type != 0) |
| 1290 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1291 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1292 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1293 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1294 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1295 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1296 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1297 | err_put_inode: |
| 1298 | iput(inode); |
| 1299 | err: |
| 1300 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1301 | } |
| 1302 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1303 | static struct nfs4_state * |
| 1304 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1305 | { |
| 1306 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1307 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1308 | return _nfs4_opendata_to_nfs4_state(data); |
| 1309 | } |
| 1310 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1311 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1312 | { |
| 1313 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1314 | struct nfs_open_context *ctx; |
| 1315 | |
| 1316 | spin_lock(&state->inode->i_lock); |
| 1317 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1318 | if (ctx->state != state) |
| 1319 | continue; |
| 1320 | get_nfs_open_context(ctx); |
| 1321 | spin_unlock(&state->inode->i_lock); |
| 1322 | return ctx; |
| 1323 | } |
| 1324 | spin_unlock(&state->inode->i_lock); |
| 1325 | return ERR_PTR(-ENOENT); |
| 1326 | } |
| 1327 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1328 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1329 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1330 | { |
| 1331 | struct nfs4_opendata *opendata; |
| 1332 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1333 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1334 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1335 | if (opendata == NULL) |
| 1336 | return ERR_PTR(-ENOMEM); |
| 1337 | opendata->state = state; |
| 1338 | atomic_inc(&state->count); |
| 1339 | return opendata; |
| 1340 | } |
| 1341 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1342 | 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] | 1343 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1344 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1345 | int ret; |
| 1346 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1347 | opendata->o_arg.open_flags = 0; |
| 1348 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1349 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1350 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1351 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1352 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1353 | if (ret != 0) |
| 1354 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1355 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1356 | if (IS_ERR(newstate)) |
| 1357 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1358 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1359 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1360 | return 0; |
| 1361 | } |
| 1362 | |
| 1363 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1364 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1365 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1366 | int ret; |
| 1367 | |
| 1368 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1369 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1370 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1371 | smp_rmb(); |
| 1372 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1373 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1374 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1375 | if (ret != 0) |
| 1376 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1377 | if (newstate != state) |
| 1378 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1379 | } |
| 1380 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1381 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1382 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1383 | if (ret != 0) |
| 1384 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1385 | if (newstate != state) |
| 1386 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1387 | } |
| 1388 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1389 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1390 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1391 | if (ret != 0) |
| 1392 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1393 | if (newstate != state) |
| 1394 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1395 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1396 | /* |
| 1397 | * We may have performed cached opens for all three recoveries. |
| 1398 | * Check if we need to update the current stateid. |
| 1399 | */ |
| 1400 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1401 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1402 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1403 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1404 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1405 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1406 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1407 | return 0; |
| 1408 | } |
| 1409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | /* |
| 1411 | * OPEN_RECLAIM: |
| 1412 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1414 | 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] | 1415 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1416 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1417 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1418 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | int status; |
| 1420 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1421 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1422 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1423 | if (IS_ERR(opendata)) |
| 1424 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1425 | rcu_read_lock(); |
| 1426 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1427 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1428 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1429 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1430 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1431 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1432 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | return status; |
| 1434 | } |
| 1435 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1436 | 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] | 1437 | { |
| 1438 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1439 | struct nfs4_exception exception = { }; |
| 1440 | int err; |
| 1441 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1442 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1443 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1444 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1445 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1446 | break; |
| 1447 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | } while (exception.retry); |
| 1449 | return err; |
| 1450 | } |
| 1451 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1452 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1453 | { |
| 1454 | struct nfs_open_context *ctx; |
| 1455 | int ret; |
| 1456 | |
| 1457 | ctx = nfs4_state_find_open_context(state); |
| 1458 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1459 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1460 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1461 | put_nfs_open_context(ctx); |
| 1462 | return ret; |
| 1463 | } |
| 1464 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1465 | 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] | 1466 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1467 | switch (err) { |
| 1468 | default: |
| 1469 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1470 | "%d.\n", __func__, err); |
| 1471 | case 0: |
| 1472 | case -ENOENT: |
| 1473 | case -ESTALE: |
| 1474 | break; |
| 1475 | case -NFS4ERR_BADSESSION: |
| 1476 | case -NFS4ERR_BADSLOT: |
| 1477 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1478 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1479 | case -NFS4ERR_DEADSESSION: |
| 1480 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1481 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1482 | return -EAGAIN; |
| 1483 | case -NFS4ERR_STALE_CLIENTID: |
| 1484 | case -NFS4ERR_STALE_STATEID: |
| 1485 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1486 | case -NFS4ERR_EXPIRED: |
| 1487 | /* Don't recall a delegation if it was lost */ |
| 1488 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1489 | return -EAGAIN; |
| 1490 | case -NFS4ERR_DELEG_REVOKED: |
| 1491 | case -NFS4ERR_ADMIN_REVOKED: |
| 1492 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1493 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1494 | nfs_inode_find_state_and_recover(state->inode, |
| 1495 | stateid); |
| 1496 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1497 | return 0; |
| 1498 | case -NFS4ERR_DELAY: |
| 1499 | case -NFS4ERR_GRACE: |
| 1500 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1501 | ssleep(1); |
| 1502 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1503 | case -ENOMEM: |
| 1504 | case -NFS4ERR_DENIED: |
| 1505 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1506 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1507 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | return err; |
| 1509 | } |
| 1510 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1511 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
| 1512 | { |
| 1513 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1514 | struct nfs4_opendata *opendata; |
| 1515 | int err; |
| 1516 | |
| 1517 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1518 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1519 | if (IS_ERR(opendata)) |
| 1520 | return PTR_ERR(opendata); |
| 1521 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
| 1522 | err = nfs4_open_recover(opendata, state); |
| 1523 | nfs4_opendata_put(opendata); |
| 1524 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1525 | } |
| 1526 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1527 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1528 | { |
| 1529 | struct nfs4_opendata *data = calldata; |
| 1530 | |
| 1531 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1532 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1533 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1534 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1535 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1536 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1537 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | static void nfs4_open_confirm_release(void *calldata) |
| 1541 | { |
| 1542 | struct nfs4_opendata *data = calldata; |
| 1543 | struct nfs4_state *state = NULL; |
| 1544 | |
| 1545 | /* If this request hasn't been cancelled, do nothing */ |
| 1546 | if (data->cancelled == 0) |
| 1547 | goto out_free; |
| 1548 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1549 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1550 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1551 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1552 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1553 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1554 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1555 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1559 | .rpc_call_done = nfs4_open_confirm_done, |
| 1560 | .rpc_release = nfs4_open_confirm_release, |
| 1561 | }; |
| 1562 | |
| 1563 | /* |
| 1564 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1565 | */ |
| 1566 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1567 | { |
| 1568 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1569 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1570 | struct rpc_message msg = { |
| 1571 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1572 | .rpc_argp = &data->c_arg, |
| 1573 | .rpc_resp = &data->c_res, |
| 1574 | .rpc_cred = data->owner->so_cred, |
| 1575 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1576 | struct rpc_task_setup task_setup_data = { |
| 1577 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1578 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1579 | .callback_ops = &nfs4_open_confirm_ops, |
| 1580 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1581 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1582 | .flags = RPC_TASK_ASYNC, |
| 1583 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | int status; |
| 1585 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1586 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1587 | data->rpc_done = 0; |
| 1588 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1589 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1590 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1591 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1592 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1593 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1594 | if (status != 0) { |
| 1595 | data->cancelled = 1; |
| 1596 | smp_wmb(); |
| 1597 | } else |
| 1598 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1599 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | return status; |
| 1601 | } |
| 1602 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1603 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1605 | struct nfs4_opendata *data = calldata; |
| 1606 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1607 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1608 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1609 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1610 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1611 | /* |
| 1612 | * Check if we still need to send an OPEN call, or if we can use |
| 1613 | * a delegation instead. |
| 1614 | */ |
| 1615 | if (data->state != NULL) { |
| 1616 | struct nfs_delegation *delegation; |
| 1617 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1618 | 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] | 1619 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1620 | rcu_read_lock(); |
| 1621 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1622 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
Trond Myklebust | cd4c9be | 2013-04-23 14:46:25 -0400 | [diff] [blame] | 1623 | data->o_arg.claim != NFS4_OPEN_CLAIM_DELEG_CUR_FH && |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1624 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1625 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1626 | rcu_read_unlock(); |
| 1627 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1628 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1629 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1630 | switch (data->o_arg.claim) { |
| 1631 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1632 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1633 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1634 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1635 | case NFS4_OPEN_CLAIM_FH: |
| 1636 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1637 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1638 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1639 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1640 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1641 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1642 | &data->o_res.seq_res, |
| 1643 | task) != 0) |
| 1644 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1645 | |
| 1646 | /* Set the create mode (note dependency on the session type) */ |
| 1647 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 1648 | if (data->o_arg.open_flags & O_EXCL) { |
| 1649 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 1650 | if (nfs4_has_persistent_session(clp)) |
| 1651 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 1652 | else if (clp->cl_mvops->minor_version > 0) |
| 1653 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 1654 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1655 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1656 | unlock_no_action: |
| 1657 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1658 | out_no_action: |
| 1659 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1660 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1661 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1662 | } |
| 1663 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1664 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1665 | { |
| 1666 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1668 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1669 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1670 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1671 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1672 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1673 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1674 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1675 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1676 | case S_IFREG: |
| 1677 | break; |
| 1678 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1679 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1680 | break; |
| 1681 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1682 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1683 | break; |
| 1684 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1685 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1686 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1687 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1688 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1689 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1690 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1691 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1692 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1693 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1694 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1695 | static void nfs4_open_release(void *calldata) |
| 1696 | { |
| 1697 | struct nfs4_opendata *data = calldata; |
| 1698 | struct nfs4_state *state = NULL; |
| 1699 | |
| 1700 | /* If this request hasn't been cancelled, do nothing */ |
| 1701 | if (data->cancelled == 0) |
| 1702 | goto out_free; |
| 1703 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1704 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1705 | goto out_free; |
| 1706 | /* In case we need an open_confirm, no cleanup! */ |
| 1707 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1708 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1709 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1710 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1711 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1712 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1713 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1717 | .rpc_call_prepare = nfs4_open_prepare, |
| 1718 | .rpc_call_done = nfs4_open_done, |
| 1719 | .rpc_release = nfs4_open_release, |
| 1720 | }; |
| 1721 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1722 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1723 | { |
| 1724 | struct inode *dir = data->dir->d_inode; |
| 1725 | struct nfs_server *server = NFS_SERVER(dir); |
| 1726 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1727 | struct nfs_openres *o_res = &data->o_res; |
| 1728 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1729 | struct rpc_message msg = { |
| 1730 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1731 | .rpc_argp = o_arg, |
| 1732 | .rpc_resp = o_res, |
| 1733 | .rpc_cred = data->owner->so_cred, |
| 1734 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1735 | struct rpc_task_setup task_setup_data = { |
| 1736 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1737 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1738 | .callback_ops = &nfs4_open_ops, |
| 1739 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1740 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1741 | .flags = RPC_TASK_ASYNC, |
| 1742 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1743 | int status; |
| 1744 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1745 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1746 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1747 | data->rpc_done = 0; |
| 1748 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1749 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1750 | data->is_recover = 0; |
| 1751 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1752 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1753 | data->is_recover = 1; |
| 1754 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1755 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1756 | if (IS_ERR(task)) |
| 1757 | return PTR_ERR(task); |
| 1758 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1759 | if (status != 0) { |
| 1760 | data->cancelled = 1; |
| 1761 | smp_wmb(); |
| 1762 | } else |
| 1763 | status = data->rpc_status; |
| 1764 | rpc_put_task(task); |
| 1765 | |
| 1766 | return status; |
| 1767 | } |
| 1768 | |
| 1769 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1770 | { |
| 1771 | struct inode *dir = data->dir->d_inode; |
| 1772 | struct nfs_openres *o_res = &data->o_res; |
| 1773 | int status; |
| 1774 | |
| 1775 | status = nfs4_run_open_task(data, 1); |
| 1776 | if (status != 0 || !data->rpc_done) |
| 1777 | return status; |
| 1778 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1779 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1780 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1781 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1782 | status = _nfs4_proc_open_confirm(data); |
| 1783 | if (status != 0) |
| 1784 | return status; |
| 1785 | } |
| 1786 | |
| 1787 | return status; |
| 1788 | } |
| 1789 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1790 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1791 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1792 | struct nfs4_state *state, fmode_t fmode, |
| 1793 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1794 | { |
| 1795 | struct nfs_access_entry cache; |
| 1796 | u32 mask; |
| 1797 | |
| 1798 | /* access call failed or for some reason the server doesn't |
| 1799 | * support any access modes -- defer access call until later */ |
| 1800 | if (opendata->o_res.access_supported == 0) |
| 1801 | return 0; |
| 1802 | |
| 1803 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1804 | /* 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] | 1805 | * write mode bits, but POSIX allows the creating process to write. |
| 1806 | * use openflags to check for exec, because fmode won't |
| 1807 | * always have FMODE_EXEC set when file open for exec. */ |
| 1808 | if (openflags & __FMODE_EXEC) { |
| 1809 | /* ONLY check for exec rights */ |
| 1810 | mask = MAY_EXEC; |
| 1811 | } else if (fmode & FMODE_READ) |
| 1812 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1813 | |
| 1814 | cache.cred = cred; |
| 1815 | cache.jiffies = jiffies; |
| 1816 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1817 | nfs_access_add_cache(state->inode, &cache); |
| 1818 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1819 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1820 | return 0; |
| 1821 | |
| 1822 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1823 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1824 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1825 | } |
| 1826 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1827 | /* |
| 1828 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1829 | */ |
| 1830 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1831 | { |
| 1832 | struct inode *dir = data->dir->d_inode; |
| 1833 | struct nfs_server *server = NFS_SERVER(dir); |
| 1834 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1835 | struct nfs_openres *o_res = &data->o_res; |
| 1836 | int status; |
| 1837 | |
| 1838 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1839 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1840 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1841 | if (status != 0) { |
| 1842 | if (status == -NFS4ERR_BADNAME && |
| 1843 | !(o_arg->open_flags & O_CREAT)) |
| 1844 | return -ENOENT; |
| 1845 | return status; |
| 1846 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1847 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1848 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1849 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1850 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1851 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1852 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1853 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1855 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1857 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | } |
| 1859 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1860 | _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] | 1861 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | } |
| 1863 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1864 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1865 | { |
| 1866 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1867 | } |
| 1868 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | /* |
| 1870 | * OPEN_EXPIRED: |
| 1871 | * reclaim state on the server after a network partition. |
| 1872 | * Assumes caller holds the appropriate lock |
| 1873 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1874 | 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] | 1875 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1876 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1877 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1879 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1880 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1881 | if (IS_ERR(opendata)) |
| 1882 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1883 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1884 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1885 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1886 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1887 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | } |
| 1889 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1890 | 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] | 1891 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1892 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1893 | struct nfs4_exception exception = { }; |
| 1894 | int err; |
| 1895 | |
| 1896 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1897 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1898 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1899 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1900 | switch (err) { |
| 1901 | default: |
| 1902 | goto out; |
| 1903 | case -NFS4ERR_GRACE: |
| 1904 | case -NFS4ERR_DELAY: |
| 1905 | nfs4_handle_exception(server, err, &exception); |
| 1906 | err = 0; |
| 1907 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1908 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1909 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1910 | return err; |
| 1911 | } |
| 1912 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1914 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1916 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1918 | ctx = nfs4_state_find_open_context(state); |
| 1919 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1920 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1921 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1922 | put_nfs_open_context(ctx); |
| 1923 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | } |
| 1925 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1926 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1927 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1928 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1929 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1930 | nfs4_stateid *stateid = &state->stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1931 | struct nfs_delegation *delegation; |
| 1932 | struct rpc_cred *cred = NULL; |
| 1933 | int status = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1934 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1935 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1936 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1937 | return; |
| 1938 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1939 | /* Get the delegation credential for use by test/free_stateid */ |
| 1940 | rcu_read_lock(); |
| 1941 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1942 | if (delegation != NULL && |
| 1943 | nfs4_stateid_match(&delegation->stateid, stateid)) { |
| 1944 | cred = get_rpccred(delegation->cred); |
| 1945 | rcu_read_unlock(); |
| 1946 | status = nfs41_test_stateid(server, stateid, cred); |
| 1947 | } else |
| 1948 | rcu_read_unlock(); |
| 1949 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1950 | if (status != NFS_OK) { |
| 1951 | /* Free the stateid unless the server explicitly |
| 1952 | * informs us the stateid is unrecognized. */ |
| 1953 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1954 | nfs41_free_stateid(server, stateid, cred); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1955 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1956 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1957 | write_seqlock(&state->seqlock); |
| 1958 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1959 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1960 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1961 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1962 | |
| 1963 | if (cred != NULL) |
| 1964 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | /** |
| 1968 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1969 | * |
| 1970 | * @state: NFSv4 state for an inode |
| 1971 | * |
| 1972 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1973 | * Otherwise a negative NFS4ERR value is returned. |
| 1974 | */ |
| 1975 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1976 | { |
| 1977 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1978 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1979 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1980 | int status; |
| 1981 | |
| 1982 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1983 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1984 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1985 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1986 | return -NFS4ERR_BAD_STATEID; |
| 1987 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1988 | status = nfs41_test_stateid(server, stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1989 | if (status != NFS_OK) { |
| 1990 | /* Free the stateid unless the server explicitly |
| 1991 | * informs us the stateid is unrecognized. */ |
| 1992 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1993 | nfs41_free_stateid(server, stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1994 | |
| 1995 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1996 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1997 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1998 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1999 | } |
| 2000 | return status; |
| 2001 | } |
| 2002 | |
| 2003 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2004 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2005 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2006 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2007 | nfs41_clear_delegation_stateid(state); |
| 2008 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2009 | if (status != NFS_OK) |
| 2010 | status = nfs4_open_expired(sp, state); |
| 2011 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2012 | } |
| 2013 | #endif |
| 2014 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2016 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2017 | * fields corresponding to attributes that were used to store the verifier. |
| 2018 | * Make sure we clobber those fields in the later setattr call |
| 2019 | */ |
| 2020 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 2021 | { |
| 2022 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 2023 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2024 | sattr->ia_valid |= ATTR_ATIME; |
| 2025 | |
| 2026 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 2027 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2028 | sattr->ia_valid |= ATTR_MTIME; |
| 2029 | } |
| 2030 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2031 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2032 | fmode_t fmode, |
| 2033 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2034 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2035 | { |
| 2036 | struct nfs4_state_owner *sp = opendata->owner; |
| 2037 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2038 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2039 | struct nfs4_state *state; |
| 2040 | unsigned int seq; |
| 2041 | int ret; |
| 2042 | |
| 2043 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2044 | |
| 2045 | ret = _nfs4_proc_open(opendata); |
| 2046 | if (ret != 0) |
| 2047 | goto out; |
| 2048 | |
| 2049 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2050 | ret = PTR_ERR(state); |
| 2051 | if (IS_ERR(state)) |
| 2052 | goto out; |
| 2053 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2054 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 2055 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2056 | dentry = opendata->dentry; |
| 2057 | if (dentry->d_inode == NULL) { |
| 2058 | /* FIXME: Is this d_drop() ever needed? */ |
| 2059 | d_drop(dentry); |
| 2060 | dentry = d_add_unique(dentry, igrab(state->inode)); |
| 2061 | if (dentry == NULL) { |
| 2062 | dentry = opendata->dentry; |
| 2063 | } else if (dentry != ctx->dentry) { |
| 2064 | dput(ctx->dentry); |
| 2065 | ctx->dentry = dget(dentry); |
| 2066 | } |
| 2067 | nfs_set_verifier(dentry, |
| 2068 | nfs_save_change_attribute(opendata->dir->d_inode)); |
| 2069 | } |
| 2070 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2071 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2072 | if (ret != 0) |
| 2073 | goto out; |
| 2074 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2075 | ctx->state = state; |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2076 | if (dentry->d_inode == state->inode) { |
| 2077 | nfs_inode_attach_open_context(ctx); |
| 2078 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2079 | nfs4_schedule_stateid_recovery(server, state); |
| 2080 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2081 | out: |
| 2082 | return ret; |
| 2083 | } |
| 2084 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2085 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2086 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2088 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2089 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2090 | int flags, |
| 2091 | struct iattr *sattr, |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2092 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | { |
| 2094 | struct nfs4_state_owner *sp; |
| 2095 | struct nfs4_state *state = NULL; |
| 2096 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2097 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2098 | struct dentry *dentry = ctx->dentry; |
| 2099 | struct rpc_cred *cred = ctx->cred; |
| 2100 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2101 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2102 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2103 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2104 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | |
| 2106 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2108 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2109 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2111 | goto out_err; |
| 2112 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2113 | status = nfs4_recover_expired_lease(server); |
| 2114 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2115 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2116 | if (dentry->d_inode != NULL) |
| 2117 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2118 | status = -ENOMEM; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2119 | if (dentry->d_inode) |
| 2120 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2121 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2122 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2123 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2124 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2126 | if (label) { |
| 2127 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2128 | if (IS_ERR(olabel)) { |
| 2129 | status = PTR_ERR(olabel); |
| 2130 | goto err_opendata_put; |
| 2131 | } |
| 2132 | } |
| 2133 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2134 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2135 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2136 | if (!opendata->f_attr.mdsthreshold) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2137 | goto err_free_label; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2138 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2139 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2140 | if (dentry->d_inode != NULL) |
| 2141 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2142 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2143 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2144 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2145 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2146 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2147 | |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2148 | if ((opendata->o_arg.open_flags & O_EXCL) && |
| 2149 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2150 | nfs4_exclusive_attrset(opendata, sattr); |
| 2151 | |
| 2152 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2153 | status = nfs4_do_setattr(state->inode, cred, |
| 2154 | opendata->o_res.f_attr, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2155 | state, label, olabel); |
| 2156 | if (status == 0) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2157 | nfs_setattr_update_inode(state->inode, sattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2158 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2159 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2160 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2161 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2162 | |
| 2163 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 2164 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 2165 | else |
| 2166 | kfree(opendata->f_attr.mdsthreshold); |
| 2167 | opendata->f_attr.mdsthreshold = NULL; |
| 2168 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2169 | nfs4_label_free(olabel); |
| 2170 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2171 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2174 | err_free_label: |
| 2175 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2176 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2177 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2178 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2179 | err_put_state_owner: |
| 2180 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | return status; |
| 2183 | } |
| 2184 | |
| 2185 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2186 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2187 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2188 | int flags, |
| 2189 | struct iattr *sattr, |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2190 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2192 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | struct nfs4_exception exception = { }; |
| 2194 | struct nfs4_state *res; |
| 2195 | int status; |
| 2196 | |
| 2197 | do { |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2198 | status = _nfs4_do_open(dir, ctx, flags, sattr, label); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2199 | res = ctx->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | if (status == 0) |
| 2201 | break; |
| 2202 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2203 | * book-keeping w.r.t. state-changing operations |
| 2204 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2205 | * It is actually a sign of a bug on the client or on the server. |
| 2206 | * |
| 2207 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2208 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | * have unhashed the old state_owner for us, and that we can |
| 2210 | * therefore safely retry using a new one. We should still warn |
| 2211 | * the user though... |
| 2212 | */ |
| 2213 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2214 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2215 | " returned a bad sequence-id error!\n", |
| 2216 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2217 | exception.retry = 1; |
| 2218 | continue; |
| 2219 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2220 | /* |
| 2221 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2222 | * state before it received the OPEN_CONFIRM. |
| 2223 | * Recover by retrying the request as per the discussion |
| 2224 | * on Page 181 of RFC3530. |
| 2225 | */ |
| 2226 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2227 | exception.retry = 1; |
| 2228 | continue; |
| 2229 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2230 | if (status == -EAGAIN) { |
| 2231 | /* We must have found a delegation */ |
| 2232 | exception.retry = 1; |
| 2233 | continue; |
| 2234 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2235 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2236 | continue; |
| 2237 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | status, &exception)); |
| 2239 | } while (exception.retry); |
| 2240 | return res; |
| 2241 | } |
| 2242 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2243 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2244 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2245 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2246 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2247 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2248 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2249 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2250 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | .iap = sattr, |
| 2252 | .server = server, |
| 2253 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2254 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2255 | }; |
| 2256 | struct nfs_setattrres res = { |
| 2257 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2258 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | .server = server, |
| 2260 | }; |
| 2261 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2262 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2263 | .rpc_argp = &arg, |
| 2264 | .rpc_resp = &res, |
| 2265 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2267 | unsigned long timestamp = jiffies; |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2268 | fmode_t fmode; |
| 2269 | bool truncate; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2270 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2272 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2273 | if (ilabel) |
| 2274 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2275 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2276 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 | |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2278 | /* Servers should only apply open mode checks for file size changes */ |
| 2279 | truncate = (sattr->ia_valid & ATTR_SIZE) ? true : false; |
| 2280 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2281 | |
| 2282 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) { |
| 2283 | /* Use that stateid */ |
| 2284 | } else if (truncate && state != NULL && nfs4_valid_open_stateid(state)) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2285 | struct nfs_lockowner lockowner = { |
| 2286 | .l_owner = current->files, |
| 2287 | .l_pid = current->tgid, |
| 2288 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2289 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2290 | &lockowner); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2291 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2292 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2294 | 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] | 2295 | if (status == 0 && state != NULL) |
| 2296 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2297 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | } |
| 2299 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2300 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2301 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2302 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2303 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2305 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2306 | struct nfs4_exception exception = { |
| 2307 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2308 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2309 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2310 | int err; |
| 2311 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2312 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state, ilabel, olabel); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2313 | switch (err) { |
| 2314 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2315 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2316 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2317 | "applying open mode checks to " |
| 2318 | "a SETATTR that is not " |
| 2319 | "changing file size.\n", |
| 2320 | server->nfs_client->cl_hostname); |
| 2321 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2322 | if (state && !(state->state & FMODE_WRITE)) { |
| 2323 | err = -EBADF; |
| 2324 | if (sattr->ia_valid & ATTR_OPEN) |
| 2325 | err = -EACCES; |
| 2326 | goto out; |
| 2327 | } |
| 2328 | } |
| 2329 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2331 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2332 | return err; |
| 2333 | } |
| 2334 | |
| 2335 | struct nfs4_closedata { |
| 2336 | struct inode *inode; |
| 2337 | struct nfs4_state *state; |
| 2338 | struct nfs_closeargs arg; |
| 2339 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2340 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2341 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2342 | bool roc; |
| 2343 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | }; |
| 2345 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2346 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2347 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2348 | struct nfs4_closedata *calldata = data; |
| 2349 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2350 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2351 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2352 | if (calldata->roc) |
| 2353 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2354 | nfs4_put_open_state(calldata->state); |
| 2355 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2356 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2357 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2358 | kfree(calldata); |
| 2359 | } |
| 2360 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2361 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2362 | fmode_t fmode) |
| 2363 | { |
| 2364 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2365 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2366 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 2367 | case FMODE_WRITE: |
| 2368 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2369 | break; |
| 2370 | case FMODE_READ: |
| 2371 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2372 | break; |
| 2373 | case 0: |
| 2374 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2375 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2376 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 2377 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2378 | spin_unlock(&state->owner->so_lock); |
| 2379 | } |
| 2380 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2381 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2382 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2383 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2386 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2387 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2388 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2389 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | /* hmm. we are done with the inode, and in the process of freeing |
| 2391 | * the state_owner. we keep this around to process errors |
| 2392 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2393 | switch (task->tk_status) { |
| 2394 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2395 | if (calldata->roc) |
| 2396 | pnfs_roc_set_barrier(state->inode, |
| 2397 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2398 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2399 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2400 | nfs4_close_clear_stateid_flags(state, |
| 2401 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | break; |
| 2403 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2404 | case -NFS4ERR_OLD_STATEID: |
| 2405 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2407 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2408 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2410 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2411 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2413 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2414 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2415 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | } |
| 2417 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2418 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2420 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2421 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2422 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2423 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2424 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2425 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2426 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2427 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2428 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2429 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2430 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2431 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2432 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2433 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2434 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2435 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2436 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2437 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2438 | } |
| 2439 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2440 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2441 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2442 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2443 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2444 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2445 | if (!nfs4_valid_open_stateid(state)) |
| 2446 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2447 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2448 | |
| 2449 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2450 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2451 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2452 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2453 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2454 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2455 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2456 | if (calldata->roc && |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2457 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) { |
| 2458 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2459 | goto out_wait; |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2460 | } |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2461 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2462 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2463 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2464 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2465 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2466 | &calldata->arg.seq_args, |
| 2467 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2468 | task) != 0) |
| 2469 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2470 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2471 | return; |
| 2472 | out_no_action: |
| 2473 | task->tk_action = NULL; |
| 2474 | out_wait: |
| 2475 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2476 | } |
| 2477 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2478 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2479 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2480 | .rpc_call_done = nfs4_close_done, |
| 2481 | .rpc_release = nfs4_free_closedata, |
| 2482 | }; |
| 2483 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | /* |
| 2485 | * It is possible for data to be read/written from a mem-mapped file |
| 2486 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2487 | * This means that we can't safely call nfsv4 close on a file until |
| 2488 | * the inode is cleared. This in turn means that we are not good |
| 2489 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2490 | * share state even when we are done with one of the three share |
| 2491 | * stateid's in the inode. |
| 2492 | * |
| 2493 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2494 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2495 | 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] | 2496 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2497 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2499 | struct nfs4_state_owner *sp = state->owner; |
| 2500 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2501 | struct rpc_message msg = { |
| 2502 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2503 | .rpc_cred = state->owner->so_cred, |
| 2504 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2505 | struct rpc_task_setup task_setup_data = { |
| 2506 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2507 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2508 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2509 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2510 | .flags = RPC_TASK_ASYNC, |
| 2511 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2512 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2513 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2514 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2515 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2516 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2517 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2518 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2519 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2520 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2521 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2522 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2523 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2524 | if (calldata->arg.seqid == NULL) |
| 2525 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2526 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2527 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2528 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2529 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2530 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2531 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2532 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2533 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2534 | msg.rpc_argp = &calldata->arg; |
| 2535 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2536 | task_setup_data.callback_data = calldata; |
| 2537 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2538 | if (IS_ERR(task)) |
| 2539 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2540 | status = 0; |
| 2541 | if (wait) |
| 2542 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2543 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2544 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2545 | out_free_calldata: |
| 2546 | kfree(calldata); |
| 2547 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2548 | nfs4_put_open_state(state); |
| 2549 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2550 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2551 | } |
| 2552 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2553 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2554 | 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] | 2555 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2556 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2557 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 2558 | |
| 2559 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2560 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2561 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2562 | state = nfs4_do_open(dir, ctx, open_flags, attr, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2563 | |
| 2564 | nfs4_label_release_security(label); |
| 2565 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2566 | if (IS_ERR(state)) |
| 2567 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2568 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2569 | } |
| 2570 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2571 | 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] | 2572 | { |
| 2573 | if (ctx->state == NULL) |
| 2574 | return; |
| 2575 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2576 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2577 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2578 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2579 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2580 | |
| 2581 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2582 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2583 | struct nfs4_server_caps_arg args = { |
| 2584 | .fhandle = fhandle, |
| 2585 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | struct nfs4_server_caps_res res = {}; |
| 2587 | struct rpc_message msg = { |
| 2588 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2589 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | .rpc_resp = &res, |
| 2591 | }; |
| 2592 | int status; |
| 2593 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2594 | 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] | 2595 | if (status == 0) { |
| 2596 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2597 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2598 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2599 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2600 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2601 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2603 | server->caps |= NFS_CAP_ACLS; |
| 2604 | if (res.has_links != 0) |
| 2605 | server->caps |= NFS_CAP_HARDLINKS; |
| 2606 | if (res.has_symlinks != 0) |
| 2607 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2608 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2609 | server->caps |= NFS_CAP_FILEID; |
| 2610 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2611 | server->caps |= NFS_CAP_MODE; |
| 2612 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2613 | server->caps |= NFS_CAP_NLINK; |
| 2614 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2615 | server->caps |= NFS_CAP_OWNER; |
| 2616 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2617 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2618 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2619 | server->caps |= NFS_CAP_ATIME; |
| 2620 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2621 | server->caps |= NFS_CAP_CTIME; |
| 2622 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2623 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2624 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 2625 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2626 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 2627 | #endif |
| 2628 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 2629 | sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2630 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2631 | if (server->caps & NFS_CAP_SECURITY_LABEL) { |
| 2632 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2633 | res.attr_bitmask[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2634 | } |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2635 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2636 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2637 | 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] | 2638 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2639 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2642 | return status; |
| 2643 | } |
| 2644 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2645 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2646 | { |
| 2647 | struct nfs4_exception exception = { }; |
| 2648 | int err; |
| 2649 | do { |
| 2650 | err = nfs4_handle_exception(server, |
| 2651 | _nfs4_server_capabilities(server, fhandle), |
| 2652 | &exception); |
| 2653 | } while (exception.retry); |
| 2654 | return err; |
| 2655 | } |
| 2656 | |
| 2657 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2658 | struct nfs_fsinfo *info) |
| 2659 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2660 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2661 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2662 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | }; |
| 2664 | struct nfs4_lookup_res res = { |
| 2665 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2666 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | .fh = fhandle, |
| 2668 | }; |
| 2669 | struct rpc_message msg = { |
| 2670 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2671 | .rpc_argp = &args, |
| 2672 | .rpc_resp = &res, |
| 2673 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2674 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2675 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 2676 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 2677 | /* |
| 2678 | * Process the label in the upcoming getfattr |
| 2679 | */ |
| 2680 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 2681 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2682 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2683 | 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] | 2684 | } |
| 2685 | |
| 2686 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2687 | struct nfs_fsinfo *info) |
| 2688 | { |
| 2689 | struct nfs4_exception exception = { }; |
| 2690 | int err; |
| 2691 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2692 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2693 | switch (err) { |
| 2694 | case 0: |
| 2695 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2696 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2697 | default: |
| 2698 | err = nfs4_handle_exception(server, err, &exception); |
| 2699 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2701 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | return err; |
| 2703 | } |
| 2704 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2705 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2706 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2707 | { |
| 2708 | struct rpc_auth *auth; |
| 2709 | int ret; |
| 2710 | |
| 2711 | auth = rpcauth_create(flavor, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2712 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 2713 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2714 | goto out; |
| 2715 | } |
| 2716 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2717 | out: |
| 2718 | return ret; |
| 2719 | } |
| 2720 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2721 | /* |
| 2722 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 2723 | * |
| 2724 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 2725 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 2726 | * |
| 2727 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 2728 | * negative errno value. |
| 2729 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2730 | 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] | 2731 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2733 | /* Per 3530bis 15.33.5 */ |
| 2734 | static const rpc_authflavor_t flav_array[] = { |
| 2735 | RPC_AUTH_GSS_KRB5P, |
| 2736 | RPC_AUTH_GSS_KRB5I, |
| 2737 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 2738 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2739 | RPC_AUTH_NULL, |
| 2740 | }; |
| 2741 | int status = -EPERM; |
| 2742 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2743 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2744 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2745 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2746 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2747 | continue; |
| 2748 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2749 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2750 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2751 | /* |
| 2752 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2753 | * to access the mount. It could also mean that we tried to mount |
| 2754 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2755 | * existing mount programs don't handle -EACCES very well so it should |
| 2756 | * be mapped to -EPERM instead. |
| 2757 | */ |
| 2758 | if (status == -EACCES) |
| 2759 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2760 | return status; |
| 2761 | } |
| 2762 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2763 | static int nfs4_do_find_root_sec(struct nfs_server *server, |
| 2764 | struct nfs_fh *fhandle, struct nfs_fsinfo *info) |
| 2765 | { |
| 2766 | int mv = server->nfs_client->cl_minorversion; |
| 2767 | return nfs_v4_minor_ops[mv]->find_root_sec(server, fhandle, info); |
| 2768 | } |
| 2769 | |
| 2770 | /** |
| 2771 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 2772 | * @server: initialized nfs_server handle |
| 2773 | * @fhandle: we fill in the pseudo-fs root file handle |
| 2774 | * @info: we fill in an FSINFO struct |
| 2775 | * |
| 2776 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2777 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2778 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2779 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2780 | { |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2781 | int status; |
| 2782 | |
| 2783 | status = nfs4_lookup_root(server, fhandle, info); |
| 2784 | if ((status == -NFS4ERR_WRONGSEC) && |
| 2785 | !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2786 | status = nfs4_do_find_root_sec(server, fhandle, info); |
| 2787 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | if (status == 0) |
| 2789 | status = nfs4_server_capabilities(server, fhandle); |
| 2790 | if (status == 0) |
| 2791 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2792 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2793 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2794 | } |
| 2795 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2796 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2797 | struct nfs_fsinfo *info) |
| 2798 | { |
| 2799 | int error; |
| 2800 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2801 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2802 | |
| 2803 | error = nfs4_server_capabilities(server, mntfh); |
| 2804 | if (error < 0) { |
| 2805 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2806 | return error; |
| 2807 | } |
| 2808 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2809 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 2810 | if (IS_ERR(label)) |
| 2811 | return PTR_ERR(label); |
| 2812 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2813 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2814 | if (error < 0) { |
| 2815 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2816 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2817 | } |
| 2818 | |
| 2819 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2820 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2821 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2822 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2823 | err_free_label: |
| 2824 | nfs4_label_free(label); |
| 2825 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2826 | return error; |
| 2827 | } |
| 2828 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2829 | /* |
| 2830 | * Get locations and (maybe) other attributes of a referral. |
| 2831 | * Note that we'll actually follow the referral later when |
| 2832 | * we detect fsid mismatch in inode revalidation |
| 2833 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2834 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2835 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2836 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2837 | { |
| 2838 | int status = -ENOMEM; |
| 2839 | struct page *page = NULL; |
| 2840 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2841 | |
| 2842 | page = alloc_page(GFP_KERNEL); |
| 2843 | if (page == NULL) |
| 2844 | goto out; |
| 2845 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2846 | if (locations == NULL) |
| 2847 | goto out; |
| 2848 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2849 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2850 | if (status != 0) |
| 2851 | goto out; |
| 2852 | /* Make sure server returned a different fsid for the referral */ |
| 2853 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2854 | dprintk("%s: server did not return a different fsid for" |
| 2855 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2856 | status = -EIO; |
| 2857 | goto out; |
| 2858 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2859 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2860 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2861 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2862 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2863 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2864 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2865 | out: |
| 2866 | if (page) |
| 2867 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2868 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2869 | return status; |
| 2870 | } |
| 2871 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2872 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2873 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | { |
| 2875 | struct nfs4_getattr_arg args = { |
| 2876 | .fh = fhandle, |
| 2877 | .bitmask = server->attr_bitmask, |
| 2878 | }; |
| 2879 | struct nfs4_getattr_res res = { |
| 2880 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2881 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | .server = server, |
| 2883 | }; |
| 2884 | struct rpc_message msg = { |
| 2885 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2886 | .rpc_argp = &args, |
| 2887 | .rpc_resp = &res, |
| 2888 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2889 | |
| 2890 | args.bitmask = nfs4_bitmask(server, label); |
| 2891 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2892 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2893 | 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] | 2894 | } |
| 2895 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2896 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2897 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | { |
| 2899 | struct nfs4_exception exception = { }; |
| 2900 | int err; |
| 2901 | do { |
| 2902 | err = nfs4_handle_exception(server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2903 | _nfs4_proc_getattr(server, fhandle, fattr, label), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2904 | &exception); |
| 2905 | } while (exception.retry); |
| 2906 | return err; |
| 2907 | } |
| 2908 | |
| 2909 | /* |
| 2910 | * The file is not closed if it is opened due to the a request to change |
| 2911 | * the size of the file. The open call will not be needed once the |
| 2912 | * VFS layer lookup-intents are implemented. |
| 2913 | * |
| 2914 | * Close is called when the inode is destroyed. |
| 2915 | * If we haven't opened the file for O_WRONLY, we |
| 2916 | * need to in the size_change case to obtain a stateid. |
| 2917 | * |
| 2918 | * Got race? |
| 2919 | * Because OPEN is always done by name in nfsv4, it is |
| 2920 | * possible that we opened a different file by the same |
| 2921 | * name. We can recognize this race condition, but we |
| 2922 | * can't do anything about it besides returning an error. |
| 2923 | * |
| 2924 | * This will be fixed with VFS changes (lookup-intent). |
| 2925 | */ |
| 2926 | static int |
| 2927 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2928 | struct iattr *sattr) |
| 2929 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2930 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2931 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2932 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2933 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2934 | int status; |
| 2935 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2936 | if (pnfs_ld_layoutret_on_setattr(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 2937 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2938 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2939 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2940 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2941 | /* Deal with open(O_TRUNC) */ |
| 2942 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 2943 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2944 | |
| 2945 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 2946 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2947 | return 0; |
| 2948 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2949 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2950 | if (sattr->ia_valid & ATTR_FILE) { |
| 2951 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2952 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2953 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2954 | if (ctx) { |
| 2955 | cred = ctx->cred; |
| 2956 | state = ctx->state; |
| 2957 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2958 | } |
| 2959 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2960 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 2961 | if (IS_ERR(label)) |
| 2962 | return PTR_ERR(label); |
| 2963 | |
| 2964 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2965 | if (status == 0) { |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2966 | nfs_setattr_update_inode(inode, sattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2967 | nfs_setsecurity(inode, fattr, label); |
| 2968 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2969 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | return status; |
| 2971 | } |
| 2972 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2973 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2974 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2975 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2976 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2977 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2978 | int status; |
| 2979 | struct nfs4_lookup_arg args = { |
| 2980 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2981 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2982 | .name = name, |
| 2983 | }; |
| 2984 | struct nfs4_lookup_res res = { |
| 2985 | .server = server, |
| 2986 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2987 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2988 | .fh = fhandle, |
| 2989 | }; |
| 2990 | struct rpc_message msg = { |
| 2991 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2992 | .rpc_argp = &args, |
| 2993 | .rpc_resp = &res, |
| 2994 | }; |
| 2995 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2996 | args.bitmask = nfs4_bitmask(server, label); |
| 2997 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2998 | nfs_fattr_init(fattr); |
| 2999 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3000 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3001 | 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] | 3002 | dprintk("NFS reply lookup: %d\n", status); |
| 3003 | return status; |
| 3004 | } |
| 3005 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3006 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3007 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3008 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3009 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3010 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3011 | fattr->nlink = 2; |
| 3012 | } |
| 3013 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3014 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 3015 | struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3016 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3017 | { |
| 3018 | struct nfs4_exception exception = { }; |
| 3019 | struct rpc_clnt *client = *clnt; |
| 3020 | int err; |
| 3021 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3022 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3023 | switch (err) { |
| 3024 | case -NFS4ERR_BADNAME: |
| 3025 | err = -ENOENT; |
| 3026 | goto out; |
| 3027 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3028 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3029 | goto out; |
| 3030 | case -NFS4ERR_WRONGSEC: |
| 3031 | err = -EPERM; |
| 3032 | if (client != *clnt) |
| 3033 | goto out; |
| 3034 | |
| 3035 | client = nfs4_create_sec_client(client, dir, name); |
| 3036 | if (IS_ERR(client)) |
| 3037 | return PTR_ERR(client); |
| 3038 | |
| 3039 | exception.retry = 1; |
| 3040 | break; |
| 3041 | default: |
| 3042 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3043 | } |
| 3044 | } while (exception.retry); |
| 3045 | |
| 3046 | out: |
| 3047 | if (err == 0) |
| 3048 | *clnt = client; |
| 3049 | else if (client != *clnt) |
| 3050 | rpc_shutdown_client(client); |
| 3051 | |
| 3052 | return err; |
| 3053 | } |
| 3054 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 3055 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3056 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3057 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3059 | int status; |
| 3060 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3061 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3062 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3063 | if (client != NFS_CLIENT(dir)) { |
| 3064 | rpc_shutdown_client(client); |
| 3065 | nfs_fixup_secinfo_attributes(fattr); |
| 3066 | } |
| 3067 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3068 | } |
| 3069 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3070 | struct rpc_clnt * |
| 3071 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 3072 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3073 | { |
| 3074 | int status; |
| 3075 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 3076 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3077 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3078 | if (status < 0) { |
| 3079 | rpc_shutdown_client(client); |
| 3080 | return ERR_PTR(status); |
| 3081 | } |
| 3082 | return client; |
| 3083 | } |
| 3084 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3086 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3087 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3088 | struct nfs4_accessargs args = { |
| 3089 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3090 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3092 | struct nfs4_accessres res = { |
| 3093 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3094 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | struct rpc_message msg = { |
| 3096 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3097 | .rpc_argp = &args, |
| 3098 | .rpc_resp = &res, |
| 3099 | .rpc_cred = entry->cred, |
| 3100 | }; |
| 3101 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3102 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | |
| 3104 | /* |
| 3105 | * Determine which access bits we want to ask for... |
| 3106 | */ |
| 3107 | if (mode & MAY_READ) |
| 3108 | args.access |= NFS4_ACCESS_READ; |
| 3109 | if (S_ISDIR(inode->i_mode)) { |
| 3110 | if (mode & MAY_WRITE) |
| 3111 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3112 | if (mode & MAY_EXEC) |
| 3113 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3114 | } else { |
| 3115 | if (mode & MAY_WRITE) |
| 3116 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3117 | if (mode & MAY_EXEC) |
| 3118 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3119 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3120 | |
| 3121 | res.fattr = nfs_alloc_fattr(); |
| 3122 | if (res.fattr == NULL) |
| 3123 | return -ENOMEM; |
| 3124 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3125 | 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] | 3126 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3127 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3128 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3130 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | return status; |
| 3132 | } |
| 3133 | |
| 3134 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3135 | { |
| 3136 | struct nfs4_exception exception = { }; |
| 3137 | int err; |
| 3138 | do { |
| 3139 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3140 | _nfs4_proc_access(inode, entry), |
| 3141 | &exception); |
| 3142 | } while (exception.retry); |
| 3143 | return err; |
| 3144 | } |
| 3145 | |
| 3146 | /* |
| 3147 | * TODO: For the time being, we don't try to get any attributes |
| 3148 | * along with any of the zero-copy operations READ, READDIR, |
| 3149 | * READLINK, WRITE. |
| 3150 | * |
| 3151 | * In the case of the first three, we want to put the GETATTR |
| 3152 | * after the read-type operation -- this is because it is hard |
| 3153 | * to predict the length of a GETATTR response in v4, and thus |
| 3154 | * align the READ data correctly. This means that the GETATTR |
| 3155 | * may end up partially falling into the page cache, and we should |
| 3156 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3157 | * To do this efficiently, we need to know the total length |
| 3158 | * of data received, which doesn't seem to be available outside |
| 3159 | * of the RPC layer. |
| 3160 | * |
| 3161 | * In the case of WRITE, we also want to put the GETATTR after |
| 3162 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3163 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3164 | * |
| 3165 | * Both of these changes to the XDR layer would in fact be quite |
| 3166 | * minor, but I decided to leave them for a subsequent patch. |
| 3167 | */ |
| 3168 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3169 | unsigned int pgbase, unsigned int pglen) |
| 3170 | { |
| 3171 | struct nfs4_readlink args = { |
| 3172 | .fh = NFS_FH(inode), |
| 3173 | .pgbase = pgbase, |
| 3174 | .pglen = pglen, |
| 3175 | .pages = &page, |
| 3176 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3177 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3178 | struct rpc_message msg = { |
| 3179 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3180 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3181 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | }; |
| 3183 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3184 | 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] | 3185 | } |
| 3186 | |
| 3187 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3188 | unsigned int pgbase, unsigned int pglen) |
| 3189 | { |
| 3190 | struct nfs4_exception exception = { }; |
| 3191 | int err; |
| 3192 | do { |
| 3193 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3194 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 3195 | &exception); |
| 3196 | } while (exception.retry); |
| 3197 | return err; |
| 3198 | } |
| 3199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3201 | * 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] | 3202 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | static int |
| 3204 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3205 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3207 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3208 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | int status = 0; |
| 3211 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3212 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3213 | if (IS_ERR(ctx)) |
| 3214 | return PTR_ERR(ctx); |
| 3215 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3216 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3217 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3218 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 3219 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | if (IS_ERR(state)) { |
| 3221 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3222 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3224 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3225 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3226 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | return status; |
| 3228 | } |
| 3229 | |
| 3230 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3231 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3232 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3233 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3234 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3235 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3237 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3238 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3239 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3241 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3242 | .rpc_argp = &args, |
| 3243 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3244 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3245 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3246 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3247 | 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] | 3248 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3249 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | return status; |
| 3251 | } |
| 3252 | |
| 3253 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3254 | { |
| 3255 | struct nfs4_exception exception = { }; |
| 3256 | int err; |
| 3257 | do { |
| 3258 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3259 | _nfs4_proc_remove(dir, name), |
| 3260 | &exception); |
| 3261 | } while (exception.retry); |
| 3262 | return err; |
| 3263 | } |
| 3264 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3265 | 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] | 3266 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3267 | struct nfs_server *server = NFS_SERVER(dir); |
| 3268 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3269 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3271 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3273 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3274 | |
| 3275 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3276 | } |
| 3277 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3278 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3279 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3280 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 3281 | &data->args.seq_args, |
| 3282 | &data->res.seq_res, |
| 3283 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3284 | } |
| 3285 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3286 | 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] | 3287 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3288 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 3289 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3290 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3291 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3292 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3293 | return 0; |
| 3294 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3295 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | } |
| 3297 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3298 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3299 | { |
| 3300 | struct nfs_server *server = NFS_SERVER(dir); |
| 3301 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3302 | struct nfs_renameres *res = msg->rpc_resp; |
| 3303 | |
| 3304 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3305 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3306 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3307 | } |
| 3308 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3309 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3310 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3311 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3312 | &data->args.seq_args, |
| 3313 | &data->res.seq_res, |
| 3314 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3315 | } |
| 3316 | |
| 3317 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3318 | struct inode *new_dir) |
| 3319 | { |
| 3320 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 3321 | |
| 3322 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3323 | return 0; |
| 3324 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 3325 | return 0; |
| 3326 | |
| 3327 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3328 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3329 | return 1; |
| 3330 | } |
| 3331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3332 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3333 | struct inode *new_dir, struct qstr *new_name) |
| 3334 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3335 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 3336 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3337 | .old_dir = NFS_FH(old_dir), |
| 3338 | .new_dir = NFS_FH(new_dir), |
| 3339 | .old_name = old_name, |
| 3340 | .new_name = new_name, |
| 3341 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3342 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3343 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3344 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | struct rpc_message msg = { |
| 3346 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3347 | .rpc_argp = &arg, |
| 3348 | .rpc_resp = &res, |
| 3349 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3350 | int status = -ENOMEM; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3351 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3352 | 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] | 3353 | if (!status) { |
| 3354 | update_changeattr(old_dir, &res.old_cinfo); |
| 3355 | update_changeattr(new_dir, &res.new_cinfo); |
| 3356 | } |
| 3357 | return status; |
| 3358 | } |
| 3359 | |
| 3360 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3361 | struct inode *new_dir, struct qstr *new_name) |
| 3362 | { |
| 3363 | struct nfs4_exception exception = { }; |
| 3364 | int err; |
| 3365 | do { |
| 3366 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3367 | _nfs4_proc_rename(old_dir, old_name, |
| 3368 | new_dir, new_name), |
| 3369 | &exception); |
| 3370 | } while (exception.retry); |
| 3371 | return err; |
| 3372 | } |
| 3373 | |
| 3374 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3375 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3376 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3377 | struct nfs4_link_arg arg = { |
| 3378 | .fh = NFS_FH(inode), |
| 3379 | .dir_fh = NFS_FH(dir), |
| 3380 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3381 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3382 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3383 | struct nfs4_link_res res = { |
| 3384 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3385 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3386 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | struct rpc_message msg = { |
| 3388 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3389 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3390 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3391 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3392 | int status = -ENOMEM; |
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 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3395 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3396 | goto out; |
| 3397 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3398 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3399 | if (IS_ERR(res.label)) { |
| 3400 | status = PTR_ERR(res.label); |
| 3401 | goto out; |
| 3402 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3403 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3404 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3405 | 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] | 3406 | if (!status) { |
| 3407 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3408 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 3409 | if (!status) |
| 3410 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3411 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3412 | |
| 3413 | |
| 3414 | nfs4_label_free(res.label); |
| 3415 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3416 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3417 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | return status; |
| 3419 | } |
| 3420 | |
| 3421 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3422 | { |
| 3423 | struct nfs4_exception exception = { }; |
| 3424 | int err; |
| 3425 | do { |
| 3426 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3427 | _nfs4_proc_link(inode, dir, name), |
| 3428 | &exception); |
| 3429 | } while (exception.retry); |
| 3430 | return err; |
| 3431 | } |
| 3432 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3433 | struct nfs4_createdata { |
| 3434 | struct rpc_message msg; |
| 3435 | struct nfs4_create_arg arg; |
| 3436 | struct nfs4_create_res res; |
| 3437 | struct nfs_fh fh; |
| 3438 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3439 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3440 | }; |
| 3441 | |
| 3442 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3443 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3444 | { |
| 3445 | struct nfs4_createdata *data; |
| 3446 | |
| 3447 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3448 | if (data != NULL) { |
| 3449 | struct nfs_server *server = NFS_SERVER(dir); |
| 3450 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3451 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3452 | if (IS_ERR(data->label)) |
| 3453 | goto out_free; |
| 3454 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3455 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3456 | data->msg.rpc_argp = &data->arg; |
| 3457 | data->msg.rpc_resp = &data->res; |
| 3458 | data->arg.dir_fh = NFS_FH(dir); |
| 3459 | data->arg.server = server; |
| 3460 | data->arg.name = name; |
| 3461 | data->arg.attrs = sattr; |
| 3462 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3463 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3464 | data->res.server = server; |
| 3465 | data->res.fh = &data->fh; |
| 3466 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3467 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3468 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3469 | } |
| 3470 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3471 | out_free: |
| 3472 | kfree(data); |
| 3473 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3474 | } |
| 3475 | |
| 3476 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3477 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3478 | 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] | 3479 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3480 | if (status == 0) { |
| 3481 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3482 | 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] | 3483 | } |
| 3484 | return status; |
| 3485 | } |
| 3486 | |
| 3487 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3488 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3489 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3490 | kfree(data); |
| 3491 | } |
| 3492 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3493 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3494 | struct page *page, unsigned int len, struct iattr *sattr, |
| 3495 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3497 | struct nfs4_createdata *data; |
| 3498 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3499 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3500 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3501 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3502 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3503 | status = -ENOMEM; |
| 3504 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3505 | if (data == NULL) |
| 3506 | goto out; |
| 3507 | |
| 3508 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3509 | data->arg.u.symlink.pages = &page; |
| 3510 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3511 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3512 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3513 | status = nfs4_do_create(dir, dentry, data); |
| 3514 | |
| 3515 | nfs4_free_createdata(data); |
| 3516 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3517 | return status; |
| 3518 | } |
| 3519 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3520 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3521 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3522 | { |
| 3523 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3524 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3525 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3526 | |
| 3527 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3528 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | do { |
| 3530 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3531 | _nfs4_proc_symlink(dir, dentry, page, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3532 | len, sattr, label), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3533 | &exception); |
| 3534 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3535 | |
| 3536 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3537 | return err; |
| 3538 | } |
| 3539 | |
| 3540 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3541 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3542 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3543 | struct nfs4_createdata *data; |
| 3544 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3545 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3546 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3547 | if (data == NULL) |
| 3548 | goto out; |
| 3549 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3550 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3551 | status = nfs4_do_create(dir, dentry, data); |
| 3552 | |
| 3553 | nfs4_free_createdata(data); |
| 3554 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | return status; |
| 3556 | } |
| 3557 | |
| 3558 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3559 | struct iattr *sattr) |
| 3560 | { |
| 3561 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3562 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3563 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3564 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3565 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3566 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3567 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3568 | do { |
| 3569 | err = nfs4_handle_exception(NFS_SERVER(dir), |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3570 | _nfs4_proc_mkdir(dir, dentry, sattr, label), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3571 | &exception); |
| 3572 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3573 | nfs4_label_release_security(label); |
| 3574 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3575 | return err; |
| 3576 | } |
| 3577 | |
| 3578 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3579 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3580 | { |
| 3581 | struct inode *dir = dentry->d_inode; |
| 3582 | struct nfs4_readdir_arg args = { |
| 3583 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3584 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | .pgbase = 0, |
| 3586 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3587 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3588 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3589 | }; |
| 3590 | struct nfs4_readdir_res res; |
| 3591 | struct rpc_message msg = { |
| 3592 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3593 | .rpc_argp = &args, |
| 3594 | .rpc_resp = &res, |
| 3595 | .rpc_cred = cred, |
| 3596 | }; |
| 3597 | int status; |
| 3598 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3599 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3600 | dentry->d_parent->d_name.name, |
| 3601 | dentry->d_name.name, |
| 3602 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3603 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3604 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3605 | 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] | 3606 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3607 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3608 | status += args.pgbase; |
| 3609 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3610 | |
| 3611 | nfs_invalidate_atime(dir); |
| 3612 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3613 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3614 | return status; |
| 3615 | } |
| 3616 | |
| 3617 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3618 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | { |
| 3620 | struct nfs4_exception exception = { }; |
| 3621 | int err; |
| 3622 | do { |
| 3623 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3624 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3625 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3626 | &exception); |
| 3627 | } while (exception.retry); |
| 3628 | return err; |
| 3629 | } |
| 3630 | |
| 3631 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3632 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3633 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3634 | struct nfs4_createdata *data; |
| 3635 | int mode = sattr->ia_mode; |
| 3636 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3637 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3638 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3639 | if (data == NULL) |
| 3640 | goto out; |
| 3641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3642 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3643 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3644 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3645 | data->arg.ftype = NF4BLK; |
| 3646 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3647 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3648 | } |
| 3649 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3650 | data->arg.ftype = NF4CHR; |
| 3651 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3652 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3653 | } else if (!S_ISSOCK(mode)) { |
| 3654 | status = -EINVAL; |
| 3655 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3656 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3657 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3658 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3659 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3660 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3661 | nfs4_free_createdata(data); |
| 3662 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3663 | return status; |
| 3664 | } |
| 3665 | |
| 3666 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3667 | struct iattr *sattr, dev_t rdev) |
| 3668 | { |
| 3669 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3670 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3671 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3672 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3673 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3674 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3675 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3676 | do { |
| 3677 | err = nfs4_handle_exception(NFS_SERVER(dir), |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3678 | _nfs4_proc_mknod(dir, dentry, sattr, label, rdev), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3679 | &exception); |
| 3680 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3681 | |
| 3682 | nfs4_label_release_security(label); |
| 3683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3684 | return err; |
| 3685 | } |
| 3686 | |
| 3687 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3688 | struct nfs_fsstat *fsstat) |
| 3689 | { |
| 3690 | struct nfs4_statfs_arg args = { |
| 3691 | .fh = fhandle, |
| 3692 | .bitmask = server->attr_bitmask, |
| 3693 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3694 | struct nfs4_statfs_res res = { |
| 3695 | .fsstat = fsstat, |
| 3696 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3697 | struct rpc_message msg = { |
| 3698 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3699 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3700 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3701 | }; |
| 3702 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3703 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3704 | 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] | 3705 | } |
| 3706 | |
| 3707 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3708 | { |
| 3709 | struct nfs4_exception exception = { }; |
| 3710 | int err; |
| 3711 | do { |
| 3712 | err = nfs4_handle_exception(server, |
| 3713 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3714 | &exception); |
| 3715 | } while (exception.retry); |
| 3716 | return err; |
| 3717 | } |
| 3718 | |
| 3719 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3720 | struct nfs_fsinfo *fsinfo) |
| 3721 | { |
| 3722 | struct nfs4_fsinfo_arg args = { |
| 3723 | .fh = fhandle, |
| 3724 | .bitmask = server->attr_bitmask, |
| 3725 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3726 | struct nfs4_fsinfo_res res = { |
| 3727 | .fsinfo = fsinfo, |
| 3728 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3729 | struct rpc_message msg = { |
| 3730 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3731 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3732 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3733 | }; |
| 3734 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3735 | 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] | 3736 | } |
| 3737 | |
| 3738 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3739 | { |
| 3740 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3741 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3742 | int err; |
| 3743 | |
| 3744 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3745 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3746 | if (err == 0) { |
| 3747 | struct nfs_client *clp = server->nfs_client; |
| 3748 | |
| 3749 | spin_lock(&clp->cl_lock); |
| 3750 | clp->cl_lease_time = fsinfo->lease_time * HZ; |
| 3751 | clp->cl_last_renewal = now; |
| 3752 | spin_unlock(&clp->cl_lock); |
| 3753 | break; |
| 3754 | } |
| 3755 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3756 | } while (exception.retry); |
| 3757 | return err; |
| 3758 | } |
| 3759 | |
| 3760 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3761 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3762 | int error; |
| 3763 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3764 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3765 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3766 | if (error == 0) { |
| 3767 | /* block layout checks this! */ |
| 3768 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3769 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3770 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3771 | |
| 3772 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3773 | } |
| 3774 | |
| 3775 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3776 | struct nfs_pathconf *pathconf) |
| 3777 | { |
| 3778 | struct nfs4_pathconf_arg args = { |
| 3779 | .fh = fhandle, |
| 3780 | .bitmask = server->attr_bitmask, |
| 3781 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3782 | struct nfs4_pathconf_res res = { |
| 3783 | .pathconf = pathconf, |
| 3784 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3785 | struct rpc_message msg = { |
| 3786 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3787 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3788 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | }; |
| 3790 | |
| 3791 | /* None of the pathconf attributes are mandatory to implement */ |
| 3792 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3793 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3794 | return 0; |
| 3795 | } |
| 3796 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3797 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3798 | 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] | 3799 | } |
| 3800 | |
| 3801 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3802 | struct nfs_pathconf *pathconf) |
| 3803 | { |
| 3804 | struct nfs4_exception exception = { }; |
| 3805 | int err; |
| 3806 | |
| 3807 | do { |
| 3808 | err = nfs4_handle_exception(server, |
| 3809 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3810 | &exception); |
| 3811 | } while (exception.retry); |
| 3812 | return err; |
| 3813 | } |
| 3814 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3815 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3816 | const struct nfs_open_context *ctx, |
| 3817 | const struct nfs_lock_context *l_ctx, |
| 3818 | fmode_t fmode) |
| 3819 | { |
| 3820 | const struct nfs_lockowner *lockowner = NULL; |
| 3821 | |
| 3822 | if (l_ctx != NULL) |
| 3823 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3824 | return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3825 | } |
| 3826 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 3827 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3828 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 3829 | const struct nfs_open_context *ctx, |
| 3830 | const struct nfs_lock_context *l_ctx, |
| 3831 | fmode_t fmode) |
| 3832 | { |
| 3833 | nfs4_stateid current_stateid; |
| 3834 | |
| 3835 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode)) |
| 3836 | return false; |
| 3837 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 3838 | } |
| 3839 | |
| 3840 | static bool nfs4_error_stateid_expired(int err) |
| 3841 | { |
| 3842 | switch (err) { |
| 3843 | case -NFS4ERR_DELEG_REVOKED: |
| 3844 | case -NFS4ERR_ADMIN_REVOKED: |
| 3845 | case -NFS4ERR_BAD_STATEID: |
| 3846 | case -NFS4ERR_STALE_STATEID: |
| 3847 | case -NFS4ERR_OLD_STATEID: |
| 3848 | case -NFS4ERR_OPENMODE: |
| 3849 | case -NFS4ERR_EXPIRED: |
| 3850 | return true; |
| 3851 | } |
| 3852 | return false; |
| 3853 | } |
| 3854 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3855 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3856 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3857 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3858 | } |
| 3859 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3860 | 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] | 3861 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3862 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3863 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3864 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3865 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3866 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3867 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3868 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3869 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3870 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3871 | renew_lease(server, data->timestamp); |
| 3872 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3873 | } |
| 3874 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3875 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
| 3876 | struct nfs_readargs *args) |
| 3877 | { |
| 3878 | |
| 3879 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3880 | nfs4_stateid_is_current(&args->stateid, |
| 3881 | args->context, |
| 3882 | args->lock_context, |
| 3883 | FMODE_READ)) |
| 3884 | return false; |
| 3885 | rpc_restart_call_prepare(task); |
| 3886 | return true; |
| 3887 | } |
| 3888 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3889 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3890 | { |
| 3891 | |
| 3892 | dprintk("--> %s\n", __func__); |
| 3893 | |
| 3894 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3895 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3896 | if (nfs4_read_stateid_changed(task, &data->args)) |
| 3897 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3898 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3899 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3900 | } |
| 3901 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3902 | 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] | 3903 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3904 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3905 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3906 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3907 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3908 | } |
| 3909 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3910 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3911 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3912 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3913 | &data->args.seq_args, |
| 3914 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3915 | task)) |
| 3916 | return; |
| 3917 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 3918 | data->args.lock_context, FMODE_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3919 | } |
| 3920 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3921 | 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] | 3922 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3923 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3924 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3925 | 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] | 3926 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3927 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3928 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3929 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3930 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3931 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3932 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3933 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3934 | } |
| 3935 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3936 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
| 3937 | struct nfs_writeargs *args) |
| 3938 | { |
| 3939 | |
| 3940 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3941 | nfs4_stateid_is_current(&args->stateid, |
| 3942 | args->context, |
| 3943 | args->lock_context, |
| 3944 | FMODE_WRITE)) |
| 3945 | return false; |
| 3946 | rpc_restart_call_prepare(task); |
| 3947 | return true; |
| 3948 | } |
| 3949 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3950 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3951 | { |
| 3952 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3953 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3954 | if (nfs4_write_stateid_changed(task, &data->args)) |
| 3955 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3956 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3957 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3958 | } |
| 3959 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3960 | static |
| 3961 | 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] | 3962 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3963 | const struct nfs_pgio_header *hdr = data->header; |
| 3964 | |
| 3965 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3966 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3967 | return false; |
| 3968 | /* Otherwise, request attributes if and only if we don't hold |
| 3969 | * a delegation |
| 3970 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3971 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3972 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3973 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3974 | 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] | 3975 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3976 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3977 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3978 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3979 | data->args.bitmask = NULL; |
| 3980 | data->res.fattr = NULL; |
| 3981 | } else |
| 3982 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3983 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3984 | if (!data->write_done_cb) |
| 3985 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3986 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | data->timestamp = jiffies; |
| 3988 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3989 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3990 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3991 | } |
| 3992 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3993 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3994 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3995 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3996 | &data->args.seq_args, |
| 3997 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3998 | task)) |
| 3999 | return; |
| 4000 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 4001 | data->args.lock_context, FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4002 | } |
| 4003 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4004 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4005 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4006 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4007 | &data->args.seq_args, |
| 4008 | &data->res.seq_res, |
| 4009 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4010 | } |
| 4011 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4012 | 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] | 4013 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4014 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4015 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4016 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4017 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4018 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4019 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4020 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4021 | } |
| 4022 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4023 | 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] | 4024 | { |
| 4025 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4026 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4027 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4028 | } |
| 4029 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4030 | 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] | 4031 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4032 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4033 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4034 | if (data->commit_done_cb == NULL) |
| 4035 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4036 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4037 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4038 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 | } |
| 4040 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4041 | struct nfs4_renewdata { |
| 4042 | struct nfs_client *client; |
| 4043 | unsigned long timestamp; |
| 4044 | }; |
| 4045 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4046 | /* |
| 4047 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4048 | * standalone procedure for queueing an asynchronous RENEW. |
| 4049 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4050 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4051 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4052 | struct nfs4_renewdata *data = calldata; |
| 4053 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4054 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4055 | if (atomic_read(&clp->cl_count) > 1) |
| 4056 | nfs4_schedule_state_renewal(clp); |
| 4057 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4058 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4059 | } |
| 4060 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4061 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4062 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4063 | struct nfs4_renewdata *data = calldata; |
| 4064 | struct nfs_client *clp = data->client; |
| 4065 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4066 | |
| 4067 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4068 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4069 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4070 | return; |
| 4071 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4072 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4073 | return; |
| 4074 | } |
| 4075 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4076 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4077 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4078 | } |
| 4079 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4080 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4081 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4082 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4083 | }; |
| 4084 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4085 | 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] | 4086 | { |
| 4087 | struct rpc_message msg = { |
| 4088 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4089 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4090 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4091 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4092 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4093 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4094 | if (renew_flags == 0) |
| 4095 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4096 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4097 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4098 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4099 | if (data == NULL) |
| 4100 | return -ENOMEM; |
| 4101 | data->client = clp; |
| 4102 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4103 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4104 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4105 | } |
| 4106 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4107 | 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] | 4108 | { |
| 4109 | struct rpc_message msg = { |
| 4110 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4111 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4112 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4113 | }; |
| 4114 | unsigned long now = jiffies; |
| 4115 | int status; |
| 4116 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4117 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4118 | if (status < 0) |
| 4119 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4120 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4121 | return 0; |
| 4122 | } |
| 4123 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4124 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4125 | { |
| 4126 | return (server->caps & NFS_CAP_ACLS) |
| 4127 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 4128 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 4129 | } |
| 4130 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4131 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4132 | * 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] | 4133 | * the stack. |
| 4134 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4135 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4136 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4137 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 4138 | struct page **pages, unsigned int *pgbase) |
| 4139 | { |
| 4140 | struct page *newpage, **spages; |
| 4141 | int rc = 0; |
| 4142 | size_t len; |
| 4143 | spages = pages; |
| 4144 | |
| 4145 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4146 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4147 | newpage = alloc_page(GFP_KERNEL); |
| 4148 | |
| 4149 | if (newpage == NULL) |
| 4150 | goto unwind; |
| 4151 | memcpy(page_address(newpage), buf, len); |
| 4152 | buf += len; |
| 4153 | buflen -= len; |
| 4154 | *pages++ = newpage; |
| 4155 | rc++; |
| 4156 | } while (buflen != 0); |
| 4157 | |
| 4158 | return rc; |
| 4159 | |
| 4160 | unwind: |
| 4161 | for(; rc > 0; rc--) |
| 4162 | __free_page(spages[rc-1]); |
| 4163 | return -ENOMEM; |
| 4164 | } |
| 4165 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4166 | struct nfs4_cached_acl { |
| 4167 | int cached; |
| 4168 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4169 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4170 | }; |
| 4171 | |
| 4172 | 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] | 4173 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4174 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4175 | |
| 4176 | spin_lock(&inode->i_lock); |
| 4177 | kfree(nfsi->nfs4_acl); |
| 4178 | nfsi->nfs4_acl = acl; |
| 4179 | spin_unlock(&inode->i_lock); |
| 4180 | } |
| 4181 | |
| 4182 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4183 | { |
| 4184 | nfs4_set_cached_acl(inode, NULL); |
| 4185 | } |
| 4186 | |
| 4187 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4188 | { |
| 4189 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4190 | struct nfs4_cached_acl *acl; |
| 4191 | int ret = -ENOENT; |
| 4192 | |
| 4193 | spin_lock(&inode->i_lock); |
| 4194 | acl = nfsi->nfs4_acl; |
| 4195 | if (acl == NULL) |
| 4196 | goto out; |
| 4197 | if (buf == NULL) /* user is just asking for length */ |
| 4198 | goto out_len; |
| 4199 | if (acl->cached == 0) |
| 4200 | goto out; |
| 4201 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4202 | if (acl->len > buflen) |
| 4203 | goto out; |
| 4204 | memcpy(buf, acl->data, acl->len); |
| 4205 | out_len: |
| 4206 | ret = acl->len; |
| 4207 | out: |
| 4208 | spin_unlock(&inode->i_lock); |
| 4209 | return ret; |
| 4210 | } |
| 4211 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4212 | 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] | 4213 | { |
| 4214 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4215 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4216 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4217 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4218 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4219 | if (acl == NULL) |
| 4220 | goto out; |
| 4221 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4222 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4223 | } else { |
| 4224 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4225 | if (acl == NULL) |
| 4226 | goto out; |
| 4227 | acl->cached = 0; |
| 4228 | } |
| 4229 | acl->len = acl_len; |
| 4230 | out: |
| 4231 | nfs4_set_cached_acl(inode, acl); |
| 4232 | } |
| 4233 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4234 | /* |
| 4235 | * The getxattr API returns the required buffer length when called with a |
| 4236 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4237 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4238 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4239 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4240 | * the cache. If not so, we throw away the page, and cache the required |
| 4241 | * length. The next getxattr call will then produce another round trip to |
| 4242 | * the server, this time with the input buf of the required size. |
| 4243 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4244 | 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] | 4245 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4246 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4247 | struct nfs_getaclargs args = { |
| 4248 | .fh = NFS_FH(inode), |
| 4249 | .acl_pages = pages, |
| 4250 | .acl_len = buflen, |
| 4251 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4252 | struct nfs_getaclres res = { |
| 4253 | .acl_len = buflen, |
| 4254 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4255 | struct rpc_message msg = { |
| 4256 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4257 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4258 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4259 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4260 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4261 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4262 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4263 | /* As long as we're doing a round trip to the server anyway, |
| 4264 | * let's be prepared for a page of acl data. */ |
| 4265 | if (npages == 0) |
| 4266 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4267 | if (npages > ARRAY_SIZE(pages)) |
| 4268 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4269 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4270 | for (i = 0; i < npages; i++) { |
| 4271 | pages[i] = alloc_page(GFP_KERNEL); |
| 4272 | if (!pages[i]) |
| 4273 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4274 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4275 | |
| 4276 | /* for decoding across pages */ |
| 4277 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4278 | if (!res.acl_scratch) |
| 4279 | goto out_free; |
| 4280 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4281 | args.acl_len = npages * PAGE_SIZE; |
| 4282 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4283 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4284 | 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] | 4285 | __func__, buf, buflen, npages, args.acl_len); |
| 4286 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4287 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4288 | if (ret) |
| 4289 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4290 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4291 | /* Handle the case where the passed-in buffer is too short */ |
| 4292 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4293 | /* Did the user only issue a request for the acl length? */ |
| 4294 | if (buf == NULL) |
| 4295 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4296 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4297 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4298 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4299 | 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] | 4300 | if (buf) { |
| 4301 | if (res.acl_len > buflen) { |
| 4302 | ret = -ERANGE; |
| 4303 | goto out_free; |
| 4304 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4305 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4306 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4307 | out_ok: |
| 4308 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4309 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4310 | for (i = 0; i < npages; i++) |
| 4311 | if (pages[i]) |
| 4312 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4313 | if (res.acl_scratch) |
| 4314 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4315 | return ret; |
| 4316 | } |
| 4317 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4318 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4319 | { |
| 4320 | struct nfs4_exception exception = { }; |
| 4321 | ssize_t ret; |
| 4322 | do { |
| 4323 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 4324 | if (ret >= 0) |
| 4325 | break; |
| 4326 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4327 | } while (exception.retry); |
| 4328 | return ret; |
| 4329 | } |
| 4330 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4331 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4332 | { |
| 4333 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4334 | int ret; |
| 4335 | |
| 4336 | if (!nfs4_server_supports_acls(server)) |
| 4337 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4338 | ret = nfs_revalidate_inode(server, inode); |
| 4339 | if (ret < 0) |
| 4340 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4341 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4342 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4343 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4344 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4345 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4346 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4347 | return ret; |
| 4348 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4349 | } |
| 4350 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4351 | 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] | 4352 | { |
| 4353 | struct nfs_server *server = NFS_SERVER(inode); |
| 4354 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4355 | struct nfs_setaclargs arg = { |
| 4356 | .fh = NFS_FH(inode), |
| 4357 | .acl_pages = pages, |
| 4358 | .acl_len = buflen, |
| 4359 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4360 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4361 | struct rpc_message msg = { |
| 4362 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4363 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4364 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4365 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4366 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4367 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4368 | |
| 4369 | if (!nfs4_server_supports_acls(server)) |
| 4370 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4371 | if (npages > ARRAY_SIZE(pages)) |
| 4372 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4373 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4374 | if (i < 0) |
| 4375 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4376 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4377 | 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] | 4378 | |
| 4379 | /* |
| 4380 | * Free each page after tx, so the only ref left is |
| 4381 | * held by the network stack |
| 4382 | */ |
| 4383 | for (; i > 0; i--) |
| 4384 | put_page(pages[i-1]); |
| 4385 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4386 | /* |
| 4387 | * Acl update can result in inode attribute update. |
| 4388 | * so mark the attribute cache invalid. |
| 4389 | */ |
| 4390 | spin_lock(&inode->i_lock); |
| 4391 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4392 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4393 | nfs_access_zap_cache(inode); |
| 4394 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4395 | return ret; |
| 4396 | } |
| 4397 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4398 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4399 | { |
| 4400 | struct nfs4_exception exception = { }; |
| 4401 | int err; |
| 4402 | do { |
| 4403 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4404 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 4405 | &exception); |
| 4406 | } while (exception.retry); |
| 4407 | return err; |
| 4408 | } |
| 4409 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4410 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 4411 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 4412 | size_t buflen) |
| 4413 | { |
| 4414 | struct nfs_server *server = NFS_SERVER(inode); |
| 4415 | struct nfs_fattr fattr; |
| 4416 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 4417 | |
| 4418 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
| 4419 | struct nfs4_getattr_arg args = { |
| 4420 | .fh = NFS_FH(inode), |
| 4421 | .bitmask = bitmask, |
| 4422 | }; |
| 4423 | struct nfs4_getattr_res res = { |
| 4424 | .fattr = &fattr, |
| 4425 | .label = &label, |
| 4426 | .server = server, |
| 4427 | }; |
| 4428 | struct rpc_message msg = { |
| 4429 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 4430 | .rpc_argp = &args, |
| 4431 | .rpc_resp = &res, |
| 4432 | }; |
| 4433 | int ret; |
| 4434 | |
| 4435 | nfs_fattr_init(&fattr); |
| 4436 | |
| 4437 | ret = rpc_call_sync(server->client, &msg, 0); |
| 4438 | if (ret) |
| 4439 | return ret; |
| 4440 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 4441 | return -ENOENT; |
| 4442 | if (buflen < label.len) |
| 4443 | return -ERANGE; |
| 4444 | return 0; |
| 4445 | } |
| 4446 | |
| 4447 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 4448 | size_t buflen) |
| 4449 | { |
| 4450 | struct nfs4_exception exception = { }; |
| 4451 | int err; |
| 4452 | |
| 4453 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4454 | return -EOPNOTSUPP; |
| 4455 | |
| 4456 | do { |
| 4457 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4458 | _nfs4_get_security_label(inode, buf, buflen), |
| 4459 | &exception); |
| 4460 | } while (exception.retry); |
| 4461 | return err; |
| 4462 | } |
| 4463 | |
| 4464 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 4465 | struct nfs4_label *ilabel, |
| 4466 | struct nfs_fattr *fattr, |
| 4467 | struct nfs4_label *olabel) |
| 4468 | { |
| 4469 | |
| 4470 | struct iattr sattr = {0}; |
| 4471 | struct nfs_server *server = NFS_SERVER(inode); |
| 4472 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
| 4473 | struct nfs_setattrargs args = { |
| 4474 | .fh = NFS_FH(inode), |
| 4475 | .iap = &sattr, |
| 4476 | .server = server, |
| 4477 | .bitmask = bitmask, |
| 4478 | .label = ilabel, |
| 4479 | }; |
| 4480 | struct nfs_setattrres res = { |
| 4481 | .fattr = fattr, |
| 4482 | .label = olabel, |
| 4483 | .server = server, |
| 4484 | }; |
| 4485 | struct rpc_message msg = { |
| 4486 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 4487 | .rpc_argp = &args, |
| 4488 | .rpc_resp = &res, |
| 4489 | }; |
| 4490 | int status; |
| 4491 | |
| 4492 | nfs4_stateid_copy(&args.stateid, &zero_stateid); |
| 4493 | |
| 4494 | status = rpc_call_sync(server->client, &msg, 0); |
| 4495 | if (status) |
| 4496 | dprintk("%s failed: %d\n", __func__, status); |
| 4497 | |
| 4498 | return status; |
| 4499 | } |
| 4500 | |
| 4501 | static int nfs4_do_set_security_label(struct inode *inode, |
| 4502 | struct nfs4_label *ilabel, |
| 4503 | struct nfs_fattr *fattr, |
| 4504 | struct nfs4_label *olabel) |
| 4505 | { |
| 4506 | struct nfs4_exception exception = { }; |
| 4507 | int err; |
| 4508 | |
| 4509 | do { |
| 4510 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4511 | _nfs4_do_set_security_label(inode, ilabel, |
| 4512 | fattr, olabel), |
| 4513 | &exception); |
| 4514 | } while (exception.retry); |
| 4515 | return err; |
| 4516 | } |
| 4517 | |
| 4518 | static int |
| 4519 | nfs4_set_security_label(struct dentry *dentry, const void *buf, size_t buflen) |
| 4520 | { |
| 4521 | struct nfs4_label ilabel, *olabel = NULL; |
| 4522 | struct nfs_fattr fattr; |
| 4523 | struct rpc_cred *cred; |
| 4524 | struct inode *inode = dentry->d_inode; |
| 4525 | int status; |
| 4526 | |
| 4527 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4528 | return -EOPNOTSUPP; |
| 4529 | |
| 4530 | nfs_fattr_init(&fattr); |
| 4531 | |
| 4532 | ilabel.pi = 0; |
| 4533 | ilabel.lfs = 0; |
| 4534 | ilabel.label = (char *)buf; |
| 4535 | ilabel.len = buflen; |
| 4536 | |
| 4537 | cred = rpc_lookup_cred(); |
| 4538 | if (IS_ERR(cred)) |
| 4539 | return PTR_ERR(cred); |
| 4540 | |
| 4541 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 4542 | if (IS_ERR(olabel)) { |
| 4543 | status = -PTR_ERR(olabel); |
| 4544 | goto out; |
| 4545 | } |
| 4546 | |
| 4547 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 4548 | if (status == 0) |
| 4549 | nfs_setsecurity(inode, &fattr, olabel); |
| 4550 | |
| 4551 | nfs4_label_free(olabel); |
| 4552 | out: |
| 4553 | put_rpccred(cred); |
| 4554 | return status; |
| 4555 | } |
| 4556 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 4557 | |
| 4558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4560 | 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] | 4561 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4562 | struct nfs_client *clp = server->nfs_client; |
| 4563 | |
| 4564 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4565 | return 0; |
| 4566 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4567 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4568 | case -NFS4ERR_ADMIN_REVOKED: |
| 4569 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 4570 | if (state == NULL) |
| 4571 | break; |
| 4572 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4573 | case -NFS4ERR_OPENMODE: |
| 4574 | if (state == NULL) |
| 4575 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4576 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4577 | goto stateid_invalid; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4578 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4579 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4580 | if (state != NULL) { |
| 4581 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4582 | goto stateid_invalid; |
| 4583 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4584 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4585 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4586 | nfs4_schedule_lease_recovery(clp); |
| 4587 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4588 | #if defined(CONFIG_NFS_V4_1) |
| 4589 | case -NFS4ERR_BADSESSION: |
| 4590 | case -NFS4ERR_BADSLOT: |
| 4591 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4592 | case -NFS4ERR_DEADSESSION: |
| 4593 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4594 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4595 | case -NFS4ERR_SEQ_MISORDERED: |
| 4596 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4597 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4598 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4599 | task->tk_status = 0; |
| 4600 | return -EAGAIN; |
| 4601 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4602 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4603 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4604 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4605 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 4606 | task->tk_status = 0; |
| 4607 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4608 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4609 | case -NFS4ERR_OLD_STATEID: |
| 4610 | task->tk_status = 0; |
| 4611 | return -EAGAIN; |
| 4612 | } |
| 4613 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4614 | return 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4615 | stateid_invalid: |
| 4616 | task->tk_status = -EIO; |
| 4617 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4618 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4619 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4620 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4621 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 4622 | task->tk_status = 0; |
| 4623 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4624 | } |
| 4625 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4626 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4627 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4628 | { |
| 4629 | __be32 verf[2]; |
| 4630 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4631 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4632 | /* An impossible timestamp guarantees this value |
| 4633 | * will never match a generated boot time. */ |
| 4634 | verf[0] = 0; |
| 4635 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 4636 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4637 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 4638 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 4639 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4640 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4641 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4642 | } |
| 4643 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4644 | static unsigned int |
| 4645 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4646 | char *buf, size_t len) |
| 4647 | { |
| 4648 | unsigned int result; |
| 4649 | |
| 4650 | rcu_read_lock(); |
| 4651 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4652 | clp->cl_ipaddr, |
| 4653 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4654 | RPC_DISPLAY_ADDR), |
| 4655 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4656 | RPC_DISPLAY_PROTO)); |
| 4657 | rcu_read_unlock(); |
| 4658 | return result; |
| 4659 | } |
| 4660 | |
| 4661 | static unsigned int |
| 4662 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4663 | char *buf, size_t len) |
| 4664 | { |
Trond Myklebust | 55b5929 | 2013-07-24 16:36:35 -0400 | [diff] [blame] | 4665 | const char *nodename = clp->cl_rpcclient->cl_nodename; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4666 | |
| 4667 | if (nfs4_client_id_uniquifier[0] != '\0') |
Trond Myklebust | 55b5929 | 2013-07-24 16:36:35 -0400 | [diff] [blame] | 4668 | return scnprintf(buf, len, "Linux NFSv%u.%u %s/%s", |
| 4669 | clp->rpc_ops->version, |
| 4670 | clp->cl_minorversion, |
| 4671 | nfs4_client_id_uniquifier, |
| 4672 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4673 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4674 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4675 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4676 | } |
| 4677 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4678 | /** |
| 4679 | * nfs4_proc_setclientid - Negotiate client ID |
| 4680 | * @clp: state data structure |
| 4681 | * @program: RPC program for NFSv4 callback service |
| 4682 | * @port: IP port number for NFS4 callback service |
| 4683 | * @cred: RPC credential to use for this call |
| 4684 | * @res: where to place the result |
| 4685 | * |
| 4686 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4687 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4688 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4689 | unsigned short port, struct rpc_cred *cred, |
| 4690 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4691 | { |
| 4692 | nfs4_verifier sc_verifier; |
| 4693 | struct nfs4_setclientid setclientid = { |
| 4694 | .sc_verifier = &sc_verifier, |
| 4695 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4696 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4697 | }; |
| 4698 | struct rpc_message msg = { |
| 4699 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4700 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4701 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4702 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4703 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4704 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4705 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4706 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4707 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4708 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4709 | setclientid.sc_name_len = |
| 4710 | nfs4_init_uniform_client_string(clp, |
| 4711 | setclientid.sc_name, |
| 4712 | sizeof(setclientid.sc_name)); |
| 4713 | else |
| 4714 | setclientid.sc_name_len = |
| 4715 | nfs4_init_nonuniform_client_string(clp, |
| 4716 | setclientid.sc_name, |
| 4717 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4718 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4719 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4720 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Djalal Harouni | fe2d539 | 2013-06-18 17:58:12 +0100 | [diff] [blame] | 4721 | sizeof(setclientid.sc_netid), "%s", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4722 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4723 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4724 | rcu_read_unlock(); |
| 4725 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4726 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4727 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4728 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4729 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4730 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4731 | setclientid.sc_name_len, setclientid.sc_name); |
| 4732 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 4733 | dprintk("NFS reply setclientid: %d\n", status); |
| 4734 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4735 | } |
| 4736 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4737 | /** |
| 4738 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4739 | * @clp: state data structure |
| 4740 | * @res: result of a previous SETCLIENTID |
| 4741 | * @cred: RPC credential to use for this call |
| 4742 | * |
| 4743 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4744 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4745 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4746 | struct nfs4_setclientid_res *arg, |
| 4747 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4748 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4749 | struct rpc_message msg = { |
| 4750 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4751 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4752 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4753 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4754 | int status; |
| 4755 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4756 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4757 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4758 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4759 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4760 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4761 | return status; |
| 4762 | } |
| 4763 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4764 | struct nfs4_delegreturndata { |
| 4765 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4766 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4767 | struct nfs_fh fh; |
| 4768 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4769 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4770 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4771 | int rpc_status; |
| 4772 | }; |
| 4773 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4774 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4775 | { |
| 4776 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4777 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4778 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4779 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4780 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4781 | switch (task->tk_status) { |
| 4782 | case -NFS4ERR_STALE_STATEID: |
| 4783 | case -NFS4ERR_EXPIRED: |
| 4784 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4785 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4786 | break; |
| 4787 | default: |
| 4788 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4789 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4790 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4791 | return; |
| 4792 | } |
| 4793 | } |
| 4794 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4795 | } |
| 4796 | |
| 4797 | static void nfs4_delegreturn_release(void *calldata) |
| 4798 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4799 | kfree(calldata); |
| 4800 | } |
| 4801 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4802 | #if defined(CONFIG_NFS_V4_1) |
| 4803 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4804 | { |
| 4805 | struct nfs4_delegreturndata *d_data; |
| 4806 | |
| 4807 | d_data = (struct nfs4_delegreturndata *)data; |
| 4808 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4809 | nfs4_setup_sequence(d_data->res.server, |
| 4810 | &d_data->args.seq_args, |
| 4811 | &d_data->res.seq_res, |
| 4812 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4813 | } |
| 4814 | #endif /* CONFIG_NFS_V4_1 */ |
| 4815 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4816 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4817 | #if defined(CONFIG_NFS_V4_1) |
| 4818 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4819 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4820 | .rpc_call_done = nfs4_delegreturn_done, |
| 4821 | .rpc_release = nfs4_delegreturn_release, |
| 4822 | }; |
| 4823 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4824 | 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] | 4825 | { |
| 4826 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4827 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4828 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4829 | struct rpc_message msg = { |
| 4830 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4831 | .rpc_cred = cred, |
| 4832 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4833 | struct rpc_task_setup task_setup_data = { |
| 4834 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4835 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4836 | .callback_ops = &nfs4_delegreturn_ops, |
| 4837 | .flags = RPC_TASK_ASYNC, |
| 4838 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4839 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4840 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4841 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4842 | if (data == NULL) |
| 4843 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4844 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4845 | data->args.fhandle = &data->fh; |
| 4846 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4847 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4848 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4849 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4850 | data->res.fattr = &data->fattr; |
| 4851 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4852 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4853 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4854 | data->rpc_status = 0; |
| 4855 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4856 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4857 | msg.rpc_argp = &data->args; |
| 4858 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4859 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4860 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4861 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4862 | if (!issync) |
| 4863 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4864 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4865 | if (status != 0) |
| 4866 | goto out; |
| 4867 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4868 | if (status == 0) |
| 4869 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4870 | else |
| 4871 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4872 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4873 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4874 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4875 | } |
| 4876 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4877 | 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] | 4878 | { |
| 4879 | struct nfs_server *server = NFS_SERVER(inode); |
| 4880 | struct nfs4_exception exception = { }; |
| 4881 | int err; |
| 4882 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4883 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4884 | switch (err) { |
| 4885 | case -NFS4ERR_STALE_STATEID: |
| 4886 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4887 | case 0: |
| 4888 | return 0; |
| 4889 | } |
| 4890 | err = nfs4_handle_exception(server, err, &exception); |
| 4891 | } while (exception.retry); |
| 4892 | return err; |
| 4893 | } |
| 4894 | |
| 4895 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4896 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4897 | |
| 4898 | /* |
| 4899 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4900 | */ |
| 4901 | static unsigned long |
| 4902 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4903 | { |
Colin Cross | 416ad3c | 2013-05-06 23:50:06 +0000 | [diff] [blame] | 4904 | freezable_schedule_timeout_killable_unsafe(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4905 | timeout <<= 1; |
| 4906 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4907 | return NFS4_LOCK_MAXTIMEOUT; |
| 4908 | return timeout; |
| 4909 | } |
| 4910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4911 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4912 | { |
| 4913 | struct inode *inode = state->inode; |
| 4914 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4915 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4916 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4917 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4918 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4919 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4920 | struct nfs_lockt_res res = { |
| 4921 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4922 | }; |
| 4923 | struct rpc_message msg = { |
| 4924 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4925 | .rpc_argp = &arg, |
| 4926 | .rpc_resp = &res, |
| 4927 | .rpc_cred = state->owner->so_cred, |
| 4928 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4929 | struct nfs4_lock_state *lsp; |
| 4930 | int status; |
| 4931 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4932 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4933 | status = nfs4_set_lock_state(state, request); |
| 4934 | if (status != 0) |
| 4935 | goto out; |
| 4936 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4937 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4938 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4939 | 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] | 4940 | switch (status) { |
| 4941 | case 0: |
| 4942 | request->fl_type = F_UNLCK; |
| 4943 | break; |
| 4944 | case -NFS4ERR_DENIED: |
| 4945 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4946 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4947 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4948 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4949 | return status; |
| 4950 | } |
| 4951 | |
| 4952 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4953 | { |
| 4954 | struct nfs4_exception exception = { }; |
| 4955 | int err; |
| 4956 | |
| 4957 | do { |
| 4958 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4959 | _nfs4_proc_getlk(state, cmd, request), |
| 4960 | &exception); |
| 4961 | } while (exception.retry); |
| 4962 | return err; |
| 4963 | } |
| 4964 | |
| 4965 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4966 | { |
| 4967 | int res = 0; |
| 4968 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4969 | case FL_POSIX: |
| 4970 | res = posix_lock_file_wait(file, fl); |
| 4971 | break; |
| 4972 | case FL_FLOCK: |
| 4973 | res = flock_lock_file_wait(file, fl); |
| 4974 | break; |
| 4975 | default: |
| 4976 | BUG(); |
| 4977 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4978 | return res; |
| 4979 | } |
| 4980 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4981 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4982 | struct nfs_locku_args arg; |
| 4983 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4984 | struct nfs4_lock_state *lsp; |
| 4985 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4986 | struct file_lock fl; |
| 4987 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4988 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4989 | }; |
| 4990 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4991 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4992 | struct nfs_open_context *ctx, |
| 4993 | struct nfs4_lock_state *lsp, |
| 4994 | struct nfs_seqid *seqid) |
| 4995 | { |
| 4996 | struct nfs4_unlockdata *p; |
| 4997 | struct inode *inode = lsp->ls_state->inode; |
| 4998 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4999 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5000 | if (p == NULL) |
| 5001 | return NULL; |
| 5002 | p->arg.fh = NFS_FH(inode); |
| 5003 | p->arg.fl = &p->fl; |
| 5004 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5005 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5006 | p->arg.stateid = &lsp->ls_stateid; |
| 5007 | p->lsp = lsp; |
| 5008 | atomic_inc(&lsp->ls_count); |
| 5009 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5010 | p->ctx = get_nfs_open_context(ctx); |
| 5011 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5012 | p->server = NFS_SERVER(inode); |
| 5013 | return p; |
| 5014 | } |
| 5015 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5016 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5017 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5018 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5019 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5020 | nfs4_put_lock_state(calldata->lsp); |
| 5021 | put_nfs_open_context(calldata->ctx); |
| 5022 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5023 | } |
| 5024 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5025 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5026 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5027 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5028 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5029 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5030 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5031 | switch (task->tk_status) { |
| 5032 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5033 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 5034 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5035 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5036 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5037 | case -NFS4ERR_BAD_STATEID: |
| 5038 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5039 | case -NFS4ERR_STALE_STATEID: |
| 5040 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5041 | break; |
| 5042 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5043 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5044 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5045 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5046 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5047 | } |
| 5048 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5049 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5050 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5051 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5052 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5053 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5054 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5055 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5056 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5057 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5058 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5059 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5060 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5061 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5062 | &calldata->res.seq_res, |
| 5063 | task) != 0) |
| 5064 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5065 | return; |
| 5066 | out_no_action: |
| 5067 | task->tk_action = NULL; |
| 5068 | out_wait: |
| 5069 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5070 | } |
| 5071 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5072 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5073 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5074 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5075 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5076 | }; |
| 5077 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5078 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5079 | struct nfs_open_context *ctx, |
| 5080 | struct nfs4_lock_state *lsp, |
| 5081 | struct nfs_seqid *seqid) |
| 5082 | { |
| 5083 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5084 | struct rpc_message msg = { |
| 5085 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5086 | .rpc_cred = ctx->cred, |
| 5087 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5088 | struct rpc_task_setup task_setup_data = { |
| 5089 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5090 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5091 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5092 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5093 | .flags = RPC_TASK_ASYNC, |
| 5094 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5095 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5096 | /* Ensure this is an unlock - when canceling a lock, the |
| 5097 | * canceled lock is passed in, and it won't be an unlock. |
| 5098 | */ |
| 5099 | fl->fl_type = F_UNLCK; |
| 5100 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5101 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5102 | if (data == NULL) { |
| 5103 | nfs_free_seqid(seqid); |
| 5104 | return ERR_PTR(-ENOMEM); |
| 5105 | } |
| 5106 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5107 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5108 | msg.rpc_argp = &data->arg; |
| 5109 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5110 | task_setup_data.callback_data = data; |
| 5111 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5112 | } |
| 5113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5114 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5115 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5116 | struct inode *inode = state->inode; |
| 5117 | struct nfs4_state_owner *sp = state->owner; |
| 5118 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5119 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5120 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5121 | struct rpc_task *task; |
| 5122 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5123 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5124 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5125 | status = nfs4_set_lock_state(state, request); |
| 5126 | /* Unlock _before_ we do the RPC call */ |
| 5127 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5128 | /* Exclude nfs_delegation_claim_locks() */ |
| 5129 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5130 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5131 | down_read(&nfsi->rwsem); |
| 5132 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 5133 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5134 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5135 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5136 | } |
| 5137 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5138 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5139 | if (status != 0) |
| 5140 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5141 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5142 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5143 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5144 | goto out; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5145 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5146 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5147 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5148 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5149 | 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] | 5150 | status = PTR_ERR(task); |
| 5151 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5152 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5153 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5154 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5155 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5156 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5157 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5158 | } |
| 5159 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5160 | struct nfs4_lockdata { |
| 5161 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5162 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5163 | struct nfs4_lock_state *lsp; |
| 5164 | struct nfs_open_context *ctx; |
| 5165 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5166 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5167 | int rpc_status; |
| 5168 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5169 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5170 | }; |
| 5171 | |
| 5172 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5173 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5174 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5175 | { |
| 5176 | struct nfs4_lockdata *p; |
| 5177 | struct inode *inode = lsp->ls_state->inode; |
| 5178 | struct nfs_server *server = NFS_SERVER(inode); |
| 5179 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5180 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5181 | if (p == NULL) |
| 5182 | return NULL; |
| 5183 | |
| 5184 | p->arg.fh = NFS_FH(inode); |
| 5185 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5186 | 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] | 5187 | if (p->arg.open_seqid == NULL) |
| 5188 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5189 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5190 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5191 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5192 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5193 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5194 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5195 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5196 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5197 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5198 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5199 | atomic_inc(&lsp->ls_count); |
| 5200 | p->ctx = get_nfs_open_context(ctx); |
| 5201 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5202 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5203 | out_free_seqid: |
| 5204 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5205 | out_free: |
| 5206 | kfree(p); |
| 5207 | return NULL; |
| 5208 | } |
| 5209 | |
| 5210 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 5211 | { |
| 5212 | struct nfs4_lockdata *data = calldata; |
| 5213 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5214 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5215 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5216 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5217 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5218 | /* Do we need to do an open_to_lock_owner? */ |
| 5219 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5220 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5221 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5222 | } |
Trond Myklebust | 8e472f3 | 2013-04-20 01:30:53 -0400 | [diff] [blame] | 5223 | data->arg.open_stateid = &state->open_stateid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5224 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5225 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5226 | } else |
| 5227 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5228 | if (!nfs4_valid_open_stateid(state)) { |
| 5229 | data->rpc_status = -EBADF; |
| 5230 | task->tk_action = NULL; |
| 5231 | goto out_release_open_seqid; |
| 5232 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5233 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5234 | if (nfs4_setup_sequence(data->server, |
| 5235 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5236 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5237 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5238 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5239 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5240 | nfs_release_seqid(data->arg.open_seqid); |
| 5241 | out_release_lock_seqid: |
| 5242 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5243 | out_wait: |
| 5244 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5245 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5246 | } |
| 5247 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5248 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 5249 | { |
| 5250 | struct nfs4_lockdata *data = calldata; |
| 5251 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5252 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5253 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5254 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5255 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5256 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5257 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5258 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5259 | if (data->rpc_status == 0) |
| 5260 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 5261 | else |
| 5262 | goto out; |
| 5263 | } |
| 5264 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5265 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5266 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 5267 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5268 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5269 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5270 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5271 | } |
| 5272 | |
| 5273 | static void nfs4_lock_release(void *calldata) |
| 5274 | { |
| 5275 | struct nfs4_lockdata *data = calldata; |
| 5276 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5277 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5278 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5279 | if (data->cancelled != 0) { |
| 5280 | struct rpc_task *task; |
| 5281 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 5282 | data->arg.lock_seqid); |
| 5283 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5284 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5285 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5286 | } else |
| 5287 | nfs_free_seqid(data->arg.lock_seqid); |
| 5288 | nfs4_put_lock_state(data->lsp); |
| 5289 | put_nfs_open_context(data->ctx); |
| 5290 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5291 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5292 | } |
| 5293 | |
| 5294 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 5295 | .rpc_call_prepare = nfs4_lock_prepare, |
| 5296 | .rpc_call_done = nfs4_lock_done, |
| 5297 | .rpc_release = nfs4_lock_release, |
| 5298 | }; |
| 5299 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5300 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 5301 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5302 | switch (error) { |
| 5303 | case -NFS4ERR_ADMIN_REVOKED: |
| 5304 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5305 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5306 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5307 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5308 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5309 | break; |
| 5310 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5311 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5312 | case -NFS4ERR_EXPIRED: |
| 5313 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5314 | }; |
| 5315 | } |
| 5316 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5317 | 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] | 5318 | { |
| 5319 | struct nfs4_lockdata *data; |
| 5320 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5321 | struct rpc_message msg = { |
| 5322 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 5323 | .rpc_cred = state->owner->so_cred, |
| 5324 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5325 | struct rpc_task_setup task_setup_data = { |
| 5326 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5327 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5328 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5329 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5330 | .flags = RPC_TASK_ASYNC, |
| 5331 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5332 | int ret; |
| 5333 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5334 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5335 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5336 | fl->fl_u.nfs4_fl.owner, |
| 5337 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5338 | if (data == NULL) |
| 5339 | return -ENOMEM; |
| 5340 | if (IS_SETLKW(cmd)) |
| 5341 | data->arg.block = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5342 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5343 | msg.rpc_argp = &data->arg; |
| 5344 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5345 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5346 | if (recovery_type > NFS_LOCK_NEW) { |
| 5347 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 5348 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 5349 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
| 5350 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5351 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5352 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5353 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5354 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 5355 | if (ret == 0) { |
| 5356 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5357 | if (ret) |
| 5358 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 5359 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5360 | } else |
| 5361 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5362 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5363 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5364 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5365 | } |
| 5366 | |
| 5367 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 5368 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5369 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5370 | struct nfs4_exception exception = { |
| 5371 | .inode = state->inode, |
| 5372 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5373 | int err; |
| 5374 | |
| 5375 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5376 | /* Cache the lock if possible... */ |
| 5377 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5378 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5379 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5380 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5381 | break; |
| 5382 | nfs4_handle_exception(server, err, &exception); |
| 5383 | } while (exception.retry); |
| 5384 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5385 | } |
| 5386 | |
| 5387 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5388 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5389 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5390 | struct nfs4_exception exception = { |
| 5391 | .inode = state->inode, |
| 5392 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5393 | int err; |
| 5394 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5395 | err = nfs4_set_lock_state(state, request); |
| 5396 | if (err != 0) |
| 5397 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5398 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5399 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5400 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5401 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5402 | switch (err) { |
| 5403 | default: |
| 5404 | goto out; |
| 5405 | case -NFS4ERR_GRACE: |
| 5406 | case -NFS4ERR_DELAY: |
| 5407 | nfs4_handle_exception(server, err, &exception); |
| 5408 | err = 0; |
| 5409 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5410 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5411 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5412 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5413 | } |
| 5414 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5415 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5416 | /** |
| 5417 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 5418 | * |
| 5419 | * @state: NFSv4 state for an inode |
| 5420 | * |
| 5421 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 5422 | * Otherwise a negative NFS4ERR value is returned. |
| 5423 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5424 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5425 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5426 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5427 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5428 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5429 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5430 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5431 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5432 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 5433 | |
| 5434 | status = nfs41_test_stateid(server, |
| 5435 | &lsp->ls_stateid, |
| 5436 | cred); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5437 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5438 | /* Free the stateid unless the server |
| 5439 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 5440 | if (status != -NFS4ERR_BAD_STATEID) |
| 5441 | nfs41_free_stateid(server, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5442 | &lsp->ls_stateid, |
| 5443 | cred); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5444 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5445 | ret = status; |
| 5446 | } |
| 5447 | } |
| 5448 | }; |
| 5449 | |
| 5450 | return ret; |
| 5451 | } |
| 5452 | |
| 5453 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5454 | { |
| 5455 | int status = NFS_OK; |
| 5456 | |
| 5457 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 5458 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5459 | if (status != NFS_OK) |
| 5460 | status = nfs4_lock_expired(state, request); |
| 5461 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5462 | } |
| 5463 | #endif |
| 5464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5465 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5466 | { |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5467 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5468 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5469 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5470 | unsigned int seq; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5471 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5472 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5473 | if ((fl_flags & FL_POSIX) && |
| 5474 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 5475 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5476 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5477 | status = nfs4_set_lock_state(state, request); |
| 5478 | if (status != 0) |
| 5479 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5480 | request->fl_flags |= FL_ACCESS; |
| 5481 | status = do_vfs_lock(request->fl_file, request); |
| 5482 | if (status < 0) |
| 5483 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5484 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5485 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5486 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5487 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5488 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 5489 | status = do_vfs_lock(request->fl_file, request); |
| 5490 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5491 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5492 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 5493 | up_read(&nfsi->rwsem); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5494 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5495 | if (status != 0) |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5496 | goto out; |
| 5497 | down_read(&nfsi->rwsem); |
| 5498 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { |
| 5499 | status = -NFS4ERR_DELAY; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5500 | goto out_unlock; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5501 | } |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5502 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5503 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5504 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5505 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 5506 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5507 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5508 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5509 | out: |
| 5510 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5511 | return status; |
| 5512 | } |
| 5513 | |
| 5514 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5515 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5516 | struct nfs4_exception exception = { |
| 5517 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5518 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5519 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5520 | int err; |
| 5521 | |
| 5522 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5523 | err = _nfs4_proc_setlk(state, cmd, request); |
| 5524 | if (err == -NFS4ERR_DENIED) |
| 5525 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5526 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5527 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5528 | } while (exception.retry); |
| 5529 | return err; |
| 5530 | } |
| 5531 | |
| 5532 | static int |
| 5533 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 5534 | { |
| 5535 | struct nfs_open_context *ctx; |
| 5536 | struct nfs4_state *state; |
| 5537 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 5538 | int status; |
| 5539 | |
| 5540 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5541 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5542 | state = ctx->state; |
| 5543 | |
| 5544 | if (request->fl_start < 0 || request->fl_end < 0) |
| 5545 | return -EINVAL; |
| 5546 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5547 | if (IS_GETLK(cmd)) { |
| 5548 | if (state != NULL) |
| 5549 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 5550 | return 0; |
| 5551 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5552 | |
| 5553 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 5554 | return -EINVAL; |
| 5555 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5556 | if (request->fl_type == F_UNLCK) { |
| 5557 | if (state != NULL) |
| 5558 | return nfs4_proc_unlck(state, cmd, request); |
| 5559 | return 0; |
| 5560 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5561 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5562 | if (state == NULL) |
| 5563 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5564 | /* |
| 5565 | * Don't rely on the VFS having checked the file open mode, |
| 5566 | * since it won't do this for flock() locks. |
| 5567 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5568 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5569 | case F_RDLCK: |
| 5570 | if (!(filp->f_mode & FMODE_READ)) |
| 5571 | return -EBADF; |
| 5572 | break; |
| 5573 | case F_WRLCK: |
| 5574 | if (!(filp->f_mode & FMODE_WRITE)) |
| 5575 | return -EBADF; |
| 5576 | } |
| 5577 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5578 | do { |
| 5579 | status = nfs4_proc_setlk(state, cmd, request); |
| 5580 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 5581 | break; |
| 5582 | timeout = nfs4_set_lock_task_retry(timeout); |
| 5583 | status = -ERESTARTSYS; |
| 5584 | if (signalled()) |
| 5585 | break; |
| 5586 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5587 | return status; |
| 5588 | } |
| 5589 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5590 | 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] | 5591 | { |
| 5592 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5593 | int err; |
| 5594 | |
| 5595 | err = nfs4_set_lock_state(state, fl); |
| 5596 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5597 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 5598 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5599 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5600 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5601 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5602 | struct nfs_release_lockowner_data { |
| 5603 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5604 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5605 | struct nfs_release_lockowner_args args; |
| 5606 | }; |
| 5607 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5608 | static void nfs4_release_lockowner_release(void *calldata) |
| 5609 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5610 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5611 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5612 | kfree(calldata); |
| 5613 | } |
| 5614 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5615 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5616 | .rpc_release = nfs4_release_lockowner_release, |
| 5617 | }; |
| 5618 | |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 5619 | 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] | 5620 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5621 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5622 | struct rpc_message msg = { |
| 5623 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5624 | }; |
| 5625 | |
| 5626 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5627 | return -EINVAL; |
| 5628 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5629 | if (!data) |
| 5630 | return -ENOMEM; |
| 5631 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5632 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5633 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5634 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5635 | data->args.lock_owner.s_dev = server->s_dev; |
| 5636 | msg.rpc_argp = &data->args; |
| 5637 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5638 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5639 | } |
| 5640 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5641 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5642 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5643 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5644 | const void *buf, size_t buflen, |
| 5645 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5646 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5647 | if (strcmp(key, "") != 0) |
| 5648 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5649 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5650 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5651 | } |
| 5652 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5653 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5654 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5655 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5656 | if (strcmp(key, "") != 0) |
| 5657 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5658 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5659 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5660 | } |
| 5661 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5662 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5663 | size_t list_len, const char *name, |
| 5664 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5665 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5666 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5667 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5668 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5669 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5670 | |
| 5671 | if (list && len <= list_len) |
| 5672 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5673 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5674 | } |
| 5675 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 5676 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5677 | static inline int nfs4_server_supports_labels(struct nfs_server *server) |
| 5678 | { |
| 5679 | return server->caps & NFS_CAP_SECURITY_LABEL; |
| 5680 | } |
| 5681 | |
| 5682 | static int nfs4_xattr_set_nfs4_label(struct dentry *dentry, const char *key, |
| 5683 | const void *buf, size_t buflen, |
| 5684 | int flags, int type) |
| 5685 | { |
| 5686 | if (security_ismaclabel(key)) |
| 5687 | return nfs4_set_security_label(dentry, buf, buflen); |
| 5688 | |
| 5689 | return -EOPNOTSUPP; |
| 5690 | } |
| 5691 | |
| 5692 | static int nfs4_xattr_get_nfs4_label(struct dentry *dentry, const char *key, |
| 5693 | void *buf, size_t buflen, int type) |
| 5694 | { |
| 5695 | if (security_ismaclabel(key)) |
| 5696 | return nfs4_get_security_label(dentry->d_inode, buf, buflen); |
| 5697 | return -EOPNOTSUPP; |
| 5698 | } |
| 5699 | |
| 5700 | static size_t nfs4_xattr_list_nfs4_label(struct dentry *dentry, char *list, |
| 5701 | size_t list_len, const char *name, |
| 5702 | size_t name_len, int type) |
| 5703 | { |
| 5704 | size_t len = 0; |
| 5705 | |
| 5706 | if (nfs_server_capable(dentry->d_inode, NFS_CAP_SECURITY_LABEL)) { |
| 5707 | len = security_inode_listsecurity(dentry->d_inode, NULL, 0); |
| 5708 | if (list && len <= list_len) |
| 5709 | security_inode_listsecurity(dentry->d_inode, list, len); |
| 5710 | } |
| 5711 | return len; |
| 5712 | } |
| 5713 | |
| 5714 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 5715 | .prefix = XATTR_SECURITY_PREFIX, |
| 5716 | .list = nfs4_xattr_list_nfs4_label, |
| 5717 | .get = nfs4_xattr_get_nfs4_label, |
| 5718 | .set = nfs4_xattr_set_nfs4_label, |
| 5719 | }; |
| 5720 | #endif |
| 5721 | |
| 5722 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5723 | /* |
| 5724 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5725 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5726 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5727 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5728 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5729 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5730 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5731 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5732 | return; |
| 5733 | |
| 5734 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5735 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5736 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5737 | fattr->nlink = 2; |
| 5738 | } |
| 5739 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5740 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5741 | const struct qstr *name, |
| 5742 | struct nfs4_fs_locations *fs_locations, |
| 5743 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5744 | { |
| 5745 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 5746 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5747 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5748 | }; |
| 5749 | struct nfs4_fs_locations_arg args = { |
| 5750 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5751 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5752 | .page = page, |
| 5753 | .bitmask = bitmask, |
| 5754 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5755 | struct nfs4_fs_locations_res res = { |
| 5756 | .fs_locations = fs_locations, |
| 5757 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5758 | struct rpc_message msg = { |
| 5759 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5760 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5761 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5762 | }; |
| 5763 | int status; |
| 5764 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5765 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5766 | |
| 5767 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5768 | * is not supported */ |
| 5769 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5770 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5771 | else |
| 5772 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5773 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5774 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5775 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5776 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5777 | 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] | 5778 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5779 | return status; |
| 5780 | } |
| 5781 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5782 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5783 | const struct qstr *name, |
| 5784 | struct nfs4_fs_locations *fs_locations, |
| 5785 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5786 | { |
| 5787 | struct nfs4_exception exception = { }; |
| 5788 | int err; |
| 5789 | do { |
| 5790 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5791 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5792 | &exception); |
| 5793 | } while (exception.retry); |
| 5794 | return err; |
| 5795 | } |
| 5796 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame^] | 5797 | /** |
| 5798 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 5799 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 5800 | */ |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5801 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5802 | { |
| 5803 | int status; |
| 5804 | struct nfs4_secinfo_arg args = { |
| 5805 | .dir_fh = NFS_FH(dir), |
| 5806 | .name = name, |
| 5807 | }; |
| 5808 | struct nfs4_secinfo_res res = { |
| 5809 | .flavors = flavors, |
| 5810 | }; |
| 5811 | struct rpc_message msg = { |
| 5812 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5813 | .rpc_argp = &args, |
| 5814 | .rpc_resp = &res, |
| 5815 | }; |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame^] | 5816 | struct rpc_clnt *clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5817 | |
| 5818 | dprintk("NFS call secinfo %s\n", name->name); |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame^] | 5819 | 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] | 5820 | dprintk("NFS reply secinfo: %d\n", status); |
| 5821 | return status; |
| 5822 | } |
| 5823 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5824 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5825 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5826 | { |
| 5827 | struct nfs4_exception exception = { }; |
| 5828 | int err; |
| 5829 | do { |
| 5830 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5831 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5832 | &exception); |
| 5833 | } while (exception.retry); |
| 5834 | return err; |
| 5835 | } |
| 5836 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5837 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5838 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5839 | * Check the exchange flags returned by the server for invalid flags, having |
| 5840 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5841 | * DS flags set. |
| 5842 | */ |
| 5843 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5844 | { |
| 5845 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5846 | goto out_inval; |
| 5847 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5848 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5849 | goto out_inval; |
| 5850 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5851 | goto out_inval; |
| 5852 | return NFS_OK; |
| 5853 | out_inval: |
| 5854 | return -NFS4ERR_INVAL; |
| 5855 | } |
| 5856 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5857 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5858 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5859 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5860 | { |
| 5861 | if (a->server_scope_sz == b->server_scope_sz && |
| 5862 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5863 | return true; |
| 5864 | |
| 5865 | return false; |
| 5866 | } |
| 5867 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5868 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5869 | * nfs4_proc_bind_conn_to_session() |
| 5870 | * |
| 5871 | * The 4.1 client currently uses the same TCP connection for the |
| 5872 | * fore and backchannel. |
| 5873 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5874 | 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] | 5875 | { |
| 5876 | int status; |
| 5877 | struct nfs41_bind_conn_to_session_res res; |
| 5878 | struct rpc_message msg = { |
| 5879 | .rpc_proc = |
| 5880 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5881 | .rpc_argp = clp, |
| 5882 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5883 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5884 | }; |
| 5885 | |
| 5886 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5887 | |
| 5888 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5889 | if (unlikely(res.session == NULL)) { |
| 5890 | status = -ENOMEM; |
| 5891 | goto out; |
| 5892 | } |
| 5893 | |
| 5894 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5895 | if (status == 0) { |
| 5896 | if (memcmp(res.session->sess_id.data, |
| 5897 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5898 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5899 | status = -EIO; |
| 5900 | goto out_session; |
| 5901 | } |
| 5902 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5903 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5904 | __func__); |
| 5905 | status = -EIO; |
| 5906 | goto out_session; |
| 5907 | } |
| 5908 | if (res.use_conn_in_rdma_mode) { |
| 5909 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5910 | __func__); |
| 5911 | status = -EIO; |
| 5912 | goto out_session; |
| 5913 | } |
| 5914 | } |
| 5915 | out_session: |
| 5916 | kfree(res.session); |
| 5917 | out: |
| 5918 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5919 | return status; |
| 5920 | } |
| 5921 | |
| 5922 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5923 | * nfs4_proc_exchange_id() |
| 5924 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5925 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5926 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5927 | * Since the clientid has expired, all compounds using sessions |
| 5928 | * associated with the stale clientid will be returning |
| 5929 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5930 | * be in some phase of session reset. |
| 5931 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5932 | 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] | 5933 | { |
| 5934 | nfs4_verifier verifier; |
| 5935 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5936 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5937 | .client = clp, |
Trond Myklebust | 4f0b429 | 2013-05-20 12:24:03 -0400 | [diff] [blame] | 5938 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 5939 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5940 | }; |
| 5941 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5942 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5943 | }; |
| 5944 | int status; |
| 5945 | struct rpc_message msg = { |
| 5946 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5947 | .rpc_argp = &args, |
| 5948 | .rpc_resp = &res, |
| 5949 | .rpc_cred = cred, |
| 5950 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5951 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5952 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5953 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 5954 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5955 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5956 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5957 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5958 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5959 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5960 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5961 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5962 | status = -ENOMEM; |
| 5963 | goto out; |
| 5964 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5965 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5966 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5967 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5968 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5969 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5970 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5971 | } |
| 5972 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5973 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5974 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5975 | status = -ENOMEM; |
| 5976 | goto out_server_scope; |
| 5977 | } |
| 5978 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5979 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5980 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5981 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5982 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5983 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5984 | clp->cl_clientid = res.clientid; |
| 5985 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5986 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5987 | clp->cl_seqid = res.seqid; |
| 5988 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5989 | kfree(clp->cl_serverowner); |
| 5990 | clp->cl_serverowner = res.server_owner; |
| 5991 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5992 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5993 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5994 | kfree(clp->cl_implid); |
| 5995 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5996 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5997 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5998 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5999 | res.server_scope)) { |
| 6000 | dprintk("%s: server_scope mismatch detected\n", |
| 6001 | __func__); |
| 6002 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6003 | kfree(clp->cl_serverscope); |
| 6004 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6005 | } |
| 6006 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6007 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6008 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6009 | goto out; |
| 6010 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6011 | } else |
| 6012 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6013 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6014 | out_server_owner: |
| 6015 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6016 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6017 | kfree(res.server_scope); |
| 6018 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6019 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6020 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6021 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6022 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 6023 | clp->cl_implid->date.seconds, |
| 6024 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6025 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6026 | return status; |
| 6027 | } |
| 6028 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6029 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 6030 | struct rpc_cred *cred) |
| 6031 | { |
| 6032 | struct rpc_message msg = { |
| 6033 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 6034 | .rpc_argp = clp, |
| 6035 | .rpc_cred = cred, |
| 6036 | }; |
| 6037 | int status; |
| 6038 | |
| 6039 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 6040 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 6041 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6042 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 6043 | return status; |
| 6044 | } |
| 6045 | |
| 6046 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 6047 | struct rpc_cred *cred) |
| 6048 | { |
| 6049 | unsigned int loop; |
| 6050 | int ret; |
| 6051 | |
| 6052 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 6053 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 6054 | switch (ret) { |
| 6055 | case -NFS4ERR_DELAY: |
| 6056 | case -NFS4ERR_CLIENTID_BUSY: |
| 6057 | ssleep(1); |
| 6058 | break; |
| 6059 | default: |
| 6060 | return ret; |
| 6061 | } |
| 6062 | } |
| 6063 | return 0; |
| 6064 | } |
| 6065 | |
| 6066 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 6067 | { |
| 6068 | struct rpc_cred *cred; |
| 6069 | int ret = 0; |
| 6070 | |
| 6071 | if (clp->cl_mvops->minor_version < 1) |
| 6072 | goto out; |
| 6073 | if (clp->cl_exchange_flags == 0) |
| 6074 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6075 | if (clp->cl_preserve_clid) |
| 6076 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 6077 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6078 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 6079 | if (cred) |
| 6080 | put_rpccred(cred); |
| 6081 | switch (ret) { |
| 6082 | case 0: |
| 6083 | case -NFS4ERR_STALE_CLIENTID: |
| 6084 | clp->cl_exchange_flags = 0; |
| 6085 | } |
| 6086 | out: |
| 6087 | return ret; |
| 6088 | } |
| 6089 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6090 | struct nfs4_get_lease_time_data { |
| 6091 | struct nfs4_get_lease_time_args *args; |
| 6092 | struct nfs4_get_lease_time_res *res; |
| 6093 | struct nfs_client *clp; |
| 6094 | }; |
| 6095 | |
| 6096 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 6097 | void *calldata) |
| 6098 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6099 | struct nfs4_get_lease_time_data *data = |
| 6100 | (struct nfs4_get_lease_time_data *)calldata; |
| 6101 | |
| 6102 | dprintk("--> %s\n", __func__); |
| 6103 | /* just setup sequence, do not trigger session recovery |
| 6104 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6105 | nfs41_setup_sequence(data->clp->cl_session, |
| 6106 | &data->args->la_seq_args, |
| 6107 | &data->res->lr_seq_res, |
| 6108 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6109 | dprintk("<-- %s\n", __func__); |
| 6110 | } |
| 6111 | |
| 6112 | /* |
| 6113 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 6114 | * from sequence operation or clientid errors. |
| 6115 | */ |
| 6116 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 6117 | { |
| 6118 | struct nfs4_get_lease_time_data *data = |
| 6119 | (struct nfs4_get_lease_time_data *)calldata; |
| 6120 | |
| 6121 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6122 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 6123 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6124 | switch (task->tk_status) { |
| 6125 | case -NFS4ERR_DELAY: |
| 6126 | case -NFS4ERR_GRACE: |
| 6127 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 6128 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 6129 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6130 | /* fall through */ |
| 6131 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6132 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6133 | return; |
| 6134 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6135 | dprintk("<-- %s\n", __func__); |
| 6136 | } |
| 6137 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6138 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6139 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 6140 | .rpc_call_done = nfs4_get_lease_time_done, |
| 6141 | }; |
| 6142 | |
| 6143 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 6144 | { |
| 6145 | struct rpc_task *task; |
| 6146 | struct nfs4_get_lease_time_args args; |
| 6147 | struct nfs4_get_lease_time_res res = { |
| 6148 | .lr_fsinfo = fsinfo, |
| 6149 | }; |
| 6150 | struct nfs4_get_lease_time_data data = { |
| 6151 | .args = &args, |
| 6152 | .res = &res, |
| 6153 | .clp = clp, |
| 6154 | }; |
| 6155 | struct rpc_message msg = { |
| 6156 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 6157 | .rpc_argp = &args, |
| 6158 | .rpc_resp = &res, |
| 6159 | }; |
| 6160 | struct rpc_task_setup task_setup = { |
| 6161 | .rpc_client = clp->cl_rpcclient, |
| 6162 | .rpc_message = &msg, |
| 6163 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6164 | .callback_data = &data, |
| 6165 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6166 | }; |
| 6167 | int status; |
| 6168 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6169 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6170 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6171 | dprintk("--> %s\n", __func__); |
| 6172 | task = rpc_run_task(&task_setup); |
| 6173 | |
| 6174 | if (IS_ERR(task)) |
| 6175 | status = PTR_ERR(task); |
| 6176 | else { |
| 6177 | status = task->tk_status; |
| 6178 | rpc_put_task(task); |
| 6179 | } |
| 6180 | dprintk("<-- %s return %d\n", __func__, status); |
| 6181 | |
| 6182 | return status; |
| 6183 | } |
| 6184 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6185 | /* |
| 6186 | * Initialize the values to be used by the client in CREATE_SESSION |
| 6187 | * If nfs4_init_session set the fore channel request and response sizes, |
| 6188 | * use them. |
| 6189 | * |
| 6190 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 6191 | * always set csa_cachethis to FALSE because the current implementation |
| 6192 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 6193 | */ |
| 6194 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 6195 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 6196 | unsigned int max_rqst_sz, max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6197 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 6198 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 6199 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 6200 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6201 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 6202 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 6203 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6204 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 6205 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6206 | |
| 6207 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 6208 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6209 | __func__, |
| 6210 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 6211 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6212 | |
| 6213 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6214 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 6215 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 6216 | args->bc_attrs.max_resp_sz_cached = 0; |
| 6217 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 6218 | args->bc_attrs.max_reqs = 1; |
| 6219 | |
| 6220 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 6221 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 6222 | __func__, |
| 6223 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 6224 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 6225 | args->bc_attrs.max_reqs); |
| 6226 | } |
| 6227 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6228 | 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] | 6229 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6230 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 6231 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 6232 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6233 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 6234 | return -EINVAL; |
| 6235 | /* |
| 6236 | * Our requested max_ops is the minimum we need; we're not |
| 6237 | * prepared to break up compounds into smaller pieces than that. |
| 6238 | * So, no point even trying to continue if the server won't |
| 6239 | * cooperate: |
| 6240 | */ |
| 6241 | if (rcvd->max_ops < sent->max_ops) |
| 6242 | return -EINVAL; |
| 6243 | if (rcvd->max_reqs == 0) |
| 6244 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6245 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 6246 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6247 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6248 | } |
| 6249 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6250 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 6251 | { |
| 6252 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 6253 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6254 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6255 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 6256 | return -EINVAL; |
| 6257 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 6258 | return -EINVAL; |
| 6259 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 6260 | return -EINVAL; |
| 6261 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6262 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6263 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6264 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6265 | return -EINVAL; |
| 6266 | return 0; |
| 6267 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6268 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6269 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 6270 | struct nfs4_session *session) |
| 6271 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6272 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6273 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6274 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 6275 | if (ret) |
| 6276 | return ret; |
| 6277 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6278 | } |
| 6279 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6280 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 6281 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6282 | { |
| 6283 | struct nfs4_session *session = clp->cl_session; |
| 6284 | struct nfs41_create_session_args args = { |
| 6285 | .client = clp, |
| 6286 | .cb_program = NFS4_CALLBACK, |
| 6287 | }; |
| 6288 | struct nfs41_create_session_res res = { |
| 6289 | .client = clp, |
| 6290 | }; |
| 6291 | struct rpc_message msg = { |
| 6292 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 6293 | .rpc_argp = &args, |
| 6294 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6295 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6296 | }; |
| 6297 | int status; |
| 6298 | |
| 6299 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 6300 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6301 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6302 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6303 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 6304 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6305 | /* Verify the session's negotiated channel_attrs values */ |
| 6306 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6307 | /* Increment the clientid slot sequence id */ |
| 6308 | clp->cl_seqid++; |
| 6309 | } |
| 6310 | |
| 6311 | return status; |
| 6312 | } |
| 6313 | |
| 6314 | /* |
| 6315 | * Issues a CREATE_SESSION operation to the server. |
| 6316 | * It is the responsibility of the caller to verify the session is |
| 6317 | * expired before calling this routine. |
| 6318 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6319 | 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] | 6320 | { |
| 6321 | int status; |
| 6322 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6323 | struct nfs4_session *session = clp->cl_session; |
| 6324 | |
| 6325 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 6326 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6327 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6328 | if (status) |
| 6329 | goto out; |
| 6330 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 6331 | /* Init or reset the session slot tables */ |
| 6332 | status = nfs4_setup_session_slot_tables(session); |
| 6333 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6334 | if (status) |
| 6335 | goto out; |
| 6336 | |
| 6337 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 6338 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 6339 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6340 | out: |
| 6341 | dprintk("<-- %s\n", __func__); |
| 6342 | return status; |
| 6343 | } |
| 6344 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6345 | /* |
| 6346 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 6347 | * The caller must serialize access to this routine. |
| 6348 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6349 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 6350 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6351 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6352 | struct rpc_message msg = { |
| 6353 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 6354 | .rpc_argp = session, |
| 6355 | .rpc_cred = cred, |
| 6356 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6357 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6358 | |
| 6359 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 6360 | |
| 6361 | /* session is still being setup */ |
| 6362 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 6363 | return status; |
| 6364 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6365 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6366 | |
| 6367 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 6368 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6369 | "Session has been destroyed regardless...\n", status); |
| 6370 | |
| 6371 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 6372 | return status; |
| 6373 | } |
| 6374 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6375 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6376 | * Renew the cl_session lease. |
| 6377 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6378 | struct nfs4_sequence_data { |
| 6379 | struct nfs_client *clp; |
| 6380 | struct nfs4_sequence_args args; |
| 6381 | struct nfs4_sequence_res res; |
| 6382 | }; |
| 6383 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6384 | static void nfs41_sequence_release(void *data) |
| 6385 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6386 | struct nfs4_sequence_data *calldata = data; |
| 6387 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6388 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6389 | if (atomic_read(&clp->cl_count) > 1) |
| 6390 | nfs4_schedule_state_renewal(clp); |
| 6391 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6392 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6393 | } |
| 6394 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6395 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6396 | { |
| 6397 | switch(task->tk_status) { |
| 6398 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6399 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 6400 | return -EAGAIN; |
| 6401 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6402 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6403 | } |
| 6404 | return 0; |
| 6405 | } |
| 6406 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6407 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6408 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6409 | struct nfs4_sequence_data *calldata = data; |
| 6410 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6411 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6412 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 6413 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6414 | |
| 6415 | if (task->tk_status < 0) { |
| 6416 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6417 | if (atomic_read(&clp->cl_count) == 1) |
| 6418 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6419 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6420 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 6421 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6422 | return; |
| 6423 | } |
| 6424 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6425 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6426 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6427 | dprintk("<-- %s\n", __func__); |
| 6428 | } |
| 6429 | |
| 6430 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 6431 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6432 | struct nfs4_sequence_data *calldata = data; |
| 6433 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6434 | struct nfs4_sequence_args *args; |
| 6435 | struct nfs4_sequence_res *res; |
| 6436 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6437 | args = task->tk_msg.rpc_argp; |
| 6438 | res = task->tk_msg.rpc_resp; |
| 6439 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6440 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6441 | } |
| 6442 | |
| 6443 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 6444 | .rpc_call_done = nfs41_sequence_call_done, |
| 6445 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6446 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6447 | }; |
| 6448 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6449 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 6450 | struct rpc_cred *cred, |
| 6451 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6452 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6453 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6454 | struct rpc_message msg = { |
| 6455 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 6456 | .rpc_cred = cred, |
| 6457 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6458 | struct rpc_task_setup task_setup_data = { |
| 6459 | .rpc_client = clp->cl_rpcclient, |
| 6460 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6461 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 6462 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6463 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6464 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6465 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6466 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 6467 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6468 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6469 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6470 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6471 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6472 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6473 | if (is_privileged) |
| 6474 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6475 | msg.rpc_argp = &calldata->args; |
| 6476 | msg.rpc_resp = &calldata->res; |
| 6477 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6478 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6479 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6480 | return rpc_run_task(&task_setup_data); |
| 6481 | } |
| 6482 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6483 | 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] | 6484 | { |
| 6485 | struct rpc_task *task; |
| 6486 | int ret = 0; |
| 6487 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6488 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 6489 | return 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6490 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6491 | if (IS_ERR(task)) |
| 6492 | ret = PTR_ERR(task); |
| 6493 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6494 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6495 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6496 | return ret; |
| 6497 | } |
| 6498 | |
| 6499 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 6500 | { |
| 6501 | struct rpc_task *task; |
| 6502 | int ret; |
| 6503 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6504 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6505 | if (IS_ERR(task)) { |
| 6506 | ret = PTR_ERR(task); |
| 6507 | goto out; |
| 6508 | } |
| 6509 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6510 | if (!ret) { |
| 6511 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 6512 | |
| 6513 | if (task->tk_status == 0) |
| 6514 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6515 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6516 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6517 | rpc_put_task(task); |
| 6518 | out: |
| 6519 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6520 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6521 | } |
| 6522 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6523 | struct nfs4_reclaim_complete_data { |
| 6524 | struct nfs_client *clp; |
| 6525 | struct nfs41_reclaim_complete_args arg; |
| 6526 | struct nfs41_reclaim_complete_res res; |
| 6527 | }; |
| 6528 | |
| 6529 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 6530 | { |
| 6531 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6532 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6533 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 6534 | &calldata->arg.seq_args, |
| 6535 | &calldata->res.seq_res, |
| 6536 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6537 | } |
| 6538 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6539 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6540 | { |
| 6541 | switch(task->tk_status) { |
| 6542 | case 0: |
| 6543 | case -NFS4ERR_COMPLETE_ALREADY: |
| 6544 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 6545 | break; |
| 6546 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6547 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6548 | /* fall through */ |
| 6549 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6550 | return -EAGAIN; |
| 6551 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6552 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6553 | } |
| 6554 | return 0; |
| 6555 | } |
| 6556 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6557 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 6558 | { |
| 6559 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6560 | struct nfs_client *clp = calldata->clp; |
| 6561 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 6562 | |
| 6563 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6564 | if (!nfs41_sequence_done(task, res)) |
| 6565 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6566 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6567 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 6568 | rpc_restart_call_prepare(task); |
| 6569 | return; |
| 6570 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6571 | dprintk("<-- %s\n", __func__); |
| 6572 | } |
| 6573 | |
| 6574 | static void nfs4_free_reclaim_complete_data(void *data) |
| 6575 | { |
| 6576 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6577 | |
| 6578 | kfree(calldata); |
| 6579 | } |
| 6580 | |
| 6581 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 6582 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 6583 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 6584 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 6585 | }; |
| 6586 | |
| 6587 | /* |
| 6588 | * Issue a global reclaim complete. |
| 6589 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 6590 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 6591 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6592 | { |
| 6593 | struct nfs4_reclaim_complete_data *calldata; |
| 6594 | struct rpc_task *task; |
| 6595 | struct rpc_message msg = { |
| 6596 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 6597 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6598 | }; |
| 6599 | struct rpc_task_setup task_setup_data = { |
| 6600 | .rpc_client = clp->cl_rpcclient, |
| 6601 | .rpc_message = &msg, |
| 6602 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 6603 | .flags = RPC_TASK_ASYNC, |
| 6604 | }; |
| 6605 | int status = -ENOMEM; |
| 6606 | |
| 6607 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6608 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6609 | if (calldata == NULL) |
| 6610 | goto out; |
| 6611 | calldata->clp = clp; |
| 6612 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6613 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6614 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6615 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6616 | msg.rpc_argp = &calldata->arg; |
| 6617 | msg.rpc_resp = &calldata->res; |
| 6618 | task_setup_data.callback_data = calldata; |
| 6619 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6620 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6621 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6622 | goto out; |
| 6623 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6624 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6625 | if (status == 0) |
| 6626 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6627 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6628 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6629 | out: |
| 6630 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6631 | return status; |
| 6632 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6633 | |
| 6634 | static void |
| 6635 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6636 | { |
| 6637 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6638 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6639 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6640 | |
| 6641 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6642 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6643 | * right now covering the LAYOUTGET we are about to send. |
| 6644 | * However, that is not so catastrophic, and there seems |
| 6645 | * to be no way to prevent it completely. |
| 6646 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6647 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6648 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6649 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6650 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6651 | NFS_I(lgp->args.inode)->layout, |
| 6652 | lgp->args.ctx->state)) { |
| 6653 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6654 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6655 | } |
| 6656 | |
| 6657 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6658 | { |
| 6659 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6660 | struct inode *inode = lgp->args.inode; |
| 6661 | struct nfs_server *server = NFS_SERVER(inode); |
| 6662 | struct pnfs_layout_hdr *lo; |
| 6663 | struct nfs4_state *state = NULL; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6664 | unsigned long timeo, giveup; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6665 | |
| 6666 | dprintk("--> %s\n", __func__); |
| 6667 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6668 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6669 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6670 | |
| 6671 | switch (task->tk_status) { |
| 6672 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6673 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6674 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6675 | case -NFS4ERR_RECALLCONFLICT: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6676 | timeo = rpc_get_timeout(task->tk_client); |
| 6677 | giveup = lgp->args.timestamp + timeo; |
| 6678 | if (time_after(giveup, jiffies)) |
| 6679 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6680 | break; |
| 6681 | case -NFS4ERR_EXPIRED: |
| 6682 | case -NFS4ERR_BAD_STATEID: |
| 6683 | spin_lock(&inode->i_lock); |
| 6684 | lo = NFS_I(inode)->layout; |
| 6685 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6686 | spin_unlock(&inode->i_lock); |
| 6687 | /* If the open stateid was bad, then recover it. */ |
| 6688 | state = lgp->args.ctx->state; |
| 6689 | } else { |
| 6690 | LIST_HEAD(head); |
| 6691 | |
| 6692 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6693 | spin_unlock(&inode->i_lock); |
| 6694 | /* Mark the bad layout state as invalid, then |
| 6695 | * retry using the open stateid. */ |
| 6696 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6697 | } |
| 6698 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6699 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6700 | rpc_restart_call_prepare(task); |
| 6701 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6702 | dprintk("<-- %s\n", __func__); |
| 6703 | } |
| 6704 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6705 | static size_t max_response_pages(struct nfs_server *server) |
| 6706 | { |
| 6707 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6708 | return nfs_page_array_len(0, max_resp_sz); |
| 6709 | } |
| 6710 | |
| 6711 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6712 | { |
| 6713 | int i; |
| 6714 | |
| 6715 | if (!pages) |
| 6716 | return; |
| 6717 | |
| 6718 | for (i = 0; i < size; i++) { |
| 6719 | if (!pages[i]) |
| 6720 | break; |
| 6721 | __free_page(pages[i]); |
| 6722 | } |
| 6723 | kfree(pages); |
| 6724 | } |
| 6725 | |
| 6726 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6727 | { |
| 6728 | struct page **pages; |
| 6729 | int i; |
| 6730 | |
| 6731 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6732 | if (!pages) { |
| 6733 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6734 | return NULL; |
| 6735 | } |
| 6736 | |
| 6737 | for (i = 0; i < size; i++) { |
| 6738 | pages[i] = alloc_page(gfp_flags); |
| 6739 | if (!pages[i]) { |
| 6740 | dprintk("%s: failed to allocate page\n", __func__); |
| 6741 | nfs4_free_pages(pages, size); |
| 6742 | return NULL; |
| 6743 | } |
| 6744 | } |
| 6745 | |
| 6746 | return pages; |
| 6747 | } |
| 6748 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6749 | static void nfs4_layoutget_release(void *calldata) |
| 6750 | { |
| 6751 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6752 | struct inode *inode = lgp->args.inode; |
| 6753 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6754 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6755 | |
| 6756 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6757 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6758 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6759 | put_nfs_open_context(lgp->args.ctx); |
| 6760 | kfree(calldata); |
| 6761 | dprintk("<-- %s\n", __func__); |
| 6762 | } |
| 6763 | |
| 6764 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6765 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6766 | .rpc_call_done = nfs4_layoutget_done, |
| 6767 | .rpc_release = nfs4_layoutget_release, |
| 6768 | }; |
| 6769 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6770 | struct pnfs_layout_segment * |
| 6771 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6772 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6773 | struct inode *inode = lgp->args.inode; |
| 6774 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6775 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6776 | struct rpc_task *task; |
| 6777 | struct rpc_message msg = { |
| 6778 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6779 | .rpc_argp = &lgp->args, |
| 6780 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 6781 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6782 | }; |
| 6783 | struct rpc_task_setup task_setup_data = { |
| 6784 | .rpc_client = server->client, |
| 6785 | .rpc_message = &msg, |
| 6786 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6787 | .callback_data = lgp, |
| 6788 | .flags = RPC_TASK_ASYNC, |
| 6789 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6790 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6791 | int status = 0; |
| 6792 | |
| 6793 | dprintk("--> %s\n", __func__); |
| 6794 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6795 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6796 | if (!lgp->args.layout.pages) { |
| 6797 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6798 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6799 | } |
| 6800 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6801 | lgp->args.timestamp = jiffies; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6802 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6803 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6804 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6805 | 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] | 6806 | |
| 6807 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 6808 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 6809 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6810 | task = rpc_run_task(&task_setup_data); |
| 6811 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6812 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6813 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6814 | if (status == 0) |
| 6815 | status = task->tk_status; |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 6816 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 6817 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6818 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6819 | rpc_put_task(task); |
| 6820 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6821 | if (status) |
| 6822 | return ERR_PTR(status); |
| 6823 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6824 | } |
| 6825 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6826 | static void |
| 6827 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6828 | { |
| 6829 | struct nfs4_layoutreturn *lrp = calldata; |
| 6830 | |
| 6831 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6832 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 6833 | &lrp->args.seq_args, |
| 6834 | &lrp->res.seq_res, |
| 6835 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6836 | } |
| 6837 | |
| 6838 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6839 | { |
| 6840 | struct nfs4_layoutreturn *lrp = calldata; |
| 6841 | struct nfs_server *server; |
| 6842 | |
| 6843 | dprintk("--> %s\n", __func__); |
| 6844 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6845 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6846 | return; |
| 6847 | |
| 6848 | server = NFS_SERVER(lrp->args.inode); |
| 6849 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6850 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6851 | return; |
| 6852 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6853 | dprintk("<-- %s\n", __func__); |
| 6854 | } |
| 6855 | |
| 6856 | static void nfs4_layoutreturn_release(void *calldata) |
| 6857 | { |
| 6858 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6859 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6860 | |
| 6861 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6862 | spin_lock(&lo->plh_inode->i_lock); |
| 6863 | if (lrp->res.lrs_present) |
| 6864 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6865 | lo->plh_block_lgets--; |
| 6866 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6867 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6868 | kfree(calldata); |
| 6869 | dprintk("<-- %s\n", __func__); |
| 6870 | } |
| 6871 | |
| 6872 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6873 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6874 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6875 | .rpc_release = nfs4_layoutreturn_release, |
| 6876 | }; |
| 6877 | |
| 6878 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6879 | { |
| 6880 | struct rpc_task *task; |
| 6881 | struct rpc_message msg = { |
| 6882 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6883 | .rpc_argp = &lrp->args, |
| 6884 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 6885 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6886 | }; |
| 6887 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 6888 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6889 | .rpc_message = &msg, |
| 6890 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6891 | .callback_data = lrp, |
| 6892 | }; |
| 6893 | int status; |
| 6894 | |
| 6895 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6896 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6897 | task = rpc_run_task(&task_setup_data); |
| 6898 | if (IS_ERR(task)) |
| 6899 | return PTR_ERR(task); |
| 6900 | status = task->tk_status; |
| 6901 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6902 | rpc_put_task(task); |
| 6903 | return status; |
| 6904 | } |
| 6905 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6906 | /* |
| 6907 | * Retrieve the list of Data Server devices from the MDS. |
| 6908 | */ |
| 6909 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6910 | const struct nfs_fh *fh, |
| 6911 | struct pnfs_devicelist *devlist) |
| 6912 | { |
| 6913 | struct nfs4_getdevicelist_args args = { |
| 6914 | .fh = fh, |
| 6915 | .layoutclass = server->pnfs_curr_ld->id, |
| 6916 | }; |
| 6917 | struct nfs4_getdevicelist_res res = { |
| 6918 | .devlist = devlist, |
| 6919 | }; |
| 6920 | struct rpc_message msg = { |
| 6921 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6922 | .rpc_argp = &args, |
| 6923 | .rpc_resp = &res, |
| 6924 | }; |
| 6925 | int status; |
| 6926 | |
| 6927 | dprintk("--> %s\n", __func__); |
| 6928 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6929 | &res.seq_res, 0); |
| 6930 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6931 | return status; |
| 6932 | } |
| 6933 | |
| 6934 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6935 | const struct nfs_fh *fh, |
| 6936 | struct pnfs_devicelist *devlist) |
| 6937 | { |
| 6938 | struct nfs4_exception exception = { }; |
| 6939 | int err; |
| 6940 | |
| 6941 | do { |
| 6942 | err = nfs4_handle_exception(server, |
| 6943 | _nfs4_getdevicelist(server, fh, devlist), |
| 6944 | &exception); |
| 6945 | } while (exception.retry); |
| 6946 | |
| 6947 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6948 | err, devlist->num_devs); |
| 6949 | |
| 6950 | return err; |
| 6951 | } |
| 6952 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6953 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6954 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 6955 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 6956 | struct pnfs_device *pdev, |
| 6957 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6958 | { |
| 6959 | struct nfs4_getdeviceinfo_args args = { |
| 6960 | .pdev = pdev, |
| 6961 | }; |
| 6962 | struct nfs4_getdeviceinfo_res res = { |
| 6963 | .pdev = pdev, |
| 6964 | }; |
| 6965 | struct rpc_message msg = { |
| 6966 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6967 | .rpc_argp = &args, |
| 6968 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 6969 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6970 | }; |
| 6971 | int status; |
| 6972 | |
| 6973 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6974 | 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] | 6975 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6976 | |
| 6977 | return status; |
| 6978 | } |
| 6979 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 6980 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 6981 | struct pnfs_device *pdev, |
| 6982 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6983 | { |
| 6984 | struct nfs4_exception exception = { }; |
| 6985 | int err; |
| 6986 | |
| 6987 | do { |
| 6988 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 6989 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6990 | &exception); |
| 6991 | } while (exception.retry); |
| 6992 | return err; |
| 6993 | } |
| 6994 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6995 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6996 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6997 | { |
| 6998 | struct nfs4_layoutcommit_data *data = calldata; |
| 6999 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7000 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7001 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7002 | nfs41_setup_sequence(session, |
| 7003 | &data->args.seq_args, |
| 7004 | &data->res.seq_res, |
| 7005 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7006 | } |
| 7007 | |
| 7008 | static void |
| 7009 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 7010 | { |
| 7011 | struct nfs4_layoutcommit_data *data = calldata; |
| 7012 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 7013 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7014 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7015 | return; |
| 7016 | |
| 7017 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7018 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 7019 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 7020 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 7021 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7022 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7023 | break; |
| 7024 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7025 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 7026 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7027 | break; |
| 7028 | default: |
| 7029 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 7030 | rpc_restart_call_prepare(task); |
| 7031 | return; |
| 7032 | } |
| 7033 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7034 | } |
| 7035 | |
| 7036 | static void nfs4_layoutcommit_release(void *calldata) |
| 7037 | { |
| 7038 | struct nfs4_layoutcommit_data *data = calldata; |
| 7039 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 7040 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7041 | put_rpccred(data->cred); |
| 7042 | kfree(data); |
| 7043 | } |
| 7044 | |
| 7045 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 7046 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 7047 | .rpc_call_done = nfs4_layoutcommit_done, |
| 7048 | .rpc_release = nfs4_layoutcommit_release, |
| 7049 | }; |
| 7050 | |
| 7051 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 7052 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7053 | { |
| 7054 | struct rpc_message msg = { |
| 7055 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 7056 | .rpc_argp = &data->args, |
| 7057 | .rpc_resp = &data->res, |
| 7058 | .rpc_cred = data->cred, |
| 7059 | }; |
| 7060 | struct rpc_task_setup task_setup_data = { |
| 7061 | .task = &data->task, |
| 7062 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 7063 | .rpc_message = &msg, |
| 7064 | .callback_ops = &nfs4_layoutcommit_ops, |
| 7065 | .callback_data = data, |
| 7066 | .flags = RPC_TASK_ASYNC, |
| 7067 | }; |
| 7068 | struct rpc_task *task; |
| 7069 | int status = 0; |
| 7070 | |
| 7071 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 7072 | "lbw: %llu inode %lu\n", |
| 7073 | data->task.tk_pid, sync, |
| 7074 | data->args.lastbytewritten, |
| 7075 | data->args.inode->i_ino); |
| 7076 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 7077 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7078 | task = rpc_run_task(&task_setup_data); |
| 7079 | if (IS_ERR(task)) |
| 7080 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 7081 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7082 | goto out; |
| 7083 | status = nfs4_wait_for_completion_rpc_task(task); |
| 7084 | if (status != 0) |
| 7085 | goto out; |
| 7086 | status = task->tk_status; |
| 7087 | out: |
| 7088 | dprintk("%s: status %d\n", __func__, status); |
| 7089 | rpc_put_task(task); |
| 7090 | return status; |
| 7091 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7092 | |
| 7093 | static int |
| 7094 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 7095 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 7096 | { |
| 7097 | struct nfs41_secinfo_no_name_args args = { |
| 7098 | .style = SECINFO_STYLE_CURRENT_FH, |
| 7099 | }; |
| 7100 | struct nfs4_secinfo_res res = { |
| 7101 | .flavors = flavors, |
| 7102 | }; |
| 7103 | struct rpc_message msg = { |
| 7104 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 7105 | .rpc_argp = &args, |
| 7106 | .rpc_resp = &res, |
| 7107 | }; |
| 7108 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 7109 | } |
| 7110 | |
| 7111 | static int |
| 7112 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 7113 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 7114 | { |
| 7115 | struct nfs4_exception exception = { }; |
| 7116 | int err; |
| 7117 | do { |
| 7118 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 7119 | switch (err) { |
| 7120 | case 0: |
| 7121 | case -NFS4ERR_WRONGSEC: |
| 7122 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 7123 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7124 | default: |
| 7125 | err = nfs4_handle_exception(server, err, &exception); |
| 7126 | } |
| 7127 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 7128 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7129 | return err; |
| 7130 | } |
| 7131 | |
| 7132 | static int |
| 7133 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 7134 | struct nfs_fsinfo *info) |
| 7135 | { |
| 7136 | int err; |
| 7137 | struct page *page; |
| 7138 | rpc_authflavor_t flavor; |
| 7139 | struct nfs4_secinfo_flavors *flavors; |
| 7140 | |
| 7141 | page = alloc_page(GFP_KERNEL); |
| 7142 | if (!page) { |
| 7143 | err = -ENOMEM; |
| 7144 | goto out; |
| 7145 | } |
| 7146 | |
| 7147 | flavors = page_address(page); |
| 7148 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 7149 | |
| 7150 | /* |
| 7151 | * Fall back on "guess and check" method if |
| 7152 | * the server doesn't support SECINFO_NO_NAME |
| 7153 | */ |
| 7154 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 7155 | err = nfs4_find_root_sec(server, fhandle, info); |
| 7156 | goto out_freepage; |
| 7157 | } |
| 7158 | if (err) |
| 7159 | goto out_freepage; |
| 7160 | |
| 7161 | flavor = nfs_find_best_sec(flavors); |
| 7162 | if (err == 0) |
| 7163 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 7164 | |
| 7165 | out_freepage: |
| 7166 | put_page(page); |
| 7167 | if (err == -EACCES) |
| 7168 | return -EPERM; |
| 7169 | out: |
| 7170 | return err; |
| 7171 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7172 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7173 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 7174 | nfs4_stateid *stateid, |
| 7175 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7176 | { |
| 7177 | int status; |
| 7178 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7179 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7180 | }; |
| 7181 | struct nfs41_test_stateid_res res; |
| 7182 | struct rpc_message msg = { |
| 7183 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 7184 | .rpc_argp = &args, |
| 7185 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7186 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7187 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7188 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7189 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 7190 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7191 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7192 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
| 7193 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7194 | if (status != NFS_OK) { |
| 7195 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7196 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7197 | } |
| 7198 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7199 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7200 | } |
| 7201 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7202 | /** |
| 7203 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 7204 | * |
| 7205 | * @server: server / transport on which to perform the operation |
| 7206 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7207 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7208 | * |
| 7209 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 7210 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 7211 | * failed or the state ID is not currently valid. |
| 7212 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7213 | static int nfs41_test_stateid(struct nfs_server *server, |
| 7214 | nfs4_stateid *stateid, |
| 7215 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7216 | { |
| 7217 | struct nfs4_exception exception = { }; |
| 7218 | int err; |
| 7219 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7220 | err = _nfs41_test_stateid(server, stateid, cred); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7221 | if (err != -NFS4ERR_DELAY) |
| 7222 | break; |
| 7223 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7224 | } while (exception.retry); |
| 7225 | return err; |
| 7226 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7227 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7228 | struct nfs_free_stateid_data { |
| 7229 | struct nfs_server *server; |
| 7230 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7231 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7232 | }; |
| 7233 | |
| 7234 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 7235 | { |
| 7236 | struct nfs_free_stateid_data *data = calldata; |
| 7237 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 7238 | &data->args.seq_args, |
| 7239 | &data->res.seq_res, |
| 7240 | task); |
| 7241 | } |
| 7242 | |
| 7243 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 7244 | { |
| 7245 | struct nfs_free_stateid_data *data = calldata; |
| 7246 | |
| 7247 | nfs41_sequence_done(task, &data->res.seq_res); |
| 7248 | |
| 7249 | switch (task->tk_status) { |
| 7250 | case -NFS4ERR_DELAY: |
| 7251 | if (nfs4_async_handle_error(task, data->server, NULL) == -EAGAIN) |
| 7252 | rpc_restart_call_prepare(task); |
| 7253 | } |
| 7254 | } |
| 7255 | |
| 7256 | static void nfs41_free_stateid_release(void *calldata) |
| 7257 | { |
| 7258 | kfree(calldata); |
| 7259 | } |
| 7260 | |
| 7261 | const struct rpc_call_ops nfs41_free_stateid_ops = { |
| 7262 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 7263 | .rpc_call_done = nfs41_free_stateid_done, |
| 7264 | .rpc_release = nfs41_free_stateid_release, |
| 7265 | }; |
| 7266 | |
| 7267 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
| 7268 | nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7269 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7270 | bool privileged) |
| 7271 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7272 | struct rpc_message msg = { |
| 7273 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7274 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7275 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7276 | struct rpc_task_setup task_setup = { |
| 7277 | .rpc_client = server->client, |
| 7278 | .rpc_message = &msg, |
| 7279 | .callback_ops = &nfs41_free_stateid_ops, |
| 7280 | .flags = RPC_TASK_ASYNC, |
| 7281 | }; |
| 7282 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7283 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7284 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7285 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 7286 | if (!data) |
| 7287 | return ERR_PTR(-ENOMEM); |
| 7288 | data->server = server; |
| 7289 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 7290 | |
| 7291 | task_setup.callback_data = data; |
| 7292 | |
| 7293 | msg.rpc_argp = &data->args; |
| 7294 | msg.rpc_resp = &data->res; |
| 7295 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
| 7296 | if (privileged) |
| 7297 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 7298 | |
| 7299 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7300 | } |
| 7301 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7302 | /** |
| 7303 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 7304 | * |
| 7305 | * @server: server / transport on which to perform the operation |
| 7306 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7307 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7308 | * |
| 7309 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 7310 | * negative NFS4ERR value is returned. |
| 7311 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7312 | static int nfs41_free_stateid(struct nfs_server *server, |
| 7313 | nfs4_stateid *stateid, |
| 7314 | struct rpc_cred *cred) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7315 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7316 | struct rpc_task *task; |
| 7317 | int ret; |
| 7318 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7319 | task = _nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7320 | if (IS_ERR(task)) |
| 7321 | return PTR_ERR(task); |
| 7322 | ret = rpc_wait_for_completion_task(task); |
| 7323 | if (!ret) |
| 7324 | ret = task->tk_status; |
| 7325 | rpc_put_task(task); |
| 7326 | return ret; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7327 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7328 | |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7329 | static int nfs41_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp) |
| 7330 | { |
| 7331 | struct rpc_task *task; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7332 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7333 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7334 | task = _nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7335 | nfs4_free_lock_state(server, lsp); |
| 7336 | if (IS_ERR(task)) |
| 7337 | return PTR_ERR(task); |
| 7338 | rpc_put_task(task); |
| 7339 | return 0; |
| 7340 | } |
| 7341 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7342 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 7343 | const nfs4_stateid *s2) |
| 7344 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7345 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7346 | return false; |
| 7347 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7348 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7349 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7350 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7351 | return true; |
| 7352 | |
| 7353 | return false; |
| 7354 | } |
| 7355 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7356 | #endif /* CONFIG_NFS_V4_1 */ |
| 7357 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7358 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 7359 | const nfs4_stateid *s2) |
| 7360 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7361 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7362 | } |
| 7363 | |
| 7364 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7365 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7366 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7367 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7368 | .recover_open = nfs4_open_reclaim, |
| 7369 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7370 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7371 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7372 | }; |
| 7373 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7374 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7375 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7376 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 7377 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 7378 | .recover_open = nfs4_open_reclaim, |
| 7379 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7380 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7381 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7382 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7383 | }; |
| 7384 | #endif /* CONFIG_NFS_V4_1 */ |
| 7385 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7386 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7387 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7388 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7389 | .recover_open = nfs4_open_expired, |
| 7390 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7391 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7392 | }; |
| 7393 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7394 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7395 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7396 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 7397 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7398 | .recover_open = nfs41_open_expired, |
| 7399 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7400 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7401 | }; |
| 7402 | #endif /* CONFIG_NFS_V4_1 */ |
| 7403 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7404 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7405 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7406 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7407 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7408 | }; |
| 7409 | |
| 7410 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7411 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7412 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7413 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7414 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7415 | }; |
| 7416 | #endif |
| 7417 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7418 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 7419 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 7420 | .init_caps = NFS_CAP_READDIRPLUS |
| 7421 | | NFS_CAP_ATOMIC_OPEN |
| 7422 | | NFS_CAP_CHANGE_ATTR |
| 7423 | | NFS_CAP_POSIX_LOCK, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7424 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7425 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7426 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7427 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7428 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 7429 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 7430 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7431 | }; |
| 7432 | |
| 7433 | #if defined(CONFIG_NFS_V4_1) |
| 7434 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 7435 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 7436 | .init_caps = NFS_CAP_READDIRPLUS |
| 7437 | | NFS_CAP_ATOMIC_OPEN |
| 7438 | | NFS_CAP_CHANGE_ATTR |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 7439 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 7440 | | NFS_CAP_STATEID_NFSV41 |
| 7441 | | NFS_CAP_ATOMIC_OPEN_V1, |
Bryan Schumaker | 104287c | 2012-11-12 14:13:13 -0500 | [diff] [blame] | 7442 | .call_sync = nfs4_call_sync_sequence, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7443 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7444 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7445 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7446 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 7447 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 7448 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7449 | }; |
| 7450 | #endif |
| 7451 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7452 | #if defined(CONFIG_NFS_V4_2) |
| 7453 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 7454 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 7455 | .init_caps = NFS_CAP_READDIRPLUS |
| 7456 | | NFS_CAP_ATOMIC_OPEN |
| 7457 | | NFS_CAP_CHANGE_ATTR |
| 7458 | | NFS_CAP_POSIX_LOCK |
| 7459 | | NFS_CAP_STATEID_NFSV41 |
| 7460 | | NFS_CAP_ATOMIC_OPEN_V1, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7461 | .call_sync = nfs4_call_sync_sequence, |
| 7462 | .match_stateid = nfs41_match_stateid, |
| 7463 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 7464 | .free_lock_state = nfs41_free_lock_state, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7465 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 7466 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 7467 | .state_renewal_ops = &nfs41_state_renewal_ops, |
| 7468 | }; |
| 7469 | #endif |
| 7470 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7471 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 7472 | [0] = &nfs_v4_0_minor_ops, |
| 7473 | #if defined(CONFIG_NFS_V4_1) |
| 7474 | [1] = &nfs_v4_1_minor_ops, |
| 7475 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7476 | #if defined(CONFIG_NFS_V4_2) |
| 7477 | [2] = &nfs_v4_2_minor_ops, |
| 7478 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7479 | }; |
| 7480 | |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 7481 | const struct inode_operations nfs4_dir_inode_operations = { |
| 7482 | .create = nfs_create, |
| 7483 | .lookup = nfs_lookup, |
| 7484 | .atomic_open = nfs_atomic_open, |
| 7485 | .link = nfs_link, |
| 7486 | .unlink = nfs_unlink, |
| 7487 | .symlink = nfs_symlink, |
| 7488 | .mkdir = nfs_mkdir, |
| 7489 | .rmdir = nfs_rmdir, |
| 7490 | .mknod = nfs_mknod, |
| 7491 | .rename = nfs_rename, |
| 7492 | .permission = nfs_permission, |
| 7493 | .getattr = nfs_getattr, |
| 7494 | .setattr = nfs_setattr, |
| 7495 | .getxattr = generic_getxattr, |
| 7496 | .setxattr = generic_setxattr, |
| 7497 | .listxattr = generic_listxattr, |
| 7498 | .removexattr = generic_removexattr, |
| 7499 | }; |
| 7500 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 7501 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7502 | .permission = nfs_permission, |
| 7503 | .getattr = nfs_getattr, |
| 7504 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7505 | .getxattr = generic_getxattr, |
| 7506 | .setxattr = generic_setxattr, |
| 7507 | .listxattr = generic_listxattr, |
| 7508 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7509 | }; |
| 7510 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 7511 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7512 | .version = 4, /* protocol version */ |
| 7513 | .dentry_ops = &nfs4_dentry_operations, |
| 7514 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7515 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 7516 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7517 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 7518 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 7519 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7520 | .getattr = nfs4_proc_getattr, |
| 7521 | .setattr = nfs4_proc_setattr, |
| 7522 | .lookup = nfs4_proc_lookup, |
| 7523 | .access = nfs4_proc_access, |
| 7524 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7525 | .create = nfs4_proc_create, |
| 7526 | .remove = nfs4_proc_remove, |
| 7527 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 7528 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7529 | .unlink_done = nfs4_proc_unlink_done, |
| 7530 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7531 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 7532 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7533 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7534 | .link = nfs4_proc_link, |
| 7535 | .symlink = nfs4_proc_symlink, |
| 7536 | .mkdir = nfs4_proc_mkdir, |
| 7537 | .rmdir = nfs4_proc_remove, |
| 7538 | .readdir = nfs4_proc_readdir, |
| 7539 | .mknod = nfs4_proc_mknod, |
| 7540 | .statfs = nfs4_proc_statfs, |
| 7541 | .fsinfo = nfs4_proc_fsinfo, |
| 7542 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 7543 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7544 | .decode_dirent = nfs4_decode_dirent, |
| 7545 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 7546 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 7547 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7548 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7549 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 7550 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 7551 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7552 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7553 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 7554 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7555 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7556 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 7557 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 7558 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 7559 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 7560 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 7561 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 7562 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 7563 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 7564 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 7565 | .create_server = nfs4_create_server, |
| 7566 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7567 | }; |
| 7568 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7569 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 7570 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 7571 | .list = nfs4_xattr_list_nfs4_acl, |
| 7572 | .get = nfs4_xattr_get_nfs4_acl, |
| 7573 | .set = nfs4_xattr_set_nfs4_acl, |
| 7574 | }; |
| 7575 | |
| 7576 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 7577 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7578 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 7579 | &nfs4_xattr_nfs4_label_handler, |
| 7580 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7581 | NULL |
| 7582 | }; |
| 7583 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7584 | /* |
| 7585 | * Local variables: |
| 7586 | * c-basic-offset: 8 |
| 7587 | * End: |
| 7588 | */ |