Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
| 46 | #include <linux/nfs.h> |
| 47 | #include <linux/nfs4.h> |
| 48 | #include <linux/nfs_fs.h> |
| 49 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 50 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 52 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 53 | #include <linux/module.h> |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 54 | #include <linux/nfs_idmap.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 55 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 56 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 57 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 59 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 61 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 62 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 63 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 64 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 65 | #include "netns.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 66 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 67 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 69 | #include "nfs4trace.h" |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 72 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 73 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 75 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 76 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 77 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 78 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 80 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 81 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 82 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label); |
| 83 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 84 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 85 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 86 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 87 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 88 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 89 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 90 | struct rpc_cred *); |
| 91 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *, |
| 92 | struct rpc_cred *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 93 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 94 | |
| 95 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 96 | static inline struct nfs4_label * |
| 97 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 98 | struct iattr *sattr, struct nfs4_label *label) |
| 99 | { |
| 100 | int err; |
| 101 | |
| 102 | if (label == NULL) |
| 103 | return NULL; |
| 104 | |
| 105 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 106 | return NULL; |
| 107 | |
| 108 | if (NFS_SERVER(dir)->nfs_client->cl_minorversion < 2) |
| 109 | return NULL; |
| 110 | |
| 111 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 112 | &dentry->d_name, (void **)&label->label, &label->len); |
| 113 | if (err == 0) |
| 114 | return label; |
| 115 | |
| 116 | return NULL; |
| 117 | } |
| 118 | static inline void |
| 119 | nfs4_label_release_security(struct nfs4_label *label) |
| 120 | { |
| 121 | if (label) |
| 122 | security_release_secctx(label->label, label->len); |
| 123 | } |
| 124 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 125 | { |
| 126 | if (label) |
| 127 | return server->attr_bitmask; |
| 128 | |
| 129 | return server->attr_bitmask_nl; |
| 130 | } |
| 131 | #else |
| 132 | static inline struct nfs4_label * |
| 133 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 134 | struct iattr *sattr, struct nfs4_label *l) |
| 135 | { return NULL; } |
| 136 | static inline void |
| 137 | nfs4_label_release_security(struct nfs4_label *label) |
| 138 | { return; } |
| 139 | static inline u32 * |
| 140 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 141 | { return server->attr_bitmask; } |
| 142 | #endif |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 145 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 147 | if (err >= -1000) |
| 148 | return err; |
| 149 | switch (err) { |
| 150 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 151 | case -NFS4ERR_LAYOUTTRYLATER: |
| 152 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 153 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 154 | case -NFS4ERR_WRONGSEC: |
| 155 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 156 | case -NFS4ERR_BADOWNER: |
| 157 | case -NFS4ERR_BADNAME: |
| 158 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 159 | case -NFS4ERR_SHARE_DENIED: |
| 160 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 161 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 162 | return -EPROTONOSUPPORT; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 163 | case -NFS4ERR_ACCESS: |
| 164 | return -EACCES; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 165 | case -NFS4ERR_FILE_OPEN: |
| 166 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 167 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 169 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 170 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 172 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | /* |
| 176 | * This is our standard bitmap for GETATTR requests. |
| 177 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 178 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | FATTR4_WORD0_TYPE |
| 180 | | FATTR4_WORD0_CHANGE |
| 181 | | FATTR4_WORD0_SIZE |
| 182 | | FATTR4_WORD0_FSID |
| 183 | | FATTR4_WORD0_FILEID, |
| 184 | FATTR4_WORD1_MODE |
| 185 | | FATTR4_WORD1_NUMLINKS |
| 186 | | FATTR4_WORD1_OWNER |
| 187 | | FATTR4_WORD1_OWNER_GROUP |
| 188 | | FATTR4_WORD1_RAWDEV |
| 189 | | FATTR4_WORD1_SPACE_USED |
| 190 | | FATTR4_WORD1_TIME_ACCESS |
| 191 | | FATTR4_WORD1_TIME_METADATA |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 192 | | FATTR4_WORD1_TIME_MODIFY, |
| 193 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 194 | FATTR4_WORD2_SECURITY_LABEL |
| 195 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | }; |
| 197 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 198 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 199 | FATTR4_WORD0_TYPE |
| 200 | | FATTR4_WORD0_CHANGE |
| 201 | | FATTR4_WORD0_SIZE |
| 202 | | FATTR4_WORD0_FSID |
| 203 | | FATTR4_WORD0_FILEID, |
| 204 | FATTR4_WORD1_MODE |
| 205 | | FATTR4_WORD1_NUMLINKS |
| 206 | | FATTR4_WORD1_OWNER |
| 207 | | FATTR4_WORD1_OWNER_GROUP |
| 208 | | FATTR4_WORD1_RAWDEV |
| 209 | | FATTR4_WORD1_SPACE_USED |
| 210 | | FATTR4_WORD1_TIME_ACCESS |
| 211 | | FATTR4_WORD1_TIME_METADATA |
| 212 | | FATTR4_WORD1_TIME_MODIFY, |
| 213 | FATTR4_WORD2_MDSTHRESHOLD |
| 214 | }; |
| 215 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 216 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 217 | FATTR4_WORD0_TYPE |
| 218 | | FATTR4_WORD0_CHANGE |
| 219 | | FATTR4_WORD0_FILEID, |
| 220 | }; |
| 221 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 222 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | FATTR4_WORD0_FILES_AVAIL |
| 224 | | FATTR4_WORD0_FILES_FREE |
| 225 | | FATTR4_WORD0_FILES_TOTAL, |
| 226 | FATTR4_WORD1_SPACE_AVAIL |
| 227 | | FATTR4_WORD1_SPACE_FREE |
| 228 | | FATTR4_WORD1_SPACE_TOTAL |
| 229 | }; |
| 230 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 231 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | FATTR4_WORD0_MAXLINK |
| 233 | | FATTR4_WORD0_MAXNAME, |
| 234 | 0 |
| 235 | }; |
| 236 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 237 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | | FATTR4_WORD0_MAXREAD |
| 239 | | FATTR4_WORD0_MAXWRITE |
| 240 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 241 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 242 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 243 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | }; |
| 245 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 246 | const u32 nfs4_fs_locations_bitmap[3] = { |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 247 | FATTR4_WORD0_TYPE |
| 248 | | FATTR4_WORD0_CHANGE |
| 249 | | FATTR4_WORD0_SIZE |
| 250 | | FATTR4_WORD0_FSID |
| 251 | | FATTR4_WORD0_FILEID |
| 252 | | FATTR4_WORD0_FS_LOCATIONS, |
| 253 | FATTR4_WORD1_MODE |
| 254 | | FATTR4_WORD1_NUMLINKS |
| 255 | | FATTR4_WORD1_OWNER |
| 256 | | FATTR4_WORD1_OWNER_GROUP |
| 257 | | FATTR4_WORD1_RAWDEV |
| 258 | | FATTR4_WORD1_SPACE_USED |
| 259 | | FATTR4_WORD1_TIME_ACCESS |
| 260 | | FATTR4_WORD1_TIME_METADATA |
| 261 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 262 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 263 | }; |
| 264 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 265 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | struct nfs4_readdir_arg *readdir) |
| 267 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 268 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 271 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | readdir->cookie = 0; |
| 277 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 278 | if (cookie == 2) |
| 279 | return; |
| 280 | |
| 281 | /* |
| 282 | * NFSv4 servers do not return entries for '.' and '..' |
| 283 | * Therefore, we fake these entries here. We let '.' |
| 284 | * have cookie 0 and '..' have cookie 1. Note that |
| 285 | * when talking to the server, we always send cookie 0 |
| 286 | * instead of 1 or 2. |
| 287 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 288 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | |
| 290 | if (cookie == 0) { |
| 291 | *p++ = xdr_one; /* next */ |
| 292 | *p++ = xdr_zero; /* cookie, first word */ |
| 293 | *p++ = xdr_one; /* cookie, second word */ |
| 294 | *p++ = xdr_one; /* entry len */ |
| 295 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 296 | p++; |
| 297 | *p++ = xdr_one; /* bitmap length */ |
| 298 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 299 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 300 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | *p++ = xdr_one; /* next */ |
| 304 | *p++ = xdr_zero; /* cookie, first word */ |
| 305 | *p++ = xdr_two; /* cookie, second word */ |
| 306 | *p++ = xdr_two; /* entry len */ |
| 307 | memcpy(p, "..\0\0", 4); /* entry */ |
| 308 | p++; |
| 309 | *p++ = xdr_one; /* bitmap length */ |
| 310 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 311 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 312 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
| 314 | readdir->pgbase = (char *)p - (char *)start; |
| 315 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 316 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 319 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 320 | { |
| 321 | int res = 0; |
| 322 | |
| 323 | might_sleep(); |
| 324 | |
| 325 | if (*timeout <= 0) |
| 326 | *timeout = NFS4_POLL_RETRY_MIN; |
| 327 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 328 | *timeout = NFS4_POLL_RETRY_MAX; |
Colin Cross | 416ad3c | 2013-05-06 23:50:06 +0000 | [diff] [blame] | 329 | freezable_schedule_timeout_killable_unsafe(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 330 | if (fatal_signal_pending(current)) |
| 331 | res = -ERESTARTSYS; |
| 332 | *timeout <<= 1; |
| 333 | return res; |
| 334 | } |
| 335 | |
| 336 | /* This is the error handling routine for processes that are allowed |
| 337 | * to sleep. |
| 338 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 339 | static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 340 | { |
| 341 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 342 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 343 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 344 | int ret = errorcode; |
| 345 | |
| 346 | exception->retry = 0; |
| 347 | switch(errorcode) { |
| 348 | case 0: |
| 349 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 350 | case -NFS4ERR_OPENMODE: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 351 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 352 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 353 | exception->retry = 1; |
| 354 | return 0; |
| 355 | } |
| 356 | if (state == NULL) |
| 357 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 358 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 359 | if (ret < 0) |
| 360 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 361 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 362 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 363 | case -NFS4ERR_ADMIN_REVOKED: |
| 364 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | b570a97 | 2013-04-12 15:04:51 -0400 | [diff] [blame] | 365 | if (inode != NULL && nfs4_have_delegation(inode, FMODE_READ)) { |
| 366 | nfs_remove_bad_delegation(inode); |
| 367 | exception->retry = 1; |
| 368 | break; |
| 369 | } |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 370 | if (state == NULL) |
| 371 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 372 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 373 | if (ret < 0) |
| 374 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 375 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 376 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 377 | if (state != NULL) { |
| 378 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 379 | if (ret < 0) |
| 380 | break; |
| 381 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 382 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 383 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 384 | nfs4_schedule_lease_recovery(clp); |
| 385 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 386 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 387 | case -NFS4ERR_BADSESSION: |
| 388 | case -NFS4ERR_BADSLOT: |
| 389 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 390 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 391 | case -NFS4ERR_DEADSESSION: |
| 392 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 393 | case -NFS4ERR_SEQ_MISORDERED: |
| 394 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 395 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 396 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 397 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 398 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 399 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 400 | if (exception->timeout > HZ) { |
| 401 | /* We have retried a decent amount, time to |
| 402 | * fail |
| 403 | */ |
| 404 | ret = -EBUSY; |
| 405 | break; |
| 406 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 407 | case -NFS4ERR_GRACE: |
| 408 | case -NFS4ERR_DELAY: |
| 409 | ret = nfs4_delay(server->client, &exception->timeout); |
| 410 | if (ret != 0) |
| 411 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 412 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 413 | case -NFS4ERR_OLD_STATEID: |
| 414 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 415 | break; |
| 416 | case -NFS4ERR_BADOWNER: |
| 417 | /* The following works around a Linux server bug! */ |
| 418 | case -NFS4ERR_BADNAME: |
| 419 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 420 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 421 | exception->retry = 1; |
| 422 | printk(KERN_WARNING "NFS: v4 server %s " |
| 423 | "does not accept raw " |
| 424 | "uid/gids. " |
| 425 | "Reenabling the idmapper.\n", |
| 426 | server->nfs_client->cl_hostname); |
| 427 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 428 | } |
| 429 | /* We failed to handle the error */ |
| 430 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 431 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 432 | ret = nfs4_wait_clnt_recover(clp); |
| 433 | if (ret == 0) |
| 434 | exception->retry = 1; |
| 435 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 436 | } |
| 437 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 438 | /* |
| 439 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 440 | * or 'false' otherwise. |
| 441 | */ |
| 442 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 443 | { |
| 444 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 445 | |
| 446 | if (flavor == RPC_AUTH_GSS_KRB5I || |
| 447 | flavor == RPC_AUTH_GSS_KRB5P) |
| 448 | return true; |
| 449 | |
| 450 | return false; |
| 451 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 452 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 453 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | spin_lock(&clp->cl_lock); |
| 456 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 457 | clp->cl_last_renewal = timestamp; |
| 458 | spin_unlock(&clp->cl_lock); |
| 459 | } |
| 460 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 461 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 462 | { |
| 463 | do_renew_lease(server->nfs_client, timestamp); |
| 464 | } |
| 465 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 466 | struct nfs4_call_sync_data { |
| 467 | const struct nfs_server *seq_server; |
| 468 | struct nfs4_sequence_args *seq_args; |
| 469 | struct nfs4_sequence_res *seq_res; |
| 470 | }; |
| 471 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame^] | 472 | static void nfs4_init_sequence(struct nfs4_sequence_args *args, |
| 473 | struct nfs4_sequence_res *res, int cache_reply) |
| 474 | { |
| 475 | args->sa_slot = NULL; |
| 476 | args->sa_cache_this = cache_reply; |
| 477 | args->sa_privileged = 0; |
| 478 | |
| 479 | res->sr_slot = NULL; |
| 480 | } |
| 481 | |
| 482 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 483 | { |
| 484 | args->sa_privileged = 1; |
| 485 | } |
| 486 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 487 | #if defined(CONFIG_NFS_V4_1) |
| 488 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 489 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 490 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 491 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 492 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 493 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 494 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 495 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 496 | /* just wake up the next guy waiting since |
| 497 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 498 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 499 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 500 | } |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 501 | tbl = res->sr_slot->table; |
| 502 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 503 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 504 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 505 | /* Be nice to the server: try to ensure that the last transmitted |
| 506 | * value for highest_user_slotid <= target_highest_slotid |
| 507 | */ |
| 508 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 509 | send_new_highest_used_slotid = true; |
| 510 | |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 511 | if (nfs41_wake_and_assign_slot(tbl, res->sr_slot)) { |
| 512 | send_new_highest_used_slotid = false; |
| 513 | goto out_unlock; |
| 514 | } |
Trond Myklebust | f4af6e2a | 2012-11-20 14:17:32 -0500 | [diff] [blame] | 515 | nfs4_free_slot(tbl, res->sr_slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 516 | |
| 517 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 518 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 519 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 520 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 521 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 522 | if (send_new_highest_used_slotid) |
| 523 | nfs41_server_notify_highest_slotid_update(session->clp); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 524 | } |
| 525 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 526 | 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] | 527 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 528 | struct nfs4_session *session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 529 | struct nfs4_slot *slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 530 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 531 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 532 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 533 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 534 | /* don't increment the sequence number if the task wasn't sent */ |
| 535 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 536 | goto out; |
| 537 | |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 538 | slot = res->sr_slot; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 539 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 540 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 541 | if (slot->interrupted) { |
| 542 | slot->interrupted = 0; |
| 543 | interrupted = true; |
| 544 | } |
| 545 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 546 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 547 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 548 | switch (res->sr_status) { |
| 549 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 550 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 551 | ++slot->seq_nr; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 552 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 553 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 554 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 555 | if (res->sr_status_flags != 0) |
| 556 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 557 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 558 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 559 | case 1: |
| 560 | /* |
| 561 | * sr_status remains 1 if an RPC level error occurred. |
| 562 | * The server may or may not have processed the sequence |
| 563 | * operation.. |
| 564 | * Mark the slot as having hosted an interrupted RPC call. |
| 565 | */ |
| 566 | slot->interrupted = 1; |
| 567 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 568 | case -NFS4ERR_DELAY: |
| 569 | /* The server detected a resend of the RPC call and |
| 570 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 571 | * of RFC5661. |
| 572 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 573 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 574 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 575 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 576 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 577 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 578 | case -NFS4ERR_BADSLOT: |
| 579 | /* |
| 580 | * The slot id we used was probably retired. Try again |
| 581 | * using a different slot id. |
| 582 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 583 | goto retry_nowait; |
| 584 | case -NFS4ERR_SEQ_MISORDERED: |
| 585 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 586 | * Was the last operation on this sequence interrupted? |
| 587 | * If so, retry after bumping the sequence number. |
| 588 | */ |
| 589 | if (interrupted) { |
| 590 | ++slot->seq_nr; |
| 591 | goto retry_nowait; |
| 592 | } |
| 593 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 594 | * Could this slot have been previously retired? |
| 595 | * If so, then the server may be expecting seq_nr = 1! |
| 596 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 597 | if (slot->seq_nr != 1) { |
| 598 | slot->seq_nr = 1; |
| 599 | goto retry_nowait; |
| 600 | } |
| 601 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 602 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 603 | ++slot->seq_nr; |
| 604 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 605 | default: |
| 606 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 607 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 608 | } |
| 609 | out: |
| 610 | /* The session may be reset by one of the error handlers. */ |
| 611 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 612 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 613 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 614 | retry_nowait: |
| 615 | if (rpc_restart_call_prepare(task)) { |
| 616 | task->tk_status = 0; |
| 617 | ret = 0; |
| 618 | } |
| 619 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 620 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 621 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 622 | goto out; |
| 623 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 624 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 625 | } |
| 626 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 627 | static int nfs4_sequence_done(struct rpc_task *task, |
| 628 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 629 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 630 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 631 | return 1; |
| 632 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 633 | } |
| 634 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 635 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 636 | struct nfs4_sequence_args *args, |
| 637 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 638 | struct rpc_task *task) |
| 639 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 640 | struct nfs4_slot *slot; |
| 641 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 642 | |
| 643 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 644 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 645 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 646 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 647 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 648 | tbl = &session->fc_slot_table; |
| 649 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 650 | task->tk_timeout = 0; |
| 651 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 652 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 653 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 654 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 655 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 656 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 657 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 658 | } |
| 659 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 660 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 661 | if (IS_ERR(slot)) { |
| 662 | /* If out of memory, try again in 1/4 second */ |
| 663 | if (slot == ERR_PTR(-ENOMEM)) |
| 664 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 665 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 666 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 667 | } |
| 668 | spin_unlock(&tbl->slot_tbl_lock); |
| 669 | |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 670 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 671 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 672 | dprintk("<-- %s slotid=%u seqid=%u\n", __func__, |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 673 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 674 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 675 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 676 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 677 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 678 | /* |
| 679 | * sr_status is only set in decode_sequence, and so will remain |
| 680 | * set to 1 if an rpc level failure occurs. |
| 681 | */ |
| 682 | res->sr_status = 1; |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 683 | trace_nfs4_setup_sequence(session, args); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 684 | out_success: |
| 685 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 686 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 687 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 688 | /* Privileged tasks are queued with top priority */ |
| 689 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 690 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 691 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 692 | else |
| 693 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 694 | spin_unlock(&tbl->slot_tbl_lock); |
| 695 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 696 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 697 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 698 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 699 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 700 | struct nfs4_sequence_args *args, |
| 701 | struct nfs4_sequence_res *res, |
| 702 | struct rpc_task *task) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 703 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 704 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 705 | int ret = 0; |
| 706 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 707 | if (session == NULL) { |
| 708 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 709 | goto out; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 710 | } |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 711 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 712 | dprintk("--> %s clp %p session %p sr_slot %u\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 713 | __func__, session->clp, session, res->sr_slot ? |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 714 | res->sr_slot->slot_nr : NFS4_NO_SLOT); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 715 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 716 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 717 | out: |
| 718 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 719 | return ret; |
| 720 | } |
| 721 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 722 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 723 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 724 | struct nfs4_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 725 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 726 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 727 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 728 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 729 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 730 | } |
| 731 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 732 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 733 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 734 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 735 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 736 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 737 | } |
| 738 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 739 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 740 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 741 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 742 | }; |
| 743 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 744 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 745 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 746 | struct rpc_message *msg, |
| 747 | struct nfs4_sequence_args *args, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 748 | struct nfs4_sequence_res *res) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 749 | { |
| 750 | int ret; |
| 751 | struct rpc_task *task; |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 752 | struct nfs4_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 753 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 754 | .seq_args = args, |
| 755 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 756 | }; |
| 757 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 758 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 759 | .rpc_message = msg, |
| 760 | .callback_ops = &nfs41_call_sync_ops, |
| 761 | .callback_data = &data |
| 762 | }; |
| 763 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 764 | task = rpc_run_task(&task_setup); |
| 765 | if (IS_ERR(task)) |
| 766 | ret = PTR_ERR(task); |
| 767 | else { |
| 768 | ret = task->tk_status; |
| 769 | rpc_put_task(task); |
| 770 | } |
| 771 | return ret; |
| 772 | } |
| 773 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 774 | #else |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 775 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 776 | struct nfs4_sequence_args *args, |
| 777 | struct nfs4_sequence_res *res, |
| 778 | struct rpc_task *task) |
| 779 | { |
| 780 | rpc_call_start(task); |
| 781 | return 0; |
| 782 | } |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 783 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 784 | static int nfs4_sequence_done(struct rpc_task *task, |
| 785 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 786 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 787 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 788 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 789 | #endif /* CONFIG_NFS_V4_1 */ |
| 790 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 791 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 792 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 793 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 794 | struct rpc_message *msg, |
| 795 | struct nfs4_sequence_args *args, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 796 | struct nfs4_sequence_res *res) |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 797 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 798 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 799 | } |
| 800 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 801 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 802 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 803 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 804 | struct rpc_message *msg, |
| 805 | struct nfs4_sequence_args *args, |
| 806 | struct nfs4_sequence_res *res, |
| 807 | int cache_reply) |
| 808 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame^] | 809 | nfs4_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 810 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 811 | args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 812 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 813 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 814 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 816 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 818 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 819 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 820 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 821 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 822 | dir->i_version = cinfo->after; |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 823 | nfs_fscache_invalidate(dir); |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 824 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | } |
| 826 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 827 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 828 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 829 | struct nfs_openargs o_arg; |
| 830 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 831 | struct nfs_open_confirmargs c_arg; |
| 832 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 833 | struct nfs4_string owner_name; |
| 834 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 835 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 836 | struct nfs4_label *f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 837 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 838 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 839 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 840 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 841 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 842 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 843 | unsigned int rpc_done : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 844 | unsigned int is_recover : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 845 | int rpc_status; |
| 846 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 847 | }; |
| 848 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 849 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 850 | int err, struct nfs4_exception *exception) |
| 851 | { |
| 852 | if (err != -EINVAL) |
| 853 | return false; |
| 854 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 855 | return false; |
| 856 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 857 | exception->retry = 1; |
| 858 | return true; |
| 859 | } |
| 860 | |
| 861 | static enum open_claim_type4 |
| 862 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 863 | enum open_claim_type4 claim) |
| 864 | { |
| 865 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 866 | return claim; |
| 867 | switch (claim) { |
| 868 | default: |
| 869 | return claim; |
| 870 | case NFS4_OPEN_CLAIM_FH: |
| 871 | return NFS4_OPEN_CLAIM_NULL; |
| 872 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 873 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 874 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 875 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 876 | } |
| 877 | } |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 878 | |
| 879 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 880 | { |
| 881 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 882 | p->o_res.f_label = p->f_label; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 883 | p->o_res.seqid = p->o_arg.seqid; |
| 884 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 885 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 886 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 887 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 888 | 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] | 889 | } |
| 890 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 891 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 892 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 893 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 894 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 895 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 896 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 897 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 898 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 899 | struct inode *dir = parent->d_inode; |
| 900 | struct nfs_server *server = NFS_SERVER(dir); |
| 901 | struct nfs4_opendata *p; |
| 902 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 903 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 904 | if (p == NULL) |
| 905 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 906 | |
| 907 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 908 | if (IS_ERR(p->f_label)) |
| 909 | goto err_free_p; |
| 910 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 911 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 912 | if (p->o_arg.seqid == NULL) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 913 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 914 | nfs_sb_active(dentry->d_sb); |
| 915 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 916 | p->dir = parent; |
| 917 | p->owner = sp; |
| 918 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 919 | p->o_arg.open_flags = flags; |
| 920 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 921 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 922 | * will return permission denied for all bits until close */ |
| 923 | if (!(flags & O_EXCL)) { |
| 924 | /* ask server to check for all possible rights as results |
| 925 | * are cached */ |
| 926 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 927 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 928 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 929 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 930 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 931 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 932 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 933 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 934 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 935 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 936 | p->o_arg.label = label; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 937 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 938 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 939 | case NFS4_OPEN_CLAIM_NULL: |
| 940 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 941 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 942 | p->o_arg.fh = NFS_FH(dir); |
| 943 | break; |
| 944 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 945 | case NFS4_OPEN_CLAIM_FH: |
| 946 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 947 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 948 | p->o_arg.fh = NFS_FH(dentry->d_inode); |
| 949 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 950 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 951 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 952 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 953 | p->o_arg.u.attrs = &p->attrs; |
| 954 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 955 | |
| 956 | verf[0] = jiffies; |
| 957 | verf[1] = current->pid; |
| 958 | memcpy(p->o_arg.u.verifier.data, verf, |
| 959 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 960 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 961 | p->c_arg.fh = &p->o_res.fh; |
| 962 | p->c_arg.stateid = &p->o_res.stateid; |
| 963 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 964 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 965 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 966 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 967 | |
| 968 | err_free_label: |
| 969 | nfs4_label_free(p->f_label); |
| 970 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 971 | kfree(p); |
| 972 | err: |
| 973 | dput(parent); |
| 974 | return NULL; |
| 975 | } |
| 976 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 977 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 978 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 979 | struct nfs4_opendata *p = container_of(kref, |
| 980 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 981 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 982 | |
| 983 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 984 | if (p->state != NULL) |
| 985 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 986 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 987 | |
| 988 | nfs4_label_free(p->f_label); |
| 989 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 990 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 991 | dput(p->dentry); |
| 992 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 993 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 994 | kfree(p); |
| 995 | } |
| 996 | |
| 997 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 998 | { |
| 999 | if (p != NULL) |
| 1000 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1001 | } |
| 1002 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1003 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1004 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1005 | int ret; |
| 1006 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1007 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1008 | return ret; |
| 1009 | } |
| 1010 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1011 | 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] | 1012 | { |
| 1013 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1014 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1015 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1016 | goto out; |
| 1017 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1018 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1019 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1020 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1021 | break; |
| 1022 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1023 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1024 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1025 | break; |
| 1026 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1027 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1028 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1029 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1030 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1031 | return ret; |
| 1032 | } |
| 1033 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1034 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1035 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1036 | if (delegation == NULL) |
| 1037 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1038 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1039 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1040 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1041 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1042 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1043 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1044 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1045 | return 1; |
| 1046 | } |
| 1047 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1048 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1049 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1050 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1051 | case FMODE_WRITE: |
| 1052 | state->n_wronly++; |
| 1053 | break; |
| 1054 | case FMODE_READ: |
| 1055 | state->n_rdonly++; |
| 1056 | break; |
| 1057 | case FMODE_READ|FMODE_WRITE: |
| 1058 | state->n_rdwr++; |
| 1059 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1060 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1061 | } |
| 1062 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1063 | 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] | 1064 | { |
| 1065 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1066 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1067 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 92b40e9 | 2013-04-20 01:25:45 -0400 | [diff] [blame] | 1068 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1069 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1070 | case FMODE_READ: |
| 1071 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1072 | break; |
| 1073 | case FMODE_WRITE: |
| 1074 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1075 | break; |
| 1076 | case FMODE_READ|FMODE_WRITE: |
| 1077 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1078 | } |
| 1079 | } |
| 1080 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1081 | 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] | 1082 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1083 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1084 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1085 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1086 | } |
| 1087 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1088 | 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] | 1089 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1090 | /* |
| 1091 | * Protect the call to nfs4_state_set_mode_locked and |
| 1092 | * serialise the stateid update |
| 1093 | */ |
| 1094 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1095 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1096 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1097 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1098 | } |
| 1099 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1100 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1101 | write_sequnlock(&state->seqlock); |
| 1102 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1103 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1104 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | } |
| 1106 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1107 | 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] | 1108 | { |
| 1109 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1110 | struct nfs_delegation *deleg_cur; |
| 1111 | int ret = 0; |
| 1112 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1113 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1114 | |
| 1115 | rcu_read_lock(); |
| 1116 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1117 | if (deleg_cur == NULL) |
| 1118 | goto no_delegation; |
| 1119 | |
| 1120 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1121 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1122 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1123 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1124 | goto no_delegation_unlock; |
| 1125 | |
| 1126 | if (delegation == NULL) |
| 1127 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1128 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1129 | goto no_delegation_unlock; |
| 1130 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1131 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1132 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1133 | ret = 1; |
| 1134 | no_delegation_unlock: |
| 1135 | spin_unlock(&deleg_cur->lock); |
| 1136 | no_delegation: |
| 1137 | rcu_read_unlock(); |
| 1138 | |
| 1139 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1140 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1141 | ret = 1; |
| 1142 | } |
| 1143 | |
| 1144 | return ret; |
| 1145 | } |
| 1146 | |
| 1147 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1148 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1149 | { |
| 1150 | struct nfs_delegation *delegation; |
| 1151 | |
| 1152 | rcu_read_lock(); |
| 1153 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1154 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1155 | rcu_read_unlock(); |
| 1156 | return; |
| 1157 | } |
| 1158 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1159 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1160 | } |
| 1161 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1162 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1163 | { |
| 1164 | struct nfs4_state *state = opendata->state; |
| 1165 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1166 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1167 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1168 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1169 | nfs4_stateid stateid; |
| 1170 | int ret = -EAGAIN; |
| 1171 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1172 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1173 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1174 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1175 | if (can_open_cached(state, fmode, open_mode)) { |
| 1176 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1177 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1178 | goto out_return_state; |
| 1179 | } |
| 1180 | spin_unlock(&state->owner->so_lock); |
| 1181 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1182 | rcu_read_lock(); |
| 1183 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1184 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1185 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1186 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1187 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1188 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1189 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1190 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1191 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1192 | if (!opendata->is_recover) { |
| 1193 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1194 | if (ret != 0) |
| 1195 | goto out; |
| 1196 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1197 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1198 | |
| 1199 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1200 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1201 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1202 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1203 | out: |
| 1204 | return ERR_PTR(ret); |
| 1205 | out_return_state: |
| 1206 | atomic_inc(&state->count); |
| 1207 | return state; |
| 1208 | } |
| 1209 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1210 | static void |
| 1211 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1212 | { |
| 1213 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1214 | struct nfs_delegation *delegation; |
| 1215 | int delegation_flags = 0; |
| 1216 | |
| 1217 | rcu_read_lock(); |
| 1218 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1219 | if (delegation) |
| 1220 | delegation_flags = delegation->flags; |
| 1221 | rcu_read_unlock(); |
| 1222 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1223 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1224 | "returning a delegation for " |
| 1225 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1226 | clp->cl_hostname); |
| 1227 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1228 | nfs_inode_set_delegation(state->inode, |
| 1229 | data->owner->so_cred, |
| 1230 | &data->o_res); |
| 1231 | else |
| 1232 | nfs_inode_reclaim_delegation(state->inode, |
| 1233 | data->owner->so_cred, |
| 1234 | &data->o_res); |
| 1235 | } |
| 1236 | |
| 1237 | /* |
| 1238 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1239 | * and update the nfs4_state. |
| 1240 | */ |
| 1241 | static struct nfs4_state * |
| 1242 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1243 | { |
| 1244 | struct inode *inode = data->state->inode; |
| 1245 | struct nfs4_state *state = data->state; |
| 1246 | int ret; |
| 1247 | |
| 1248 | if (!data->rpc_done) { |
| 1249 | ret = data->rpc_status; |
| 1250 | goto err; |
| 1251 | } |
| 1252 | |
| 1253 | ret = -ESTALE; |
| 1254 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || |
| 1255 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || |
| 1256 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) |
| 1257 | goto err; |
| 1258 | |
| 1259 | ret = -ENOMEM; |
| 1260 | state = nfs4_get_open_state(inode, data->owner); |
| 1261 | if (state == NULL) |
| 1262 | goto err; |
| 1263 | |
| 1264 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1265 | if (ret) |
| 1266 | goto err; |
| 1267 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1268 | nfs_setsecurity(inode, &data->f_attr, data->f_label); |
| 1269 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1270 | if (data->o_res.delegation_type != 0) |
| 1271 | nfs4_opendata_check_deleg(data, state); |
| 1272 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1273 | data->o_arg.fmode); |
| 1274 | |
| 1275 | return state; |
| 1276 | err: |
| 1277 | return ERR_PTR(ret); |
| 1278 | |
| 1279 | } |
| 1280 | |
| 1281 | static struct nfs4_state * |
| 1282 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1283 | { |
| 1284 | struct inode *inode; |
| 1285 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1286 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1287 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1288 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1289 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1290 | goto out; |
| 1291 | } |
| 1292 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1293 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1294 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1295 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1296 | 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] | 1297 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1298 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1299 | goto err; |
| 1300 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1301 | state = nfs4_get_open_state(inode, data->owner); |
| 1302 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1303 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1304 | if (data->o_res.delegation_type != 0) |
| 1305 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1306 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1307 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1308 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1309 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1310 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1311 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1312 | err_put_inode: |
| 1313 | iput(inode); |
| 1314 | err: |
| 1315 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1316 | } |
| 1317 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1318 | static struct nfs4_state * |
| 1319 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1320 | { |
| 1321 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1322 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1323 | return _nfs4_opendata_to_nfs4_state(data); |
| 1324 | } |
| 1325 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1326 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1327 | { |
| 1328 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1329 | struct nfs_open_context *ctx; |
| 1330 | |
| 1331 | spin_lock(&state->inode->i_lock); |
| 1332 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1333 | if (ctx->state != state) |
| 1334 | continue; |
| 1335 | get_nfs_open_context(ctx); |
| 1336 | spin_unlock(&state->inode->i_lock); |
| 1337 | return ctx; |
| 1338 | } |
| 1339 | spin_unlock(&state->inode->i_lock); |
| 1340 | return ERR_PTR(-ENOENT); |
| 1341 | } |
| 1342 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1343 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1344 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1345 | { |
| 1346 | struct nfs4_opendata *opendata; |
| 1347 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1348 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1349 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1350 | if (opendata == NULL) |
| 1351 | return ERR_PTR(-ENOMEM); |
| 1352 | opendata->state = state; |
| 1353 | atomic_inc(&state->count); |
| 1354 | return opendata; |
| 1355 | } |
| 1356 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1357 | 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] | 1358 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1359 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1360 | int ret; |
| 1361 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1362 | opendata->o_arg.open_flags = 0; |
| 1363 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1364 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1365 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1366 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1367 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1368 | if (ret != 0) |
| 1369 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1370 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1371 | if (IS_ERR(newstate)) |
| 1372 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1373 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1374 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1375 | return 0; |
| 1376 | } |
| 1377 | |
| 1378 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1379 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1380 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1381 | int ret; |
| 1382 | |
| 1383 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1384 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1385 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1386 | smp_rmb(); |
| 1387 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1388 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1389 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1390 | if (ret != 0) |
| 1391 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1392 | if (newstate != state) |
| 1393 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1394 | } |
| 1395 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1396 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1397 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1398 | if (ret != 0) |
| 1399 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1400 | if (newstate != state) |
| 1401 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1402 | } |
| 1403 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1404 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1405 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1406 | if (ret != 0) |
| 1407 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1408 | if (newstate != state) |
| 1409 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1410 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1411 | /* |
| 1412 | * We may have performed cached opens for all three recoveries. |
| 1413 | * Check if we need to update the current stateid. |
| 1414 | */ |
| 1415 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1416 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1417 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1418 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1419 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1420 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1421 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1422 | return 0; |
| 1423 | } |
| 1424 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | /* |
| 1426 | * OPEN_RECLAIM: |
| 1427 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1429 | 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] | 1430 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1431 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1432 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1433 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | int status; |
| 1435 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1436 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1437 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1438 | if (IS_ERR(opendata)) |
| 1439 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1440 | rcu_read_lock(); |
| 1441 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1442 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1443 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1444 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1445 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1446 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1447 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | return status; |
| 1449 | } |
| 1450 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1451 | 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] | 1452 | { |
| 1453 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1454 | struct nfs4_exception exception = { }; |
| 1455 | int err; |
| 1456 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1457 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1458 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1459 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1460 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1461 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1462 | break; |
| 1463 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | } while (exception.retry); |
| 1465 | return err; |
| 1466 | } |
| 1467 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1468 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1469 | { |
| 1470 | struct nfs_open_context *ctx; |
| 1471 | int ret; |
| 1472 | |
| 1473 | ctx = nfs4_state_find_open_context(state); |
| 1474 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1475 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1476 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1477 | put_nfs_open_context(ctx); |
| 1478 | return ret; |
| 1479 | } |
| 1480 | |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1481 | 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] | 1482 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1483 | switch (err) { |
| 1484 | default: |
| 1485 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1486 | "%d.\n", __func__, err); |
| 1487 | case 0: |
| 1488 | case -ENOENT: |
| 1489 | case -ESTALE: |
| 1490 | break; |
| 1491 | case -NFS4ERR_BADSESSION: |
| 1492 | case -NFS4ERR_BADSLOT: |
| 1493 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1494 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1495 | case -NFS4ERR_DEADSESSION: |
| 1496 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1497 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1498 | return -EAGAIN; |
| 1499 | case -NFS4ERR_STALE_CLIENTID: |
| 1500 | case -NFS4ERR_STALE_STATEID: |
| 1501 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1502 | case -NFS4ERR_EXPIRED: |
| 1503 | /* Don't recall a delegation if it was lost */ |
| 1504 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1505 | return -EAGAIN; |
| 1506 | case -NFS4ERR_DELEG_REVOKED: |
| 1507 | case -NFS4ERR_ADMIN_REVOKED: |
| 1508 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1509 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1510 | nfs_inode_find_state_and_recover(state->inode, |
| 1511 | stateid); |
| 1512 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1513 | return 0; |
| 1514 | case -NFS4ERR_DELAY: |
| 1515 | case -NFS4ERR_GRACE: |
| 1516 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1517 | ssleep(1); |
| 1518 | return -EAGAIN; |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1519 | case -ENOMEM: |
| 1520 | case -NFS4ERR_DENIED: |
| 1521 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1522 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1523 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | return err; |
| 1525 | } |
| 1526 | |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1527 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
| 1528 | { |
| 1529 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1530 | struct nfs4_opendata *opendata; |
| 1531 | int err; |
| 1532 | |
| 1533 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1534 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1535 | if (IS_ERR(opendata)) |
| 1536 | return PTR_ERR(opendata); |
| 1537 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
| 1538 | err = nfs4_open_recover(opendata, state); |
| 1539 | nfs4_opendata_put(opendata); |
| 1540 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1541 | } |
| 1542 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1543 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1544 | { |
| 1545 | struct nfs4_opendata *data = calldata; |
| 1546 | |
| 1547 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1548 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1549 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1550 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1551 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1552 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1553 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | static void nfs4_open_confirm_release(void *calldata) |
| 1557 | { |
| 1558 | struct nfs4_opendata *data = calldata; |
| 1559 | struct nfs4_state *state = NULL; |
| 1560 | |
| 1561 | /* If this request hasn't been cancelled, do nothing */ |
| 1562 | if (data->cancelled == 0) |
| 1563 | goto out_free; |
| 1564 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1565 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1566 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1567 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1568 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1569 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1570 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1571 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1575 | .rpc_call_done = nfs4_open_confirm_done, |
| 1576 | .rpc_release = nfs4_open_confirm_release, |
| 1577 | }; |
| 1578 | |
| 1579 | /* |
| 1580 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1581 | */ |
| 1582 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1583 | { |
| 1584 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1585 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1586 | struct rpc_message msg = { |
| 1587 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1588 | .rpc_argp = &data->c_arg, |
| 1589 | .rpc_resp = &data->c_res, |
| 1590 | .rpc_cred = data->owner->so_cred, |
| 1591 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1592 | struct rpc_task_setup task_setup_data = { |
| 1593 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1594 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1595 | .callback_ops = &nfs4_open_confirm_ops, |
| 1596 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1597 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1598 | .flags = RPC_TASK_ASYNC, |
| 1599 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | int status; |
| 1601 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1602 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1603 | data->rpc_done = 0; |
| 1604 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1605 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1606 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1607 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1608 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1609 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1610 | if (status != 0) { |
| 1611 | data->cancelled = 1; |
| 1612 | smp_wmb(); |
| 1613 | } else |
| 1614 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1615 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | return status; |
| 1617 | } |
| 1618 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1619 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1621 | struct nfs4_opendata *data = calldata; |
| 1622 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1623 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1624 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1625 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1626 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1627 | /* |
| 1628 | * Check if we still need to send an OPEN call, or if we can use |
| 1629 | * a delegation instead. |
| 1630 | */ |
| 1631 | if (data->state != NULL) { |
| 1632 | struct nfs_delegation *delegation; |
| 1633 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1634 | 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] | 1635 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1636 | rcu_read_lock(); |
| 1637 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1638 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
Trond Myklebust | cd4c9be | 2013-04-23 14:46:25 -0400 | [diff] [blame] | 1639 | data->o_arg.claim != NFS4_OPEN_CLAIM_DELEG_CUR_FH && |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1640 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1641 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1642 | rcu_read_unlock(); |
| 1643 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1644 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1645 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1646 | switch (data->o_arg.claim) { |
| 1647 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1648 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1649 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1650 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1651 | case NFS4_OPEN_CLAIM_FH: |
| 1652 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1653 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1654 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1655 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1656 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1657 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1658 | &data->o_res.seq_res, |
| 1659 | task) != 0) |
| 1660 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1661 | |
| 1662 | /* Set the create mode (note dependency on the session type) */ |
| 1663 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 1664 | if (data->o_arg.open_flags & O_EXCL) { |
| 1665 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 1666 | if (nfs4_has_persistent_session(clp)) |
| 1667 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 1668 | else if (clp->cl_mvops->minor_version > 0) |
| 1669 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 1670 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1671 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1672 | unlock_no_action: |
| 1673 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1674 | out_no_action: |
| 1675 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1676 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1677 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1678 | } |
| 1679 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1680 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1681 | { |
| 1682 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1684 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1685 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1686 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1687 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1688 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1689 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1690 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1691 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1692 | case S_IFREG: |
| 1693 | break; |
| 1694 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1695 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1696 | break; |
| 1697 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1698 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1699 | break; |
| 1700 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1701 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1702 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1703 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1704 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1705 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1706 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1707 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1708 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1709 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1710 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1711 | static void nfs4_open_release(void *calldata) |
| 1712 | { |
| 1713 | struct nfs4_opendata *data = calldata; |
| 1714 | struct nfs4_state *state = NULL; |
| 1715 | |
| 1716 | /* If this request hasn't been cancelled, do nothing */ |
| 1717 | if (data->cancelled == 0) |
| 1718 | goto out_free; |
| 1719 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1720 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1721 | goto out_free; |
| 1722 | /* In case we need an open_confirm, no cleanup! */ |
| 1723 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1724 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1725 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1726 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1727 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1728 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1729 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1733 | .rpc_call_prepare = nfs4_open_prepare, |
| 1734 | .rpc_call_done = nfs4_open_done, |
| 1735 | .rpc_release = nfs4_open_release, |
| 1736 | }; |
| 1737 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1738 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1739 | { |
| 1740 | struct inode *dir = data->dir->d_inode; |
| 1741 | struct nfs_server *server = NFS_SERVER(dir); |
| 1742 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1743 | struct nfs_openres *o_res = &data->o_res; |
| 1744 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1745 | struct rpc_message msg = { |
| 1746 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1747 | .rpc_argp = o_arg, |
| 1748 | .rpc_resp = o_res, |
| 1749 | .rpc_cred = data->owner->so_cred, |
| 1750 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1751 | struct rpc_task_setup task_setup_data = { |
| 1752 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1753 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1754 | .callback_ops = &nfs4_open_ops, |
| 1755 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1756 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1757 | .flags = RPC_TASK_ASYNC, |
| 1758 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1759 | int status; |
| 1760 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame^] | 1761 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1762 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1763 | data->rpc_done = 0; |
| 1764 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1765 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1766 | data->is_recover = 0; |
| 1767 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1768 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1769 | data->is_recover = 1; |
| 1770 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1771 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1772 | if (IS_ERR(task)) |
| 1773 | return PTR_ERR(task); |
| 1774 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1775 | if (status != 0) { |
| 1776 | data->cancelled = 1; |
| 1777 | smp_wmb(); |
| 1778 | } else |
| 1779 | status = data->rpc_status; |
| 1780 | rpc_put_task(task); |
| 1781 | |
| 1782 | return status; |
| 1783 | } |
| 1784 | |
| 1785 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1786 | { |
| 1787 | struct inode *dir = data->dir->d_inode; |
| 1788 | struct nfs_openres *o_res = &data->o_res; |
| 1789 | int status; |
| 1790 | |
| 1791 | status = nfs4_run_open_task(data, 1); |
| 1792 | if (status != 0 || !data->rpc_done) |
| 1793 | return status; |
| 1794 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1795 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1796 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1797 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1798 | status = _nfs4_proc_open_confirm(data); |
| 1799 | if (status != 0) |
| 1800 | return status; |
| 1801 | } |
| 1802 | |
| 1803 | return status; |
| 1804 | } |
| 1805 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1806 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1807 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1808 | struct nfs4_state *state, fmode_t fmode, |
| 1809 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1810 | { |
| 1811 | struct nfs_access_entry cache; |
| 1812 | u32 mask; |
| 1813 | |
| 1814 | /* access call failed or for some reason the server doesn't |
| 1815 | * support any access modes -- defer access call until later */ |
| 1816 | if (opendata->o_res.access_supported == 0) |
| 1817 | return 0; |
| 1818 | |
| 1819 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1820 | /* 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] | 1821 | * write mode bits, but POSIX allows the creating process to write. |
| 1822 | * use openflags to check for exec, because fmode won't |
| 1823 | * always have FMODE_EXEC set when file open for exec. */ |
| 1824 | if (openflags & __FMODE_EXEC) { |
| 1825 | /* ONLY check for exec rights */ |
| 1826 | mask = MAY_EXEC; |
| 1827 | } else if (fmode & FMODE_READ) |
| 1828 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1829 | |
| 1830 | cache.cred = cred; |
| 1831 | cache.jiffies = jiffies; |
| 1832 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1833 | nfs_access_add_cache(state->inode, &cache); |
| 1834 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1835 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1836 | return 0; |
| 1837 | |
| 1838 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1839 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1840 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1841 | } |
| 1842 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1843 | /* |
| 1844 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1845 | */ |
| 1846 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1847 | { |
| 1848 | struct inode *dir = data->dir->d_inode; |
| 1849 | struct nfs_server *server = NFS_SERVER(dir); |
| 1850 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1851 | struct nfs_openres *o_res = &data->o_res; |
| 1852 | int status; |
| 1853 | |
| 1854 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1855 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1856 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1857 | if (status != 0) { |
| 1858 | if (status == -NFS4ERR_BADNAME && |
| 1859 | !(o_arg->open_flags & O_CREAT)) |
| 1860 | return -ENOENT; |
| 1861 | return status; |
| 1862 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1863 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1864 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1865 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1866 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1867 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1868 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1869 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1871 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1873 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | } |
| 1875 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1876 | _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] | 1877 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | } |
| 1879 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1880 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1881 | { |
| 1882 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1883 | } |
| 1884 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | /* |
| 1886 | * OPEN_EXPIRED: |
| 1887 | * reclaim state on the server after a network partition. |
| 1888 | * Assumes caller holds the appropriate lock |
| 1889 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1890 | 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] | 1891 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1892 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1893 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1895 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1896 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1897 | if (IS_ERR(opendata)) |
| 1898 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1899 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1900 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1901 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1902 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1903 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | } |
| 1905 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1906 | 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] | 1907 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1908 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1909 | struct nfs4_exception exception = { }; |
| 1910 | int err; |
| 1911 | |
| 1912 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1913 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1914 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1915 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1916 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1917 | switch (err) { |
| 1918 | default: |
| 1919 | goto out; |
| 1920 | case -NFS4ERR_GRACE: |
| 1921 | case -NFS4ERR_DELAY: |
| 1922 | nfs4_handle_exception(server, err, &exception); |
| 1923 | err = 0; |
| 1924 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1925 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1926 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1927 | return err; |
| 1928 | } |
| 1929 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1931 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1933 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1935 | ctx = nfs4_state_find_open_context(state); |
| 1936 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1937 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1938 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1939 | put_nfs_open_context(ctx); |
| 1940 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | } |
| 1942 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1943 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1944 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1945 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1946 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1947 | nfs4_stateid *stateid = &state->stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1948 | struct nfs_delegation *delegation; |
| 1949 | struct rpc_cred *cred = NULL; |
| 1950 | int status = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1951 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1952 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1953 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1954 | return; |
| 1955 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1956 | /* Get the delegation credential for use by test/free_stateid */ |
| 1957 | rcu_read_lock(); |
| 1958 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1959 | if (delegation != NULL && |
| 1960 | nfs4_stateid_match(&delegation->stateid, stateid)) { |
| 1961 | cred = get_rpccred(delegation->cred); |
| 1962 | rcu_read_unlock(); |
| 1963 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 1964 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1965 | } else |
| 1966 | rcu_read_unlock(); |
| 1967 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1968 | if (status != NFS_OK) { |
| 1969 | /* Free the stateid unless the server explicitly |
| 1970 | * informs us the stateid is unrecognized. */ |
| 1971 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1972 | nfs41_free_stateid(server, stateid, cred); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1973 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1974 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1975 | write_seqlock(&state->seqlock); |
| 1976 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1977 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1978 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1979 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1980 | |
| 1981 | if (cred != NULL) |
| 1982 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | /** |
| 1986 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1987 | * |
| 1988 | * @state: NFSv4 state for an inode |
| 1989 | * |
| 1990 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1991 | * Otherwise a negative NFS4ERR value is returned. |
| 1992 | */ |
| 1993 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1994 | { |
| 1995 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1996 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1997 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1998 | int status; |
| 1999 | |
| 2000 | /* If a state reset has been done, test_stateid is unneeded */ |
| 2001 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 2002 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 2003 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 2004 | return -NFS4ERR_BAD_STATEID; |
| 2005 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2006 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2007 | trace_nfs4_test_open_stateid(state, NULL, status); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2008 | if (status != NFS_OK) { |
| 2009 | /* Free the stateid unless the server explicitly |
| 2010 | * informs us the stateid is unrecognized. */ |
| 2011 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2012 | nfs41_free_stateid(server, stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2013 | |
| 2014 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2015 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2016 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2017 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2018 | } |
| 2019 | return status; |
| 2020 | } |
| 2021 | |
| 2022 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2023 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2024 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2025 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2026 | nfs41_clear_delegation_stateid(state); |
| 2027 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2028 | if (status != NFS_OK) |
| 2029 | status = nfs4_open_expired(sp, state); |
| 2030 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2031 | } |
| 2032 | #endif |
| 2033 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2035 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2036 | * fields corresponding to attributes that were used to store the verifier. |
| 2037 | * Make sure we clobber those fields in the later setattr call |
| 2038 | */ |
| 2039 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 2040 | { |
| 2041 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 2042 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2043 | sattr->ia_valid |= ATTR_ATIME; |
| 2044 | |
| 2045 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 2046 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2047 | sattr->ia_valid |= ATTR_MTIME; |
| 2048 | } |
| 2049 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2050 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2051 | fmode_t fmode, |
| 2052 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2053 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2054 | { |
| 2055 | struct nfs4_state_owner *sp = opendata->owner; |
| 2056 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2057 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2058 | struct nfs4_state *state; |
| 2059 | unsigned int seq; |
| 2060 | int ret; |
| 2061 | |
| 2062 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2063 | |
| 2064 | ret = _nfs4_proc_open(opendata); |
| 2065 | if (ret != 0) |
| 2066 | goto out; |
| 2067 | |
| 2068 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2069 | ret = PTR_ERR(state); |
| 2070 | if (IS_ERR(state)) |
| 2071 | goto out; |
| 2072 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2073 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 2074 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2075 | dentry = opendata->dentry; |
| 2076 | if (dentry->d_inode == NULL) { |
| 2077 | /* FIXME: Is this d_drop() ever needed? */ |
| 2078 | d_drop(dentry); |
| 2079 | dentry = d_add_unique(dentry, igrab(state->inode)); |
| 2080 | if (dentry == NULL) { |
| 2081 | dentry = opendata->dentry; |
| 2082 | } else if (dentry != ctx->dentry) { |
| 2083 | dput(ctx->dentry); |
| 2084 | ctx->dentry = dget(dentry); |
| 2085 | } |
| 2086 | nfs_set_verifier(dentry, |
| 2087 | nfs_save_change_attribute(opendata->dir->d_inode)); |
| 2088 | } |
| 2089 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2090 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2091 | if (ret != 0) |
| 2092 | goto out; |
| 2093 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2094 | ctx->state = state; |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2095 | if (dentry->d_inode == state->inode) { |
| 2096 | nfs_inode_attach_open_context(ctx); |
| 2097 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2098 | nfs4_schedule_stateid_recovery(server, state); |
| 2099 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2100 | out: |
| 2101 | return ret; |
| 2102 | } |
| 2103 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2104 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2105 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2106 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2107 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2108 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2109 | int flags, |
| 2110 | struct iattr *sattr, |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2111 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | { |
| 2113 | struct nfs4_state_owner *sp; |
| 2114 | struct nfs4_state *state = NULL; |
| 2115 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2116 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2117 | struct dentry *dentry = ctx->dentry; |
| 2118 | struct rpc_cred *cred = ctx->cred; |
| 2119 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2120 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2121 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2122 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2123 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | |
| 2125 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2126 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2127 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2128 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2130 | goto out_err; |
| 2131 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2132 | status = nfs4_recover_expired_lease(server); |
| 2133 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2134 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2135 | if (dentry->d_inode != NULL) |
| 2136 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2137 | status = -ENOMEM; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2138 | if (dentry->d_inode) |
| 2139 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2140 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2141 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2142 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2143 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2145 | if (label) { |
| 2146 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2147 | if (IS_ERR(olabel)) { |
| 2148 | status = PTR_ERR(olabel); |
| 2149 | goto err_opendata_put; |
| 2150 | } |
| 2151 | } |
| 2152 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2153 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2154 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2155 | if (!opendata->f_attr.mdsthreshold) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2156 | goto err_free_label; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2157 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2158 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2159 | if (dentry->d_inode != NULL) |
| 2160 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2161 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2162 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2163 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2164 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2165 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2166 | |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2167 | if ((opendata->o_arg.open_flags & O_EXCL) && |
| 2168 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2169 | nfs4_exclusive_attrset(opendata, sattr); |
| 2170 | |
| 2171 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2172 | status = nfs4_do_setattr(state->inode, cred, |
| 2173 | opendata->o_res.f_attr, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2174 | state, label, olabel); |
| 2175 | if (status == 0) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2176 | nfs_setattr_update_inode(state->inode, sattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2177 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2178 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2179 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2180 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2181 | |
| 2182 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 2183 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 2184 | else |
| 2185 | kfree(opendata->f_attr.mdsthreshold); |
| 2186 | opendata->f_attr.mdsthreshold = NULL; |
| 2187 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2188 | nfs4_label_free(olabel); |
| 2189 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2190 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2192 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2193 | err_free_label: |
| 2194 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2195 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2196 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2197 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2198 | err_put_state_owner: |
| 2199 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | return status; |
| 2202 | } |
| 2203 | |
| 2204 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2205 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2206 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2207 | int flags, |
| 2208 | struct iattr *sattr, |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2209 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2211 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | struct nfs4_exception exception = { }; |
| 2213 | struct nfs4_state *res; |
| 2214 | int status; |
| 2215 | |
| 2216 | do { |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2217 | status = _nfs4_do_open(dir, ctx, flags, sattr, label); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2218 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2219 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | if (status == 0) |
| 2221 | break; |
| 2222 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2223 | * book-keeping w.r.t. state-changing operations |
| 2224 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2225 | * It is actually a sign of a bug on the client or on the server. |
| 2226 | * |
| 2227 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2228 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | * have unhashed the old state_owner for us, and that we can |
| 2230 | * therefore safely retry using a new one. We should still warn |
| 2231 | * the user though... |
| 2232 | */ |
| 2233 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2234 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2235 | " returned a bad sequence-id error!\n", |
| 2236 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | exception.retry = 1; |
| 2238 | continue; |
| 2239 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2240 | /* |
| 2241 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2242 | * state before it received the OPEN_CONFIRM. |
| 2243 | * Recover by retrying the request as per the discussion |
| 2244 | * on Page 181 of RFC3530. |
| 2245 | */ |
| 2246 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2247 | exception.retry = 1; |
| 2248 | continue; |
| 2249 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2250 | if (status == -EAGAIN) { |
| 2251 | /* We must have found a delegation */ |
| 2252 | exception.retry = 1; |
| 2253 | continue; |
| 2254 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2255 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2256 | continue; |
| 2257 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | status, &exception)); |
| 2259 | } while (exception.retry); |
| 2260 | return res; |
| 2261 | } |
| 2262 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2263 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2264 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2265 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2266 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2268 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2270 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | .iap = sattr, |
| 2272 | .server = server, |
| 2273 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2274 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | }; |
| 2276 | struct nfs_setattrres res = { |
| 2277 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2278 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | .server = server, |
| 2280 | }; |
| 2281 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2282 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2283 | .rpc_argp = &arg, |
| 2284 | .rpc_resp = &res, |
| 2285 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2287 | unsigned long timestamp = jiffies; |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2288 | fmode_t fmode; |
| 2289 | bool truncate; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2290 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2292 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2293 | if (ilabel) |
| 2294 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2295 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2296 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2298 | /* Servers should only apply open mode checks for file size changes */ |
| 2299 | truncate = (sattr->ia_valid & ATTR_SIZE) ? true : false; |
| 2300 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2301 | |
| 2302 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) { |
| 2303 | /* Use that stateid */ |
| 2304 | } else if (truncate && state != NULL && nfs4_valid_open_stateid(state)) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2305 | struct nfs_lockowner lockowner = { |
| 2306 | .l_owner = current->files, |
| 2307 | .l_pid = current->tgid, |
| 2308 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2309 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2310 | &lockowner); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2311 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2312 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2314 | 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] | 2315 | if (status == 0 && state != NULL) |
| 2316 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2317 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | } |
| 2319 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2320 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2321 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2322 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2323 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2325 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2326 | struct nfs4_exception exception = { |
| 2327 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2328 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2329 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | int err; |
| 2331 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2332 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state, ilabel, olabel); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 2333 | trace_nfs4_setattr(inode, err); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2334 | switch (err) { |
| 2335 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2336 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2337 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2338 | "applying open mode checks to " |
| 2339 | "a SETATTR that is not " |
| 2340 | "changing file size.\n", |
| 2341 | server->nfs_client->cl_hostname); |
| 2342 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2343 | if (state && !(state->state & FMODE_WRITE)) { |
| 2344 | err = -EBADF; |
| 2345 | if (sattr->ia_valid & ATTR_OPEN) |
| 2346 | err = -EACCES; |
| 2347 | goto out; |
| 2348 | } |
| 2349 | } |
| 2350 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2352 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2353 | return err; |
| 2354 | } |
| 2355 | |
| 2356 | struct nfs4_closedata { |
| 2357 | struct inode *inode; |
| 2358 | struct nfs4_state *state; |
| 2359 | struct nfs_closeargs arg; |
| 2360 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2361 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2362 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2363 | bool roc; |
| 2364 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | }; |
| 2366 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2367 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2368 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2369 | struct nfs4_closedata *calldata = data; |
| 2370 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2371 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2372 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2373 | if (calldata->roc) |
| 2374 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2375 | nfs4_put_open_state(calldata->state); |
| 2376 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2377 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2378 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2379 | kfree(calldata); |
| 2380 | } |
| 2381 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2382 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2383 | fmode_t fmode) |
| 2384 | { |
| 2385 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2386 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2387 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 2388 | case FMODE_WRITE: |
| 2389 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2390 | break; |
| 2391 | case FMODE_READ: |
| 2392 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2393 | break; |
| 2394 | case 0: |
| 2395 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2396 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2397 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 2398 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2399 | spin_unlock(&state->owner->so_lock); |
| 2400 | } |
| 2401 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2402 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2404 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2405 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2407 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2408 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2409 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2410 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2411 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | /* hmm. we are done with the inode, and in the process of freeing |
| 2413 | * the state_owner. we keep this around to process errors |
| 2414 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 | switch (task->tk_status) { |
| 2416 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2417 | if (calldata->roc) |
| 2418 | pnfs_roc_set_barrier(state->inode, |
| 2419 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2420 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2421 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2422 | nfs4_close_clear_stateid_flags(state, |
| 2423 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2424 | break; |
| 2425 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2426 | case -NFS4ERR_OLD_STATEID: |
| 2427 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2429 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2430 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2431 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2432 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2433 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2435 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2436 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2437 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2438 | } |
| 2439 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2440 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2441 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2442 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2443 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2444 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2445 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2446 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2447 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2448 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2449 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2450 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2451 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2452 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2453 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2454 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2455 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2456 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2457 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2458 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2459 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2460 | } |
| 2461 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2462 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2463 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2464 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2465 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2466 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2467 | if (!nfs4_valid_open_stateid(state)) |
| 2468 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2469 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2470 | |
| 2471 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2472 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2473 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2474 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2475 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2476 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2477 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2478 | if (calldata->roc && |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2479 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) { |
| 2480 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2481 | goto out_wait; |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2482 | } |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2483 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2484 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2485 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2486 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2487 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2488 | &calldata->arg.seq_args, |
| 2489 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2490 | task) != 0) |
| 2491 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2492 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2493 | return; |
| 2494 | out_no_action: |
| 2495 | task->tk_action = NULL; |
| 2496 | out_wait: |
| 2497 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | } |
| 2499 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2500 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2501 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2502 | .rpc_call_done = nfs4_close_done, |
| 2503 | .rpc_release = nfs4_free_closedata, |
| 2504 | }; |
| 2505 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | /* |
| 2507 | * It is possible for data to be read/written from a mem-mapped file |
| 2508 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2509 | * This means that we can't safely call nfsv4 close on a file until |
| 2510 | * the inode is cleared. This in turn means that we are not good |
| 2511 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2512 | * share state even when we are done with one of the three share |
| 2513 | * stateid's in the inode. |
| 2514 | * |
| 2515 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2516 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2517 | 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] | 2518 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2519 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2521 | struct nfs4_state_owner *sp = state->owner; |
| 2522 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2523 | struct rpc_message msg = { |
| 2524 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2525 | .rpc_cred = state->owner->so_cred, |
| 2526 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2527 | struct rpc_task_setup task_setup_data = { |
| 2528 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2529 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2530 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2531 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2532 | .flags = RPC_TASK_ASYNC, |
| 2533 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2534 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2536 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2538 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame^] | 2539 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2540 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2541 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2542 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2543 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2544 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2545 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2546 | if (calldata->arg.seqid == NULL) |
| 2547 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2548 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2549 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2550 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2551 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2552 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2553 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2554 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2555 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2556 | msg.rpc_argp = &calldata->arg; |
| 2557 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2558 | task_setup_data.callback_data = calldata; |
| 2559 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2560 | if (IS_ERR(task)) |
| 2561 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2562 | status = 0; |
| 2563 | if (wait) |
| 2564 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2565 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2566 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2567 | out_free_calldata: |
| 2568 | kfree(calldata); |
| 2569 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2570 | nfs4_put_open_state(state); |
| 2571 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2572 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | } |
| 2574 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2575 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2576 | 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] | 2577 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2578 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2579 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 2580 | |
| 2581 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2582 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2583 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2584 | state = nfs4_do_open(dir, ctx, open_flags, attr, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2585 | |
| 2586 | nfs4_label_release_security(label); |
| 2587 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2588 | if (IS_ERR(state)) |
| 2589 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2590 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | } |
| 2592 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2593 | 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] | 2594 | { |
| 2595 | if (ctx->state == NULL) |
| 2596 | return; |
| 2597 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2598 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2599 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2600 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2601 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | |
| 2603 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2604 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2605 | struct nfs4_server_caps_arg args = { |
| 2606 | .fhandle = fhandle, |
| 2607 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2608 | struct nfs4_server_caps_res res = {}; |
| 2609 | struct rpc_message msg = { |
| 2610 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2611 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2612 | .rpc_resp = &res, |
| 2613 | }; |
| 2614 | int status; |
| 2615 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2616 | 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] | 2617 | if (status == 0) { |
| 2618 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2619 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2620 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2621 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2622 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2623 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2624 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2625 | server->caps |= NFS_CAP_ACLS; |
| 2626 | if (res.has_links != 0) |
| 2627 | server->caps |= NFS_CAP_HARDLINKS; |
| 2628 | if (res.has_symlinks != 0) |
| 2629 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2630 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2631 | server->caps |= NFS_CAP_FILEID; |
| 2632 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2633 | server->caps |= NFS_CAP_MODE; |
| 2634 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2635 | server->caps |= NFS_CAP_NLINK; |
| 2636 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2637 | server->caps |= NFS_CAP_OWNER; |
| 2638 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2639 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2640 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2641 | server->caps |= NFS_CAP_ATIME; |
| 2642 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2643 | server->caps |= NFS_CAP_CTIME; |
| 2644 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2645 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2646 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 2647 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2648 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 2649 | #endif |
| 2650 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 2651 | sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2652 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2653 | if (server->caps & NFS_CAP_SECURITY_LABEL) { |
| 2654 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2655 | res.attr_bitmask[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2656 | } |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2657 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2658 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2659 | 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] | 2660 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2661 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2663 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | return status; |
| 2665 | } |
| 2666 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2667 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 | { |
| 2669 | struct nfs4_exception exception = { }; |
| 2670 | int err; |
| 2671 | do { |
| 2672 | err = nfs4_handle_exception(server, |
| 2673 | _nfs4_server_capabilities(server, fhandle), |
| 2674 | &exception); |
| 2675 | } while (exception.retry); |
| 2676 | return err; |
| 2677 | } |
| 2678 | |
| 2679 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2680 | struct nfs_fsinfo *info) |
| 2681 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2682 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2684 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | }; |
| 2686 | struct nfs4_lookup_res res = { |
| 2687 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2688 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 | .fh = fhandle, |
| 2690 | }; |
| 2691 | struct rpc_message msg = { |
| 2692 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2693 | .rpc_argp = &args, |
| 2694 | .rpc_resp = &res, |
| 2695 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2696 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2697 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 2698 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 2699 | /* |
| 2700 | * Process the label in the upcoming getfattr |
| 2701 | */ |
| 2702 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 2703 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2704 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2705 | 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] | 2706 | } |
| 2707 | |
| 2708 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2709 | struct nfs_fsinfo *info) |
| 2710 | { |
| 2711 | struct nfs4_exception exception = { }; |
| 2712 | int err; |
| 2713 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2714 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 2715 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2716 | switch (err) { |
| 2717 | case 0: |
| 2718 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2719 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2720 | default: |
| 2721 | err = nfs4_handle_exception(server, err, &exception); |
| 2722 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2723 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2724 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2725 | return err; |
| 2726 | } |
| 2727 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2728 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2729 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2730 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 2731 | struct rpc_auth_create_args auth_args = { |
| 2732 | .pseudoflavor = flavor, |
| 2733 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2734 | struct rpc_auth *auth; |
| 2735 | int ret; |
| 2736 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 2737 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2738 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 2739 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2740 | goto out; |
| 2741 | } |
| 2742 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2743 | out: |
| 2744 | return ret; |
| 2745 | } |
| 2746 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2747 | /* |
| 2748 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 2749 | * |
| 2750 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 2751 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 2752 | * |
| 2753 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 2754 | * negative errno value. |
| 2755 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2756 | 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] | 2757 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2758 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2759 | /* Per 3530bis 15.33.5 */ |
| 2760 | static const rpc_authflavor_t flav_array[] = { |
| 2761 | RPC_AUTH_GSS_KRB5P, |
| 2762 | RPC_AUTH_GSS_KRB5I, |
| 2763 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 2764 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2765 | RPC_AUTH_NULL, |
| 2766 | }; |
| 2767 | int status = -EPERM; |
| 2768 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2770 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2771 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2772 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2773 | continue; |
| 2774 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2775 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2776 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2777 | /* |
| 2778 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2779 | * to access the mount. It could also mean that we tried to mount |
| 2780 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2781 | * existing mount programs don't handle -EACCES very well so it should |
| 2782 | * be mapped to -EPERM instead. |
| 2783 | */ |
| 2784 | if (status == -EACCES) |
| 2785 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2786 | return status; |
| 2787 | } |
| 2788 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2789 | static int nfs4_do_find_root_sec(struct nfs_server *server, |
| 2790 | struct nfs_fh *fhandle, struct nfs_fsinfo *info) |
| 2791 | { |
| 2792 | int mv = server->nfs_client->cl_minorversion; |
| 2793 | return nfs_v4_minor_ops[mv]->find_root_sec(server, fhandle, info); |
| 2794 | } |
| 2795 | |
| 2796 | /** |
| 2797 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 2798 | * @server: initialized nfs_server handle |
| 2799 | * @fhandle: we fill in the pseudo-fs root file handle |
| 2800 | * @info: we fill in an FSINFO struct |
| 2801 | * |
| 2802 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2803 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2804 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2805 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2806 | { |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2807 | int status; |
| 2808 | |
| 2809 | status = nfs4_lookup_root(server, fhandle, info); |
| 2810 | if ((status == -NFS4ERR_WRONGSEC) && |
| 2811 | !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2812 | status = nfs4_do_find_root_sec(server, fhandle, info); |
| 2813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2814 | if (status == 0) |
| 2815 | status = nfs4_server_capabilities(server, fhandle); |
| 2816 | if (status == 0) |
| 2817 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2818 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2819 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2820 | } |
| 2821 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2822 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2823 | struct nfs_fsinfo *info) |
| 2824 | { |
| 2825 | int error; |
| 2826 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2827 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2828 | |
| 2829 | error = nfs4_server_capabilities(server, mntfh); |
| 2830 | if (error < 0) { |
| 2831 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2832 | return error; |
| 2833 | } |
| 2834 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2835 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 2836 | if (IS_ERR(label)) |
| 2837 | return PTR_ERR(label); |
| 2838 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2839 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2840 | if (error < 0) { |
| 2841 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2842 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2843 | } |
| 2844 | |
| 2845 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2846 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2847 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2848 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2849 | err_free_label: |
| 2850 | nfs4_label_free(label); |
| 2851 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2852 | return error; |
| 2853 | } |
| 2854 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2855 | /* |
| 2856 | * Get locations and (maybe) other attributes of a referral. |
| 2857 | * Note that we'll actually follow the referral later when |
| 2858 | * we detect fsid mismatch in inode revalidation |
| 2859 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2860 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2861 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2862 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2863 | { |
| 2864 | int status = -ENOMEM; |
| 2865 | struct page *page = NULL; |
| 2866 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2867 | |
| 2868 | page = alloc_page(GFP_KERNEL); |
| 2869 | if (page == NULL) |
| 2870 | goto out; |
| 2871 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2872 | if (locations == NULL) |
| 2873 | goto out; |
| 2874 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2875 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2876 | if (status != 0) |
| 2877 | goto out; |
| 2878 | /* Make sure server returned a different fsid for the referral */ |
| 2879 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2880 | dprintk("%s: server did not return a different fsid for" |
| 2881 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2882 | status = -EIO; |
| 2883 | goto out; |
| 2884 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2885 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2886 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2887 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2888 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2889 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2890 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2891 | out: |
| 2892 | if (page) |
| 2893 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2894 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2895 | return status; |
| 2896 | } |
| 2897 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2898 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2899 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | { |
| 2901 | struct nfs4_getattr_arg args = { |
| 2902 | .fh = fhandle, |
| 2903 | .bitmask = server->attr_bitmask, |
| 2904 | }; |
| 2905 | struct nfs4_getattr_res res = { |
| 2906 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2907 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2908 | .server = server, |
| 2909 | }; |
| 2910 | struct rpc_message msg = { |
| 2911 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2912 | .rpc_argp = &args, |
| 2913 | .rpc_resp = &res, |
| 2914 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2915 | |
| 2916 | args.bitmask = nfs4_bitmask(server, label); |
| 2917 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2918 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2919 | 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] | 2920 | } |
| 2921 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2922 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2923 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2924 | { |
| 2925 | struct nfs4_exception exception = { }; |
| 2926 | int err; |
| 2927 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 2928 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 2929 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 2930 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2931 | &exception); |
| 2932 | } while (exception.retry); |
| 2933 | return err; |
| 2934 | } |
| 2935 | |
| 2936 | /* |
| 2937 | * The file is not closed if it is opened due to the a request to change |
| 2938 | * the size of the file. The open call will not be needed once the |
| 2939 | * VFS layer lookup-intents are implemented. |
| 2940 | * |
| 2941 | * Close is called when the inode is destroyed. |
| 2942 | * If we haven't opened the file for O_WRONLY, we |
| 2943 | * need to in the size_change case to obtain a stateid. |
| 2944 | * |
| 2945 | * Got race? |
| 2946 | * Because OPEN is always done by name in nfsv4, it is |
| 2947 | * possible that we opened a different file by the same |
| 2948 | * name. We can recognize this race condition, but we |
| 2949 | * can't do anything about it besides returning an error. |
| 2950 | * |
| 2951 | * This will be fixed with VFS changes (lookup-intent). |
| 2952 | */ |
| 2953 | static int |
| 2954 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2955 | struct iattr *sattr) |
| 2956 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2957 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2958 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2959 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2960 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2961 | int status; |
| 2962 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2963 | if (pnfs_ld_layoutret_on_setattr(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 2964 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2965 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2966 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2967 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2968 | /* Deal with open(O_TRUNC) */ |
| 2969 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 2970 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2971 | |
| 2972 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 2973 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2974 | return 0; |
| 2975 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2976 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2977 | if (sattr->ia_valid & ATTR_FILE) { |
| 2978 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2979 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2980 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2981 | if (ctx) { |
| 2982 | cred = ctx->cred; |
| 2983 | state = ctx->state; |
| 2984 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2985 | } |
| 2986 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2987 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 2988 | if (IS_ERR(label)) |
| 2989 | return PTR_ERR(label); |
| 2990 | |
| 2991 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2992 | if (status == 0) { |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2993 | nfs_setattr_update_inode(inode, sattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2994 | nfs_setsecurity(inode, fattr, label); |
| 2995 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2996 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | return status; |
| 2998 | } |
| 2999 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3000 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3001 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3002 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3003 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3004 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3005 | int status; |
| 3006 | struct nfs4_lookup_arg args = { |
| 3007 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3008 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3009 | .name = name, |
| 3010 | }; |
| 3011 | struct nfs4_lookup_res res = { |
| 3012 | .server = server, |
| 3013 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3014 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3015 | .fh = fhandle, |
| 3016 | }; |
| 3017 | struct rpc_message msg = { |
| 3018 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3019 | .rpc_argp = &args, |
| 3020 | .rpc_resp = &res, |
| 3021 | }; |
| 3022 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3023 | args.bitmask = nfs4_bitmask(server, label); |
| 3024 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3025 | nfs_fattr_init(fattr); |
| 3026 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3027 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3028 | 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] | 3029 | dprintk("NFS reply lookup: %d\n", status); |
| 3030 | return status; |
| 3031 | } |
| 3032 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3033 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3034 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3035 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3036 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3037 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3038 | fattr->nlink = 2; |
| 3039 | } |
| 3040 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3041 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 3042 | struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3043 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3044 | { |
| 3045 | struct nfs4_exception exception = { }; |
| 3046 | struct rpc_clnt *client = *clnt; |
| 3047 | int err; |
| 3048 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3049 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3050 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3051 | switch (err) { |
| 3052 | case -NFS4ERR_BADNAME: |
| 3053 | err = -ENOENT; |
| 3054 | goto out; |
| 3055 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3056 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3057 | goto out; |
| 3058 | case -NFS4ERR_WRONGSEC: |
| 3059 | err = -EPERM; |
| 3060 | if (client != *clnt) |
| 3061 | goto out; |
| 3062 | |
| 3063 | client = nfs4_create_sec_client(client, dir, name); |
| 3064 | if (IS_ERR(client)) |
| 3065 | return PTR_ERR(client); |
| 3066 | |
| 3067 | exception.retry = 1; |
| 3068 | break; |
| 3069 | default: |
| 3070 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3071 | } |
| 3072 | } while (exception.retry); |
| 3073 | |
| 3074 | out: |
| 3075 | if (err == 0) |
| 3076 | *clnt = client; |
| 3077 | else if (client != *clnt) |
| 3078 | rpc_shutdown_client(client); |
| 3079 | |
| 3080 | return err; |
| 3081 | } |
| 3082 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 3083 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3084 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3085 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3086 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3087 | int status; |
| 3088 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3089 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3090 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3091 | if (client != NFS_CLIENT(dir)) { |
| 3092 | rpc_shutdown_client(client); |
| 3093 | nfs_fixup_secinfo_attributes(fattr); |
| 3094 | } |
| 3095 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3096 | } |
| 3097 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3098 | struct rpc_clnt * |
| 3099 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 3100 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3101 | { |
| 3102 | int status; |
| 3103 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 3104 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3105 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3106 | if (status < 0) { |
| 3107 | rpc_shutdown_client(client); |
| 3108 | return ERR_PTR(status); |
| 3109 | } |
| 3110 | return client; |
| 3111 | } |
| 3112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3114 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3115 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3116 | struct nfs4_accessargs args = { |
| 3117 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3118 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3120 | struct nfs4_accessres res = { |
| 3121 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3122 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3123 | struct rpc_message msg = { |
| 3124 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3125 | .rpc_argp = &args, |
| 3126 | .rpc_resp = &res, |
| 3127 | .rpc_cred = entry->cred, |
| 3128 | }; |
| 3129 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3130 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | |
| 3132 | /* |
| 3133 | * Determine which access bits we want to ask for... |
| 3134 | */ |
| 3135 | if (mode & MAY_READ) |
| 3136 | args.access |= NFS4_ACCESS_READ; |
| 3137 | if (S_ISDIR(inode->i_mode)) { |
| 3138 | if (mode & MAY_WRITE) |
| 3139 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3140 | if (mode & MAY_EXEC) |
| 3141 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3142 | } else { |
| 3143 | if (mode & MAY_WRITE) |
| 3144 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3145 | if (mode & MAY_EXEC) |
| 3146 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3147 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3148 | |
| 3149 | res.fattr = nfs_alloc_fattr(); |
| 3150 | if (res.fattr == NULL) |
| 3151 | return -ENOMEM; |
| 3152 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3153 | 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] | 3154 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3155 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3156 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3158 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | return status; |
| 3160 | } |
| 3161 | |
| 3162 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3163 | { |
| 3164 | struct nfs4_exception exception = { }; |
| 3165 | int err; |
| 3166 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3167 | err = _nfs4_proc_access(inode, entry); |
| 3168 | trace_nfs4_access(inode, err); |
| 3169 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3170 | &exception); |
| 3171 | } while (exception.retry); |
| 3172 | return err; |
| 3173 | } |
| 3174 | |
| 3175 | /* |
| 3176 | * TODO: For the time being, we don't try to get any attributes |
| 3177 | * along with any of the zero-copy operations READ, READDIR, |
| 3178 | * READLINK, WRITE. |
| 3179 | * |
| 3180 | * In the case of the first three, we want to put the GETATTR |
| 3181 | * after the read-type operation -- this is because it is hard |
| 3182 | * to predict the length of a GETATTR response in v4, and thus |
| 3183 | * align the READ data correctly. This means that the GETATTR |
| 3184 | * may end up partially falling into the page cache, and we should |
| 3185 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3186 | * To do this efficiently, we need to know the total length |
| 3187 | * of data received, which doesn't seem to be available outside |
| 3188 | * of the RPC layer. |
| 3189 | * |
| 3190 | * In the case of WRITE, we also want to put the GETATTR after |
| 3191 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3192 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | * |
| 3194 | * Both of these changes to the XDR layer would in fact be quite |
| 3195 | * minor, but I decided to leave them for a subsequent patch. |
| 3196 | */ |
| 3197 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3198 | unsigned int pgbase, unsigned int pglen) |
| 3199 | { |
| 3200 | struct nfs4_readlink args = { |
| 3201 | .fh = NFS_FH(inode), |
| 3202 | .pgbase = pgbase, |
| 3203 | .pglen = pglen, |
| 3204 | .pages = &page, |
| 3205 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3206 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3207 | struct rpc_message msg = { |
| 3208 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3209 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3210 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3211 | }; |
| 3212 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3213 | 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] | 3214 | } |
| 3215 | |
| 3216 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3217 | unsigned int pgbase, unsigned int pglen) |
| 3218 | { |
| 3219 | struct nfs4_exception exception = { }; |
| 3220 | int err; |
| 3221 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3222 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3223 | trace_nfs4_readlink(inode, err); |
| 3224 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | &exception); |
| 3226 | } while (exception.retry); |
| 3227 | return err; |
| 3228 | } |
| 3229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3230 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3231 | * 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] | 3232 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3233 | static int |
| 3234 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3235 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3237 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3238 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | int status = 0; |
| 3241 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3242 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3243 | if (IS_ERR(ctx)) |
| 3244 | return PTR_ERR(ctx); |
| 3245 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3246 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3247 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3248 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 3249 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | if (IS_ERR(state)) { |
| 3251 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3252 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3253 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3255 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3256 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3257 | return status; |
| 3258 | } |
| 3259 | |
| 3260 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3261 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3262 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3263 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3264 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3265 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3267 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3268 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3269 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3271 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3272 | .rpc_argp = &args, |
| 3273 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3275 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3276 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3277 | 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] | 3278 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3279 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3280 | return status; |
| 3281 | } |
| 3282 | |
| 3283 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3284 | { |
| 3285 | struct nfs4_exception exception = { }; |
| 3286 | int err; |
| 3287 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3288 | err = _nfs4_proc_remove(dir, name); |
| 3289 | trace_nfs4_remove(dir, name, err); |
| 3290 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3291 | &exception); |
| 3292 | } while (exception.retry); |
| 3293 | return err; |
| 3294 | } |
| 3295 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3296 | 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] | 3297 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3298 | struct nfs_server *server = NFS_SERVER(dir); |
| 3299 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3300 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3301 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3302 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3303 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame^] | 3304 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3305 | |
| 3306 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3307 | } |
| 3308 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3309 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3310 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3311 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 3312 | &data->args.seq_args, |
| 3313 | &data->res.seq_res, |
| 3314 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | } |
| 3316 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3317 | 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] | 3318 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3319 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 3320 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3321 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3322 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3323 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3324 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3325 | return 0; |
| 3326 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3327 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3328 | } |
| 3329 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3330 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3331 | { |
| 3332 | struct nfs_server *server = NFS_SERVER(dir); |
| 3333 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3334 | struct nfs_renameres *res = msg->rpc_resp; |
| 3335 | |
| 3336 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3337 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame^] | 3338 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3339 | } |
| 3340 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3341 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3342 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3343 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3344 | &data->args.seq_args, |
| 3345 | &data->res.seq_res, |
| 3346 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3347 | } |
| 3348 | |
| 3349 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3350 | struct inode *new_dir) |
| 3351 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 3352 | struct nfs_renamedata *data = task->tk_calldata; |
| 3353 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3354 | |
| 3355 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3356 | return 0; |
| 3357 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 3358 | return 0; |
| 3359 | |
| 3360 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3361 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3362 | return 1; |
| 3363 | } |
| 3364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3365 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3366 | struct inode *new_dir, struct qstr *new_name) |
| 3367 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3368 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 3369 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3370 | .old_dir = NFS_FH(old_dir), |
| 3371 | .new_dir = NFS_FH(new_dir), |
| 3372 | .old_name = old_name, |
| 3373 | .new_name = new_name, |
| 3374 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3375 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3376 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3377 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3378 | struct rpc_message msg = { |
| 3379 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3380 | .rpc_argp = &arg, |
| 3381 | .rpc_resp = &res, |
| 3382 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3383 | int status = -ENOMEM; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3384 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3385 | 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] | 3386 | if (!status) { |
| 3387 | update_changeattr(old_dir, &res.old_cinfo); |
| 3388 | update_changeattr(new_dir, &res.new_cinfo); |
| 3389 | } |
| 3390 | return status; |
| 3391 | } |
| 3392 | |
| 3393 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3394 | struct inode *new_dir, struct qstr *new_name) |
| 3395 | { |
| 3396 | struct nfs4_exception exception = { }; |
| 3397 | int err; |
| 3398 | do { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 3399 | err = _nfs4_proc_rename(old_dir, old_name, |
| 3400 | new_dir, new_name); |
| 3401 | trace_nfs4_rename(old_dir, old_name, new_dir, new_name, err); |
| 3402 | err = nfs4_handle_exception(NFS_SERVER(old_dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3403 | &exception); |
| 3404 | } while (exception.retry); |
| 3405 | return err; |
| 3406 | } |
| 3407 | |
| 3408 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3409 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3410 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3411 | struct nfs4_link_arg arg = { |
| 3412 | .fh = NFS_FH(inode), |
| 3413 | .dir_fh = NFS_FH(dir), |
| 3414 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3415 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3416 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3417 | struct nfs4_link_res res = { |
| 3418 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3419 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3420 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | struct rpc_message msg = { |
| 3422 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3423 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3424 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3425 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3426 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3427 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3428 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3429 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3430 | goto out; |
| 3431 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3432 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3433 | if (IS_ERR(res.label)) { |
| 3434 | status = PTR_ERR(res.label); |
| 3435 | goto out; |
| 3436 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3437 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3438 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3439 | 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] | 3440 | if (!status) { |
| 3441 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3442 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 3443 | if (!status) |
| 3444 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3445 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3446 | |
| 3447 | |
| 3448 | nfs4_label_free(res.label); |
| 3449 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3450 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3451 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3452 | return status; |
| 3453 | } |
| 3454 | |
| 3455 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3456 | { |
| 3457 | struct nfs4_exception exception = { }; |
| 3458 | int err; |
| 3459 | do { |
| 3460 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3461 | _nfs4_proc_link(inode, dir, name), |
| 3462 | &exception); |
| 3463 | } while (exception.retry); |
| 3464 | return err; |
| 3465 | } |
| 3466 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3467 | struct nfs4_createdata { |
| 3468 | struct rpc_message msg; |
| 3469 | struct nfs4_create_arg arg; |
| 3470 | struct nfs4_create_res res; |
| 3471 | struct nfs_fh fh; |
| 3472 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3473 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3474 | }; |
| 3475 | |
| 3476 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3477 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3478 | { |
| 3479 | struct nfs4_createdata *data; |
| 3480 | |
| 3481 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3482 | if (data != NULL) { |
| 3483 | struct nfs_server *server = NFS_SERVER(dir); |
| 3484 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3485 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3486 | if (IS_ERR(data->label)) |
| 3487 | goto out_free; |
| 3488 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3489 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3490 | data->msg.rpc_argp = &data->arg; |
| 3491 | data->msg.rpc_resp = &data->res; |
| 3492 | data->arg.dir_fh = NFS_FH(dir); |
| 3493 | data->arg.server = server; |
| 3494 | data->arg.name = name; |
| 3495 | data->arg.attrs = sattr; |
| 3496 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3497 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3498 | data->res.server = server; |
| 3499 | data->res.fh = &data->fh; |
| 3500 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3501 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3502 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3503 | } |
| 3504 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3505 | out_free: |
| 3506 | kfree(data); |
| 3507 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3508 | } |
| 3509 | |
| 3510 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3511 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3512 | 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] | 3513 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3514 | if (status == 0) { |
| 3515 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3516 | 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] | 3517 | } |
| 3518 | return status; |
| 3519 | } |
| 3520 | |
| 3521 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3522 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3523 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3524 | kfree(data); |
| 3525 | } |
| 3526 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3527 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3528 | struct page *page, unsigned int len, struct iattr *sattr, |
| 3529 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3530 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3531 | struct nfs4_createdata *data; |
| 3532 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3533 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3534 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3535 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3536 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3537 | status = -ENOMEM; |
| 3538 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3539 | if (data == NULL) |
| 3540 | goto out; |
| 3541 | |
| 3542 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3543 | data->arg.u.symlink.pages = &page; |
| 3544 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3545 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3546 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3547 | status = nfs4_do_create(dir, dentry, data); |
| 3548 | |
| 3549 | nfs4_free_createdata(data); |
| 3550 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3551 | return status; |
| 3552 | } |
| 3553 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3554 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3555 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3556 | { |
| 3557 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3558 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3559 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3560 | |
| 3561 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3563 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3564 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 3565 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 3566 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3567 | &exception); |
| 3568 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3569 | |
| 3570 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3571 | return err; |
| 3572 | } |
| 3573 | |
| 3574 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3575 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3576 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3577 | struct nfs4_createdata *data; |
| 3578 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3580 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3581 | if (data == NULL) |
| 3582 | goto out; |
| 3583 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3584 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3585 | status = nfs4_do_create(dir, dentry, data); |
| 3586 | |
| 3587 | nfs4_free_createdata(data); |
| 3588 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3589 | return status; |
| 3590 | } |
| 3591 | |
| 3592 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3593 | struct iattr *sattr) |
| 3594 | { |
| 3595 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3596 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3597 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3598 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3599 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3600 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3601 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3602 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3603 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 3604 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 3605 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3606 | &exception); |
| 3607 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3608 | nfs4_label_release_security(label); |
| 3609 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3610 | return err; |
| 3611 | } |
| 3612 | |
| 3613 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3614 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3615 | { |
| 3616 | struct inode *dir = dentry->d_inode; |
| 3617 | struct nfs4_readdir_arg args = { |
| 3618 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3619 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3620 | .pgbase = 0, |
| 3621 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3622 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3623 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3624 | }; |
| 3625 | struct nfs4_readdir_res res; |
| 3626 | struct rpc_message msg = { |
| 3627 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3628 | .rpc_argp = &args, |
| 3629 | .rpc_resp = &res, |
| 3630 | .rpc_cred = cred, |
| 3631 | }; |
| 3632 | int status; |
| 3633 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3634 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3635 | dentry->d_parent->d_name.name, |
| 3636 | dentry->d_name.name, |
| 3637 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3638 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3639 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3640 | 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] | 3641 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3642 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3643 | status += args.pgbase; |
| 3644 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3645 | |
| 3646 | nfs_invalidate_atime(dir); |
| 3647 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3648 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3649 | return status; |
| 3650 | } |
| 3651 | |
| 3652 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3653 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3654 | { |
| 3655 | struct nfs4_exception exception = { }; |
| 3656 | int err; |
| 3657 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3658 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 3659 | pages, count, plus); |
| 3660 | trace_nfs4_readdir(dentry->d_inode, err); |
| 3661 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3662 | &exception); |
| 3663 | } while (exception.retry); |
| 3664 | return err; |
| 3665 | } |
| 3666 | |
| 3667 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3668 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3669 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3670 | struct nfs4_createdata *data; |
| 3671 | int mode = sattr->ia_mode; |
| 3672 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3673 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3674 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3675 | if (data == NULL) |
| 3676 | goto out; |
| 3677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3678 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3679 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3680 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3681 | data->arg.ftype = NF4BLK; |
| 3682 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3683 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3684 | } |
| 3685 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3686 | data->arg.ftype = NF4CHR; |
| 3687 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3688 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3689 | } else if (!S_ISSOCK(mode)) { |
| 3690 | status = -EINVAL; |
| 3691 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3692 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3693 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3694 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3695 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3696 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3697 | nfs4_free_createdata(data); |
| 3698 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3699 | return status; |
| 3700 | } |
| 3701 | |
| 3702 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3703 | struct iattr *sattr, dev_t rdev) |
| 3704 | { |
| 3705 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3706 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3707 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3708 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3709 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3710 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3711 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3712 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3713 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 3714 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 3715 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3716 | &exception); |
| 3717 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3718 | |
| 3719 | nfs4_label_release_security(label); |
| 3720 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3721 | return err; |
| 3722 | } |
| 3723 | |
| 3724 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3725 | struct nfs_fsstat *fsstat) |
| 3726 | { |
| 3727 | struct nfs4_statfs_arg args = { |
| 3728 | .fh = fhandle, |
| 3729 | .bitmask = server->attr_bitmask, |
| 3730 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3731 | struct nfs4_statfs_res res = { |
| 3732 | .fsstat = fsstat, |
| 3733 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3734 | struct rpc_message msg = { |
| 3735 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3736 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3737 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3738 | }; |
| 3739 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3740 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3741 | 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] | 3742 | } |
| 3743 | |
| 3744 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3745 | { |
| 3746 | struct nfs4_exception exception = { }; |
| 3747 | int err; |
| 3748 | do { |
| 3749 | err = nfs4_handle_exception(server, |
| 3750 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3751 | &exception); |
| 3752 | } while (exception.retry); |
| 3753 | return err; |
| 3754 | } |
| 3755 | |
| 3756 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3757 | struct nfs_fsinfo *fsinfo) |
| 3758 | { |
| 3759 | struct nfs4_fsinfo_arg args = { |
| 3760 | .fh = fhandle, |
| 3761 | .bitmask = server->attr_bitmask, |
| 3762 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3763 | struct nfs4_fsinfo_res res = { |
| 3764 | .fsinfo = fsinfo, |
| 3765 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3766 | struct rpc_message msg = { |
| 3767 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3768 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3769 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3770 | }; |
| 3771 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3772 | 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] | 3773 | } |
| 3774 | |
| 3775 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3776 | { |
| 3777 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3778 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3779 | int err; |
| 3780 | |
| 3781 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3782 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3783 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3784 | if (err == 0) { |
| 3785 | struct nfs_client *clp = server->nfs_client; |
| 3786 | |
| 3787 | spin_lock(&clp->cl_lock); |
| 3788 | clp->cl_lease_time = fsinfo->lease_time * HZ; |
| 3789 | clp->cl_last_renewal = now; |
| 3790 | spin_unlock(&clp->cl_lock); |
| 3791 | break; |
| 3792 | } |
| 3793 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3794 | } while (exception.retry); |
| 3795 | return err; |
| 3796 | } |
| 3797 | |
| 3798 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3799 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3800 | int error; |
| 3801 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3802 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3803 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3804 | if (error == 0) { |
| 3805 | /* block layout checks this! */ |
| 3806 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3807 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3808 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3809 | |
| 3810 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3811 | } |
| 3812 | |
| 3813 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3814 | struct nfs_pathconf *pathconf) |
| 3815 | { |
| 3816 | struct nfs4_pathconf_arg args = { |
| 3817 | .fh = fhandle, |
| 3818 | .bitmask = server->attr_bitmask, |
| 3819 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3820 | struct nfs4_pathconf_res res = { |
| 3821 | .pathconf = pathconf, |
| 3822 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3823 | struct rpc_message msg = { |
| 3824 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3825 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3826 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3827 | }; |
| 3828 | |
| 3829 | /* None of the pathconf attributes are mandatory to implement */ |
| 3830 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3831 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3832 | return 0; |
| 3833 | } |
| 3834 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3835 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3836 | 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] | 3837 | } |
| 3838 | |
| 3839 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3840 | struct nfs_pathconf *pathconf) |
| 3841 | { |
| 3842 | struct nfs4_exception exception = { }; |
| 3843 | int err; |
| 3844 | |
| 3845 | do { |
| 3846 | err = nfs4_handle_exception(server, |
| 3847 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3848 | &exception); |
| 3849 | } while (exception.retry); |
| 3850 | return err; |
| 3851 | } |
| 3852 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3853 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3854 | const struct nfs_open_context *ctx, |
| 3855 | const struct nfs_lock_context *l_ctx, |
| 3856 | fmode_t fmode) |
| 3857 | { |
| 3858 | const struct nfs_lockowner *lockowner = NULL; |
| 3859 | |
| 3860 | if (l_ctx != NULL) |
| 3861 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3862 | return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3863 | } |
| 3864 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 3865 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3866 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 3867 | const struct nfs_open_context *ctx, |
| 3868 | const struct nfs_lock_context *l_ctx, |
| 3869 | fmode_t fmode) |
| 3870 | { |
| 3871 | nfs4_stateid current_stateid; |
| 3872 | |
| 3873 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode)) |
| 3874 | return false; |
| 3875 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 3876 | } |
| 3877 | |
| 3878 | static bool nfs4_error_stateid_expired(int err) |
| 3879 | { |
| 3880 | switch (err) { |
| 3881 | case -NFS4ERR_DELEG_REVOKED: |
| 3882 | case -NFS4ERR_ADMIN_REVOKED: |
| 3883 | case -NFS4ERR_BAD_STATEID: |
| 3884 | case -NFS4ERR_STALE_STATEID: |
| 3885 | case -NFS4ERR_OLD_STATEID: |
| 3886 | case -NFS4ERR_OPENMODE: |
| 3887 | case -NFS4ERR_EXPIRED: |
| 3888 | return true; |
| 3889 | } |
| 3890 | return false; |
| 3891 | } |
| 3892 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3893 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3894 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3895 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3896 | } |
| 3897 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3898 | 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] | 3899 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3900 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3901 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 3902 | trace_nfs4_read(data, task->tk_status); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3903 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3904 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3905 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3906 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3907 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3908 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3909 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3910 | renew_lease(server, data->timestamp); |
| 3911 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3912 | } |
| 3913 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3914 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
| 3915 | struct nfs_readargs *args) |
| 3916 | { |
| 3917 | |
| 3918 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3919 | nfs4_stateid_is_current(&args->stateid, |
| 3920 | args->context, |
| 3921 | args->lock_context, |
| 3922 | FMODE_READ)) |
| 3923 | return false; |
| 3924 | rpc_restart_call_prepare(task); |
| 3925 | return true; |
| 3926 | } |
| 3927 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3928 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3929 | { |
| 3930 | |
| 3931 | dprintk("--> %s\n", __func__); |
| 3932 | |
| 3933 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3934 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3935 | if (nfs4_read_stateid_changed(task, &data->args)) |
| 3936 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3937 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3938 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3939 | } |
| 3940 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3941 | 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] | 3942 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3943 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3944 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3945 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame^] | 3946 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3947 | } |
| 3948 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3949 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3950 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3951 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3952 | &data->args.seq_args, |
| 3953 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3954 | task)) |
| 3955 | return; |
| 3956 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 3957 | data->args.lock_context, FMODE_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3958 | } |
| 3959 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3960 | 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] | 3961 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3962 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3963 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 3964 | trace_nfs4_write(data, task->tk_status); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3965 | 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] | 3966 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3967 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3968 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3969 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3970 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3971 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3972 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3973 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3974 | } |
| 3975 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3976 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
| 3977 | struct nfs_writeargs *args) |
| 3978 | { |
| 3979 | |
| 3980 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3981 | nfs4_stateid_is_current(&args->stateid, |
| 3982 | args->context, |
| 3983 | args->lock_context, |
| 3984 | FMODE_WRITE)) |
| 3985 | return false; |
| 3986 | rpc_restart_call_prepare(task); |
| 3987 | return true; |
| 3988 | } |
| 3989 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3990 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3991 | { |
| 3992 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3993 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3994 | if (nfs4_write_stateid_changed(task, &data->args)) |
| 3995 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3996 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3997 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3998 | } |
| 3999 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4000 | static |
| 4001 | 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] | 4002 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4003 | const struct nfs_pgio_header *hdr = data->header; |
| 4004 | |
| 4005 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 4006 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 4007 | return false; |
| 4008 | /* Otherwise, request attributes if and only if we don't hold |
| 4009 | * a delegation |
| 4010 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4011 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4012 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4013 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4014 | 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] | 4015 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 4016 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4017 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4018 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4019 | data->args.bitmask = NULL; |
| 4020 | data->res.fattr = NULL; |
| 4021 | } else |
| 4022 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4023 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4024 | if (!data->write_done_cb) |
| 4025 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4026 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | data->timestamp = jiffies; |
| 4028 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4029 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame^] | 4030 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4031 | } |
| 4032 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 4033 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 4034 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4035 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4036 | &data->args.seq_args, |
| 4037 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4038 | task)) |
| 4039 | return; |
| 4040 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 4041 | data->args.lock_context, FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4042 | } |
| 4043 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4044 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4045 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4046 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4047 | &data->args.seq_args, |
| 4048 | &data->res.seq_res, |
| 4049 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | } |
| 4051 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4052 | 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] | 4053 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4054 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4055 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4056 | trace_nfs4_commit(data, task->tk_status); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4057 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4058 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4059 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4060 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4061 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4062 | } |
| 4063 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4064 | 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] | 4065 | { |
| 4066 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4067 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4068 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4069 | } |
| 4070 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4071 | 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] | 4072 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4073 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4074 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4075 | if (data->commit_done_cb == NULL) |
| 4076 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4077 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4078 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame^] | 4079 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4080 | } |
| 4081 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4082 | struct nfs4_renewdata { |
| 4083 | struct nfs_client *client; |
| 4084 | unsigned long timestamp; |
| 4085 | }; |
| 4086 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4087 | /* |
| 4088 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4089 | * standalone procedure for queueing an asynchronous RENEW. |
| 4090 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4091 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4092 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4093 | struct nfs4_renewdata *data = calldata; |
| 4094 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4095 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4096 | if (atomic_read(&clp->cl_count) > 1) |
| 4097 | nfs4_schedule_state_renewal(clp); |
| 4098 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4099 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4100 | } |
| 4101 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4102 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4103 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4104 | struct nfs4_renewdata *data = calldata; |
| 4105 | struct nfs_client *clp = data->client; |
| 4106 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4107 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4108 | trace_nfs4_renew_async(clp, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4109 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4110 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4111 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4112 | return; |
| 4113 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4114 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4115 | return; |
| 4116 | } |
| 4117 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4118 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4119 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4120 | } |
| 4121 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4122 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4123 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4124 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4125 | }; |
| 4126 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4127 | 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] | 4128 | { |
| 4129 | struct rpc_message msg = { |
| 4130 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4131 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4132 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4133 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4134 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4135 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4136 | if (renew_flags == 0) |
| 4137 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4138 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4139 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4140 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4141 | if (data == NULL) |
| 4142 | return -ENOMEM; |
| 4143 | data->client = clp; |
| 4144 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4145 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4146 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4147 | } |
| 4148 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4149 | 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] | 4150 | { |
| 4151 | struct rpc_message msg = { |
| 4152 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4153 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4154 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4155 | }; |
| 4156 | unsigned long now = jiffies; |
| 4157 | int status; |
| 4158 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4159 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4160 | if (status < 0) |
| 4161 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4162 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4163 | return 0; |
| 4164 | } |
| 4165 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4166 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4167 | { |
| 4168 | return (server->caps & NFS_CAP_ACLS) |
| 4169 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 4170 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 4171 | } |
| 4172 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4173 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4174 | * 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] | 4175 | * the stack. |
| 4176 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4177 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4178 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4179 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 4180 | struct page **pages, unsigned int *pgbase) |
| 4181 | { |
| 4182 | struct page *newpage, **spages; |
| 4183 | int rc = 0; |
| 4184 | size_t len; |
| 4185 | spages = pages; |
| 4186 | |
| 4187 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4188 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4189 | newpage = alloc_page(GFP_KERNEL); |
| 4190 | |
| 4191 | if (newpage == NULL) |
| 4192 | goto unwind; |
| 4193 | memcpy(page_address(newpage), buf, len); |
| 4194 | buf += len; |
| 4195 | buflen -= len; |
| 4196 | *pages++ = newpage; |
| 4197 | rc++; |
| 4198 | } while (buflen != 0); |
| 4199 | |
| 4200 | return rc; |
| 4201 | |
| 4202 | unwind: |
| 4203 | for(; rc > 0; rc--) |
| 4204 | __free_page(spages[rc-1]); |
| 4205 | return -ENOMEM; |
| 4206 | } |
| 4207 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4208 | struct nfs4_cached_acl { |
| 4209 | int cached; |
| 4210 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4211 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4212 | }; |
| 4213 | |
| 4214 | 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] | 4215 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4216 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4217 | |
| 4218 | spin_lock(&inode->i_lock); |
| 4219 | kfree(nfsi->nfs4_acl); |
| 4220 | nfsi->nfs4_acl = acl; |
| 4221 | spin_unlock(&inode->i_lock); |
| 4222 | } |
| 4223 | |
| 4224 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4225 | { |
| 4226 | nfs4_set_cached_acl(inode, NULL); |
| 4227 | } |
| 4228 | |
| 4229 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4230 | { |
| 4231 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4232 | struct nfs4_cached_acl *acl; |
| 4233 | int ret = -ENOENT; |
| 4234 | |
| 4235 | spin_lock(&inode->i_lock); |
| 4236 | acl = nfsi->nfs4_acl; |
| 4237 | if (acl == NULL) |
| 4238 | goto out; |
| 4239 | if (buf == NULL) /* user is just asking for length */ |
| 4240 | goto out_len; |
| 4241 | if (acl->cached == 0) |
| 4242 | goto out; |
| 4243 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4244 | if (acl->len > buflen) |
| 4245 | goto out; |
| 4246 | memcpy(buf, acl->data, acl->len); |
| 4247 | out_len: |
| 4248 | ret = acl->len; |
| 4249 | out: |
| 4250 | spin_unlock(&inode->i_lock); |
| 4251 | return ret; |
| 4252 | } |
| 4253 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4254 | 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] | 4255 | { |
| 4256 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4257 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4258 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4259 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4260 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4261 | if (acl == NULL) |
| 4262 | goto out; |
| 4263 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4264 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4265 | } else { |
| 4266 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4267 | if (acl == NULL) |
| 4268 | goto out; |
| 4269 | acl->cached = 0; |
| 4270 | } |
| 4271 | acl->len = acl_len; |
| 4272 | out: |
| 4273 | nfs4_set_cached_acl(inode, acl); |
| 4274 | } |
| 4275 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4276 | /* |
| 4277 | * The getxattr API returns the required buffer length when called with a |
| 4278 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4279 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4280 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4281 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4282 | * the cache. If not so, we throw away the page, and cache the required |
| 4283 | * length. The next getxattr call will then produce another round trip to |
| 4284 | * the server, this time with the input buf of the required size. |
| 4285 | */ |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4286 | 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] | 4287 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4288 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4289 | struct nfs_getaclargs args = { |
| 4290 | .fh = NFS_FH(inode), |
| 4291 | .acl_pages = pages, |
| 4292 | .acl_len = buflen, |
| 4293 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4294 | struct nfs_getaclres res = { |
| 4295 | .acl_len = buflen, |
| 4296 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4297 | struct rpc_message msg = { |
| 4298 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4299 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4300 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4301 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4302 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4303 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4304 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4305 | /* As long as we're doing a round trip to the server anyway, |
| 4306 | * let's be prepared for a page of acl data. */ |
| 4307 | if (npages == 0) |
| 4308 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4309 | if (npages > ARRAY_SIZE(pages)) |
| 4310 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4311 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4312 | for (i = 0; i < npages; i++) { |
| 4313 | pages[i] = alloc_page(GFP_KERNEL); |
| 4314 | if (!pages[i]) |
| 4315 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4316 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4317 | |
| 4318 | /* for decoding across pages */ |
| 4319 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4320 | if (!res.acl_scratch) |
| 4321 | goto out_free; |
| 4322 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4323 | args.acl_len = npages * PAGE_SIZE; |
| 4324 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4325 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4326 | 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] | 4327 | __func__, buf, buflen, npages, args.acl_len); |
| 4328 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4329 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4330 | if (ret) |
| 4331 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4332 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4333 | /* Handle the case where the passed-in buffer is too short */ |
| 4334 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4335 | /* Did the user only issue a request for the acl length? */ |
| 4336 | if (buf == NULL) |
| 4337 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4338 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4339 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4340 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4341 | 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] | 4342 | if (buf) { |
| 4343 | if (res.acl_len > buflen) { |
| 4344 | ret = -ERANGE; |
| 4345 | goto out_free; |
| 4346 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4347 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4348 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4349 | out_ok: |
| 4350 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4351 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4352 | for (i = 0; i < npages; i++) |
| 4353 | if (pages[i]) |
| 4354 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4355 | if (res.acl_scratch) |
| 4356 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4357 | return ret; |
| 4358 | } |
| 4359 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4360 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4361 | { |
| 4362 | struct nfs4_exception exception = { }; |
| 4363 | ssize_t ret; |
| 4364 | do { |
| 4365 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4366 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4367 | if (ret >= 0) |
| 4368 | break; |
| 4369 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4370 | } while (exception.retry); |
| 4371 | return ret; |
| 4372 | } |
| 4373 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4374 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4375 | { |
| 4376 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4377 | int ret; |
| 4378 | |
| 4379 | if (!nfs4_server_supports_acls(server)) |
| 4380 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4381 | ret = nfs_revalidate_inode(server, inode); |
| 4382 | if (ret < 0) |
| 4383 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4384 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4385 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4386 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4387 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4388 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4389 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4390 | return ret; |
| 4391 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4392 | } |
| 4393 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4394 | 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] | 4395 | { |
| 4396 | struct nfs_server *server = NFS_SERVER(inode); |
| 4397 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4398 | struct nfs_setaclargs arg = { |
| 4399 | .fh = NFS_FH(inode), |
| 4400 | .acl_pages = pages, |
| 4401 | .acl_len = buflen, |
| 4402 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4403 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4404 | struct rpc_message msg = { |
| 4405 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4406 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4407 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4408 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4409 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4410 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4411 | |
| 4412 | if (!nfs4_server_supports_acls(server)) |
| 4413 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4414 | if (npages > ARRAY_SIZE(pages)) |
| 4415 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4416 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4417 | if (i < 0) |
| 4418 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4419 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4420 | 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] | 4421 | |
| 4422 | /* |
| 4423 | * Free each page after tx, so the only ref left is |
| 4424 | * held by the network stack |
| 4425 | */ |
| 4426 | for (; i > 0; i--) |
| 4427 | put_page(pages[i-1]); |
| 4428 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4429 | /* |
| 4430 | * Acl update can result in inode attribute update. |
| 4431 | * so mark the attribute cache invalid. |
| 4432 | */ |
| 4433 | spin_lock(&inode->i_lock); |
| 4434 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4435 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4436 | nfs_access_zap_cache(inode); |
| 4437 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4438 | return ret; |
| 4439 | } |
| 4440 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4441 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4442 | { |
| 4443 | struct nfs4_exception exception = { }; |
| 4444 | int err; |
| 4445 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4446 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 4447 | trace_nfs4_set_acl(inode, err); |
| 4448 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4449 | &exception); |
| 4450 | } while (exception.retry); |
| 4451 | return err; |
| 4452 | } |
| 4453 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4454 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 4455 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 4456 | size_t buflen) |
| 4457 | { |
| 4458 | struct nfs_server *server = NFS_SERVER(inode); |
| 4459 | struct nfs_fattr fattr; |
| 4460 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 4461 | |
| 4462 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
| 4463 | struct nfs4_getattr_arg args = { |
| 4464 | .fh = NFS_FH(inode), |
| 4465 | .bitmask = bitmask, |
| 4466 | }; |
| 4467 | struct nfs4_getattr_res res = { |
| 4468 | .fattr = &fattr, |
| 4469 | .label = &label, |
| 4470 | .server = server, |
| 4471 | }; |
| 4472 | struct rpc_message msg = { |
| 4473 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 4474 | .rpc_argp = &args, |
| 4475 | .rpc_resp = &res, |
| 4476 | }; |
| 4477 | int ret; |
| 4478 | |
| 4479 | nfs_fattr_init(&fattr); |
| 4480 | |
| 4481 | ret = rpc_call_sync(server->client, &msg, 0); |
| 4482 | if (ret) |
| 4483 | return ret; |
| 4484 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 4485 | return -ENOENT; |
| 4486 | if (buflen < label.len) |
| 4487 | return -ERANGE; |
| 4488 | return 0; |
| 4489 | } |
| 4490 | |
| 4491 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 4492 | size_t buflen) |
| 4493 | { |
| 4494 | struct nfs4_exception exception = { }; |
| 4495 | int err; |
| 4496 | |
| 4497 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4498 | return -EOPNOTSUPP; |
| 4499 | |
| 4500 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4501 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 4502 | trace_nfs4_get_security_label(inode, err); |
| 4503 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4504 | &exception); |
| 4505 | } while (exception.retry); |
| 4506 | return err; |
| 4507 | } |
| 4508 | |
| 4509 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 4510 | struct nfs4_label *ilabel, |
| 4511 | struct nfs_fattr *fattr, |
| 4512 | struct nfs4_label *olabel) |
| 4513 | { |
| 4514 | |
| 4515 | struct iattr sattr = {0}; |
| 4516 | struct nfs_server *server = NFS_SERVER(inode); |
| 4517 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
| 4518 | struct nfs_setattrargs args = { |
| 4519 | .fh = NFS_FH(inode), |
| 4520 | .iap = &sattr, |
| 4521 | .server = server, |
| 4522 | .bitmask = bitmask, |
| 4523 | .label = ilabel, |
| 4524 | }; |
| 4525 | struct nfs_setattrres res = { |
| 4526 | .fattr = fattr, |
| 4527 | .label = olabel, |
| 4528 | .server = server, |
| 4529 | }; |
| 4530 | struct rpc_message msg = { |
| 4531 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 4532 | .rpc_argp = &args, |
| 4533 | .rpc_resp = &res, |
| 4534 | }; |
| 4535 | int status; |
| 4536 | |
| 4537 | nfs4_stateid_copy(&args.stateid, &zero_stateid); |
| 4538 | |
| 4539 | status = rpc_call_sync(server->client, &msg, 0); |
| 4540 | if (status) |
| 4541 | dprintk("%s failed: %d\n", __func__, status); |
| 4542 | |
| 4543 | return status; |
| 4544 | } |
| 4545 | |
| 4546 | static int nfs4_do_set_security_label(struct inode *inode, |
| 4547 | struct nfs4_label *ilabel, |
| 4548 | struct nfs_fattr *fattr, |
| 4549 | struct nfs4_label *olabel) |
| 4550 | { |
| 4551 | struct nfs4_exception exception = { }; |
| 4552 | int err; |
| 4553 | |
| 4554 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4555 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 4556 | fattr, olabel); |
| 4557 | trace_nfs4_set_security_label(inode, err); |
| 4558 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4559 | &exception); |
| 4560 | } while (exception.retry); |
| 4561 | return err; |
| 4562 | } |
| 4563 | |
| 4564 | static int |
| 4565 | nfs4_set_security_label(struct dentry *dentry, const void *buf, size_t buflen) |
| 4566 | { |
| 4567 | struct nfs4_label ilabel, *olabel = NULL; |
| 4568 | struct nfs_fattr fattr; |
| 4569 | struct rpc_cred *cred; |
| 4570 | struct inode *inode = dentry->d_inode; |
| 4571 | int status; |
| 4572 | |
| 4573 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4574 | return -EOPNOTSUPP; |
| 4575 | |
| 4576 | nfs_fattr_init(&fattr); |
| 4577 | |
| 4578 | ilabel.pi = 0; |
| 4579 | ilabel.lfs = 0; |
| 4580 | ilabel.label = (char *)buf; |
| 4581 | ilabel.len = buflen; |
| 4582 | |
| 4583 | cred = rpc_lookup_cred(); |
| 4584 | if (IS_ERR(cred)) |
| 4585 | return PTR_ERR(cred); |
| 4586 | |
| 4587 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 4588 | if (IS_ERR(olabel)) { |
| 4589 | status = -PTR_ERR(olabel); |
| 4590 | goto out; |
| 4591 | } |
| 4592 | |
| 4593 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 4594 | if (status == 0) |
| 4595 | nfs_setsecurity(inode, &fattr, olabel); |
| 4596 | |
| 4597 | nfs4_label_free(olabel); |
| 4598 | out: |
| 4599 | put_rpccred(cred); |
| 4600 | return status; |
| 4601 | } |
| 4602 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 4603 | |
| 4604 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4605 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4606 | 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] | 4607 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4608 | struct nfs_client *clp = server->nfs_client; |
| 4609 | |
| 4610 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4611 | return 0; |
| 4612 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4613 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4614 | case -NFS4ERR_ADMIN_REVOKED: |
| 4615 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 4616 | if (state == NULL) |
| 4617 | break; |
| 4618 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4619 | case -NFS4ERR_OPENMODE: |
| 4620 | if (state == NULL) |
| 4621 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4622 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4623 | goto stateid_invalid; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4624 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4625 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4626 | if (state != NULL) { |
| 4627 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4628 | goto stateid_invalid; |
| 4629 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4630 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4631 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4632 | nfs4_schedule_lease_recovery(clp); |
| 4633 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4634 | #if defined(CONFIG_NFS_V4_1) |
| 4635 | case -NFS4ERR_BADSESSION: |
| 4636 | case -NFS4ERR_BADSLOT: |
| 4637 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4638 | case -NFS4ERR_DEADSESSION: |
| 4639 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4640 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4641 | case -NFS4ERR_SEQ_MISORDERED: |
| 4642 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4643 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4644 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4645 | task->tk_status = 0; |
| 4646 | return -EAGAIN; |
| 4647 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4648 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4649 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4650 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4651 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 4652 | task->tk_status = 0; |
| 4653 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4654 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4655 | case -NFS4ERR_OLD_STATEID: |
| 4656 | task->tk_status = 0; |
| 4657 | return -EAGAIN; |
| 4658 | } |
| 4659 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4660 | return 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4661 | stateid_invalid: |
| 4662 | task->tk_status = -EIO; |
| 4663 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4664 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4665 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4666 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4667 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 4668 | task->tk_status = 0; |
| 4669 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4670 | } |
| 4671 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4672 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4673 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4674 | { |
| 4675 | __be32 verf[2]; |
| 4676 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4677 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4678 | /* An impossible timestamp guarantees this value |
| 4679 | * will never match a generated boot time. */ |
| 4680 | verf[0] = 0; |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 4681 | verf[1] = cpu_to_be32(NSEC_PER_SEC + 1); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4682 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4683 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 4684 | verf[0] = cpu_to_be32(nn->boot_time.tv_sec); |
| 4685 | verf[1] = cpu_to_be32(nn->boot_time.tv_nsec); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4686 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4687 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4688 | } |
| 4689 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4690 | static unsigned int |
| 4691 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4692 | char *buf, size_t len) |
| 4693 | { |
| 4694 | unsigned int result; |
| 4695 | |
| 4696 | rcu_read_lock(); |
| 4697 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4698 | clp->cl_ipaddr, |
| 4699 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4700 | RPC_DISPLAY_ADDR), |
| 4701 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4702 | RPC_DISPLAY_PROTO)); |
| 4703 | rcu_read_unlock(); |
| 4704 | return result; |
| 4705 | } |
| 4706 | |
| 4707 | static unsigned int |
| 4708 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4709 | char *buf, size_t len) |
| 4710 | { |
Trond Myklebust | 55b5929 | 2013-07-24 16:36:35 -0400 | [diff] [blame] | 4711 | const char *nodename = clp->cl_rpcclient->cl_nodename; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4712 | |
| 4713 | if (nfs4_client_id_uniquifier[0] != '\0') |
Trond Myklebust | 55b5929 | 2013-07-24 16:36:35 -0400 | [diff] [blame] | 4714 | return scnprintf(buf, len, "Linux NFSv%u.%u %s/%s", |
| 4715 | clp->rpc_ops->version, |
| 4716 | clp->cl_minorversion, |
| 4717 | nfs4_client_id_uniquifier, |
| 4718 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4719 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4720 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4721 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4722 | } |
| 4723 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4724 | /** |
| 4725 | * nfs4_proc_setclientid - Negotiate client ID |
| 4726 | * @clp: state data structure |
| 4727 | * @program: RPC program for NFSv4 callback service |
| 4728 | * @port: IP port number for NFS4 callback service |
| 4729 | * @cred: RPC credential to use for this call |
| 4730 | * @res: where to place the result |
| 4731 | * |
| 4732 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4733 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4734 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4735 | unsigned short port, struct rpc_cred *cred, |
| 4736 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4737 | { |
| 4738 | nfs4_verifier sc_verifier; |
| 4739 | struct nfs4_setclientid setclientid = { |
| 4740 | .sc_verifier = &sc_verifier, |
| 4741 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4742 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4743 | }; |
| 4744 | struct rpc_message msg = { |
| 4745 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4746 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4747 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4748 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4749 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4750 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4751 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4752 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4753 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4754 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4755 | setclientid.sc_name_len = |
| 4756 | nfs4_init_uniform_client_string(clp, |
| 4757 | setclientid.sc_name, |
| 4758 | sizeof(setclientid.sc_name)); |
| 4759 | else |
| 4760 | setclientid.sc_name_len = |
| 4761 | nfs4_init_nonuniform_client_string(clp, |
| 4762 | setclientid.sc_name, |
| 4763 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4764 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4765 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4766 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Djalal Harouni | fe2d539 | 2013-06-18 17:58:12 +0100 | [diff] [blame] | 4767 | sizeof(setclientid.sc_netid), "%s", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4768 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4769 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4770 | rcu_read_unlock(); |
| 4771 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4772 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4773 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4774 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4775 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4776 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4777 | setclientid.sc_name_len, setclientid.sc_name); |
| 4778 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4779 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4780 | dprintk("NFS reply setclientid: %d\n", status); |
| 4781 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4782 | } |
| 4783 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4784 | /** |
| 4785 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4786 | * @clp: state data structure |
| 4787 | * @res: result of a previous SETCLIENTID |
| 4788 | * @cred: RPC credential to use for this call |
| 4789 | * |
| 4790 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4791 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4792 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4793 | struct nfs4_setclientid_res *arg, |
| 4794 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4795 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4796 | struct rpc_message msg = { |
| 4797 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4798 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4799 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4800 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4801 | int status; |
| 4802 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4803 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4804 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4805 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4806 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4807 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4808 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4809 | return status; |
| 4810 | } |
| 4811 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4812 | struct nfs4_delegreturndata { |
| 4813 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4814 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4815 | struct nfs_fh fh; |
| 4816 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4817 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4818 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4819 | int rpc_status; |
| 4820 | }; |
| 4821 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4822 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4823 | { |
| 4824 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4825 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4826 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4827 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4828 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 4829 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4830 | switch (task->tk_status) { |
| 4831 | case -NFS4ERR_STALE_STATEID: |
| 4832 | case -NFS4ERR_EXPIRED: |
| 4833 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4834 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4835 | break; |
| 4836 | default: |
| 4837 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4838 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4839 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4840 | return; |
| 4841 | } |
| 4842 | } |
| 4843 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4844 | } |
| 4845 | |
| 4846 | static void nfs4_delegreturn_release(void *calldata) |
| 4847 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4848 | kfree(calldata); |
| 4849 | } |
| 4850 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4851 | #if defined(CONFIG_NFS_V4_1) |
| 4852 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4853 | { |
| 4854 | struct nfs4_delegreturndata *d_data; |
| 4855 | |
| 4856 | d_data = (struct nfs4_delegreturndata *)data; |
| 4857 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4858 | nfs4_setup_sequence(d_data->res.server, |
| 4859 | &d_data->args.seq_args, |
| 4860 | &d_data->res.seq_res, |
| 4861 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4862 | } |
| 4863 | #endif /* CONFIG_NFS_V4_1 */ |
| 4864 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4865 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4866 | #if defined(CONFIG_NFS_V4_1) |
| 4867 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4868 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4869 | .rpc_call_done = nfs4_delegreturn_done, |
| 4870 | .rpc_release = nfs4_delegreturn_release, |
| 4871 | }; |
| 4872 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4873 | 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] | 4874 | { |
| 4875 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4876 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4877 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4878 | struct rpc_message msg = { |
| 4879 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4880 | .rpc_cred = cred, |
| 4881 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4882 | struct rpc_task_setup task_setup_data = { |
| 4883 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4884 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4885 | .callback_ops = &nfs4_delegreturn_ops, |
| 4886 | .flags = RPC_TASK_ASYNC, |
| 4887 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4888 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4889 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4890 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4891 | if (data == NULL) |
| 4892 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame^] | 4893 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4894 | data->args.fhandle = &data->fh; |
| 4895 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4896 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4897 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4898 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4899 | data->res.fattr = &data->fattr; |
| 4900 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4901 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4902 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4903 | data->rpc_status = 0; |
| 4904 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4905 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4906 | msg.rpc_argp = &data->args; |
| 4907 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4908 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4909 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4910 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4911 | if (!issync) |
| 4912 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4913 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4914 | if (status != 0) |
| 4915 | goto out; |
| 4916 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4917 | if (status == 0) |
| 4918 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4919 | else |
| 4920 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4921 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4922 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4923 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4924 | } |
| 4925 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4926 | 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] | 4927 | { |
| 4928 | struct nfs_server *server = NFS_SERVER(inode); |
| 4929 | struct nfs4_exception exception = { }; |
| 4930 | int err; |
| 4931 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4932 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 4933 | trace_nfs4_delegreturn(inode, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4934 | switch (err) { |
| 4935 | case -NFS4ERR_STALE_STATEID: |
| 4936 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4937 | case 0: |
| 4938 | return 0; |
| 4939 | } |
| 4940 | err = nfs4_handle_exception(server, err, &exception); |
| 4941 | } while (exception.retry); |
| 4942 | return err; |
| 4943 | } |
| 4944 | |
| 4945 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4946 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4947 | |
| 4948 | /* |
| 4949 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4950 | */ |
| 4951 | static unsigned long |
| 4952 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4953 | { |
Colin Cross | 416ad3c | 2013-05-06 23:50:06 +0000 | [diff] [blame] | 4954 | freezable_schedule_timeout_killable_unsafe(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4955 | timeout <<= 1; |
| 4956 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4957 | return NFS4_LOCK_MAXTIMEOUT; |
| 4958 | return timeout; |
| 4959 | } |
| 4960 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4961 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4962 | { |
| 4963 | struct inode *inode = state->inode; |
| 4964 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4965 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4966 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4967 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4968 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4969 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4970 | struct nfs_lockt_res res = { |
| 4971 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4972 | }; |
| 4973 | struct rpc_message msg = { |
| 4974 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4975 | .rpc_argp = &arg, |
| 4976 | .rpc_resp = &res, |
| 4977 | .rpc_cred = state->owner->so_cred, |
| 4978 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4979 | struct nfs4_lock_state *lsp; |
| 4980 | int status; |
| 4981 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4982 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4983 | status = nfs4_set_lock_state(state, request); |
| 4984 | if (status != 0) |
| 4985 | goto out; |
| 4986 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4987 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4988 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4989 | 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] | 4990 | switch (status) { |
| 4991 | case 0: |
| 4992 | request->fl_type = F_UNLCK; |
| 4993 | break; |
| 4994 | case -NFS4ERR_DENIED: |
| 4995 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4996 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4997 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4998 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4999 | return status; |
| 5000 | } |
| 5001 | |
| 5002 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5003 | { |
| 5004 | struct nfs4_exception exception = { }; |
| 5005 | int err; |
| 5006 | |
| 5007 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5008 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5009 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5010 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5011 | &exception); |
| 5012 | } while (exception.retry); |
| 5013 | return err; |
| 5014 | } |
| 5015 | |
| 5016 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 5017 | { |
| 5018 | int res = 0; |
| 5019 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 5020 | case FL_POSIX: |
| 5021 | res = posix_lock_file_wait(file, fl); |
| 5022 | break; |
| 5023 | case FL_FLOCK: |
| 5024 | res = flock_lock_file_wait(file, fl); |
| 5025 | break; |
| 5026 | default: |
| 5027 | BUG(); |
| 5028 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5029 | return res; |
| 5030 | } |
| 5031 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5032 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5033 | struct nfs_locku_args arg; |
| 5034 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5035 | struct nfs4_lock_state *lsp; |
| 5036 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5037 | struct file_lock fl; |
| 5038 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5039 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5040 | }; |
| 5041 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5042 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5043 | struct nfs_open_context *ctx, |
| 5044 | struct nfs4_lock_state *lsp, |
| 5045 | struct nfs_seqid *seqid) |
| 5046 | { |
| 5047 | struct nfs4_unlockdata *p; |
| 5048 | struct inode *inode = lsp->ls_state->inode; |
| 5049 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5050 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5051 | if (p == NULL) |
| 5052 | return NULL; |
| 5053 | p->arg.fh = NFS_FH(inode); |
| 5054 | p->arg.fl = &p->fl; |
| 5055 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5056 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5057 | p->arg.stateid = &lsp->ls_stateid; |
| 5058 | p->lsp = lsp; |
| 5059 | atomic_inc(&lsp->ls_count); |
| 5060 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5061 | p->ctx = get_nfs_open_context(ctx); |
| 5062 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5063 | p->server = NFS_SERVER(inode); |
| 5064 | return p; |
| 5065 | } |
| 5066 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5067 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5068 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5069 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5070 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5071 | nfs4_put_lock_state(calldata->lsp); |
| 5072 | put_nfs_open_context(calldata->ctx); |
| 5073 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5074 | } |
| 5075 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5076 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5077 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5078 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5079 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5080 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5081 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5082 | switch (task->tk_status) { |
| 5083 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5084 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 5085 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5086 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5087 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5088 | case -NFS4ERR_BAD_STATEID: |
| 5089 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5090 | case -NFS4ERR_STALE_STATEID: |
| 5091 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5092 | break; |
| 5093 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5094 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5095 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5096 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5097 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5098 | } |
| 5099 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5100 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5101 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5102 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5103 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5104 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5105 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5106 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5107 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5108 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5109 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5110 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5111 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5112 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5113 | &calldata->res.seq_res, |
| 5114 | task) != 0) |
| 5115 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5116 | return; |
| 5117 | out_no_action: |
| 5118 | task->tk_action = NULL; |
| 5119 | out_wait: |
| 5120 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5121 | } |
| 5122 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5123 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5124 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5125 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5126 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5127 | }; |
| 5128 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5129 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5130 | struct nfs_open_context *ctx, |
| 5131 | struct nfs4_lock_state *lsp, |
| 5132 | struct nfs_seqid *seqid) |
| 5133 | { |
| 5134 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5135 | struct rpc_message msg = { |
| 5136 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5137 | .rpc_cred = ctx->cred, |
| 5138 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5139 | struct rpc_task_setup task_setup_data = { |
| 5140 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5141 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5142 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5143 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5144 | .flags = RPC_TASK_ASYNC, |
| 5145 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5146 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5147 | /* Ensure this is an unlock - when canceling a lock, the |
| 5148 | * canceled lock is passed in, and it won't be an unlock. |
| 5149 | */ |
| 5150 | fl->fl_type = F_UNLCK; |
| 5151 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5152 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5153 | if (data == NULL) { |
| 5154 | nfs_free_seqid(seqid); |
| 5155 | return ERR_PTR(-ENOMEM); |
| 5156 | } |
| 5157 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame^] | 5158 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5159 | msg.rpc_argp = &data->arg; |
| 5160 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5161 | task_setup_data.callback_data = data; |
| 5162 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5163 | } |
| 5164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5165 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5166 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5167 | struct inode *inode = state->inode; |
| 5168 | struct nfs4_state_owner *sp = state->owner; |
| 5169 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5170 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5171 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5172 | struct rpc_task *task; |
| 5173 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5174 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5175 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5176 | status = nfs4_set_lock_state(state, request); |
| 5177 | /* Unlock _before_ we do the RPC call */ |
| 5178 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5179 | /* Exclude nfs_delegation_claim_locks() */ |
| 5180 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5181 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5182 | down_read(&nfsi->rwsem); |
| 5183 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 5184 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5185 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5186 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5187 | } |
| 5188 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5189 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5190 | if (status != 0) |
| 5191 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5192 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5193 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5194 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5195 | goto out; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5196 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5197 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5198 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5199 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5200 | 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] | 5201 | status = PTR_ERR(task); |
| 5202 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5203 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5204 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5205 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5206 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5207 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5208 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5209 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5210 | } |
| 5211 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5212 | struct nfs4_lockdata { |
| 5213 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5214 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5215 | struct nfs4_lock_state *lsp; |
| 5216 | struct nfs_open_context *ctx; |
| 5217 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5218 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5219 | int rpc_status; |
| 5220 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5221 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5222 | }; |
| 5223 | |
| 5224 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5225 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5226 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5227 | { |
| 5228 | struct nfs4_lockdata *p; |
| 5229 | struct inode *inode = lsp->ls_state->inode; |
| 5230 | struct nfs_server *server = NFS_SERVER(inode); |
| 5231 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5232 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5233 | if (p == NULL) |
| 5234 | return NULL; |
| 5235 | |
| 5236 | p->arg.fh = NFS_FH(inode); |
| 5237 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5238 | 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] | 5239 | if (p->arg.open_seqid == NULL) |
| 5240 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5241 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5242 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5243 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5244 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5245 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5246 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5247 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5248 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5249 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5250 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5251 | atomic_inc(&lsp->ls_count); |
| 5252 | p->ctx = get_nfs_open_context(ctx); |
| 5253 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5254 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5255 | out_free_seqid: |
| 5256 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5257 | out_free: |
| 5258 | kfree(p); |
| 5259 | return NULL; |
| 5260 | } |
| 5261 | |
| 5262 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 5263 | { |
| 5264 | struct nfs4_lockdata *data = calldata; |
| 5265 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5266 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5267 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5268 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5269 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5270 | /* Do we need to do an open_to_lock_owner? */ |
| 5271 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5272 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5273 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5274 | } |
Trond Myklebust | 8e472f3 | 2013-04-20 01:30:53 -0400 | [diff] [blame] | 5275 | data->arg.open_stateid = &state->open_stateid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5276 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5277 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5278 | } else |
| 5279 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5280 | if (!nfs4_valid_open_stateid(state)) { |
| 5281 | data->rpc_status = -EBADF; |
| 5282 | task->tk_action = NULL; |
| 5283 | goto out_release_open_seqid; |
| 5284 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5285 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5286 | if (nfs4_setup_sequence(data->server, |
| 5287 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5288 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5289 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5290 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5291 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5292 | nfs_release_seqid(data->arg.open_seqid); |
| 5293 | out_release_lock_seqid: |
| 5294 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5295 | out_wait: |
| 5296 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5297 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5298 | } |
| 5299 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5300 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 5301 | { |
| 5302 | struct nfs4_lockdata *data = calldata; |
| 5303 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5304 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5305 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5306 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5307 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5308 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5309 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5310 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5311 | if (data->rpc_status == 0) |
| 5312 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 5313 | else |
| 5314 | goto out; |
| 5315 | } |
| 5316 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5317 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5318 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 5319 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5320 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5321 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5322 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5323 | } |
| 5324 | |
| 5325 | static void nfs4_lock_release(void *calldata) |
| 5326 | { |
| 5327 | struct nfs4_lockdata *data = calldata; |
| 5328 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5329 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5330 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5331 | if (data->cancelled != 0) { |
| 5332 | struct rpc_task *task; |
| 5333 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 5334 | data->arg.lock_seqid); |
| 5335 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5336 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5337 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5338 | } else |
| 5339 | nfs_free_seqid(data->arg.lock_seqid); |
| 5340 | nfs4_put_lock_state(data->lsp); |
| 5341 | put_nfs_open_context(data->ctx); |
| 5342 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5343 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5344 | } |
| 5345 | |
| 5346 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 5347 | .rpc_call_prepare = nfs4_lock_prepare, |
| 5348 | .rpc_call_done = nfs4_lock_done, |
| 5349 | .rpc_release = nfs4_lock_release, |
| 5350 | }; |
| 5351 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5352 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 5353 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5354 | switch (error) { |
| 5355 | case -NFS4ERR_ADMIN_REVOKED: |
| 5356 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5357 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5358 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5359 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5360 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5361 | break; |
| 5362 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5363 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5364 | case -NFS4ERR_EXPIRED: |
| 5365 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5366 | }; |
| 5367 | } |
| 5368 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5369 | 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] | 5370 | { |
| 5371 | struct nfs4_lockdata *data; |
| 5372 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5373 | struct rpc_message msg = { |
| 5374 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 5375 | .rpc_cred = state->owner->so_cred, |
| 5376 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5377 | struct rpc_task_setup task_setup_data = { |
| 5378 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5379 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5380 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5381 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5382 | .flags = RPC_TASK_ASYNC, |
| 5383 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5384 | int ret; |
| 5385 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5386 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5387 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5388 | fl->fl_u.nfs4_fl.owner, |
| 5389 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5390 | if (data == NULL) |
| 5391 | return -ENOMEM; |
| 5392 | if (IS_SETLKW(cmd)) |
| 5393 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame^] | 5394 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5395 | msg.rpc_argp = &data->arg; |
| 5396 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5397 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5398 | if (recovery_type > NFS_LOCK_NEW) { |
| 5399 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 5400 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 5401 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
| 5402 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5403 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5404 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5405 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5406 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 5407 | if (ret == 0) { |
| 5408 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5409 | if (ret) |
| 5410 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 5411 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5412 | } else |
| 5413 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5414 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5415 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5416 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5417 | } |
| 5418 | |
| 5419 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 5420 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5421 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5422 | struct nfs4_exception exception = { |
| 5423 | .inode = state->inode, |
| 5424 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5425 | int err; |
| 5426 | |
| 5427 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5428 | /* Cache the lock if possible... */ |
| 5429 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5430 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5431 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5432 | trace_nfs4_lock_reclaim(request, state, F_SETLK, err); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5433 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5434 | break; |
| 5435 | nfs4_handle_exception(server, err, &exception); |
| 5436 | } while (exception.retry); |
| 5437 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5438 | } |
| 5439 | |
| 5440 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5441 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5442 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5443 | struct nfs4_exception exception = { |
| 5444 | .inode = state->inode, |
| 5445 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5446 | int err; |
| 5447 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5448 | err = nfs4_set_lock_state(state, request); |
| 5449 | if (err != 0) |
| 5450 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5451 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5452 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5453 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5454 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5455 | trace_nfs4_lock_expired(request, state, F_SETLK, err); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5456 | switch (err) { |
| 5457 | default: |
| 5458 | goto out; |
| 5459 | case -NFS4ERR_GRACE: |
| 5460 | case -NFS4ERR_DELAY: |
| 5461 | nfs4_handle_exception(server, err, &exception); |
| 5462 | err = 0; |
| 5463 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5464 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5465 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5466 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5467 | } |
| 5468 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5469 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5470 | /** |
| 5471 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 5472 | * |
| 5473 | * @state: NFSv4 state for an inode |
| 5474 | * |
| 5475 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 5476 | * Otherwise a negative NFS4ERR value is returned. |
| 5477 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5478 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5479 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5480 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5481 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5482 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5483 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5484 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5485 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5486 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 5487 | |
| 5488 | status = nfs41_test_stateid(server, |
| 5489 | &lsp->ls_stateid, |
| 5490 | cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 5491 | trace_nfs4_test_lock_stateid(state, lsp, status); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5492 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5493 | /* Free the stateid unless the server |
| 5494 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 5495 | if (status != -NFS4ERR_BAD_STATEID) |
| 5496 | nfs41_free_stateid(server, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5497 | &lsp->ls_stateid, |
| 5498 | cred); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5499 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5500 | ret = status; |
| 5501 | } |
| 5502 | } |
| 5503 | }; |
| 5504 | |
| 5505 | return ret; |
| 5506 | } |
| 5507 | |
| 5508 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5509 | { |
| 5510 | int status = NFS_OK; |
| 5511 | |
| 5512 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 5513 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5514 | if (status != NFS_OK) |
| 5515 | status = nfs4_lock_expired(state, request); |
| 5516 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5517 | } |
| 5518 | #endif |
| 5519 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5520 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5521 | { |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5522 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5523 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5524 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5525 | unsigned int seq; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5526 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5527 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5528 | if ((fl_flags & FL_POSIX) && |
| 5529 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 5530 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5531 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5532 | status = nfs4_set_lock_state(state, request); |
| 5533 | if (status != 0) |
| 5534 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5535 | request->fl_flags |= FL_ACCESS; |
| 5536 | status = do_vfs_lock(request->fl_file, request); |
| 5537 | if (status < 0) |
| 5538 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5539 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5540 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5541 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5542 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5543 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 5544 | status = do_vfs_lock(request->fl_file, request); |
| 5545 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5546 | } |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5547 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 5548 | up_read(&nfsi->rwsem); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5549 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5550 | if (status != 0) |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5551 | goto out; |
| 5552 | down_read(&nfsi->rwsem); |
| 5553 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { |
| 5554 | status = -NFS4ERR_DELAY; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5555 | goto out_unlock; |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5556 | } |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5557 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5558 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5559 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5560 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 5561 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5562 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5563 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5564 | out: |
| 5565 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5566 | return status; |
| 5567 | } |
| 5568 | |
| 5569 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5570 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5571 | struct nfs4_exception exception = { |
| 5572 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5573 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5574 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5575 | int err; |
| 5576 | |
| 5577 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5578 | err = _nfs4_proc_setlk(state, cmd, request); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5579 | trace_nfs4_set_lock(request, state, cmd, err); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5580 | if (err == -NFS4ERR_DENIED) |
| 5581 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5582 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5583 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5584 | } while (exception.retry); |
| 5585 | return err; |
| 5586 | } |
| 5587 | |
| 5588 | static int |
| 5589 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 5590 | { |
| 5591 | struct nfs_open_context *ctx; |
| 5592 | struct nfs4_state *state; |
| 5593 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 5594 | int status; |
| 5595 | |
| 5596 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5597 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5598 | state = ctx->state; |
| 5599 | |
| 5600 | if (request->fl_start < 0 || request->fl_end < 0) |
| 5601 | return -EINVAL; |
| 5602 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5603 | if (IS_GETLK(cmd)) { |
| 5604 | if (state != NULL) |
| 5605 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 5606 | return 0; |
| 5607 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5608 | |
| 5609 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 5610 | return -EINVAL; |
| 5611 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5612 | if (request->fl_type == F_UNLCK) { |
| 5613 | if (state != NULL) |
| 5614 | return nfs4_proc_unlck(state, cmd, request); |
| 5615 | return 0; |
| 5616 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5617 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5618 | if (state == NULL) |
| 5619 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5620 | /* |
| 5621 | * Don't rely on the VFS having checked the file open mode, |
| 5622 | * since it won't do this for flock() locks. |
| 5623 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5624 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5625 | case F_RDLCK: |
| 5626 | if (!(filp->f_mode & FMODE_READ)) |
| 5627 | return -EBADF; |
| 5628 | break; |
| 5629 | case F_WRLCK: |
| 5630 | if (!(filp->f_mode & FMODE_WRITE)) |
| 5631 | return -EBADF; |
| 5632 | } |
| 5633 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5634 | do { |
| 5635 | status = nfs4_proc_setlk(state, cmd, request); |
| 5636 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 5637 | break; |
| 5638 | timeout = nfs4_set_lock_task_retry(timeout); |
| 5639 | status = -ERESTARTSYS; |
| 5640 | if (signalled()) |
| 5641 | break; |
| 5642 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5643 | return status; |
| 5644 | } |
| 5645 | |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5646 | 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] | 5647 | { |
| 5648 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5649 | int err; |
| 5650 | |
| 5651 | err = nfs4_set_lock_state(state, fl); |
| 5652 | if (err != 0) |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5653 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 5654 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5655 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5656 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5657 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5658 | struct nfs_release_lockowner_data { |
| 5659 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5660 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5661 | struct nfs_release_lockowner_args args; |
| 5662 | }; |
| 5663 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5664 | static void nfs4_release_lockowner_release(void *calldata) |
| 5665 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5666 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5667 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5668 | kfree(calldata); |
| 5669 | } |
| 5670 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5671 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5672 | .rpc_release = nfs4_release_lockowner_release, |
| 5673 | }; |
| 5674 | |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 5675 | 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] | 5676 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5677 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5678 | struct rpc_message msg = { |
| 5679 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5680 | }; |
| 5681 | |
| 5682 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5683 | return -EINVAL; |
| 5684 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5685 | if (!data) |
| 5686 | return -ENOMEM; |
| 5687 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5688 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5689 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5690 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5691 | data->args.lock_owner.s_dev = server->s_dev; |
| 5692 | msg.rpc_argp = &data->args; |
| 5693 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5694 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5695 | } |
| 5696 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5697 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5698 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5699 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5700 | const void *buf, size_t buflen, |
| 5701 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5702 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5703 | if (strcmp(key, "") != 0) |
| 5704 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5705 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5706 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5707 | } |
| 5708 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5709 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5710 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5711 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5712 | if (strcmp(key, "") != 0) |
| 5713 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5714 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5715 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5716 | } |
| 5717 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5718 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5719 | size_t list_len, const char *name, |
| 5720 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5721 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5722 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5723 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5724 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5725 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5726 | |
| 5727 | if (list && len <= list_len) |
| 5728 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5729 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5730 | } |
| 5731 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 5732 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5733 | static inline int nfs4_server_supports_labels(struct nfs_server *server) |
| 5734 | { |
| 5735 | return server->caps & NFS_CAP_SECURITY_LABEL; |
| 5736 | } |
| 5737 | |
| 5738 | static int nfs4_xattr_set_nfs4_label(struct dentry *dentry, const char *key, |
| 5739 | const void *buf, size_t buflen, |
| 5740 | int flags, int type) |
| 5741 | { |
| 5742 | if (security_ismaclabel(key)) |
| 5743 | return nfs4_set_security_label(dentry, buf, buflen); |
| 5744 | |
| 5745 | return -EOPNOTSUPP; |
| 5746 | } |
| 5747 | |
| 5748 | static int nfs4_xattr_get_nfs4_label(struct dentry *dentry, const char *key, |
| 5749 | void *buf, size_t buflen, int type) |
| 5750 | { |
| 5751 | if (security_ismaclabel(key)) |
| 5752 | return nfs4_get_security_label(dentry->d_inode, buf, buflen); |
| 5753 | return -EOPNOTSUPP; |
| 5754 | } |
| 5755 | |
| 5756 | static size_t nfs4_xattr_list_nfs4_label(struct dentry *dentry, char *list, |
| 5757 | size_t list_len, const char *name, |
| 5758 | size_t name_len, int type) |
| 5759 | { |
| 5760 | size_t len = 0; |
| 5761 | |
| 5762 | if (nfs_server_capable(dentry->d_inode, NFS_CAP_SECURITY_LABEL)) { |
| 5763 | len = security_inode_listsecurity(dentry->d_inode, NULL, 0); |
| 5764 | if (list && len <= list_len) |
| 5765 | security_inode_listsecurity(dentry->d_inode, list, len); |
| 5766 | } |
| 5767 | return len; |
| 5768 | } |
| 5769 | |
| 5770 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 5771 | .prefix = XATTR_SECURITY_PREFIX, |
| 5772 | .list = nfs4_xattr_list_nfs4_label, |
| 5773 | .get = nfs4_xattr_get_nfs4_label, |
| 5774 | .set = nfs4_xattr_set_nfs4_label, |
| 5775 | }; |
| 5776 | #endif |
| 5777 | |
| 5778 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5779 | /* |
| 5780 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5781 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5782 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5783 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5784 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5785 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5786 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5787 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5788 | return; |
| 5789 | |
| 5790 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5791 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5792 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5793 | fattr->nlink = 2; |
| 5794 | } |
| 5795 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5796 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5797 | const struct qstr *name, |
| 5798 | struct nfs4_fs_locations *fs_locations, |
| 5799 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5800 | { |
| 5801 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 5802 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5803 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5804 | }; |
| 5805 | struct nfs4_fs_locations_arg args = { |
| 5806 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5807 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5808 | .page = page, |
| 5809 | .bitmask = bitmask, |
| 5810 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5811 | struct nfs4_fs_locations_res res = { |
| 5812 | .fs_locations = fs_locations, |
| 5813 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5814 | struct rpc_message msg = { |
| 5815 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5816 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5817 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5818 | }; |
| 5819 | int status; |
| 5820 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5821 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5822 | |
| 5823 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5824 | * is not supported */ |
| 5825 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5826 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5827 | else |
| 5828 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5829 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5830 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5831 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5832 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5833 | 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] | 5834 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5835 | return status; |
| 5836 | } |
| 5837 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5838 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5839 | const struct qstr *name, |
| 5840 | struct nfs4_fs_locations *fs_locations, |
| 5841 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5842 | { |
| 5843 | struct nfs4_exception exception = { }; |
| 5844 | int err; |
| 5845 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 5846 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 5847 | fs_locations, page); |
| 5848 | trace_nfs4_get_fs_locations(dir, name, err); |
| 5849 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5850 | &exception); |
| 5851 | } while (exception.retry); |
| 5852 | return err; |
| 5853 | } |
| 5854 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 5855 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 5856 | * If 'use_integrity' is true and the state managment nfs_client |
| 5857 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 5858 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 5859 | * Considerations sections. Otherwise, just use the user cred with the |
| 5860 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 5861 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 5862 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5863 | { |
| 5864 | int status; |
| 5865 | struct nfs4_secinfo_arg args = { |
| 5866 | .dir_fh = NFS_FH(dir), |
| 5867 | .name = name, |
| 5868 | }; |
| 5869 | struct nfs4_secinfo_res res = { |
| 5870 | .flavors = flavors, |
| 5871 | }; |
| 5872 | struct rpc_message msg = { |
| 5873 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5874 | .rpc_argp = &args, |
| 5875 | .rpc_resp = &res, |
| 5876 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 5877 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
| 5878 | |
| 5879 | if (use_integrity) { |
| 5880 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
| 5881 | msg.rpc_cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 5882 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5883 | |
| 5884 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 5885 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 5886 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5887 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 5888 | |
| 5889 | if (msg.rpc_cred) |
| 5890 | put_rpccred(msg.rpc_cred); |
| 5891 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5892 | return status; |
| 5893 | } |
| 5894 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5895 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5896 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5897 | { |
| 5898 | struct nfs4_exception exception = { }; |
| 5899 | int err; |
| 5900 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 5901 | err = -NFS4ERR_WRONGSEC; |
| 5902 | |
| 5903 | /* try to use integrity protection with machine cred */ |
| 5904 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 5905 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 5906 | |
| 5907 | /* |
| 5908 | * if unable to use integrity protection, or SECINFO with |
| 5909 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 5910 | * disallowed by spec, but exists in deployed servers) use |
| 5911 | * the current filesystem's rpc_client and the user cred. |
| 5912 | */ |
| 5913 | if (err == -NFS4ERR_WRONGSEC) |
| 5914 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 5915 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 5916 | trace_nfs4_secinfo(dir, name, err); |
| 5917 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5918 | &exception); |
| 5919 | } while (exception.retry); |
| 5920 | return err; |
| 5921 | } |
| 5922 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5923 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5924 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5925 | * Check the exchange flags returned by the server for invalid flags, having |
| 5926 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5927 | * DS flags set. |
| 5928 | */ |
| 5929 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5930 | { |
| 5931 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5932 | goto out_inval; |
| 5933 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5934 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5935 | goto out_inval; |
| 5936 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5937 | goto out_inval; |
| 5938 | return NFS_OK; |
| 5939 | out_inval: |
| 5940 | return -NFS4ERR_INVAL; |
| 5941 | } |
| 5942 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5943 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5944 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5945 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5946 | { |
| 5947 | if (a->server_scope_sz == b->server_scope_sz && |
| 5948 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5949 | return true; |
| 5950 | |
| 5951 | return false; |
| 5952 | } |
| 5953 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5954 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5955 | * nfs4_proc_bind_conn_to_session() |
| 5956 | * |
| 5957 | * The 4.1 client currently uses the same TCP connection for the |
| 5958 | * fore and backchannel. |
| 5959 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5960 | 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] | 5961 | { |
| 5962 | int status; |
| 5963 | struct nfs41_bind_conn_to_session_res res; |
| 5964 | struct rpc_message msg = { |
| 5965 | .rpc_proc = |
| 5966 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5967 | .rpc_argp = clp, |
| 5968 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5969 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5970 | }; |
| 5971 | |
| 5972 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5973 | |
| 5974 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5975 | if (unlikely(res.session == NULL)) { |
| 5976 | status = -ENOMEM; |
| 5977 | goto out; |
| 5978 | } |
| 5979 | |
| 5980 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5981 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5982 | if (status == 0) { |
| 5983 | if (memcmp(res.session->sess_id.data, |
| 5984 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5985 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5986 | status = -EIO; |
| 5987 | goto out_session; |
| 5988 | } |
| 5989 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5990 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5991 | __func__); |
| 5992 | status = -EIO; |
| 5993 | goto out_session; |
| 5994 | } |
| 5995 | if (res.use_conn_in_rdma_mode) { |
| 5996 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5997 | __func__); |
| 5998 | status = -EIO; |
| 5999 | goto out_session; |
| 6000 | } |
| 6001 | } |
| 6002 | out_session: |
| 6003 | kfree(res.session); |
| 6004 | out: |
| 6005 | dprintk("<-- %s status= %d\n", __func__, status); |
| 6006 | return status; |
| 6007 | } |
| 6008 | |
| 6009 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6010 | * nfs4_proc_exchange_id() |
| 6011 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6012 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6013 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6014 | * Since the clientid has expired, all compounds using sessions |
| 6015 | * associated with the stale clientid will be returning |
| 6016 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 6017 | * be in some phase of session reset. |
| 6018 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6019 | 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] | 6020 | { |
| 6021 | nfs4_verifier verifier; |
| 6022 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 6023 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6024 | .client = clp, |
Trond Myklebust | 4f0b429 | 2013-05-20 12:24:03 -0400 | [diff] [blame] | 6025 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 6026 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6027 | }; |
| 6028 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6029 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6030 | }; |
| 6031 | int status; |
| 6032 | struct rpc_message msg = { |
| 6033 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 6034 | .rpc_argp = &args, |
| 6035 | .rpc_resp = &res, |
| 6036 | .rpc_cred = cred, |
| 6037 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6038 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6039 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6040 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 6041 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6042 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 6043 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 6044 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6045 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6046 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6047 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6048 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6049 | status = -ENOMEM; |
| 6050 | goto out; |
| 6051 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6052 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6053 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6054 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6055 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6056 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6057 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6058 | } |
| 6059 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6060 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6061 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6062 | status = -ENOMEM; |
| 6063 | goto out_server_scope; |
| 6064 | } |
| 6065 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6066 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6067 | trace_nfs4_exchange_id(clp, status); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6068 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6069 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6070 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6071 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6072 | clp->cl_clientid = res.clientid; |
| 6073 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 6074 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 6075 | clp->cl_seqid = res.seqid; |
| 6076 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6077 | kfree(clp->cl_serverowner); |
| 6078 | clp->cl_serverowner = res.server_owner; |
| 6079 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6080 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6081 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 6082 | kfree(clp->cl_implid); |
| 6083 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6084 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6085 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6086 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6087 | res.server_scope)) { |
| 6088 | dprintk("%s: server_scope mismatch detected\n", |
| 6089 | __func__); |
| 6090 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6091 | kfree(clp->cl_serverscope); |
| 6092 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6093 | } |
| 6094 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6095 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6096 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6097 | goto out; |
| 6098 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6099 | } else |
| 6100 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6101 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6102 | out_server_owner: |
| 6103 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6104 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6105 | kfree(res.server_scope); |
| 6106 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6107 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6108 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6109 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6110 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 6111 | clp->cl_implid->date.seconds, |
| 6112 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6113 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6114 | return status; |
| 6115 | } |
| 6116 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6117 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 6118 | struct rpc_cred *cred) |
| 6119 | { |
| 6120 | struct rpc_message msg = { |
| 6121 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 6122 | .rpc_argp = clp, |
| 6123 | .rpc_cred = cred, |
| 6124 | }; |
| 6125 | int status; |
| 6126 | |
| 6127 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6128 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6129 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 6130 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6131 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 6132 | return status; |
| 6133 | } |
| 6134 | |
| 6135 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 6136 | struct rpc_cred *cred) |
| 6137 | { |
| 6138 | unsigned int loop; |
| 6139 | int ret; |
| 6140 | |
| 6141 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 6142 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 6143 | switch (ret) { |
| 6144 | case -NFS4ERR_DELAY: |
| 6145 | case -NFS4ERR_CLIENTID_BUSY: |
| 6146 | ssleep(1); |
| 6147 | break; |
| 6148 | default: |
| 6149 | return ret; |
| 6150 | } |
| 6151 | } |
| 6152 | return 0; |
| 6153 | } |
| 6154 | |
| 6155 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 6156 | { |
| 6157 | struct rpc_cred *cred; |
| 6158 | int ret = 0; |
| 6159 | |
| 6160 | if (clp->cl_mvops->minor_version < 1) |
| 6161 | goto out; |
| 6162 | if (clp->cl_exchange_flags == 0) |
| 6163 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6164 | if (clp->cl_preserve_clid) |
| 6165 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 6166 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6167 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 6168 | if (cred) |
| 6169 | put_rpccred(cred); |
| 6170 | switch (ret) { |
| 6171 | case 0: |
| 6172 | case -NFS4ERR_STALE_CLIENTID: |
| 6173 | clp->cl_exchange_flags = 0; |
| 6174 | } |
| 6175 | out: |
| 6176 | return ret; |
| 6177 | } |
| 6178 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6179 | struct nfs4_get_lease_time_data { |
| 6180 | struct nfs4_get_lease_time_args *args; |
| 6181 | struct nfs4_get_lease_time_res *res; |
| 6182 | struct nfs_client *clp; |
| 6183 | }; |
| 6184 | |
| 6185 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 6186 | void *calldata) |
| 6187 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6188 | struct nfs4_get_lease_time_data *data = |
| 6189 | (struct nfs4_get_lease_time_data *)calldata; |
| 6190 | |
| 6191 | dprintk("--> %s\n", __func__); |
| 6192 | /* just setup sequence, do not trigger session recovery |
| 6193 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6194 | nfs41_setup_sequence(data->clp->cl_session, |
| 6195 | &data->args->la_seq_args, |
| 6196 | &data->res->lr_seq_res, |
| 6197 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6198 | dprintk("<-- %s\n", __func__); |
| 6199 | } |
| 6200 | |
| 6201 | /* |
| 6202 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 6203 | * from sequence operation or clientid errors. |
| 6204 | */ |
| 6205 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 6206 | { |
| 6207 | struct nfs4_get_lease_time_data *data = |
| 6208 | (struct nfs4_get_lease_time_data *)calldata; |
| 6209 | |
| 6210 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6211 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 6212 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6213 | switch (task->tk_status) { |
| 6214 | case -NFS4ERR_DELAY: |
| 6215 | case -NFS4ERR_GRACE: |
| 6216 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 6217 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 6218 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6219 | /* fall through */ |
| 6220 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6221 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6222 | return; |
| 6223 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6224 | dprintk("<-- %s\n", __func__); |
| 6225 | } |
| 6226 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6227 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6228 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 6229 | .rpc_call_done = nfs4_get_lease_time_done, |
| 6230 | }; |
| 6231 | |
| 6232 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 6233 | { |
| 6234 | struct rpc_task *task; |
| 6235 | struct nfs4_get_lease_time_args args; |
| 6236 | struct nfs4_get_lease_time_res res = { |
| 6237 | .lr_fsinfo = fsinfo, |
| 6238 | }; |
| 6239 | struct nfs4_get_lease_time_data data = { |
| 6240 | .args = &args, |
| 6241 | .res = &res, |
| 6242 | .clp = clp, |
| 6243 | }; |
| 6244 | struct rpc_message msg = { |
| 6245 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 6246 | .rpc_argp = &args, |
| 6247 | .rpc_resp = &res, |
| 6248 | }; |
| 6249 | struct rpc_task_setup task_setup = { |
| 6250 | .rpc_client = clp->cl_rpcclient, |
| 6251 | .rpc_message = &msg, |
| 6252 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6253 | .callback_data = &data, |
| 6254 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6255 | }; |
| 6256 | int status; |
| 6257 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame^] | 6258 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6259 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6260 | dprintk("--> %s\n", __func__); |
| 6261 | task = rpc_run_task(&task_setup); |
| 6262 | |
| 6263 | if (IS_ERR(task)) |
| 6264 | status = PTR_ERR(task); |
| 6265 | else { |
| 6266 | status = task->tk_status; |
| 6267 | rpc_put_task(task); |
| 6268 | } |
| 6269 | dprintk("<-- %s return %d\n", __func__, status); |
| 6270 | |
| 6271 | return status; |
| 6272 | } |
| 6273 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6274 | /* |
| 6275 | * Initialize the values to be used by the client in CREATE_SESSION |
| 6276 | * If nfs4_init_session set the fore channel request and response sizes, |
| 6277 | * use them. |
| 6278 | * |
| 6279 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 6280 | * always set csa_cachethis to FALSE because the current implementation |
| 6281 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 6282 | */ |
| 6283 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 6284 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 6285 | unsigned int max_rqst_sz, max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6286 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 6287 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 6288 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 6289 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6290 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 6291 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 6292 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6293 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 6294 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6295 | |
| 6296 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 6297 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6298 | __func__, |
| 6299 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 6300 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6301 | |
| 6302 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6303 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 6304 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 6305 | args->bc_attrs.max_resp_sz_cached = 0; |
| 6306 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 6307 | args->bc_attrs.max_reqs = 1; |
| 6308 | |
| 6309 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 6310 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 6311 | __func__, |
| 6312 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 6313 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 6314 | args->bc_attrs.max_reqs); |
| 6315 | } |
| 6316 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6317 | 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] | 6318 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6319 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 6320 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 6321 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6322 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 6323 | return -EINVAL; |
| 6324 | /* |
| 6325 | * Our requested max_ops is the minimum we need; we're not |
| 6326 | * prepared to break up compounds into smaller pieces than that. |
| 6327 | * So, no point even trying to continue if the server won't |
| 6328 | * cooperate: |
| 6329 | */ |
| 6330 | if (rcvd->max_ops < sent->max_ops) |
| 6331 | return -EINVAL; |
| 6332 | if (rcvd->max_reqs == 0) |
| 6333 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6334 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 6335 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6336 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6337 | } |
| 6338 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6339 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 6340 | { |
| 6341 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 6342 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6343 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6344 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 6345 | return -EINVAL; |
| 6346 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 6347 | return -EINVAL; |
| 6348 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 6349 | return -EINVAL; |
| 6350 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6351 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6352 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6353 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6354 | return -EINVAL; |
| 6355 | return 0; |
| 6356 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6357 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6358 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 6359 | struct nfs4_session *session) |
| 6360 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6361 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6362 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6363 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 6364 | if (ret) |
| 6365 | return ret; |
| 6366 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6367 | } |
| 6368 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6369 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 6370 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6371 | { |
| 6372 | struct nfs4_session *session = clp->cl_session; |
| 6373 | struct nfs41_create_session_args args = { |
| 6374 | .client = clp, |
| 6375 | .cb_program = NFS4_CALLBACK, |
| 6376 | }; |
| 6377 | struct nfs41_create_session_res res = { |
| 6378 | .client = clp, |
| 6379 | }; |
| 6380 | struct rpc_message msg = { |
| 6381 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 6382 | .rpc_argp = &args, |
| 6383 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6384 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6385 | }; |
| 6386 | int status; |
| 6387 | |
| 6388 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 6389 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6390 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6391 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6392 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6393 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 6394 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6395 | /* Verify the session's negotiated channel_attrs values */ |
| 6396 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6397 | /* Increment the clientid slot sequence id */ |
| 6398 | clp->cl_seqid++; |
| 6399 | } |
| 6400 | |
| 6401 | return status; |
| 6402 | } |
| 6403 | |
| 6404 | /* |
| 6405 | * Issues a CREATE_SESSION operation to the server. |
| 6406 | * It is the responsibility of the caller to verify the session is |
| 6407 | * expired before calling this routine. |
| 6408 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6409 | 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] | 6410 | { |
| 6411 | int status; |
| 6412 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6413 | struct nfs4_session *session = clp->cl_session; |
| 6414 | |
| 6415 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 6416 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6417 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6418 | if (status) |
| 6419 | goto out; |
| 6420 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 6421 | /* Init or reset the session slot tables */ |
| 6422 | status = nfs4_setup_session_slot_tables(session); |
| 6423 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6424 | if (status) |
| 6425 | goto out; |
| 6426 | |
| 6427 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 6428 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 6429 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6430 | out: |
| 6431 | dprintk("<-- %s\n", __func__); |
| 6432 | return status; |
| 6433 | } |
| 6434 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6435 | /* |
| 6436 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 6437 | * The caller must serialize access to this routine. |
| 6438 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6439 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 6440 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6441 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6442 | struct rpc_message msg = { |
| 6443 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 6444 | .rpc_argp = session, |
| 6445 | .rpc_cred = cred, |
| 6446 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6447 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6448 | |
| 6449 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 6450 | |
| 6451 | /* session is still being setup */ |
| 6452 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 6453 | return status; |
| 6454 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6455 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6456 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6457 | |
| 6458 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 6459 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6460 | "Session has been destroyed regardless...\n", status); |
| 6461 | |
| 6462 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 6463 | return status; |
| 6464 | } |
| 6465 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6466 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6467 | * Renew the cl_session lease. |
| 6468 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6469 | struct nfs4_sequence_data { |
| 6470 | struct nfs_client *clp; |
| 6471 | struct nfs4_sequence_args args; |
| 6472 | struct nfs4_sequence_res res; |
| 6473 | }; |
| 6474 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6475 | static void nfs41_sequence_release(void *data) |
| 6476 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6477 | struct nfs4_sequence_data *calldata = data; |
| 6478 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6479 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6480 | if (atomic_read(&clp->cl_count) > 1) |
| 6481 | nfs4_schedule_state_renewal(clp); |
| 6482 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6483 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6484 | } |
| 6485 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6486 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6487 | { |
| 6488 | switch(task->tk_status) { |
| 6489 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6490 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 6491 | return -EAGAIN; |
| 6492 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6493 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6494 | } |
| 6495 | return 0; |
| 6496 | } |
| 6497 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6498 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6499 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6500 | struct nfs4_sequence_data *calldata = data; |
| 6501 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6502 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6503 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 6504 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6505 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6506 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6507 | if (task->tk_status < 0) { |
| 6508 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6509 | if (atomic_read(&clp->cl_count) == 1) |
| 6510 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6511 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6512 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 6513 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6514 | return; |
| 6515 | } |
| 6516 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6517 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6518 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6519 | dprintk("<-- %s\n", __func__); |
| 6520 | } |
| 6521 | |
| 6522 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 6523 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6524 | struct nfs4_sequence_data *calldata = data; |
| 6525 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6526 | struct nfs4_sequence_args *args; |
| 6527 | struct nfs4_sequence_res *res; |
| 6528 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6529 | args = task->tk_msg.rpc_argp; |
| 6530 | res = task->tk_msg.rpc_resp; |
| 6531 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6532 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6533 | } |
| 6534 | |
| 6535 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 6536 | .rpc_call_done = nfs41_sequence_call_done, |
| 6537 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6538 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6539 | }; |
| 6540 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6541 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 6542 | struct rpc_cred *cred, |
| 6543 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6544 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6545 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6546 | struct rpc_message msg = { |
| 6547 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 6548 | .rpc_cred = cred, |
| 6549 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6550 | struct rpc_task_setup task_setup_data = { |
| 6551 | .rpc_client = clp->cl_rpcclient, |
| 6552 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6553 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 6554 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6555 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6556 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6557 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6558 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 6559 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6560 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6561 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6562 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6563 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame^] | 6564 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6565 | if (is_privileged) |
| 6566 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6567 | msg.rpc_argp = &calldata->args; |
| 6568 | msg.rpc_resp = &calldata->res; |
| 6569 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6570 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6571 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6572 | return rpc_run_task(&task_setup_data); |
| 6573 | } |
| 6574 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6575 | 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] | 6576 | { |
| 6577 | struct rpc_task *task; |
| 6578 | int ret = 0; |
| 6579 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6580 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 6581 | return 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6582 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6583 | if (IS_ERR(task)) |
| 6584 | ret = PTR_ERR(task); |
| 6585 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6586 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6587 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6588 | return ret; |
| 6589 | } |
| 6590 | |
| 6591 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 6592 | { |
| 6593 | struct rpc_task *task; |
| 6594 | int ret; |
| 6595 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6596 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6597 | if (IS_ERR(task)) { |
| 6598 | ret = PTR_ERR(task); |
| 6599 | goto out; |
| 6600 | } |
| 6601 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6602 | if (!ret) { |
| 6603 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 6604 | |
| 6605 | if (task->tk_status == 0) |
| 6606 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6607 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6608 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6609 | rpc_put_task(task); |
| 6610 | out: |
| 6611 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6612 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6613 | } |
| 6614 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6615 | struct nfs4_reclaim_complete_data { |
| 6616 | struct nfs_client *clp; |
| 6617 | struct nfs41_reclaim_complete_args arg; |
| 6618 | struct nfs41_reclaim_complete_res res; |
| 6619 | }; |
| 6620 | |
| 6621 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 6622 | { |
| 6623 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6624 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6625 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 6626 | &calldata->arg.seq_args, |
| 6627 | &calldata->res.seq_res, |
| 6628 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6629 | } |
| 6630 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6631 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6632 | { |
| 6633 | switch(task->tk_status) { |
| 6634 | case 0: |
| 6635 | case -NFS4ERR_COMPLETE_ALREADY: |
| 6636 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 6637 | break; |
| 6638 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6639 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6640 | /* fall through */ |
| 6641 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6642 | return -EAGAIN; |
| 6643 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6644 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6645 | } |
| 6646 | return 0; |
| 6647 | } |
| 6648 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6649 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 6650 | { |
| 6651 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6652 | struct nfs_client *clp = calldata->clp; |
| 6653 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 6654 | |
| 6655 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6656 | if (!nfs41_sequence_done(task, res)) |
| 6657 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6658 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6659 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6660 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 6661 | rpc_restart_call_prepare(task); |
| 6662 | return; |
| 6663 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6664 | dprintk("<-- %s\n", __func__); |
| 6665 | } |
| 6666 | |
| 6667 | static void nfs4_free_reclaim_complete_data(void *data) |
| 6668 | { |
| 6669 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6670 | |
| 6671 | kfree(calldata); |
| 6672 | } |
| 6673 | |
| 6674 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 6675 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 6676 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 6677 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 6678 | }; |
| 6679 | |
| 6680 | /* |
| 6681 | * Issue a global reclaim complete. |
| 6682 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 6683 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 6684 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6685 | { |
| 6686 | struct nfs4_reclaim_complete_data *calldata; |
| 6687 | struct rpc_task *task; |
| 6688 | struct rpc_message msg = { |
| 6689 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 6690 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6691 | }; |
| 6692 | struct rpc_task_setup task_setup_data = { |
| 6693 | .rpc_client = clp->cl_rpcclient, |
| 6694 | .rpc_message = &msg, |
| 6695 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 6696 | .flags = RPC_TASK_ASYNC, |
| 6697 | }; |
| 6698 | int status = -ENOMEM; |
| 6699 | |
| 6700 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6701 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6702 | if (calldata == NULL) |
| 6703 | goto out; |
| 6704 | calldata->clp = clp; |
| 6705 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6706 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame^] | 6707 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6708 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6709 | msg.rpc_argp = &calldata->arg; |
| 6710 | msg.rpc_resp = &calldata->res; |
| 6711 | task_setup_data.callback_data = calldata; |
| 6712 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6713 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6714 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6715 | goto out; |
| 6716 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6717 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6718 | if (status == 0) |
| 6719 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6720 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6721 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6722 | out: |
| 6723 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6724 | return status; |
| 6725 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6726 | |
| 6727 | static void |
| 6728 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6729 | { |
| 6730 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6731 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6732 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6733 | |
| 6734 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6735 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6736 | * right now covering the LAYOUTGET we are about to send. |
| 6737 | * However, that is not so catastrophic, and there seems |
| 6738 | * to be no way to prevent it completely. |
| 6739 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6740 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6741 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6742 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6743 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6744 | NFS_I(lgp->args.inode)->layout, |
| 6745 | lgp->args.ctx->state)) { |
| 6746 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6747 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6748 | } |
| 6749 | |
| 6750 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6751 | { |
| 6752 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6753 | struct inode *inode = lgp->args.inode; |
| 6754 | struct nfs_server *server = NFS_SERVER(inode); |
| 6755 | struct pnfs_layout_hdr *lo; |
| 6756 | struct nfs4_state *state = NULL; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6757 | unsigned long timeo, giveup; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6758 | |
| 6759 | dprintk("--> %s\n", __func__); |
| 6760 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6761 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6762 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6763 | |
| 6764 | switch (task->tk_status) { |
| 6765 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6766 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6767 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6768 | case -NFS4ERR_RECALLCONFLICT: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6769 | timeo = rpc_get_timeout(task->tk_client); |
| 6770 | giveup = lgp->args.timestamp + timeo; |
| 6771 | if (time_after(giveup, jiffies)) |
| 6772 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6773 | break; |
| 6774 | case -NFS4ERR_EXPIRED: |
| 6775 | case -NFS4ERR_BAD_STATEID: |
| 6776 | spin_lock(&inode->i_lock); |
| 6777 | lo = NFS_I(inode)->layout; |
| 6778 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6779 | spin_unlock(&inode->i_lock); |
| 6780 | /* If the open stateid was bad, then recover it. */ |
| 6781 | state = lgp->args.ctx->state; |
| 6782 | } else { |
| 6783 | LIST_HEAD(head); |
| 6784 | |
| 6785 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6786 | spin_unlock(&inode->i_lock); |
| 6787 | /* Mark the bad layout state as invalid, then |
| 6788 | * retry using the open stateid. */ |
| 6789 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6790 | } |
| 6791 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6792 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6793 | rpc_restart_call_prepare(task); |
| 6794 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6795 | dprintk("<-- %s\n", __func__); |
| 6796 | } |
| 6797 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6798 | static size_t max_response_pages(struct nfs_server *server) |
| 6799 | { |
| 6800 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6801 | return nfs_page_array_len(0, max_resp_sz); |
| 6802 | } |
| 6803 | |
| 6804 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6805 | { |
| 6806 | int i; |
| 6807 | |
| 6808 | if (!pages) |
| 6809 | return; |
| 6810 | |
| 6811 | for (i = 0; i < size; i++) { |
| 6812 | if (!pages[i]) |
| 6813 | break; |
| 6814 | __free_page(pages[i]); |
| 6815 | } |
| 6816 | kfree(pages); |
| 6817 | } |
| 6818 | |
| 6819 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6820 | { |
| 6821 | struct page **pages; |
| 6822 | int i; |
| 6823 | |
| 6824 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6825 | if (!pages) { |
| 6826 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6827 | return NULL; |
| 6828 | } |
| 6829 | |
| 6830 | for (i = 0; i < size; i++) { |
| 6831 | pages[i] = alloc_page(gfp_flags); |
| 6832 | if (!pages[i]) { |
| 6833 | dprintk("%s: failed to allocate page\n", __func__); |
| 6834 | nfs4_free_pages(pages, size); |
| 6835 | return NULL; |
| 6836 | } |
| 6837 | } |
| 6838 | |
| 6839 | return pages; |
| 6840 | } |
| 6841 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6842 | static void nfs4_layoutget_release(void *calldata) |
| 6843 | { |
| 6844 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6845 | struct inode *inode = lgp->args.inode; |
| 6846 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6847 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6848 | |
| 6849 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6850 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6851 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6852 | put_nfs_open_context(lgp->args.ctx); |
| 6853 | kfree(calldata); |
| 6854 | dprintk("<-- %s\n", __func__); |
| 6855 | } |
| 6856 | |
| 6857 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6858 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6859 | .rpc_call_done = nfs4_layoutget_done, |
| 6860 | .rpc_release = nfs4_layoutget_release, |
| 6861 | }; |
| 6862 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6863 | struct pnfs_layout_segment * |
| 6864 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6865 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6866 | struct inode *inode = lgp->args.inode; |
| 6867 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6868 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6869 | struct rpc_task *task; |
| 6870 | struct rpc_message msg = { |
| 6871 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6872 | .rpc_argp = &lgp->args, |
| 6873 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 6874 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6875 | }; |
| 6876 | struct rpc_task_setup task_setup_data = { |
| 6877 | .rpc_client = server->client, |
| 6878 | .rpc_message = &msg, |
| 6879 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6880 | .callback_data = lgp, |
| 6881 | .flags = RPC_TASK_ASYNC, |
| 6882 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6883 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6884 | int status = 0; |
| 6885 | |
| 6886 | dprintk("--> %s\n", __func__); |
| 6887 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6888 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6889 | if (!lgp->args.layout.pages) { |
| 6890 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6891 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6892 | } |
| 6893 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6894 | lgp->args.timestamp = jiffies; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6895 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6896 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6897 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame^] | 6898 | nfs4_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6899 | |
| 6900 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 6901 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 6902 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6903 | task = rpc_run_task(&task_setup_data); |
| 6904 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6905 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6906 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6907 | if (status == 0) |
| 6908 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 6909 | trace_nfs4_layoutget(lgp->args.ctx, |
| 6910 | &lgp->args.range, |
| 6911 | &lgp->res.range, |
| 6912 | status); |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 6913 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 6914 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6915 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6916 | rpc_put_task(task); |
| 6917 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6918 | if (status) |
| 6919 | return ERR_PTR(status); |
| 6920 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6921 | } |
| 6922 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6923 | static void |
| 6924 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6925 | { |
| 6926 | struct nfs4_layoutreturn *lrp = calldata; |
| 6927 | |
| 6928 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6929 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 6930 | &lrp->args.seq_args, |
| 6931 | &lrp->res.seq_res, |
| 6932 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6933 | } |
| 6934 | |
| 6935 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6936 | { |
| 6937 | struct nfs4_layoutreturn *lrp = calldata; |
| 6938 | struct nfs_server *server; |
| 6939 | |
| 6940 | dprintk("--> %s\n", __func__); |
| 6941 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6942 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6943 | return; |
| 6944 | |
| 6945 | server = NFS_SERVER(lrp->args.inode); |
| 6946 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6947 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6948 | return; |
| 6949 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6950 | dprintk("<-- %s\n", __func__); |
| 6951 | } |
| 6952 | |
| 6953 | static void nfs4_layoutreturn_release(void *calldata) |
| 6954 | { |
| 6955 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6956 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6957 | |
| 6958 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6959 | spin_lock(&lo->plh_inode->i_lock); |
| 6960 | if (lrp->res.lrs_present) |
| 6961 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6962 | lo->plh_block_lgets--; |
| 6963 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6964 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6965 | kfree(calldata); |
| 6966 | dprintk("<-- %s\n", __func__); |
| 6967 | } |
| 6968 | |
| 6969 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6970 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6971 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6972 | .rpc_release = nfs4_layoutreturn_release, |
| 6973 | }; |
| 6974 | |
| 6975 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6976 | { |
| 6977 | struct rpc_task *task; |
| 6978 | struct rpc_message msg = { |
| 6979 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6980 | .rpc_argp = &lrp->args, |
| 6981 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 6982 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6983 | }; |
| 6984 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 6985 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6986 | .rpc_message = &msg, |
| 6987 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6988 | .callback_data = lrp, |
| 6989 | }; |
| 6990 | int status; |
| 6991 | |
| 6992 | dprintk("--> %s\n", __func__); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame^] | 6993 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6994 | task = rpc_run_task(&task_setup_data); |
| 6995 | if (IS_ERR(task)) |
| 6996 | return PTR_ERR(task); |
| 6997 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 6998 | trace_nfs4_layoutreturn(lrp->args.inode, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6999 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7000 | rpc_put_task(task); |
| 7001 | return status; |
| 7002 | } |
| 7003 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 7004 | /* |
| 7005 | * Retrieve the list of Data Server devices from the MDS. |
| 7006 | */ |
| 7007 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 7008 | const struct nfs_fh *fh, |
| 7009 | struct pnfs_devicelist *devlist) |
| 7010 | { |
| 7011 | struct nfs4_getdevicelist_args args = { |
| 7012 | .fh = fh, |
| 7013 | .layoutclass = server->pnfs_curr_ld->id, |
| 7014 | }; |
| 7015 | struct nfs4_getdevicelist_res res = { |
| 7016 | .devlist = devlist, |
| 7017 | }; |
| 7018 | struct rpc_message msg = { |
| 7019 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 7020 | .rpc_argp = &args, |
| 7021 | .rpc_resp = &res, |
| 7022 | }; |
| 7023 | int status; |
| 7024 | |
| 7025 | dprintk("--> %s\n", __func__); |
| 7026 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 7027 | &res.seq_res, 0); |
| 7028 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7029 | return status; |
| 7030 | } |
| 7031 | |
| 7032 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 7033 | const struct nfs_fh *fh, |
| 7034 | struct pnfs_devicelist *devlist) |
| 7035 | { |
| 7036 | struct nfs4_exception exception = { }; |
| 7037 | int err; |
| 7038 | |
| 7039 | do { |
| 7040 | err = nfs4_handle_exception(server, |
| 7041 | _nfs4_getdevicelist(server, fh, devlist), |
| 7042 | &exception); |
| 7043 | } while (exception.retry); |
| 7044 | |
| 7045 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 7046 | err, devlist->num_devs); |
| 7047 | |
| 7048 | return err; |
| 7049 | } |
| 7050 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 7051 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7052 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7053 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 7054 | struct pnfs_device *pdev, |
| 7055 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7056 | { |
| 7057 | struct nfs4_getdeviceinfo_args args = { |
| 7058 | .pdev = pdev, |
| 7059 | }; |
| 7060 | struct nfs4_getdeviceinfo_res res = { |
| 7061 | .pdev = pdev, |
| 7062 | }; |
| 7063 | struct rpc_message msg = { |
| 7064 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 7065 | .rpc_argp = &args, |
| 7066 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7067 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7068 | }; |
| 7069 | int status; |
| 7070 | |
| 7071 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 7072 | 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] | 7073 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7074 | |
| 7075 | return status; |
| 7076 | } |
| 7077 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7078 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 7079 | struct pnfs_device *pdev, |
| 7080 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7081 | { |
| 7082 | struct nfs4_exception exception = { }; |
| 7083 | int err; |
| 7084 | |
| 7085 | do { |
| 7086 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7087 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7088 | &exception); |
| 7089 | } while (exception.retry); |
| 7090 | return err; |
| 7091 | } |
| 7092 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 7093 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7094 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 7095 | { |
| 7096 | struct nfs4_layoutcommit_data *data = calldata; |
| 7097 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7098 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7099 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7100 | nfs41_setup_sequence(session, |
| 7101 | &data->args.seq_args, |
| 7102 | &data->res.seq_res, |
| 7103 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7104 | } |
| 7105 | |
| 7106 | static void |
| 7107 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 7108 | { |
| 7109 | struct nfs4_layoutcommit_data *data = calldata; |
| 7110 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 7111 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7112 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7113 | return; |
| 7114 | |
| 7115 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7116 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 7117 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 7118 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 7119 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7120 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7121 | break; |
| 7122 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7123 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 7124 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7125 | break; |
| 7126 | default: |
| 7127 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 7128 | rpc_restart_call_prepare(task); |
| 7129 | return; |
| 7130 | } |
| 7131 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7132 | } |
| 7133 | |
| 7134 | static void nfs4_layoutcommit_release(void *calldata) |
| 7135 | { |
| 7136 | struct nfs4_layoutcommit_data *data = calldata; |
| 7137 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 7138 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7139 | put_rpccred(data->cred); |
| 7140 | kfree(data); |
| 7141 | } |
| 7142 | |
| 7143 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 7144 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 7145 | .rpc_call_done = nfs4_layoutcommit_done, |
| 7146 | .rpc_release = nfs4_layoutcommit_release, |
| 7147 | }; |
| 7148 | |
| 7149 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 7150 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7151 | { |
| 7152 | struct rpc_message msg = { |
| 7153 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 7154 | .rpc_argp = &data->args, |
| 7155 | .rpc_resp = &data->res, |
| 7156 | .rpc_cred = data->cred, |
| 7157 | }; |
| 7158 | struct rpc_task_setup task_setup_data = { |
| 7159 | .task = &data->task, |
| 7160 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 7161 | .rpc_message = &msg, |
| 7162 | .callback_ops = &nfs4_layoutcommit_ops, |
| 7163 | .callback_data = data, |
| 7164 | .flags = RPC_TASK_ASYNC, |
| 7165 | }; |
| 7166 | struct rpc_task *task; |
| 7167 | int status = 0; |
| 7168 | |
| 7169 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 7170 | "lbw: %llu inode %lu\n", |
| 7171 | data->task.tk_pid, sync, |
| 7172 | data->args.lastbytewritten, |
| 7173 | data->args.inode->i_ino); |
| 7174 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame^] | 7175 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7176 | task = rpc_run_task(&task_setup_data); |
| 7177 | if (IS_ERR(task)) |
| 7178 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 7179 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7180 | goto out; |
| 7181 | status = nfs4_wait_for_completion_rpc_task(task); |
| 7182 | if (status != 0) |
| 7183 | goto out; |
| 7184 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 7185 | trace_nfs4_layoutcommit(data->args.inode, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7186 | out: |
| 7187 | dprintk("%s: status %d\n", __func__, status); |
| 7188 | rpc_put_task(task); |
| 7189 | return status; |
| 7190 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7191 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 7192 | /** |
| 7193 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 7194 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 7195 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7196 | static int |
| 7197 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 7198 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 7199 | { |
| 7200 | struct nfs41_secinfo_no_name_args args = { |
| 7201 | .style = SECINFO_STYLE_CURRENT_FH, |
| 7202 | }; |
| 7203 | struct nfs4_secinfo_res res = { |
| 7204 | .flavors = flavors, |
| 7205 | }; |
| 7206 | struct rpc_message msg = { |
| 7207 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 7208 | .rpc_argp = &args, |
| 7209 | .rpc_resp = &res, |
| 7210 | }; |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 7211 | return nfs4_call_sync(server->nfs_client->cl_rpcclient, server, &msg, |
| 7212 | &args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7213 | } |
| 7214 | |
| 7215 | static int |
| 7216 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 7217 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 7218 | { |
| 7219 | struct nfs4_exception exception = { }; |
| 7220 | int err; |
| 7221 | do { |
| 7222 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 7223 | switch (err) { |
| 7224 | case 0: |
| 7225 | case -NFS4ERR_WRONGSEC: |
| 7226 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 7227 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7228 | default: |
| 7229 | err = nfs4_handle_exception(server, err, &exception); |
| 7230 | } |
| 7231 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 7232 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7233 | return err; |
| 7234 | } |
| 7235 | |
| 7236 | static int |
| 7237 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 7238 | struct nfs_fsinfo *info) |
| 7239 | { |
| 7240 | int err; |
| 7241 | struct page *page; |
| 7242 | rpc_authflavor_t flavor; |
| 7243 | struct nfs4_secinfo_flavors *flavors; |
| 7244 | |
| 7245 | page = alloc_page(GFP_KERNEL); |
| 7246 | if (!page) { |
| 7247 | err = -ENOMEM; |
| 7248 | goto out; |
| 7249 | } |
| 7250 | |
| 7251 | flavors = page_address(page); |
| 7252 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 7253 | |
| 7254 | /* |
| 7255 | * Fall back on "guess and check" method if |
| 7256 | * the server doesn't support SECINFO_NO_NAME |
| 7257 | */ |
| 7258 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 7259 | err = nfs4_find_root_sec(server, fhandle, info); |
| 7260 | goto out_freepage; |
| 7261 | } |
| 7262 | if (err) |
| 7263 | goto out_freepage; |
| 7264 | |
| 7265 | flavor = nfs_find_best_sec(flavors); |
| 7266 | if (err == 0) |
| 7267 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 7268 | |
| 7269 | out_freepage: |
| 7270 | put_page(page); |
| 7271 | if (err == -EACCES) |
| 7272 | return -EPERM; |
| 7273 | out: |
| 7274 | return err; |
| 7275 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7276 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7277 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 7278 | nfs4_stateid *stateid, |
| 7279 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7280 | { |
| 7281 | int status; |
| 7282 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7283 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7284 | }; |
| 7285 | struct nfs41_test_stateid_res res; |
| 7286 | struct rpc_message msg = { |
| 7287 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 7288 | .rpc_argp = &args, |
| 7289 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7290 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7291 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7292 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7293 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame^] | 7294 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7295 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7296 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
| 7297 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7298 | if (status != NFS_OK) { |
| 7299 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7300 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7301 | } |
| 7302 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7303 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7304 | } |
| 7305 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7306 | /** |
| 7307 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 7308 | * |
| 7309 | * @server: server / transport on which to perform the operation |
| 7310 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7311 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7312 | * |
| 7313 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 7314 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 7315 | * failed or the state ID is not currently valid. |
| 7316 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7317 | static int nfs41_test_stateid(struct nfs_server *server, |
| 7318 | nfs4_stateid *stateid, |
| 7319 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7320 | { |
| 7321 | struct nfs4_exception exception = { }; |
| 7322 | int err; |
| 7323 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7324 | err = _nfs41_test_stateid(server, stateid, cred); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7325 | if (err != -NFS4ERR_DELAY) |
| 7326 | break; |
| 7327 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7328 | } while (exception.retry); |
| 7329 | return err; |
| 7330 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7331 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7332 | struct nfs_free_stateid_data { |
| 7333 | struct nfs_server *server; |
| 7334 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7335 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7336 | }; |
| 7337 | |
| 7338 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 7339 | { |
| 7340 | struct nfs_free_stateid_data *data = calldata; |
| 7341 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 7342 | &data->args.seq_args, |
| 7343 | &data->res.seq_res, |
| 7344 | task); |
| 7345 | } |
| 7346 | |
| 7347 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 7348 | { |
| 7349 | struct nfs_free_stateid_data *data = calldata; |
| 7350 | |
| 7351 | nfs41_sequence_done(task, &data->res.seq_res); |
| 7352 | |
| 7353 | switch (task->tk_status) { |
| 7354 | case -NFS4ERR_DELAY: |
| 7355 | if (nfs4_async_handle_error(task, data->server, NULL) == -EAGAIN) |
| 7356 | rpc_restart_call_prepare(task); |
| 7357 | } |
| 7358 | } |
| 7359 | |
| 7360 | static void nfs41_free_stateid_release(void *calldata) |
| 7361 | { |
| 7362 | kfree(calldata); |
| 7363 | } |
| 7364 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 7365 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7366 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 7367 | .rpc_call_done = nfs41_free_stateid_done, |
| 7368 | .rpc_release = nfs41_free_stateid_release, |
| 7369 | }; |
| 7370 | |
| 7371 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
| 7372 | nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7373 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7374 | bool privileged) |
| 7375 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7376 | struct rpc_message msg = { |
| 7377 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7378 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7379 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7380 | struct rpc_task_setup task_setup = { |
| 7381 | .rpc_client = server->client, |
| 7382 | .rpc_message = &msg, |
| 7383 | .callback_ops = &nfs41_free_stateid_ops, |
| 7384 | .flags = RPC_TASK_ASYNC, |
| 7385 | }; |
| 7386 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7387 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7388 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7389 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 7390 | if (!data) |
| 7391 | return ERR_PTR(-ENOMEM); |
| 7392 | data->server = server; |
| 7393 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 7394 | |
| 7395 | task_setup.callback_data = data; |
| 7396 | |
| 7397 | msg.rpc_argp = &data->args; |
| 7398 | msg.rpc_resp = &data->res; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame^] | 7399 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7400 | if (privileged) |
| 7401 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 7402 | |
| 7403 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7404 | } |
| 7405 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7406 | /** |
| 7407 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 7408 | * |
| 7409 | * @server: server / transport on which to perform the operation |
| 7410 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7411 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7412 | * |
| 7413 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 7414 | * negative NFS4ERR value is returned. |
| 7415 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7416 | static int nfs41_free_stateid(struct nfs_server *server, |
| 7417 | nfs4_stateid *stateid, |
| 7418 | struct rpc_cred *cred) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7419 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7420 | struct rpc_task *task; |
| 7421 | int ret; |
| 7422 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7423 | task = _nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7424 | if (IS_ERR(task)) |
| 7425 | return PTR_ERR(task); |
| 7426 | ret = rpc_wait_for_completion_task(task); |
| 7427 | if (!ret) |
| 7428 | ret = task->tk_status; |
| 7429 | rpc_put_task(task); |
| 7430 | return ret; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7431 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7432 | |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7433 | static int nfs41_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp) |
| 7434 | { |
| 7435 | struct rpc_task *task; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7436 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7437 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7438 | task = _nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7439 | nfs4_free_lock_state(server, lsp); |
| 7440 | if (IS_ERR(task)) |
| 7441 | return PTR_ERR(task); |
| 7442 | rpc_put_task(task); |
| 7443 | return 0; |
| 7444 | } |
| 7445 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7446 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 7447 | const nfs4_stateid *s2) |
| 7448 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7449 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7450 | return false; |
| 7451 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7452 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7453 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7454 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7455 | return true; |
| 7456 | |
| 7457 | return false; |
| 7458 | } |
| 7459 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7460 | #endif /* CONFIG_NFS_V4_1 */ |
| 7461 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7462 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 7463 | const nfs4_stateid *s2) |
| 7464 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7465 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7466 | } |
| 7467 | |
| 7468 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7469 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7470 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7471 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7472 | .recover_open = nfs4_open_reclaim, |
| 7473 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7474 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7475 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7476 | }; |
| 7477 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7478 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7479 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7480 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 7481 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 7482 | .recover_open = nfs4_open_reclaim, |
| 7483 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7484 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7485 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7486 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7487 | }; |
| 7488 | #endif /* CONFIG_NFS_V4_1 */ |
| 7489 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7490 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7491 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7492 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7493 | .recover_open = nfs4_open_expired, |
| 7494 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7495 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7496 | }; |
| 7497 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7498 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7499 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7500 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 7501 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7502 | .recover_open = nfs41_open_expired, |
| 7503 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7504 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7505 | }; |
| 7506 | #endif /* CONFIG_NFS_V4_1 */ |
| 7507 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7508 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7509 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7510 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7511 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7512 | }; |
| 7513 | |
| 7514 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7515 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7516 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7517 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7518 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7519 | }; |
| 7520 | #endif |
| 7521 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7522 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 7523 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 7524 | .init_caps = NFS_CAP_READDIRPLUS |
| 7525 | | NFS_CAP_ATOMIC_OPEN |
| 7526 | | NFS_CAP_CHANGE_ATTR |
| 7527 | | NFS_CAP_POSIX_LOCK, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7528 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7529 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7530 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7531 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7532 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 7533 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 7534 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7535 | }; |
| 7536 | |
| 7537 | #if defined(CONFIG_NFS_V4_1) |
| 7538 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 7539 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 7540 | .init_caps = NFS_CAP_READDIRPLUS |
| 7541 | | NFS_CAP_ATOMIC_OPEN |
| 7542 | | NFS_CAP_CHANGE_ATTR |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 7543 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 7544 | | NFS_CAP_STATEID_NFSV41 |
| 7545 | | NFS_CAP_ATOMIC_OPEN_V1, |
Bryan Schumaker | 104287c | 2012-11-12 14:13:13 -0500 | [diff] [blame] | 7546 | .call_sync = nfs4_call_sync_sequence, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7547 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7548 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7549 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7550 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 7551 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 7552 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7553 | }; |
| 7554 | #endif |
| 7555 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7556 | #if defined(CONFIG_NFS_V4_2) |
| 7557 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 7558 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 7559 | .init_caps = NFS_CAP_READDIRPLUS |
| 7560 | | NFS_CAP_ATOMIC_OPEN |
| 7561 | | NFS_CAP_CHANGE_ATTR |
| 7562 | | NFS_CAP_POSIX_LOCK |
| 7563 | | NFS_CAP_STATEID_NFSV41 |
| 7564 | | NFS_CAP_ATOMIC_OPEN_V1, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7565 | .call_sync = nfs4_call_sync_sequence, |
| 7566 | .match_stateid = nfs41_match_stateid, |
| 7567 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 7568 | .free_lock_state = nfs41_free_lock_state, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7569 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 7570 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 7571 | .state_renewal_ops = &nfs41_state_renewal_ops, |
| 7572 | }; |
| 7573 | #endif |
| 7574 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7575 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 7576 | [0] = &nfs_v4_0_minor_ops, |
| 7577 | #if defined(CONFIG_NFS_V4_1) |
| 7578 | [1] = &nfs_v4_1_minor_ops, |
| 7579 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7580 | #if defined(CONFIG_NFS_V4_2) |
| 7581 | [2] = &nfs_v4_2_minor_ops, |
| 7582 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7583 | }; |
| 7584 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 7585 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 7586 | .create = nfs_create, |
| 7587 | .lookup = nfs_lookup, |
| 7588 | .atomic_open = nfs_atomic_open, |
| 7589 | .link = nfs_link, |
| 7590 | .unlink = nfs_unlink, |
| 7591 | .symlink = nfs_symlink, |
| 7592 | .mkdir = nfs_mkdir, |
| 7593 | .rmdir = nfs_rmdir, |
| 7594 | .mknod = nfs_mknod, |
| 7595 | .rename = nfs_rename, |
| 7596 | .permission = nfs_permission, |
| 7597 | .getattr = nfs_getattr, |
| 7598 | .setattr = nfs_setattr, |
| 7599 | .getxattr = generic_getxattr, |
| 7600 | .setxattr = generic_setxattr, |
| 7601 | .listxattr = generic_listxattr, |
| 7602 | .removexattr = generic_removexattr, |
| 7603 | }; |
| 7604 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 7605 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7606 | .permission = nfs_permission, |
| 7607 | .getattr = nfs_getattr, |
| 7608 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7609 | .getxattr = generic_getxattr, |
| 7610 | .setxattr = generic_setxattr, |
| 7611 | .listxattr = generic_listxattr, |
| 7612 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7613 | }; |
| 7614 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 7615 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7616 | .version = 4, /* protocol version */ |
| 7617 | .dentry_ops = &nfs4_dentry_operations, |
| 7618 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7619 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 7620 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7621 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 7622 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 7623 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7624 | .getattr = nfs4_proc_getattr, |
| 7625 | .setattr = nfs4_proc_setattr, |
| 7626 | .lookup = nfs4_proc_lookup, |
| 7627 | .access = nfs4_proc_access, |
| 7628 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7629 | .create = nfs4_proc_create, |
| 7630 | .remove = nfs4_proc_remove, |
| 7631 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 7632 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7633 | .unlink_done = nfs4_proc_unlink_done, |
| 7634 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7635 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 7636 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7637 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7638 | .link = nfs4_proc_link, |
| 7639 | .symlink = nfs4_proc_symlink, |
| 7640 | .mkdir = nfs4_proc_mkdir, |
| 7641 | .rmdir = nfs4_proc_remove, |
| 7642 | .readdir = nfs4_proc_readdir, |
| 7643 | .mknod = nfs4_proc_mknod, |
| 7644 | .statfs = nfs4_proc_statfs, |
| 7645 | .fsinfo = nfs4_proc_fsinfo, |
| 7646 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 7647 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7648 | .decode_dirent = nfs4_decode_dirent, |
| 7649 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 7650 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 7651 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7652 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7653 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 7654 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 7655 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7656 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7657 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 7658 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7659 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7660 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 7661 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 7662 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 7663 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 7664 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 7665 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 7666 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 7667 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 7668 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 7669 | .create_server = nfs4_create_server, |
| 7670 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7671 | }; |
| 7672 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7673 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 7674 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 7675 | .list = nfs4_xattr_list_nfs4_acl, |
| 7676 | .get = nfs4_xattr_get_nfs4_acl, |
| 7677 | .set = nfs4_xattr_set_nfs4_acl, |
| 7678 | }; |
| 7679 | |
| 7680 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 7681 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7682 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 7683 | &nfs4_xattr_nfs4_label_handler, |
| 7684 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7685 | NULL |
| 7686 | }; |
| 7687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7688 | /* |
| 7689 | * Local variables: |
| 7690 | * c-basic-offset: 8 |
| 7691 | * End: |
| 7692 | */ |