Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
| 46 | #include <linux/nfs.h> |
| 47 | #include <linux/nfs4.h> |
| 48 | #include <linux/nfs_fs.h> |
| 49 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 50 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 52 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 53 | #include <linux/module.h> |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 54 | #include <linux/nfs_idmap.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 55 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 56 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 57 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 59 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 61 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 62 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 63 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 64 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 65 | #include "netns.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 66 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 67 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 69 | #include "nfs4trace.h" |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 72 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 73 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 75 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 76 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 77 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 78 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 80 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 81 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 82 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label); |
| 83 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 84 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 85 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 86 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 87 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 88 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 89 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 90 | struct rpc_cred *); |
| 91 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *, |
| 92 | struct rpc_cred *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 93 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 94 | |
| 95 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 96 | static inline struct nfs4_label * |
| 97 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 98 | struct iattr *sattr, struct nfs4_label *label) |
| 99 | { |
| 100 | int err; |
| 101 | |
| 102 | if (label == NULL) |
| 103 | return NULL; |
| 104 | |
| 105 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 106 | return NULL; |
| 107 | |
| 108 | if (NFS_SERVER(dir)->nfs_client->cl_minorversion < 2) |
| 109 | return NULL; |
| 110 | |
| 111 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 112 | &dentry->d_name, (void **)&label->label, &label->len); |
| 113 | if (err == 0) |
| 114 | return label; |
| 115 | |
| 116 | return NULL; |
| 117 | } |
| 118 | static inline void |
| 119 | nfs4_label_release_security(struct nfs4_label *label) |
| 120 | { |
| 121 | if (label) |
| 122 | security_release_secctx(label->label, label->len); |
| 123 | } |
| 124 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 125 | { |
| 126 | if (label) |
| 127 | return server->attr_bitmask; |
| 128 | |
| 129 | return server->attr_bitmask_nl; |
| 130 | } |
| 131 | #else |
| 132 | static inline struct nfs4_label * |
| 133 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 134 | struct iattr *sattr, struct nfs4_label *l) |
| 135 | { return NULL; } |
| 136 | static inline void |
| 137 | nfs4_label_release_security(struct nfs4_label *label) |
| 138 | { return; } |
| 139 | static inline u32 * |
| 140 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 141 | { return server->attr_bitmask; } |
| 142 | #endif |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 145 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 147 | if (err >= -1000) |
| 148 | return err; |
| 149 | switch (err) { |
| 150 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 151 | case -NFS4ERR_LAYOUTTRYLATER: |
| 152 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 153 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 154 | case -NFS4ERR_WRONGSEC: |
| 155 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 156 | case -NFS4ERR_BADOWNER: |
| 157 | case -NFS4ERR_BADNAME: |
| 158 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 159 | case -NFS4ERR_SHARE_DENIED: |
| 160 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 161 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 162 | return -EPROTONOSUPPORT; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 163 | case -NFS4ERR_ACCESS: |
| 164 | return -EACCES; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 165 | case -NFS4ERR_FILE_OPEN: |
| 166 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 167 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 169 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 170 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 172 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | /* |
| 176 | * This is our standard bitmap for GETATTR requests. |
| 177 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 178 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | FATTR4_WORD0_TYPE |
| 180 | | FATTR4_WORD0_CHANGE |
| 181 | | FATTR4_WORD0_SIZE |
| 182 | | FATTR4_WORD0_FSID |
| 183 | | FATTR4_WORD0_FILEID, |
| 184 | FATTR4_WORD1_MODE |
| 185 | | FATTR4_WORD1_NUMLINKS |
| 186 | | FATTR4_WORD1_OWNER |
| 187 | | FATTR4_WORD1_OWNER_GROUP |
| 188 | | FATTR4_WORD1_RAWDEV |
| 189 | | FATTR4_WORD1_SPACE_USED |
| 190 | | FATTR4_WORD1_TIME_ACCESS |
| 191 | | FATTR4_WORD1_TIME_METADATA |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 192 | | FATTR4_WORD1_TIME_MODIFY, |
| 193 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 194 | FATTR4_WORD2_SECURITY_LABEL |
| 195 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | }; |
| 197 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 198 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 199 | FATTR4_WORD0_TYPE |
| 200 | | FATTR4_WORD0_CHANGE |
| 201 | | FATTR4_WORD0_SIZE |
| 202 | | FATTR4_WORD0_FSID |
| 203 | | FATTR4_WORD0_FILEID, |
| 204 | FATTR4_WORD1_MODE |
| 205 | | FATTR4_WORD1_NUMLINKS |
| 206 | | FATTR4_WORD1_OWNER |
| 207 | | FATTR4_WORD1_OWNER_GROUP |
| 208 | | FATTR4_WORD1_RAWDEV |
| 209 | | FATTR4_WORD1_SPACE_USED |
| 210 | | FATTR4_WORD1_TIME_ACCESS |
| 211 | | FATTR4_WORD1_TIME_METADATA |
| 212 | | FATTR4_WORD1_TIME_MODIFY, |
| 213 | FATTR4_WORD2_MDSTHRESHOLD |
| 214 | }; |
| 215 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 216 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 217 | FATTR4_WORD0_TYPE |
| 218 | | FATTR4_WORD0_CHANGE |
| 219 | | FATTR4_WORD0_FILEID, |
| 220 | }; |
| 221 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 222 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | FATTR4_WORD0_FILES_AVAIL |
| 224 | | FATTR4_WORD0_FILES_FREE |
| 225 | | FATTR4_WORD0_FILES_TOTAL, |
| 226 | FATTR4_WORD1_SPACE_AVAIL |
| 227 | | FATTR4_WORD1_SPACE_FREE |
| 228 | | FATTR4_WORD1_SPACE_TOTAL |
| 229 | }; |
| 230 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 231 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | FATTR4_WORD0_MAXLINK |
| 233 | | FATTR4_WORD0_MAXNAME, |
| 234 | 0 |
| 235 | }; |
| 236 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 237 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | | FATTR4_WORD0_MAXREAD |
| 239 | | FATTR4_WORD0_MAXWRITE |
| 240 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 241 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 242 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 243 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | }; |
| 245 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 246 | const u32 nfs4_fs_locations_bitmap[3] = { |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 247 | FATTR4_WORD0_TYPE |
| 248 | | FATTR4_WORD0_CHANGE |
| 249 | | FATTR4_WORD0_SIZE |
| 250 | | FATTR4_WORD0_FSID |
| 251 | | FATTR4_WORD0_FILEID |
| 252 | | FATTR4_WORD0_FS_LOCATIONS, |
| 253 | FATTR4_WORD1_MODE |
| 254 | | FATTR4_WORD1_NUMLINKS |
| 255 | | FATTR4_WORD1_OWNER |
| 256 | | FATTR4_WORD1_OWNER_GROUP |
| 257 | | FATTR4_WORD1_RAWDEV |
| 258 | | FATTR4_WORD1_SPACE_USED |
| 259 | | FATTR4_WORD1_TIME_ACCESS |
| 260 | | FATTR4_WORD1_TIME_METADATA |
| 261 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 262 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 263 | }; |
| 264 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 265 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | struct nfs4_readdir_arg *readdir) |
| 267 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 268 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 271 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | readdir->cookie = 0; |
| 277 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 278 | if (cookie == 2) |
| 279 | return; |
| 280 | |
| 281 | /* |
| 282 | * NFSv4 servers do not return entries for '.' and '..' |
| 283 | * Therefore, we fake these entries here. We let '.' |
| 284 | * have cookie 0 and '..' have cookie 1. Note that |
| 285 | * when talking to the server, we always send cookie 0 |
| 286 | * instead of 1 or 2. |
| 287 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 288 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | |
| 290 | if (cookie == 0) { |
| 291 | *p++ = xdr_one; /* next */ |
| 292 | *p++ = xdr_zero; /* cookie, first word */ |
| 293 | *p++ = xdr_one; /* cookie, second word */ |
| 294 | *p++ = xdr_one; /* entry len */ |
| 295 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 296 | p++; |
| 297 | *p++ = xdr_one; /* bitmap length */ |
| 298 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 299 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 300 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | *p++ = xdr_one; /* next */ |
| 304 | *p++ = xdr_zero; /* cookie, first word */ |
| 305 | *p++ = xdr_two; /* cookie, second word */ |
| 306 | *p++ = xdr_two; /* entry len */ |
| 307 | memcpy(p, "..\0\0", 4); /* entry */ |
| 308 | p++; |
| 309 | *p++ = xdr_one; /* bitmap length */ |
| 310 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 311 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 312 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
| 314 | readdir->pgbase = (char *)p - (char *)start; |
| 315 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 316 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 319 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 320 | { |
| 321 | int res = 0; |
| 322 | |
| 323 | might_sleep(); |
| 324 | |
| 325 | if (*timeout <= 0) |
| 326 | *timeout = NFS4_POLL_RETRY_MIN; |
| 327 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 328 | *timeout = NFS4_POLL_RETRY_MAX; |
Colin Cross | 416ad3c | 2013-05-06 23:50:06 +0000 | [diff] [blame] | 329 | freezable_schedule_timeout_killable_unsafe(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 330 | if (fatal_signal_pending(current)) |
| 331 | res = -ERESTARTSYS; |
| 332 | *timeout <<= 1; |
| 333 | return res; |
| 334 | } |
| 335 | |
| 336 | /* This is the error handling routine for processes that are allowed |
| 337 | * to sleep. |
| 338 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 339 | static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 340 | { |
| 341 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 342 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 343 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 344 | int ret = errorcode; |
| 345 | |
| 346 | exception->retry = 0; |
| 347 | switch(errorcode) { |
| 348 | case 0: |
| 349 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 350 | case -NFS4ERR_OPENMODE: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 351 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 352 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 353 | exception->retry = 1; |
| 354 | return 0; |
| 355 | } |
| 356 | if (state == NULL) |
| 357 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 358 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 359 | if (ret < 0) |
| 360 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 361 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 362 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 363 | case -NFS4ERR_ADMIN_REVOKED: |
| 364 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | b570a97 | 2013-04-12 15:04:51 -0400 | [diff] [blame] | 365 | if (inode != NULL && nfs4_have_delegation(inode, FMODE_READ)) { |
| 366 | nfs_remove_bad_delegation(inode); |
| 367 | exception->retry = 1; |
| 368 | break; |
| 369 | } |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 370 | if (state == NULL) |
| 371 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 372 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 373 | if (ret < 0) |
| 374 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 375 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 376 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 377 | if (state != NULL) { |
| 378 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 379 | if (ret < 0) |
| 380 | break; |
| 381 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 382 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 383 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 384 | nfs4_schedule_lease_recovery(clp); |
| 385 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 386 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 387 | case -NFS4ERR_BADSESSION: |
| 388 | case -NFS4ERR_BADSLOT: |
| 389 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 390 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 391 | case -NFS4ERR_DEADSESSION: |
| 392 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 393 | case -NFS4ERR_SEQ_MISORDERED: |
| 394 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 395 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 396 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 397 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 398 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 399 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 400 | if (exception->timeout > HZ) { |
| 401 | /* We have retried a decent amount, time to |
| 402 | * fail |
| 403 | */ |
| 404 | ret = -EBUSY; |
| 405 | break; |
| 406 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 407 | case -NFS4ERR_GRACE: |
| 408 | case -NFS4ERR_DELAY: |
| 409 | ret = nfs4_delay(server->client, &exception->timeout); |
| 410 | if (ret != 0) |
| 411 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 412 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 413 | case -NFS4ERR_OLD_STATEID: |
| 414 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 415 | break; |
| 416 | case -NFS4ERR_BADOWNER: |
| 417 | /* The following works around a Linux server bug! */ |
| 418 | case -NFS4ERR_BADNAME: |
| 419 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 420 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 421 | exception->retry = 1; |
| 422 | printk(KERN_WARNING "NFS: v4 server %s " |
| 423 | "does not accept raw " |
| 424 | "uid/gids. " |
| 425 | "Reenabling the idmapper.\n", |
| 426 | server->nfs_client->cl_hostname); |
| 427 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 428 | } |
| 429 | /* We failed to handle the error */ |
| 430 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 431 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 432 | ret = nfs4_wait_clnt_recover(clp); |
| 433 | if (ret == 0) |
| 434 | exception->retry = 1; |
| 435 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 439 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | spin_lock(&clp->cl_lock); |
| 442 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 443 | clp->cl_last_renewal = timestamp; |
| 444 | spin_unlock(&clp->cl_lock); |
| 445 | } |
| 446 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 447 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 448 | { |
| 449 | do_renew_lease(server->nfs_client, timestamp); |
| 450 | } |
| 451 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 452 | #if defined(CONFIG_NFS_V4_1) |
| 453 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 454 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 455 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 456 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 457 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 458 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 459 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 460 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 461 | /* just wake up the next guy waiting since |
| 462 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 463 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 464 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 465 | } |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 466 | tbl = res->sr_slot->table; |
| 467 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 468 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 469 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 470 | /* Be nice to the server: try to ensure that the last transmitted |
| 471 | * value for highest_user_slotid <= target_highest_slotid |
| 472 | */ |
| 473 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 474 | send_new_highest_used_slotid = true; |
| 475 | |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 476 | if (nfs41_wake_and_assign_slot(tbl, res->sr_slot)) { |
| 477 | send_new_highest_used_slotid = false; |
| 478 | goto out_unlock; |
| 479 | } |
Trond Myklebust | f4af6e2a | 2012-11-20 14:17:32 -0500 | [diff] [blame] | 480 | nfs4_free_slot(tbl, res->sr_slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 481 | |
| 482 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 483 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 484 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 485 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 486 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 487 | if (send_new_highest_used_slotid) |
| 488 | nfs41_server_notify_highest_slotid_update(session->clp); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 489 | } |
| 490 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 491 | static int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 492 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 493 | struct nfs4_session *session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 494 | struct nfs4_slot *slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 495 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 496 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 497 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 498 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 499 | /* don't increment the sequence number if the task wasn't sent */ |
| 500 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 501 | goto out; |
| 502 | |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 503 | slot = res->sr_slot; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 504 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 505 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 506 | if (slot->interrupted) { |
| 507 | slot->interrupted = 0; |
| 508 | interrupted = true; |
| 509 | } |
| 510 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 511 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 512 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 513 | switch (res->sr_status) { |
| 514 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 515 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 516 | ++slot->seq_nr; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 517 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 518 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 519 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 520 | if (res->sr_status_flags != 0) |
| 521 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 522 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 523 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 524 | case 1: |
| 525 | /* |
| 526 | * sr_status remains 1 if an RPC level error occurred. |
| 527 | * The server may or may not have processed the sequence |
| 528 | * operation.. |
| 529 | * Mark the slot as having hosted an interrupted RPC call. |
| 530 | */ |
| 531 | slot->interrupted = 1; |
| 532 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 533 | case -NFS4ERR_DELAY: |
| 534 | /* The server detected a resend of the RPC call and |
| 535 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 536 | * of RFC5661. |
| 537 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 538 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 539 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 540 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 541 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 542 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 543 | case -NFS4ERR_BADSLOT: |
| 544 | /* |
| 545 | * The slot id we used was probably retired. Try again |
| 546 | * using a different slot id. |
| 547 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 548 | goto retry_nowait; |
| 549 | case -NFS4ERR_SEQ_MISORDERED: |
| 550 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 551 | * Was the last operation on this sequence interrupted? |
| 552 | * If so, retry after bumping the sequence number. |
| 553 | */ |
| 554 | if (interrupted) { |
| 555 | ++slot->seq_nr; |
| 556 | goto retry_nowait; |
| 557 | } |
| 558 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 559 | * Could this slot have been previously retired? |
| 560 | * If so, then the server may be expecting seq_nr = 1! |
| 561 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 562 | if (slot->seq_nr != 1) { |
| 563 | slot->seq_nr = 1; |
| 564 | goto retry_nowait; |
| 565 | } |
| 566 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 567 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 568 | ++slot->seq_nr; |
| 569 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 570 | default: |
| 571 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 572 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 573 | } |
| 574 | out: |
| 575 | /* The session may be reset by one of the error handlers. */ |
| 576 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 577 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 578 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 579 | retry_nowait: |
| 580 | if (rpc_restart_call_prepare(task)) { |
| 581 | task->tk_status = 0; |
| 582 | ret = 0; |
| 583 | } |
| 584 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 585 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 586 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 587 | goto out; |
| 588 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 589 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 590 | } |
| 591 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 592 | static int nfs4_sequence_done(struct rpc_task *task, |
| 593 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 594 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 595 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 596 | return 1; |
| 597 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 598 | } |
| 599 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 600 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 601 | struct nfs4_sequence_res *res, int cache_reply) |
| 602 | { |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 603 | args->sa_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 604 | args->sa_cache_this = 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 605 | args->sa_privileged = 0; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 606 | if (cache_reply) |
| 607 | args->sa_cache_this = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 608 | res->sr_slot = NULL; |
| 609 | } |
| 610 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 611 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 612 | { |
| 613 | args->sa_privileged = 1; |
| 614 | } |
| 615 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 616 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 617 | struct nfs4_sequence_args *args, |
| 618 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 619 | struct rpc_task *task) |
| 620 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 621 | struct nfs4_slot *slot; |
| 622 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 623 | |
| 624 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 625 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 626 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 627 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 628 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 629 | tbl = &session->fc_slot_table; |
| 630 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 631 | task->tk_timeout = 0; |
| 632 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 633 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 634 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 635 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 636 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 637 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 638 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 639 | } |
| 640 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 641 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 642 | if (IS_ERR(slot)) { |
| 643 | /* If out of memory, try again in 1/4 second */ |
| 644 | if (slot == ERR_PTR(-ENOMEM)) |
| 645 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 646 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 647 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 648 | } |
| 649 | spin_unlock(&tbl->slot_tbl_lock); |
| 650 | |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 651 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 652 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 653 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, |
| 654 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 655 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 656 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 657 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 658 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 659 | /* |
| 660 | * sr_status is only set in decode_sequence, and so will remain |
| 661 | * set to 1 if an rpc level failure occurs. |
| 662 | */ |
| 663 | res->sr_status = 1; |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 664 | trace_nfs4_setup_sequence(session, args); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 665 | out_success: |
| 666 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 667 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 668 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 669 | /* Privileged tasks are queued with top priority */ |
| 670 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 671 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 672 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 673 | else |
| 674 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 675 | spin_unlock(&tbl->slot_tbl_lock); |
| 676 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 677 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 678 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 679 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 680 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 681 | struct nfs4_sequence_args *args, |
| 682 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 683 | struct rpc_task *task) |
| 684 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 685 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 686 | int ret = 0; |
| 687 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 688 | if (session == NULL) { |
| 689 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 690 | goto out; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 691 | } |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 692 | |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 693 | dprintk("--> %s clp %p session %p sr_slot %d\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 694 | __func__, session->clp, session, res->sr_slot ? |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 695 | res->sr_slot->slot_nr : -1); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 696 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 697 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 698 | out: |
| 699 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 700 | return ret; |
| 701 | } |
| 702 | |
| 703 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 704 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 705 | struct nfs4_sequence_args *seq_args; |
| 706 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 707 | }; |
| 708 | |
| 709 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 710 | { |
| 711 | struct nfs41_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 712 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 713 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 714 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 715 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 716 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 717 | } |
| 718 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 719 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 720 | { |
| 721 | struct nfs41_call_sync_data *data = calldata; |
| 722 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 723 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 724 | } |
| 725 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 726 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 727 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 728 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 729 | }; |
| 730 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 731 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 732 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 733 | struct rpc_message *msg, |
| 734 | struct nfs4_sequence_args *args, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 735 | struct nfs4_sequence_res *res) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 736 | { |
| 737 | int ret; |
| 738 | struct rpc_task *task; |
| 739 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 740 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 741 | .seq_args = args, |
| 742 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 743 | }; |
| 744 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 745 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 746 | .rpc_message = msg, |
| 747 | .callback_ops = &nfs41_call_sync_ops, |
| 748 | .callback_data = &data |
| 749 | }; |
| 750 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 751 | task = rpc_run_task(&task_setup); |
| 752 | if (IS_ERR(task)) |
| 753 | ret = PTR_ERR(task); |
| 754 | else { |
| 755 | ret = task->tk_status; |
| 756 | rpc_put_task(task); |
| 757 | } |
| 758 | return ret; |
| 759 | } |
| 760 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 761 | #else |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 762 | static |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 763 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 764 | struct nfs4_sequence_res *res, int cache_reply) |
| 765 | { |
| 766 | } |
| 767 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 768 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 769 | { |
| 770 | } |
| 771 | |
| 772 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 773 | static int nfs4_sequence_done(struct rpc_task *task, |
| 774 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 775 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 776 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 777 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 778 | #endif /* CONFIG_NFS_V4_1 */ |
| 779 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 780 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 781 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 782 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 783 | struct rpc_message *msg, |
| 784 | struct nfs4_sequence_args *args, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 785 | struct nfs4_sequence_res *res) |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 786 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 787 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 788 | } |
| 789 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 790 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 791 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 792 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 793 | struct rpc_message *msg, |
| 794 | struct nfs4_sequence_args *args, |
| 795 | struct nfs4_sequence_res *res, |
| 796 | int cache_reply) |
| 797 | { |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 798 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 799 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 800 | args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 801 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 802 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 803 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 805 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 807 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 808 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 809 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 810 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 811 | dir->i_version = cinfo->after; |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 812 | nfs_fscache_invalidate(dir); |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 813 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | } |
| 815 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 816 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 817 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 818 | struct nfs_openargs o_arg; |
| 819 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 820 | struct nfs_open_confirmargs c_arg; |
| 821 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 822 | struct nfs4_string owner_name; |
| 823 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 824 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 825 | struct nfs4_label *f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 826 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 827 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 828 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 829 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 830 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 831 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 832 | unsigned int rpc_done : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 833 | unsigned int is_recover : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 834 | int rpc_status; |
| 835 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 836 | }; |
| 837 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 838 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 839 | int err, struct nfs4_exception *exception) |
| 840 | { |
| 841 | if (err != -EINVAL) |
| 842 | return false; |
| 843 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 844 | return false; |
| 845 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 846 | exception->retry = 1; |
| 847 | return true; |
| 848 | } |
| 849 | |
| 850 | static enum open_claim_type4 |
| 851 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 852 | enum open_claim_type4 claim) |
| 853 | { |
| 854 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 855 | return claim; |
| 856 | switch (claim) { |
| 857 | default: |
| 858 | return claim; |
| 859 | case NFS4_OPEN_CLAIM_FH: |
| 860 | return NFS4_OPEN_CLAIM_NULL; |
| 861 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 862 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 863 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 864 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 865 | } |
| 866 | } |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 867 | |
| 868 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 869 | { |
| 870 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 871 | p->o_res.f_label = p->f_label; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 872 | p->o_res.seqid = p->o_arg.seqid; |
| 873 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 874 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 875 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 876 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 877 | 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] | 878 | } |
| 879 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 880 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 881 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 882 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 883 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 884 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 885 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 886 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 887 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 888 | struct inode *dir = parent->d_inode; |
| 889 | struct nfs_server *server = NFS_SERVER(dir); |
| 890 | struct nfs4_opendata *p; |
| 891 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 892 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 893 | if (p == NULL) |
| 894 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 895 | |
| 896 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 897 | if (IS_ERR(p->f_label)) |
| 898 | goto err_free_p; |
| 899 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 900 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 901 | if (p->o_arg.seqid == NULL) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 902 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 903 | nfs_sb_active(dentry->d_sb); |
| 904 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 905 | p->dir = parent; |
| 906 | p->owner = sp; |
| 907 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 908 | p->o_arg.open_flags = flags; |
| 909 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 910 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 911 | * will return permission denied for all bits until close */ |
| 912 | if (!(flags & O_EXCL)) { |
| 913 | /* ask server to check for all possible rights as results |
| 914 | * are cached */ |
| 915 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 916 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 917 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 918 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 919 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 920 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 921 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 922 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 923 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 924 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 925 | p->o_arg.label = label; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 926 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 927 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 928 | case NFS4_OPEN_CLAIM_NULL: |
| 929 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 930 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 931 | p->o_arg.fh = NFS_FH(dir); |
| 932 | break; |
| 933 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 934 | case NFS4_OPEN_CLAIM_FH: |
| 935 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 936 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 937 | p->o_arg.fh = NFS_FH(dentry->d_inode); |
| 938 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 939 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 940 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 941 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 942 | p->o_arg.u.attrs = &p->attrs; |
| 943 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 944 | |
| 945 | verf[0] = jiffies; |
| 946 | verf[1] = current->pid; |
| 947 | memcpy(p->o_arg.u.verifier.data, verf, |
| 948 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 949 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 950 | p->c_arg.fh = &p->o_res.fh; |
| 951 | p->c_arg.stateid = &p->o_res.stateid; |
| 952 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 953 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 954 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 955 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 956 | |
| 957 | err_free_label: |
| 958 | nfs4_label_free(p->f_label); |
| 959 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 960 | kfree(p); |
| 961 | err: |
| 962 | dput(parent); |
| 963 | return NULL; |
| 964 | } |
| 965 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 966 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 967 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 968 | struct nfs4_opendata *p = container_of(kref, |
| 969 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 970 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 971 | |
| 972 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 973 | if (p->state != NULL) |
| 974 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 975 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 976 | |
| 977 | nfs4_label_free(p->f_label); |
| 978 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 979 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 980 | dput(p->dentry); |
| 981 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 982 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 983 | kfree(p); |
| 984 | } |
| 985 | |
| 986 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 987 | { |
| 988 | if (p != NULL) |
| 989 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 990 | } |
| 991 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 992 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 993 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 994 | int ret; |
| 995 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 996 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 997 | return ret; |
| 998 | } |
| 999 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1000 | 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] | 1001 | { |
| 1002 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1003 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1004 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1005 | goto out; |
| 1006 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1007 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1008 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1009 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1010 | break; |
| 1011 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1012 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1013 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1014 | break; |
| 1015 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1016 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1017 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1018 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1019 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1020 | return ret; |
| 1021 | } |
| 1022 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1023 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1024 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1025 | if (delegation == NULL) |
| 1026 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1027 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1028 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1029 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1030 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1031 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1032 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1033 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1034 | return 1; |
| 1035 | } |
| 1036 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1037 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1038 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1039 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1040 | case FMODE_WRITE: |
| 1041 | state->n_wronly++; |
| 1042 | break; |
| 1043 | case FMODE_READ: |
| 1044 | state->n_rdonly++; |
| 1045 | break; |
| 1046 | case FMODE_READ|FMODE_WRITE: |
| 1047 | state->n_rdwr++; |
| 1048 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1049 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1050 | } |
| 1051 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1052 | 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] | 1053 | { |
| 1054 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1055 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1056 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 92b40e9 | 2013-04-20 01:25:45 -0400 | [diff] [blame] | 1057 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1058 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1059 | case FMODE_READ: |
| 1060 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1061 | break; |
| 1062 | case FMODE_WRITE: |
| 1063 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1064 | break; |
| 1065 | case FMODE_READ|FMODE_WRITE: |
| 1066 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1067 | } |
| 1068 | } |
| 1069 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1070 | 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] | 1071 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1072 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1073 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1074 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1075 | } |
| 1076 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1077 | 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] | 1078 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1079 | /* |
| 1080 | * Protect the call to nfs4_state_set_mode_locked and |
| 1081 | * serialise the stateid update |
| 1082 | */ |
| 1083 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1084 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1085 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1086 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1087 | } |
| 1088 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1089 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1090 | write_sequnlock(&state->seqlock); |
| 1091 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1092 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1093 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | } |
| 1095 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1096 | 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] | 1097 | { |
| 1098 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1099 | struct nfs_delegation *deleg_cur; |
| 1100 | int ret = 0; |
| 1101 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1102 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1103 | |
| 1104 | rcu_read_lock(); |
| 1105 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1106 | if (deleg_cur == NULL) |
| 1107 | goto no_delegation; |
| 1108 | |
| 1109 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1110 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1111 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1112 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1113 | goto no_delegation_unlock; |
| 1114 | |
| 1115 | if (delegation == NULL) |
| 1116 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1117 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1118 | goto no_delegation_unlock; |
| 1119 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1120 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1121 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1122 | ret = 1; |
| 1123 | no_delegation_unlock: |
| 1124 | spin_unlock(&deleg_cur->lock); |
| 1125 | no_delegation: |
| 1126 | rcu_read_unlock(); |
| 1127 | |
| 1128 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1129 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1130 | ret = 1; |
| 1131 | } |
| 1132 | |
| 1133 | return ret; |
| 1134 | } |
| 1135 | |
| 1136 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1137 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1138 | { |
| 1139 | struct nfs_delegation *delegation; |
| 1140 | |
| 1141 | rcu_read_lock(); |
| 1142 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1143 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1144 | rcu_read_unlock(); |
| 1145 | return; |
| 1146 | } |
| 1147 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1148 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1149 | } |
| 1150 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1151 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1152 | { |
| 1153 | struct nfs4_state *state = opendata->state; |
| 1154 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1155 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1156 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1157 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1158 | nfs4_stateid stateid; |
| 1159 | int ret = -EAGAIN; |
| 1160 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1161 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1162 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1163 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1164 | if (can_open_cached(state, fmode, open_mode)) { |
| 1165 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1166 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1167 | goto out_return_state; |
| 1168 | } |
| 1169 | spin_unlock(&state->owner->so_lock); |
| 1170 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1171 | rcu_read_lock(); |
| 1172 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1173 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1174 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1175 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1176 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1177 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1178 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1179 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1180 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1181 | if (!opendata->is_recover) { |
| 1182 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1183 | if (ret != 0) |
| 1184 | goto out; |
| 1185 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1186 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1187 | |
| 1188 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1189 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1190 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1191 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1192 | out: |
| 1193 | return ERR_PTR(ret); |
| 1194 | out_return_state: |
| 1195 | atomic_inc(&state->count); |
| 1196 | return state; |
| 1197 | } |
| 1198 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1199 | static void |
| 1200 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1201 | { |
| 1202 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1203 | struct nfs_delegation *delegation; |
| 1204 | int delegation_flags = 0; |
| 1205 | |
| 1206 | rcu_read_lock(); |
| 1207 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1208 | if (delegation) |
| 1209 | delegation_flags = delegation->flags; |
| 1210 | rcu_read_unlock(); |
| 1211 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1212 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1213 | "returning a delegation for " |
| 1214 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1215 | clp->cl_hostname); |
| 1216 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1217 | nfs_inode_set_delegation(state->inode, |
| 1218 | data->owner->so_cred, |
| 1219 | &data->o_res); |
| 1220 | else |
| 1221 | nfs_inode_reclaim_delegation(state->inode, |
| 1222 | data->owner->so_cred, |
| 1223 | &data->o_res); |
| 1224 | } |
| 1225 | |
| 1226 | /* |
| 1227 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1228 | * and update the nfs4_state. |
| 1229 | */ |
| 1230 | static struct nfs4_state * |
| 1231 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1232 | { |
| 1233 | struct inode *inode = data->state->inode; |
| 1234 | struct nfs4_state *state = data->state; |
| 1235 | int ret; |
| 1236 | |
| 1237 | if (!data->rpc_done) { |
| 1238 | ret = data->rpc_status; |
| 1239 | goto err; |
| 1240 | } |
| 1241 | |
| 1242 | ret = -ESTALE; |
| 1243 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || |
| 1244 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || |
| 1245 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) |
| 1246 | goto err; |
| 1247 | |
| 1248 | ret = -ENOMEM; |
| 1249 | state = nfs4_get_open_state(inode, data->owner); |
| 1250 | if (state == NULL) |
| 1251 | goto err; |
| 1252 | |
| 1253 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1254 | if (ret) |
| 1255 | goto err; |
| 1256 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1257 | nfs_setsecurity(inode, &data->f_attr, data->f_label); |
| 1258 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1259 | if (data->o_res.delegation_type != 0) |
| 1260 | nfs4_opendata_check_deleg(data, state); |
| 1261 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1262 | data->o_arg.fmode); |
| 1263 | |
| 1264 | return state; |
| 1265 | err: |
| 1266 | return ERR_PTR(ret); |
| 1267 | |
| 1268 | } |
| 1269 | |
| 1270 | static struct nfs4_state * |
| 1271 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1272 | { |
| 1273 | struct inode *inode; |
| 1274 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1275 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1276 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1277 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1278 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1279 | goto out; |
| 1280 | } |
| 1281 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1282 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1283 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1284 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1285 | 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] | 1286 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1287 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1288 | goto err; |
| 1289 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1290 | state = nfs4_get_open_state(inode, data->owner); |
| 1291 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1292 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1293 | if (data->o_res.delegation_type != 0) |
| 1294 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1295 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1296 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1297 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1298 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1299 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1300 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1301 | err_put_inode: |
| 1302 | iput(inode); |
| 1303 | err: |
| 1304 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1305 | } |
| 1306 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1307 | static struct nfs4_state * |
| 1308 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1309 | { |
| 1310 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1311 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1312 | return _nfs4_opendata_to_nfs4_state(data); |
| 1313 | } |
| 1314 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1315 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1316 | { |
| 1317 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1318 | struct nfs_open_context *ctx; |
| 1319 | |
| 1320 | spin_lock(&state->inode->i_lock); |
| 1321 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1322 | if (ctx->state != state) |
| 1323 | continue; |
| 1324 | get_nfs_open_context(ctx); |
| 1325 | spin_unlock(&state->inode->i_lock); |
| 1326 | return ctx; |
| 1327 | } |
| 1328 | spin_unlock(&state->inode->i_lock); |
| 1329 | return ERR_PTR(-ENOENT); |
| 1330 | } |
| 1331 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1332 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1333 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1334 | { |
| 1335 | struct nfs4_opendata *opendata; |
| 1336 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1337 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1338 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1339 | if (opendata == NULL) |
| 1340 | return ERR_PTR(-ENOMEM); |
| 1341 | opendata->state = state; |
| 1342 | atomic_inc(&state->count); |
| 1343 | return opendata; |
| 1344 | } |
| 1345 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1346 | 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] | 1347 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1348 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1349 | int ret; |
| 1350 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1351 | opendata->o_arg.open_flags = 0; |
| 1352 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1353 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1354 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1355 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1356 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1357 | if (ret != 0) |
| 1358 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1359 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1360 | if (IS_ERR(newstate)) |
| 1361 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1362 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1363 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1364 | return 0; |
| 1365 | } |
| 1366 | |
| 1367 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1368 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1369 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1370 | int ret; |
| 1371 | |
| 1372 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1373 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1374 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1375 | smp_rmb(); |
| 1376 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1377 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1378 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1379 | if (ret != 0) |
| 1380 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1381 | if (newstate != state) |
| 1382 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1383 | } |
| 1384 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1385 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1386 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1387 | if (ret != 0) |
| 1388 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1389 | if (newstate != state) |
| 1390 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1391 | } |
| 1392 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1393 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1394 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1395 | if (ret != 0) |
| 1396 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1397 | if (newstate != state) |
| 1398 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1399 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1400 | /* |
| 1401 | * We may have performed cached opens for all three recoveries. |
| 1402 | * Check if we need to update the current stateid. |
| 1403 | */ |
| 1404 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1405 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1406 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1407 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1408 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1409 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1410 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1411 | return 0; |
| 1412 | } |
| 1413 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | /* |
| 1415 | * OPEN_RECLAIM: |
| 1416 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1418 | 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] | 1419 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1420 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1421 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1422 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | int status; |
| 1424 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1425 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1426 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1427 | if (IS_ERR(opendata)) |
| 1428 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1429 | rcu_read_lock(); |
| 1430 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1431 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1432 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1433 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1434 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1435 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1436 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | return status; |
| 1438 | } |
| 1439 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1440 | 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] | 1441 | { |
| 1442 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1443 | struct nfs4_exception exception = { }; |
| 1444 | int err; |
| 1445 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1446 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1447 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1448 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1449 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1450 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1451 | break; |
| 1452 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | } while (exception.retry); |
| 1454 | return err; |
| 1455 | } |
| 1456 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1457 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1458 | { |
| 1459 | struct nfs_open_context *ctx; |
| 1460 | int ret; |
| 1461 | |
| 1462 | ctx = nfs4_state_find_open_context(state); |
| 1463 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1464 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1465 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1466 | put_nfs_open_context(ctx); |
| 1467 | return ret; |
| 1468 | } |
| 1469 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1470 | 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] | 1471 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1472 | switch (err) { |
| 1473 | default: |
| 1474 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1475 | "%d.\n", __func__, err); |
| 1476 | case 0: |
| 1477 | case -ENOENT: |
| 1478 | case -ESTALE: |
| 1479 | break; |
| 1480 | case -NFS4ERR_BADSESSION: |
| 1481 | case -NFS4ERR_BADSLOT: |
| 1482 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1483 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1484 | case -NFS4ERR_DEADSESSION: |
| 1485 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1486 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1487 | return -EAGAIN; |
| 1488 | case -NFS4ERR_STALE_CLIENTID: |
| 1489 | case -NFS4ERR_STALE_STATEID: |
| 1490 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1491 | case -NFS4ERR_EXPIRED: |
| 1492 | /* Don't recall a delegation if it was lost */ |
| 1493 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1494 | return -EAGAIN; |
| 1495 | case -NFS4ERR_DELEG_REVOKED: |
| 1496 | case -NFS4ERR_ADMIN_REVOKED: |
| 1497 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1498 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1499 | nfs_inode_find_state_and_recover(state->inode, |
| 1500 | stateid); |
| 1501 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1502 | return 0; |
| 1503 | case -NFS4ERR_DELAY: |
| 1504 | case -NFS4ERR_GRACE: |
| 1505 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1506 | ssleep(1); |
| 1507 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1508 | case -ENOMEM: |
| 1509 | case -NFS4ERR_DENIED: |
| 1510 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1511 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1512 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | return err; |
| 1514 | } |
| 1515 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1516 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
| 1517 | { |
| 1518 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1519 | struct nfs4_opendata *opendata; |
| 1520 | int err; |
| 1521 | |
| 1522 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1523 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1524 | if (IS_ERR(opendata)) |
| 1525 | return PTR_ERR(opendata); |
| 1526 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
| 1527 | err = nfs4_open_recover(opendata, state); |
| 1528 | nfs4_opendata_put(opendata); |
| 1529 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1530 | } |
| 1531 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1532 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1533 | { |
| 1534 | struct nfs4_opendata *data = calldata; |
| 1535 | |
| 1536 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1537 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1538 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1539 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1540 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1541 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1542 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | static void nfs4_open_confirm_release(void *calldata) |
| 1546 | { |
| 1547 | struct nfs4_opendata *data = calldata; |
| 1548 | struct nfs4_state *state = NULL; |
| 1549 | |
| 1550 | /* If this request hasn't been cancelled, do nothing */ |
| 1551 | if (data->cancelled == 0) |
| 1552 | goto out_free; |
| 1553 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1554 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1555 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1556 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1557 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1558 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1559 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1560 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1561 | } |
| 1562 | |
| 1563 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1564 | .rpc_call_done = nfs4_open_confirm_done, |
| 1565 | .rpc_release = nfs4_open_confirm_release, |
| 1566 | }; |
| 1567 | |
| 1568 | /* |
| 1569 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1570 | */ |
| 1571 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1572 | { |
| 1573 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1574 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1575 | struct rpc_message msg = { |
| 1576 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1577 | .rpc_argp = &data->c_arg, |
| 1578 | .rpc_resp = &data->c_res, |
| 1579 | .rpc_cred = data->owner->so_cred, |
| 1580 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1581 | struct rpc_task_setup task_setup_data = { |
| 1582 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1583 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1584 | .callback_ops = &nfs4_open_confirm_ops, |
| 1585 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1586 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1587 | .flags = RPC_TASK_ASYNC, |
| 1588 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | int status; |
| 1590 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1591 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1592 | data->rpc_done = 0; |
| 1593 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1594 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1595 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1596 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1597 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1598 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1599 | if (status != 0) { |
| 1600 | data->cancelled = 1; |
| 1601 | smp_wmb(); |
| 1602 | } else |
| 1603 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1604 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | return status; |
| 1606 | } |
| 1607 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1608 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1610 | struct nfs4_opendata *data = calldata; |
| 1611 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1612 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1613 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1614 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1615 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1616 | /* |
| 1617 | * Check if we still need to send an OPEN call, or if we can use |
| 1618 | * a delegation instead. |
| 1619 | */ |
| 1620 | if (data->state != NULL) { |
| 1621 | struct nfs_delegation *delegation; |
| 1622 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1623 | 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] | 1624 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1625 | rcu_read_lock(); |
| 1626 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1627 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
Trond Myklebust | cd4c9be | 2013-04-23 14:46:25 -0400 | [diff] [blame] | 1628 | data->o_arg.claim != NFS4_OPEN_CLAIM_DELEG_CUR_FH && |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1629 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1630 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1631 | rcu_read_unlock(); |
| 1632 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1633 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1634 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1635 | switch (data->o_arg.claim) { |
| 1636 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1637 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1638 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1639 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1640 | case NFS4_OPEN_CLAIM_FH: |
| 1641 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1642 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1643 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1644 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1645 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1646 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1647 | &data->o_res.seq_res, |
| 1648 | task) != 0) |
| 1649 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1650 | |
| 1651 | /* Set the create mode (note dependency on the session type) */ |
| 1652 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 1653 | if (data->o_arg.open_flags & O_EXCL) { |
| 1654 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 1655 | if (nfs4_has_persistent_session(clp)) |
| 1656 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 1657 | else if (clp->cl_mvops->minor_version > 0) |
| 1658 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 1659 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1660 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1661 | unlock_no_action: |
| 1662 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1663 | out_no_action: |
| 1664 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1665 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1666 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1667 | } |
| 1668 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1669 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1670 | { |
| 1671 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1673 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1674 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1675 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1676 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1677 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1678 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1679 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1680 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1681 | case S_IFREG: |
| 1682 | break; |
| 1683 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1684 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1685 | break; |
| 1686 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1687 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1688 | break; |
| 1689 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1690 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1691 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1692 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1693 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1694 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1695 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1696 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1697 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1698 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1699 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1700 | static void nfs4_open_release(void *calldata) |
| 1701 | { |
| 1702 | struct nfs4_opendata *data = calldata; |
| 1703 | struct nfs4_state *state = NULL; |
| 1704 | |
| 1705 | /* If this request hasn't been cancelled, do nothing */ |
| 1706 | if (data->cancelled == 0) |
| 1707 | goto out_free; |
| 1708 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1709 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1710 | goto out_free; |
| 1711 | /* In case we need an open_confirm, no cleanup! */ |
| 1712 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1713 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1714 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1715 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1716 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1717 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1718 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1722 | .rpc_call_prepare = nfs4_open_prepare, |
| 1723 | .rpc_call_done = nfs4_open_done, |
| 1724 | .rpc_release = nfs4_open_release, |
| 1725 | }; |
| 1726 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1727 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1728 | { |
| 1729 | struct inode *dir = data->dir->d_inode; |
| 1730 | struct nfs_server *server = NFS_SERVER(dir); |
| 1731 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1732 | struct nfs_openres *o_res = &data->o_res; |
| 1733 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1734 | struct rpc_message msg = { |
| 1735 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1736 | .rpc_argp = o_arg, |
| 1737 | .rpc_resp = o_res, |
| 1738 | .rpc_cred = data->owner->so_cred, |
| 1739 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1740 | struct rpc_task_setup task_setup_data = { |
| 1741 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1742 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1743 | .callback_ops = &nfs4_open_ops, |
| 1744 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1745 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1746 | .flags = RPC_TASK_ASYNC, |
| 1747 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1748 | int status; |
| 1749 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1750 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1751 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1752 | data->rpc_done = 0; |
| 1753 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1754 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1755 | data->is_recover = 0; |
| 1756 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1757 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1758 | data->is_recover = 1; |
| 1759 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1760 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1761 | if (IS_ERR(task)) |
| 1762 | return PTR_ERR(task); |
| 1763 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1764 | if (status != 0) { |
| 1765 | data->cancelled = 1; |
| 1766 | smp_wmb(); |
| 1767 | } else |
| 1768 | status = data->rpc_status; |
| 1769 | rpc_put_task(task); |
| 1770 | |
| 1771 | return status; |
| 1772 | } |
| 1773 | |
| 1774 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1775 | { |
| 1776 | struct inode *dir = data->dir->d_inode; |
| 1777 | struct nfs_openres *o_res = &data->o_res; |
| 1778 | int status; |
| 1779 | |
| 1780 | status = nfs4_run_open_task(data, 1); |
| 1781 | if (status != 0 || !data->rpc_done) |
| 1782 | return status; |
| 1783 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1784 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1785 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1786 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1787 | status = _nfs4_proc_open_confirm(data); |
| 1788 | if (status != 0) |
| 1789 | return status; |
| 1790 | } |
| 1791 | |
| 1792 | return status; |
| 1793 | } |
| 1794 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1795 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1796 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1797 | struct nfs4_state *state, fmode_t fmode, |
| 1798 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1799 | { |
| 1800 | struct nfs_access_entry cache; |
| 1801 | u32 mask; |
| 1802 | |
| 1803 | /* access call failed or for some reason the server doesn't |
| 1804 | * support any access modes -- defer access call until later */ |
| 1805 | if (opendata->o_res.access_supported == 0) |
| 1806 | return 0; |
| 1807 | |
| 1808 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1809 | /* 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] | 1810 | * write mode bits, but POSIX allows the creating process to write. |
| 1811 | * use openflags to check for exec, because fmode won't |
| 1812 | * always have FMODE_EXEC set when file open for exec. */ |
| 1813 | if (openflags & __FMODE_EXEC) { |
| 1814 | /* ONLY check for exec rights */ |
| 1815 | mask = MAY_EXEC; |
| 1816 | } else if (fmode & FMODE_READ) |
| 1817 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1818 | |
| 1819 | cache.cred = cred; |
| 1820 | cache.jiffies = jiffies; |
| 1821 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1822 | nfs_access_add_cache(state->inode, &cache); |
| 1823 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1824 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1825 | return 0; |
| 1826 | |
| 1827 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1828 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1829 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1830 | } |
| 1831 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1832 | /* |
| 1833 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1834 | */ |
| 1835 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1836 | { |
| 1837 | struct inode *dir = data->dir->d_inode; |
| 1838 | struct nfs_server *server = NFS_SERVER(dir); |
| 1839 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1840 | struct nfs_openres *o_res = &data->o_res; |
| 1841 | int status; |
| 1842 | |
| 1843 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1844 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1845 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1846 | if (status != 0) { |
| 1847 | if (status == -NFS4ERR_BADNAME && |
| 1848 | !(o_arg->open_flags & O_CREAT)) |
| 1849 | return -ENOENT; |
| 1850 | return status; |
| 1851 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1852 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1853 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1854 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1855 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1856 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1857 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1858 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1860 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1862 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | } |
| 1864 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1865 | _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] | 1866 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | } |
| 1868 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1869 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1870 | { |
| 1871 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1872 | } |
| 1873 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | /* |
| 1875 | * OPEN_EXPIRED: |
| 1876 | * reclaim state on the server after a network partition. |
| 1877 | * Assumes caller holds the appropriate lock |
| 1878 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1879 | 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] | 1880 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1881 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1882 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1884 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1885 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1886 | if (IS_ERR(opendata)) |
| 1887 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1888 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1889 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1890 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1891 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1892 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | } |
| 1894 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1895 | 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] | 1896 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1897 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1898 | struct nfs4_exception exception = { }; |
| 1899 | int err; |
| 1900 | |
| 1901 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1902 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1903 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1904 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1905 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1906 | switch (err) { |
| 1907 | default: |
| 1908 | goto out; |
| 1909 | case -NFS4ERR_GRACE: |
| 1910 | case -NFS4ERR_DELAY: |
| 1911 | nfs4_handle_exception(server, err, &exception); |
| 1912 | err = 0; |
| 1913 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1914 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1915 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1916 | return err; |
| 1917 | } |
| 1918 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1920 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1922 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1924 | ctx = nfs4_state_find_open_context(state); |
| 1925 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1926 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1927 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1928 | put_nfs_open_context(ctx); |
| 1929 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | } |
| 1931 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1932 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1933 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1934 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1935 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1936 | nfs4_stateid *stateid = &state->stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1937 | struct nfs_delegation *delegation; |
| 1938 | struct rpc_cred *cred = NULL; |
| 1939 | int status = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1940 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1941 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1942 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1943 | return; |
| 1944 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1945 | /* Get the delegation credential for use by test/free_stateid */ |
| 1946 | rcu_read_lock(); |
| 1947 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1948 | if (delegation != NULL && |
| 1949 | nfs4_stateid_match(&delegation->stateid, stateid)) { |
| 1950 | cred = get_rpccred(delegation->cred); |
| 1951 | rcu_read_unlock(); |
| 1952 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 1953 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1954 | } else |
| 1955 | rcu_read_unlock(); |
| 1956 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1957 | if (status != NFS_OK) { |
| 1958 | /* Free the stateid unless the server explicitly |
| 1959 | * informs us the stateid is unrecognized. */ |
| 1960 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1961 | nfs41_free_stateid(server, stateid, cred); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1962 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1963 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1964 | write_seqlock(&state->seqlock); |
| 1965 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1966 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1967 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1968 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1969 | |
| 1970 | if (cred != NULL) |
| 1971 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | /** |
| 1975 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1976 | * |
| 1977 | * @state: NFSv4 state for an inode |
| 1978 | * |
| 1979 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1980 | * Otherwise a negative NFS4ERR value is returned. |
| 1981 | */ |
| 1982 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1983 | { |
| 1984 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1985 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1986 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1987 | int status; |
| 1988 | |
| 1989 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1990 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1991 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1992 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1993 | return -NFS4ERR_BAD_STATEID; |
| 1994 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1995 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 1996 | trace_nfs4_test_open_stateid(state, NULL, status); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1997 | if (status != NFS_OK) { |
| 1998 | /* Free the stateid unless the server explicitly |
| 1999 | * informs us the stateid is unrecognized. */ |
| 2000 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2001 | nfs41_free_stateid(server, stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2002 | |
| 2003 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2004 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2005 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2006 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2007 | } |
| 2008 | return status; |
| 2009 | } |
| 2010 | |
| 2011 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2012 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2013 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2014 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2015 | nfs41_clear_delegation_stateid(state); |
| 2016 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2017 | if (status != NFS_OK) |
| 2018 | status = nfs4_open_expired(sp, state); |
| 2019 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2020 | } |
| 2021 | #endif |
| 2022 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2024 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2025 | * fields corresponding to attributes that were used to store the verifier. |
| 2026 | * Make sure we clobber those fields in the later setattr call |
| 2027 | */ |
| 2028 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 2029 | { |
| 2030 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 2031 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2032 | sattr->ia_valid |= ATTR_ATIME; |
| 2033 | |
| 2034 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 2035 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2036 | sattr->ia_valid |= ATTR_MTIME; |
| 2037 | } |
| 2038 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2039 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2040 | fmode_t fmode, |
| 2041 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2042 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2043 | { |
| 2044 | struct nfs4_state_owner *sp = opendata->owner; |
| 2045 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2046 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2047 | struct nfs4_state *state; |
| 2048 | unsigned int seq; |
| 2049 | int ret; |
| 2050 | |
| 2051 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2052 | |
| 2053 | ret = _nfs4_proc_open(opendata); |
| 2054 | if (ret != 0) |
| 2055 | goto out; |
| 2056 | |
| 2057 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2058 | ret = PTR_ERR(state); |
| 2059 | if (IS_ERR(state)) |
| 2060 | goto out; |
| 2061 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2062 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 2063 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2064 | dentry = opendata->dentry; |
| 2065 | if (dentry->d_inode == NULL) { |
| 2066 | /* FIXME: Is this d_drop() ever needed? */ |
| 2067 | d_drop(dentry); |
| 2068 | dentry = d_add_unique(dentry, igrab(state->inode)); |
| 2069 | if (dentry == NULL) { |
| 2070 | dentry = opendata->dentry; |
| 2071 | } else if (dentry != ctx->dentry) { |
| 2072 | dput(ctx->dentry); |
| 2073 | ctx->dentry = dget(dentry); |
| 2074 | } |
| 2075 | nfs_set_verifier(dentry, |
| 2076 | nfs_save_change_attribute(opendata->dir->d_inode)); |
| 2077 | } |
| 2078 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2079 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2080 | if (ret != 0) |
| 2081 | goto out; |
| 2082 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2083 | ctx->state = state; |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2084 | if (dentry->d_inode == state->inode) { |
| 2085 | nfs_inode_attach_open_context(ctx); |
| 2086 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2087 | nfs4_schedule_stateid_recovery(server, state); |
| 2088 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2089 | out: |
| 2090 | return ret; |
| 2091 | } |
| 2092 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2093 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2094 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2096 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2097 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2098 | int flags, |
| 2099 | struct iattr *sattr, |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2100 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | { |
| 2102 | struct nfs4_state_owner *sp; |
| 2103 | struct nfs4_state *state = NULL; |
| 2104 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2105 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2106 | struct dentry *dentry = ctx->dentry; |
| 2107 | struct rpc_cred *cred = ctx->cred; |
| 2108 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2109 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2110 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2111 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2112 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | |
| 2114 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2116 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2117 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2119 | goto out_err; |
| 2120 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2121 | status = nfs4_recover_expired_lease(server); |
| 2122 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2123 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2124 | if (dentry->d_inode != NULL) |
| 2125 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2126 | status = -ENOMEM; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2127 | if (dentry->d_inode) |
| 2128 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2129 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2130 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2131 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2132 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2134 | if (label) { |
| 2135 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2136 | if (IS_ERR(olabel)) { |
| 2137 | status = PTR_ERR(olabel); |
| 2138 | goto err_opendata_put; |
| 2139 | } |
| 2140 | } |
| 2141 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2142 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2143 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2144 | if (!opendata->f_attr.mdsthreshold) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2145 | goto err_free_label; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2146 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2147 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2148 | if (dentry->d_inode != NULL) |
| 2149 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2150 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2151 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2152 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2153 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2154 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2155 | |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2156 | if ((opendata->o_arg.open_flags & O_EXCL) && |
| 2157 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2158 | nfs4_exclusive_attrset(opendata, sattr); |
| 2159 | |
| 2160 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2161 | status = nfs4_do_setattr(state->inode, cred, |
| 2162 | opendata->o_res.f_attr, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2163 | state, label, olabel); |
| 2164 | if (status == 0) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2165 | nfs_setattr_update_inode(state->inode, sattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2166 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2167 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2168 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2169 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2170 | |
| 2171 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 2172 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 2173 | else |
| 2174 | kfree(opendata->f_attr.mdsthreshold); |
| 2175 | opendata->f_attr.mdsthreshold = NULL; |
| 2176 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2177 | nfs4_label_free(olabel); |
| 2178 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2179 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2182 | err_free_label: |
| 2183 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2184 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2185 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2186 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2187 | err_put_state_owner: |
| 2188 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | return status; |
| 2191 | } |
| 2192 | |
| 2193 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2194 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2195 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2196 | int flags, |
| 2197 | struct iattr *sattr, |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2198 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2200 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | struct nfs4_exception exception = { }; |
| 2202 | struct nfs4_state *res; |
| 2203 | int status; |
| 2204 | |
| 2205 | do { |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2206 | status = _nfs4_do_open(dir, ctx, flags, sattr, label); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2207 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2208 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | if (status == 0) |
| 2210 | break; |
| 2211 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2212 | * book-keeping w.r.t. state-changing operations |
| 2213 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2214 | * It is actually a sign of a bug on the client or on the server. |
| 2215 | * |
| 2216 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2217 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | * have unhashed the old state_owner for us, and that we can |
| 2219 | * therefore safely retry using a new one. We should still warn |
| 2220 | * the user though... |
| 2221 | */ |
| 2222 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2223 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2224 | " returned a bad sequence-id error!\n", |
| 2225 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2226 | exception.retry = 1; |
| 2227 | continue; |
| 2228 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2229 | /* |
| 2230 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2231 | * state before it received the OPEN_CONFIRM. |
| 2232 | * Recover by retrying the request as per the discussion |
| 2233 | * on Page 181 of RFC3530. |
| 2234 | */ |
| 2235 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2236 | exception.retry = 1; |
| 2237 | continue; |
| 2238 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2239 | if (status == -EAGAIN) { |
| 2240 | /* We must have found a delegation */ |
| 2241 | exception.retry = 1; |
| 2242 | continue; |
| 2243 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2244 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2245 | continue; |
| 2246 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2247 | status, &exception)); |
| 2248 | } while (exception.retry); |
| 2249 | return res; |
| 2250 | } |
| 2251 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2252 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2253 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2254 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2255 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2257 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2259 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | .iap = sattr, |
| 2261 | .server = server, |
| 2262 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2263 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2264 | }; |
| 2265 | struct nfs_setattrres res = { |
| 2266 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2267 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | .server = server, |
| 2269 | }; |
| 2270 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2271 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2272 | .rpc_argp = &arg, |
| 2273 | .rpc_resp = &res, |
| 2274 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2276 | unsigned long timestamp = jiffies; |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2277 | fmode_t fmode; |
| 2278 | bool truncate; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2279 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2281 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2282 | if (ilabel) |
| 2283 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2284 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2285 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2287 | /* Servers should only apply open mode checks for file size changes */ |
| 2288 | truncate = (sattr->ia_valid & ATTR_SIZE) ? true : false; |
| 2289 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2290 | |
| 2291 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) { |
| 2292 | /* Use that stateid */ |
| 2293 | } else if (truncate && state != NULL && nfs4_valid_open_stateid(state)) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2294 | struct nfs_lockowner lockowner = { |
| 2295 | .l_owner = current->files, |
| 2296 | .l_pid = current->tgid, |
| 2297 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2298 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2299 | &lockowner); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2300 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2301 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2303 | 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] | 2304 | if (status == 0 && state != NULL) |
| 2305 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2306 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2307 | } |
| 2308 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2309 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2310 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2311 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2312 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2314 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2315 | struct nfs4_exception exception = { |
| 2316 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2317 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2318 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2319 | int err; |
| 2320 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2321 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state, ilabel, olabel); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 2322 | trace_nfs4_setattr(inode, err); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2323 | switch (err) { |
| 2324 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2325 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2326 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2327 | "applying open mode checks to " |
| 2328 | "a SETATTR that is not " |
| 2329 | "changing file size.\n", |
| 2330 | server->nfs_client->cl_hostname); |
| 2331 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2332 | if (state && !(state->state & FMODE_WRITE)) { |
| 2333 | err = -EBADF; |
| 2334 | if (sattr->ia_valid & ATTR_OPEN) |
| 2335 | err = -EACCES; |
| 2336 | goto out; |
| 2337 | } |
| 2338 | } |
| 2339 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2341 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | return err; |
| 2343 | } |
| 2344 | |
| 2345 | struct nfs4_closedata { |
| 2346 | struct inode *inode; |
| 2347 | struct nfs4_state *state; |
| 2348 | struct nfs_closeargs arg; |
| 2349 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2350 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2351 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2352 | bool roc; |
| 2353 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2354 | }; |
| 2355 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2356 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2357 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2358 | struct nfs4_closedata *calldata = data; |
| 2359 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2360 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2361 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2362 | if (calldata->roc) |
| 2363 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2364 | nfs4_put_open_state(calldata->state); |
| 2365 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2366 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2367 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2368 | kfree(calldata); |
| 2369 | } |
| 2370 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2371 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2372 | fmode_t fmode) |
| 2373 | { |
| 2374 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2375 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2376 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 2377 | case FMODE_WRITE: |
| 2378 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2379 | break; |
| 2380 | case FMODE_READ: |
| 2381 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2382 | break; |
| 2383 | case 0: |
| 2384 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2385 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2386 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 2387 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2388 | spin_unlock(&state->owner->so_lock); |
| 2389 | } |
| 2390 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2391 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2393 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2396 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2397 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2398 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2399 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2400 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2401 | /* hmm. we are done with the inode, and in the process of freeing |
| 2402 | * the state_owner. we keep this around to process errors |
| 2403 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | switch (task->tk_status) { |
| 2405 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2406 | if (calldata->roc) |
| 2407 | pnfs_roc_set_barrier(state->inode, |
| 2408 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2409 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2410 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2411 | nfs4_close_clear_stateid_flags(state, |
| 2412 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2413 | break; |
| 2414 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2415 | case -NFS4ERR_OLD_STATEID: |
| 2416 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2418 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2419 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2421 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2422 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2424 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2425 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2426 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2427 | } |
| 2428 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2429 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2431 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2432 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2433 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2434 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2435 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2436 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2437 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2438 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2439 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2440 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2441 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2442 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2443 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2444 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2445 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2446 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2447 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2448 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2449 | } |
| 2450 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2451 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2452 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2453 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2454 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2455 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2456 | if (!nfs4_valid_open_stateid(state)) |
| 2457 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2458 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2459 | |
| 2460 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2461 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2462 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2463 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2464 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2465 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2466 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2467 | if (calldata->roc && |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2468 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) { |
| 2469 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2470 | goto out_wait; |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2471 | } |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2472 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2473 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2474 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2475 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2476 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2477 | &calldata->arg.seq_args, |
| 2478 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2479 | task) != 0) |
| 2480 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2481 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2482 | return; |
| 2483 | out_no_action: |
| 2484 | task->tk_action = NULL; |
| 2485 | out_wait: |
| 2486 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | } |
| 2488 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2489 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2490 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2491 | .rpc_call_done = nfs4_close_done, |
| 2492 | .rpc_release = nfs4_free_closedata, |
| 2493 | }; |
| 2494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2495 | /* |
| 2496 | * It is possible for data to be read/written from a mem-mapped file |
| 2497 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2498 | * This means that we can't safely call nfsv4 close on a file until |
| 2499 | * the inode is cleared. This in turn means that we are not good |
| 2500 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2501 | * share state even when we are done with one of the three share |
| 2502 | * stateid's in the inode. |
| 2503 | * |
| 2504 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2505 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2506 | 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] | 2507 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2508 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2510 | struct nfs4_state_owner *sp = state->owner; |
| 2511 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2512 | struct rpc_message msg = { |
| 2513 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2514 | .rpc_cred = state->owner->so_cred, |
| 2515 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2516 | struct rpc_task_setup task_setup_data = { |
| 2517 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2518 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2519 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2520 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2521 | .flags = RPC_TASK_ASYNC, |
| 2522 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2523 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2525 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2526 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2527 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2528 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2529 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2531 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2532 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2533 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2534 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2535 | if (calldata->arg.seqid == NULL) |
| 2536 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2537 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2538 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2539 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2540 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2541 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2542 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2543 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2544 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2545 | msg.rpc_argp = &calldata->arg; |
| 2546 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2547 | task_setup_data.callback_data = calldata; |
| 2548 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2549 | if (IS_ERR(task)) |
| 2550 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2551 | status = 0; |
| 2552 | if (wait) |
| 2553 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2554 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2555 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2556 | out_free_calldata: |
| 2557 | kfree(calldata); |
| 2558 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2559 | nfs4_put_open_state(state); |
| 2560 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2561 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | } |
| 2563 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2564 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2565 | 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] | 2566 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2567 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2568 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 2569 | |
| 2570 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2571 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2572 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2573 | state = nfs4_do_open(dir, ctx, open_flags, attr, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2574 | |
| 2575 | nfs4_label_release_security(label); |
| 2576 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2577 | if (IS_ERR(state)) |
| 2578 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2579 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2580 | } |
| 2581 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2582 | 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] | 2583 | { |
| 2584 | if (ctx->state == NULL) |
| 2585 | return; |
| 2586 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2587 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2588 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2589 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2590 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | |
| 2592 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2593 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2594 | struct nfs4_server_caps_arg args = { |
| 2595 | .fhandle = fhandle, |
| 2596 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2597 | struct nfs4_server_caps_res res = {}; |
| 2598 | struct rpc_message msg = { |
| 2599 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2600 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2601 | .rpc_resp = &res, |
| 2602 | }; |
| 2603 | int status; |
| 2604 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2605 | 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] | 2606 | if (status == 0) { |
| 2607 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2608 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2609 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2610 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2611 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2612 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2614 | server->caps |= NFS_CAP_ACLS; |
| 2615 | if (res.has_links != 0) |
| 2616 | server->caps |= NFS_CAP_HARDLINKS; |
| 2617 | if (res.has_symlinks != 0) |
| 2618 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2619 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2620 | server->caps |= NFS_CAP_FILEID; |
| 2621 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2622 | server->caps |= NFS_CAP_MODE; |
| 2623 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2624 | server->caps |= NFS_CAP_NLINK; |
| 2625 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2626 | server->caps |= NFS_CAP_OWNER; |
| 2627 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2628 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2629 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2630 | server->caps |= NFS_CAP_ATIME; |
| 2631 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2632 | server->caps |= NFS_CAP_CTIME; |
| 2633 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2634 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2635 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 2636 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2637 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 2638 | #endif |
| 2639 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 2640 | sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2641 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2642 | if (server->caps & NFS_CAP_SECURITY_LABEL) { |
| 2643 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2644 | res.attr_bitmask[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2645 | } |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2646 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2647 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2648 | 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] | 2649 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2650 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2651 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2652 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | return status; |
| 2654 | } |
| 2655 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2656 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2657 | { |
| 2658 | struct nfs4_exception exception = { }; |
| 2659 | int err; |
| 2660 | do { |
| 2661 | err = nfs4_handle_exception(server, |
| 2662 | _nfs4_server_capabilities(server, fhandle), |
| 2663 | &exception); |
| 2664 | } while (exception.retry); |
| 2665 | return err; |
| 2666 | } |
| 2667 | |
| 2668 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2669 | struct nfs_fsinfo *info) |
| 2670 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2671 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2673 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2674 | }; |
| 2675 | struct nfs4_lookup_res res = { |
| 2676 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2677 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | .fh = fhandle, |
| 2679 | }; |
| 2680 | struct rpc_message msg = { |
| 2681 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2682 | .rpc_argp = &args, |
| 2683 | .rpc_resp = &res, |
| 2684 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2685 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2686 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 2687 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 2688 | /* |
| 2689 | * Process the label in the upcoming getfattr |
| 2690 | */ |
| 2691 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 2692 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2693 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2694 | 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] | 2695 | } |
| 2696 | |
| 2697 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2698 | struct nfs_fsinfo *info) |
| 2699 | { |
| 2700 | struct nfs4_exception exception = { }; |
| 2701 | int err; |
| 2702 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2703 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 2704 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2705 | switch (err) { |
| 2706 | case 0: |
| 2707 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2708 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2709 | default: |
| 2710 | err = nfs4_handle_exception(server, err, &exception); |
| 2711 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2712 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2713 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | return err; |
| 2715 | } |
| 2716 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2717 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2718 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2719 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame^] | 2720 | struct rpc_auth_create_args auth_args = { |
| 2721 | .pseudoflavor = flavor, |
| 2722 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2723 | struct rpc_auth *auth; |
| 2724 | int ret; |
| 2725 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame^] | 2726 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2727 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 2728 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2729 | goto out; |
| 2730 | } |
| 2731 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2732 | out: |
| 2733 | return ret; |
| 2734 | } |
| 2735 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2736 | /* |
| 2737 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 2738 | * |
| 2739 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 2740 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 2741 | * |
| 2742 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 2743 | * negative errno value. |
| 2744 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2745 | 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] | 2746 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2748 | /* Per 3530bis 15.33.5 */ |
| 2749 | static const rpc_authflavor_t flav_array[] = { |
| 2750 | RPC_AUTH_GSS_KRB5P, |
| 2751 | RPC_AUTH_GSS_KRB5I, |
| 2752 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 2753 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2754 | RPC_AUTH_NULL, |
| 2755 | }; |
| 2756 | int status = -EPERM; |
| 2757 | size_t i; |
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 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2760 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2761 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2762 | continue; |
| 2763 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2764 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2765 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2766 | /* |
| 2767 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2768 | * to access the mount. It could also mean that we tried to mount |
| 2769 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2770 | * existing mount programs don't handle -EACCES very well so it should |
| 2771 | * be mapped to -EPERM instead. |
| 2772 | */ |
| 2773 | if (status == -EACCES) |
| 2774 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2775 | return status; |
| 2776 | } |
| 2777 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2778 | static int nfs4_do_find_root_sec(struct nfs_server *server, |
| 2779 | struct nfs_fh *fhandle, struct nfs_fsinfo *info) |
| 2780 | { |
| 2781 | int mv = server->nfs_client->cl_minorversion; |
| 2782 | return nfs_v4_minor_ops[mv]->find_root_sec(server, fhandle, info); |
| 2783 | } |
| 2784 | |
| 2785 | /** |
| 2786 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 2787 | * @server: initialized nfs_server handle |
| 2788 | * @fhandle: we fill in the pseudo-fs root file handle |
| 2789 | * @info: we fill in an FSINFO struct |
| 2790 | * |
| 2791 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2792 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2793 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2794 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2795 | { |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2796 | int status; |
| 2797 | |
| 2798 | status = nfs4_lookup_root(server, fhandle, info); |
| 2799 | if ((status == -NFS4ERR_WRONGSEC) && |
| 2800 | !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2801 | status = nfs4_do_find_root_sec(server, fhandle, info); |
| 2802 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2803 | if (status == 0) |
| 2804 | status = nfs4_server_capabilities(server, fhandle); |
| 2805 | if (status == 0) |
| 2806 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2807 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2808 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2809 | } |
| 2810 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2811 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2812 | struct nfs_fsinfo *info) |
| 2813 | { |
| 2814 | int error; |
| 2815 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2816 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2817 | |
| 2818 | error = nfs4_server_capabilities(server, mntfh); |
| 2819 | if (error < 0) { |
| 2820 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2821 | return error; |
| 2822 | } |
| 2823 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2824 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 2825 | if (IS_ERR(label)) |
| 2826 | return PTR_ERR(label); |
| 2827 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2828 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2829 | if (error < 0) { |
| 2830 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2831 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2832 | } |
| 2833 | |
| 2834 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2835 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2836 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2837 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2838 | err_free_label: |
| 2839 | nfs4_label_free(label); |
| 2840 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2841 | return error; |
| 2842 | } |
| 2843 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2844 | /* |
| 2845 | * Get locations and (maybe) other attributes of a referral. |
| 2846 | * Note that we'll actually follow the referral later when |
| 2847 | * we detect fsid mismatch in inode revalidation |
| 2848 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2849 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2850 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2851 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2852 | { |
| 2853 | int status = -ENOMEM; |
| 2854 | struct page *page = NULL; |
| 2855 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2856 | |
| 2857 | page = alloc_page(GFP_KERNEL); |
| 2858 | if (page == NULL) |
| 2859 | goto out; |
| 2860 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2861 | if (locations == NULL) |
| 2862 | goto out; |
| 2863 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2864 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2865 | if (status != 0) |
| 2866 | goto out; |
| 2867 | /* Make sure server returned a different fsid for the referral */ |
| 2868 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2869 | dprintk("%s: server did not return a different fsid for" |
| 2870 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2871 | status = -EIO; |
| 2872 | goto out; |
| 2873 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2874 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2875 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2876 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2877 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2878 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2879 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2880 | out: |
| 2881 | if (page) |
| 2882 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2883 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2884 | return status; |
| 2885 | } |
| 2886 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2887 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2888 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | { |
| 2890 | struct nfs4_getattr_arg args = { |
| 2891 | .fh = fhandle, |
| 2892 | .bitmask = server->attr_bitmask, |
| 2893 | }; |
| 2894 | struct nfs4_getattr_res res = { |
| 2895 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2896 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | .server = server, |
| 2898 | }; |
| 2899 | struct rpc_message msg = { |
| 2900 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2901 | .rpc_argp = &args, |
| 2902 | .rpc_resp = &res, |
| 2903 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2904 | |
| 2905 | args.bitmask = nfs4_bitmask(server, label); |
| 2906 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2907 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2908 | 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] | 2909 | } |
| 2910 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2911 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2912 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | { |
| 2914 | struct nfs4_exception exception = { }; |
| 2915 | int err; |
| 2916 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 2917 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 2918 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 2919 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | &exception); |
| 2921 | } while (exception.retry); |
| 2922 | return err; |
| 2923 | } |
| 2924 | |
| 2925 | /* |
| 2926 | * The file is not closed if it is opened due to the a request to change |
| 2927 | * the size of the file. The open call will not be needed once the |
| 2928 | * VFS layer lookup-intents are implemented. |
| 2929 | * |
| 2930 | * Close is called when the inode is destroyed. |
| 2931 | * If we haven't opened the file for O_WRONLY, we |
| 2932 | * need to in the size_change case to obtain a stateid. |
| 2933 | * |
| 2934 | * Got race? |
| 2935 | * Because OPEN is always done by name in nfsv4, it is |
| 2936 | * possible that we opened a different file by the same |
| 2937 | * name. We can recognize this race condition, but we |
| 2938 | * can't do anything about it besides returning an error. |
| 2939 | * |
| 2940 | * This will be fixed with VFS changes (lookup-intent). |
| 2941 | */ |
| 2942 | static int |
| 2943 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2944 | struct iattr *sattr) |
| 2945 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2946 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2947 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2948 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2949 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | int status; |
| 2951 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2952 | if (pnfs_ld_layoutret_on_setattr(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 2953 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2954 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2955 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2957 | /* Deal with open(O_TRUNC) */ |
| 2958 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 2959 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2960 | |
| 2961 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 2962 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2963 | return 0; |
| 2964 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2965 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2966 | if (sattr->ia_valid & ATTR_FILE) { |
| 2967 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2968 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2969 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2970 | if (ctx) { |
| 2971 | cred = ctx->cred; |
| 2972 | state = ctx->state; |
| 2973 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2974 | } |
| 2975 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2976 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 2977 | if (IS_ERR(label)) |
| 2978 | return PTR_ERR(label); |
| 2979 | |
| 2980 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2981 | if (status == 0) { |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2982 | nfs_setattr_update_inode(inode, sattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2983 | nfs_setsecurity(inode, fattr, label); |
| 2984 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2985 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | return status; |
| 2987 | } |
| 2988 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2989 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2990 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2991 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2992 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2993 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2994 | int status; |
| 2995 | struct nfs4_lookup_arg args = { |
| 2996 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2997 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2998 | .name = name, |
| 2999 | }; |
| 3000 | struct nfs4_lookup_res res = { |
| 3001 | .server = server, |
| 3002 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3003 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3004 | .fh = fhandle, |
| 3005 | }; |
| 3006 | struct rpc_message msg = { |
| 3007 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3008 | .rpc_argp = &args, |
| 3009 | .rpc_resp = &res, |
| 3010 | }; |
| 3011 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3012 | args.bitmask = nfs4_bitmask(server, label); |
| 3013 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3014 | nfs_fattr_init(fattr); |
| 3015 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3017 | 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] | 3018 | dprintk("NFS reply lookup: %d\n", status); |
| 3019 | return status; |
| 3020 | } |
| 3021 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3022 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3023 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3024 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3025 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3026 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3027 | fattr->nlink = 2; |
| 3028 | } |
| 3029 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3030 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 3031 | struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3032 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3033 | { |
| 3034 | struct nfs4_exception exception = { }; |
| 3035 | struct rpc_clnt *client = *clnt; |
| 3036 | int err; |
| 3037 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3038 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3039 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3040 | switch (err) { |
| 3041 | case -NFS4ERR_BADNAME: |
| 3042 | err = -ENOENT; |
| 3043 | goto out; |
| 3044 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3045 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3046 | goto out; |
| 3047 | case -NFS4ERR_WRONGSEC: |
| 3048 | err = -EPERM; |
| 3049 | if (client != *clnt) |
| 3050 | goto out; |
| 3051 | |
| 3052 | client = nfs4_create_sec_client(client, dir, name); |
| 3053 | if (IS_ERR(client)) |
| 3054 | return PTR_ERR(client); |
| 3055 | |
| 3056 | exception.retry = 1; |
| 3057 | break; |
| 3058 | default: |
| 3059 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3060 | } |
| 3061 | } while (exception.retry); |
| 3062 | |
| 3063 | out: |
| 3064 | if (err == 0) |
| 3065 | *clnt = client; |
| 3066 | else if (client != *clnt) |
| 3067 | rpc_shutdown_client(client); |
| 3068 | |
| 3069 | return err; |
| 3070 | } |
| 3071 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 3072 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3073 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3074 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3075 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3076 | int status; |
| 3077 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3078 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3079 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3080 | if (client != NFS_CLIENT(dir)) { |
| 3081 | rpc_shutdown_client(client); |
| 3082 | nfs_fixup_secinfo_attributes(fattr); |
| 3083 | } |
| 3084 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | } |
| 3086 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3087 | struct rpc_clnt * |
| 3088 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 3089 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3090 | { |
| 3091 | int status; |
| 3092 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 3093 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3094 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3095 | if (status < 0) { |
| 3096 | rpc_shutdown_client(client); |
| 3097 | return ERR_PTR(status); |
| 3098 | } |
| 3099 | return client; |
| 3100 | } |
| 3101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3103 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3104 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3105 | struct nfs4_accessargs args = { |
| 3106 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3107 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3108 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3109 | struct nfs4_accessres res = { |
| 3110 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3111 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3112 | struct rpc_message msg = { |
| 3113 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3114 | .rpc_argp = &args, |
| 3115 | .rpc_resp = &res, |
| 3116 | .rpc_cred = entry->cred, |
| 3117 | }; |
| 3118 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3119 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | |
| 3121 | /* |
| 3122 | * Determine which access bits we want to ask for... |
| 3123 | */ |
| 3124 | if (mode & MAY_READ) |
| 3125 | args.access |= NFS4_ACCESS_READ; |
| 3126 | if (S_ISDIR(inode->i_mode)) { |
| 3127 | if (mode & MAY_WRITE) |
| 3128 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3129 | if (mode & MAY_EXEC) |
| 3130 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3131 | } else { |
| 3132 | if (mode & MAY_WRITE) |
| 3133 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3134 | if (mode & MAY_EXEC) |
| 3135 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3136 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3137 | |
| 3138 | res.fattr = nfs_alloc_fattr(); |
| 3139 | if (res.fattr == NULL) |
| 3140 | return -ENOMEM; |
| 3141 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3142 | 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] | 3143 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3144 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3145 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3146 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3147 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | return status; |
| 3149 | } |
| 3150 | |
| 3151 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3152 | { |
| 3153 | struct nfs4_exception exception = { }; |
| 3154 | int err; |
| 3155 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3156 | err = _nfs4_proc_access(inode, entry); |
| 3157 | trace_nfs4_access(inode, err); |
| 3158 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | &exception); |
| 3160 | } while (exception.retry); |
| 3161 | return err; |
| 3162 | } |
| 3163 | |
| 3164 | /* |
| 3165 | * TODO: For the time being, we don't try to get any attributes |
| 3166 | * along with any of the zero-copy operations READ, READDIR, |
| 3167 | * READLINK, WRITE. |
| 3168 | * |
| 3169 | * In the case of the first three, we want to put the GETATTR |
| 3170 | * after the read-type operation -- this is because it is hard |
| 3171 | * to predict the length of a GETATTR response in v4, and thus |
| 3172 | * align the READ data correctly. This means that the GETATTR |
| 3173 | * may end up partially falling into the page cache, and we should |
| 3174 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3175 | * To do this efficiently, we need to know the total length |
| 3176 | * of data received, which doesn't seem to be available outside |
| 3177 | * of the RPC layer. |
| 3178 | * |
| 3179 | * In the case of WRITE, we also want to put the GETATTR after |
| 3180 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3181 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | * |
| 3183 | * Both of these changes to the XDR layer would in fact be quite |
| 3184 | * minor, but I decided to leave them for a subsequent patch. |
| 3185 | */ |
| 3186 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3187 | unsigned int pgbase, unsigned int pglen) |
| 3188 | { |
| 3189 | struct nfs4_readlink args = { |
| 3190 | .fh = NFS_FH(inode), |
| 3191 | .pgbase = pgbase, |
| 3192 | .pglen = pglen, |
| 3193 | .pages = &page, |
| 3194 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3195 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | struct rpc_message msg = { |
| 3197 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3198 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3199 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | }; |
| 3201 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3202 | 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] | 3203 | } |
| 3204 | |
| 3205 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3206 | unsigned int pgbase, unsigned int pglen) |
| 3207 | { |
| 3208 | struct nfs4_exception exception = { }; |
| 3209 | int err; |
| 3210 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3211 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3212 | trace_nfs4_readlink(inode, err); |
| 3213 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | &exception); |
| 3215 | } while (exception.retry); |
| 3216 | return err; |
| 3217 | } |
| 3218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3220 | * 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] | 3221 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3222 | static int |
| 3223 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3224 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3226 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3227 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | int status = 0; |
| 3230 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3231 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3232 | if (IS_ERR(ctx)) |
| 3233 | return PTR_ERR(ctx); |
| 3234 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3235 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3236 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3237 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 3238 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | if (IS_ERR(state)) { |
| 3240 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3241 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3244 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3245 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | return status; |
| 3247 | } |
| 3248 | |
| 3249 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3250 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3251 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3252 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3253 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3254 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3256 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3257 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3258 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3260 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3261 | .rpc_argp = &args, |
| 3262 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3263 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3264 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3265 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3266 | 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] | 3267 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3268 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3269 | return status; |
| 3270 | } |
| 3271 | |
| 3272 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3273 | { |
| 3274 | struct nfs4_exception exception = { }; |
| 3275 | int err; |
| 3276 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3277 | err = _nfs4_proc_remove(dir, name); |
| 3278 | trace_nfs4_remove(dir, name, err); |
| 3279 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3280 | &exception); |
| 3281 | } while (exception.retry); |
| 3282 | return err; |
| 3283 | } |
| 3284 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3285 | 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] | 3286 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3287 | struct nfs_server *server = NFS_SERVER(dir); |
| 3288 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3289 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3291 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3292 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3293 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3294 | |
| 3295 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | } |
| 3297 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3298 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3299 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3300 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 3301 | &data->args.seq_args, |
| 3302 | &data->res.seq_res, |
| 3303 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3304 | } |
| 3305 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3306 | 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] | 3307 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3308 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 3309 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3310 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3311 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3312 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3313 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3314 | return 0; |
| 3315 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3316 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3317 | } |
| 3318 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3319 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3320 | { |
| 3321 | struct nfs_server *server = NFS_SERVER(dir); |
| 3322 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3323 | struct nfs_renameres *res = msg->rpc_resp; |
| 3324 | |
| 3325 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3326 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3327 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3328 | } |
| 3329 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3330 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3331 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3332 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3333 | &data->args.seq_args, |
| 3334 | &data->res.seq_res, |
| 3335 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3336 | } |
| 3337 | |
| 3338 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3339 | struct inode *new_dir) |
| 3340 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 3341 | struct nfs_renamedata *data = task->tk_calldata; |
| 3342 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3343 | |
| 3344 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3345 | return 0; |
| 3346 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 3347 | return 0; |
| 3348 | |
| 3349 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3350 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3351 | return 1; |
| 3352 | } |
| 3353 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3355 | struct inode *new_dir, struct qstr *new_name) |
| 3356 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3357 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 3358 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3359 | .old_dir = NFS_FH(old_dir), |
| 3360 | .new_dir = NFS_FH(new_dir), |
| 3361 | .old_name = old_name, |
| 3362 | .new_name = new_name, |
| 3363 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3364 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3365 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3366 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | struct rpc_message msg = { |
| 3368 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3369 | .rpc_argp = &arg, |
| 3370 | .rpc_resp = &res, |
| 3371 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3372 | int status = -ENOMEM; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3373 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3374 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | if (!status) { |
| 3376 | update_changeattr(old_dir, &res.old_cinfo); |
| 3377 | update_changeattr(new_dir, &res.new_cinfo); |
| 3378 | } |
| 3379 | return status; |
| 3380 | } |
| 3381 | |
| 3382 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3383 | struct inode *new_dir, struct qstr *new_name) |
| 3384 | { |
| 3385 | struct nfs4_exception exception = { }; |
| 3386 | int err; |
| 3387 | do { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 3388 | err = _nfs4_proc_rename(old_dir, old_name, |
| 3389 | new_dir, new_name); |
| 3390 | trace_nfs4_rename(old_dir, old_name, new_dir, new_name, err); |
| 3391 | err = nfs4_handle_exception(NFS_SERVER(old_dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3392 | &exception); |
| 3393 | } while (exception.retry); |
| 3394 | return err; |
| 3395 | } |
| 3396 | |
| 3397 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3398 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3399 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3400 | struct nfs4_link_arg arg = { |
| 3401 | .fh = NFS_FH(inode), |
| 3402 | .dir_fh = NFS_FH(dir), |
| 3403 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3404 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3405 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3406 | struct nfs4_link_res res = { |
| 3407 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3408 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3409 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3410 | struct rpc_message msg = { |
| 3411 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3412 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3413 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3414 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3415 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3416 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3417 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3418 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3419 | goto out; |
| 3420 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3421 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3422 | if (IS_ERR(res.label)) { |
| 3423 | status = PTR_ERR(res.label); |
| 3424 | goto out; |
| 3425 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3426 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3427 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3428 | 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] | 3429 | if (!status) { |
| 3430 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3431 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 3432 | if (!status) |
| 3433 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3434 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3435 | |
| 3436 | |
| 3437 | nfs4_label_free(res.label); |
| 3438 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3439 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3440 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3441 | return status; |
| 3442 | } |
| 3443 | |
| 3444 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3445 | { |
| 3446 | struct nfs4_exception exception = { }; |
| 3447 | int err; |
| 3448 | do { |
| 3449 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3450 | _nfs4_proc_link(inode, dir, name), |
| 3451 | &exception); |
| 3452 | } while (exception.retry); |
| 3453 | return err; |
| 3454 | } |
| 3455 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3456 | struct nfs4_createdata { |
| 3457 | struct rpc_message msg; |
| 3458 | struct nfs4_create_arg arg; |
| 3459 | struct nfs4_create_res res; |
| 3460 | struct nfs_fh fh; |
| 3461 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3462 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3463 | }; |
| 3464 | |
| 3465 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3466 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3467 | { |
| 3468 | struct nfs4_createdata *data; |
| 3469 | |
| 3470 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3471 | if (data != NULL) { |
| 3472 | struct nfs_server *server = NFS_SERVER(dir); |
| 3473 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3474 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3475 | if (IS_ERR(data->label)) |
| 3476 | goto out_free; |
| 3477 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3478 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3479 | data->msg.rpc_argp = &data->arg; |
| 3480 | data->msg.rpc_resp = &data->res; |
| 3481 | data->arg.dir_fh = NFS_FH(dir); |
| 3482 | data->arg.server = server; |
| 3483 | data->arg.name = name; |
| 3484 | data->arg.attrs = sattr; |
| 3485 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3486 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3487 | data->res.server = server; |
| 3488 | data->res.fh = &data->fh; |
| 3489 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3490 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3491 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3492 | } |
| 3493 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3494 | out_free: |
| 3495 | kfree(data); |
| 3496 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3497 | } |
| 3498 | |
| 3499 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3500 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3501 | 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] | 3502 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3503 | if (status == 0) { |
| 3504 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3505 | 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] | 3506 | } |
| 3507 | return status; |
| 3508 | } |
| 3509 | |
| 3510 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3511 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3512 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3513 | kfree(data); |
| 3514 | } |
| 3515 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3516 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3517 | struct page *page, unsigned int len, struct iattr *sattr, |
| 3518 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3519 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3520 | struct nfs4_createdata *data; |
| 3521 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3522 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3523 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3524 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3525 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3526 | status = -ENOMEM; |
| 3527 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3528 | if (data == NULL) |
| 3529 | goto out; |
| 3530 | |
| 3531 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3532 | data->arg.u.symlink.pages = &page; |
| 3533 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3534 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3536 | status = nfs4_do_create(dir, dentry, data); |
| 3537 | |
| 3538 | nfs4_free_createdata(data); |
| 3539 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3540 | return status; |
| 3541 | } |
| 3542 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3543 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3544 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3545 | { |
| 3546 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3547 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3548 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3549 | |
| 3550 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3552 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3553 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 3554 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 3555 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3556 | &exception); |
| 3557 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3558 | |
| 3559 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3560 | return err; |
| 3561 | } |
| 3562 | |
| 3563 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3564 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3565 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3566 | struct nfs4_createdata *data; |
| 3567 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3568 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3569 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3570 | if (data == NULL) |
| 3571 | goto out; |
| 3572 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3573 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3574 | status = nfs4_do_create(dir, dentry, data); |
| 3575 | |
| 3576 | nfs4_free_createdata(data); |
| 3577 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3578 | return status; |
| 3579 | } |
| 3580 | |
| 3581 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3582 | struct iattr *sattr) |
| 3583 | { |
| 3584 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3585 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3586 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3587 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3588 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3589 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3590 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3591 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3592 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 3593 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 3594 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | &exception); |
| 3596 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3597 | nfs4_label_release_security(label); |
| 3598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3599 | return err; |
| 3600 | } |
| 3601 | |
| 3602 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3603 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3604 | { |
| 3605 | struct inode *dir = dentry->d_inode; |
| 3606 | struct nfs4_readdir_arg args = { |
| 3607 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3608 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3609 | .pgbase = 0, |
| 3610 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3611 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3612 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3613 | }; |
| 3614 | struct nfs4_readdir_res res; |
| 3615 | struct rpc_message msg = { |
| 3616 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3617 | .rpc_argp = &args, |
| 3618 | .rpc_resp = &res, |
| 3619 | .rpc_cred = cred, |
| 3620 | }; |
| 3621 | int status; |
| 3622 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3623 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3624 | dentry->d_parent->d_name.name, |
| 3625 | dentry->d_name.name, |
| 3626 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3627 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3628 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3629 | 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] | 3630 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3631 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3632 | status += args.pgbase; |
| 3633 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3634 | |
| 3635 | nfs_invalidate_atime(dir); |
| 3636 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3637 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3638 | return status; |
| 3639 | } |
| 3640 | |
| 3641 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3642 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3643 | { |
| 3644 | struct nfs4_exception exception = { }; |
| 3645 | int err; |
| 3646 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3647 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 3648 | pages, count, plus); |
| 3649 | trace_nfs4_readdir(dentry->d_inode, err); |
| 3650 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3651 | &exception); |
| 3652 | } while (exception.retry); |
| 3653 | return err; |
| 3654 | } |
| 3655 | |
| 3656 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3657 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3658 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3659 | struct nfs4_createdata *data; |
| 3660 | int mode = sattr->ia_mode; |
| 3661 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3662 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3663 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3664 | if (data == NULL) |
| 3665 | goto out; |
| 3666 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3667 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3668 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3669 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3670 | data->arg.ftype = NF4BLK; |
| 3671 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3672 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3673 | } |
| 3674 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3675 | data->arg.ftype = NF4CHR; |
| 3676 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3677 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3678 | } else if (!S_ISSOCK(mode)) { |
| 3679 | status = -EINVAL; |
| 3680 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3681 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3682 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3683 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3684 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3685 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3686 | nfs4_free_createdata(data); |
| 3687 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | return status; |
| 3689 | } |
| 3690 | |
| 3691 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3692 | struct iattr *sattr, dev_t rdev) |
| 3693 | { |
| 3694 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3695 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3697 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3698 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3699 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3700 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3701 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3702 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 3703 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 3704 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3705 | &exception); |
| 3706 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3707 | |
| 3708 | nfs4_label_release_security(label); |
| 3709 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3710 | return err; |
| 3711 | } |
| 3712 | |
| 3713 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3714 | struct nfs_fsstat *fsstat) |
| 3715 | { |
| 3716 | struct nfs4_statfs_arg args = { |
| 3717 | .fh = fhandle, |
| 3718 | .bitmask = server->attr_bitmask, |
| 3719 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3720 | struct nfs4_statfs_res res = { |
| 3721 | .fsstat = fsstat, |
| 3722 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3723 | struct rpc_message msg = { |
| 3724 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3725 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3726 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3727 | }; |
| 3728 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3729 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3730 | 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] | 3731 | } |
| 3732 | |
| 3733 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3734 | { |
| 3735 | struct nfs4_exception exception = { }; |
| 3736 | int err; |
| 3737 | do { |
| 3738 | err = nfs4_handle_exception(server, |
| 3739 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3740 | &exception); |
| 3741 | } while (exception.retry); |
| 3742 | return err; |
| 3743 | } |
| 3744 | |
| 3745 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3746 | struct nfs_fsinfo *fsinfo) |
| 3747 | { |
| 3748 | struct nfs4_fsinfo_arg args = { |
| 3749 | .fh = fhandle, |
| 3750 | .bitmask = server->attr_bitmask, |
| 3751 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3752 | struct nfs4_fsinfo_res res = { |
| 3753 | .fsinfo = fsinfo, |
| 3754 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | struct rpc_message msg = { |
| 3756 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3757 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3758 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3759 | }; |
| 3760 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3761 | 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] | 3762 | } |
| 3763 | |
| 3764 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3765 | { |
| 3766 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3767 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3768 | int err; |
| 3769 | |
| 3770 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3771 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3772 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3773 | if (err == 0) { |
| 3774 | struct nfs_client *clp = server->nfs_client; |
| 3775 | |
| 3776 | spin_lock(&clp->cl_lock); |
| 3777 | clp->cl_lease_time = fsinfo->lease_time * HZ; |
| 3778 | clp->cl_last_renewal = now; |
| 3779 | spin_unlock(&clp->cl_lock); |
| 3780 | break; |
| 3781 | } |
| 3782 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3783 | } while (exception.retry); |
| 3784 | return err; |
| 3785 | } |
| 3786 | |
| 3787 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3788 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3789 | int error; |
| 3790 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3791 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3792 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3793 | if (error == 0) { |
| 3794 | /* block layout checks this! */ |
| 3795 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3796 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3797 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3798 | |
| 3799 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3800 | } |
| 3801 | |
| 3802 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3803 | struct nfs_pathconf *pathconf) |
| 3804 | { |
| 3805 | struct nfs4_pathconf_arg args = { |
| 3806 | .fh = fhandle, |
| 3807 | .bitmask = server->attr_bitmask, |
| 3808 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3809 | struct nfs4_pathconf_res res = { |
| 3810 | .pathconf = pathconf, |
| 3811 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | struct rpc_message msg = { |
| 3813 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3814 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3815 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3816 | }; |
| 3817 | |
| 3818 | /* None of the pathconf attributes are mandatory to implement */ |
| 3819 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3820 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3821 | return 0; |
| 3822 | } |
| 3823 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3824 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3825 | 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] | 3826 | } |
| 3827 | |
| 3828 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3829 | struct nfs_pathconf *pathconf) |
| 3830 | { |
| 3831 | struct nfs4_exception exception = { }; |
| 3832 | int err; |
| 3833 | |
| 3834 | do { |
| 3835 | err = nfs4_handle_exception(server, |
| 3836 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3837 | &exception); |
| 3838 | } while (exception.retry); |
| 3839 | return err; |
| 3840 | } |
| 3841 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3842 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3843 | const struct nfs_open_context *ctx, |
| 3844 | const struct nfs_lock_context *l_ctx, |
| 3845 | fmode_t fmode) |
| 3846 | { |
| 3847 | const struct nfs_lockowner *lockowner = NULL; |
| 3848 | |
| 3849 | if (l_ctx != NULL) |
| 3850 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3851 | return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3852 | } |
| 3853 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 3854 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3855 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 3856 | const struct nfs_open_context *ctx, |
| 3857 | const struct nfs_lock_context *l_ctx, |
| 3858 | fmode_t fmode) |
| 3859 | { |
| 3860 | nfs4_stateid current_stateid; |
| 3861 | |
| 3862 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode)) |
| 3863 | return false; |
| 3864 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 3865 | } |
| 3866 | |
| 3867 | static bool nfs4_error_stateid_expired(int err) |
| 3868 | { |
| 3869 | switch (err) { |
| 3870 | case -NFS4ERR_DELEG_REVOKED: |
| 3871 | case -NFS4ERR_ADMIN_REVOKED: |
| 3872 | case -NFS4ERR_BAD_STATEID: |
| 3873 | case -NFS4ERR_STALE_STATEID: |
| 3874 | case -NFS4ERR_OLD_STATEID: |
| 3875 | case -NFS4ERR_OPENMODE: |
| 3876 | case -NFS4ERR_EXPIRED: |
| 3877 | return true; |
| 3878 | } |
| 3879 | return false; |
| 3880 | } |
| 3881 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3882 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3883 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3884 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3885 | } |
| 3886 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3887 | 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] | 3888 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3889 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3890 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 3891 | trace_nfs4_read(data, task->tk_status); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3892 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3893 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3894 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3895 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3896 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3897 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3898 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3899 | renew_lease(server, data->timestamp); |
| 3900 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3901 | } |
| 3902 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3903 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
| 3904 | struct nfs_readargs *args) |
| 3905 | { |
| 3906 | |
| 3907 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3908 | nfs4_stateid_is_current(&args->stateid, |
| 3909 | args->context, |
| 3910 | args->lock_context, |
| 3911 | FMODE_READ)) |
| 3912 | return false; |
| 3913 | rpc_restart_call_prepare(task); |
| 3914 | return true; |
| 3915 | } |
| 3916 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3917 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3918 | { |
| 3919 | |
| 3920 | dprintk("--> %s\n", __func__); |
| 3921 | |
| 3922 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3923 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3924 | if (nfs4_read_stateid_changed(task, &data->args)) |
| 3925 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3926 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3927 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3928 | } |
| 3929 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3930 | 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] | 3931 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3932 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3933 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3934 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3935 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3936 | } |
| 3937 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3938 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3939 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3940 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3941 | &data->args.seq_args, |
| 3942 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3943 | task)) |
| 3944 | return; |
| 3945 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 3946 | data->args.lock_context, FMODE_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3947 | } |
| 3948 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3949 | 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] | 3950 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3951 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3952 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 3953 | trace_nfs4_write(data, task->tk_status); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3954 | 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] | 3955 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3956 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3957 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3958 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3959 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3960 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3961 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3962 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3963 | } |
| 3964 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3965 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
| 3966 | struct nfs_writeargs *args) |
| 3967 | { |
| 3968 | |
| 3969 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3970 | nfs4_stateid_is_current(&args->stateid, |
| 3971 | args->context, |
| 3972 | args->lock_context, |
| 3973 | FMODE_WRITE)) |
| 3974 | return false; |
| 3975 | rpc_restart_call_prepare(task); |
| 3976 | return true; |
| 3977 | } |
| 3978 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3979 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3980 | { |
| 3981 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3982 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3983 | if (nfs4_write_stateid_changed(task, &data->args)) |
| 3984 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3985 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3986 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3987 | } |
| 3988 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3989 | static |
| 3990 | 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] | 3991 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3992 | const struct nfs_pgio_header *hdr = data->header; |
| 3993 | |
| 3994 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3995 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3996 | return false; |
| 3997 | /* Otherwise, request attributes if and only if we don't hold |
| 3998 | * a delegation |
| 3999 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4000 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4001 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4002 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4003 | 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] | 4004 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 4005 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4006 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4007 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4008 | data->args.bitmask = NULL; |
| 4009 | data->res.fattr = NULL; |
| 4010 | } else |
| 4011 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4012 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4013 | if (!data->write_done_cb) |
| 4014 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4015 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4016 | data->timestamp = jiffies; |
| 4017 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4018 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4019 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4020 | } |
| 4021 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 4022 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 4023 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4024 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4025 | &data->args.seq_args, |
| 4026 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4027 | task)) |
| 4028 | return; |
| 4029 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 4030 | data->args.lock_context, FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4031 | } |
| 4032 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4033 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4034 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4035 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4036 | &data->args.seq_args, |
| 4037 | &data->res.seq_res, |
| 4038 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 | } |
| 4040 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4041 | 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] | 4042 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4044 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4045 | trace_nfs4_commit(data, task->tk_status); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4046 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4047 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4048 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4049 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4050 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4051 | } |
| 4052 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4053 | 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] | 4054 | { |
| 4055 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4056 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4057 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4058 | } |
| 4059 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4060 | 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] | 4061 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4062 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4063 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4064 | if (data->commit_done_cb == NULL) |
| 4065 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4066 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4067 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4068 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | } |
| 4070 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4071 | struct nfs4_renewdata { |
| 4072 | struct nfs_client *client; |
| 4073 | unsigned long timestamp; |
| 4074 | }; |
| 4075 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4076 | /* |
| 4077 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4078 | * standalone procedure for queueing an asynchronous RENEW. |
| 4079 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4080 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4081 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4082 | struct nfs4_renewdata *data = calldata; |
| 4083 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4084 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4085 | if (atomic_read(&clp->cl_count) > 1) |
| 4086 | nfs4_schedule_state_renewal(clp); |
| 4087 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4088 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4089 | } |
| 4090 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4091 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [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; |
| 4095 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4097 | trace_nfs4_renew_async(clp, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4098 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4099 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4100 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4101 | return; |
| 4102 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4103 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4104 | return; |
| 4105 | } |
| 4106 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4107 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4108 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4109 | } |
| 4110 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4111 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4112 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4113 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4114 | }; |
| 4115 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4116 | 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] | 4117 | { |
| 4118 | struct rpc_message msg = { |
| 4119 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4120 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4121 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4122 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4123 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4125 | if (renew_flags == 0) |
| 4126 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4127 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4128 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4129 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4130 | if (data == NULL) |
| 4131 | return -ENOMEM; |
| 4132 | data->client = clp; |
| 4133 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4134 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4135 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4136 | } |
| 4137 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4138 | 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] | 4139 | { |
| 4140 | struct rpc_message msg = { |
| 4141 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4142 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4143 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4144 | }; |
| 4145 | unsigned long now = jiffies; |
| 4146 | int status; |
| 4147 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4148 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4149 | if (status < 0) |
| 4150 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4151 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4152 | return 0; |
| 4153 | } |
| 4154 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4155 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4156 | { |
| 4157 | return (server->caps & NFS_CAP_ACLS) |
| 4158 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 4159 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 4160 | } |
| 4161 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4162 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4163 | * 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] | 4164 | * the stack. |
| 4165 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4166 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4167 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4168 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 4169 | struct page **pages, unsigned int *pgbase) |
| 4170 | { |
| 4171 | struct page *newpage, **spages; |
| 4172 | int rc = 0; |
| 4173 | size_t len; |
| 4174 | spages = pages; |
| 4175 | |
| 4176 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4177 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4178 | newpage = alloc_page(GFP_KERNEL); |
| 4179 | |
| 4180 | if (newpage == NULL) |
| 4181 | goto unwind; |
| 4182 | memcpy(page_address(newpage), buf, len); |
| 4183 | buf += len; |
| 4184 | buflen -= len; |
| 4185 | *pages++ = newpage; |
| 4186 | rc++; |
| 4187 | } while (buflen != 0); |
| 4188 | |
| 4189 | return rc; |
| 4190 | |
| 4191 | unwind: |
| 4192 | for(; rc > 0; rc--) |
| 4193 | __free_page(spages[rc-1]); |
| 4194 | return -ENOMEM; |
| 4195 | } |
| 4196 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4197 | struct nfs4_cached_acl { |
| 4198 | int cached; |
| 4199 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4200 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4201 | }; |
| 4202 | |
| 4203 | 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] | 4204 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4205 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4206 | |
| 4207 | spin_lock(&inode->i_lock); |
| 4208 | kfree(nfsi->nfs4_acl); |
| 4209 | nfsi->nfs4_acl = acl; |
| 4210 | spin_unlock(&inode->i_lock); |
| 4211 | } |
| 4212 | |
| 4213 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4214 | { |
| 4215 | nfs4_set_cached_acl(inode, NULL); |
| 4216 | } |
| 4217 | |
| 4218 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4219 | { |
| 4220 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4221 | struct nfs4_cached_acl *acl; |
| 4222 | int ret = -ENOENT; |
| 4223 | |
| 4224 | spin_lock(&inode->i_lock); |
| 4225 | acl = nfsi->nfs4_acl; |
| 4226 | if (acl == NULL) |
| 4227 | goto out; |
| 4228 | if (buf == NULL) /* user is just asking for length */ |
| 4229 | goto out_len; |
| 4230 | if (acl->cached == 0) |
| 4231 | goto out; |
| 4232 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4233 | if (acl->len > buflen) |
| 4234 | goto out; |
| 4235 | memcpy(buf, acl->data, acl->len); |
| 4236 | out_len: |
| 4237 | ret = acl->len; |
| 4238 | out: |
| 4239 | spin_unlock(&inode->i_lock); |
| 4240 | return ret; |
| 4241 | } |
| 4242 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4243 | 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] | 4244 | { |
| 4245 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4246 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4247 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4248 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4249 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4250 | if (acl == NULL) |
| 4251 | goto out; |
| 4252 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4253 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4254 | } else { |
| 4255 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4256 | if (acl == NULL) |
| 4257 | goto out; |
| 4258 | acl->cached = 0; |
| 4259 | } |
| 4260 | acl->len = acl_len; |
| 4261 | out: |
| 4262 | nfs4_set_cached_acl(inode, acl); |
| 4263 | } |
| 4264 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4265 | /* |
| 4266 | * The getxattr API returns the required buffer length when called with a |
| 4267 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4268 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4269 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4270 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4271 | * the cache. If not so, we throw away the page, and cache the required |
| 4272 | * length. The next getxattr call will then produce another round trip to |
| 4273 | * the server, this time with the input buf of the required size. |
| 4274 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4275 | 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] | 4276 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4277 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4278 | struct nfs_getaclargs args = { |
| 4279 | .fh = NFS_FH(inode), |
| 4280 | .acl_pages = pages, |
| 4281 | .acl_len = buflen, |
| 4282 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4283 | struct nfs_getaclres res = { |
| 4284 | .acl_len = buflen, |
| 4285 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4286 | struct rpc_message msg = { |
| 4287 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4288 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4289 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4290 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4291 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4292 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4293 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4294 | /* As long as we're doing a round trip to the server anyway, |
| 4295 | * let's be prepared for a page of acl data. */ |
| 4296 | if (npages == 0) |
| 4297 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4298 | if (npages > ARRAY_SIZE(pages)) |
| 4299 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4300 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4301 | for (i = 0; i < npages; i++) { |
| 4302 | pages[i] = alloc_page(GFP_KERNEL); |
| 4303 | if (!pages[i]) |
| 4304 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4305 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4306 | |
| 4307 | /* for decoding across pages */ |
| 4308 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4309 | if (!res.acl_scratch) |
| 4310 | goto out_free; |
| 4311 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4312 | args.acl_len = npages * PAGE_SIZE; |
| 4313 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4314 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4315 | 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] | 4316 | __func__, buf, buflen, npages, args.acl_len); |
| 4317 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4318 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4319 | if (ret) |
| 4320 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4321 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4322 | /* Handle the case where the passed-in buffer is too short */ |
| 4323 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4324 | /* Did the user only issue a request for the acl length? */ |
| 4325 | if (buf == NULL) |
| 4326 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4327 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4328 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4329 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4330 | 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] | 4331 | if (buf) { |
| 4332 | if (res.acl_len > buflen) { |
| 4333 | ret = -ERANGE; |
| 4334 | goto out_free; |
| 4335 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4336 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4337 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4338 | out_ok: |
| 4339 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4340 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4341 | for (i = 0; i < npages; i++) |
| 4342 | if (pages[i]) |
| 4343 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4344 | if (res.acl_scratch) |
| 4345 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4346 | return ret; |
| 4347 | } |
| 4348 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4349 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4350 | { |
| 4351 | struct nfs4_exception exception = { }; |
| 4352 | ssize_t ret; |
| 4353 | do { |
| 4354 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4355 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4356 | if (ret >= 0) |
| 4357 | break; |
| 4358 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4359 | } while (exception.retry); |
| 4360 | return ret; |
| 4361 | } |
| 4362 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4363 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4364 | { |
| 4365 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4366 | int ret; |
| 4367 | |
| 4368 | if (!nfs4_server_supports_acls(server)) |
| 4369 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4370 | ret = nfs_revalidate_inode(server, inode); |
| 4371 | if (ret < 0) |
| 4372 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4373 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4374 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4375 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4376 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4377 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4378 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4379 | return ret; |
| 4380 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4381 | } |
| 4382 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4383 | 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] | 4384 | { |
| 4385 | struct nfs_server *server = NFS_SERVER(inode); |
| 4386 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4387 | struct nfs_setaclargs arg = { |
| 4388 | .fh = NFS_FH(inode), |
| 4389 | .acl_pages = pages, |
| 4390 | .acl_len = buflen, |
| 4391 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4392 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4393 | struct rpc_message msg = { |
| 4394 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4395 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4396 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4397 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4398 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4399 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4400 | |
| 4401 | if (!nfs4_server_supports_acls(server)) |
| 4402 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4403 | if (npages > ARRAY_SIZE(pages)) |
| 4404 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4405 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4406 | if (i < 0) |
| 4407 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4408 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4409 | 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] | 4410 | |
| 4411 | /* |
| 4412 | * Free each page after tx, so the only ref left is |
| 4413 | * held by the network stack |
| 4414 | */ |
| 4415 | for (; i > 0; i--) |
| 4416 | put_page(pages[i-1]); |
| 4417 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4418 | /* |
| 4419 | * Acl update can result in inode attribute update. |
| 4420 | * so mark the attribute cache invalid. |
| 4421 | */ |
| 4422 | spin_lock(&inode->i_lock); |
| 4423 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4424 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4425 | nfs_access_zap_cache(inode); |
| 4426 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4427 | return ret; |
| 4428 | } |
| 4429 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4430 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4431 | { |
| 4432 | struct nfs4_exception exception = { }; |
| 4433 | int err; |
| 4434 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4435 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 4436 | trace_nfs4_set_acl(inode, err); |
| 4437 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4438 | &exception); |
| 4439 | } while (exception.retry); |
| 4440 | return err; |
| 4441 | } |
| 4442 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4443 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 4444 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 4445 | size_t buflen) |
| 4446 | { |
| 4447 | struct nfs_server *server = NFS_SERVER(inode); |
| 4448 | struct nfs_fattr fattr; |
| 4449 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 4450 | |
| 4451 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
| 4452 | struct nfs4_getattr_arg args = { |
| 4453 | .fh = NFS_FH(inode), |
| 4454 | .bitmask = bitmask, |
| 4455 | }; |
| 4456 | struct nfs4_getattr_res res = { |
| 4457 | .fattr = &fattr, |
| 4458 | .label = &label, |
| 4459 | .server = server, |
| 4460 | }; |
| 4461 | struct rpc_message msg = { |
| 4462 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 4463 | .rpc_argp = &args, |
| 4464 | .rpc_resp = &res, |
| 4465 | }; |
| 4466 | int ret; |
| 4467 | |
| 4468 | nfs_fattr_init(&fattr); |
| 4469 | |
| 4470 | ret = rpc_call_sync(server->client, &msg, 0); |
| 4471 | if (ret) |
| 4472 | return ret; |
| 4473 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 4474 | return -ENOENT; |
| 4475 | if (buflen < label.len) |
| 4476 | return -ERANGE; |
| 4477 | return 0; |
| 4478 | } |
| 4479 | |
| 4480 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 4481 | size_t buflen) |
| 4482 | { |
| 4483 | struct nfs4_exception exception = { }; |
| 4484 | int err; |
| 4485 | |
| 4486 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4487 | return -EOPNOTSUPP; |
| 4488 | |
| 4489 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4490 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 4491 | trace_nfs4_get_security_label(inode, err); |
| 4492 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4493 | &exception); |
| 4494 | } while (exception.retry); |
| 4495 | return err; |
| 4496 | } |
| 4497 | |
| 4498 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 4499 | struct nfs4_label *ilabel, |
| 4500 | struct nfs_fattr *fattr, |
| 4501 | struct nfs4_label *olabel) |
| 4502 | { |
| 4503 | |
| 4504 | struct iattr sattr = {0}; |
| 4505 | struct nfs_server *server = NFS_SERVER(inode); |
| 4506 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
| 4507 | struct nfs_setattrargs args = { |
| 4508 | .fh = NFS_FH(inode), |
| 4509 | .iap = &sattr, |
| 4510 | .server = server, |
| 4511 | .bitmask = bitmask, |
| 4512 | .label = ilabel, |
| 4513 | }; |
| 4514 | struct nfs_setattrres res = { |
| 4515 | .fattr = fattr, |
| 4516 | .label = olabel, |
| 4517 | .server = server, |
| 4518 | }; |
| 4519 | struct rpc_message msg = { |
| 4520 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 4521 | .rpc_argp = &args, |
| 4522 | .rpc_resp = &res, |
| 4523 | }; |
| 4524 | int status; |
| 4525 | |
| 4526 | nfs4_stateid_copy(&args.stateid, &zero_stateid); |
| 4527 | |
| 4528 | status = rpc_call_sync(server->client, &msg, 0); |
| 4529 | if (status) |
| 4530 | dprintk("%s failed: %d\n", __func__, status); |
| 4531 | |
| 4532 | return status; |
| 4533 | } |
| 4534 | |
| 4535 | static int nfs4_do_set_security_label(struct inode *inode, |
| 4536 | struct nfs4_label *ilabel, |
| 4537 | struct nfs_fattr *fattr, |
| 4538 | struct nfs4_label *olabel) |
| 4539 | { |
| 4540 | struct nfs4_exception exception = { }; |
| 4541 | int err; |
| 4542 | |
| 4543 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4544 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 4545 | fattr, olabel); |
| 4546 | trace_nfs4_set_security_label(inode, err); |
| 4547 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4548 | &exception); |
| 4549 | } while (exception.retry); |
| 4550 | return err; |
| 4551 | } |
| 4552 | |
| 4553 | static int |
| 4554 | nfs4_set_security_label(struct dentry *dentry, const void *buf, size_t buflen) |
| 4555 | { |
| 4556 | struct nfs4_label ilabel, *olabel = NULL; |
| 4557 | struct nfs_fattr fattr; |
| 4558 | struct rpc_cred *cred; |
| 4559 | struct inode *inode = dentry->d_inode; |
| 4560 | int status; |
| 4561 | |
| 4562 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4563 | return -EOPNOTSUPP; |
| 4564 | |
| 4565 | nfs_fattr_init(&fattr); |
| 4566 | |
| 4567 | ilabel.pi = 0; |
| 4568 | ilabel.lfs = 0; |
| 4569 | ilabel.label = (char *)buf; |
| 4570 | ilabel.len = buflen; |
| 4571 | |
| 4572 | cred = rpc_lookup_cred(); |
| 4573 | if (IS_ERR(cred)) |
| 4574 | return PTR_ERR(cred); |
| 4575 | |
| 4576 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 4577 | if (IS_ERR(olabel)) { |
| 4578 | status = -PTR_ERR(olabel); |
| 4579 | goto out; |
| 4580 | } |
| 4581 | |
| 4582 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 4583 | if (status == 0) |
| 4584 | nfs_setsecurity(inode, &fattr, olabel); |
| 4585 | |
| 4586 | nfs4_label_free(olabel); |
| 4587 | out: |
| 4588 | put_rpccred(cred); |
| 4589 | return status; |
| 4590 | } |
| 4591 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 4592 | |
| 4593 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4594 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4595 | 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] | 4596 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4597 | struct nfs_client *clp = server->nfs_client; |
| 4598 | |
| 4599 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4600 | return 0; |
| 4601 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4602 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4603 | case -NFS4ERR_ADMIN_REVOKED: |
| 4604 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 4605 | if (state == NULL) |
| 4606 | break; |
| 4607 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4608 | case -NFS4ERR_OPENMODE: |
| 4609 | if (state == NULL) |
| 4610 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4611 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4612 | goto stateid_invalid; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4613 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4614 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4615 | if (state != NULL) { |
| 4616 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4617 | goto stateid_invalid; |
| 4618 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4619 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4620 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4621 | nfs4_schedule_lease_recovery(clp); |
| 4622 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4623 | #if defined(CONFIG_NFS_V4_1) |
| 4624 | case -NFS4ERR_BADSESSION: |
| 4625 | case -NFS4ERR_BADSLOT: |
| 4626 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4627 | case -NFS4ERR_DEADSESSION: |
| 4628 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4629 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4630 | case -NFS4ERR_SEQ_MISORDERED: |
| 4631 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4632 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4633 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4634 | task->tk_status = 0; |
| 4635 | return -EAGAIN; |
| 4636 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4637 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4638 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4639 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4640 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 4641 | task->tk_status = 0; |
| 4642 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4643 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4644 | case -NFS4ERR_OLD_STATEID: |
| 4645 | task->tk_status = 0; |
| 4646 | return -EAGAIN; |
| 4647 | } |
| 4648 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4649 | return 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4650 | stateid_invalid: |
| 4651 | task->tk_status = -EIO; |
| 4652 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4653 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4654 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4655 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4656 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 4657 | task->tk_status = 0; |
| 4658 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4659 | } |
| 4660 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4661 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4662 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4663 | { |
| 4664 | __be32 verf[2]; |
| 4665 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4666 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4667 | /* An impossible timestamp guarantees this value |
| 4668 | * will never match a generated boot time. */ |
| 4669 | verf[0] = 0; |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 4670 | verf[1] = cpu_to_be32(NSEC_PER_SEC + 1); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4671 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4672 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 4673 | verf[0] = cpu_to_be32(nn->boot_time.tv_sec); |
| 4674 | verf[1] = cpu_to_be32(nn->boot_time.tv_nsec); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4675 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4676 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4677 | } |
| 4678 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4679 | static unsigned int |
| 4680 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4681 | char *buf, size_t len) |
| 4682 | { |
| 4683 | unsigned int result; |
| 4684 | |
| 4685 | rcu_read_lock(); |
| 4686 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4687 | clp->cl_ipaddr, |
| 4688 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4689 | RPC_DISPLAY_ADDR), |
| 4690 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4691 | RPC_DISPLAY_PROTO)); |
| 4692 | rcu_read_unlock(); |
| 4693 | return result; |
| 4694 | } |
| 4695 | |
| 4696 | static unsigned int |
| 4697 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4698 | char *buf, size_t len) |
| 4699 | { |
Trond Myklebust | 55b5929 | 2013-07-24 16:36:35 -0400 | [diff] [blame] | 4700 | const char *nodename = clp->cl_rpcclient->cl_nodename; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4701 | |
| 4702 | if (nfs4_client_id_uniquifier[0] != '\0') |
Trond Myklebust | 55b5929 | 2013-07-24 16:36:35 -0400 | [diff] [blame] | 4703 | return scnprintf(buf, len, "Linux NFSv%u.%u %s/%s", |
| 4704 | clp->rpc_ops->version, |
| 4705 | clp->cl_minorversion, |
| 4706 | nfs4_client_id_uniquifier, |
| 4707 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4708 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4709 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4710 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4711 | } |
| 4712 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4713 | /** |
| 4714 | * nfs4_proc_setclientid - Negotiate client ID |
| 4715 | * @clp: state data structure |
| 4716 | * @program: RPC program for NFSv4 callback service |
| 4717 | * @port: IP port number for NFS4 callback service |
| 4718 | * @cred: RPC credential to use for this call |
| 4719 | * @res: where to place the result |
| 4720 | * |
| 4721 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4722 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4723 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4724 | unsigned short port, struct rpc_cred *cred, |
| 4725 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4726 | { |
| 4727 | nfs4_verifier sc_verifier; |
| 4728 | struct nfs4_setclientid setclientid = { |
| 4729 | .sc_verifier = &sc_verifier, |
| 4730 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4731 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4732 | }; |
| 4733 | struct rpc_message msg = { |
| 4734 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4735 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4736 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4737 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4738 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4739 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4740 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4741 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4742 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4743 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4744 | setclientid.sc_name_len = |
| 4745 | nfs4_init_uniform_client_string(clp, |
| 4746 | setclientid.sc_name, |
| 4747 | sizeof(setclientid.sc_name)); |
| 4748 | else |
| 4749 | setclientid.sc_name_len = |
| 4750 | nfs4_init_nonuniform_client_string(clp, |
| 4751 | setclientid.sc_name, |
| 4752 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4753 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4754 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4755 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Djalal Harouni | fe2d539 | 2013-06-18 17:58:12 +0100 | [diff] [blame] | 4756 | sizeof(setclientid.sc_netid), "%s", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4757 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4758 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4759 | rcu_read_unlock(); |
| 4760 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4761 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4762 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4763 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4764 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4765 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4766 | setclientid.sc_name_len, setclientid.sc_name); |
| 4767 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4768 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4769 | dprintk("NFS reply setclientid: %d\n", status); |
| 4770 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4771 | } |
| 4772 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4773 | /** |
| 4774 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4775 | * @clp: state data structure |
| 4776 | * @res: result of a previous SETCLIENTID |
| 4777 | * @cred: RPC credential to use for this call |
| 4778 | * |
| 4779 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4780 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4781 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4782 | struct nfs4_setclientid_res *arg, |
| 4783 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4784 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4785 | struct rpc_message msg = { |
| 4786 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4787 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4788 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4789 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4790 | int status; |
| 4791 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4792 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4793 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4794 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4795 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4796 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4797 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4798 | return status; |
| 4799 | } |
| 4800 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4801 | struct nfs4_delegreturndata { |
| 4802 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4803 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4804 | struct nfs_fh fh; |
| 4805 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4806 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4807 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4808 | int rpc_status; |
| 4809 | }; |
| 4810 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4811 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4812 | { |
| 4813 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4814 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4815 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4816 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4817 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 4818 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4819 | switch (task->tk_status) { |
| 4820 | case -NFS4ERR_STALE_STATEID: |
| 4821 | case -NFS4ERR_EXPIRED: |
| 4822 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4823 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4824 | break; |
| 4825 | default: |
| 4826 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4827 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4828 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4829 | return; |
| 4830 | } |
| 4831 | } |
| 4832 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4833 | } |
| 4834 | |
| 4835 | static void nfs4_delegreturn_release(void *calldata) |
| 4836 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4837 | kfree(calldata); |
| 4838 | } |
| 4839 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4840 | #if defined(CONFIG_NFS_V4_1) |
| 4841 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4842 | { |
| 4843 | struct nfs4_delegreturndata *d_data; |
| 4844 | |
| 4845 | d_data = (struct nfs4_delegreturndata *)data; |
| 4846 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4847 | nfs4_setup_sequence(d_data->res.server, |
| 4848 | &d_data->args.seq_args, |
| 4849 | &d_data->res.seq_res, |
| 4850 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4851 | } |
| 4852 | #endif /* CONFIG_NFS_V4_1 */ |
| 4853 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4854 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4855 | #if defined(CONFIG_NFS_V4_1) |
| 4856 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4857 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4858 | .rpc_call_done = nfs4_delegreturn_done, |
| 4859 | .rpc_release = nfs4_delegreturn_release, |
| 4860 | }; |
| 4861 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4862 | 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] | 4863 | { |
| 4864 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4865 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4866 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4867 | struct rpc_message msg = { |
| 4868 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4869 | .rpc_cred = cred, |
| 4870 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4871 | struct rpc_task_setup task_setup_data = { |
| 4872 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4873 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4874 | .callback_ops = &nfs4_delegreturn_ops, |
| 4875 | .flags = RPC_TASK_ASYNC, |
| 4876 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4877 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4878 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4879 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4880 | if (data == NULL) |
| 4881 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4882 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4883 | data->args.fhandle = &data->fh; |
| 4884 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4885 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4886 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4887 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4888 | data->res.fattr = &data->fattr; |
| 4889 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4890 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4891 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4892 | data->rpc_status = 0; |
| 4893 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4894 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4895 | msg.rpc_argp = &data->args; |
| 4896 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4897 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4898 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4899 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4900 | if (!issync) |
| 4901 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4902 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4903 | if (status != 0) |
| 4904 | goto out; |
| 4905 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4906 | if (status == 0) |
| 4907 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4908 | else |
| 4909 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4910 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4911 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4912 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4913 | } |
| 4914 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4915 | 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] | 4916 | { |
| 4917 | struct nfs_server *server = NFS_SERVER(inode); |
| 4918 | struct nfs4_exception exception = { }; |
| 4919 | int err; |
| 4920 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4921 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 4922 | trace_nfs4_delegreturn(inode, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4923 | switch (err) { |
| 4924 | case -NFS4ERR_STALE_STATEID: |
| 4925 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4926 | case 0: |
| 4927 | return 0; |
| 4928 | } |
| 4929 | err = nfs4_handle_exception(server, err, &exception); |
| 4930 | } while (exception.retry); |
| 4931 | return err; |
| 4932 | } |
| 4933 | |
| 4934 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4935 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4936 | |
| 4937 | /* |
| 4938 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4939 | */ |
| 4940 | static unsigned long |
| 4941 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4942 | { |
Colin Cross | 416ad3c | 2013-05-06 23:50:06 +0000 | [diff] [blame] | 4943 | freezable_schedule_timeout_killable_unsafe(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4944 | timeout <<= 1; |
| 4945 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4946 | return NFS4_LOCK_MAXTIMEOUT; |
| 4947 | return timeout; |
| 4948 | } |
| 4949 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4950 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4951 | { |
| 4952 | struct inode *inode = state->inode; |
| 4953 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4954 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4955 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4956 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4957 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4958 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4959 | struct nfs_lockt_res res = { |
| 4960 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4961 | }; |
| 4962 | struct rpc_message msg = { |
| 4963 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4964 | .rpc_argp = &arg, |
| 4965 | .rpc_resp = &res, |
| 4966 | .rpc_cred = state->owner->so_cred, |
| 4967 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4968 | struct nfs4_lock_state *lsp; |
| 4969 | int status; |
| 4970 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4971 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4972 | status = nfs4_set_lock_state(state, request); |
| 4973 | if (status != 0) |
| 4974 | goto out; |
| 4975 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4976 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4977 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4978 | 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] | 4979 | switch (status) { |
| 4980 | case 0: |
| 4981 | request->fl_type = F_UNLCK; |
| 4982 | break; |
| 4983 | case -NFS4ERR_DENIED: |
| 4984 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4985 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4986 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4987 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4988 | return status; |
| 4989 | } |
| 4990 | |
| 4991 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4992 | { |
| 4993 | struct nfs4_exception exception = { }; |
| 4994 | int err; |
| 4995 | |
| 4996 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 4997 | err = _nfs4_proc_getlk(state, cmd, request); |
| 4998 | trace_nfs4_get_lock(request, state, cmd, err); |
| 4999 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5000 | &exception); |
| 5001 | } while (exception.retry); |
| 5002 | return err; |
| 5003 | } |
| 5004 | |
| 5005 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 5006 | { |
| 5007 | int res = 0; |
| 5008 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 5009 | case FL_POSIX: |
| 5010 | res = posix_lock_file_wait(file, fl); |
| 5011 | break; |
| 5012 | case FL_FLOCK: |
| 5013 | res = flock_lock_file_wait(file, fl); |
| 5014 | break; |
| 5015 | default: |
| 5016 | BUG(); |
| 5017 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5018 | return res; |
| 5019 | } |
| 5020 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5021 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5022 | struct nfs_locku_args arg; |
| 5023 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5024 | struct nfs4_lock_state *lsp; |
| 5025 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5026 | struct file_lock fl; |
| 5027 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5028 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5029 | }; |
| 5030 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5031 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5032 | struct nfs_open_context *ctx, |
| 5033 | struct nfs4_lock_state *lsp, |
| 5034 | struct nfs_seqid *seqid) |
| 5035 | { |
| 5036 | struct nfs4_unlockdata *p; |
| 5037 | struct inode *inode = lsp->ls_state->inode; |
| 5038 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5039 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5040 | if (p == NULL) |
| 5041 | return NULL; |
| 5042 | p->arg.fh = NFS_FH(inode); |
| 5043 | p->arg.fl = &p->fl; |
| 5044 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5045 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5046 | p->arg.stateid = &lsp->ls_stateid; |
| 5047 | p->lsp = lsp; |
| 5048 | atomic_inc(&lsp->ls_count); |
| 5049 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5050 | p->ctx = get_nfs_open_context(ctx); |
| 5051 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5052 | p->server = NFS_SERVER(inode); |
| 5053 | return p; |
| 5054 | } |
| 5055 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5056 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5057 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5058 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5059 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5060 | nfs4_put_lock_state(calldata->lsp); |
| 5061 | put_nfs_open_context(calldata->ctx); |
| 5062 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5063 | } |
| 5064 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5065 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5066 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5067 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5068 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5069 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5070 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5071 | switch (task->tk_status) { |
| 5072 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5073 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 5074 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5075 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5076 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5077 | case -NFS4ERR_BAD_STATEID: |
| 5078 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5079 | case -NFS4ERR_STALE_STATEID: |
| 5080 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5081 | break; |
| 5082 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5083 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5084 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5085 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5086 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5087 | } |
| 5088 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5089 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5090 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5091 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5092 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5093 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5094 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5095 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5096 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5097 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5098 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5099 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5100 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5101 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5102 | &calldata->res.seq_res, |
| 5103 | task) != 0) |
| 5104 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5105 | return; |
| 5106 | out_no_action: |
| 5107 | task->tk_action = NULL; |
| 5108 | out_wait: |
| 5109 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5110 | } |
| 5111 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5112 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5113 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5114 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5115 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5116 | }; |
| 5117 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5118 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5119 | struct nfs_open_context *ctx, |
| 5120 | struct nfs4_lock_state *lsp, |
| 5121 | struct nfs_seqid *seqid) |
| 5122 | { |
| 5123 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5124 | struct rpc_message msg = { |
| 5125 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5126 | .rpc_cred = ctx->cred, |
| 5127 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5128 | struct rpc_task_setup task_setup_data = { |
| 5129 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5130 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5131 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5132 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5133 | .flags = RPC_TASK_ASYNC, |
| 5134 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5135 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5136 | /* Ensure this is an unlock - when canceling a lock, the |
| 5137 | * canceled lock is passed in, and it won't be an unlock. |
| 5138 | */ |
| 5139 | fl->fl_type = F_UNLCK; |
| 5140 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5141 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5142 | if (data == NULL) { |
| 5143 | nfs_free_seqid(seqid); |
| 5144 | return ERR_PTR(-ENOMEM); |
| 5145 | } |
| 5146 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5147 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5148 | msg.rpc_argp = &data->arg; |
| 5149 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5150 | task_setup_data.callback_data = data; |
| 5151 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5152 | } |
| 5153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5154 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5155 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5156 | struct inode *inode = state->inode; |
| 5157 | struct nfs4_state_owner *sp = state->owner; |
| 5158 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5159 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5160 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5161 | struct rpc_task *task; |
| 5162 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5163 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5164 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5165 | status = nfs4_set_lock_state(state, request); |
| 5166 | /* Unlock _before_ we do the RPC call */ |
| 5167 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5168 | /* Exclude nfs_delegation_claim_locks() */ |
| 5169 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5170 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5171 | down_read(&nfsi->rwsem); |
| 5172 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 5173 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5174 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5175 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5176 | } |
| 5177 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5178 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5179 | if (status != 0) |
| 5180 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5181 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5182 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5183 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5184 | goto out; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5185 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5186 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5187 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5188 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5189 | 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] | 5190 | status = PTR_ERR(task); |
| 5191 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5192 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5193 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5194 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5195 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5196 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5197 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5198 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5199 | } |
| 5200 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5201 | struct nfs4_lockdata { |
| 5202 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5203 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5204 | struct nfs4_lock_state *lsp; |
| 5205 | struct nfs_open_context *ctx; |
| 5206 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5207 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5208 | int rpc_status; |
| 5209 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5210 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5211 | }; |
| 5212 | |
| 5213 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5214 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5215 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5216 | { |
| 5217 | struct nfs4_lockdata *p; |
| 5218 | struct inode *inode = lsp->ls_state->inode; |
| 5219 | struct nfs_server *server = NFS_SERVER(inode); |
| 5220 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5221 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5222 | if (p == NULL) |
| 5223 | return NULL; |
| 5224 | |
| 5225 | p->arg.fh = NFS_FH(inode); |
| 5226 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5227 | 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] | 5228 | if (p->arg.open_seqid == NULL) |
| 5229 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5230 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5231 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5232 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5233 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5234 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5235 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5236 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5237 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5238 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5239 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5240 | atomic_inc(&lsp->ls_count); |
| 5241 | p->ctx = get_nfs_open_context(ctx); |
| 5242 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5243 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5244 | out_free_seqid: |
| 5245 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5246 | out_free: |
| 5247 | kfree(p); |
| 5248 | return NULL; |
| 5249 | } |
| 5250 | |
| 5251 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 5252 | { |
| 5253 | struct nfs4_lockdata *data = calldata; |
| 5254 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5255 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5256 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5257 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5258 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5259 | /* Do we need to do an open_to_lock_owner? */ |
| 5260 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5261 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5262 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5263 | } |
Trond Myklebust | 8e472f3 | 2013-04-20 01:30:53 -0400 | [diff] [blame] | 5264 | data->arg.open_stateid = &state->open_stateid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5265 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5266 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5267 | } else |
| 5268 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5269 | if (!nfs4_valid_open_stateid(state)) { |
| 5270 | data->rpc_status = -EBADF; |
| 5271 | task->tk_action = NULL; |
| 5272 | goto out_release_open_seqid; |
| 5273 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5274 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5275 | if (nfs4_setup_sequence(data->server, |
| 5276 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5277 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5278 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5279 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5280 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5281 | nfs_release_seqid(data->arg.open_seqid); |
| 5282 | out_release_lock_seqid: |
| 5283 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5284 | out_wait: |
| 5285 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5286 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5287 | } |
| 5288 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5289 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 5290 | { |
| 5291 | struct nfs4_lockdata *data = calldata; |
| 5292 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5293 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5294 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5295 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5296 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5297 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5298 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5299 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5300 | if (data->rpc_status == 0) |
| 5301 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 5302 | else |
| 5303 | goto out; |
| 5304 | } |
| 5305 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5306 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5307 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 5308 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5309 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5310 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5311 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5312 | } |
| 5313 | |
| 5314 | static void nfs4_lock_release(void *calldata) |
| 5315 | { |
| 5316 | struct nfs4_lockdata *data = calldata; |
| 5317 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5318 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5319 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5320 | if (data->cancelled != 0) { |
| 5321 | struct rpc_task *task; |
| 5322 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 5323 | data->arg.lock_seqid); |
| 5324 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5325 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5326 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5327 | } else |
| 5328 | nfs_free_seqid(data->arg.lock_seqid); |
| 5329 | nfs4_put_lock_state(data->lsp); |
| 5330 | put_nfs_open_context(data->ctx); |
| 5331 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5332 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5333 | } |
| 5334 | |
| 5335 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 5336 | .rpc_call_prepare = nfs4_lock_prepare, |
| 5337 | .rpc_call_done = nfs4_lock_done, |
| 5338 | .rpc_release = nfs4_lock_release, |
| 5339 | }; |
| 5340 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5341 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 5342 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5343 | switch (error) { |
| 5344 | case -NFS4ERR_ADMIN_REVOKED: |
| 5345 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5346 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5347 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5348 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5349 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5350 | break; |
| 5351 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5352 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5353 | case -NFS4ERR_EXPIRED: |
| 5354 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5355 | }; |
| 5356 | } |
| 5357 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5358 | 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] | 5359 | { |
| 5360 | struct nfs4_lockdata *data; |
| 5361 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5362 | struct rpc_message msg = { |
| 5363 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 5364 | .rpc_cred = state->owner->so_cred, |
| 5365 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5366 | struct rpc_task_setup task_setup_data = { |
| 5367 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5368 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5369 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5370 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5371 | .flags = RPC_TASK_ASYNC, |
| 5372 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5373 | int ret; |
| 5374 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5375 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5376 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5377 | fl->fl_u.nfs4_fl.owner, |
| 5378 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5379 | if (data == NULL) |
| 5380 | return -ENOMEM; |
| 5381 | if (IS_SETLKW(cmd)) |
| 5382 | data->arg.block = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5383 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5384 | msg.rpc_argp = &data->arg; |
| 5385 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5386 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5387 | if (recovery_type > NFS_LOCK_NEW) { |
| 5388 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 5389 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 5390 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
| 5391 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5392 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5393 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5394 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5395 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 5396 | if (ret == 0) { |
| 5397 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5398 | if (ret) |
| 5399 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 5400 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5401 | } else |
| 5402 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5403 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5404 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5405 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5406 | } |
| 5407 | |
| 5408 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 5409 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5410 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5411 | struct nfs4_exception exception = { |
| 5412 | .inode = state->inode, |
| 5413 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5414 | int err; |
| 5415 | |
| 5416 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5417 | /* Cache the lock if possible... */ |
| 5418 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5419 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5420 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5421 | trace_nfs4_lock_reclaim(request, state, F_SETLK, err); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5422 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5423 | break; |
| 5424 | nfs4_handle_exception(server, err, &exception); |
| 5425 | } while (exception.retry); |
| 5426 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5427 | } |
| 5428 | |
| 5429 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5430 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5431 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5432 | struct nfs4_exception exception = { |
| 5433 | .inode = state->inode, |
| 5434 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5435 | int err; |
| 5436 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5437 | err = nfs4_set_lock_state(state, request); |
| 5438 | if (err != 0) |
| 5439 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5440 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5441 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5442 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5443 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5444 | trace_nfs4_lock_expired(request, state, F_SETLK, err); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5445 | switch (err) { |
| 5446 | default: |
| 5447 | goto out; |
| 5448 | case -NFS4ERR_GRACE: |
| 5449 | case -NFS4ERR_DELAY: |
| 5450 | nfs4_handle_exception(server, err, &exception); |
| 5451 | err = 0; |
| 5452 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5453 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5454 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5455 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5456 | } |
| 5457 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5458 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5459 | /** |
| 5460 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 5461 | * |
| 5462 | * @state: NFSv4 state for an inode |
| 5463 | * |
| 5464 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 5465 | * Otherwise a negative NFS4ERR value is returned. |
| 5466 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5467 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5468 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5469 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5470 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5471 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5472 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5473 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5474 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5475 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 5476 | |
| 5477 | status = nfs41_test_stateid(server, |
| 5478 | &lsp->ls_stateid, |
| 5479 | cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 5480 | trace_nfs4_test_lock_stateid(state, lsp, status); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5481 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5482 | /* Free the stateid unless the server |
| 5483 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 5484 | if (status != -NFS4ERR_BAD_STATEID) |
| 5485 | nfs41_free_stateid(server, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5486 | &lsp->ls_stateid, |
| 5487 | cred); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5488 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5489 | ret = status; |
| 5490 | } |
| 5491 | } |
| 5492 | }; |
| 5493 | |
| 5494 | return ret; |
| 5495 | } |
| 5496 | |
| 5497 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5498 | { |
| 5499 | int status = NFS_OK; |
| 5500 | |
| 5501 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 5502 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5503 | if (status != NFS_OK) |
| 5504 | status = nfs4_lock_expired(state, request); |
| 5505 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5506 | } |
| 5507 | #endif |
| 5508 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5509 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5510 | { |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5511 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5512 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5513 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5514 | unsigned int seq; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5515 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5516 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5517 | if ((fl_flags & FL_POSIX) && |
| 5518 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 5519 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5520 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5521 | status = nfs4_set_lock_state(state, request); |
| 5522 | if (status != 0) |
| 5523 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5524 | request->fl_flags |= FL_ACCESS; |
| 5525 | status = do_vfs_lock(request->fl_file, request); |
| 5526 | if (status < 0) |
| 5527 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5528 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5529 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5530 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5531 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5532 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 5533 | status = do_vfs_lock(request->fl_file, request); |
| 5534 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5535 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5536 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 5537 | up_read(&nfsi->rwsem); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5538 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5539 | if (status != 0) |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5540 | goto out; |
| 5541 | down_read(&nfsi->rwsem); |
| 5542 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { |
| 5543 | status = -NFS4ERR_DELAY; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5544 | goto out_unlock; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5545 | } |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5546 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5547 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5548 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5549 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 5550 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5551 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5552 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5553 | out: |
| 5554 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5555 | return status; |
| 5556 | } |
| 5557 | |
| 5558 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5559 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5560 | struct nfs4_exception exception = { |
| 5561 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5562 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5563 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5564 | int err; |
| 5565 | |
| 5566 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5567 | err = _nfs4_proc_setlk(state, cmd, request); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5568 | trace_nfs4_set_lock(request, state, cmd, err); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5569 | if (err == -NFS4ERR_DENIED) |
| 5570 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5571 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5572 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5573 | } while (exception.retry); |
| 5574 | return err; |
| 5575 | } |
| 5576 | |
| 5577 | static int |
| 5578 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 5579 | { |
| 5580 | struct nfs_open_context *ctx; |
| 5581 | struct nfs4_state *state; |
| 5582 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 5583 | int status; |
| 5584 | |
| 5585 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5586 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5587 | state = ctx->state; |
| 5588 | |
| 5589 | if (request->fl_start < 0 || request->fl_end < 0) |
| 5590 | return -EINVAL; |
| 5591 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5592 | if (IS_GETLK(cmd)) { |
| 5593 | if (state != NULL) |
| 5594 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 5595 | return 0; |
| 5596 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5597 | |
| 5598 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 5599 | return -EINVAL; |
| 5600 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5601 | if (request->fl_type == F_UNLCK) { |
| 5602 | if (state != NULL) |
| 5603 | return nfs4_proc_unlck(state, cmd, request); |
| 5604 | return 0; |
| 5605 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5606 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5607 | if (state == NULL) |
| 5608 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5609 | /* |
| 5610 | * Don't rely on the VFS having checked the file open mode, |
| 5611 | * since it won't do this for flock() locks. |
| 5612 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5613 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5614 | case F_RDLCK: |
| 5615 | if (!(filp->f_mode & FMODE_READ)) |
| 5616 | return -EBADF; |
| 5617 | break; |
| 5618 | case F_WRLCK: |
| 5619 | if (!(filp->f_mode & FMODE_WRITE)) |
| 5620 | return -EBADF; |
| 5621 | } |
| 5622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5623 | do { |
| 5624 | status = nfs4_proc_setlk(state, cmd, request); |
| 5625 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 5626 | break; |
| 5627 | timeout = nfs4_set_lock_task_retry(timeout); |
| 5628 | status = -ERESTARTSYS; |
| 5629 | if (signalled()) |
| 5630 | break; |
| 5631 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5632 | return status; |
| 5633 | } |
| 5634 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5635 | 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] | 5636 | { |
| 5637 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5638 | int err; |
| 5639 | |
| 5640 | err = nfs4_set_lock_state(state, fl); |
| 5641 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5642 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 5643 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5644 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5645 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5646 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5647 | struct nfs_release_lockowner_data { |
| 5648 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5649 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5650 | struct nfs_release_lockowner_args args; |
| 5651 | }; |
| 5652 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5653 | static void nfs4_release_lockowner_release(void *calldata) |
| 5654 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5655 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5656 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5657 | kfree(calldata); |
| 5658 | } |
| 5659 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5660 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5661 | .rpc_release = nfs4_release_lockowner_release, |
| 5662 | }; |
| 5663 | |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 5664 | 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] | 5665 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5666 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5667 | struct rpc_message msg = { |
| 5668 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5669 | }; |
| 5670 | |
| 5671 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5672 | return -EINVAL; |
| 5673 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5674 | if (!data) |
| 5675 | return -ENOMEM; |
| 5676 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5677 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5678 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5679 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5680 | data->args.lock_owner.s_dev = server->s_dev; |
| 5681 | msg.rpc_argp = &data->args; |
| 5682 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5683 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5684 | } |
| 5685 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5686 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5687 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5688 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5689 | const void *buf, size_t buflen, |
| 5690 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5691 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5692 | if (strcmp(key, "") != 0) |
| 5693 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5694 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5695 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5696 | } |
| 5697 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5698 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5699 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5700 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5701 | if (strcmp(key, "") != 0) |
| 5702 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5703 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5704 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5705 | } |
| 5706 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5707 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5708 | size_t list_len, const char *name, |
| 5709 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5710 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5711 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5712 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5713 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5714 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5715 | |
| 5716 | if (list && len <= list_len) |
| 5717 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5718 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5719 | } |
| 5720 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 5721 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5722 | static inline int nfs4_server_supports_labels(struct nfs_server *server) |
| 5723 | { |
| 5724 | return server->caps & NFS_CAP_SECURITY_LABEL; |
| 5725 | } |
| 5726 | |
| 5727 | static int nfs4_xattr_set_nfs4_label(struct dentry *dentry, const char *key, |
| 5728 | const void *buf, size_t buflen, |
| 5729 | int flags, int type) |
| 5730 | { |
| 5731 | if (security_ismaclabel(key)) |
| 5732 | return nfs4_set_security_label(dentry, buf, buflen); |
| 5733 | |
| 5734 | return -EOPNOTSUPP; |
| 5735 | } |
| 5736 | |
| 5737 | static int nfs4_xattr_get_nfs4_label(struct dentry *dentry, const char *key, |
| 5738 | void *buf, size_t buflen, int type) |
| 5739 | { |
| 5740 | if (security_ismaclabel(key)) |
| 5741 | return nfs4_get_security_label(dentry->d_inode, buf, buflen); |
| 5742 | return -EOPNOTSUPP; |
| 5743 | } |
| 5744 | |
| 5745 | static size_t nfs4_xattr_list_nfs4_label(struct dentry *dentry, char *list, |
| 5746 | size_t list_len, const char *name, |
| 5747 | size_t name_len, int type) |
| 5748 | { |
| 5749 | size_t len = 0; |
| 5750 | |
| 5751 | if (nfs_server_capable(dentry->d_inode, NFS_CAP_SECURITY_LABEL)) { |
| 5752 | len = security_inode_listsecurity(dentry->d_inode, NULL, 0); |
| 5753 | if (list && len <= list_len) |
| 5754 | security_inode_listsecurity(dentry->d_inode, list, len); |
| 5755 | } |
| 5756 | return len; |
| 5757 | } |
| 5758 | |
| 5759 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 5760 | .prefix = XATTR_SECURITY_PREFIX, |
| 5761 | .list = nfs4_xattr_list_nfs4_label, |
| 5762 | .get = nfs4_xattr_get_nfs4_label, |
| 5763 | .set = nfs4_xattr_set_nfs4_label, |
| 5764 | }; |
| 5765 | #endif |
| 5766 | |
| 5767 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5768 | /* |
| 5769 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5770 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5771 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5772 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5773 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5774 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5775 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5776 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5777 | return; |
| 5778 | |
| 5779 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5780 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5781 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5782 | fattr->nlink = 2; |
| 5783 | } |
| 5784 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5785 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5786 | const struct qstr *name, |
| 5787 | struct nfs4_fs_locations *fs_locations, |
| 5788 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5789 | { |
| 5790 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 5791 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5792 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5793 | }; |
| 5794 | struct nfs4_fs_locations_arg args = { |
| 5795 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5796 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5797 | .page = page, |
| 5798 | .bitmask = bitmask, |
| 5799 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5800 | struct nfs4_fs_locations_res res = { |
| 5801 | .fs_locations = fs_locations, |
| 5802 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5803 | struct rpc_message msg = { |
| 5804 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5805 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5806 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5807 | }; |
| 5808 | int status; |
| 5809 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5810 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5811 | |
| 5812 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5813 | * is not supported */ |
| 5814 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5815 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5816 | else |
| 5817 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5818 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5819 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5820 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5821 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5822 | 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] | 5823 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5824 | return status; |
| 5825 | } |
| 5826 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5827 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5828 | const struct qstr *name, |
| 5829 | struct nfs4_fs_locations *fs_locations, |
| 5830 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5831 | { |
| 5832 | struct nfs4_exception exception = { }; |
| 5833 | int err; |
| 5834 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 5835 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 5836 | fs_locations, page); |
| 5837 | trace_nfs4_get_fs_locations(dir, name, err); |
| 5838 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5839 | &exception); |
| 5840 | } while (exception.retry); |
| 5841 | return err; |
| 5842 | } |
| 5843 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 5844 | /** |
| 5845 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 5846 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 5847 | */ |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5848 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5849 | { |
| 5850 | int status; |
| 5851 | struct nfs4_secinfo_arg args = { |
| 5852 | .dir_fh = NFS_FH(dir), |
| 5853 | .name = name, |
| 5854 | }; |
| 5855 | struct nfs4_secinfo_res res = { |
| 5856 | .flavors = flavors, |
| 5857 | }; |
| 5858 | struct rpc_message msg = { |
| 5859 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5860 | .rpc_argp = &args, |
| 5861 | .rpc_resp = &res, |
| 5862 | }; |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 5863 | struct rpc_clnt *clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5864 | |
| 5865 | dprintk("NFS call secinfo %s\n", name->name); |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 5866 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5867 | dprintk("NFS reply secinfo: %d\n", status); |
| 5868 | return status; |
| 5869 | } |
| 5870 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5871 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5872 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5873 | { |
| 5874 | struct nfs4_exception exception = { }; |
| 5875 | int err; |
| 5876 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 5877 | err = _nfs4_proc_secinfo(dir, name, flavors); |
| 5878 | trace_nfs4_secinfo(dir, name, err); |
| 5879 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5880 | &exception); |
| 5881 | } while (exception.retry); |
| 5882 | return err; |
| 5883 | } |
| 5884 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5885 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5886 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5887 | * Check the exchange flags returned by the server for invalid flags, having |
| 5888 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5889 | * DS flags set. |
| 5890 | */ |
| 5891 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5892 | { |
| 5893 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5894 | goto out_inval; |
| 5895 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5896 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5897 | goto out_inval; |
| 5898 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5899 | goto out_inval; |
| 5900 | return NFS_OK; |
| 5901 | out_inval: |
| 5902 | return -NFS4ERR_INVAL; |
| 5903 | } |
| 5904 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5905 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5906 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5907 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5908 | { |
| 5909 | if (a->server_scope_sz == b->server_scope_sz && |
| 5910 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5911 | return true; |
| 5912 | |
| 5913 | return false; |
| 5914 | } |
| 5915 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5916 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5917 | * nfs4_proc_bind_conn_to_session() |
| 5918 | * |
| 5919 | * The 4.1 client currently uses the same TCP connection for the |
| 5920 | * fore and backchannel. |
| 5921 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5922 | 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] | 5923 | { |
| 5924 | int status; |
| 5925 | struct nfs41_bind_conn_to_session_res res; |
| 5926 | struct rpc_message msg = { |
| 5927 | .rpc_proc = |
| 5928 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5929 | .rpc_argp = clp, |
| 5930 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5931 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5932 | }; |
| 5933 | |
| 5934 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5935 | |
| 5936 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5937 | if (unlikely(res.session == NULL)) { |
| 5938 | status = -ENOMEM; |
| 5939 | goto out; |
| 5940 | } |
| 5941 | |
| 5942 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5943 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5944 | if (status == 0) { |
| 5945 | if (memcmp(res.session->sess_id.data, |
| 5946 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5947 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5948 | status = -EIO; |
| 5949 | goto out_session; |
| 5950 | } |
| 5951 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5952 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5953 | __func__); |
| 5954 | status = -EIO; |
| 5955 | goto out_session; |
| 5956 | } |
| 5957 | if (res.use_conn_in_rdma_mode) { |
| 5958 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5959 | __func__); |
| 5960 | status = -EIO; |
| 5961 | goto out_session; |
| 5962 | } |
| 5963 | } |
| 5964 | out_session: |
| 5965 | kfree(res.session); |
| 5966 | out: |
| 5967 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5968 | return status; |
| 5969 | } |
| 5970 | |
| 5971 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5972 | * nfs4_proc_exchange_id() |
| 5973 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5974 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5975 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5976 | * Since the clientid has expired, all compounds using sessions |
| 5977 | * associated with the stale clientid will be returning |
| 5978 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5979 | * be in some phase of session reset. |
| 5980 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5981 | 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] | 5982 | { |
| 5983 | nfs4_verifier verifier; |
| 5984 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5985 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5986 | .client = clp, |
Trond Myklebust | 4f0b429 | 2013-05-20 12:24:03 -0400 | [diff] [blame] | 5987 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 5988 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5989 | }; |
| 5990 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5991 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5992 | }; |
| 5993 | int status; |
| 5994 | struct rpc_message msg = { |
| 5995 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5996 | .rpc_argp = &args, |
| 5997 | .rpc_resp = &res, |
| 5998 | .rpc_cred = cred, |
| 5999 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6000 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6001 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6002 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 6003 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6004 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 6005 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 6006 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6007 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6008 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6009 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6010 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6011 | status = -ENOMEM; |
| 6012 | goto out; |
| 6013 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6014 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6015 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6016 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6017 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6018 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6019 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6020 | } |
| 6021 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6022 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6023 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6024 | status = -ENOMEM; |
| 6025 | goto out_server_scope; |
| 6026 | } |
| 6027 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6028 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6029 | trace_nfs4_exchange_id(clp, status); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6030 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6031 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6032 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6033 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6034 | clp->cl_clientid = res.clientid; |
| 6035 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 6036 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 6037 | clp->cl_seqid = res.seqid; |
| 6038 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6039 | kfree(clp->cl_serverowner); |
| 6040 | clp->cl_serverowner = res.server_owner; |
| 6041 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6042 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6043 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 6044 | kfree(clp->cl_implid); |
| 6045 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6046 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6047 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6048 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6049 | res.server_scope)) { |
| 6050 | dprintk("%s: server_scope mismatch detected\n", |
| 6051 | __func__); |
| 6052 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6053 | kfree(clp->cl_serverscope); |
| 6054 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6055 | } |
| 6056 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6057 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6058 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6059 | goto out; |
| 6060 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6061 | } else |
| 6062 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6063 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6064 | out_server_owner: |
| 6065 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6066 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6067 | kfree(res.server_scope); |
| 6068 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6069 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6070 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6071 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6072 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 6073 | clp->cl_implid->date.seconds, |
| 6074 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6075 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6076 | return status; |
| 6077 | } |
| 6078 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6079 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 6080 | struct rpc_cred *cred) |
| 6081 | { |
| 6082 | struct rpc_message msg = { |
| 6083 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 6084 | .rpc_argp = clp, |
| 6085 | .rpc_cred = cred, |
| 6086 | }; |
| 6087 | int status; |
| 6088 | |
| 6089 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6090 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6091 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 6092 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6093 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 6094 | return status; |
| 6095 | } |
| 6096 | |
| 6097 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 6098 | struct rpc_cred *cred) |
| 6099 | { |
| 6100 | unsigned int loop; |
| 6101 | int ret; |
| 6102 | |
| 6103 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 6104 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 6105 | switch (ret) { |
| 6106 | case -NFS4ERR_DELAY: |
| 6107 | case -NFS4ERR_CLIENTID_BUSY: |
| 6108 | ssleep(1); |
| 6109 | break; |
| 6110 | default: |
| 6111 | return ret; |
| 6112 | } |
| 6113 | } |
| 6114 | return 0; |
| 6115 | } |
| 6116 | |
| 6117 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 6118 | { |
| 6119 | struct rpc_cred *cred; |
| 6120 | int ret = 0; |
| 6121 | |
| 6122 | if (clp->cl_mvops->minor_version < 1) |
| 6123 | goto out; |
| 6124 | if (clp->cl_exchange_flags == 0) |
| 6125 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6126 | if (clp->cl_preserve_clid) |
| 6127 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 6128 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6129 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 6130 | if (cred) |
| 6131 | put_rpccred(cred); |
| 6132 | switch (ret) { |
| 6133 | case 0: |
| 6134 | case -NFS4ERR_STALE_CLIENTID: |
| 6135 | clp->cl_exchange_flags = 0; |
| 6136 | } |
| 6137 | out: |
| 6138 | return ret; |
| 6139 | } |
| 6140 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6141 | struct nfs4_get_lease_time_data { |
| 6142 | struct nfs4_get_lease_time_args *args; |
| 6143 | struct nfs4_get_lease_time_res *res; |
| 6144 | struct nfs_client *clp; |
| 6145 | }; |
| 6146 | |
| 6147 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 6148 | void *calldata) |
| 6149 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6150 | struct nfs4_get_lease_time_data *data = |
| 6151 | (struct nfs4_get_lease_time_data *)calldata; |
| 6152 | |
| 6153 | dprintk("--> %s\n", __func__); |
| 6154 | /* just setup sequence, do not trigger session recovery |
| 6155 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6156 | nfs41_setup_sequence(data->clp->cl_session, |
| 6157 | &data->args->la_seq_args, |
| 6158 | &data->res->lr_seq_res, |
| 6159 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6160 | dprintk("<-- %s\n", __func__); |
| 6161 | } |
| 6162 | |
| 6163 | /* |
| 6164 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 6165 | * from sequence operation or clientid errors. |
| 6166 | */ |
| 6167 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 6168 | { |
| 6169 | struct nfs4_get_lease_time_data *data = |
| 6170 | (struct nfs4_get_lease_time_data *)calldata; |
| 6171 | |
| 6172 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6173 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 6174 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6175 | switch (task->tk_status) { |
| 6176 | case -NFS4ERR_DELAY: |
| 6177 | case -NFS4ERR_GRACE: |
| 6178 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 6179 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 6180 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6181 | /* fall through */ |
| 6182 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6183 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6184 | return; |
| 6185 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6186 | dprintk("<-- %s\n", __func__); |
| 6187 | } |
| 6188 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6189 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6190 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 6191 | .rpc_call_done = nfs4_get_lease_time_done, |
| 6192 | }; |
| 6193 | |
| 6194 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 6195 | { |
| 6196 | struct rpc_task *task; |
| 6197 | struct nfs4_get_lease_time_args args; |
| 6198 | struct nfs4_get_lease_time_res res = { |
| 6199 | .lr_fsinfo = fsinfo, |
| 6200 | }; |
| 6201 | struct nfs4_get_lease_time_data data = { |
| 6202 | .args = &args, |
| 6203 | .res = &res, |
| 6204 | .clp = clp, |
| 6205 | }; |
| 6206 | struct rpc_message msg = { |
| 6207 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 6208 | .rpc_argp = &args, |
| 6209 | .rpc_resp = &res, |
| 6210 | }; |
| 6211 | struct rpc_task_setup task_setup = { |
| 6212 | .rpc_client = clp->cl_rpcclient, |
| 6213 | .rpc_message = &msg, |
| 6214 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6215 | .callback_data = &data, |
| 6216 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6217 | }; |
| 6218 | int status; |
| 6219 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6220 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6221 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6222 | dprintk("--> %s\n", __func__); |
| 6223 | task = rpc_run_task(&task_setup); |
| 6224 | |
| 6225 | if (IS_ERR(task)) |
| 6226 | status = PTR_ERR(task); |
| 6227 | else { |
| 6228 | status = task->tk_status; |
| 6229 | rpc_put_task(task); |
| 6230 | } |
| 6231 | dprintk("<-- %s return %d\n", __func__, status); |
| 6232 | |
| 6233 | return status; |
| 6234 | } |
| 6235 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6236 | /* |
| 6237 | * Initialize the values to be used by the client in CREATE_SESSION |
| 6238 | * If nfs4_init_session set the fore channel request and response sizes, |
| 6239 | * use them. |
| 6240 | * |
| 6241 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 6242 | * always set csa_cachethis to FALSE because the current implementation |
| 6243 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 6244 | */ |
| 6245 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 6246 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 6247 | unsigned int max_rqst_sz, max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6248 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 6249 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 6250 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 6251 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6252 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 6253 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 6254 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6255 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 6256 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6257 | |
| 6258 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 6259 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6260 | __func__, |
| 6261 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 6262 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6263 | |
| 6264 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6265 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 6266 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 6267 | args->bc_attrs.max_resp_sz_cached = 0; |
| 6268 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 6269 | args->bc_attrs.max_reqs = 1; |
| 6270 | |
| 6271 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 6272 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 6273 | __func__, |
| 6274 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 6275 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 6276 | args->bc_attrs.max_reqs); |
| 6277 | } |
| 6278 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6279 | 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] | 6280 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6281 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 6282 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 6283 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6284 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 6285 | return -EINVAL; |
| 6286 | /* |
| 6287 | * Our requested max_ops is the minimum we need; we're not |
| 6288 | * prepared to break up compounds into smaller pieces than that. |
| 6289 | * So, no point even trying to continue if the server won't |
| 6290 | * cooperate: |
| 6291 | */ |
| 6292 | if (rcvd->max_ops < sent->max_ops) |
| 6293 | return -EINVAL; |
| 6294 | if (rcvd->max_reqs == 0) |
| 6295 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6296 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 6297 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6298 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6299 | } |
| 6300 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6301 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 6302 | { |
| 6303 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 6304 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6305 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6306 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 6307 | return -EINVAL; |
| 6308 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 6309 | return -EINVAL; |
| 6310 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 6311 | return -EINVAL; |
| 6312 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6313 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6314 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6315 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6316 | return -EINVAL; |
| 6317 | return 0; |
| 6318 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6319 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6320 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 6321 | struct nfs4_session *session) |
| 6322 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6323 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6324 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6325 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 6326 | if (ret) |
| 6327 | return ret; |
| 6328 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6329 | } |
| 6330 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6331 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 6332 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6333 | { |
| 6334 | struct nfs4_session *session = clp->cl_session; |
| 6335 | struct nfs41_create_session_args args = { |
| 6336 | .client = clp, |
| 6337 | .cb_program = NFS4_CALLBACK, |
| 6338 | }; |
| 6339 | struct nfs41_create_session_res res = { |
| 6340 | .client = clp, |
| 6341 | }; |
| 6342 | struct rpc_message msg = { |
| 6343 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 6344 | .rpc_argp = &args, |
| 6345 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6346 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6347 | }; |
| 6348 | int status; |
| 6349 | |
| 6350 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 6351 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6352 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6353 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6354 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6355 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 6356 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6357 | /* Verify the session's negotiated channel_attrs values */ |
| 6358 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6359 | /* Increment the clientid slot sequence id */ |
| 6360 | clp->cl_seqid++; |
| 6361 | } |
| 6362 | |
| 6363 | return status; |
| 6364 | } |
| 6365 | |
| 6366 | /* |
| 6367 | * Issues a CREATE_SESSION operation to the server. |
| 6368 | * It is the responsibility of the caller to verify the session is |
| 6369 | * expired before calling this routine. |
| 6370 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6371 | 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] | 6372 | { |
| 6373 | int status; |
| 6374 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6375 | struct nfs4_session *session = clp->cl_session; |
| 6376 | |
| 6377 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 6378 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6379 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6380 | if (status) |
| 6381 | goto out; |
| 6382 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 6383 | /* Init or reset the session slot tables */ |
| 6384 | status = nfs4_setup_session_slot_tables(session); |
| 6385 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6386 | if (status) |
| 6387 | goto out; |
| 6388 | |
| 6389 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 6390 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 6391 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6392 | out: |
| 6393 | dprintk("<-- %s\n", __func__); |
| 6394 | return status; |
| 6395 | } |
| 6396 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6397 | /* |
| 6398 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 6399 | * The caller must serialize access to this routine. |
| 6400 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6401 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 6402 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6403 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6404 | struct rpc_message msg = { |
| 6405 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 6406 | .rpc_argp = session, |
| 6407 | .rpc_cred = cred, |
| 6408 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6409 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6410 | |
| 6411 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 6412 | |
| 6413 | /* session is still being setup */ |
| 6414 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 6415 | return status; |
| 6416 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6417 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6418 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6419 | |
| 6420 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 6421 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6422 | "Session has been destroyed regardless...\n", status); |
| 6423 | |
| 6424 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 6425 | return status; |
| 6426 | } |
| 6427 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6428 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6429 | * Renew the cl_session lease. |
| 6430 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6431 | struct nfs4_sequence_data { |
| 6432 | struct nfs_client *clp; |
| 6433 | struct nfs4_sequence_args args; |
| 6434 | struct nfs4_sequence_res res; |
| 6435 | }; |
| 6436 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6437 | static void nfs41_sequence_release(void *data) |
| 6438 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6439 | struct nfs4_sequence_data *calldata = data; |
| 6440 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6441 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6442 | if (atomic_read(&clp->cl_count) > 1) |
| 6443 | nfs4_schedule_state_renewal(clp); |
| 6444 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6445 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6446 | } |
| 6447 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6448 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6449 | { |
| 6450 | switch(task->tk_status) { |
| 6451 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6452 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 6453 | return -EAGAIN; |
| 6454 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6455 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6456 | } |
| 6457 | return 0; |
| 6458 | } |
| 6459 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6460 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6461 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6462 | struct nfs4_sequence_data *calldata = data; |
| 6463 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6464 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6465 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 6466 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6467 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6468 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6469 | if (task->tk_status < 0) { |
| 6470 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6471 | if (atomic_read(&clp->cl_count) == 1) |
| 6472 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6473 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6474 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 6475 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6476 | return; |
| 6477 | } |
| 6478 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6479 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6480 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6481 | dprintk("<-- %s\n", __func__); |
| 6482 | } |
| 6483 | |
| 6484 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 6485 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6486 | struct nfs4_sequence_data *calldata = data; |
| 6487 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6488 | struct nfs4_sequence_args *args; |
| 6489 | struct nfs4_sequence_res *res; |
| 6490 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6491 | args = task->tk_msg.rpc_argp; |
| 6492 | res = task->tk_msg.rpc_resp; |
| 6493 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6494 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6495 | } |
| 6496 | |
| 6497 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 6498 | .rpc_call_done = nfs41_sequence_call_done, |
| 6499 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6500 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6501 | }; |
| 6502 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6503 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 6504 | struct rpc_cred *cred, |
| 6505 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6506 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6507 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6508 | struct rpc_message msg = { |
| 6509 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 6510 | .rpc_cred = cred, |
| 6511 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6512 | struct rpc_task_setup task_setup_data = { |
| 6513 | .rpc_client = clp->cl_rpcclient, |
| 6514 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6515 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 6516 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6517 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6518 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6519 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6520 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 6521 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6522 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6523 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6524 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6525 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6526 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6527 | if (is_privileged) |
| 6528 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6529 | msg.rpc_argp = &calldata->args; |
| 6530 | msg.rpc_resp = &calldata->res; |
| 6531 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6532 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6533 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6534 | return rpc_run_task(&task_setup_data); |
| 6535 | } |
| 6536 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6537 | 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] | 6538 | { |
| 6539 | struct rpc_task *task; |
| 6540 | int ret = 0; |
| 6541 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6542 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 6543 | return 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6544 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6545 | if (IS_ERR(task)) |
| 6546 | ret = PTR_ERR(task); |
| 6547 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6548 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6549 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6550 | return ret; |
| 6551 | } |
| 6552 | |
| 6553 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 6554 | { |
| 6555 | struct rpc_task *task; |
| 6556 | int ret; |
| 6557 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6558 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6559 | if (IS_ERR(task)) { |
| 6560 | ret = PTR_ERR(task); |
| 6561 | goto out; |
| 6562 | } |
| 6563 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6564 | if (!ret) { |
| 6565 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 6566 | |
| 6567 | if (task->tk_status == 0) |
| 6568 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6569 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6570 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6571 | rpc_put_task(task); |
| 6572 | out: |
| 6573 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6574 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6575 | } |
| 6576 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6577 | struct nfs4_reclaim_complete_data { |
| 6578 | struct nfs_client *clp; |
| 6579 | struct nfs41_reclaim_complete_args arg; |
| 6580 | struct nfs41_reclaim_complete_res res; |
| 6581 | }; |
| 6582 | |
| 6583 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 6584 | { |
| 6585 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6586 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6587 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 6588 | &calldata->arg.seq_args, |
| 6589 | &calldata->res.seq_res, |
| 6590 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6591 | } |
| 6592 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6593 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6594 | { |
| 6595 | switch(task->tk_status) { |
| 6596 | case 0: |
| 6597 | case -NFS4ERR_COMPLETE_ALREADY: |
| 6598 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 6599 | break; |
| 6600 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6601 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6602 | /* fall through */ |
| 6603 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6604 | return -EAGAIN; |
| 6605 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6606 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6607 | } |
| 6608 | return 0; |
| 6609 | } |
| 6610 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6611 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 6612 | { |
| 6613 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6614 | struct nfs_client *clp = calldata->clp; |
| 6615 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 6616 | |
| 6617 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6618 | if (!nfs41_sequence_done(task, res)) |
| 6619 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6620 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6621 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6622 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 6623 | rpc_restart_call_prepare(task); |
| 6624 | return; |
| 6625 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6626 | dprintk("<-- %s\n", __func__); |
| 6627 | } |
| 6628 | |
| 6629 | static void nfs4_free_reclaim_complete_data(void *data) |
| 6630 | { |
| 6631 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6632 | |
| 6633 | kfree(calldata); |
| 6634 | } |
| 6635 | |
| 6636 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 6637 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 6638 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 6639 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 6640 | }; |
| 6641 | |
| 6642 | /* |
| 6643 | * Issue a global reclaim complete. |
| 6644 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 6645 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 6646 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6647 | { |
| 6648 | struct nfs4_reclaim_complete_data *calldata; |
| 6649 | struct rpc_task *task; |
| 6650 | struct rpc_message msg = { |
| 6651 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 6652 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6653 | }; |
| 6654 | struct rpc_task_setup task_setup_data = { |
| 6655 | .rpc_client = clp->cl_rpcclient, |
| 6656 | .rpc_message = &msg, |
| 6657 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 6658 | .flags = RPC_TASK_ASYNC, |
| 6659 | }; |
| 6660 | int status = -ENOMEM; |
| 6661 | |
| 6662 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6663 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6664 | if (calldata == NULL) |
| 6665 | goto out; |
| 6666 | calldata->clp = clp; |
| 6667 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6668 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6669 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6670 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6671 | msg.rpc_argp = &calldata->arg; |
| 6672 | msg.rpc_resp = &calldata->res; |
| 6673 | task_setup_data.callback_data = calldata; |
| 6674 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6675 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6676 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6677 | goto out; |
| 6678 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6679 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6680 | if (status == 0) |
| 6681 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6682 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6683 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6684 | out: |
| 6685 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6686 | return status; |
| 6687 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6688 | |
| 6689 | static void |
| 6690 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6691 | { |
| 6692 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6693 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6694 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6695 | |
| 6696 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6697 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6698 | * right now covering the LAYOUTGET we are about to send. |
| 6699 | * However, that is not so catastrophic, and there seems |
| 6700 | * to be no way to prevent it completely. |
| 6701 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6702 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6703 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6704 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6705 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6706 | NFS_I(lgp->args.inode)->layout, |
| 6707 | lgp->args.ctx->state)) { |
| 6708 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6709 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6710 | } |
| 6711 | |
| 6712 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6713 | { |
| 6714 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6715 | struct inode *inode = lgp->args.inode; |
| 6716 | struct nfs_server *server = NFS_SERVER(inode); |
| 6717 | struct pnfs_layout_hdr *lo; |
| 6718 | struct nfs4_state *state = NULL; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6719 | unsigned long timeo, giveup; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6720 | |
| 6721 | dprintk("--> %s\n", __func__); |
| 6722 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6723 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6724 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6725 | |
| 6726 | switch (task->tk_status) { |
| 6727 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6728 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6729 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6730 | case -NFS4ERR_RECALLCONFLICT: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6731 | timeo = rpc_get_timeout(task->tk_client); |
| 6732 | giveup = lgp->args.timestamp + timeo; |
| 6733 | if (time_after(giveup, jiffies)) |
| 6734 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6735 | break; |
| 6736 | case -NFS4ERR_EXPIRED: |
| 6737 | case -NFS4ERR_BAD_STATEID: |
| 6738 | spin_lock(&inode->i_lock); |
| 6739 | lo = NFS_I(inode)->layout; |
| 6740 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6741 | spin_unlock(&inode->i_lock); |
| 6742 | /* If the open stateid was bad, then recover it. */ |
| 6743 | state = lgp->args.ctx->state; |
| 6744 | } else { |
| 6745 | LIST_HEAD(head); |
| 6746 | |
| 6747 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6748 | spin_unlock(&inode->i_lock); |
| 6749 | /* Mark the bad layout state as invalid, then |
| 6750 | * retry using the open stateid. */ |
| 6751 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6752 | } |
| 6753 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6754 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6755 | rpc_restart_call_prepare(task); |
| 6756 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6757 | dprintk("<-- %s\n", __func__); |
| 6758 | } |
| 6759 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6760 | static size_t max_response_pages(struct nfs_server *server) |
| 6761 | { |
| 6762 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6763 | return nfs_page_array_len(0, max_resp_sz); |
| 6764 | } |
| 6765 | |
| 6766 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6767 | { |
| 6768 | int i; |
| 6769 | |
| 6770 | if (!pages) |
| 6771 | return; |
| 6772 | |
| 6773 | for (i = 0; i < size; i++) { |
| 6774 | if (!pages[i]) |
| 6775 | break; |
| 6776 | __free_page(pages[i]); |
| 6777 | } |
| 6778 | kfree(pages); |
| 6779 | } |
| 6780 | |
| 6781 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6782 | { |
| 6783 | struct page **pages; |
| 6784 | int i; |
| 6785 | |
| 6786 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6787 | if (!pages) { |
| 6788 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6789 | return NULL; |
| 6790 | } |
| 6791 | |
| 6792 | for (i = 0; i < size; i++) { |
| 6793 | pages[i] = alloc_page(gfp_flags); |
| 6794 | if (!pages[i]) { |
| 6795 | dprintk("%s: failed to allocate page\n", __func__); |
| 6796 | nfs4_free_pages(pages, size); |
| 6797 | return NULL; |
| 6798 | } |
| 6799 | } |
| 6800 | |
| 6801 | return pages; |
| 6802 | } |
| 6803 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6804 | static void nfs4_layoutget_release(void *calldata) |
| 6805 | { |
| 6806 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6807 | struct inode *inode = lgp->args.inode; |
| 6808 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6809 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6810 | |
| 6811 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6812 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6813 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6814 | put_nfs_open_context(lgp->args.ctx); |
| 6815 | kfree(calldata); |
| 6816 | dprintk("<-- %s\n", __func__); |
| 6817 | } |
| 6818 | |
| 6819 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6820 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6821 | .rpc_call_done = nfs4_layoutget_done, |
| 6822 | .rpc_release = nfs4_layoutget_release, |
| 6823 | }; |
| 6824 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6825 | struct pnfs_layout_segment * |
| 6826 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6827 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6828 | struct inode *inode = lgp->args.inode; |
| 6829 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6830 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6831 | struct rpc_task *task; |
| 6832 | struct rpc_message msg = { |
| 6833 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6834 | .rpc_argp = &lgp->args, |
| 6835 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 6836 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6837 | }; |
| 6838 | struct rpc_task_setup task_setup_data = { |
| 6839 | .rpc_client = server->client, |
| 6840 | .rpc_message = &msg, |
| 6841 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6842 | .callback_data = lgp, |
| 6843 | .flags = RPC_TASK_ASYNC, |
| 6844 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6845 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6846 | int status = 0; |
| 6847 | |
| 6848 | dprintk("--> %s\n", __func__); |
| 6849 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6850 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6851 | if (!lgp->args.layout.pages) { |
| 6852 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6853 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6854 | } |
| 6855 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6856 | lgp->args.timestamp = jiffies; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6857 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6858 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6859 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6860 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6861 | |
| 6862 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 6863 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 6864 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6865 | task = rpc_run_task(&task_setup_data); |
| 6866 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6867 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6868 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6869 | if (status == 0) |
| 6870 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 6871 | trace_nfs4_layoutget(lgp->args.ctx, |
| 6872 | &lgp->args.range, |
| 6873 | &lgp->res.range, |
| 6874 | status); |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 6875 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 6876 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6877 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6878 | rpc_put_task(task); |
| 6879 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6880 | if (status) |
| 6881 | return ERR_PTR(status); |
| 6882 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6883 | } |
| 6884 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6885 | static void |
| 6886 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6887 | { |
| 6888 | struct nfs4_layoutreturn *lrp = calldata; |
| 6889 | |
| 6890 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6891 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 6892 | &lrp->args.seq_args, |
| 6893 | &lrp->res.seq_res, |
| 6894 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6895 | } |
| 6896 | |
| 6897 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6898 | { |
| 6899 | struct nfs4_layoutreturn *lrp = calldata; |
| 6900 | struct nfs_server *server; |
| 6901 | |
| 6902 | dprintk("--> %s\n", __func__); |
| 6903 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6904 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6905 | return; |
| 6906 | |
| 6907 | server = NFS_SERVER(lrp->args.inode); |
| 6908 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6909 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6910 | return; |
| 6911 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6912 | dprintk("<-- %s\n", __func__); |
| 6913 | } |
| 6914 | |
| 6915 | static void nfs4_layoutreturn_release(void *calldata) |
| 6916 | { |
| 6917 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6918 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6919 | |
| 6920 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6921 | spin_lock(&lo->plh_inode->i_lock); |
| 6922 | if (lrp->res.lrs_present) |
| 6923 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6924 | lo->plh_block_lgets--; |
| 6925 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6926 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6927 | kfree(calldata); |
| 6928 | dprintk("<-- %s\n", __func__); |
| 6929 | } |
| 6930 | |
| 6931 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6932 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6933 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6934 | .rpc_release = nfs4_layoutreturn_release, |
| 6935 | }; |
| 6936 | |
| 6937 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6938 | { |
| 6939 | struct rpc_task *task; |
| 6940 | struct rpc_message msg = { |
| 6941 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6942 | .rpc_argp = &lrp->args, |
| 6943 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 6944 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6945 | }; |
| 6946 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 6947 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6948 | .rpc_message = &msg, |
| 6949 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6950 | .callback_data = lrp, |
| 6951 | }; |
| 6952 | int status; |
| 6953 | |
| 6954 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6955 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6956 | task = rpc_run_task(&task_setup_data); |
| 6957 | if (IS_ERR(task)) |
| 6958 | return PTR_ERR(task); |
| 6959 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 6960 | trace_nfs4_layoutreturn(lrp->args.inode, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6961 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6962 | rpc_put_task(task); |
| 6963 | return status; |
| 6964 | } |
| 6965 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6966 | /* |
| 6967 | * Retrieve the list of Data Server devices from the MDS. |
| 6968 | */ |
| 6969 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6970 | const struct nfs_fh *fh, |
| 6971 | struct pnfs_devicelist *devlist) |
| 6972 | { |
| 6973 | struct nfs4_getdevicelist_args args = { |
| 6974 | .fh = fh, |
| 6975 | .layoutclass = server->pnfs_curr_ld->id, |
| 6976 | }; |
| 6977 | struct nfs4_getdevicelist_res res = { |
| 6978 | .devlist = devlist, |
| 6979 | }; |
| 6980 | struct rpc_message msg = { |
| 6981 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6982 | .rpc_argp = &args, |
| 6983 | .rpc_resp = &res, |
| 6984 | }; |
| 6985 | int status; |
| 6986 | |
| 6987 | dprintk("--> %s\n", __func__); |
| 6988 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6989 | &res.seq_res, 0); |
| 6990 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6991 | return status; |
| 6992 | } |
| 6993 | |
| 6994 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6995 | const struct nfs_fh *fh, |
| 6996 | struct pnfs_devicelist *devlist) |
| 6997 | { |
| 6998 | struct nfs4_exception exception = { }; |
| 6999 | int err; |
| 7000 | |
| 7001 | do { |
| 7002 | err = nfs4_handle_exception(server, |
| 7003 | _nfs4_getdevicelist(server, fh, devlist), |
| 7004 | &exception); |
| 7005 | } while (exception.retry); |
| 7006 | |
| 7007 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 7008 | err, devlist->num_devs); |
| 7009 | |
| 7010 | return err; |
| 7011 | } |
| 7012 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 7013 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7014 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7015 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 7016 | struct pnfs_device *pdev, |
| 7017 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7018 | { |
| 7019 | struct nfs4_getdeviceinfo_args args = { |
| 7020 | .pdev = pdev, |
| 7021 | }; |
| 7022 | struct nfs4_getdeviceinfo_res res = { |
| 7023 | .pdev = pdev, |
| 7024 | }; |
| 7025 | struct rpc_message msg = { |
| 7026 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 7027 | .rpc_argp = &args, |
| 7028 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7029 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7030 | }; |
| 7031 | int status; |
| 7032 | |
| 7033 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 7034 | 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] | 7035 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7036 | |
| 7037 | return status; |
| 7038 | } |
| 7039 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7040 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 7041 | struct pnfs_device *pdev, |
| 7042 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7043 | { |
| 7044 | struct nfs4_exception exception = { }; |
| 7045 | int err; |
| 7046 | |
| 7047 | do { |
| 7048 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7049 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7050 | &exception); |
| 7051 | } while (exception.retry); |
| 7052 | return err; |
| 7053 | } |
| 7054 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 7055 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7056 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 7057 | { |
| 7058 | struct nfs4_layoutcommit_data *data = calldata; |
| 7059 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7060 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7061 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7062 | nfs41_setup_sequence(session, |
| 7063 | &data->args.seq_args, |
| 7064 | &data->res.seq_res, |
| 7065 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7066 | } |
| 7067 | |
| 7068 | static void |
| 7069 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 7070 | { |
| 7071 | struct nfs4_layoutcommit_data *data = calldata; |
| 7072 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 7073 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7074 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7075 | return; |
| 7076 | |
| 7077 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7078 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 7079 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 7080 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 7081 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7082 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7083 | break; |
| 7084 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7085 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 7086 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7087 | break; |
| 7088 | default: |
| 7089 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 7090 | rpc_restart_call_prepare(task); |
| 7091 | return; |
| 7092 | } |
| 7093 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7094 | } |
| 7095 | |
| 7096 | static void nfs4_layoutcommit_release(void *calldata) |
| 7097 | { |
| 7098 | struct nfs4_layoutcommit_data *data = calldata; |
| 7099 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 7100 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7101 | put_rpccred(data->cred); |
| 7102 | kfree(data); |
| 7103 | } |
| 7104 | |
| 7105 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 7106 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 7107 | .rpc_call_done = nfs4_layoutcommit_done, |
| 7108 | .rpc_release = nfs4_layoutcommit_release, |
| 7109 | }; |
| 7110 | |
| 7111 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 7112 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7113 | { |
| 7114 | struct rpc_message msg = { |
| 7115 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 7116 | .rpc_argp = &data->args, |
| 7117 | .rpc_resp = &data->res, |
| 7118 | .rpc_cred = data->cred, |
| 7119 | }; |
| 7120 | struct rpc_task_setup task_setup_data = { |
| 7121 | .task = &data->task, |
| 7122 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 7123 | .rpc_message = &msg, |
| 7124 | .callback_ops = &nfs4_layoutcommit_ops, |
| 7125 | .callback_data = data, |
| 7126 | .flags = RPC_TASK_ASYNC, |
| 7127 | }; |
| 7128 | struct rpc_task *task; |
| 7129 | int status = 0; |
| 7130 | |
| 7131 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 7132 | "lbw: %llu inode %lu\n", |
| 7133 | data->task.tk_pid, sync, |
| 7134 | data->args.lastbytewritten, |
| 7135 | data->args.inode->i_ino); |
| 7136 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 7137 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7138 | task = rpc_run_task(&task_setup_data); |
| 7139 | if (IS_ERR(task)) |
| 7140 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 7141 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7142 | goto out; |
| 7143 | status = nfs4_wait_for_completion_rpc_task(task); |
| 7144 | if (status != 0) |
| 7145 | goto out; |
| 7146 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 7147 | trace_nfs4_layoutcommit(data->args.inode, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7148 | out: |
| 7149 | dprintk("%s: status %d\n", __func__, status); |
| 7150 | rpc_put_task(task); |
| 7151 | return status; |
| 7152 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7153 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 7154 | /** |
| 7155 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 7156 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 7157 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7158 | static int |
| 7159 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 7160 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 7161 | { |
| 7162 | struct nfs41_secinfo_no_name_args args = { |
| 7163 | .style = SECINFO_STYLE_CURRENT_FH, |
| 7164 | }; |
| 7165 | struct nfs4_secinfo_res res = { |
| 7166 | .flavors = flavors, |
| 7167 | }; |
| 7168 | struct rpc_message msg = { |
| 7169 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 7170 | .rpc_argp = &args, |
| 7171 | .rpc_resp = &res, |
| 7172 | }; |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 7173 | return nfs4_call_sync(server->nfs_client->cl_rpcclient, server, &msg, |
| 7174 | &args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7175 | } |
| 7176 | |
| 7177 | static int |
| 7178 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 7179 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 7180 | { |
| 7181 | struct nfs4_exception exception = { }; |
| 7182 | int err; |
| 7183 | do { |
| 7184 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 7185 | switch (err) { |
| 7186 | case 0: |
| 7187 | case -NFS4ERR_WRONGSEC: |
| 7188 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 7189 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7190 | default: |
| 7191 | err = nfs4_handle_exception(server, err, &exception); |
| 7192 | } |
| 7193 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 7194 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7195 | return err; |
| 7196 | } |
| 7197 | |
| 7198 | static int |
| 7199 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 7200 | struct nfs_fsinfo *info) |
| 7201 | { |
| 7202 | int err; |
| 7203 | struct page *page; |
| 7204 | rpc_authflavor_t flavor; |
| 7205 | struct nfs4_secinfo_flavors *flavors; |
| 7206 | |
| 7207 | page = alloc_page(GFP_KERNEL); |
| 7208 | if (!page) { |
| 7209 | err = -ENOMEM; |
| 7210 | goto out; |
| 7211 | } |
| 7212 | |
| 7213 | flavors = page_address(page); |
| 7214 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 7215 | |
| 7216 | /* |
| 7217 | * Fall back on "guess and check" method if |
| 7218 | * the server doesn't support SECINFO_NO_NAME |
| 7219 | */ |
| 7220 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 7221 | err = nfs4_find_root_sec(server, fhandle, info); |
| 7222 | goto out_freepage; |
| 7223 | } |
| 7224 | if (err) |
| 7225 | goto out_freepage; |
| 7226 | |
| 7227 | flavor = nfs_find_best_sec(flavors); |
| 7228 | if (err == 0) |
| 7229 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 7230 | |
| 7231 | out_freepage: |
| 7232 | put_page(page); |
| 7233 | if (err == -EACCES) |
| 7234 | return -EPERM; |
| 7235 | out: |
| 7236 | return err; |
| 7237 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7238 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7239 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 7240 | nfs4_stateid *stateid, |
| 7241 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7242 | { |
| 7243 | int status; |
| 7244 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7245 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7246 | }; |
| 7247 | struct nfs41_test_stateid_res res; |
| 7248 | struct rpc_message msg = { |
| 7249 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 7250 | .rpc_argp = &args, |
| 7251 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7252 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7253 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7254 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7255 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 7256 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7257 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7258 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
| 7259 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7260 | if (status != NFS_OK) { |
| 7261 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7262 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7263 | } |
| 7264 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7265 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7266 | } |
| 7267 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7268 | /** |
| 7269 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 7270 | * |
| 7271 | * @server: server / transport on which to perform the operation |
| 7272 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7273 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7274 | * |
| 7275 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 7276 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 7277 | * failed or the state ID is not currently valid. |
| 7278 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7279 | static int nfs41_test_stateid(struct nfs_server *server, |
| 7280 | nfs4_stateid *stateid, |
| 7281 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7282 | { |
| 7283 | struct nfs4_exception exception = { }; |
| 7284 | int err; |
| 7285 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7286 | err = _nfs41_test_stateid(server, stateid, cred); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7287 | if (err != -NFS4ERR_DELAY) |
| 7288 | break; |
| 7289 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7290 | } while (exception.retry); |
| 7291 | return err; |
| 7292 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7293 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7294 | struct nfs_free_stateid_data { |
| 7295 | struct nfs_server *server; |
| 7296 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7297 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7298 | }; |
| 7299 | |
| 7300 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 7301 | { |
| 7302 | struct nfs_free_stateid_data *data = calldata; |
| 7303 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 7304 | &data->args.seq_args, |
| 7305 | &data->res.seq_res, |
| 7306 | task); |
| 7307 | } |
| 7308 | |
| 7309 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 7310 | { |
| 7311 | struct nfs_free_stateid_data *data = calldata; |
| 7312 | |
| 7313 | nfs41_sequence_done(task, &data->res.seq_res); |
| 7314 | |
| 7315 | switch (task->tk_status) { |
| 7316 | case -NFS4ERR_DELAY: |
| 7317 | if (nfs4_async_handle_error(task, data->server, NULL) == -EAGAIN) |
| 7318 | rpc_restart_call_prepare(task); |
| 7319 | } |
| 7320 | } |
| 7321 | |
| 7322 | static void nfs41_free_stateid_release(void *calldata) |
| 7323 | { |
| 7324 | kfree(calldata); |
| 7325 | } |
| 7326 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 7327 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7328 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 7329 | .rpc_call_done = nfs41_free_stateid_done, |
| 7330 | .rpc_release = nfs41_free_stateid_release, |
| 7331 | }; |
| 7332 | |
| 7333 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
| 7334 | nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7335 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7336 | bool privileged) |
| 7337 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7338 | struct rpc_message msg = { |
| 7339 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7340 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7341 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7342 | struct rpc_task_setup task_setup = { |
| 7343 | .rpc_client = server->client, |
| 7344 | .rpc_message = &msg, |
| 7345 | .callback_ops = &nfs41_free_stateid_ops, |
| 7346 | .flags = RPC_TASK_ASYNC, |
| 7347 | }; |
| 7348 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7349 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7350 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7351 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 7352 | if (!data) |
| 7353 | return ERR_PTR(-ENOMEM); |
| 7354 | data->server = server; |
| 7355 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 7356 | |
| 7357 | task_setup.callback_data = data; |
| 7358 | |
| 7359 | msg.rpc_argp = &data->args; |
| 7360 | msg.rpc_resp = &data->res; |
| 7361 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
| 7362 | if (privileged) |
| 7363 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 7364 | |
| 7365 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7366 | } |
| 7367 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7368 | /** |
| 7369 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 7370 | * |
| 7371 | * @server: server / transport on which to perform the operation |
| 7372 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7373 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7374 | * |
| 7375 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 7376 | * negative NFS4ERR value is returned. |
| 7377 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7378 | static int nfs41_free_stateid(struct nfs_server *server, |
| 7379 | nfs4_stateid *stateid, |
| 7380 | struct rpc_cred *cred) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7381 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7382 | struct rpc_task *task; |
| 7383 | int ret; |
| 7384 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7385 | task = _nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7386 | if (IS_ERR(task)) |
| 7387 | return PTR_ERR(task); |
| 7388 | ret = rpc_wait_for_completion_task(task); |
| 7389 | if (!ret) |
| 7390 | ret = task->tk_status; |
| 7391 | rpc_put_task(task); |
| 7392 | return ret; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7393 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7394 | |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7395 | static int nfs41_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp) |
| 7396 | { |
| 7397 | struct rpc_task *task; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7398 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7399 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7400 | task = _nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7401 | nfs4_free_lock_state(server, lsp); |
| 7402 | if (IS_ERR(task)) |
| 7403 | return PTR_ERR(task); |
| 7404 | rpc_put_task(task); |
| 7405 | return 0; |
| 7406 | } |
| 7407 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7408 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 7409 | const nfs4_stateid *s2) |
| 7410 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7411 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7412 | return false; |
| 7413 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7414 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7415 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7416 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7417 | return true; |
| 7418 | |
| 7419 | return false; |
| 7420 | } |
| 7421 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7422 | #endif /* CONFIG_NFS_V4_1 */ |
| 7423 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7424 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 7425 | const nfs4_stateid *s2) |
| 7426 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7427 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7428 | } |
| 7429 | |
| 7430 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7431 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7432 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7433 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7434 | .recover_open = nfs4_open_reclaim, |
| 7435 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7436 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7437 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7438 | }; |
| 7439 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7440 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7441 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7442 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 7443 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 7444 | .recover_open = nfs4_open_reclaim, |
| 7445 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7446 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7447 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7448 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7449 | }; |
| 7450 | #endif /* CONFIG_NFS_V4_1 */ |
| 7451 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7452 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7453 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7454 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7455 | .recover_open = nfs4_open_expired, |
| 7456 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7457 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7458 | }; |
| 7459 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7460 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7461 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7462 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 7463 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7464 | .recover_open = nfs41_open_expired, |
| 7465 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7466 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7467 | }; |
| 7468 | #endif /* CONFIG_NFS_V4_1 */ |
| 7469 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7470 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7471 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7472 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7473 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7474 | }; |
| 7475 | |
| 7476 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7477 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7478 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7479 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7480 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7481 | }; |
| 7482 | #endif |
| 7483 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7484 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 7485 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 7486 | .init_caps = NFS_CAP_READDIRPLUS |
| 7487 | | NFS_CAP_ATOMIC_OPEN |
| 7488 | | NFS_CAP_CHANGE_ATTR |
| 7489 | | NFS_CAP_POSIX_LOCK, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7490 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7491 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7492 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7493 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7494 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 7495 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 7496 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7497 | }; |
| 7498 | |
| 7499 | #if defined(CONFIG_NFS_V4_1) |
| 7500 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 7501 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 7502 | .init_caps = NFS_CAP_READDIRPLUS |
| 7503 | | NFS_CAP_ATOMIC_OPEN |
| 7504 | | NFS_CAP_CHANGE_ATTR |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 7505 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 7506 | | NFS_CAP_STATEID_NFSV41 |
| 7507 | | NFS_CAP_ATOMIC_OPEN_V1, |
Bryan Schumaker | 104287c | 2012-11-12 14:13:13 -0500 | [diff] [blame] | 7508 | .call_sync = nfs4_call_sync_sequence, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7509 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7510 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7511 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7512 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 7513 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 7514 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7515 | }; |
| 7516 | #endif |
| 7517 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7518 | #if defined(CONFIG_NFS_V4_2) |
| 7519 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 7520 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 7521 | .init_caps = NFS_CAP_READDIRPLUS |
| 7522 | | NFS_CAP_ATOMIC_OPEN |
| 7523 | | NFS_CAP_CHANGE_ATTR |
| 7524 | | NFS_CAP_POSIX_LOCK |
| 7525 | | NFS_CAP_STATEID_NFSV41 |
| 7526 | | NFS_CAP_ATOMIC_OPEN_V1, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7527 | .call_sync = nfs4_call_sync_sequence, |
| 7528 | .match_stateid = nfs41_match_stateid, |
| 7529 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 7530 | .free_lock_state = nfs41_free_lock_state, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7531 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 7532 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 7533 | .state_renewal_ops = &nfs41_state_renewal_ops, |
| 7534 | }; |
| 7535 | #endif |
| 7536 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7537 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 7538 | [0] = &nfs_v4_0_minor_ops, |
| 7539 | #if defined(CONFIG_NFS_V4_1) |
| 7540 | [1] = &nfs_v4_1_minor_ops, |
| 7541 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7542 | #if defined(CONFIG_NFS_V4_2) |
| 7543 | [2] = &nfs_v4_2_minor_ops, |
| 7544 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7545 | }; |
| 7546 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 7547 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 7548 | .create = nfs_create, |
| 7549 | .lookup = nfs_lookup, |
| 7550 | .atomic_open = nfs_atomic_open, |
| 7551 | .link = nfs_link, |
| 7552 | .unlink = nfs_unlink, |
| 7553 | .symlink = nfs_symlink, |
| 7554 | .mkdir = nfs_mkdir, |
| 7555 | .rmdir = nfs_rmdir, |
| 7556 | .mknod = nfs_mknod, |
| 7557 | .rename = nfs_rename, |
| 7558 | .permission = nfs_permission, |
| 7559 | .getattr = nfs_getattr, |
| 7560 | .setattr = nfs_setattr, |
| 7561 | .getxattr = generic_getxattr, |
| 7562 | .setxattr = generic_setxattr, |
| 7563 | .listxattr = generic_listxattr, |
| 7564 | .removexattr = generic_removexattr, |
| 7565 | }; |
| 7566 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 7567 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7568 | .permission = nfs_permission, |
| 7569 | .getattr = nfs_getattr, |
| 7570 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7571 | .getxattr = generic_getxattr, |
| 7572 | .setxattr = generic_setxattr, |
| 7573 | .listxattr = generic_listxattr, |
| 7574 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7575 | }; |
| 7576 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 7577 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7578 | .version = 4, /* protocol version */ |
| 7579 | .dentry_ops = &nfs4_dentry_operations, |
| 7580 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7581 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 7582 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7583 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 7584 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 7585 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7586 | .getattr = nfs4_proc_getattr, |
| 7587 | .setattr = nfs4_proc_setattr, |
| 7588 | .lookup = nfs4_proc_lookup, |
| 7589 | .access = nfs4_proc_access, |
| 7590 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7591 | .create = nfs4_proc_create, |
| 7592 | .remove = nfs4_proc_remove, |
| 7593 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 7594 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7595 | .unlink_done = nfs4_proc_unlink_done, |
| 7596 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7597 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 7598 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7599 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7600 | .link = nfs4_proc_link, |
| 7601 | .symlink = nfs4_proc_symlink, |
| 7602 | .mkdir = nfs4_proc_mkdir, |
| 7603 | .rmdir = nfs4_proc_remove, |
| 7604 | .readdir = nfs4_proc_readdir, |
| 7605 | .mknod = nfs4_proc_mknod, |
| 7606 | .statfs = nfs4_proc_statfs, |
| 7607 | .fsinfo = nfs4_proc_fsinfo, |
| 7608 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 7609 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7610 | .decode_dirent = nfs4_decode_dirent, |
| 7611 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 7612 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 7613 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7614 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7615 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 7616 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 7617 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7618 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7619 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 7620 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7621 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7622 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 7623 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 7624 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 7625 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 7626 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 7627 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 7628 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 7629 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 7630 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 7631 | .create_server = nfs4_create_server, |
| 7632 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7633 | }; |
| 7634 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7635 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 7636 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 7637 | .list = nfs4_xattr_list_nfs4_acl, |
| 7638 | .get = nfs4_xattr_get_nfs4_acl, |
| 7639 | .set = nfs4_xattr_set_nfs4_acl, |
| 7640 | }; |
| 7641 | |
| 7642 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 7643 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7644 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 7645 | &nfs4_xattr_nfs4_label_handler, |
| 7646 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7647 | NULL |
| 7648 | }; |
| 7649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7650 | /* |
| 7651 | * Local variables: |
| 7652 | * c-basic-offset: 8 |
| 7653 | * End: |
| 7654 | */ |