Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
| 46 | #include <linux/nfs.h> |
| 47 | #include <linux/nfs4.h> |
| 48 | #include <linux/nfs_fs.h> |
| 49 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 50 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 52 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 53 | #include <linux/module.h> |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 54 | #include <linux/nfs_idmap.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 55 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 56 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 57 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 59 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 61 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 62 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 63 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 64 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 65 | #include "netns.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 66 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 67 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 70 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 71 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 73 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 74 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 75 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 76 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 78 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 79 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 80 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label); |
| 81 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 82 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 83 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 84 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 85 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 86 | #ifdef CONFIG_NFS_V4_1 |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 87 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *); |
| 88 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 89 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 90 | |
| 91 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 92 | static inline struct nfs4_label * |
| 93 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 94 | struct iattr *sattr, struct nfs4_label *label) |
| 95 | { |
| 96 | int err; |
| 97 | |
| 98 | if (label == NULL) |
| 99 | return NULL; |
| 100 | |
| 101 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 102 | return NULL; |
| 103 | |
| 104 | if (NFS_SERVER(dir)->nfs_client->cl_minorversion < 2) |
| 105 | return NULL; |
| 106 | |
| 107 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 108 | &dentry->d_name, (void **)&label->label, &label->len); |
| 109 | if (err == 0) |
| 110 | return label; |
| 111 | |
| 112 | return NULL; |
| 113 | } |
| 114 | static inline void |
| 115 | nfs4_label_release_security(struct nfs4_label *label) |
| 116 | { |
| 117 | if (label) |
| 118 | security_release_secctx(label->label, label->len); |
| 119 | } |
| 120 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 121 | { |
| 122 | if (label) |
| 123 | return server->attr_bitmask; |
| 124 | |
| 125 | return server->attr_bitmask_nl; |
| 126 | } |
| 127 | #else |
| 128 | static inline struct nfs4_label * |
| 129 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 130 | struct iattr *sattr, struct nfs4_label *l) |
| 131 | { return NULL; } |
| 132 | static inline void |
| 133 | nfs4_label_release_security(struct nfs4_label *label) |
| 134 | { return; } |
| 135 | static inline u32 * |
| 136 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 137 | { return server->attr_bitmask; } |
| 138 | #endif |
| 139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 141 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 143 | if (err >= -1000) |
| 144 | return err; |
| 145 | switch (err) { |
| 146 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 147 | case -NFS4ERR_LAYOUTTRYLATER: |
| 148 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 149 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 150 | case -NFS4ERR_WRONGSEC: |
| 151 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 152 | case -NFS4ERR_BADOWNER: |
| 153 | case -NFS4ERR_BADNAME: |
| 154 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 155 | case -NFS4ERR_SHARE_DENIED: |
| 156 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 157 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 158 | return -EPROTONOSUPPORT; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 159 | case -NFS4ERR_ACCESS: |
| 160 | return -EACCES; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 161 | case -NFS4ERR_FILE_OPEN: |
| 162 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 163 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 165 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 166 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 168 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | /* |
| 172 | * This is our standard bitmap for GETATTR requests. |
| 173 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 174 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | FATTR4_WORD0_TYPE |
| 176 | | FATTR4_WORD0_CHANGE |
| 177 | | FATTR4_WORD0_SIZE |
| 178 | | FATTR4_WORD0_FSID |
| 179 | | FATTR4_WORD0_FILEID, |
| 180 | FATTR4_WORD1_MODE |
| 181 | | FATTR4_WORD1_NUMLINKS |
| 182 | | FATTR4_WORD1_OWNER |
| 183 | | FATTR4_WORD1_OWNER_GROUP |
| 184 | | FATTR4_WORD1_RAWDEV |
| 185 | | FATTR4_WORD1_SPACE_USED |
| 186 | | FATTR4_WORD1_TIME_ACCESS |
| 187 | | FATTR4_WORD1_TIME_METADATA |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 188 | | FATTR4_WORD1_TIME_MODIFY, |
| 189 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 190 | FATTR4_WORD2_SECURITY_LABEL |
| 191 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | }; |
| 193 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 194 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 195 | FATTR4_WORD0_TYPE |
| 196 | | FATTR4_WORD0_CHANGE |
| 197 | | FATTR4_WORD0_SIZE |
| 198 | | FATTR4_WORD0_FSID |
| 199 | | FATTR4_WORD0_FILEID, |
| 200 | FATTR4_WORD1_MODE |
| 201 | | FATTR4_WORD1_NUMLINKS |
| 202 | | FATTR4_WORD1_OWNER |
| 203 | | FATTR4_WORD1_OWNER_GROUP |
| 204 | | FATTR4_WORD1_RAWDEV |
| 205 | | FATTR4_WORD1_SPACE_USED |
| 206 | | FATTR4_WORD1_TIME_ACCESS |
| 207 | | FATTR4_WORD1_TIME_METADATA |
| 208 | | FATTR4_WORD1_TIME_MODIFY, |
| 209 | FATTR4_WORD2_MDSTHRESHOLD |
| 210 | }; |
| 211 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 212 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 213 | FATTR4_WORD0_TYPE |
| 214 | | FATTR4_WORD0_CHANGE |
| 215 | | FATTR4_WORD0_FILEID, |
| 216 | }; |
| 217 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 218 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | FATTR4_WORD0_FILES_AVAIL |
| 220 | | FATTR4_WORD0_FILES_FREE |
| 221 | | FATTR4_WORD0_FILES_TOTAL, |
| 222 | FATTR4_WORD1_SPACE_AVAIL |
| 223 | | FATTR4_WORD1_SPACE_FREE |
| 224 | | FATTR4_WORD1_SPACE_TOTAL |
| 225 | }; |
| 226 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 227 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | FATTR4_WORD0_MAXLINK |
| 229 | | FATTR4_WORD0_MAXNAME, |
| 230 | 0 |
| 231 | }; |
| 232 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 233 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | | FATTR4_WORD0_MAXREAD |
| 235 | | FATTR4_WORD0_MAXWRITE |
| 236 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 237 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 238 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 239 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | }; |
| 241 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 242 | const u32 nfs4_fs_locations_bitmap[3] = { |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 243 | FATTR4_WORD0_TYPE |
| 244 | | FATTR4_WORD0_CHANGE |
| 245 | | FATTR4_WORD0_SIZE |
| 246 | | FATTR4_WORD0_FSID |
| 247 | | FATTR4_WORD0_FILEID |
| 248 | | FATTR4_WORD0_FS_LOCATIONS, |
| 249 | FATTR4_WORD1_MODE |
| 250 | | FATTR4_WORD1_NUMLINKS |
| 251 | | FATTR4_WORD1_OWNER |
| 252 | | FATTR4_WORD1_OWNER_GROUP |
| 253 | | FATTR4_WORD1_RAWDEV |
| 254 | | FATTR4_WORD1_SPACE_USED |
| 255 | | FATTR4_WORD1_TIME_ACCESS |
| 256 | | FATTR4_WORD1_TIME_METADATA |
| 257 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 258 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 259 | }; |
| 260 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 261 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | struct nfs4_readdir_arg *readdir) |
| 263 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 264 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 267 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | readdir->cookie = 0; |
| 273 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 274 | if (cookie == 2) |
| 275 | return; |
| 276 | |
| 277 | /* |
| 278 | * NFSv4 servers do not return entries for '.' and '..' |
| 279 | * Therefore, we fake these entries here. We let '.' |
| 280 | * have cookie 0 and '..' have cookie 1. Note that |
| 281 | * when talking to the server, we always send cookie 0 |
| 282 | * instead of 1 or 2. |
| 283 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 284 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | if (cookie == 0) { |
| 287 | *p++ = xdr_one; /* next */ |
| 288 | *p++ = xdr_zero; /* cookie, first word */ |
| 289 | *p++ = xdr_one; /* cookie, second word */ |
| 290 | *p++ = xdr_one; /* entry len */ |
| 291 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 292 | p++; |
| 293 | *p++ = xdr_one; /* bitmap length */ |
| 294 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 295 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 296 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | *p++ = xdr_one; /* next */ |
| 300 | *p++ = xdr_zero; /* cookie, first word */ |
| 301 | *p++ = xdr_two; /* cookie, second word */ |
| 302 | *p++ = xdr_two; /* entry len */ |
| 303 | memcpy(p, "..\0\0", 4); /* entry */ |
| 304 | p++; |
| 305 | *p++ = xdr_one; /* bitmap length */ |
| 306 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 307 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 308 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
| 310 | readdir->pgbase = (char *)p - (char *)start; |
| 311 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 312 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 315 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 316 | { |
| 317 | int res = 0; |
| 318 | |
| 319 | might_sleep(); |
| 320 | |
| 321 | if (*timeout <= 0) |
| 322 | *timeout = NFS4_POLL_RETRY_MIN; |
| 323 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 324 | *timeout = NFS4_POLL_RETRY_MAX; |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 325 | freezable_schedule_timeout_killable(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 326 | if (fatal_signal_pending(current)) |
| 327 | res = -ERESTARTSYS; |
| 328 | *timeout <<= 1; |
| 329 | return res; |
| 330 | } |
| 331 | |
| 332 | /* This is the error handling routine for processes that are allowed |
| 333 | * to sleep. |
| 334 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 335 | 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] | 336 | { |
| 337 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 338 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 339 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 340 | int ret = errorcode; |
| 341 | |
| 342 | exception->retry = 0; |
| 343 | switch(errorcode) { |
| 344 | case 0: |
| 345 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 346 | case -NFS4ERR_OPENMODE: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 347 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 348 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 349 | exception->retry = 1; |
| 350 | return 0; |
| 351 | } |
| 352 | if (state == NULL) |
| 353 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 354 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 355 | if (ret < 0) |
| 356 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 357 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 358 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 359 | case -NFS4ERR_ADMIN_REVOKED: |
| 360 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | b570a97 | 2013-04-12 15:04:51 -0400 | [diff] [blame] | 361 | if (inode != NULL && nfs4_have_delegation(inode, FMODE_READ)) { |
| 362 | nfs_remove_bad_delegation(inode); |
| 363 | exception->retry = 1; |
| 364 | break; |
| 365 | } |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 366 | if (state == NULL) |
| 367 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 368 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 369 | if (ret < 0) |
| 370 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 371 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 372 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 373 | if (state != NULL) { |
| 374 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 375 | if (ret < 0) |
| 376 | break; |
| 377 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 378 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 379 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 380 | nfs4_schedule_lease_recovery(clp); |
| 381 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 382 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 383 | case -NFS4ERR_BADSESSION: |
| 384 | case -NFS4ERR_BADSLOT: |
| 385 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 386 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 387 | case -NFS4ERR_DEADSESSION: |
| 388 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 389 | case -NFS4ERR_SEQ_MISORDERED: |
| 390 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 391 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 392 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 393 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 394 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 395 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 396 | if (exception->timeout > HZ) { |
| 397 | /* We have retried a decent amount, time to |
| 398 | * fail |
| 399 | */ |
| 400 | ret = -EBUSY; |
| 401 | break; |
| 402 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 403 | case -NFS4ERR_GRACE: |
| 404 | case -NFS4ERR_DELAY: |
| 405 | ret = nfs4_delay(server->client, &exception->timeout); |
| 406 | if (ret != 0) |
| 407 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 408 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 409 | case -NFS4ERR_OLD_STATEID: |
| 410 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 411 | break; |
| 412 | case -NFS4ERR_BADOWNER: |
| 413 | /* The following works around a Linux server bug! */ |
| 414 | case -NFS4ERR_BADNAME: |
| 415 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 416 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 417 | exception->retry = 1; |
| 418 | printk(KERN_WARNING "NFS: v4 server %s " |
| 419 | "does not accept raw " |
| 420 | "uid/gids. " |
| 421 | "Reenabling the idmapper.\n", |
| 422 | server->nfs_client->cl_hostname); |
| 423 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 424 | } |
| 425 | /* We failed to handle the error */ |
| 426 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 427 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 428 | ret = nfs4_wait_clnt_recover(clp); |
| 429 | if (ret == 0) |
| 430 | exception->retry = 1; |
| 431 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 435 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | spin_lock(&clp->cl_lock); |
| 438 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 439 | clp->cl_last_renewal = timestamp; |
| 440 | spin_unlock(&clp->cl_lock); |
| 441 | } |
| 442 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 443 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 444 | { |
| 445 | do_renew_lease(server->nfs_client, timestamp); |
| 446 | } |
| 447 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 448 | #if defined(CONFIG_NFS_V4_1) |
| 449 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 450 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 451 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 452 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 453 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 454 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 455 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 456 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 457 | /* just wake up the next guy waiting since |
| 458 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 459 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 460 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 461 | } |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 462 | tbl = res->sr_slot->table; |
| 463 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 464 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 465 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 466 | /* Be nice to the server: try to ensure that the last transmitted |
| 467 | * value for highest_user_slotid <= target_highest_slotid |
| 468 | */ |
| 469 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 470 | send_new_highest_used_slotid = true; |
| 471 | |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 472 | if (nfs41_wake_and_assign_slot(tbl, res->sr_slot)) { |
| 473 | send_new_highest_used_slotid = false; |
| 474 | goto out_unlock; |
| 475 | } |
Trond Myklebust | f4af6e2a | 2012-11-20 14:17:32 -0500 | [diff] [blame] | 476 | nfs4_free_slot(tbl, res->sr_slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 477 | |
| 478 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 479 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 480 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 481 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 482 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 483 | if (send_new_highest_used_slotid) |
| 484 | nfs41_server_notify_highest_slotid_update(session->clp); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 485 | } |
| 486 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 487 | 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] | 488 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 489 | struct nfs4_session *session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 490 | struct nfs4_slot *slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 491 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 492 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 493 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 494 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 495 | /* don't increment the sequence number if the task wasn't sent */ |
| 496 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 497 | goto out; |
| 498 | |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 499 | slot = res->sr_slot; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 500 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 501 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 502 | if (slot->interrupted) { |
| 503 | slot->interrupted = 0; |
| 504 | interrupted = true; |
| 505 | } |
| 506 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 507 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 508 | switch (res->sr_status) { |
| 509 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 510 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 511 | ++slot->seq_nr; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 512 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 513 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 514 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 515 | if (res->sr_status_flags != 0) |
| 516 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 517 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 518 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 519 | case 1: |
| 520 | /* |
| 521 | * sr_status remains 1 if an RPC level error occurred. |
| 522 | * The server may or may not have processed the sequence |
| 523 | * operation.. |
| 524 | * Mark the slot as having hosted an interrupted RPC call. |
| 525 | */ |
| 526 | slot->interrupted = 1; |
| 527 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 528 | case -NFS4ERR_DELAY: |
| 529 | /* The server detected a resend of the RPC call and |
| 530 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 531 | * of RFC5661. |
| 532 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 533 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 534 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 535 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 536 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 537 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 538 | case -NFS4ERR_BADSLOT: |
| 539 | /* |
| 540 | * The slot id we used was probably retired. Try again |
| 541 | * using a different slot id. |
| 542 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 543 | goto retry_nowait; |
| 544 | case -NFS4ERR_SEQ_MISORDERED: |
| 545 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 546 | * Was the last operation on this sequence interrupted? |
| 547 | * If so, retry after bumping the sequence number. |
| 548 | */ |
| 549 | if (interrupted) { |
| 550 | ++slot->seq_nr; |
| 551 | goto retry_nowait; |
| 552 | } |
| 553 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 554 | * Could this slot have been previously retired? |
| 555 | * If so, then the server may be expecting seq_nr = 1! |
| 556 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 557 | if (slot->seq_nr != 1) { |
| 558 | slot->seq_nr = 1; |
| 559 | goto retry_nowait; |
| 560 | } |
| 561 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 562 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 563 | ++slot->seq_nr; |
| 564 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 565 | default: |
| 566 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 567 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 568 | } |
| 569 | out: |
| 570 | /* The session may be reset by one of the error handlers. */ |
| 571 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 572 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 573 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 574 | retry_nowait: |
| 575 | if (rpc_restart_call_prepare(task)) { |
| 576 | task->tk_status = 0; |
| 577 | ret = 0; |
| 578 | } |
| 579 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 580 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 581 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 582 | goto out; |
| 583 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 584 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 585 | } |
| 586 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 587 | static int nfs4_sequence_done(struct rpc_task *task, |
| 588 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 589 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 590 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 591 | return 1; |
| 592 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 593 | } |
| 594 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 595 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 596 | struct nfs4_sequence_res *res, int cache_reply) |
| 597 | { |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 598 | args->sa_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 599 | args->sa_cache_this = 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 600 | args->sa_privileged = 0; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 601 | if (cache_reply) |
| 602 | args->sa_cache_this = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 603 | res->sr_slot = NULL; |
| 604 | } |
| 605 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 606 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 607 | { |
| 608 | args->sa_privileged = 1; |
| 609 | } |
| 610 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 611 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 612 | struct nfs4_sequence_args *args, |
| 613 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 614 | struct rpc_task *task) |
| 615 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 616 | struct nfs4_slot *slot; |
| 617 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 618 | |
| 619 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 620 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 621 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 622 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 623 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 624 | tbl = &session->fc_slot_table; |
| 625 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 626 | task->tk_timeout = 0; |
| 627 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 628 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 629 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 630 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 631 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 632 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 633 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 634 | } |
| 635 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 636 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 637 | if (IS_ERR(slot)) { |
| 638 | /* If out of memory, try again in 1/4 second */ |
| 639 | if (slot == ERR_PTR(-ENOMEM)) |
| 640 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 641 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 642 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 643 | } |
| 644 | spin_unlock(&tbl->slot_tbl_lock); |
| 645 | |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 646 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 647 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 648 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, |
| 649 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 650 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 651 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 652 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 653 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 654 | /* |
| 655 | * sr_status is only set in decode_sequence, and so will remain |
| 656 | * set to 1 if an rpc level failure occurs. |
| 657 | */ |
| 658 | res->sr_status = 1; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 659 | out_success: |
| 660 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 661 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 662 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 663 | /* Privileged tasks are queued with top priority */ |
| 664 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 665 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 666 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 667 | else |
| 668 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 669 | spin_unlock(&tbl->slot_tbl_lock); |
| 670 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 671 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 672 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 673 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 674 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 675 | struct nfs4_sequence_args *args, |
| 676 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 677 | struct rpc_task *task) |
| 678 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 679 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 680 | int ret = 0; |
| 681 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 682 | if (session == NULL) { |
| 683 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 684 | goto out; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 685 | } |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 686 | |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 687 | dprintk("--> %s clp %p session %p sr_slot %d\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 688 | __func__, session->clp, session, res->sr_slot ? |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 689 | res->sr_slot->slot_nr : -1); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 690 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 691 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 692 | out: |
| 693 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 694 | return ret; |
| 695 | } |
| 696 | |
| 697 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 698 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 699 | struct nfs4_sequence_args *seq_args; |
| 700 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 701 | }; |
| 702 | |
| 703 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 704 | { |
| 705 | struct nfs41_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 706 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 707 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 708 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 709 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 710 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 711 | } |
| 712 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 713 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 714 | { |
| 715 | struct nfs41_call_sync_data *data = calldata; |
| 716 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 717 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 718 | } |
| 719 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 720 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 721 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 722 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 723 | }; |
| 724 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 725 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 726 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 727 | struct rpc_message *msg, |
| 728 | struct nfs4_sequence_args *args, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 729 | struct nfs4_sequence_res *res) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 730 | { |
| 731 | int ret; |
| 732 | struct rpc_task *task; |
| 733 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 734 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 735 | .seq_args = args, |
| 736 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 737 | }; |
| 738 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 739 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 740 | .rpc_message = msg, |
| 741 | .callback_ops = &nfs41_call_sync_ops, |
| 742 | .callback_data = &data |
| 743 | }; |
| 744 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 745 | task = rpc_run_task(&task_setup); |
| 746 | if (IS_ERR(task)) |
| 747 | ret = PTR_ERR(task); |
| 748 | else { |
| 749 | ret = task->tk_status; |
| 750 | rpc_put_task(task); |
| 751 | } |
| 752 | return ret; |
| 753 | } |
| 754 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 755 | #else |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 756 | static |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 757 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 758 | struct nfs4_sequence_res *res, int cache_reply) |
| 759 | { |
| 760 | } |
| 761 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 762 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 763 | { |
| 764 | } |
| 765 | |
| 766 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 767 | static int nfs4_sequence_done(struct rpc_task *task, |
| 768 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 769 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 770 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 771 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 772 | #endif /* CONFIG_NFS_V4_1 */ |
| 773 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 774 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 775 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 776 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 777 | struct rpc_message *msg, |
| 778 | struct nfs4_sequence_args *args, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 779 | struct nfs4_sequence_res *res) |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 780 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 781 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 782 | } |
| 783 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 784 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 785 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 786 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 787 | struct rpc_message *msg, |
| 788 | struct nfs4_sequence_args *args, |
| 789 | struct nfs4_sequence_res *res, |
| 790 | int cache_reply) |
| 791 | { |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 792 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 793 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 794 | args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 795 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 796 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 797 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 799 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 801 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 802 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 803 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 804 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 805 | dir->i_version = cinfo->after; |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 806 | nfs_fscache_invalidate(dir); |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 807 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | } |
| 809 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 810 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 811 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 812 | struct nfs_openargs o_arg; |
| 813 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 814 | struct nfs_open_confirmargs c_arg; |
| 815 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 816 | struct nfs4_string owner_name; |
| 817 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 818 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 819 | struct nfs4_label *f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 820 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 821 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 822 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 823 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 824 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 825 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 826 | unsigned int rpc_done : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 827 | unsigned int is_recover : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 828 | int rpc_status; |
| 829 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 830 | }; |
| 831 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 832 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 833 | int err, struct nfs4_exception *exception) |
| 834 | { |
| 835 | if (err != -EINVAL) |
| 836 | return false; |
| 837 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 838 | return false; |
| 839 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 840 | exception->retry = 1; |
| 841 | return true; |
| 842 | } |
| 843 | |
| 844 | static enum open_claim_type4 |
| 845 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 846 | enum open_claim_type4 claim) |
| 847 | { |
| 848 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 849 | return claim; |
| 850 | switch (claim) { |
| 851 | default: |
| 852 | return claim; |
| 853 | case NFS4_OPEN_CLAIM_FH: |
| 854 | return NFS4_OPEN_CLAIM_NULL; |
| 855 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 856 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 857 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 858 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 859 | } |
| 860 | } |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 861 | |
| 862 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 863 | { |
| 864 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 865 | p->o_res.f_label = p->f_label; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 866 | p->o_res.seqid = p->o_arg.seqid; |
| 867 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 868 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 869 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 870 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 871 | 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] | 872 | } |
| 873 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 874 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 875 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 876 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 877 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 878 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 879 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 880 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 881 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 882 | struct inode *dir = parent->d_inode; |
| 883 | struct nfs_server *server = NFS_SERVER(dir); |
| 884 | struct nfs4_opendata *p; |
| 885 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 886 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 887 | if (p == NULL) |
| 888 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 889 | |
| 890 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 891 | if (IS_ERR(p->f_label)) |
| 892 | goto err_free_p; |
| 893 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 894 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 895 | if (p->o_arg.seqid == NULL) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 896 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 897 | nfs_sb_active(dentry->d_sb); |
| 898 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 899 | p->dir = parent; |
| 900 | p->owner = sp; |
| 901 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 902 | p->o_arg.open_flags = flags; |
| 903 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 904 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 905 | * will return permission denied for all bits until close */ |
| 906 | if (!(flags & O_EXCL)) { |
| 907 | /* ask server to check for all possible rights as results |
| 908 | * are cached */ |
| 909 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 910 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 911 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 912 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 913 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 914 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 915 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 916 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 917 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 918 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 919 | p->o_arg.label = label; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 920 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 921 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 922 | case NFS4_OPEN_CLAIM_NULL: |
| 923 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 924 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 925 | p->o_arg.fh = NFS_FH(dir); |
| 926 | break; |
| 927 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 928 | case NFS4_OPEN_CLAIM_FH: |
| 929 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 930 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 931 | p->o_arg.fh = NFS_FH(dentry->d_inode); |
| 932 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 933 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 934 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 935 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 936 | p->o_arg.u.attrs = &p->attrs; |
| 937 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 938 | |
| 939 | verf[0] = jiffies; |
| 940 | verf[1] = current->pid; |
| 941 | memcpy(p->o_arg.u.verifier.data, verf, |
| 942 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 943 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 944 | p->c_arg.fh = &p->o_res.fh; |
| 945 | p->c_arg.stateid = &p->o_res.stateid; |
| 946 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 947 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 948 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 949 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 950 | |
| 951 | err_free_label: |
| 952 | nfs4_label_free(p->f_label); |
| 953 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 954 | kfree(p); |
| 955 | err: |
| 956 | dput(parent); |
| 957 | return NULL; |
| 958 | } |
| 959 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 960 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 961 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 962 | struct nfs4_opendata *p = container_of(kref, |
| 963 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 964 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 965 | |
| 966 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 967 | if (p->state != NULL) |
| 968 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 969 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 970 | |
| 971 | nfs4_label_free(p->f_label); |
| 972 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 973 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 974 | dput(p->dentry); |
| 975 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 976 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 977 | kfree(p); |
| 978 | } |
| 979 | |
| 980 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 981 | { |
| 982 | if (p != NULL) |
| 983 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 984 | } |
| 985 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 986 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 987 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 988 | int ret; |
| 989 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 990 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 991 | return ret; |
| 992 | } |
| 993 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 994 | 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] | 995 | { |
| 996 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 997 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 998 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 999 | goto out; |
| 1000 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1001 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1002 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1003 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1004 | break; |
| 1005 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1006 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1007 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1008 | break; |
| 1009 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1010 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1011 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1012 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1013 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1014 | return ret; |
| 1015 | } |
| 1016 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1017 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1018 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1019 | if (delegation == NULL) |
| 1020 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1021 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1022 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1023 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1024 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1025 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1026 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1027 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1028 | return 1; |
| 1029 | } |
| 1030 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1031 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1032 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1033 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1034 | case FMODE_WRITE: |
| 1035 | state->n_wronly++; |
| 1036 | break; |
| 1037 | case FMODE_READ: |
| 1038 | state->n_rdonly++; |
| 1039 | break; |
| 1040 | case FMODE_READ|FMODE_WRITE: |
| 1041 | state->n_rdwr++; |
| 1042 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1043 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1044 | } |
| 1045 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1046 | 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] | 1047 | { |
| 1048 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1049 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1050 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 92b40e9 | 2013-04-20 01:25:45 -0400 | [diff] [blame] | 1051 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1052 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1053 | case FMODE_READ: |
| 1054 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1055 | break; |
| 1056 | case FMODE_WRITE: |
| 1057 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1058 | break; |
| 1059 | case FMODE_READ|FMODE_WRITE: |
| 1060 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1061 | } |
| 1062 | } |
| 1063 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1064 | 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] | 1065 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1066 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1067 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1068 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1069 | } |
| 1070 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1071 | 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] | 1072 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1073 | /* |
| 1074 | * Protect the call to nfs4_state_set_mode_locked and |
| 1075 | * serialise the stateid update |
| 1076 | */ |
| 1077 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1078 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1079 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1080 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1081 | } |
| 1082 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1083 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1084 | write_sequnlock(&state->seqlock); |
| 1085 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1086 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1087 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1090 | 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] | 1091 | { |
| 1092 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1093 | struct nfs_delegation *deleg_cur; |
| 1094 | int ret = 0; |
| 1095 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1096 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1097 | |
| 1098 | rcu_read_lock(); |
| 1099 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1100 | if (deleg_cur == NULL) |
| 1101 | goto no_delegation; |
| 1102 | |
| 1103 | spin_lock(&deleg_cur->lock); |
| 1104 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1105 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1106 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1107 | goto no_delegation_unlock; |
| 1108 | |
| 1109 | if (delegation == NULL) |
| 1110 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1111 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1112 | goto no_delegation_unlock; |
| 1113 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1114 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1115 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1116 | ret = 1; |
| 1117 | no_delegation_unlock: |
| 1118 | spin_unlock(&deleg_cur->lock); |
| 1119 | no_delegation: |
| 1120 | rcu_read_unlock(); |
| 1121 | |
| 1122 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1123 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1124 | ret = 1; |
| 1125 | } |
| 1126 | |
| 1127 | return ret; |
| 1128 | } |
| 1129 | |
| 1130 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1131 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1132 | { |
| 1133 | struct nfs_delegation *delegation; |
| 1134 | |
| 1135 | rcu_read_lock(); |
| 1136 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1137 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1138 | rcu_read_unlock(); |
| 1139 | return; |
| 1140 | } |
| 1141 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1142 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1143 | } |
| 1144 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1145 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1146 | { |
| 1147 | struct nfs4_state *state = opendata->state; |
| 1148 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1149 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1150 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1151 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1152 | nfs4_stateid stateid; |
| 1153 | int ret = -EAGAIN; |
| 1154 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1155 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1156 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1157 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1158 | if (can_open_cached(state, fmode, open_mode)) { |
| 1159 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1160 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1161 | goto out_return_state; |
| 1162 | } |
| 1163 | spin_unlock(&state->owner->so_lock); |
| 1164 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1165 | rcu_read_lock(); |
| 1166 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1167 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1168 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1169 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1170 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1171 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1172 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1173 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1174 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1175 | if (!opendata->is_recover) { |
| 1176 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1177 | if (ret != 0) |
| 1178 | goto out; |
| 1179 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1180 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1181 | |
| 1182 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1183 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1184 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1185 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1186 | out: |
| 1187 | return ERR_PTR(ret); |
| 1188 | out_return_state: |
| 1189 | atomic_inc(&state->count); |
| 1190 | return state; |
| 1191 | } |
| 1192 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1193 | static void |
| 1194 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1195 | { |
| 1196 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1197 | struct nfs_delegation *delegation; |
| 1198 | int delegation_flags = 0; |
| 1199 | |
| 1200 | rcu_read_lock(); |
| 1201 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1202 | if (delegation) |
| 1203 | delegation_flags = delegation->flags; |
| 1204 | rcu_read_unlock(); |
| 1205 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1206 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1207 | "returning a delegation for " |
| 1208 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1209 | clp->cl_hostname); |
| 1210 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1211 | nfs_inode_set_delegation(state->inode, |
| 1212 | data->owner->so_cred, |
| 1213 | &data->o_res); |
| 1214 | else |
| 1215 | nfs_inode_reclaim_delegation(state->inode, |
| 1216 | data->owner->so_cred, |
| 1217 | &data->o_res); |
| 1218 | } |
| 1219 | |
| 1220 | /* |
| 1221 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1222 | * and update the nfs4_state. |
| 1223 | */ |
| 1224 | static struct nfs4_state * |
| 1225 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1226 | { |
| 1227 | struct inode *inode = data->state->inode; |
| 1228 | struct nfs4_state *state = data->state; |
| 1229 | int ret; |
| 1230 | |
| 1231 | if (!data->rpc_done) { |
| 1232 | ret = data->rpc_status; |
| 1233 | goto err; |
| 1234 | } |
| 1235 | |
| 1236 | ret = -ESTALE; |
| 1237 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || |
| 1238 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || |
| 1239 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) |
| 1240 | goto err; |
| 1241 | |
| 1242 | ret = -ENOMEM; |
| 1243 | state = nfs4_get_open_state(inode, data->owner); |
| 1244 | if (state == NULL) |
| 1245 | goto err; |
| 1246 | |
| 1247 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1248 | if (ret) |
| 1249 | goto err; |
| 1250 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1251 | nfs_setsecurity(inode, &data->f_attr, data->f_label); |
| 1252 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1253 | if (data->o_res.delegation_type != 0) |
| 1254 | nfs4_opendata_check_deleg(data, state); |
| 1255 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1256 | data->o_arg.fmode); |
| 1257 | |
| 1258 | return state; |
| 1259 | err: |
| 1260 | return ERR_PTR(ret); |
| 1261 | |
| 1262 | } |
| 1263 | |
| 1264 | static struct nfs4_state * |
| 1265 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1266 | { |
| 1267 | struct inode *inode; |
| 1268 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1269 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1270 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1271 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1272 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1273 | goto out; |
| 1274 | } |
| 1275 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1276 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1277 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1278 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1279 | 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] | 1280 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1281 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1282 | goto err; |
| 1283 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1284 | state = nfs4_get_open_state(inode, data->owner); |
| 1285 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1286 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1287 | if (data->o_res.delegation_type != 0) |
| 1288 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1289 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1290 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1291 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1292 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1293 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1294 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1295 | err_put_inode: |
| 1296 | iput(inode); |
| 1297 | err: |
| 1298 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1299 | } |
| 1300 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1301 | static struct nfs4_state * |
| 1302 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1303 | { |
| 1304 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1305 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1306 | return _nfs4_opendata_to_nfs4_state(data); |
| 1307 | } |
| 1308 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1309 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1310 | { |
| 1311 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1312 | struct nfs_open_context *ctx; |
| 1313 | |
| 1314 | spin_lock(&state->inode->i_lock); |
| 1315 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1316 | if (ctx->state != state) |
| 1317 | continue; |
| 1318 | get_nfs_open_context(ctx); |
| 1319 | spin_unlock(&state->inode->i_lock); |
| 1320 | return ctx; |
| 1321 | } |
| 1322 | spin_unlock(&state->inode->i_lock); |
| 1323 | return ERR_PTR(-ENOENT); |
| 1324 | } |
| 1325 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1326 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1327 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1328 | { |
| 1329 | struct nfs4_opendata *opendata; |
| 1330 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1331 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1332 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1333 | if (opendata == NULL) |
| 1334 | return ERR_PTR(-ENOMEM); |
| 1335 | opendata->state = state; |
| 1336 | atomic_inc(&state->count); |
| 1337 | return opendata; |
| 1338 | } |
| 1339 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1340 | 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] | 1341 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1342 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1343 | int ret; |
| 1344 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1345 | opendata->o_arg.open_flags = 0; |
| 1346 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1347 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1348 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1349 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1350 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1351 | if (ret != 0) |
| 1352 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1353 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1354 | if (IS_ERR(newstate)) |
| 1355 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1356 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1357 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1358 | return 0; |
| 1359 | } |
| 1360 | |
| 1361 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1362 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1363 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1364 | int ret; |
| 1365 | |
| 1366 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1367 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1368 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1369 | smp_rmb(); |
| 1370 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1371 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1372 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1373 | if (ret != 0) |
| 1374 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1375 | if (newstate != state) |
| 1376 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1377 | } |
| 1378 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1379 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1380 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1381 | if (ret != 0) |
| 1382 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1383 | if (newstate != state) |
| 1384 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1385 | } |
| 1386 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1387 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1388 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1389 | if (ret != 0) |
| 1390 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1391 | if (newstate != state) |
| 1392 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1393 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1394 | /* |
| 1395 | * We may have performed cached opens for all three recoveries. |
| 1396 | * Check if we need to update the current stateid. |
| 1397 | */ |
| 1398 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1399 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1400 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1401 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1402 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1403 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1404 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1405 | return 0; |
| 1406 | } |
| 1407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | /* |
| 1409 | * OPEN_RECLAIM: |
| 1410 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1412 | 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] | 1413 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1414 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1415 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1416 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | int status; |
| 1418 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1419 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1420 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1421 | if (IS_ERR(opendata)) |
| 1422 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1423 | rcu_read_lock(); |
| 1424 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1425 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1426 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1427 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1428 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1429 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1430 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | return status; |
| 1432 | } |
| 1433 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1434 | 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] | 1435 | { |
| 1436 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1437 | struct nfs4_exception exception = { }; |
| 1438 | int err; |
| 1439 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1440 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1441 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1442 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1443 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1444 | break; |
| 1445 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | } while (exception.retry); |
| 1447 | return err; |
| 1448 | } |
| 1449 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1450 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1451 | { |
| 1452 | struct nfs_open_context *ctx; |
| 1453 | int ret; |
| 1454 | |
| 1455 | ctx = nfs4_state_find_open_context(state); |
| 1456 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1457 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1458 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1459 | put_nfs_open_context(ctx); |
| 1460 | return ret; |
| 1461 | } |
| 1462 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1463 | 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] | 1464 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1465 | switch (err) { |
| 1466 | default: |
| 1467 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1468 | "%d.\n", __func__, err); |
| 1469 | case 0: |
| 1470 | case -ENOENT: |
| 1471 | case -ESTALE: |
| 1472 | break; |
| 1473 | case -NFS4ERR_BADSESSION: |
| 1474 | case -NFS4ERR_BADSLOT: |
| 1475 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1476 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1477 | case -NFS4ERR_DEADSESSION: |
| 1478 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1479 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1480 | return -EAGAIN; |
| 1481 | case -NFS4ERR_STALE_CLIENTID: |
| 1482 | case -NFS4ERR_STALE_STATEID: |
| 1483 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1484 | case -NFS4ERR_EXPIRED: |
| 1485 | /* Don't recall a delegation if it was lost */ |
| 1486 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1487 | return -EAGAIN; |
| 1488 | case -NFS4ERR_DELEG_REVOKED: |
| 1489 | case -NFS4ERR_ADMIN_REVOKED: |
| 1490 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1491 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1492 | nfs_inode_find_state_and_recover(state->inode, |
| 1493 | stateid); |
| 1494 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1495 | return 0; |
| 1496 | case -NFS4ERR_DELAY: |
| 1497 | case -NFS4ERR_GRACE: |
| 1498 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1499 | ssleep(1); |
| 1500 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1501 | case -ENOMEM: |
| 1502 | case -NFS4ERR_DENIED: |
| 1503 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1504 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1505 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | return err; |
| 1507 | } |
| 1508 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1509 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
| 1510 | { |
| 1511 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1512 | struct nfs4_opendata *opendata; |
| 1513 | int err; |
| 1514 | |
| 1515 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1516 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1517 | if (IS_ERR(opendata)) |
| 1518 | return PTR_ERR(opendata); |
| 1519 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
| 1520 | err = nfs4_open_recover(opendata, state); |
| 1521 | nfs4_opendata_put(opendata); |
| 1522 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1523 | } |
| 1524 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1525 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1526 | { |
| 1527 | struct nfs4_opendata *data = calldata; |
| 1528 | |
| 1529 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1530 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1531 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1532 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1533 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1534 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1535 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | static void nfs4_open_confirm_release(void *calldata) |
| 1539 | { |
| 1540 | struct nfs4_opendata *data = calldata; |
| 1541 | struct nfs4_state *state = NULL; |
| 1542 | |
| 1543 | /* If this request hasn't been cancelled, do nothing */ |
| 1544 | if (data->cancelled == 0) |
| 1545 | goto out_free; |
| 1546 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1547 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1548 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1549 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1550 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1551 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1552 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1553 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1557 | .rpc_call_done = nfs4_open_confirm_done, |
| 1558 | .rpc_release = nfs4_open_confirm_release, |
| 1559 | }; |
| 1560 | |
| 1561 | /* |
| 1562 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1563 | */ |
| 1564 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1565 | { |
| 1566 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1567 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1568 | struct rpc_message msg = { |
| 1569 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1570 | .rpc_argp = &data->c_arg, |
| 1571 | .rpc_resp = &data->c_res, |
| 1572 | .rpc_cred = data->owner->so_cred, |
| 1573 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1574 | struct rpc_task_setup task_setup_data = { |
| 1575 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1576 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1577 | .callback_ops = &nfs4_open_confirm_ops, |
| 1578 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1579 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1580 | .flags = RPC_TASK_ASYNC, |
| 1581 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | int status; |
| 1583 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1584 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1585 | data->rpc_done = 0; |
| 1586 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1587 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1588 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1589 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1590 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1591 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1592 | if (status != 0) { |
| 1593 | data->cancelled = 1; |
| 1594 | smp_wmb(); |
| 1595 | } else |
| 1596 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1597 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | return status; |
| 1599 | } |
| 1600 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1601 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1603 | struct nfs4_opendata *data = calldata; |
| 1604 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1605 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1606 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1607 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1608 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1609 | /* |
| 1610 | * Check if we still need to send an OPEN call, or if we can use |
| 1611 | * a delegation instead. |
| 1612 | */ |
| 1613 | if (data->state != NULL) { |
| 1614 | struct nfs_delegation *delegation; |
| 1615 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1616 | 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] | 1617 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1618 | rcu_read_lock(); |
| 1619 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1620 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
Trond Myklebust | cd4c9be | 2013-04-23 14:46:25 -0400 | [diff] [blame] | 1621 | data->o_arg.claim != NFS4_OPEN_CLAIM_DELEG_CUR_FH && |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1622 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1623 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1624 | rcu_read_unlock(); |
| 1625 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1626 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1627 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1628 | switch (data->o_arg.claim) { |
| 1629 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1630 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1631 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1632 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1633 | case NFS4_OPEN_CLAIM_FH: |
| 1634 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1635 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1636 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1637 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1638 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1639 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1640 | &data->o_res.seq_res, |
| 1641 | task) != 0) |
| 1642 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1643 | |
| 1644 | /* Set the create mode (note dependency on the session type) */ |
| 1645 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 1646 | if (data->o_arg.open_flags & O_EXCL) { |
| 1647 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 1648 | if (nfs4_has_persistent_session(clp)) |
| 1649 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 1650 | else if (clp->cl_mvops->minor_version > 0) |
| 1651 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 1652 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1653 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1654 | unlock_no_action: |
| 1655 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1656 | out_no_action: |
| 1657 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1658 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1659 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1660 | } |
| 1661 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1662 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1663 | { |
| 1664 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1666 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1667 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1668 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1669 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1670 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1671 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1672 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1673 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1674 | case S_IFREG: |
| 1675 | break; |
| 1676 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1677 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1678 | break; |
| 1679 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1680 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1681 | break; |
| 1682 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1683 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1684 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1685 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1686 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1687 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1688 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1689 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1690 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1691 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1692 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1693 | static void nfs4_open_release(void *calldata) |
| 1694 | { |
| 1695 | struct nfs4_opendata *data = calldata; |
| 1696 | struct nfs4_state *state = NULL; |
| 1697 | |
| 1698 | /* If this request hasn't been cancelled, do nothing */ |
| 1699 | if (data->cancelled == 0) |
| 1700 | goto out_free; |
| 1701 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1702 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1703 | goto out_free; |
| 1704 | /* In case we need an open_confirm, no cleanup! */ |
| 1705 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1706 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1707 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1708 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1709 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1710 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1711 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1715 | .rpc_call_prepare = nfs4_open_prepare, |
| 1716 | .rpc_call_done = nfs4_open_done, |
| 1717 | .rpc_release = nfs4_open_release, |
| 1718 | }; |
| 1719 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1720 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1721 | { |
| 1722 | struct inode *dir = data->dir->d_inode; |
| 1723 | struct nfs_server *server = NFS_SERVER(dir); |
| 1724 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1725 | struct nfs_openres *o_res = &data->o_res; |
| 1726 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1727 | struct rpc_message msg = { |
| 1728 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1729 | .rpc_argp = o_arg, |
| 1730 | .rpc_resp = o_res, |
| 1731 | .rpc_cred = data->owner->so_cred, |
| 1732 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1733 | struct rpc_task_setup task_setup_data = { |
| 1734 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1735 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1736 | .callback_ops = &nfs4_open_ops, |
| 1737 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1738 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1739 | .flags = RPC_TASK_ASYNC, |
| 1740 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1741 | int status; |
| 1742 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1743 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1744 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1745 | data->rpc_done = 0; |
| 1746 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1747 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1748 | data->is_recover = 0; |
| 1749 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1750 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1751 | data->is_recover = 1; |
| 1752 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1753 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1754 | if (IS_ERR(task)) |
| 1755 | return PTR_ERR(task); |
| 1756 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1757 | if (status != 0) { |
| 1758 | data->cancelled = 1; |
| 1759 | smp_wmb(); |
| 1760 | } else |
| 1761 | status = data->rpc_status; |
| 1762 | rpc_put_task(task); |
| 1763 | |
| 1764 | return status; |
| 1765 | } |
| 1766 | |
| 1767 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1768 | { |
| 1769 | struct inode *dir = data->dir->d_inode; |
| 1770 | struct nfs_openres *o_res = &data->o_res; |
| 1771 | int status; |
| 1772 | |
| 1773 | status = nfs4_run_open_task(data, 1); |
| 1774 | if (status != 0 || !data->rpc_done) |
| 1775 | return status; |
| 1776 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1777 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1778 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1779 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1780 | status = _nfs4_proc_open_confirm(data); |
| 1781 | if (status != 0) |
| 1782 | return status; |
| 1783 | } |
| 1784 | |
| 1785 | return status; |
| 1786 | } |
| 1787 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1788 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1789 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1790 | struct nfs4_state *state, fmode_t fmode, |
| 1791 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1792 | { |
| 1793 | struct nfs_access_entry cache; |
| 1794 | u32 mask; |
| 1795 | |
| 1796 | /* access call failed or for some reason the server doesn't |
| 1797 | * support any access modes -- defer access call until later */ |
| 1798 | if (opendata->o_res.access_supported == 0) |
| 1799 | return 0; |
| 1800 | |
| 1801 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1802 | /* 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] | 1803 | * write mode bits, but POSIX allows the creating process to write. |
| 1804 | * use openflags to check for exec, because fmode won't |
| 1805 | * always have FMODE_EXEC set when file open for exec. */ |
| 1806 | if (openflags & __FMODE_EXEC) { |
| 1807 | /* ONLY check for exec rights */ |
| 1808 | mask = MAY_EXEC; |
| 1809 | } else if (fmode & FMODE_READ) |
| 1810 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1811 | |
| 1812 | cache.cred = cred; |
| 1813 | cache.jiffies = jiffies; |
| 1814 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1815 | nfs_access_add_cache(state->inode, &cache); |
| 1816 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1817 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1818 | return 0; |
| 1819 | |
| 1820 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1821 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1822 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1823 | } |
| 1824 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1825 | /* |
| 1826 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1827 | */ |
| 1828 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1829 | { |
| 1830 | struct inode *dir = data->dir->d_inode; |
| 1831 | struct nfs_server *server = NFS_SERVER(dir); |
| 1832 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1833 | struct nfs_openres *o_res = &data->o_res; |
| 1834 | int status; |
| 1835 | |
| 1836 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1837 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1838 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1839 | if (status != 0) { |
| 1840 | if (status == -NFS4ERR_BADNAME && |
| 1841 | !(o_arg->open_flags & O_CREAT)) |
| 1842 | return -ENOENT; |
| 1843 | return status; |
| 1844 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1845 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1846 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1847 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1848 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1849 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1850 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1851 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1853 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1855 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | } |
| 1857 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1858 | _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] | 1859 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | } |
| 1861 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1862 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1863 | { |
| 1864 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1865 | } |
| 1866 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | /* |
| 1868 | * OPEN_EXPIRED: |
| 1869 | * reclaim state on the server after a network partition. |
| 1870 | * Assumes caller holds the appropriate lock |
| 1871 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1872 | 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] | 1873 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1874 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1875 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1877 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1878 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1879 | if (IS_ERR(opendata)) |
| 1880 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1881 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1882 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1883 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1884 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1885 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | } |
| 1887 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1888 | 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] | 1889 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1890 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1891 | struct nfs4_exception exception = { }; |
| 1892 | int err; |
| 1893 | |
| 1894 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1895 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1896 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1897 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1898 | switch (err) { |
| 1899 | default: |
| 1900 | goto out; |
| 1901 | case -NFS4ERR_GRACE: |
| 1902 | case -NFS4ERR_DELAY: |
| 1903 | nfs4_handle_exception(server, err, &exception); |
| 1904 | err = 0; |
| 1905 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1906 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1907 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1908 | return err; |
| 1909 | } |
| 1910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1912 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1914 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1916 | ctx = nfs4_state_find_open_context(state); |
| 1917 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1918 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1919 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1920 | put_nfs_open_context(ctx); |
| 1921 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | } |
| 1923 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1924 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1925 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1926 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1927 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1928 | nfs4_stateid *stateid = &state->stateid; |
| 1929 | int status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1930 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1931 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1932 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1933 | return; |
| 1934 | |
| 1935 | status = nfs41_test_stateid(server, stateid); |
| 1936 | if (status != NFS_OK) { |
| 1937 | /* Free the stateid unless the server explicitly |
| 1938 | * informs us the stateid is unrecognized. */ |
| 1939 | if (status != -NFS4ERR_BAD_STATEID) |
| 1940 | nfs41_free_stateid(server, stateid); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1941 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1942 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1943 | write_seqlock(&state->seqlock); |
| 1944 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1945 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1946 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1947 | } |
| 1948 | } |
| 1949 | |
| 1950 | /** |
| 1951 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1952 | * |
| 1953 | * @state: NFSv4 state for an inode |
| 1954 | * |
| 1955 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1956 | * Otherwise a negative NFS4ERR value is returned. |
| 1957 | */ |
| 1958 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1959 | { |
| 1960 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1961 | nfs4_stateid *stateid = &state->open_stateid; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1962 | int status; |
| 1963 | |
| 1964 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1965 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1966 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1967 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1968 | return -NFS4ERR_BAD_STATEID; |
| 1969 | |
| 1970 | status = nfs41_test_stateid(server, stateid); |
| 1971 | if (status != NFS_OK) { |
| 1972 | /* Free the stateid unless the server explicitly |
| 1973 | * informs us the stateid is unrecognized. */ |
| 1974 | if (status != -NFS4ERR_BAD_STATEID) |
| 1975 | nfs41_free_stateid(server, stateid); |
| 1976 | |
| 1977 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1978 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1979 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1980 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1981 | } |
| 1982 | return status; |
| 1983 | } |
| 1984 | |
| 1985 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1986 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1987 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1988 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1989 | nfs41_clear_delegation_stateid(state); |
| 1990 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1991 | if (status != NFS_OK) |
| 1992 | status = nfs4_open_expired(sp, state); |
| 1993 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1994 | } |
| 1995 | #endif |
| 1996 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1997 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1998 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1999 | * fields corresponding to attributes that were used to store the verifier. |
| 2000 | * Make sure we clobber those fields in the later setattr call |
| 2001 | */ |
| 2002 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 2003 | { |
| 2004 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 2005 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2006 | sattr->ia_valid |= ATTR_ATIME; |
| 2007 | |
| 2008 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 2009 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2010 | sattr->ia_valid |= ATTR_MTIME; |
| 2011 | } |
| 2012 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2013 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2014 | fmode_t fmode, |
| 2015 | int flags, |
| 2016 | struct nfs4_state **res) |
| 2017 | { |
| 2018 | struct nfs4_state_owner *sp = opendata->owner; |
| 2019 | struct nfs_server *server = sp->so_server; |
| 2020 | struct nfs4_state *state; |
| 2021 | unsigned int seq; |
| 2022 | int ret; |
| 2023 | |
| 2024 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2025 | |
| 2026 | ret = _nfs4_proc_open(opendata); |
| 2027 | if (ret != 0) |
| 2028 | goto out; |
| 2029 | |
| 2030 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2031 | ret = PTR_ERR(state); |
| 2032 | if (IS_ERR(state)) |
| 2033 | goto out; |
| 2034 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2035 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 2036 | |
| 2037 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2038 | if (ret != 0) |
| 2039 | goto out; |
| 2040 | |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2041 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2042 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2043 | *res = state; |
| 2044 | out: |
| 2045 | return ret; |
| 2046 | } |
| 2047 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2048 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2049 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2051 | static int _nfs4_do_open(struct inode *dir, |
| 2052 | struct dentry *dentry, |
| 2053 | fmode_t fmode, |
| 2054 | int flags, |
| 2055 | struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2056 | struct nfs4_label *label, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2057 | struct rpc_cred *cred, |
| 2058 | struct nfs4_state **res, |
| 2059 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | { |
| 2061 | struct nfs4_state_owner *sp; |
| 2062 | struct nfs4_state *state = NULL; |
| 2063 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2064 | struct nfs4_opendata *opendata; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2065 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2066 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2067 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | |
| 2069 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2071 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2072 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2074 | goto out_err; |
| 2075 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2076 | status = nfs4_recover_expired_lease(server); |
| 2077 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2078 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2079 | if (dentry->d_inode != NULL) |
| 2080 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2081 | status = -ENOMEM; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2082 | if (dentry->d_inode) |
| 2083 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2084 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2085 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2086 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2087 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2089 | if (label) { |
| 2090 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2091 | if (IS_ERR(olabel)) { |
| 2092 | status = PTR_ERR(olabel); |
| 2093 | goto err_opendata_put; |
| 2094 | } |
| 2095 | } |
| 2096 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2097 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2098 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2099 | if (!opendata->f_attr.mdsthreshold) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2100 | goto err_free_label; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2101 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2102 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2103 | if (dentry->d_inode != NULL) |
| 2104 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2105 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2106 | status = _nfs4_open_and_get_state(opendata, fmode, flags, &state); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2107 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2108 | goto err_free_label; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2109 | |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2110 | if ((opendata->o_arg.open_flags & O_EXCL) && |
| 2111 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2112 | nfs4_exclusive_attrset(opendata, sattr); |
| 2113 | |
| 2114 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2115 | status = nfs4_do_setattr(state->inode, cred, |
| 2116 | opendata->o_res.f_attr, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2117 | state, label, olabel); |
| 2118 | if (status == 0) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2119 | nfs_setattr_update_inode(state->inode, sattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2120 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2121 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2122 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2123 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2124 | |
| 2125 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 2126 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 2127 | else |
| 2128 | kfree(opendata->f_attr.mdsthreshold); |
| 2129 | opendata->f_attr.mdsthreshold = NULL; |
| 2130 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2131 | nfs4_label_free(olabel); |
| 2132 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2133 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | *res = state; |
| 2136 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2137 | err_free_label: |
| 2138 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2139 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2140 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2141 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2142 | err_put_state_owner: |
| 2143 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2145 | *res = NULL; |
| 2146 | return status; |
| 2147 | } |
| 2148 | |
| 2149 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2150 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
| 2151 | struct dentry *dentry, |
| 2152 | fmode_t fmode, |
| 2153 | int flags, |
| 2154 | struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2155 | struct nfs4_label *label, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2156 | struct rpc_cred *cred, |
| 2157 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2159 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | struct nfs4_exception exception = { }; |
| 2161 | struct nfs4_state *res; |
| 2162 | int status; |
| 2163 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2164 | fmode &= FMODE_READ|FMODE_WRITE|FMODE_EXEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2166 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, label, cred, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2167 | &res, ctx_th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | if (status == 0) |
| 2169 | break; |
| 2170 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2171 | * book-keeping w.r.t. state-changing operations |
| 2172 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2173 | * It is actually a sign of a bug on the client or on the server. |
| 2174 | * |
| 2175 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2176 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | * have unhashed the old state_owner for us, and that we can |
| 2178 | * therefore safely retry using a new one. We should still warn |
| 2179 | * the user though... |
| 2180 | */ |
| 2181 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2182 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2183 | " returned a bad sequence-id error!\n", |
| 2184 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | exception.retry = 1; |
| 2186 | continue; |
| 2187 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2188 | /* |
| 2189 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2190 | * state before it received the OPEN_CONFIRM. |
| 2191 | * Recover by retrying the request as per the discussion |
| 2192 | * on Page 181 of RFC3530. |
| 2193 | */ |
| 2194 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2195 | exception.retry = 1; |
| 2196 | continue; |
| 2197 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2198 | if (status == -EAGAIN) { |
| 2199 | /* We must have found a delegation */ |
| 2200 | exception.retry = 1; |
| 2201 | continue; |
| 2202 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2203 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2204 | continue; |
| 2205 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2206 | status, &exception)); |
| 2207 | } while (exception.retry); |
| 2208 | return res; |
| 2209 | } |
| 2210 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2211 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2212 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2213 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2214 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2215 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2216 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2217 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2218 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | .iap = sattr, |
| 2220 | .server = server, |
| 2221 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2222 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | }; |
| 2224 | struct nfs_setattrres res = { |
| 2225 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2226 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | .server = server, |
| 2228 | }; |
| 2229 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2230 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2231 | .rpc_argp = &arg, |
| 2232 | .rpc_resp = &res, |
| 2233 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2235 | unsigned long timestamp = jiffies; |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2236 | fmode_t fmode; |
| 2237 | bool truncate; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2238 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2240 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2241 | if (ilabel) |
| 2242 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2243 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2244 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2246 | /* Servers should only apply open mode checks for file size changes */ |
| 2247 | truncate = (sattr->ia_valid & ATTR_SIZE) ? true : false; |
| 2248 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2249 | |
| 2250 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) { |
| 2251 | /* Use that stateid */ |
| 2252 | } else if (truncate && state != NULL && nfs4_valid_open_stateid(state)) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2253 | struct nfs_lockowner lockowner = { |
| 2254 | .l_owner = current->files, |
| 2255 | .l_pid = current->tgid, |
| 2256 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2257 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2258 | &lockowner); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2259 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2260 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2261 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2262 | 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] | 2263 | if (status == 0 && state != NULL) |
| 2264 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2265 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | } |
| 2267 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2268 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2269 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2270 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2271 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2273 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2274 | struct nfs4_exception exception = { |
| 2275 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2276 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2277 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | int err; |
| 2279 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2280 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state, ilabel, olabel); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2281 | switch (err) { |
| 2282 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2283 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2284 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2285 | "applying open mode checks to " |
| 2286 | "a SETATTR that is not " |
| 2287 | "changing file size.\n", |
| 2288 | server->nfs_client->cl_hostname); |
| 2289 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2290 | if (state && !(state->state & FMODE_WRITE)) { |
| 2291 | err = -EBADF; |
| 2292 | if (sattr->ia_valid & ATTR_OPEN) |
| 2293 | err = -EACCES; |
| 2294 | goto out; |
| 2295 | } |
| 2296 | } |
| 2297 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2299 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | return err; |
| 2301 | } |
| 2302 | |
| 2303 | struct nfs4_closedata { |
| 2304 | struct inode *inode; |
| 2305 | struct nfs4_state *state; |
| 2306 | struct nfs_closeargs arg; |
| 2307 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2308 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2309 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2310 | bool roc; |
| 2311 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | }; |
| 2313 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2314 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2315 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2316 | struct nfs4_closedata *calldata = data; |
| 2317 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2318 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2319 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2320 | if (calldata->roc) |
| 2321 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2322 | nfs4_put_open_state(calldata->state); |
| 2323 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2324 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2325 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2326 | kfree(calldata); |
| 2327 | } |
| 2328 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2329 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2330 | fmode_t fmode) |
| 2331 | { |
| 2332 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2333 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2334 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 2335 | case FMODE_WRITE: |
| 2336 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2337 | break; |
| 2338 | case FMODE_READ: |
| 2339 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2340 | break; |
| 2341 | case 0: |
| 2342 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2343 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2344 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 2345 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2346 | spin_unlock(&state->owner->so_lock); |
| 2347 | } |
| 2348 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2349 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2351 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2353 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2354 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2355 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2356 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2357 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 | /* hmm. we are done with the inode, and in the process of freeing |
| 2359 | * the state_owner. we keep this around to process errors |
| 2360 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | switch (task->tk_status) { |
| 2362 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2363 | if (calldata->roc) |
| 2364 | pnfs_roc_set_barrier(state->inode, |
| 2365 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2366 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2367 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2368 | nfs4_close_clear_stateid_flags(state, |
| 2369 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2370 | break; |
| 2371 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2372 | case -NFS4ERR_OLD_STATEID: |
| 2373 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2375 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2376 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2378 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2379 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2381 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2382 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2383 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | } |
| 2385 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2386 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2388 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2389 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2390 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2391 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2392 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2393 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2394 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2395 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2396 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2397 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2398 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2399 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2400 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2401 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2402 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2403 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2404 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2405 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2406 | } |
| 2407 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2408 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2409 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2410 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2411 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2412 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2413 | if (!nfs4_valid_open_stateid(state)) |
| 2414 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2415 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2416 | |
| 2417 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2418 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2419 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2420 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2421 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2422 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2423 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2424 | if (calldata->roc && |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2425 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) { |
| 2426 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2427 | goto out_wait; |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2428 | } |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2429 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2430 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2431 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2432 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2433 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2434 | &calldata->arg.seq_args, |
| 2435 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2436 | task) != 0) |
| 2437 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2438 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2439 | return; |
| 2440 | out_no_action: |
| 2441 | task->tk_action = NULL; |
| 2442 | out_wait: |
| 2443 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | } |
| 2445 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2446 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2447 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2448 | .rpc_call_done = nfs4_close_done, |
| 2449 | .rpc_release = nfs4_free_closedata, |
| 2450 | }; |
| 2451 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2452 | /* |
| 2453 | * It is possible for data to be read/written from a mem-mapped file |
| 2454 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2455 | * This means that we can't safely call nfsv4 close on a file until |
| 2456 | * the inode is cleared. This in turn means that we are not good |
| 2457 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2458 | * share state even when we are done with one of the three share |
| 2459 | * stateid's in the inode. |
| 2460 | * |
| 2461 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2462 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2463 | 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] | 2464 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2465 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2467 | struct nfs4_state_owner *sp = state->owner; |
| 2468 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2469 | struct rpc_message msg = { |
| 2470 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2471 | .rpc_cred = state->owner->so_cred, |
| 2472 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2473 | struct rpc_task_setup task_setup_data = { |
| 2474 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2475 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2476 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2477 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2478 | .flags = RPC_TASK_ASYNC, |
| 2479 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2480 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2481 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2482 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2483 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2484 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2485 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2486 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2488 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2489 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2490 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2491 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2492 | if (calldata->arg.seqid == NULL) |
| 2493 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2494 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2495 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2496 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2497 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2498 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2499 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2500 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2501 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2502 | msg.rpc_argp = &calldata->arg; |
| 2503 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2504 | task_setup_data.callback_data = calldata; |
| 2505 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2506 | if (IS_ERR(task)) |
| 2507 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2508 | status = 0; |
| 2509 | if (wait) |
| 2510 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2511 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2512 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2513 | out_free_calldata: |
| 2514 | kfree(calldata); |
| 2515 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2516 | nfs4_put_open_state(state); |
| 2517 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2518 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2519 | } |
| 2520 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2521 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2522 | 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] | 2523 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2525 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 2526 | |
| 2527 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2528 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2529 | /* Protect against concurrent sillydeletes */ |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2530 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, label, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2531 | ctx->cred, &ctx->mdsthreshold); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2532 | |
| 2533 | nfs4_label_release_security(label); |
| 2534 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2535 | if (IS_ERR(state)) |
| 2536 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2537 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2538 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2539 | } |
| 2540 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2541 | 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] | 2542 | { |
| 2543 | if (ctx->state == NULL) |
| 2544 | return; |
| 2545 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2546 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2547 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2548 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2549 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2550 | |
| 2551 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2552 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2553 | struct nfs4_server_caps_arg args = { |
| 2554 | .fhandle = fhandle, |
| 2555 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2556 | struct nfs4_server_caps_res res = {}; |
| 2557 | struct rpc_message msg = { |
| 2558 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2559 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2560 | .rpc_resp = &res, |
| 2561 | }; |
| 2562 | int status; |
| 2563 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2564 | 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] | 2565 | if (status == 0) { |
| 2566 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2567 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2568 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2569 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2570 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2571 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2572 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2573 | server->caps |= NFS_CAP_ACLS; |
| 2574 | if (res.has_links != 0) |
| 2575 | server->caps |= NFS_CAP_HARDLINKS; |
| 2576 | if (res.has_symlinks != 0) |
| 2577 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2578 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2579 | server->caps |= NFS_CAP_FILEID; |
| 2580 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2581 | server->caps |= NFS_CAP_MODE; |
| 2582 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2583 | server->caps |= NFS_CAP_NLINK; |
| 2584 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2585 | server->caps |= NFS_CAP_OWNER; |
| 2586 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2587 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2588 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2589 | server->caps |= NFS_CAP_ATIME; |
| 2590 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2591 | server->caps |= NFS_CAP_CTIME; |
| 2592 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2593 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2594 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 2595 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2596 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 2597 | #endif |
| 2598 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 2599 | sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2600 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2601 | if (server->caps & NFS_CAP_SECURITY_LABEL) { |
| 2602 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2603 | res.attr_bitmask[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2604 | } |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2605 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2606 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2607 | 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] | 2608 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2609 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2610 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2611 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2612 | return status; |
| 2613 | } |
| 2614 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2615 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2616 | { |
| 2617 | struct nfs4_exception exception = { }; |
| 2618 | int err; |
| 2619 | do { |
| 2620 | err = nfs4_handle_exception(server, |
| 2621 | _nfs4_server_capabilities(server, fhandle), |
| 2622 | &exception); |
| 2623 | } while (exception.retry); |
| 2624 | return err; |
| 2625 | } |
| 2626 | |
| 2627 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2628 | struct nfs_fsinfo *info) |
| 2629 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2630 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2632 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | }; |
| 2634 | struct nfs4_lookup_res res = { |
| 2635 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2636 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | .fh = fhandle, |
| 2638 | }; |
| 2639 | struct rpc_message msg = { |
| 2640 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2641 | .rpc_argp = &args, |
| 2642 | .rpc_resp = &res, |
| 2643 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2644 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2645 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 2646 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 2647 | /* |
| 2648 | * Process the label in the upcoming getfattr |
| 2649 | */ |
| 2650 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 2651 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2652 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2653 | 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] | 2654 | } |
| 2655 | |
| 2656 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2657 | struct nfs_fsinfo *info) |
| 2658 | { |
| 2659 | struct nfs4_exception exception = { }; |
| 2660 | int err; |
| 2661 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2662 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2663 | switch (err) { |
| 2664 | case 0: |
| 2665 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2666 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2667 | default: |
| 2668 | err = nfs4_handle_exception(server, err, &exception); |
| 2669 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2671 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | return err; |
| 2673 | } |
| 2674 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2675 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2676 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2677 | { |
| 2678 | struct rpc_auth *auth; |
| 2679 | int ret; |
| 2680 | |
| 2681 | auth = rpcauth_create(flavor, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2682 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 2683 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2684 | goto out; |
| 2685 | } |
| 2686 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2687 | out: |
| 2688 | return ret; |
| 2689 | } |
| 2690 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2691 | /* |
| 2692 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 2693 | * |
| 2694 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 2695 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 2696 | * |
| 2697 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 2698 | * negative errno value. |
| 2699 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2700 | 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] | 2701 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2703 | /* Per 3530bis 15.33.5 */ |
| 2704 | static const rpc_authflavor_t flav_array[] = { |
| 2705 | RPC_AUTH_GSS_KRB5P, |
| 2706 | RPC_AUTH_GSS_KRB5I, |
| 2707 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 2708 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2709 | RPC_AUTH_NULL, |
| 2710 | }; |
| 2711 | int status = -EPERM; |
| 2712 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2713 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2714 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2715 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2716 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2717 | continue; |
| 2718 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2719 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2720 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2721 | /* |
| 2722 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2723 | * to access the mount. It could also mean that we tried to mount |
| 2724 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2725 | * existing mount programs don't handle -EACCES very well so it should |
| 2726 | * be mapped to -EPERM instead. |
| 2727 | */ |
| 2728 | if (status == -EACCES) |
| 2729 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2730 | return status; |
| 2731 | } |
| 2732 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2733 | static int nfs4_do_find_root_sec(struct nfs_server *server, |
| 2734 | struct nfs_fh *fhandle, struct nfs_fsinfo *info) |
| 2735 | { |
| 2736 | int mv = server->nfs_client->cl_minorversion; |
| 2737 | return nfs_v4_minor_ops[mv]->find_root_sec(server, fhandle, info); |
| 2738 | } |
| 2739 | |
| 2740 | /** |
| 2741 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 2742 | * @server: initialized nfs_server handle |
| 2743 | * @fhandle: we fill in the pseudo-fs root file handle |
| 2744 | * @info: we fill in an FSINFO struct |
| 2745 | * |
| 2746 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2747 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2748 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2749 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2750 | { |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2751 | int status; |
| 2752 | |
| 2753 | status = nfs4_lookup_root(server, fhandle, info); |
| 2754 | if ((status == -NFS4ERR_WRONGSEC) && |
| 2755 | !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2756 | status = nfs4_do_find_root_sec(server, fhandle, info); |
| 2757 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2758 | if (status == 0) |
| 2759 | status = nfs4_server_capabilities(server, fhandle); |
| 2760 | if (status == 0) |
| 2761 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2762 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2763 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | } |
| 2765 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2766 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2767 | struct nfs_fsinfo *info) |
| 2768 | { |
| 2769 | int error; |
| 2770 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2771 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2772 | |
| 2773 | error = nfs4_server_capabilities(server, mntfh); |
| 2774 | if (error < 0) { |
| 2775 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2776 | return error; |
| 2777 | } |
| 2778 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2779 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 2780 | if (IS_ERR(label)) |
| 2781 | return PTR_ERR(label); |
| 2782 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2783 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2784 | if (error < 0) { |
| 2785 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2786 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2787 | } |
| 2788 | |
| 2789 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2790 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2791 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2792 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2793 | err_free_label: |
| 2794 | nfs4_label_free(label); |
| 2795 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2796 | return error; |
| 2797 | } |
| 2798 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2799 | /* |
| 2800 | * Get locations and (maybe) other attributes of a referral. |
| 2801 | * Note that we'll actually follow the referral later when |
| 2802 | * we detect fsid mismatch in inode revalidation |
| 2803 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2804 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2805 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2806 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2807 | { |
| 2808 | int status = -ENOMEM; |
| 2809 | struct page *page = NULL; |
| 2810 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2811 | |
| 2812 | page = alloc_page(GFP_KERNEL); |
| 2813 | if (page == NULL) |
| 2814 | goto out; |
| 2815 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2816 | if (locations == NULL) |
| 2817 | goto out; |
| 2818 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2819 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2820 | if (status != 0) |
| 2821 | goto out; |
| 2822 | /* Make sure server returned a different fsid for the referral */ |
| 2823 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2824 | dprintk("%s: server did not return a different fsid for" |
| 2825 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2826 | status = -EIO; |
| 2827 | goto out; |
| 2828 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2829 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2830 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2831 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2832 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2833 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2834 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2835 | out: |
| 2836 | if (page) |
| 2837 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2838 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2839 | return status; |
| 2840 | } |
| 2841 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2842 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2843 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | { |
| 2845 | struct nfs4_getattr_arg args = { |
| 2846 | .fh = fhandle, |
| 2847 | .bitmask = server->attr_bitmask, |
| 2848 | }; |
| 2849 | struct nfs4_getattr_res res = { |
| 2850 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2851 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | .server = server, |
| 2853 | }; |
| 2854 | struct rpc_message msg = { |
| 2855 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2856 | .rpc_argp = &args, |
| 2857 | .rpc_resp = &res, |
| 2858 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2859 | |
| 2860 | args.bitmask = nfs4_bitmask(server, label); |
| 2861 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2862 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2863 | 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] | 2864 | } |
| 2865 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2866 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2867 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | { |
| 2869 | struct nfs4_exception exception = { }; |
| 2870 | int err; |
| 2871 | do { |
| 2872 | err = nfs4_handle_exception(server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2873 | _nfs4_proc_getattr(server, fhandle, fattr, label), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | &exception); |
| 2875 | } while (exception.retry); |
| 2876 | return err; |
| 2877 | } |
| 2878 | |
| 2879 | /* |
| 2880 | * The file is not closed if it is opened due to the a request to change |
| 2881 | * the size of the file. The open call will not be needed once the |
| 2882 | * VFS layer lookup-intents are implemented. |
| 2883 | * |
| 2884 | * Close is called when the inode is destroyed. |
| 2885 | * If we haven't opened the file for O_WRONLY, we |
| 2886 | * need to in the size_change case to obtain a stateid. |
| 2887 | * |
| 2888 | * Got race? |
| 2889 | * Because OPEN is always done by name in nfsv4, it is |
| 2890 | * possible that we opened a different file by the same |
| 2891 | * name. We can recognize this race condition, but we |
| 2892 | * can't do anything about it besides returning an error. |
| 2893 | * |
| 2894 | * This will be fixed with VFS changes (lookup-intent). |
| 2895 | */ |
| 2896 | static int |
| 2897 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2898 | struct iattr *sattr) |
| 2899 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2900 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2901 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2902 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2903 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2904 | int status; |
| 2905 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2906 | if (pnfs_ld_layoutret_on_setattr(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 2907 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2908 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2909 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2910 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2911 | /* Deal with open(O_TRUNC) */ |
| 2912 | if (sattr->ia_valid & ATTR_OPEN) |
| 2913 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2914 | |
| 2915 | /* Optimization: if the end result is no change, don't RPC */ |
| 2916 | if ((sattr->ia_valid & ~(ATTR_FILE)) == 0) |
| 2917 | return 0; |
| 2918 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2919 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2920 | if (sattr->ia_valid & ATTR_FILE) { |
| 2921 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2922 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2923 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2924 | if (ctx) { |
| 2925 | cred = ctx->cred; |
| 2926 | state = ctx->state; |
| 2927 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2928 | } |
| 2929 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2930 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 2931 | if (IS_ERR(label)) |
| 2932 | return PTR_ERR(label); |
| 2933 | |
| 2934 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2935 | if (status == 0) { |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2936 | nfs_setattr_update_inode(inode, sattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2937 | nfs_setsecurity(inode, fattr, label); |
| 2938 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2939 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2940 | return status; |
| 2941 | } |
| 2942 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2943 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2944 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2945 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2946 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2947 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2948 | int status; |
| 2949 | struct nfs4_lookup_arg args = { |
| 2950 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2951 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2952 | .name = name, |
| 2953 | }; |
| 2954 | struct nfs4_lookup_res res = { |
| 2955 | .server = server, |
| 2956 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2957 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2958 | .fh = fhandle, |
| 2959 | }; |
| 2960 | struct rpc_message msg = { |
| 2961 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2962 | .rpc_argp = &args, |
| 2963 | .rpc_resp = &res, |
| 2964 | }; |
| 2965 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2966 | args.bitmask = nfs4_bitmask(server, label); |
| 2967 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2968 | nfs_fattr_init(fattr); |
| 2969 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2971 | 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] | 2972 | dprintk("NFS reply lookup: %d\n", status); |
| 2973 | return status; |
| 2974 | } |
| 2975 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2976 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2977 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2978 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2979 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2980 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2981 | fattr->nlink = 2; |
| 2982 | } |
| 2983 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2984 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2985 | struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2986 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2987 | { |
| 2988 | struct nfs4_exception exception = { }; |
| 2989 | struct rpc_clnt *client = *clnt; |
| 2990 | int err; |
| 2991 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2992 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2993 | switch (err) { |
| 2994 | case -NFS4ERR_BADNAME: |
| 2995 | err = -ENOENT; |
| 2996 | goto out; |
| 2997 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2998 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2999 | goto out; |
| 3000 | case -NFS4ERR_WRONGSEC: |
| 3001 | err = -EPERM; |
| 3002 | if (client != *clnt) |
| 3003 | goto out; |
| 3004 | |
| 3005 | client = nfs4_create_sec_client(client, dir, name); |
| 3006 | if (IS_ERR(client)) |
| 3007 | return PTR_ERR(client); |
| 3008 | |
| 3009 | exception.retry = 1; |
| 3010 | break; |
| 3011 | default: |
| 3012 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3013 | } |
| 3014 | } while (exception.retry); |
| 3015 | |
| 3016 | out: |
| 3017 | if (err == 0) |
| 3018 | *clnt = client; |
| 3019 | else if (client != *clnt) |
| 3020 | rpc_shutdown_client(client); |
| 3021 | |
| 3022 | return err; |
| 3023 | } |
| 3024 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 3025 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3026 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3027 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3028 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3029 | int status; |
| 3030 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3031 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3032 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3033 | if (client != NFS_CLIENT(dir)) { |
| 3034 | rpc_shutdown_client(client); |
| 3035 | nfs_fixup_secinfo_attributes(fattr); |
| 3036 | } |
| 3037 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3038 | } |
| 3039 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3040 | struct rpc_clnt * |
| 3041 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 3042 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3043 | { |
| 3044 | int status; |
| 3045 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 3046 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3047 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3048 | if (status < 0) { |
| 3049 | rpc_shutdown_client(client); |
| 3050 | return ERR_PTR(status); |
| 3051 | } |
| 3052 | return client; |
| 3053 | } |
| 3054 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3056 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3057 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | struct nfs4_accessargs args = { |
| 3059 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3060 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3062 | struct nfs4_accessres res = { |
| 3063 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3064 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | struct rpc_message msg = { |
| 3066 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3067 | .rpc_argp = &args, |
| 3068 | .rpc_resp = &res, |
| 3069 | .rpc_cred = entry->cred, |
| 3070 | }; |
| 3071 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3072 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | |
| 3074 | /* |
| 3075 | * Determine which access bits we want to ask for... |
| 3076 | */ |
| 3077 | if (mode & MAY_READ) |
| 3078 | args.access |= NFS4_ACCESS_READ; |
| 3079 | if (S_ISDIR(inode->i_mode)) { |
| 3080 | if (mode & MAY_WRITE) |
| 3081 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3082 | if (mode & MAY_EXEC) |
| 3083 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3084 | } else { |
| 3085 | if (mode & MAY_WRITE) |
| 3086 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3087 | if (mode & MAY_EXEC) |
| 3088 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3089 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3090 | |
| 3091 | res.fattr = nfs_alloc_fattr(); |
| 3092 | if (res.fattr == NULL) |
| 3093 | return -ENOMEM; |
| 3094 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3095 | 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] | 3096 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3097 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3098 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3099 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3100 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | return status; |
| 3102 | } |
| 3103 | |
| 3104 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3105 | { |
| 3106 | struct nfs4_exception exception = { }; |
| 3107 | int err; |
| 3108 | do { |
| 3109 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3110 | _nfs4_proc_access(inode, entry), |
| 3111 | &exception); |
| 3112 | } while (exception.retry); |
| 3113 | return err; |
| 3114 | } |
| 3115 | |
| 3116 | /* |
| 3117 | * TODO: For the time being, we don't try to get any attributes |
| 3118 | * along with any of the zero-copy operations READ, READDIR, |
| 3119 | * READLINK, WRITE. |
| 3120 | * |
| 3121 | * In the case of the first three, we want to put the GETATTR |
| 3122 | * after the read-type operation -- this is because it is hard |
| 3123 | * to predict the length of a GETATTR response in v4, and thus |
| 3124 | * align the READ data correctly. This means that the GETATTR |
| 3125 | * may end up partially falling into the page cache, and we should |
| 3126 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3127 | * To do this efficiently, we need to know the total length |
| 3128 | * of data received, which doesn't seem to be available outside |
| 3129 | * of the RPC layer. |
| 3130 | * |
| 3131 | * In the case of WRITE, we also want to put the GETATTR after |
| 3132 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3133 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | * |
| 3135 | * Both of these changes to the XDR layer would in fact be quite |
| 3136 | * minor, but I decided to leave them for a subsequent patch. |
| 3137 | */ |
| 3138 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3139 | unsigned int pgbase, unsigned int pglen) |
| 3140 | { |
| 3141 | struct nfs4_readlink args = { |
| 3142 | .fh = NFS_FH(inode), |
| 3143 | .pgbase = pgbase, |
| 3144 | .pglen = pglen, |
| 3145 | .pages = &page, |
| 3146 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3147 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | struct rpc_message msg = { |
| 3149 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3150 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3151 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3152 | }; |
| 3153 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3154 | 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] | 3155 | } |
| 3156 | |
| 3157 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3158 | unsigned int pgbase, unsigned int pglen) |
| 3159 | { |
| 3160 | struct nfs4_exception exception = { }; |
| 3161 | int err; |
| 3162 | do { |
| 3163 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3164 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 3165 | &exception); |
| 3166 | } while (exception.retry); |
| 3167 | return err; |
| 3168 | } |
| 3169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3170 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3171 | * 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] | 3172 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | static int |
| 3174 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3175 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3176 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3177 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3178 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3179 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3180 | int status = 0; |
| 3181 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3182 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3183 | if (IS_ERR(ctx)) |
| 3184 | return PTR_ERR(ctx); |
| 3185 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3186 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3187 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3188 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 8626e4a | 2012-07-16 12:01:42 -0400 | [diff] [blame] | 3189 | state = nfs4_do_open(dir, dentry, ctx->mode, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3190 | flags, sattr, ilabel, ctx->cred, |
Trond Myklebust | 8626e4a | 2012-07-16 12:01:42 -0400 | [diff] [blame] | 3191 | &ctx->mdsthreshold); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 3192 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | if (IS_ERR(state)) { |
| 3194 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3195 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 3197 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 3198 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3199 | ctx->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3201 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3202 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | return status; |
| 3204 | } |
| 3205 | |
| 3206 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3207 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3208 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3209 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3211 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3213 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3214 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3215 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3217 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3218 | .rpc_argp = &args, |
| 3219 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3221 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3222 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3223 | 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] | 3224 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3225 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | return status; |
| 3227 | } |
| 3228 | |
| 3229 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3230 | { |
| 3231 | struct nfs4_exception exception = { }; |
| 3232 | int err; |
| 3233 | do { |
| 3234 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3235 | _nfs4_proc_remove(dir, name), |
| 3236 | &exception); |
| 3237 | } while (exception.retry); |
| 3238 | return err; |
| 3239 | } |
| 3240 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3241 | 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] | 3242 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3243 | struct nfs_server *server = NFS_SERVER(dir); |
| 3244 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3245 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3247 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3248 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3249 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3250 | |
| 3251 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3252 | } |
| 3253 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3254 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3255 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3256 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 3257 | &data->args.seq_args, |
| 3258 | &data->res.seq_res, |
| 3259 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | } |
| 3261 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3262 | 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] | 3263 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3264 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 3265 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3266 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3267 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3268 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3269 | return 0; |
| 3270 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3271 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | } |
| 3273 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3274 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3275 | { |
| 3276 | struct nfs_server *server = NFS_SERVER(dir); |
| 3277 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3278 | struct nfs_renameres *res = msg->rpc_resp; |
| 3279 | |
| 3280 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3281 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3282 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3283 | } |
| 3284 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3285 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3286 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3287 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3288 | &data->args.seq_args, |
| 3289 | &data->res.seq_res, |
| 3290 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3291 | } |
| 3292 | |
| 3293 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3294 | struct inode *new_dir) |
| 3295 | { |
| 3296 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 3297 | |
| 3298 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3299 | return 0; |
| 3300 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 3301 | return 0; |
| 3302 | |
| 3303 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3304 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3305 | return 1; |
| 3306 | } |
| 3307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3309 | struct inode *new_dir, struct qstr *new_name) |
| 3310 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3311 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 3312 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3313 | .old_dir = NFS_FH(old_dir), |
| 3314 | .new_dir = NFS_FH(new_dir), |
| 3315 | .old_name = old_name, |
| 3316 | .new_name = new_name, |
| 3317 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3318 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3319 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3320 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3321 | struct rpc_message msg = { |
| 3322 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3323 | .rpc_argp = &arg, |
| 3324 | .rpc_resp = &res, |
| 3325 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3326 | int status = -ENOMEM; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3327 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3328 | 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] | 3329 | if (!status) { |
| 3330 | update_changeattr(old_dir, &res.old_cinfo); |
| 3331 | update_changeattr(new_dir, &res.new_cinfo); |
| 3332 | } |
| 3333 | return status; |
| 3334 | } |
| 3335 | |
| 3336 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3337 | struct inode *new_dir, struct qstr *new_name) |
| 3338 | { |
| 3339 | struct nfs4_exception exception = { }; |
| 3340 | int err; |
| 3341 | do { |
| 3342 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3343 | _nfs4_proc_rename(old_dir, old_name, |
| 3344 | new_dir, new_name), |
| 3345 | &exception); |
| 3346 | } while (exception.retry); |
| 3347 | return err; |
| 3348 | } |
| 3349 | |
| 3350 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3351 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3352 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3353 | struct nfs4_link_arg arg = { |
| 3354 | .fh = NFS_FH(inode), |
| 3355 | .dir_fh = NFS_FH(dir), |
| 3356 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3357 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3358 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3359 | struct nfs4_link_res res = { |
| 3360 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3361 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3362 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3363 | struct rpc_message msg = { |
| 3364 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3365 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3366 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3368 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3370 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3371 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3372 | goto out; |
| 3373 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3374 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3375 | if (IS_ERR(res.label)) { |
| 3376 | status = PTR_ERR(res.label); |
| 3377 | goto out; |
| 3378 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3379 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3380 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3381 | 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] | 3382 | if (!status) { |
| 3383 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3384 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 3385 | if (!status) |
| 3386 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3387 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3388 | |
| 3389 | |
| 3390 | nfs4_label_free(res.label); |
| 3391 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3392 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3393 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | return status; |
| 3395 | } |
| 3396 | |
| 3397 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3398 | { |
| 3399 | struct nfs4_exception exception = { }; |
| 3400 | int err; |
| 3401 | do { |
| 3402 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3403 | _nfs4_proc_link(inode, dir, name), |
| 3404 | &exception); |
| 3405 | } while (exception.retry); |
| 3406 | return err; |
| 3407 | } |
| 3408 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3409 | struct nfs4_createdata { |
| 3410 | struct rpc_message msg; |
| 3411 | struct nfs4_create_arg arg; |
| 3412 | struct nfs4_create_res res; |
| 3413 | struct nfs_fh fh; |
| 3414 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3415 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3416 | }; |
| 3417 | |
| 3418 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3419 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3420 | { |
| 3421 | struct nfs4_createdata *data; |
| 3422 | |
| 3423 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3424 | if (data != NULL) { |
| 3425 | struct nfs_server *server = NFS_SERVER(dir); |
| 3426 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3427 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3428 | if (IS_ERR(data->label)) |
| 3429 | goto out_free; |
| 3430 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3431 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3432 | data->msg.rpc_argp = &data->arg; |
| 3433 | data->msg.rpc_resp = &data->res; |
| 3434 | data->arg.dir_fh = NFS_FH(dir); |
| 3435 | data->arg.server = server; |
| 3436 | data->arg.name = name; |
| 3437 | data->arg.attrs = sattr; |
| 3438 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3439 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3440 | data->res.server = server; |
| 3441 | data->res.fh = &data->fh; |
| 3442 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3443 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3444 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3445 | } |
| 3446 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3447 | out_free: |
| 3448 | kfree(data); |
| 3449 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3450 | } |
| 3451 | |
| 3452 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3453 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3454 | 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] | 3455 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3456 | if (status == 0) { |
| 3457 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3458 | 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] | 3459 | } |
| 3460 | return status; |
| 3461 | } |
| 3462 | |
| 3463 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3464 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3465 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3466 | kfree(data); |
| 3467 | } |
| 3468 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3469 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3470 | struct page *page, unsigned int len, struct iattr *sattr, |
| 3471 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3473 | struct nfs4_createdata *data; |
| 3474 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3475 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3476 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3477 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3478 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3479 | status = -ENOMEM; |
| 3480 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3481 | if (data == NULL) |
| 3482 | goto out; |
| 3483 | |
| 3484 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3485 | data->arg.u.symlink.pages = &page; |
| 3486 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3487 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3488 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3489 | status = nfs4_do_create(dir, dentry, data); |
| 3490 | |
| 3491 | nfs4_free_createdata(data); |
| 3492 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3493 | return status; |
| 3494 | } |
| 3495 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3496 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3497 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3498 | { |
| 3499 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3500 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3501 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3502 | |
| 3503 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3505 | do { |
| 3506 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3507 | _nfs4_proc_symlink(dir, dentry, page, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3508 | len, sattr, label), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3509 | &exception); |
| 3510 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3511 | |
| 3512 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3513 | return err; |
| 3514 | } |
| 3515 | |
| 3516 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3517 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3519 | struct nfs4_createdata *data; |
| 3520 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3521 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3522 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3523 | if (data == NULL) |
| 3524 | goto out; |
| 3525 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3526 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3527 | status = nfs4_do_create(dir, dentry, data); |
| 3528 | |
| 3529 | nfs4_free_createdata(data); |
| 3530 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3531 | return status; |
| 3532 | } |
| 3533 | |
| 3534 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3535 | struct iattr *sattr) |
| 3536 | { |
| 3537 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3538 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3539 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3540 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3541 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3542 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3543 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3544 | do { |
| 3545 | err = nfs4_handle_exception(NFS_SERVER(dir), |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3546 | _nfs4_proc_mkdir(dir, dentry, sattr, label), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3547 | &exception); |
| 3548 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3549 | nfs4_label_release_security(label); |
| 3550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3551 | return err; |
| 3552 | } |
| 3553 | |
| 3554 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3555 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3556 | { |
| 3557 | struct inode *dir = dentry->d_inode; |
| 3558 | struct nfs4_readdir_arg args = { |
| 3559 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3560 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3561 | .pgbase = 0, |
| 3562 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3563 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3564 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3565 | }; |
| 3566 | struct nfs4_readdir_res res; |
| 3567 | struct rpc_message msg = { |
| 3568 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3569 | .rpc_argp = &args, |
| 3570 | .rpc_resp = &res, |
| 3571 | .rpc_cred = cred, |
| 3572 | }; |
| 3573 | int status; |
| 3574 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3575 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3576 | dentry->d_parent->d_name.name, |
| 3577 | dentry->d_name.name, |
| 3578 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3579 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3580 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3581 | 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] | 3582 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3583 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3584 | status += args.pgbase; |
| 3585 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3586 | |
| 3587 | nfs_invalidate_atime(dir); |
| 3588 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3589 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | return status; |
| 3591 | } |
| 3592 | |
| 3593 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3594 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | { |
| 3596 | struct nfs4_exception exception = { }; |
| 3597 | int err; |
| 3598 | do { |
| 3599 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3600 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3601 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3602 | &exception); |
| 3603 | } while (exception.retry); |
| 3604 | return err; |
| 3605 | } |
| 3606 | |
| 3607 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3608 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3609 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3610 | struct nfs4_createdata *data; |
| 3611 | int mode = sattr->ia_mode; |
| 3612 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3613 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3614 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3615 | if (data == NULL) |
| 3616 | goto out; |
| 3617 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3618 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3619 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3620 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3621 | data->arg.ftype = NF4BLK; |
| 3622 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3623 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3624 | } |
| 3625 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3626 | data->arg.ftype = NF4CHR; |
| 3627 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3628 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3629 | } else if (!S_ISSOCK(mode)) { |
| 3630 | status = -EINVAL; |
| 3631 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3633 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3634 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3635 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3636 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3637 | nfs4_free_createdata(data); |
| 3638 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3639 | return status; |
| 3640 | } |
| 3641 | |
| 3642 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3643 | struct iattr *sattr, dev_t rdev) |
| 3644 | { |
| 3645 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3646 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3648 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3649 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3650 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3651 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | do { |
| 3653 | err = nfs4_handle_exception(NFS_SERVER(dir), |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3654 | _nfs4_proc_mknod(dir, dentry, sattr, label, rdev), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3655 | &exception); |
| 3656 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3657 | |
| 3658 | nfs4_label_release_security(label); |
| 3659 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | return err; |
| 3661 | } |
| 3662 | |
| 3663 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3664 | struct nfs_fsstat *fsstat) |
| 3665 | { |
| 3666 | struct nfs4_statfs_arg args = { |
| 3667 | .fh = fhandle, |
| 3668 | .bitmask = server->attr_bitmask, |
| 3669 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3670 | struct nfs4_statfs_res res = { |
| 3671 | .fsstat = fsstat, |
| 3672 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3673 | struct rpc_message msg = { |
| 3674 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3675 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3676 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3677 | }; |
| 3678 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3679 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3680 | 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] | 3681 | } |
| 3682 | |
| 3683 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3684 | { |
| 3685 | struct nfs4_exception exception = { }; |
| 3686 | int err; |
| 3687 | do { |
| 3688 | err = nfs4_handle_exception(server, |
| 3689 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3690 | &exception); |
| 3691 | } while (exception.retry); |
| 3692 | return err; |
| 3693 | } |
| 3694 | |
| 3695 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3696 | struct nfs_fsinfo *fsinfo) |
| 3697 | { |
| 3698 | struct nfs4_fsinfo_arg args = { |
| 3699 | .fh = fhandle, |
| 3700 | .bitmask = server->attr_bitmask, |
| 3701 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3702 | struct nfs4_fsinfo_res res = { |
| 3703 | .fsinfo = fsinfo, |
| 3704 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3705 | struct rpc_message msg = { |
| 3706 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3707 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3708 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3709 | }; |
| 3710 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3711 | 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] | 3712 | } |
| 3713 | |
| 3714 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3715 | { |
| 3716 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3717 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3718 | int err; |
| 3719 | |
| 3720 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3721 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3722 | if (err == 0) { |
| 3723 | struct nfs_client *clp = server->nfs_client; |
| 3724 | |
| 3725 | spin_lock(&clp->cl_lock); |
| 3726 | clp->cl_lease_time = fsinfo->lease_time * HZ; |
| 3727 | clp->cl_last_renewal = now; |
| 3728 | spin_unlock(&clp->cl_lock); |
| 3729 | break; |
| 3730 | } |
| 3731 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3732 | } while (exception.retry); |
| 3733 | return err; |
| 3734 | } |
| 3735 | |
| 3736 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3737 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3738 | int error; |
| 3739 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3740 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3741 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3742 | if (error == 0) { |
| 3743 | /* block layout checks this! */ |
| 3744 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3745 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3746 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3747 | |
| 3748 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3749 | } |
| 3750 | |
| 3751 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3752 | struct nfs_pathconf *pathconf) |
| 3753 | { |
| 3754 | struct nfs4_pathconf_arg args = { |
| 3755 | .fh = fhandle, |
| 3756 | .bitmask = server->attr_bitmask, |
| 3757 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3758 | struct nfs4_pathconf_res res = { |
| 3759 | .pathconf = pathconf, |
| 3760 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3761 | struct rpc_message msg = { |
| 3762 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3763 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3764 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3765 | }; |
| 3766 | |
| 3767 | /* None of the pathconf attributes are mandatory to implement */ |
| 3768 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3769 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3770 | return 0; |
| 3771 | } |
| 3772 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3773 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3774 | 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] | 3775 | } |
| 3776 | |
| 3777 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3778 | struct nfs_pathconf *pathconf) |
| 3779 | { |
| 3780 | struct nfs4_exception exception = { }; |
| 3781 | int err; |
| 3782 | |
| 3783 | do { |
| 3784 | err = nfs4_handle_exception(server, |
| 3785 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3786 | &exception); |
| 3787 | } while (exception.retry); |
| 3788 | return err; |
| 3789 | } |
| 3790 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3791 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3792 | const struct nfs_open_context *ctx, |
| 3793 | const struct nfs_lock_context *l_ctx, |
| 3794 | fmode_t fmode) |
| 3795 | { |
| 3796 | const struct nfs_lockowner *lockowner = NULL; |
| 3797 | |
| 3798 | if (l_ctx != NULL) |
| 3799 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3800 | return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3801 | } |
| 3802 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 3803 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3804 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 3805 | const struct nfs_open_context *ctx, |
| 3806 | const struct nfs_lock_context *l_ctx, |
| 3807 | fmode_t fmode) |
| 3808 | { |
| 3809 | nfs4_stateid current_stateid; |
| 3810 | |
| 3811 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode)) |
| 3812 | return false; |
| 3813 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 3814 | } |
| 3815 | |
| 3816 | static bool nfs4_error_stateid_expired(int err) |
| 3817 | { |
| 3818 | switch (err) { |
| 3819 | case -NFS4ERR_DELEG_REVOKED: |
| 3820 | case -NFS4ERR_ADMIN_REVOKED: |
| 3821 | case -NFS4ERR_BAD_STATEID: |
| 3822 | case -NFS4ERR_STALE_STATEID: |
| 3823 | case -NFS4ERR_OLD_STATEID: |
| 3824 | case -NFS4ERR_OPENMODE: |
| 3825 | case -NFS4ERR_EXPIRED: |
| 3826 | return true; |
| 3827 | } |
| 3828 | return false; |
| 3829 | } |
| 3830 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3831 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3832 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3833 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3834 | } |
| 3835 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3836 | 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] | 3837 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3838 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3840 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3841 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3842 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3844 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3845 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3846 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3847 | renew_lease(server, data->timestamp); |
| 3848 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3849 | } |
| 3850 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3851 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
| 3852 | struct nfs_readargs *args) |
| 3853 | { |
| 3854 | |
| 3855 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3856 | nfs4_stateid_is_current(&args->stateid, |
| 3857 | args->context, |
| 3858 | args->lock_context, |
| 3859 | FMODE_READ)) |
| 3860 | return false; |
| 3861 | rpc_restart_call_prepare(task); |
| 3862 | return true; |
| 3863 | } |
| 3864 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3865 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3866 | { |
| 3867 | |
| 3868 | dprintk("--> %s\n", __func__); |
| 3869 | |
| 3870 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3871 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3872 | if (nfs4_read_stateid_changed(task, &data->args)) |
| 3873 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3874 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3875 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3876 | } |
| 3877 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3878 | 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] | 3879 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3880 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3881 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3882 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3883 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3884 | } |
| 3885 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3886 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3887 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3888 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3889 | &data->args.seq_args, |
| 3890 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3891 | task)) |
| 3892 | return; |
| 3893 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 3894 | data->args.lock_context, FMODE_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3895 | } |
| 3896 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3897 | 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] | 3898 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3899 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3900 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3901 | 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] | 3902 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3903 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3904 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3905 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3906 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3907 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3908 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3909 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3910 | } |
| 3911 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3912 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
| 3913 | struct nfs_writeargs *args) |
| 3914 | { |
| 3915 | |
| 3916 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3917 | nfs4_stateid_is_current(&args->stateid, |
| 3918 | args->context, |
| 3919 | args->lock_context, |
| 3920 | FMODE_WRITE)) |
| 3921 | return false; |
| 3922 | rpc_restart_call_prepare(task); |
| 3923 | return true; |
| 3924 | } |
| 3925 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3926 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3927 | { |
| 3928 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3929 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3930 | if (nfs4_write_stateid_changed(task, &data->args)) |
| 3931 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3932 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3933 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3934 | } |
| 3935 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3936 | static |
| 3937 | 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] | 3938 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3939 | const struct nfs_pgio_header *hdr = data->header; |
| 3940 | |
| 3941 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3942 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3943 | return false; |
| 3944 | /* Otherwise, request attributes if and only if we don't hold |
| 3945 | * a delegation |
| 3946 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3947 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3948 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3949 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3950 | 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] | 3951 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3952 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3953 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3954 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3955 | data->args.bitmask = NULL; |
| 3956 | data->res.fattr = NULL; |
| 3957 | } else |
| 3958 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3959 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3960 | if (!data->write_done_cb) |
| 3961 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3962 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3963 | data->timestamp = jiffies; |
| 3964 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3965 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3966 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3967 | } |
| 3968 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3969 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3970 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3971 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3972 | &data->args.seq_args, |
| 3973 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3974 | task)) |
| 3975 | return; |
| 3976 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 3977 | data->args.lock_context, FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3978 | } |
| 3979 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3980 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3981 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3982 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3983 | &data->args.seq_args, |
| 3984 | &data->res.seq_res, |
| 3985 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3986 | } |
| 3987 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3988 | 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] | 3989 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3990 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3991 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3992 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3993 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3994 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3995 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3996 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3997 | } |
| 3998 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3999 | 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] | 4000 | { |
| 4001 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4002 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4003 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4004 | } |
| 4005 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4006 | 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] | 4007 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4008 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4009 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4010 | if (data->commit_done_cb == NULL) |
| 4011 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4012 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4013 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4014 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4015 | } |
| 4016 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4017 | struct nfs4_renewdata { |
| 4018 | struct nfs_client *client; |
| 4019 | unsigned long timestamp; |
| 4020 | }; |
| 4021 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4022 | /* |
| 4023 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4024 | * standalone procedure for queueing an asynchronous RENEW. |
| 4025 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4026 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4027 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4028 | struct nfs4_renewdata *data = calldata; |
| 4029 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4030 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4031 | if (atomic_read(&clp->cl_count) > 1) |
| 4032 | nfs4_schedule_state_renewal(clp); |
| 4033 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4034 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4035 | } |
| 4036 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4037 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4038 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4039 | struct nfs4_renewdata *data = calldata; |
| 4040 | struct nfs_client *clp = data->client; |
| 4041 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4042 | |
| 4043 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4044 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4045 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4046 | return; |
| 4047 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4048 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4049 | return; |
| 4050 | } |
| 4051 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4052 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4053 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4054 | } |
| 4055 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4056 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4057 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4058 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4059 | }; |
| 4060 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4061 | 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] | 4062 | { |
| 4063 | struct rpc_message msg = { |
| 4064 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4065 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4066 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4067 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4068 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4070 | if (renew_flags == 0) |
| 4071 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4072 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4073 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4074 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4075 | if (data == NULL) |
| 4076 | return -ENOMEM; |
| 4077 | data->client = clp; |
| 4078 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4079 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4080 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4081 | } |
| 4082 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4083 | 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] | 4084 | { |
| 4085 | struct rpc_message msg = { |
| 4086 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4087 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4088 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4089 | }; |
| 4090 | unsigned long now = jiffies; |
| 4091 | int status; |
| 4092 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4093 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4094 | if (status < 0) |
| 4095 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4096 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4097 | return 0; |
| 4098 | } |
| 4099 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4100 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4101 | { |
| 4102 | return (server->caps & NFS_CAP_ACLS) |
| 4103 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 4104 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 4105 | } |
| 4106 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4107 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4108 | * 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] | 4109 | * the stack. |
| 4110 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4111 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4112 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4113 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 4114 | struct page **pages, unsigned int *pgbase) |
| 4115 | { |
| 4116 | struct page *newpage, **spages; |
| 4117 | int rc = 0; |
| 4118 | size_t len; |
| 4119 | spages = pages; |
| 4120 | |
| 4121 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4122 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4123 | newpage = alloc_page(GFP_KERNEL); |
| 4124 | |
| 4125 | if (newpage == NULL) |
| 4126 | goto unwind; |
| 4127 | memcpy(page_address(newpage), buf, len); |
| 4128 | buf += len; |
| 4129 | buflen -= len; |
| 4130 | *pages++ = newpage; |
| 4131 | rc++; |
| 4132 | } while (buflen != 0); |
| 4133 | |
| 4134 | return rc; |
| 4135 | |
| 4136 | unwind: |
| 4137 | for(; rc > 0; rc--) |
| 4138 | __free_page(spages[rc-1]); |
| 4139 | return -ENOMEM; |
| 4140 | } |
| 4141 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4142 | struct nfs4_cached_acl { |
| 4143 | int cached; |
| 4144 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4145 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4146 | }; |
| 4147 | |
| 4148 | 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] | 4149 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4150 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4151 | |
| 4152 | spin_lock(&inode->i_lock); |
| 4153 | kfree(nfsi->nfs4_acl); |
| 4154 | nfsi->nfs4_acl = acl; |
| 4155 | spin_unlock(&inode->i_lock); |
| 4156 | } |
| 4157 | |
| 4158 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4159 | { |
| 4160 | nfs4_set_cached_acl(inode, NULL); |
| 4161 | } |
| 4162 | |
| 4163 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4164 | { |
| 4165 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4166 | struct nfs4_cached_acl *acl; |
| 4167 | int ret = -ENOENT; |
| 4168 | |
| 4169 | spin_lock(&inode->i_lock); |
| 4170 | acl = nfsi->nfs4_acl; |
| 4171 | if (acl == NULL) |
| 4172 | goto out; |
| 4173 | if (buf == NULL) /* user is just asking for length */ |
| 4174 | goto out_len; |
| 4175 | if (acl->cached == 0) |
| 4176 | goto out; |
| 4177 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4178 | if (acl->len > buflen) |
| 4179 | goto out; |
| 4180 | memcpy(buf, acl->data, acl->len); |
| 4181 | out_len: |
| 4182 | ret = acl->len; |
| 4183 | out: |
| 4184 | spin_unlock(&inode->i_lock); |
| 4185 | return ret; |
| 4186 | } |
| 4187 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4188 | 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] | 4189 | { |
| 4190 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4191 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4192 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4193 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4194 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4195 | if (acl == NULL) |
| 4196 | goto out; |
| 4197 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4198 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4199 | } else { |
| 4200 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4201 | if (acl == NULL) |
| 4202 | goto out; |
| 4203 | acl->cached = 0; |
| 4204 | } |
| 4205 | acl->len = acl_len; |
| 4206 | out: |
| 4207 | nfs4_set_cached_acl(inode, acl); |
| 4208 | } |
| 4209 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4210 | /* |
| 4211 | * The getxattr API returns the required buffer length when called with a |
| 4212 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4213 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4214 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4215 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4216 | * the cache. If not so, we throw away the page, and cache the required |
| 4217 | * length. The next getxattr call will then produce another round trip to |
| 4218 | * the server, this time with the input buf of the required size. |
| 4219 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4220 | 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] | 4221 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4222 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4223 | struct nfs_getaclargs args = { |
| 4224 | .fh = NFS_FH(inode), |
| 4225 | .acl_pages = pages, |
| 4226 | .acl_len = buflen, |
| 4227 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4228 | struct nfs_getaclres res = { |
| 4229 | .acl_len = buflen, |
| 4230 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4231 | struct rpc_message msg = { |
| 4232 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4233 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4234 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4235 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4236 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4237 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4238 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4239 | /* As long as we're doing a round trip to the server anyway, |
| 4240 | * let's be prepared for a page of acl data. */ |
| 4241 | if (npages == 0) |
| 4242 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4243 | if (npages > ARRAY_SIZE(pages)) |
| 4244 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4245 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4246 | for (i = 0; i < npages; i++) { |
| 4247 | pages[i] = alloc_page(GFP_KERNEL); |
| 4248 | if (!pages[i]) |
| 4249 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4250 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4251 | |
| 4252 | /* for decoding across pages */ |
| 4253 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4254 | if (!res.acl_scratch) |
| 4255 | goto out_free; |
| 4256 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4257 | args.acl_len = npages * PAGE_SIZE; |
| 4258 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4259 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4260 | 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] | 4261 | __func__, buf, buflen, npages, args.acl_len); |
| 4262 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4263 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4264 | if (ret) |
| 4265 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4266 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4267 | /* Handle the case where the passed-in buffer is too short */ |
| 4268 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4269 | /* Did the user only issue a request for the acl length? */ |
| 4270 | if (buf == NULL) |
| 4271 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4272 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4273 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4274 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4275 | 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] | 4276 | if (buf) { |
| 4277 | if (res.acl_len > buflen) { |
| 4278 | ret = -ERANGE; |
| 4279 | goto out_free; |
| 4280 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4281 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4282 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4283 | out_ok: |
| 4284 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4285 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4286 | for (i = 0; i < npages; i++) |
| 4287 | if (pages[i]) |
| 4288 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4289 | if (res.acl_scratch) |
| 4290 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4291 | return ret; |
| 4292 | } |
| 4293 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4294 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4295 | { |
| 4296 | struct nfs4_exception exception = { }; |
| 4297 | ssize_t ret; |
| 4298 | do { |
| 4299 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 4300 | if (ret >= 0) |
| 4301 | break; |
| 4302 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4303 | } while (exception.retry); |
| 4304 | return ret; |
| 4305 | } |
| 4306 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4307 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4308 | { |
| 4309 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4310 | int ret; |
| 4311 | |
| 4312 | if (!nfs4_server_supports_acls(server)) |
| 4313 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4314 | ret = nfs_revalidate_inode(server, inode); |
| 4315 | if (ret < 0) |
| 4316 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4317 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4318 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4319 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4320 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4321 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4322 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4323 | return ret; |
| 4324 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4325 | } |
| 4326 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4327 | 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] | 4328 | { |
| 4329 | struct nfs_server *server = NFS_SERVER(inode); |
| 4330 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4331 | struct nfs_setaclargs arg = { |
| 4332 | .fh = NFS_FH(inode), |
| 4333 | .acl_pages = pages, |
| 4334 | .acl_len = buflen, |
| 4335 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4336 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4337 | struct rpc_message msg = { |
| 4338 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4339 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4340 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4341 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4342 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4343 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4344 | |
| 4345 | if (!nfs4_server_supports_acls(server)) |
| 4346 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4347 | if (npages > ARRAY_SIZE(pages)) |
| 4348 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4349 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4350 | if (i < 0) |
| 4351 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4352 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4353 | 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] | 4354 | |
| 4355 | /* |
| 4356 | * Free each page after tx, so the only ref left is |
| 4357 | * held by the network stack |
| 4358 | */ |
| 4359 | for (; i > 0; i--) |
| 4360 | put_page(pages[i-1]); |
| 4361 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4362 | /* |
| 4363 | * Acl update can result in inode attribute update. |
| 4364 | * so mark the attribute cache invalid. |
| 4365 | */ |
| 4366 | spin_lock(&inode->i_lock); |
| 4367 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4368 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4369 | nfs_access_zap_cache(inode); |
| 4370 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4371 | return ret; |
| 4372 | } |
| 4373 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4374 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4375 | { |
| 4376 | struct nfs4_exception exception = { }; |
| 4377 | int err; |
| 4378 | do { |
| 4379 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4380 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 4381 | &exception); |
| 4382 | } while (exception.retry); |
| 4383 | return err; |
| 4384 | } |
| 4385 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4386 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 4387 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 4388 | size_t buflen) |
| 4389 | { |
| 4390 | struct nfs_server *server = NFS_SERVER(inode); |
| 4391 | struct nfs_fattr fattr; |
| 4392 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 4393 | |
| 4394 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
| 4395 | struct nfs4_getattr_arg args = { |
| 4396 | .fh = NFS_FH(inode), |
| 4397 | .bitmask = bitmask, |
| 4398 | }; |
| 4399 | struct nfs4_getattr_res res = { |
| 4400 | .fattr = &fattr, |
| 4401 | .label = &label, |
| 4402 | .server = server, |
| 4403 | }; |
| 4404 | struct rpc_message msg = { |
| 4405 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 4406 | .rpc_argp = &args, |
| 4407 | .rpc_resp = &res, |
| 4408 | }; |
| 4409 | int ret; |
| 4410 | |
| 4411 | nfs_fattr_init(&fattr); |
| 4412 | |
| 4413 | ret = rpc_call_sync(server->client, &msg, 0); |
| 4414 | if (ret) |
| 4415 | return ret; |
| 4416 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 4417 | return -ENOENT; |
| 4418 | if (buflen < label.len) |
| 4419 | return -ERANGE; |
| 4420 | return 0; |
| 4421 | } |
| 4422 | |
| 4423 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 4424 | size_t buflen) |
| 4425 | { |
| 4426 | struct nfs4_exception exception = { }; |
| 4427 | int err; |
| 4428 | |
| 4429 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4430 | return -EOPNOTSUPP; |
| 4431 | |
| 4432 | do { |
| 4433 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4434 | _nfs4_get_security_label(inode, buf, buflen), |
| 4435 | &exception); |
| 4436 | } while (exception.retry); |
| 4437 | return err; |
| 4438 | } |
| 4439 | |
| 4440 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 4441 | struct nfs4_label *ilabel, |
| 4442 | struct nfs_fattr *fattr, |
| 4443 | struct nfs4_label *olabel) |
| 4444 | { |
| 4445 | |
| 4446 | struct iattr sattr = {0}; |
| 4447 | struct nfs_server *server = NFS_SERVER(inode); |
| 4448 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
| 4449 | struct nfs_setattrargs args = { |
| 4450 | .fh = NFS_FH(inode), |
| 4451 | .iap = &sattr, |
| 4452 | .server = server, |
| 4453 | .bitmask = bitmask, |
| 4454 | .label = ilabel, |
| 4455 | }; |
| 4456 | struct nfs_setattrres res = { |
| 4457 | .fattr = fattr, |
| 4458 | .label = olabel, |
| 4459 | .server = server, |
| 4460 | }; |
| 4461 | struct rpc_message msg = { |
| 4462 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 4463 | .rpc_argp = &args, |
| 4464 | .rpc_resp = &res, |
| 4465 | }; |
| 4466 | int status; |
| 4467 | |
| 4468 | nfs4_stateid_copy(&args.stateid, &zero_stateid); |
| 4469 | |
| 4470 | status = rpc_call_sync(server->client, &msg, 0); |
| 4471 | if (status) |
| 4472 | dprintk("%s failed: %d\n", __func__, status); |
| 4473 | |
| 4474 | return status; |
| 4475 | } |
| 4476 | |
| 4477 | static int nfs4_do_set_security_label(struct inode *inode, |
| 4478 | struct nfs4_label *ilabel, |
| 4479 | struct nfs_fattr *fattr, |
| 4480 | struct nfs4_label *olabel) |
| 4481 | { |
| 4482 | struct nfs4_exception exception = { }; |
| 4483 | int err; |
| 4484 | |
| 4485 | do { |
| 4486 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4487 | _nfs4_do_set_security_label(inode, ilabel, |
| 4488 | fattr, olabel), |
| 4489 | &exception); |
| 4490 | } while (exception.retry); |
| 4491 | return err; |
| 4492 | } |
| 4493 | |
| 4494 | static int |
| 4495 | nfs4_set_security_label(struct dentry *dentry, const void *buf, size_t buflen) |
| 4496 | { |
| 4497 | struct nfs4_label ilabel, *olabel = NULL; |
| 4498 | struct nfs_fattr fattr; |
| 4499 | struct rpc_cred *cred; |
| 4500 | struct inode *inode = dentry->d_inode; |
| 4501 | int status; |
| 4502 | |
| 4503 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4504 | return -EOPNOTSUPP; |
| 4505 | |
| 4506 | nfs_fattr_init(&fattr); |
| 4507 | |
| 4508 | ilabel.pi = 0; |
| 4509 | ilabel.lfs = 0; |
| 4510 | ilabel.label = (char *)buf; |
| 4511 | ilabel.len = buflen; |
| 4512 | |
| 4513 | cred = rpc_lookup_cred(); |
| 4514 | if (IS_ERR(cred)) |
| 4515 | return PTR_ERR(cred); |
| 4516 | |
| 4517 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 4518 | if (IS_ERR(olabel)) { |
| 4519 | status = -PTR_ERR(olabel); |
| 4520 | goto out; |
| 4521 | } |
| 4522 | |
| 4523 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 4524 | if (status == 0) |
| 4525 | nfs_setsecurity(inode, &fattr, olabel); |
| 4526 | |
| 4527 | nfs4_label_free(olabel); |
| 4528 | out: |
| 4529 | put_rpccred(cred); |
| 4530 | return status; |
| 4531 | } |
| 4532 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 4533 | |
| 4534 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4535 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4536 | 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] | 4537 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4538 | struct nfs_client *clp = server->nfs_client; |
| 4539 | |
| 4540 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4541 | return 0; |
| 4542 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4543 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4544 | case -NFS4ERR_ADMIN_REVOKED: |
| 4545 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 4546 | if (state == NULL) |
| 4547 | break; |
| 4548 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4549 | case -NFS4ERR_OPENMODE: |
| 4550 | if (state == NULL) |
| 4551 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4552 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4553 | goto stateid_invalid; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4554 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4555 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4556 | if (state != NULL) { |
| 4557 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4558 | goto stateid_invalid; |
| 4559 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4560 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4561 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4562 | nfs4_schedule_lease_recovery(clp); |
| 4563 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4564 | #if defined(CONFIG_NFS_V4_1) |
| 4565 | case -NFS4ERR_BADSESSION: |
| 4566 | case -NFS4ERR_BADSLOT: |
| 4567 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4568 | case -NFS4ERR_DEADSESSION: |
| 4569 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4570 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4571 | case -NFS4ERR_SEQ_MISORDERED: |
| 4572 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4573 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4574 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4575 | task->tk_status = 0; |
| 4576 | return -EAGAIN; |
| 4577 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4578 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4579 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4580 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4581 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 4582 | task->tk_status = 0; |
| 4583 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4584 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4585 | case -NFS4ERR_OLD_STATEID: |
| 4586 | task->tk_status = 0; |
| 4587 | return -EAGAIN; |
| 4588 | } |
| 4589 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4590 | return 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4591 | stateid_invalid: |
| 4592 | task->tk_status = -EIO; |
| 4593 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4594 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4595 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4596 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4597 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 4598 | task->tk_status = 0; |
| 4599 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4600 | } |
| 4601 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4602 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4603 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4604 | { |
| 4605 | __be32 verf[2]; |
| 4606 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4607 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4608 | /* An impossible timestamp guarantees this value |
| 4609 | * will never match a generated boot time. */ |
| 4610 | verf[0] = 0; |
| 4611 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 4612 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4613 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 4614 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 4615 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4616 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4617 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4618 | } |
| 4619 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4620 | static unsigned int |
| 4621 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4622 | char *buf, size_t len) |
| 4623 | { |
| 4624 | unsigned int result; |
| 4625 | |
| 4626 | rcu_read_lock(); |
| 4627 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4628 | clp->cl_ipaddr, |
| 4629 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4630 | RPC_DISPLAY_ADDR), |
| 4631 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4632 | RPC_DISPLAY_PROTO)); |
| 4633 | rcu_read_unlock(); |
| 4634 | return result; |
| 4635 | } |
| 4636 | |
| 4637 | static unsigned int |
| 4638 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4639 | char *buf, size_t len) |
| 4640 | { |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4641 | char *nodename = clp->cl_rpcclient->cl_nodename; |
| 4642 | |
| 4643 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 4644 | nodename = nfs4_client_id_uniquifier; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4645 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4646 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4647 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4648 | } |
| 4649 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4650 | /** |
| 4651 | * nfs4_proc_setclientid - Negotiate client ID |
| 4652 | * @clp: state data structure |
| 4653 | * @program: RPC program for NFSv4 callback service |
| 4654 | * @port: IP port number for NFS4 callback service |
| 4655 | * @cred: RPC credential to use for this call |
| 4656 | * @res: where to place the result |
| 4657 | * |
| 4658 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4659 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4660 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4661 | unsigned short port, struct rpc_cred *cred, |
| 4662 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4663 | { |
| 4664 | nfs4_verifier sc_verifier; |
| 4665 | struct nfs4_setclientid setclientid = { |
| 4666 | .sc_verifier = &sc_verifier, |
| 4667 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4668 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4669 | }; |
| 4670 | struct rpc_message msg = { |
| 4671 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4672 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4673 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4674 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4675 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4676 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4677 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4678 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4679 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4680 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4681 | setclientid.sc_name_len = |
| 4682 | nfs4_init_uniform_client_string(clp, |
| 4683 | setclientid.sc_name, |
| 4684 | sizeof(setclientid.sc_name)); |
| 4685 | else |
| 4686 | setclientid.sc_name_len = |
| 4687 | nfs4_init_nonuniform_client_string(clp, |
| 4688 | setclientid.sc_name, |
| 4689 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4690 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4691 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4692 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4693 | sizeof(setclientid.sc_netid), |
| 4694 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4695 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4696 | rcu_read_unlock(); |
| 4697 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4698 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4699 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4700 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4701 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4702 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4703 | setclientid.sc_name_len, setclientid.sc_name); |
| 4704 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 4705 | dprintk("NFS reply setclientid: %d\n", status); |
| 4706 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4707 | } |
| 4708 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4709 | /** |
| 4710 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4711 | * @clp: state data structure |
| 4712 | * @res: result of a previous SETCLIENTID |
| 4713 | * @cred: RPC credential to use for this call |
| 4714 | * |
| 4715 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4716 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4717 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4718 | struct nfs4_setclientid_res *arg, |
| 4719 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4720 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4721 | struct rpc_message msg = { |
| 4722 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4723 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4724 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4725 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4726 | int status; |
| 4727 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4728 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4729 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4730 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4731 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4732 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4733 | return status; |
| 4734 | } |
| 4735 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4736 | struct nfs4_delegreturndata { |
| 4737 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4738 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4739 | struct nfs_fh fh; |
| 4740 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4741 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4742 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4743 | int rpc_status; |
| 4744 | }; |
| 4745 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4746 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4747 | { |
| 4748 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4749 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4750 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4751 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4752 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4753 | switch (task->tk_status) { |
| 4754 | case -NFS4ERR_STALE_STATEID: |
| 4755 | case -NFS4ERR_EXPIRED: |
| 4756 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4757 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4758 | break; |
| 4759 | default: |
| 4760 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4761 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4762 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4763 | return; |
| 4764 | } |
| 4765 | } |
| 4766 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4767 | } |
| 4768 | |
| 4769 | static void nfs4_delegreturn_release(void *calldata) |
| 4770 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4771 | kfree(calldata); |
| 4772 | } |
| 4773 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4774 | #if defined(CONFIG_NFS_V4_1) |
| 4775 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4776 | { |
| 4777 | struct nfs4_delegreturndata *d_data; |
| 4778 | |
| 4779 | d_data = (struct nfs4_delegreturndata *)data; |
| 4780 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4781 | nfs4_setup_sequence(d_data->res.server, |
| 4782 | &d_data->args.seq_args, |
| 4783 | &d_data->res.seq_res, |
| 4784 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4785 | } |
| 4786 | #endif /* CONFIG_NFS_V4_1 */ |
| 4787 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4788 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4789 | #if defined(CONFIG_NFS_V4_1) |
| 4790 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4791 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4792 | .rpc_call_done = nfs4_delegreturn_done, |
| 4793 | .rpc_release = nfs4_delegreturn_release, |
| 4794 | }; |
| 4795 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4796 | 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] | 4797 | { |
| 4798 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4799 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4800 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4801 | struct rpc_message msg = { |
| 4802 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4803 | .rpc_cred = cred, |
| 4804 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4805 | struct rpc_task_setup task_setup_data = { |
| 4806 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4807 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4808 | .callback_ops = &nfs4_delegreturn_ops, |
| 4809 | .flags = RPC_TASK_ASYNC, |
| 4810 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4811 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4812 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4813 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4814 | if (data == NULL) |
| 4815 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4816 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4817 | data->args.fhandle = &data->fh; |
| 4818 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4819 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4820 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4821 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4822 | data->res.fattr = &data->fattr; |
| 4823 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4824 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4825 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4826 | data->rpc_status = 0; |
| 4827 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4828 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4829 | msg.rpc_argp = &data->args; |
| 4830 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4831 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4832 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4833 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4834 | if (!issync) |
| 4835 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4836 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4837 | if (status != 0) |
| 4838 | goto out; |
| 4839 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4840 | if (status == 0) |
| 4841 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4842 | else |
| 4843 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4844 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4845 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4846 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4847 | } |
| 4848 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4849 | 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] | 4850 | { |
| 4851 | struct nfs_server *server = NFS_SERVER(inode); |
| 4852 | struct nfs4_exception exception = { }; |
| 4853 | int err; |
| 4854 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4855 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4856 | switch (err) { |
| 4857 | case -NFS4ERR_STALE_STATEID: |
| 4858 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4859 | case 0: |
| 4860 | return 0; |
| 4861 | } |
| 4862 | err = nfs4_handle_exception(server, err, &exception); |
| 4863 | } while (exception.retry); |
| 4864 | return err; |
| 4865 | } |
| 4866 | |
| 4867 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4868 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4869 | |
| 4870 | /* |
| 4871 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4872 | */ |
| 4873 | static unsigned long |
| 4874 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4875 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4876 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4877 | timeout <<= 1; |
| 4878 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4879 | return NFS4_LOCK_MAXTIMEOUT; |
| 4880 | return timeout; |
| 4881 | } |
| 4882 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4883 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4884 | { |
| 4885 | struct inode *inode = state->inode; |
| 4886 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4887 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4888 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4889 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4890 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4891 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4892 | struct nfs_lockt_res res = { |
| 4893 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4894 | }; |
| 4895 | struct rpc_message msg = { |
| 4896 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4897 | .rpc_argp = &arg, |
| 4898 | .rpc_resp = &res, |
| 4899 | .rpc_cred = state->owner->so_cred, |
| 4900 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | struct nfs4_lock_state *lsp; |
| 4902 | int status; |
| 4903 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4904 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4905 | status = nfs4_set_lock_state(state, request); |
| 4906 | if (status != 0) |
| 4907 | goto out; |
| 4908 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4909 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4910 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4911 | 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] | 4912 | switch (status) { |
| 4913 | case 0: |
| 4914 | request->fl_type = F_UNLCK; |
| 4915 | break; |
| 4916 | case -NFS4ERR_DENIED: |
| 4917 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4918 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4919 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4920 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4921 | return status; |
| 4922 | } |
| 4923 | |
| 4924 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4925 | { |
| 4926 | struct nfs4_exception exception = { }; |
| 4927 | int err; |
| 4928 | |
| 4929 | do { |
| 4930 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4931 | _nfs4_proc_getlk(state, cmd, request), |
| 4932 | &exception); |
| 4933 | } while (exception.retry); |
| 4934 | return err; |
| 4935 | } |
| 4936 | |
| 4937 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4938 | { |
| 4939 | int res = 0; |
| 4940 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4941 | case FL_POSIX: |
| 4942 | res = posix_lock_file_wait(file, fl); |
| 4943 | break; |
| 4944 | case FL_FLOCK: |
| 4945 | res = flock_lock_file_wait(file, fl); |
| 4946 | break; |
| 4947 | default: |
| 4948 | BUG(); |
| 4949 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4950 | return res; |
| 4951 | } |
| 4952 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4953 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4954 | struct nfs_locku_args arg; |
| 4955 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4956 | struct nfs4_lock_state *lsp; |
| 4957 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4958 | struct file_lock fl; |
| 4959 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4960 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4961 | }; |
| 4962 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4963 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4964 | struct nfs_open_context *ctx, |
| 4965 | struct nfs4_lock_state *lsp, |
| 4966 | struct nfs_seqid *seqid) |
| 4967 | { |
| 4968 | struct nfs4_unlockdata *p; |
| 4969 | struct inode *inode = lsp->ls_state->inode; |
| 4970 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4971 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4972 | if (p == NULL) |
| 4973 | return NULL; |
| 4974 | p->arg.fh = NFS_FH(inode); |
| 4975 | p->arg.fl = &p->fl; |
| 4976 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4977 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4978 | p->arg.stateid = &lsp->ls_stateid; |
| 4979 | p->lsp = lsp; |
| 4980 | atomic_inc(&lsp->ls_count); |
| 4981 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4982 | p->ctx = get_nfs_open_context(ctx); |
| 4983 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4984 | p->server = NFS_SERVER(inode); |
| 4985 | return p; |
| 4986 | } |
| 4987 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4988 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4989 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4990 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4991 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4992 | nfs4_put_lock_state(calldata->lsp); |
| 4993 | put_nfs_open_context(calldata->ctx); |
| 4994 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4995 | } |
| 4996 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4997 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4998 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4999 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5000 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5001 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5002 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5003 | switch (task->tk_status) { |
| 5004 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5005 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 5006 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5007 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5008 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5009 | case -NFS4ERR_BAD_STATEID: |
| 5010 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5011 | case -NFS4ERR_STALE_STATEID: |
| 5012 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5013 | break; |
| 5014 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5015 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5016 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5017 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5018 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5019 | } |
| 5020 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5021 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5022 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5023 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5024 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5025 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5026 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5027 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5028 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5029 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5030 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5031 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5032 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5033 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5034 | &calldata->res.seq_res, |
| 5035 | task) != 0) |
| 5036 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5037 | return; |
| 5038 | out_no_action: |
| 5039 | task->tk_action = NULL; |
| 5040 | out_wait: |
| 5041 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5042 | } |
| 5043 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5044 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5045 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5046 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5047 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5048 | }; |
| 5049 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5050 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5051 | struct nfs_open_context *ctx, |
| 5052 | struct nfs4_lock_state *lsp, |
| 5053 | struct nfs_seqid *seqid) |
| 5054 | { |
| 5055 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5056 | struct rpc_message msg = { |
| 5057 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5058 | .rpc_cred = ctx->cred, |
| 5059 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5060 | struct rpc_task_setup task_setup_data = { |
| 5061 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5062 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5063 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5064 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5065 | .flags = RPC_TASK_ASYNC, |
| 5066 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5067 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5068 | /* Ensure this is an unlock - when canceling a lock, the |
| 5069 | * canceled lock is passed in, and it won't be an unlock. |
| 5070 | */ |
| 5071 | fl->fl_type = F_UNLCK; |
| 5072 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5073 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5074 | if (data == NULL) { |
| 5075 | nfs_free_seqid(seqid); |
| 5076 | return ERR_PTR(-ENOMEM); |
| 5077 | } |
| 5078 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5079 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5080 | msg.rpc_argp = &data->arg; |
| 5081 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5082 | task_setup_data.callback_data = data; |
| 5083 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5084 | } |
| 5085 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5086 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5087 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5088 | struct inode *inode = state->inode; |
| 5089 | struct nfs4_state_owner *sp = state->owner; |
| 5090 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5091 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5092 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5093 | struct rpc_task *task; |
| 5094 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5095 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5096 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5097 | status = nfs4_set_lock_state(state, request); |
| 5098 | /* Unlock _before_ we do the RPC call */ |
| 5099 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5100 | /* Exclude nfs_delegation_claim_locks() */ |
| 5101 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5102 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5103 | down_read(&nfsi->rwsem); |
| 5104 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 5105 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5106 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5107 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5108 | } |
| 5109 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5110 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5111 | if (status != 0) |
| 5112 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5113 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5114 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5115 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5116 | goto out; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5117 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5118 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5119 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5120 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5121 | 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] | 5122 | status = PTR_ERR(task); |
| 5123 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5124 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5125 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5126 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5127 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5128 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5129 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5130 | } |
| 5131 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5132 | struct nfs4_lockdata { |
| 5133 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5134 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5135 | struct nfs4_lock_state *lsp; |
| 5136 | struct nfs_open_context *ctx; |
| 5137 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5138 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5139 | int rpc_status; |
| 5140 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5141 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5142 | }; |
| 5143 | |
| 5144 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5145 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5146 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5147 | { |
| 5148 | struct nfs4_lockdata *p; |
| 5149 | struct inode *inode = lsp->ls_state->inode; |
| 5150 | struct nfs_server *server = NFS_SERVER(inode); |
| 5151 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5152 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5153 | if (p == NULL) |
| 5154 | return NULL; |
| 5155 | |
| 5156 | p->arg.fh = NFS_FH(inode); |
| 5157 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5158 | 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] | 5159 | if (p->arg.open_seqid == NULL) |
| 5160 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5161 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5162 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5163 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5164 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5165 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5166 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5167 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5168 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5169 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5170 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5171 | atomic_inc(&lsp->ls_count); |
| 5172 | p->ctx = get_nfs_open_context(ctx); |
| 5173 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5174 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5175 | out_free_seqid: |
| 5176 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5177 | out_free: |
| 5178 | kfree(p); |
| 5179 | return NULL; |
| 5180 | } |
| 5181 | |
| 5182 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 5183 | { |
| 5184 | struct nfs4_lockdata *data = calldata; |
| 5185 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5186 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5187 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5188 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5189 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5190 | /* Do we need to do an open_to_lock_owner? */ |
| 5191 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5192 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5193 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5194 | } |
Trond Myklebust | 8e472f3 | 2013-04-20 01:30:53 -0400 | [diff] [blame] | 5195 | data->arg.open_stateid = &state->open_stateid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5196 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5197 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5198 | } else |
| 5199 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5200 | if (!nfs4_valid_open_stateid(state)) { |
| 5201 | data->rpc_status = -EBADF; |
| 5202 | task->tk_action = NULL; |
| 5203 | goto out_release_open_seqid; |
| 5204 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5205 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5206 | if (nfs4_setup_sequence(data->server, |
| 5207 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5208 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5209 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5210 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5211 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5212 | nfs_release_seqid(data->arg.open_seqid); |
| 5213 | out_release_lock_seqid: |
| 5214 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5215 | out_wait: |
| 5216 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5217 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5218 | } |
| 5219 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5220 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 5221 | { |
| 5222 | struct nfs4_lockdata *data = calldata; |
| 5223 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5224 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5225 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5226 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5227 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5228 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5229 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5230 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5231 | if (data->rpc_status == 0) |
| 5232 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 5233 | else |
| 5234 | goto out; |
| 5235 | } |
| 5236 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5237 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5238 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 5239 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5240 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5241 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5242 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5243 | } |
| 5244 | |
| 5245 | static void nfs4_lock_release(void *calldata) |
| 5246 | { |
| 5247 | struct nfs4_lockdata *data = calldata; |
| 5248 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5249 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5250 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5251 | if (data->cancelled != 0) { |
| 5252 | struct rpc_task *task; |
| 5253 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 5254 | data->arg.lock_seqid); |
| 5255 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5256 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5257 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5258 | } else |
| 5259 | nfs_free_seqid(data->arg.lock_seqid); |
| 5260 | nfs4_put_lock_state(data->lsp); |
| 5261 | put_nfs_open_context(data->ctx); |
| 5262 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5263 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5264 | } |
| 5265 | |
| 5266 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 5267 | .rpc_call_prepare = nfs4_lock_prepare, |
| 5268 | .rpc_call_done = nfs4_lock_done, |
| 5269 | .rpc_release = nfs4_lock_release, |
| 5270 | }; |
| 5271 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5272 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 5273 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5274 | switch (error) { |
| 5275 | case -NFS4ERR_ADMIN_REVOKED: |
| 5276 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5277 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5278 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5279 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5280 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5281 | break; |
| 5282 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5283 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5284 | case -NFS4ERR_EXPIRED: |
| 5285 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5286 | }; |
| 5287 | } |
| 5288 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5289 | 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] | 5290 | { |
| 5291 | struct nfs4_lockdata *data; |
| 5292 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5293 | struct rpc_message msg = { |
| 5294 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 5295 | .rpc_cred = state->owner->so_cred, |
| 5296 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5297 | struct rpc_task_setup task_setup_data = { |
| 5298 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5299 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5300 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5301 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5302 | .flags = RPC_TASK_ASYNC, |
| 5303 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5304 | int ret; |
| 5305 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5306 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5307 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5308 | fl->fl_u.nfs4_fl.owner, |
| 5309 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5310 | if (data == NULL) |
| 5311 | return -ENOMEM; |
| 5312 | if (IS_SETLKW(cmd)) |
| 5313 | data->arg.block = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5314 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5315 | msg.rpc_argp = &data->arg; |
| 5316 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5317 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5318 | if (recovery_type > NFS_LOCK_NEW) { |
| 5319 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 5320 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 5321 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
| 5322 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5323 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5324 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5325 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5326 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 5327 | if (ret == 0) { |
| 5328 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5329 | if (ret) |
| 5330 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 5331 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5332 | } else |
| 5333 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5334 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5335 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5336 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5337 | } |
| 5338 | |
| 5339 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 5340 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5341 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5342 | struct nfs4_exception exception = { |
| 5343 | .inode = state->inode, |
| 5344 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5345 | int err; |
| 5346 | |
| 5347 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5348 | /* Cache the lock if possible... */ |
| 5349 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5350 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5351 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5352 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5353 | break; |
| 5354 | nfs4_handle_exception(server, err, &exception); |
| 5355 | } while (exception.retry); |
| 5356 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5357 | } |
| 5358 | |
| 5359 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5360 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5361 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5362 | struct nfs4_exception exception = { |
| 5363 | .inode = state->inode, |
| 5364 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5365 | int err; |
| 5366 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5367 | err = nfs4_set_lock_state(state, request); |
| 5368 | if (err != 0) |
| 5369 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5370 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5371 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5372 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5373 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5374 | switch (err) { |
| 5375 | default: |
| 5376 | goto out; |
| 5377 | case -NFS4ERR_GRACE: |
| 5378 | case -NFS4ERR_DELAY: |
| 5379 | nfs4_handle_exception(server, err, &exception); |
| 5380 | err = 0; |
| 5381 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5382 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5383 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5384 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5385 | } |
| 5386 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5387 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5388 | /** |
| 5389 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 5390 | * |
| 5391 | * @state: NFSv4 state for an inode |
| 5392 | * |
| 5393 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 5394 | * Otherwise a negative NFS4ERR value is returned. |
| 5395 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5396 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5397 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5398 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5399 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5400 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5401 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5402 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5403 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5404 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 5405 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5406 | /* Free the stateid unless the server |
| 5407 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 5408 | if (status != -NFS4ERR_BAD_STATEID) |
| 5409 | nfs41_free_stateid(server, |
| 5410 | &lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5411 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5412 | ret = status; |
| 5413 | } |
| 5414 | } |
| 5415 | }; |
| 5416 | |
| 5417 | return ret; |
| 5418 | } |
| 5419 | |
| 5420 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5421 | { |
| 5422 | int status = NFS_OK; |
| 5423 | |
| 5424 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 5425 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5426 | if (status != NFS_OK) |
| 5427 | status = nfs4_lock_expired(state, request); |
| 5428 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5429 | } |
| 5430 | #endif |
| 5431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5432 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5433 | { |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5434 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5435 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5436 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5437 | unsigned int seq; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5438 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5439 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5440 | if ((fl_flags & FL_POSIX) && |
| 5441 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 5442 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5443 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5444 | status = nfs4_set_lock_state(state, request); |
| 5445 | if (status != 0) |
| 5446 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5447 | request->fl_flags |= FL_ACCESS; |
| 5448 | status = do_vfs_lock(request->fl_file, request); |
| 5449 | if (status < 0) |
| 5450 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5451 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5452 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5453 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5454 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5455 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 5456 | status = do_vfs_lock(request->fl_file, request); |
| 5457 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5458 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5459 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 5460 | up_read(&nfsi->rwsem); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5461 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5462 | if (status != 0) |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5463 | goto out; |
| 5464 | down_read(&nfsi->rwsem); |
| 5465 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { |
| 5466 | status = -NFS4ERR_DELAY; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5467 | goto out_unlock; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5468 | } |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5469 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5470 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5471 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5472 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 5473 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5474 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5475 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5476 | out: |
| 5477 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5478 | return status; |
| 5479 | } |
| 5480 | |
| 5481 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5482 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5483 | struct nfs4_exception exception = { |
| 5484 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5485 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5486 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5487 | int err; |
| 5488 | |
| 5489 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5490 | err = _nfs4_proc_setlk(state, cmd, request); |
| 5491 | if (err == -NFS4ERR_DENIED) |
| 5492 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5493 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5494 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5495 | } while (exception.retry); |
| 5496 | return err; |
| 5497 | } |
| 5498 | |
| 5499 | static int |
| 5500 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 5501 | { |
| 5502 | struct nfs_open_context *ctx; |
| 5503 | struct nfs4_state *state; |
| 5504 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 5505 | int status; |
| 5506 | |
| 5507 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5508 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5509 | state = ctx->state; |
| 5510 | |
| 5511 | if (request->fl_start < 0 || request->fl_end < 0) |
| 5512 | return -EINVAL; |
| 5513 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5514 | if (IS_GETLK(cmd)) { |
| 5515 | if (state != NULL) |
| 5516 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 5517 | return 0; |
| 5518 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5519 | |
| 5520 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 5521 | return -EINVAL; |
| 5522 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5523 | if (request->fl_type == F_UNLCK) { |
| 5524 | if (state != NULL) |
| 5525 | return nfs4_proc_unlck(state, cmd, request); |
| 5526 | return 0; |
| 5527 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5528 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5529 | if (state == NULL) |
| 5530 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5531 | /* |
| 5532 | * Don't rely on the VFS having checked the file open mode, |
| 5533 | * since it won't do this for flock() locks. |
| 5534 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5535 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5536 | case F_RDLCK: |
| 5537 | if (!(filp->f_mode & FMODE_READ)) |
| 5538 | return -EBADF; |
| 5539 | break; |
| 5540 | case F_WRLCK: |
| 5541 | if (!(filp->f_mode & FMODE_WRITE)) |
| 5542 | return -EBADF; |
| 5543 | } |
| 5544 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5545 | do { |
| 5546 | status = nfs4_proc_setlk(state, cmd, request); |
| 5547 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 5548 | break; |
| 5549 | timeout = nfs4_set_lock_task_retry(timeout); |
| 5550 | status = -ERESTARTSYS; |
| 5551 | if (signalled()) |
| 5552 | break; |
| 5553 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5554 | return status; |
| 5555 | } |
| 5556 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5557 | 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] | 5558 | { |
| 5559 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5560 | int err; |
| 5561 | |
| 5562 | err = nfs4_set_lock_state(state, fl); |
| 5563 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5564 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 5565 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5566 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5567 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5568 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5569 | struct nfs_release_lockowner_data { |
| 5570 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5571 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5572 | struct nfs_release_lockowner_args args; |
| 5573 | }; |
| 5574 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5575 | static void nfs4_release_lockowner_release(void *calldata) |
| 5576 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5577 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5578 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5579 | kfree(calldata); |
| 5580 | } |
| 5581 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5582 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5583 | .rpc_release = nfs4_release_lockowner_release, |
| 5584 | }; |
| 5585 | |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 5586 | 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] | 5587 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5588 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5589 | struct rpc_message msg = { |
| 5590 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5591 | }; |
| 5592 | |
| 5593 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5594 | return -EINVAL; |
| 5595 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5596 | if (!data) |
| 5597 | return -ENOMEM; |
| 5598 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5599 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5600 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5601 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5602 | data->args.lock_owner.s_dev = server->s_dev; |
| 5603 | msg.rpc_argp = &data->args; |
| 5604 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5605 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5606 | } |
| 5607 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5608 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5609 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5610 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5611 | const void *buf, size_t buflen, |
| 5612 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5613 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5614 | if (strcmp(key, "") != 0) |
| 5615 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5616 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5617 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5618 | } |
| 5619 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5620 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5621 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5622 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5623 | if (strcmp(key, "") != 0) |
| 5624 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5625 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5626 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5627 | } |
| 5628 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5629 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5630 | size_t list_len, const char *name, |
| 5631 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5632 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5633 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5634 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5635 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5636 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5637 | |
| 5638 | if (list && len <= list_len) |
| 5639 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5640 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5641 | } |
| 5642 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame^] | 5643 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5644 | static inline int nfs4_server_supports_labels(struct nfs_server *server) |
| 5645 | { |
| 5646 | return server->caps & NFS_CAP_SECURITY_LABEL; |
| 5647 | } |
| 5648 | |
| 5649 | static int nfs4_xattr_set_nfs4_label(struct dentry *dentry, const char *key, |
| 5650 | const void *buf, size_t buflen, |
| 5651 | int flags, int type) |
| 5652 | { |
| 5653 | if (security_ismaclabel(key)) |
| 5654 | return nfs4_set_security_label(dentry, buf, buflen); |
| 5655 | |
| 5656 | return -EOPNOTSUPP; |
| 5657 | } |
| 5658 | |
| 5659 | static int nfs4_xattr_get_nfs4_label(struct dentry *dentry, const char *key, |
| 5660 | void *buf, size_t buflen, int type) |
| 5661 | { |
| 5662 | if (security_ismaclabel(key)) |
| 5663 | return nfs4_get_security_label(dentry->d_inode, buf, buflen); |
| 5664 | return -EOPNOTSUPP; |
| 5665 | } |
| 5666 | |
| 5667 | static size_t nfs4_xattr_list_nfs4_label(struct dentry *dentry, char *list, |
| 5668 | size_t list_len, const char *name, |
| 5669 | size_t name_len, int type) |
| 5670 | { |
| 5671 | size_t len = 0; |
| 5672 | |
| 5673 | if (nfs_server_capable(dentry->d_inode, NFS_CAP_SECURITY_LABEL)) { |
| 5674 | len = security_inode_listsecurity(dentry->d_inode, NULL, 0); |
| 5675 | if (list && len <= list_len) |
| 5676 | security_inode_listsecurity(dentry->d_inode, list, len); |
| 5677 | } |
| 5678 | return len; |
| 5679 | } |
| 5680 | |
| 5681 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 5682 | .prefix = XATTR_SECURITY_PREFIX, |
| 5683 | .list = nfs4_xattr_list_nfs4_label, |
| 5684 | .get = nfs4_xattr_get_nfs4_label, |
| 5685 | .set = nfs4_xattr_set_nfs4_label, |
| 5686 | }; |
| 5687 | #endif |
| 5688 | |
| 5689 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5690 | /* |
| 5691 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5692 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5693 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5694 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5695 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5696 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5697 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5698 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5699 | return; |
| 5700 | |
| 5701 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5702 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5703 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5704 | fattr->nlink = 2; |
| 5705 | } |
| 5706 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5707 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5708 | const struct qstr *name, |
| 5709 | struct nfs4_fs_locations *fs_locations, |
| 5710 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5711 | { |
| 5712 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 5713 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5714 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5715 | }; |
| 5716 | struct nfs4_fs_locations_arg args = { |
| 5717 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5718 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5719 | .page = page, |
| 5720 | .bitmask = bitmask, |
| 5721 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5722 | struct nfs4_fs_locations_res res = { |
| 5723 | .fs_locations = fs_locations, |
| 5724 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5725 | struct rpc_message msg = { |
| 5726 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5727 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5728 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5729 | }; |
| 5730 | int status; |
| 5731 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5732 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5733 | |
| 5734 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5735 | * is not supported */ |
| 5736 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5737 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5738 | else |
| 5739 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5740 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5741 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5742 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5743 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5744 | 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] | 5745 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5746 | return status; |
| 5747 | } |
| 5748 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5749 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5750 | const struct qstr *name, |
| 5751 | struct nfs4_fs_locations *fs_locations, |
| 5752 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5753 | { |
| 5754 | struct nfs4_exception exception = { }; |
| 5755 | int err; |
| 5756 | do { |
| 5757 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5758 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5759 | &exception); |
| 5760 | } while (exception.retry); |
| 5761 | return err; |
| 5762 | } |
| 5763 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5764 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5765 | { |
| 5766 | int status; |
| 5767 | struct nfs4_secinfo_arg args = { |
| 5768 | .dir_fh = NFS_FH(dir), |
| 5769 | .name = name, |
| 5770 | }; |
| 5771 | struct nfs4_secinfo_res res = { |
| 5772 | .flavors = flavors, |
| 5773 | }; |
| 5774 | struct rpc_message msg = { |
| 5775 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5776 | .rpc_argp = &args, |
| 5777 | .rpc_resp = &res, |
| 5778 | }; |
| 5779 | |
| 5780 | dprintk("NFS call secinfo %s\n", name->name); |
| 5781 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5782 | dprintk("NFS reply secinfo: %d\n", status); |
| 5783 | return status; |
| 5784 | } |
| 5785 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5786 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5787 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5788 | { |
| 5789 | struct nfs4_exception exception = { }; |
| 5790 | int err; |
| 5791 | do { |
| 5792 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5793 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5794 | &exception); |
| 5795 | } while (exception.retry); |
| 5796 | return err; |
| 5797 | } |
| 5798 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5799 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5800 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5801 | * Check the exchange flags returned by the server for invalid flags, having |
| 5802 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5803 | * DS flags set. |
| 5804 | */ |
| 5805 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5806 | { |
| 5807 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5808 | goto out_inval; |
| 5809 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5810 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5811 | goto out_inval; |
| 5812 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5813 | goto out_inval; |
| 5814 | return NFS_OK; |
| 5815 | out_inval: |
| 5816 | return -NFS4ERR_INVAL; |
| 5817 | } |
| 5818 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5819 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5820 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5821 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5822 | { |
| 5823 | if (a->server_scope_sz == b->server_scope_sz && |
| 5824 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5825 | return true; |
| 5826 | |
| 5827 | return false; |
| 5828 | } |
| 5829 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5830 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5831 | * nfs4_proc_bind_conn_to_session() |
| 5832 | * |
| 5833 | * The 4.1 client currently uses the same TCP connection for the |
| 5834 | * fore and backchannel. |
| 5835 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5836 | 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] | 5837 | { |
| 5838 | int status; |
| 5839 | struct nfs41_bind_conn_to_session_res res; |
| 5840 | struct rpc_message msg = { |
| 5841 | .rpc_proc = |
| 5842 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5843 | .rpc_argp = clp, |
| 5844 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5845 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5846 | }; |
| 5847 | |
| 5848 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5849 | |
| 5850 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5851 | if (unlikely(res.session == NULL)) { |
| 5852 | status = -ENOMEM; |
| 5853 | goto out; |
| 5854 | } |
| 5855 | |
| 5856 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5857 | if (status == 0) { |
| 5858 | if (memcmp(res.session->sess_id.data, |
| 5859 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5860 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5861 | status = -EIO; |
| 5862 | goto out_session; |
| 5863 | } |
| 5864 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5865 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5866 | __func__); |
| 5867 | status = -EIO; |
| 5868 | goto out_session; |
| 5869 | } |
| 5870 | if (res.use_conn_in_rdma_mode) { |
| 5871 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5872 | __func__); |
| 5873 | status = -EIO; |
| 5874 | goto out_session; |
| 5875 | } |
| 5876 | } |
| 5877 | out_session: |
| 5878 | kfree(res.session); |
| 5879 | out: |
| 5880 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5881 | return status; |
| 5882 | } |
| 5883 | |
| 5884 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5885 | * nfs4_proc_exchange_id() |
| 5886 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5887 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5888 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5889 | * Since the clientid has expired, all compounds using sessions |
| 5890 | * associated with the stale clientid will be returning |
| 5891 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5892 | * be in some phase of session reset. |
| 5893 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5894 | 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] | 5895 | { |
| 5896 | nfs4_verifier verifier; |
| 5897 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5898 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5899 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5900 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5901 | }; |
| 5902 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5903 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5904 | }; |
| 5905 | int status; |
| 5906 | struct rpc_message msg = { |
| 5907 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5908 | .rpc_argp = &args, |
| 5909 | .rpc_resp = &res, |
| 5910 | .rpc_cred = cred, |
| 5911 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5912 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5913 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5914 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 5915 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5916 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5917 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5918 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5919 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5920 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5921 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5922 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5923 | status = -ENOMEM; |
| 5924 | goto out; |
| 5925 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5926 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5927 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5928 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5929 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5930 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5931 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5932 | } |
| 5933 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5934 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5935 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5936 | status = -ENOMEM; |
| 5937 | goto out_server_scope; |
| 5938 | } |
| 5939 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5940 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5941 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5942 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5943 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5944 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5945 | clp->cl_clientid = res.clientid; |
| 5946 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5947 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5948 | clp->cl_seqid = res.seqid; |
| 5949 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5950 | kfree(clp->cl_serverowner); |
| 5951 | clp->cl_serverowner = res.server_owner; |
| 5952 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5953 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5954 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5955 | kfree(clp->cl_implid); |
| 5956 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5957 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5958 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5959 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5960 | res.server_scope)) { |
| 5961 | dprintk("%s: server_scope mismatch detected\n", |
| 5962 | __func__); |
| 5963 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5964 | kfree(clp->cl_serverscope); |
| 5965 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5966 | } |
| 5967 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5968 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5969 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5970 | goto out; |
| 5971 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5972 | } else |
| 5973 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5974 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5975 | out_server_owner: |
| 5976 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5977 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5978 | kfree(res.server_scope); |
| 5979 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5980 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5981 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5982 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5983 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5984 | clp->cl_implid->date.seconds, |
| 5985 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5986 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5987 | return status; |
| 5988 | } |
| 5989 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5990 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5991 | struct rpc_cred *cred) |
| 5992 | { |
| 5993 | struct rpc_message msg = { |
| 5994 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 5995 | .rpc_argp = clp, |
| 5996 | .rpc_cred = cred, |
| 5997 | }; |
| 5998 | int status; |
| 5999 | |
| 6000 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 6001 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 6002 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6003 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 6004 | return status; |
| 6005 | } |
| 6006 | |
| 6007 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 6008 | struct rpc_cred *cred) |
| 6009 | { |
| 6010 | unsigned int loop; |
| 6011 | int ret; |
| 6012 | |
| 6013 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 6014 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 6015 | switch (ret) { |
| 6016 | case -NFS4ERR_DELAY: |
| 6017 | case -NFS4ERR_CLIENTID_BUSY: |
| 6018 | ssleep(1); |
| 6019 | break; |
| 6020 | default: |
| 6021 | return ret; |
| 6022 | } |
| 6023 | } |
| 6024 | return 0; |
| 6025 | } |
| 6026 | |
| 6027 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 6028 | { |
| 6029 | struct rpc_cred *cred; |
| 6030 | int ret = 0; |
| 6031 | |
| 6032 | if (clp->cl_mvops->minor_version < 1) |
| 6033 | goto out; |
| 6034 | if (clp->cl_exchange_flags == 0) |
| 6035 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6036 | if (clp->cl_preserve_clid) |
| 6037 | goto out; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6038 | cred = nfs4_get_exchange_id_cred(clp); |
| 6039 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 6040 | if (cred) |
| 6041 | put_rpccred(cred); |
| 6042 | switch (ret) { |
| 6043 | case 0: |
| 6044 | case -NFS4ERR_STALE_CLIENTID: |
| 6045 | clp->cl_exchange_flags = 0; |
| 6046 | } |
| 6047 | out: |
| 6048 | return ret; |
| 6049 | } |
| 6050 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6051 | struct nfs4_get_lease_time_data { |
| 6052 | struct nfs4_get_lease_time_args *args; |
| 6053 | struct nfs4_get_lease_time_res *res; |
| 6054 | struct nfs_client *clp; |
| 6055 | }; |
| 6056 | |
| 6057 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 6058 | void *calldata) |
| 6059 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6060 | struct nfs4_get_lease_time_data *data = |
| 6061 | (struct nfs4_get_lease_time_data *)calldata; |
| 6062 | |
| 6063 | dprintk("--> %s\n", __func__); |
| 6064 | /* just setup sequence, do not trigger session recovery |
| 6065 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6066 | nfs41_setup_sequence(data->clp->cl_session, |
| 6067 | &data->args->la_seq_args, |
| 6068 | &data->res->lr_seq_res, |
| 6069 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6070 | dprintk("<-- %s\n", __func__); |
| 6071 | } |
| 6072 | |
| 6073 | /* |
| 6074 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 6075 | * from sequence operation or clientid errors. |
| 6076 | */ |
| 6077 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 6078 | { |
| 6079 | struct nfs4_get_lease_time_data *data = |
| 6080 | (struct nfs4_get_lease_time_data *)calldata; |
| 6081 | |
| 6082 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6083 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 6084 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6085 | switch (task->tk_status) { |
| 6086 | case -NFS4ERR_DELAY: |
| 6087 | case -NFS4ERR_GRACE: |
| 6088 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 6089 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 6090 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6091 | /* fall through */ |
| 6092 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6093 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6094 | return; |
| 6095 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6096 | dprintk("<-- %s\n", __func__); |
| 6097 | } |
| 6098 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6099 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6100 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 6101 | .rpc_call_done = nfs4_get_lease_time_done, |
| 6102 | }; |
| 6103 | |
| 6104 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 6105 | { |
| 6106 | struct rpc_task *task; |
| 6107 | struct nfs4_get_lease_time_args args; |
| 6108 | struct nfs4_get_lease_time_res res = { |
| 6109 | .lr_fsinfo = fsinfo, |
| 6110 | }; |
| 6111 | struct nfs4_get_lease_time_data data = { |
| 6112 | .args = &args, |
| 6113 | .res = &res, |
| 6114 | .clp = clp, |
| 6115 | }; |
| 6116 | struct rpc_message msg = { |
| 6117 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 6118 | .rpc_argp = &args, |
| 6119 | .rpc_resp = &res, |
| 6120 | }; |
| 6121 | struct rpc_task_setup task_setup = { |
| 6122 | .rpc_client = clp->cl_rpcclient, |
| 6123 | .rpc_message = &msg, |
| 6124 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6125 | .callback_data = &data, |
| 6126 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6127 | }; |
| 6128 | int status; |
| 6129 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6130 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6131 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6132 | dprintk("--> %s\n", __func__); |
| 6133 | task = rpc_run_task(&task_setup); |
| 6134 | |
| 6135 | if (IS_ERR(task)) |
| 6136 | status = PTR_ERR(task); |
| 6137 | else { |
| 6138 | status = task->tk_status; |
| 6139 | rpc_put_task(task); |
| 6140 | } |
| 6141 | dprintk("<-- %s return %d\n", __func__, status); |
| 6142 | |
| 6143 | return status; |
| 6144 | } |
| 6145 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6146 | /* |
| 6147 | * Initialize the values to be used by the client in CREATE_SESSION |
| 6148 | * If nfs4_init_session set the fore channel request and response sizes, |
| 6149 | * use them. |
| 6150 | * |
| 6151 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 6152 | * always set csa_cachethis to FALSE because the current implementation |
| 6153 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 6154 | */ |
| 6155 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 6156 | { |
| 6157 | struct nfs4_session *session = args->client->cl_session; |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 6158 | unsigned int mxrqst_sz = session->fc_target_max_rqst_sz, |
| 6159 | mxresp_sz = session->fc_target_max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6160 | |
| 6161 | if (mxrqst_sz == 0) |
| 6162 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 6163 | if (mxresp_sz == 0) |
| 6164 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 6165 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6166 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 6167 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6168 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 6169 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6170 | |
| 6171 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 6172 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6173 | __func__, |
| 6174 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 6175 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6176 | |
| 6177 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6178 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 6179 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 6180 | args->bc_attrs.max_resp_sz_cached = 0; |
| 6181 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 6182 | args->bc_attrs.max_reqs = 1; |
| 6183 | |
| 6184 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 6185 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 6186 | __func__, |
| 6187 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 6188 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 6189 | args->bc_attrs.max_reqs); |
| 6190 | } |
| 6191 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6192 | 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] | 6193 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6194 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 6195 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 6196 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6197 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 6198 | return -EINVAL; |
| 6199 | /* |
| 6200 | * Our requested max_ops is the minimum we need; we're not |
| 6201 | * prepared to break up compounds into smaller pieces than that. |
| 6202 | * So, no point even trying to continue if the server won't |
| 6203 | * cooperate: |
| 6204 | */ |
| 6205 | if (rcvd->max_ops < sent->max_ops) |
| 6206 | return -EINVAL; |
| 6207 | if (rcvd->max_reqs == 0) |
| 6208 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6209 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 6210 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6211 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6212 | } |
| 6213 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6214 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 6215 | { |
| 6216 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 6217 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6218 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6219 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 6220 | return -EINVAL; |
| 6221 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 6222 | return -EINVAL; |
| 6223 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 6224 | return -EINVAL; |
| 6225 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6226 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6227 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6228 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6229 | return -EINVAL; |
| 6230 | return 0; |
| 6231 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6232 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6233 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 6234 | struct nfs4_session *session) |
| 6235 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6236 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6237 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6238 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 6239 | if (ret) |
| 6240 | return ret; |
| 6241 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6242 | } |
| 6243 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6244 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 6245 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6246 | { |
| 6247 | struct nfs4_session *session = clp->cl_session; |
| 6248 | struct nfs41_create_session_args args = { |
| 6249 | .client = clp, |
| 6250 | .cb_program = NFS4_CALLBACK, |
| 6251 | }; |
| 6252 | struct nfs41_create_session_res res = { |
| 6253 | .client = clp, |
| 6254 | }; |
| 6255 | struct rpc_message msg = { |
| 6256 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 6257 | .rpc_argp = &args, |
| 6258 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6259 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6260 | }; |
| 6261 | int status; |
| 6262 | |
| 6263 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 6264 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6265 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6266 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6267 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 6268 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6269 | /* Verify the session's negotiated channel_attrs values */ |
| 6270 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6271 | /* Increment the clientid slot sequence id */ |
| 6272 | clp->cl_seqid++; |
| 6273 | } |
| 6274 | |
| 6275 | return status; |
| 6276 | } |
| 6277 | |
| 6278 | /* |
| 6279 | * Issues a CREATE_SESSION operation to the server. |
| 6280 | * It is the responsibility of the caller to verify the session is |
| 6281 | * expired before calling this routine. |
| 6282 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6283 | 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] | 6284 | { |
| 6285 | int status; |
| 6286 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6287 | struct nfs4_session *session = clp->cl_session; |
| 6288 | |
| 6289 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 6290 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6291 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6292 | if (status) |
| 6293 | goto out; |
| 6294 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 6295 | /* Init or reset the session slot tables */ |
| 6296 | status = nfs4_setup_session_slot_tables(session); |
| 6297 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6298 | if (status) |
| 6299 | goto out; |
| 6300 | |
| 6301 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 6302 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 6303 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6304 | out: |
| 6305 | dprintk("<-- %s\n", __func__); |
| 6306 | return status; |
| 6307 | } |
| 6308 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6309 | /* |
| 6310 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 6311 | * The caller must serialize access to this routine. |
| 6312 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6313 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 6314 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6315 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6316 | struct rpc_message msg = { |
| 6317 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 6318 | .rpc_argp = session, |
| 6319 | .rpc_cred = cred, |
| 6320 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6321 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6322 | |
| 6323 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 6324 | |
| 6325 | /* session is still being setup */ |
| 6326 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 6327 | return status; |
| 6328 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6329 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6330 | |
| 6331 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 6332 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6333 | "Session has been destroyed regardless...\n", status); |
| 6334 | |
| 6335 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 6336 | return status; |
| 6337 | } |
| 6338 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6339 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6340 | * Renew the cl_session lease. |
| 6341 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6342 | struct nfs4_sequence_data { |
| 6343 | struct nfs_client *clp; |
| 6344 | struct nfs4_sequence_args args; |
| 6345 | struct nfs4_sequence_res res; |
| 6346 | }; |
| 6347 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6348 | static void nfs41_sequence_release(void *data) |
| 6349 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6350 | struct nfs4_sequence_data *calldata = data; |
| 6351 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6352 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6353 | if (atomic_read(&clp->cl_count) > 1) |
| 6354 | nfs4_schedule_state_renewal(clp); |
| 6355 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6356 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6357 | } |
| 6358 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6359 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6360 | { |
| 6361 | switch(task->tk_status) { |
| 6362 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6363 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 6364 | return -EAGAIN; |
| 6365 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6366 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6367 | } |
| 6368 | return 0; |
| 6369 | } |
| 6370 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6371 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6372 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6373 | struct nfs4_sequence_data *calldata = data; |
| 6374 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6375 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6376 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 6377 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6378 | |
| 6379 | if (task->tk_status < 0) { |
| 6380 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6381 | if (atomic_read(&clp->cl_count) == 1) |
| 6382 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6383 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6384 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 6385 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6386 | return; |
| 6387 | } |
| 6388 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6389 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6390 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6391 | dprintk("<-- %s\n", __func__); |
| 6392 | } |
| 6393 | |
| 6394 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 6395 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6396 | struct nfs4_sequence_data *calldata = data; |
| 6397 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6398 | struct nfs4_sequence_args *args; |
| 6399 | struct nfs4_sequence_res *res; |
| 6400 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6401 | args = task->tk_msg.rpc_argp; |
| 6402 | res = task->tk_msg.rpc_resp; |
| 6403 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6404 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6405 | } |
| 6406 | |
| 6407 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 6408 | .rpc_call_done = nfs41_sequence_call_done, |
| 6409 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6410 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6411 | }; |
| 6412 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6413 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 6414 | struct rpc_cred *cred, |
| 6415 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6416 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6417 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6418 | struct rpc_message msg = { |
| 6419 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 6420 | .rpc_cred = cred, |
| 6421 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6422 | struct rpc_task_setup task_setup_data = { |
| 6423 | .rpc_client = clp->cl_rpcclient, |
| 6424 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6425 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 6426 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6427 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6428 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6429 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6430 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 6431 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6432 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6433 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6434 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6435 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6436 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6437 | if (is_privileged) |
| 6438 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6439 | msg.rpc_argp = &calldata->args; |
| 6440 | msg.rpc_resp = &calldata->res; |
| 6441 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6442 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6443 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6444 | return rpc_run_task(&task_setup_data); |
| 6445 | } |
| 6446 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6447 | 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] | 6448 | { |
| 6449 | struct rpc_task *task; |
| 6450 | int ret = 0; |
| 6451 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6452 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 6453 | return 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6454 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6455 | if (IS_ERR(task)) |
| 6456 | ret = PTR_ERR(task); |
| 6457 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6458 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6459 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6460 | return ret; |
| 6461 | } |
| 6462 | |
| 6463 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 6464 | { |
| 6465 | struct rpc_task *task; |
| 6466 | int ret; |
| 6467 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6468 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6469 | if (IS_ERR(task)) { |
| 6470 | ret = PTR_ERR(task); |
| 6471 | goto out; |
| 6472 | } |
| 6473 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6474 | if (!ret) { |
| 6475 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 6476 | |
| 6477 | if (task->tk_status == 0) |
| 6478 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6479 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6480 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6481 | rpc_put_task(task); |
| 6482 | out: |
| 6483 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6484 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6485 | } |
| 6486 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6487 | struct nfs4_reclaim_complete_data { |
| 6488 | struct nfs_client *clp; |
| 6489 | struct nfs41_reclaim_complete_args arg; |
| 6490 | struct nfs41_reclaim_complete_res res; |
| 6491 | }; |
| 6492 | |
| 6493 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 6494 | { |
| 6495 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6496 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6497 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 6498 | &calldata->arg.seq_args, |
| 6499 | &calldata->res.seq_res, |
| 6500 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6501 | } |
| 6502 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6503 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6504 | { |
| 6505 | switch(task->tk_status) { |
| 6506 | case 0: |
| 6507 | case -NFS4ERR_COMPLETE_ALREADY: |
| 6508 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 6509 | break; |
| 6510 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6511 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6512 | /* fall through */ |
| 6513 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6514 | return -EAGAIN; |
| 6515 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6516 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6517 | } |
| 6518 | return 0; |
| 6519 | } |
| 6520 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6521 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 6522 | { |
| 6523 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6524 | struct nfs_client *clp = calldata->clp; |
| 6525 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 6526 | |
| 6527 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6528 | if (!nfs41_sequence_done(task, res)) |
| 6529 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6530 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6531 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 6532 | rpc_restart_call_prepare(task); |
| 6533 | return; |
| 6534 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6535 | dprintk("<-- %s\n", __func__); |
| 6536 | } |
| 6537 | |
| 6538 | static void nfs4_free_reclaim_complete_data(void *data) |
| 6539 | { |
| 6540 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6541 | |
| 6542 | kfree(calldata); |
| 6543 | } |
| 6544 | |
| 6545 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 6546 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 6547 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 6548 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 6549 | }; |
| 6550 | |
| 6551 | /* |
| 6552 | * Issue a global reclaim complete. |
| 6553 | */ |
| 6554 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 6555 | { |
| 6556 | struct nfs4_reclaim_complete_data *calldata; |
| 6557 | struct rpc_task *task; |
| 6558 | struct rpc_message msg = { |
| 6559 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 6560 | }; |
| 6561 | struct rpc_task_setup task_setup_data = { |
| 6562 | .rpc_client = clp->cl_rpcclient, |
| 6563 | .rpc_message = &msg, |
| 6564 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 6565 | .flags = RPC_TASK_ASYNC, |
| 6566 | }; |
| 6567 | int status = -ENOMEM; |
| 6568 | |
| 6569 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6570 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6571 | if (calldata == NULL) |
| 6572 | goto out; |
| 6573 | calldata->clp = clp; |
| 6574 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6575 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6576 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6577 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6578 | msg.rpc_argp = &calldata->arg; |
| 6579 | msg.rpc_resp = &calldata->res; |
| 6580 | task_setup_data.callback_data = calldata; |
| 6581 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6582 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6583 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6584 | goto out; |
| 6585 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6586 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6587 | if (status == 0) |
| 6588 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6589 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6590 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6591 | out: |
| 6592 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6593 | return status; |
| 6594 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6595 | |
| 6596 | static void |
| 6597 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6598 | { |
| 6599 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6600 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6601 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6602 | |
| 6603 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6604 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6605 | * right now covering the LAYOUTGET we are about to send. |
| 6606 | * However, that is not so catastrophic, and there seems |
| 6607 | * to be no way to prevent it completely. |
| 6608 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6609 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6610 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6611 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6612 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6613 | NFS_I(lgp->args.inode)->layout, |
| 6614 | lgp->args.ctx->state)) { |
| 6615 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6616 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6617 | } |
| 6618 | |
| 6619 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6620 | { |
| 6621 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6622 | struct inode *inode = lgp->args.inode; |
| 6623 | struct nfs_server *server = NFS_SERVER(inode); |
| 6624 | struct pnfs_layout_hdr *lo; |
| 6625 | struct nfs4_state *state = NULL; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6626 | unsigned long timeo, giveup; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6627 | |
| 6628 | dprintk("--> %s\n", __func__); |
| 6629 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6630 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6631 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6632 | |
| 6633 | switch (task->tk_status) { |
| 6634 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6635 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6636 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6637 | case -NFS4ERR_RECALLCONFLICT: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6638 | timeo = rpc_get_timeout(task->tk_client); |
| 6639 | giveup = lgp->args.timestamp + timeo; |
| 6640 | if (time_after(giveup, jiffies)) |
| 6641 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6642 | break; |
| 6643 | case -NFS4ERR_EXPIRED: |
| 6644 | case -NFS4ERR_BAD_STATEID: |
| 6645 | spin_lock(&inode->i_lock); |
| 6646 | lo = NFS_I(inode)->layout; |
| 6647 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6648 | spin_unlock(&inode->i_lock); |
| 6649 | /* If the open stateid was bad, then recover it. */ |
| 6650 | state = lgp->args.ctx->state; |
| 6651 | } else { |
| 6652 | LIST_HEAD(head); |
| 6653 | |
| 6654 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6655 | spin_unlock(&inode->i_lock); |
| 6656 | /* Mark the bad layout state as invalid, then |
| 6657 | * retry using the open stateid. */ |
| 6658 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6659 | } |
| 6660 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6661 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6662 | rpc_restart_call_prepare(task); |
| 6663 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6664 | dprintk("<-- %s\n", __func__); |
| 6665 | } |
| 6666 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6667 | static size_t max_response_pages(struct nfs_server *server) |
| 6668 | { |
| 6669 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6670 | return nfs_page_array_len(0, max_resp_sz); |
| 6671 | } |
| 6672 | |
| 6673 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6674 | { |
| 6675 | int i; |
| 6676 | |
| 6677 | if (!pages) |
| 6678 | return; |
| 6679 | |
| 6680 | for (i = 0; i < size; i++) { |
| 6681 | if (!pages[i]) |
| 6682 | break; |
| 6683 | __free_page(pages[i]); |
| 6684 | } |
| 6685 | kfree(pages); |
| 6686 | } |
| 6687 | |
| 6688 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6689 | { |
| 6690 | struct page **pages; |
| 6691 | int i; |
| 6692 | |
| 6693 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6694 | if (!pages) { |
| 6695 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6696 | return NULL; |
| 6697 | } |
| 6698 | |
| 6699 | for (i = 0; i < size; i++) { |
| 6700 | pages[i] = alloc_page(gfp_flags); |
| 6701 | if (!pages[i]) { |
| 6702 | dprintk("%s: failed to allocate page\n", __func__); |
| 6703 | nfs4_free_pages(pages, size); |
| 6704 | return NULL; |
| 6705 | } |
| 6706 | } |
| 6707 | |
| 6708 | return pages; |
| 6709 | } |
| 6710 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6711 | static void nfs4_layoutget_release(void *calldata) |
| 6712 | { |
| 6713 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6714 | struct inode *inode = lgp->args.inode; |
| 6715 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6716 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6717 | |
| 6718 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6719 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6720 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6721 | put_nfs_open_context(lgp->args.ctx); |
| 6722 | kfree(calldata); |
| 6723 | dprintk("<-- %s\n", __func__); |
| 6724 | } |
| 6725 | |
| 6726 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6727 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6728 | .rpc_call_done = nfs4_layoutget_done, |
| 6729 | .rpc_release = nfs4_layoutget_release, |
| 6730 | }; |
| 6731 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6732 | struct pnfs_layout_segment * |
| 6733 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6734 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6735 | struct inode *inode = lgp->args.inode; |
| 6736 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6737 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6738 | struct rpc_task *task; |
| 6739 | struct rpc_message msg = { |
| 6740 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6741 | .rpc_argp = &lgp->args, |
| 6742 | .rpc_resp = &lgp->res, |
| 6743 | }; |
| 6744 | struct rpc_task_setup task_setup_data = { |
| 6745 | .rpc_client = server->client, |
| 6746 | .rpc_message = &msg, |
| 6747 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6748 | .callback_data = lgp, |
| 6749 | .flags = RPC_TASK_ASYNC, |
| 6750 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6751 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6752 | int status = 0; |
| 6753 | |
| 6754 | dprintk("--> %s\n", __func__); |
| 6755 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6756 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6757 | if (!lgp->args.layout.pages) { |
| 6758 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6759 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6760 | } |
| 6761 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6762 | lgp->args.timestamp = jiffies; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6763 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6764 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6765 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6766 | 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] | 6767 | |
| 6768 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 6769 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 6770 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6771 | task = rpc_run_task(&task_setup_data); |
| 6772 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6773 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6774 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6775 | if (status == 0) |
| 6776 | status = task->tk_status; |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 6777 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 6778 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6779 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6780 | rpc_put_task(task); |
| 6781 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6782 | if (status) |
| 6783 | return ERR_PTR(status); |
| 6784 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6785 | } |
| 6786 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6787 | static void |
| 6788 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6789 | { |
| 6790 | struct nfs4_layoutreturn *lrp = calldata; |
| 6791 | |
| 6792 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6793 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 6794 | &lrp->args.seq_args, |
| 6795 | &lrp->res.seq_res, |
| 6796 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6797 | } |
| 6798 | |
| 6799 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6800 | { |
| 6801 | struct nfs4_layoutreturn *lrp = calldata; |
| 6802 | struct nfs_server *server; |
| 6803 | |
| 6804 | dprintk("--> %s\n", __func__); |
| 6805 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6806 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6807 | return; |
| 6808 | |
| 6809 | server = NFS_SERVER(lrp->args.inode); |
| 6810 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6811 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6812 | return; |
| 6813 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6814 | dprintk("<-- %s\n", __func__); |
| 6815 | } |
| 6816 | |
| 6817 | static void nfs4_layoutreturn_release(void *calldata) |
| 6818 | { |
| 6819 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6820 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6821 | |
| 6822 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6823 | spin_lock(&lo->plh_inode->i_lock); |
| 6824 | if (lrp->res.lrs_present) |
| 6825 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6826 | lo->plh_block_lgets--; |
| 6827 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6828 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6829 | kfree(calldata); |
| 6830 | dprintk("<-- %s\n", __func__); |
| 6831 | } |
| 6832 | |
| 6833 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6834 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6835 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6836 | .rpc_release = nfs4_layoutreturn_release, |
| 6837 | }; |
| 6838 | |
| 6839 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6840 | { |
| 6841 | struct rpc_task *task; |
| 6842 | struct rpc_message msg = { |
| 6843 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6844 | .rpc_argp = &lrp->args, |
| 6845 | .rpc_resp = &lrp->res, |
| 6846 | }; |
| 6847 | struct rpc_task_setup task_setup_data = { |
| 6848 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6849 | .rpc_message = &msg, |
| 6850 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6851 | .callback_data = lrp, |
| 6852 | }; |
| 6853 | int status; |
| 6854 | |
| 6855 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6856 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6857 | task = rpc_run_task(&task_setup_data); |
| 6858 | if (IS_ERR(task)) |
| 6859 | return PTR_ERR(task); |
| 6860 | status = task->tk_status; |
| 6861 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6862 | rpc_put_task(task); |
| 6863 | return status; |
| 6864 | } |
| 6865 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6866 | /* |
| 6867 | * Retrieve the list of Data Server devices from the MDS. |
| 6868 | */ |
| 6869 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6870 | const struct nfs_fh *fh, |
| 6871 | struct pnfs_devicelist *devlist) |
| 6872 | { |
| 6873 | struct nfs4_getdevicelist_args args = { |
| 6874 | .fh = fh, |
| 6875 | .layoutclass = server->pnfs_curr_ld->id, |
| 6876 | }; |
| 6877 | struct nfs4_getdevicelist_res res = { |
| 6878 | .devlist = devlist, |
| 6879 | }; |
| 6880 | struct rpc_message msg = { |
| 6881 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6882 | .rpc_argp = &args, |
| 6883 | .rpc_resp = &res, |
| 6884 | }; |
| 6885 | int status; |
| 6886 | |
| 6887 | dprintk("--> %s\n", __func__); |
| 6888 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6889 | &res.seq_res, 0); |
| 6890 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6891 | return status; |
| 6892 | } |
| 6893 | |
| 6894 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6895 | const struct nfs_fh *fh, |
| 6896 | struct pnfs_devicelist *devlist) |
| 6897 | { |
| 6898 | struct nfs4_exception exception = { }; |
| 6899 | int err; |
| 6900 | |
| 6901 | do { |
| 6902 | err = nfs4_handle_exception(server, |
| 6903 | _nfs4_getdevicelist(server, fh, devlist), |
| 6904 | &exception); |
| 6905 | } while (exception.retry); |
| 6906 | |
| 6907 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6908 | err, devlist->num_devs); |
| 6909 | |
| 6910 | return err; |
| 6911 | } |
| 6912 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6913 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6914 | static int |
| 6915 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6916 | { |
| 6917 | struct nfs4_getdeviceinfo_args args = { |
| 6918 | .pdev = pdev, |
| 6919 | }; |
| 6920 | struct nfs4_getdeviceinfo_res res = { |
| 6921 | .pdev = pdev, |
| 6922 | }; |
| 6923 | struct rpc_message msg = { |
| 6924 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6925 | .rpc_argp = &args, |
| 6926 | .rpc_resp = &res, |
| 6927 | }; |
| 6928 | int status; |
| 6929 | |
| 6930 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6931 | 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] | 6932 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6933 | |
| 6934 | return status; |
| 6935 | } |
| 6936 | |
| 6937 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6938 | { |
| 6939 | struct nfs4_exception exception = { }; |
| 6940 | int err; |
| 6941 | |
| 6942 | do { |
| 6943 | err = nfs4_handle_exception(server, |
| 6944 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6945 | &exception); |
| 6946 | } while (exception.retry); |
| 6947 | return err; |
| 6948 | } |
| 6949 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6950 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6951 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6952 | { |
| 6953 | struct nfs4_layoutcommit_data *data = calldata; |
| 6954 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6955 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6956 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6957 | nfs41_setup_sequence(session, |
| 6958 | &data->args.seq_args, |
| 6959 | &data->res.seq_res, |
| 6960 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6961 | } |
| 6962 | |
| 6963 | static void |
| 6964 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6965 | { |
| 6966 | struct nfs4_layoutcommit_data *data = calldata; |
| 6967 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6968 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6969 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6970 | return; |
| 6971 | |
| 6972 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6973 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6974 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6975 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6976 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6977 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6978 | break; |
| 6979 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6980 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6981 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6982 | break; |
| 6983 | default: |
| 6984 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6985 | rpc_restart_call_prepare(task); |
| 6986 | return; |
| 6987 | } |
| 6988 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6989 | } |
| 6990 | |
| 6991 | static void nfs4_layoutcommit_release(void *calldata) |
| 6992 | { |
| 6993 | struct nfs4_layoutcommit_data *data = calldata; |
| 6994 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6995 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6996 | put_rpccred(data->cred); |
| 6997 | kfree(data); |
| 6998 | } |
| 6999 | |
| 7000 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 7001 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 7002 | .rpc_call_done = nfs4_layoutcommit_done, |
| 7003 | .rpc_release = nfs4_layoutcommit_release, |
| 7004 | }; |
| 7005 | |
| 7006 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 7007 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7008 | { |
| 7009 | struct rpc_message msg = { |
| 7010 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 7011 | .rpc_argp = &data->args, |
| 7012 | .rpc_resp = &data->res, |
| 7013 | .rpc_cred = data->cred, |
| 7014 | }; |
| 7015 | struct rpc_task_setup task_setup_data = { |
| 7016 | .task = &data->task, |
| 7017 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 7018 | .rpc_message = &msg, |
| 7019 | .callback_ops = &nfs4_layoutcommit_ops, |
| 7020 | .callback_data = data, |
| 7021 | .flags = RPC_TASK_ASYNC, |
| 7022 | }; |
| 7023 | struct rpc_task *task; |
| 7024 | int status = 0; |
| 7025 | |
| 7026 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 7027 | "lbw: %llu inode %lu\n", |
| 7028 | data->task.tk_pid, sync, |
| 7029 | data->args.lastbytewritten, |
| 7030 | data->args.inode->i_ino); |
| 7031 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 7032 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7033 | task = rpc_run_task(&task_setup_data); |
| 7034 | if (IS_ERR(task)) |
| 7035 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 7036 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7037 | goto out; |
| 7038 | status = nfs4_wait_for_completion_rpc_task(task); |
| 7039 | if (status != 0) |
| 7040 | goto out; |
| 7041 | status = task->tk_status; |
| 7042 | out: |
| 7043 | dprintk("%s: status %d\n", __func__, status); |
| 7044 | rpc_put_task(task); |
| 7045 | return status; |
| 7046 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7047 | |
| 7048 | static int |
| 7049 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 7050 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 7051 | { |
| 7052 | struct nfs41_secinfo_no_name_args args = { |
| 7053 | .style = SECINFO_STYLE_CURRENT_FH, |
| 7054 | }; |
| 7055 | struct nfs4_secinfo_res res = { |
| 7056 | .flavors = flavors, |
| 7057 | }; |
| 7058 | struct rpc_message msg = { |
| 7059 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 7060 | .rpc_argp = &args, |
| 7061 | .rpc_resp = &res, |
| 7062 | }; |
| 7063 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 7064 | } |
| 7065 | |
| 7066 | static int |
| 7067 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 7068 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 7069 | { |
| 7070 | struct nfs4_exception exception = { }; |
| 7071 | int err; |
| 7072 | do { |
| 7073 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 7074 | switch (err) { |
| 7075 | case 0: |
| 7076 | case -NFS4ERR_WRONGSEC: |
| 7077 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 7078 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7079 | default: |
| 7080 | err = nfs4_handle_exception(server, err, &exception); |
| 7081 | } |
| 7082 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 7083 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7084 | return err; |
| 7085 | } |
| 7086 | |
| 7087 | static int |
| 7088 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 7089 | struct nfs_fsinfo *info) |
| 7090 | { |
| 7091 | int err; |
| 7092 | struct page *page; |
| 7093 | rpc_authflavor_t flavor; |
| 7094 | struct nfs4_secinfo_flavors *flavors; |
| 7095 | |
| 7096 | page = alloc_page(GFP_KERNEL); |
| 7097 | if (!page) { |
| 7098 | err = -ENOMEM; |
| 7099 | goto out; |
| 7100 | } |
| 7101 | |
| 7102 | flavors = page_address(page); |
| 7103 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 7104 | |
| 7105 | /* |
| 7106 | * Fall back on "guess and check" method if |
| 7107 | * the server doesn't support SECINFO_NO_NAME |
| 7108 | */ |
| 7109 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 7110 | err = nfs4_find_root_sec(server, fhandle, info); |
| 7111 | goto out_freepage; |
| 7112 | } |
| 7113 | if (err) |
| 7114 | goto out_freepage; |
| 7115 | |
| 7116 | flavor = nfs_find_best_sec(flavors); |
| 7117 | if (err == 0) |
| 7118 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 7119 | |
| 7120 | out_freepage: |
| 7121 | put_page(page); |
| 7122 | if (err == -EACCES) |
| 7123 | return -EPERM; |
| 7124 | out: |
| 7125 | return err; |
| 7126 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7127 | |
| 7128 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7129 | { |
| 7130 | int status; |
| 7131 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7132 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7133 | }; |
| 7134 | struct nfs41_test_stateid_res res; |
| 7135 | struct rpc_message msg = { |
| 7136 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 7137 | .rpc_argp = &args, |
| 7138 | .rpc_resp = &res, |
| 7139 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7140 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7141 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 7142 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7143 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7144 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
| 7145 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7146 | if (status != NFS_OK) { |
| 7147 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7148 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7149 | } |
| 7150 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7151 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7152 | } |
| 7153 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7154 | /** |
| 7155 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 7156 | * |
| 7157 | * @server: server / transport on which to perform the operation |
| 7158 | * @stateid: state ID to test |
| 7159 | * |
| 7160 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 7161 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 7162 | * failed or the state ID is not currently valid. |
| 7163 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7164 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7165 | { |
| 7166 | struct nfs4_exception exception = { }; |
| 7167 | int err; |
| 7168 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7169 | err = _nfs41_test_stateid(server, stateid); |
| 7170 | if (err != -NFS4ERR_DELAY) |
| 7171 | break; |
| 7172 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7173 | } while (exception.retry); |
| 7174 | return err; |
| 7175 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7176 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7177 | struct nfs_free_stateid_data { |
| 7178 | struct nfs_server *server; |
| 7179 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7180 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7181 | }; |
| 7182 | |
| 7183 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 7184 | { |
| 7185 | struct nfs_free_stateid_data *data = calldata; |
| 7186 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 7187 | &data->args.seq_args, |
| 7188 | &data->res.seq_res, |
| 7189 | task); |
| 7190 | } |
| 7191 | |
| 7192 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 7193 | { |
| 7194 | struct nfs_free_stateid_data *data = calldata; |
| 7195 | |
| 7196 | nfs41_sequence_done(task, &data->res.seq_res); |
| 7197 | |
| 7198 | switch (task->tk_status) { |
| 7199 | case -NFS4ERR_DELAY: |
| 7200 | if (nfs4_async_handle_error(task, data->server, NULL) == -EAGAIN) |
| 7201 | rpc_restart_call_prepare(task); |
| 7202 | } |
| 7203 | } |
| 7204 | |
| 7205 | static void nfs41_free_stateid_release(void *calldata) |
| 7206 | { |
| 7207 | kfree(calldata); |
| 7208 | } |
| 7209 | |
| 7210 | const struct rpc_call_ops nfs41_free_stateid_ops = { |
| 7211 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 7212 | .rpc_call_done = nfs41_free_stateid_done, |
| 7213 | .rpc_release = nfs41_free_stateid_release, |
| 7214 | }; |
| 7215 | |
| 7216 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
| 7217 | nfs4_stateid *stateid, |
| 7218 | bool privileged) |
| 7219 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7220 | struct rpc_message msg = { |
| 7221 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7222 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7223 | struct rpc_task_setup task_setup = { |
| 7224 | .rpc_client = server->client, |
| 7225 | .rpc_message = &msg, |
| 7226 | .callback_ops = &nfs41_free_stateid_ops, |
| 7227 | .flags = RPC_TASK_ASYNC, |
| 7228 | }; |
| 7229 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7230 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7231 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7232 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 7233 | if (!data) |
| 7234 | return ERR_PTR(-ENOMEM); |
| 7235 | data->server = server; |
| 7236 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 7237 | |
| 7238 | task_setup.callback_data = data; |
| 7239 | |
| 7240 | msg.rpc_argp = &data->args; |
| 7241 | msg.rpc_resp = &data->res; |
| 7242 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
| 7243 | if (privileged) |
| 7244 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 7245 | |
| 7246 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7247 | } |
| 7248 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7249 | /** |
| 7250 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 7251 | * |
| 7252 | * @server: server / transport on which to perform the operation |
| 7253 | * @stateid: state ID to release |
| 7254 | * |
| 7255 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 7256 | * negative NFS4ERR value is returned. |
| 7257 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7258 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7259 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7260 | struct rpc_task *task; |
| 7261 | int ret; |
| 7262 | |
| 7263 | task = _nfs41_free_stateid(server, stateid, true); |
| 7264 | if (IS_ERR(task)) |
| 7265 | return PTR_ERR(task); |
| 7266 | ret = rpc_wait_for_completion_task(task); |
| 7267 | if (!ret) |
| 7268 | ret = task->tk_status; |
| 7269 | rpc_put_task(task); |
| 7270 | return ret; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7271 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7272 | |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7273 | static int nfs41_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp) |
| 7274 | { |
| 7275 | struct rpc_task *task; |
| 7276 | |
| 7277 | task = _nfs41_free_stateid(server, &lsp->ls_stateid, false); |
| 7278 | nfs4_free_lock_state(server, lsp); |
| 7279 | if (IS_ERR(task)) |
| 7280 | return PTR_ERR(task); |
| 7281 | rpc_put_task(task); |
| 7282 | return 0; |
| 7283 | } |
| 7284 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7285 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 7286 | const nfs4_stateid *s2) |
| 7287 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7288 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7289 | return false; |
| 7290 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7291 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7292 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7293 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7294 | return true; |
| 7295 | |
| 7296 | return false; |
| 7297 | } |
| 7298 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7299 | #endif /* CONFIG_NFS_V4_1 */ |
| 7300 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7301 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 7302 | const nfs4_stateid *s2) |
| 7303 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7304 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7305 | } |
| 7306 | |
| 7307 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7308 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7309 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7310 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7311 | .recover_open = nfs4_open_reclaim, |
| 7312 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7313 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 7314 | .get_clid_cred = nfs4_get_setclientid_cred, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7315 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7316 | }; |
| 7317 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7318 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7319 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7320 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 7321 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 7322 | .recover_open = nfs4_open_reclaim, |
| 7323 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7324 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 7325 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7326 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7327 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7328 | }; |
| 7329 | #endif /* CONFIG_NFS_V4_1 */ |
| 7330 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7331 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7332 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7333 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7334 | .recover_open = nfs4_open_expired, |
| 7335 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7336 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 7337 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7338 | }; |
| 7339 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7340 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7341 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7342 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 7343 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7344 | .recover_open = nfs41_open_expired, |
| 7345 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7346 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 7347 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7348 | }; |
| 7349 | #endif /* CONFIG_NFS_V4_1 */ |
| 7350 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7351 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7352 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7353 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7354 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7355 | }; |
| 7356 | |
| 7357 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7358 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7359 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7360 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7361 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7362 | }; |
| 7363 | #endif |
| 7364 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7365 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 7366 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 7367 | .init_caps = NFS_CAP_READDIRPLUS |
| 7368 | | NFS_CAP_ATOMIC_OPEN |
| 7369 | | NFS_CAP_CHANGE_ATTR |
| 7370 | | NFS_CAP_POSIX_LOCK, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7371 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7372 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7373 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7374 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7375 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 7376 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 7377 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7378 | }; |
| 7379 | |
| 7380 | #if defined(CONFIG_NFS_V4_1) |
| 7381 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 7382 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 7383 | .init_caps = NFS_CAP_READDIRPLUS |
| 7384 | | NFS_CAP_ATOMIC_OPEN |
| 7385 | | NFS_CAP_CHANGE_ATTR |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 7386 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 7387 | | NFS_CAP_STATEID_NFSV41 |
| 7388 | | NFS_CAP_ATOMIC_OPEN_V1, |
Bryan Schumaker | 104287c | 2012-11-12 14:13:13 -0500 | [diff] [blame] | 7389 | .call_sync = nfs4_call_sync_sequence, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7390 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7391 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7392 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7393 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 7394 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 7395 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7396 | }; |
| 7397 | #endif |
| 7398 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7399 | #if defined(CONFIG_NFS_V4_2) |
| 7400 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 7401 | .minor_version = 2, |
| 7402 | .call_sync = nfs4_call_sync_sequence, |
| 7403 | .match_stateid = nfs41_match_stateid, |
| 7404 | .find_root_sec = nfs41_find_root_sec, |
| 7405 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 7406 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 7407 | .state_renewal_ops = &nfs41_state_renewal_ops, |
| 7408 | }; |
| 7409 | #endif |
| 7410 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7411 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 7412 | [0] = &nfs_v4_0_minor_ops, |
| 7413 | #if defined(CONFIG_NFS_V4_1) |
| 7414 | [1] = &nfs_v4_1_minor_ops, |
| 7415 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7416 | #if defined(CONFIG_NFS_V4_2) |
| 7417 | [2] = &nfs_v4_2_minor_ops, |
| 7418 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7419 | }; |
| 7420 | |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 7421 | const struct inode_operations nfs4_dir_inode_operations = { |
| 7422 | .create = nfs_create, |
| 7423 | .lookup = nfs_lookup, |
| 7424 | .atomic_open = nfs_atomic_open, |
| 7425 | .link = nfs_link, |
| 7426 | .unlink = nfs_unlink, |
| 7427 | .symlink = nfs_symlink, |
| 7428 | .mkdir = nfs_mkdir, |
| 7429 | .rmdir = nfs_rmdir, |
| 7430 | .mknod = nfs_mknod, |
| 7431 | .rename = nfs_rename, |
| 7432 | .permission = nfs_permission, |
| 7433 | .getattr = nfs_getattr, |
| 7434 | .setattr = nfs_setattr, |
| 7435 | .getxattr = generic_getxattr, |
| 7436 | .setxattr = generic_setxattr, |
| 7437 | .listxattr = generic_listxattr, |
| 7438 | .removexattr = generic_removexattr, |
| 7439 | }; |
| 7440 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 7441 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7442 | .permission = nfs_permission, |
| 7443 | .getattr = nfs_getattr, |
| 7444 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7445 | .getxattr = generic_getxattr, |
| 7446 | .setxattr = generic_setxattr, |
| 7447 | .listxattr = generic_listxattr, |
| 7448 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7449 | }; |
| 7450 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 7451 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7452 | .version = 4, /* protocol version */ |
| 7453 | .dentry_ops = &nfs4_dentry_operations, |
| 7454 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7455 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 7456 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7457 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 7458 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 7459 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7460 | .getattr = nfs4_proc_getattr, |
| 7461 | .setattr = nfs4_proc_setattr, |
| 7462 | .lookup = nfs4_proc_lookup, |
| 7463 | .access = nfs4_proc_access, |
| 7464 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7465 | .create = nfs4_proc_create, |
| 7466 | .remove = nfs4_proc_remove, |
| 7467 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 7468 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7469 | .unlink_done = nfs4_proc_unlink_done, |
| 7470 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7471 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 7472 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7473 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7474 | .link = nfs4_proc_link, |
| 7475 | .symlink = nfs4_proc_symlink, |
| 7476 | .mkdir = nfs4_proc_mkdir, |
| 7477 | .rmdir = nfs4_proc_remove, |
| 7478 | .readdir = nfs4_proc_readdir, |
| 7479 | .mknod = nfs4_proc_mknod, |
| 7480 | .statfs = nfs4_proc_statfs, |
| 7481 | .fsinfo = nfs4_proc_fsinfo, |
| 7482 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 7483 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7484 | .decode_dirent = nfs4_decode_dirent, |
| 7485 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 7486 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 7487 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7488 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7489 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 7490 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 7491 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7492 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7493 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 7494 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7495 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7496 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 7497 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 7498 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 7499 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 7500 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 7501 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 7502 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 7503 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 7504 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 7505 | .create_server = nfs4_create_server, |
| 7506 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7507 | }; |
| 7508 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7509 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 7510 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 7511 | .list = nfs4_xattr_list_nfs4_acl, |
| 7512 | .get = nfs4_xattr_get_nfs4_acl, |
| 7513 | .set = nfs4_xattr_set_nfs4_acl, |
| 7514 | }; |
| 7515 | |
| 7516 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 7517 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame^] | 7518 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 7519 | &nfs4_xattr_nfs4_label_handler, |
| 7520 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7521 | NULL |
| 7522 | }; |
| 7523 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7524 | /* |
| 7525 | * Local variables: |
| 7526 | * c-basic-offset: 8 |
| 7527 | * End: |
| 7528 | */ |