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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 42 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/sunrpc/clnt.h> |
| 44 | #include <linux/nfs.h> |
| 45 | #include <linux/nfs4.h> |
| 46 | #include <linux/nfs_fs.h> |
| 47 | #include <linux/nfs_page.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 49 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 50 | #include <linux/module.h> |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 51 | #include <linux/sunrpc/bc_xprt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 53 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 55 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 56 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 57 | #include "callback.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
| 59 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 60 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 61 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 63 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 64 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 65 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 66 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 67 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 68 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | 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] | 70 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 71 | static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
| 72 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 73 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 74 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 75 | struct nfs4_state *state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 78 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 80 | if (err >= -1000) |
| 81 | return err; |
| 82 | switch (err) { |
| 83 | case -NFS4ERR_RESOURCE: |
| 84 | return -EREMOTEIO; |
| 85 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 87 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 88 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 90 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /* |
| 94 | * This is our standard bitmap for GETATTR requests. |
| 95 | */ |
| 96 | const u32 nfs4_fattr_bitmap[2] = { |
| 97 | FATTR4_WORD0_TYPE |
| 98 | | FATTR4_WORD0_CHANGE |
| 99 | | FATTR4_WORD0_SIZE |
| 100 | | FATTR4_WORD0_FSID |
| 101 | | FATTR4_WORD0_FILEID, |
| 102 | FATTR4_WORD1_MODE |
| 103 | | FATTR4_WORD1_NUMLINKS |
| 104 | | FATTR4_WORD1_OWNER |
| 105 | | FATTR4_WORD1_OWNER_GROUP |
| 106 | | FATTR4_WORD1_RAWDEV |
| 107 | | FATTR4_WORD1_SPACE_USED |
| 108 | | FATTR4_WORD1_TIME_ACCESS |
| 109 | | FATTR4_WORD1_TIME_METADATA |
| 110 | | FATTR4_WORD1_TIME_MODIFY |
| 111 | }; |
| 112 | |
| 113 | const u32 nfs4_statfs_bitmap[2] = { |
| 114 | FATTR4_WORD0_FILES_AVAIL |
| 115 | | FATTR4_WORD0_FILES_FREE |
| 116 | | FATTR4_WORD0_FILES_TOTAL, |
| 117 | FATTR4_WORD1_SPACE_AVAIL |
| 118 | | FATTR4_WORD1_SPACE_FREE |
| 119 | | FATTR4_WORD1_SPACE_TOTAL |
| 120 | }; |
| 121 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 122 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | FATTR4_WORD0_MAXLINK |
| 124 | | FATTR4_WORD0_MAXNAME, |
| 125 | 0 |
| 126 | }; |
| 127 | |
| 128 | const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE |
| 129 | | FATTR4_WORD0_MAXREAD |
| 130 | | FATTR4_WORD0_MAXWRITE |
| 131 | | FATTR4_WORD0_LEASE_TIME, |
| 132 | 0 |
| 133 | }; |
| 134 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 135 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 136 | FATTR4_WORD0_TYPE |
| 137 | | FATTR4_WORD0_CHANGE |
| 138 | | FATTR4_WORD0_SIZE |
| 139 | | FATTR4_WORD0_FSID |
| 140 | | FATTR4_WORD0_FILEID |
| 141 | | FATTR4_WORD0_FS_LOCATIONS, |
| 142 | FATTR4_WORD1_MODE |
| 143 | | FATTR4_WORD1_NUMLINKS |
| 144 | | FATTR4_WORD1_OWNER |
| 145 | | FATTR4_WORD1_OWNER_GROUP |
| 146 | | FATTR4_WORD1_RAWDEV |
| 147 | | FATTR4_WORD1_SPACE_USED |
| 148 | | FATTR4_WORD1_TIME_ACCESS |
| 149 | | FATTR4_WORD1_TIME_METADATA |
| 150 | | FATTR4_WORD1_TIME_MODIFY |
| 151 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 152 | }; |
| 153 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 154 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | struct nfs4_readdir_arg *readdir) |
| 156 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 157 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
| 159 | BUG_ON(readdir->count < 80); |
| 160 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 161 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | readdir->cookie = 0; |
| 167 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 168 | if (cookie == 2) |
| 169 | return; |
| 170 | |
| 171 | /* |
| 172 | * NFSv4 servers do not return entries for '.' and '..' |
| 173 | * Therefore, we fake these entries here. We let '.' |
| 174 | * have cookie 0 and '..' have cookie 1. Note that |
| 175 | * when talking to the server, we always send cookie 0 |
| 176 | * instead of 1 or 2. |
| 177 | */ |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 178 | start = p = kmap_atomic(*readdir->pages, KM_USER0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
| 180 | if (cookie == 0) { |
| 181 | *p++ = xdr_one; /* next */ |
| 182 | *p++ = xdr_zero; /* cookie, first word */ |
| 183 | *p++ = xdr_one; /* cookie, second word */ |
| 184 | *p++ = xdr_one; /* entry len */ |
| 185 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 186 | p++; |
| 187 | *p++ = xdr_one; /* bitmap length */ |
| 188 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 189 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 190 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | *p++ = xdr_one; /* next */ |
| 194 | *p++ = xdr_zero; /* cookie, first word */ |
| 195 | *p++ = xdr_two; /* cookie, second word */ |
| 196 | *p++ = xdr_two; /* entry len */ |
| 197 | memcpy(p, "..\0\0", 4); /* entry */ |
| 198 | p++; |
| 199 | *p++ = xdr_one; /* bitmap length */ |
| 200 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 201 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 202 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
| 204 | readdir->pgbase = (char *)p - (char *)start; |
| 205 | readdir->count -= readdir->pgbase; |
| 206 | kunmap_atomic(start, KM_USER0); |
| 207 | } |
| 208 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 209 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 210 | { |
| 211 | int res; |
| 212 | |
| 213 | might_sleep(); |
| 214 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 215 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 216 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 217 | return res; |
| 218 | } |
| 219 | |
| 220 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 221 | { |
| 222 | int res = 0; |
| 223 | |
| 224 | might_sleep(); |
| 225 | |
| 226 | if (*timeout <= 0) |
| 227 | *timeout = NFS4_POLL_RETRY_MIN; |
| 228 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 229 | *timeout = NFS4_POLL_RETRY_MAX; |
| 230 | schedule_timeout_killable(*timeout); |
| 231 | if (fatal_signal_pending(current)) |
| 232 | res = -ERESTARTSYS; |
| 233 | *timeout <<= 1; |
| 234 | return res; |
| 235 | } |
| 236 | |
| 237 | /* This is the error handling routine for processes that are allowed |
| 238 | * to sleep. |
| 239 | */ |
| 240 | static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 241 | { |
| 242 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 243 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 244 | int ret = errorcode; |
| 245 | |
| 246 | exception->retry = 0; |
| 247 | switch(errorcode) { |
| 248 | case 0: |
| 249 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 250 | case -NFS4ERR_ADMIN_REVOKED: |
| 251 | case -NFS4ERR_BAD_STATEID: |
| 252 | case -NFS4ERR_OPENMODE: |
| 253 | if (state == NULL) |
| 254 | break; |
| 255 | nfs4_state_mark_reclaim_nograce(clp, state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 256 | goto do_state_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 257 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 258 | if (state == NULL) |
| 259 | break; |
| 260 | nfs4_state_mark_reclaim_reboot(clp, state); |
| 261 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 262 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 263 | goto do_state_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 264 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 265 | case -NFS4ERR_BADSESSION: |
| 266 | case -NFS4ERR_BADSLOT: |
| 267 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 268 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 269 | case -NFS4ERR_DEADSESSION: |
| 270 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 271 | case -NFS4ERR_SEQ_MISORDERED: |
| 272 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 273 | errorcode); |
Andy Adamson | 0b9e2d4 | 2009-12-04 16:02:14 -0500 | [diff] [blame] | 274 | nfs4_schedule_state_recovery(clp); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 275 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 276 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 277 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 278 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 279 | if (exception->timeout > HZ) { |
| 280 | /* We have retried a decent amount, time to |
| 281 | * fail |
| 282 | */ |
| 283 | ret = -EBUSY; |
| 284 | break; |
| 285 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 286 | case -NFS4ERR_GRACE: |
| 287 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 288 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 289 | ret = nfs4_delay(server->client, &exception->timeout); |
| 290 | if (ret != 0) |
| 291 | break; |
| 292 | case -NFS4ERR_OLD_STATEID: |
| 293 | exception->retry = 1; |
| 294 | } |
| 295 | /* We failed to handle the error */ |
| 296 | return nfs4_map_errors(ret); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 297 | do_state_recovery: |
| 298 | nfs4_schedule_state_recovery(clp); |
| 299 | ret = nfs4_wait_clnt_recover(clp); |
| 300 | if (ret == 0) |
| 301 | exception->retry = 1; |
| 302 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 306 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | { |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 308 | struct nfs_client *clp = server->nfs_client; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | spin_lock(&clp->cl_lock); |
| 310 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 311 | clp->cl_last_renewal = timestamp; |
| 312 | spin_unlock(&clp->cl_lock); |
| 313 | } |
| 314 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 315 | #if defined(CONFIG_NFS_V4_1) |
| 316 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 317 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 318 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 319 | * |
| 320 | * freeing a slot is trivially done by clearing its respective bit |
| 321 | * in the bitmap. |
| 322 | * If the freed slotid equals highest_used_slotid we want to update it |
| 323 | * so that the server would be able to size down the slot table if needed, |
| 324 | * otherwise we know that the highest_used_slotid is still in use. |
| 325 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 326 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 327 | * highest slotid in use. |
| 328 | * If none found, highest_used_slotid is set to -1. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 329 | * |
| 330 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 331 | */ |
| 332 | static void |
| 333 | nfs4_free_slot(struct nfs4_slot_table *tbl, u8 free_slotid) |
| 334 | { |
| 335 | int slotid = free_slotid; |
| 336 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 337 | /* clear used bit in bitmap */ |
| 338 | __clear_bit(slotid, tbl->used_slots); |
| 339 | |
| 340 | /* update highest_used_slotid when it is freed */ |
| 341 | if (slotid == tbl->highest_used_slotid) { |
| 342 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 343 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 344 | tbl->highest_used_slotid = slotid; |
| 345 | else |
| 346 | tbl->highest_used_slotid = -1; |
| 347 | } |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 348 | dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__, |
| 349 | free_slotid, tbl->highest_used_slotid); |
| 350 | } |
| 351 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 352 | /* |
| 353 | * Signal state manager thread if session is drained |
| 354 | */ |
| 355 | static void nfs41_check_drain_session_complete(struct nfs4_session *ses) |
| 356 | { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 357 | struct rpc_task *task; |
| 358 | |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 359 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 360 | task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq); |
| 361 | if (task) |
| 362 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 363 | return; |
| 364 | } |
| 365 | |
| 366 | if (ses->fc_slot_table.highest_used_slotid != -1) |
| 367 | return; |
| 368 | |
| 369 | dprintk("%s COMPLETE: Session Drained\n", __func__); |
| 370 | complete(&ses->complete); |
| 371 | } |
| 372 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 373 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 374 | { |
| 375 | struct nfs4_slot_table *tbl; |
| 376 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 377 | tbl = &res->sr_session->fc_slot_table; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 378 | if (res->sr_slotid == NFS4_MAX_SLOT_TABLE) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 379 | /* just wake up the next guy waiting since |
| 380 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 381 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 382 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 383 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 384 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 385 | spin_lock(&tbl->slot_tbl_lock); |
| 386 | nfs4_free_slot(tbl, res->sr_slotid); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 387 | nfs41_check_drain_session_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 388 | spin_unlock(&tbl->slot_tbl_lock); |
| 389 | res->sr_slotid = NFS4_MAX_SLOT_TABLE; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 390 | } |
| 391 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 392 | static void nfs41_sequence_done(struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 393 | { |
| 394 | unsigned long timestamp; |
| 395 | struct nfs4_slot_table *tbl; |
| 396 | struct nfs4_slot *slot; |
| 397 | |
| 398 | /* |
| 399 | * sr_status remains 1 if an RPC level error occurred. The server |
| 400 | * may or may not have processed the sequence operation.. |
| 401 | * Proceed as if the server received and processed the sequence |
| 402 | * operation. |
| 403 | */ |
| 404 | if (res->sr_status == 1) |
| 405 | res->sr_status = NFS_OK; |
| 406 | |
| 407 | /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */ |
| 408 | if (res->sr_slotid == NFS4_MAX_SLOT_TABLE) |
| 409 | goto out; |
| 410 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 411 | /* Check the SEQUENCE operation status */ |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 412 | if (res->sr_status == 0) { |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 413 | struct nfs_client *clp = res->sr_session->clp; |
| 414 | tbl = &res->sr_session->fc_slot_table; |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 415 | slot = tbl->slots + res->sr_slotid; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 416 | /* Update the slot's sequence and clientid lease timer */ |
| 417 | ++slot->seq_nr; |
| 418 | timestamp = res->sr_renewal_time; |
| 419 | spin_lock(&clp->cl_lock); |
| 420 | if (time_before(clp->cl_last_renewal, timestamp)) |
| 421 | clp->cl_last_renewal = timestamp; |
| 422 | spin_unlock(&clp->cl_lock); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 423 | /* Check sequence flags */ |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 424 | if (atomic_read(&clp->cl_count) > 1) |
| 425 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 426 | } |
| 427 | out: |
| 428 | /* The session may be reset by one of the error handlers. */ |
| 429 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 430 | nfs41_sequence_free_slot(res); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 431 | } |
| 432 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 433 | static void nfs4_sequence_done(const struct nfs_server *server, |
| 434 | struct nfs4_sequence_res *res, int rpc_status) |
| 435 | { |
| 436 | if (res->sr_session != NULL) |
| 437 | nfs41_sequence_done(res); |
| 438 | } |
| 439 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 440 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 441 | * nfs4_find_slot - efficiently look for a free slot |
| 442 | * |
| 443 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 444 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 445 | * and respectively set up the sequence operation args. |
| 446 | * The slot number is returned if found, or NFS4_MAX_SLOT_TABLE otherwise. |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 447 | * |
| 448 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 449 | */ |
| 450 | static u8 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 451 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 452 | { |
| 453 | int slotid; |
| 454 | u8 ret_id = NFS4_MAX_SLOT_TABLE; |
| 455 | BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE); |
| 456 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 457 | dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n", |
| 458 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 459 | tbl->max_slots); |
| 460 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 461 | if (slotid >= tbl->max_slots) |
| 462 | goto out; |
| 463 | __set_bit(slotid, tbl->used_slots); |
| 464 | if (slotid > tbl->highest_used_slotid) |
| 465 | tbl->highest_used_slotid = slotid; |
| 466 | ret_id = slotid; |
| 467 | out: |
| 468 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 469 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 470 | return ret_id; |
| 471 | } |
| 472 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 473 | static int nfs41_setup_sequence(struct nfs4_session *session, |
| 474 | struct nfs4_sequence_args *args, |
| 475 | struct nfs4_sequence_res *res, |
| 476 | int cache_reply, |
| 477 | struct rpc_task *task) |
| 478 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 479 | struct nfs4_slot *slot; |
| 480 | struct nfs4_slot_table *tbl; |
| 481 | u8 slotid; |
| 482 | |
| 483 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 484 | /* slot already allocated? */ |
| 485 | if (res->sr_slotid != NFS4_MAX_SLOT_TABLE) |
| 486 | return 0; |
| 487 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 488 | res->sr_slotid = NFS4_MAX_SLOT_TABLE; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 489 | tbl = &session->fc_slot_table; |
| 490 | |
| 491 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 492 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 493 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 494 | /* |
| 495 | * The state manager will wait until the slot table is empty. |
| 496 | * Schedule the reset thread |
| 497 | */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 498 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 499 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 500 | dprintk("%s Schedule Session Reset\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 501 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 502 | } |
| 503 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 504 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 505 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 506 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 507 | spin_unlock(&tbl->slot_tbl_lock); |
| 508 | dprintk("%s enforce FIFO order\n", __func__); |
| 509 | return -EAGAIN; |
| 510 | } |
| 511 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 512 | slotid = nfs4_find_slot(tbl); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 513 | if (slotid == NFS4_MAX_SLOT_TABLE) { |
| 514 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 515 | spin_unlock(&tbl->slot_tbl_lock); |
| 516 | dprintk("<-- %s: no free slots\n", __func__); |
| 517 | return -EAGAIN; |
| 518 | } |
| 519 | spin_unlock(&tbl->slot_tbl_lock); |
| 520 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 521 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 522 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 523 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 524 | args->sa_slotid = slotid; |
| 525 | args->sa_cache_this = cache_reply; |
| 526 | |
| 527 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 528 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 529 | res->sr_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 530 | res->sr_slotid = slotid; |
| 531 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 532 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 533 | /* |
| 534 | * sr_status is only set in decode_sequence, and so will remain |
| 535 | * set to 1 if an rpc level failure occurs. |
| 536 | */ |
| 537 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 538 | return 0; |
| 539 | } |
| 540 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 541 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 542 | struct nfs4_sequence_args *args, |
| 543 | struct nfs4_sequence_res *res, |
| 544 | int cache_reply, |
| 545 | struct rpc_task *task) |
| 546 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 547 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 548 | int ret = 0; |
| 549 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 550 | if (session == NULL) { |
| 551 | args->sa_session = NULL; |
| 552 | res->sr_session = NULL; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 553 | goto out; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | dprintk("--> %s clp %p session %p sr_slotid %d\n", |
| 557 | __func__, session->clp, session, res->sr_slotid); |
| 558 | |
| 559 | ret = nfs41_setup_sequence(session, args, res, cache_reply, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 560 | task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 561 | out: |
| 562 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 563 | return ret; |
| 564 | } |
| 565 | |
| 566 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 567 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 568 | struct nfs4_sequence_args *seq_args; |
| 569 | struct nfs4_sequence_res *seq_res; |
| 570 | int cache_reply; |
| 571 | }; |
| 572 | |
| 573 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 574 | { |
| 575 | struct nfs41_call_sync_data *data = calldata; |
| 576 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 577 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 578 | |
| 579 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 580 | data->seq_res, data->cache_reply, task)) |
| 581 | return; |
| 582 | rpc_call_start(task); |
| 583 | } |
| 584 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 585 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 586 | { |
| 587 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 588 | nfs41_call_sync_prepare(task, calldata); |
| 589 | } |
| 590 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 591 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 592 | { |
| 593 | struct nfs41_call_sync_data *data = calldata; |
| 594 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 595 | nfs41_sequence_done(data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 596 | } |
| 597 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 598 | struct rpc_call_ops nfs41_call_sync_ops = { |
| 599 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 600 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 601 | }; |
| 602 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 603 | struct rpc_call_ops nfs41_call_priv_sync_ops = { |
| 604 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 605 | .rpc_call_done = nfs41_call_sync_done, |
| 606 | }; |
| 607 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 608 | static int nfs4_call_sync_sequence(struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 609 | struct rpc_message *msg, |
| 610 | struct nfs4_sequence_args *args, |
| 611 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 612 | int cache_reply, |
| 613 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 614 | { |
| 615 | int ret; |
| 616 | struct rpc_task *task; |
| 617 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 618 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 619 | .seq_args = args, |
| 620 | .seq_res = res, |
| 621 | .cache_reply = cache_reply, |
| 622 | }; |
| 623 | struct rpc_task_setup task_setup = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 624 | .rpc_client = server->client, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 625 | .rpc_message = msg, |
| 626 | .callback_ops = &nfs41_call_sync_ops, |
| 627 | .callback_data = &data |
| 628 | }; |
| 629 | |
| 630 | res->sr_slotid = NFS4_MAX_SLOT_TABLE; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 631 | if (privileged) |
| 632 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 633 | task = rpc_run_task(&task_setup); |
| 634 | if (IS_ERR(task)) |
| 635 | ret = PTR_ERR(task); |
| 636 | else { |
| 637 | ret = task->tk_status; |
| 638 | rpc_put_task(task); |
| 639 | } |
| 640 | return ret; |
| 641 | } |
| 642 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 643 | int _nfs4_call_sync_session(struct nfs_server *server, |
| 644 | struct rpc_message *msg, |
| 645 | struct nfs4_sequence_args *args, |
| 646 | struct nfs4_sequence_res *res, |
| 647 | int cache_reply) |
| 648 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 649 | return nfs4_call_sync_sequence(server, msg, args, res, cache_reply, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 650 | } |
| 651 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 652 | #else |
| 653 | static void nfs4_sequence_done(const struct nfs_server *server, |
| 654 | struct nfs4_sequence_res *res, int rpc_status) |
| 655 | { |
| 656 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 657 | #endif /* CONFIG_NFS_V4_1 */ |
| 658 | |
| 659 | int _nfs4_call_sync(struct nfs_server *server, |
| 660 | struct rpc_message *msg, |
| 661 | struct nfs4_sequence_args *args, |
| 662 | struct nfs4_sequence_res *res, |
| 663 | int cache_reply) |
| 664 | { |
Benny Halevy | f375297 | 2009-04-01 09:22:04 -0400 | [diff] [blame] | 665 | args->sa_session = res->sr_session = NULL; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 666 | return rpc_call_sync(server->client, msg, 0); |
| 667 | } |
| 668 | |
| 669 | #define nfs4_call_sync(server, msg, args, res, cache_reply) \ |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 670 | (server)->nfs_client->cl_mvops->call_sync((server), (msg), &(args)->seq_args, \ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 671 | &(res)->seq_res, (cache_reply)) |
| 672 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 673 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 675 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 677 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 678 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA; |
| 679 | if (!cinfo->atomic || cinfo->before != nfsi->change_attr) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 680 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 681 | nfsi->change_attr = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 682 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | } |
| 684 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 685 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 686 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 687 | struct nfs_openargs o_arg; |
| 688 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 689 | struct nfs_open_confirmargs c_arg; |
| 690 | struct nfs_open_confirmres c_res; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 691 | struct nfs_fattr f_attr; |
| 692 | struct nfs_fattr dir_attr; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 693 | struct path path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 694 | struct dentry *dir; |
| 695 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 696 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 697 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 698 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 699 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 700 | int rpc_status; |
| 701 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 702 | }; |
| 703 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 704 | |
| 705 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 706 | { |
| 707 | p->o_res.f_attr = &p->f_attr; |
| 708 | p->o_res.dir_attr = &p->dir_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 709 | p->o_res.seqid = p->o_arg.seqid; |
| 710 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 711 | p->o_res.server = p->o_arg.server; |
| 712 | nfs_fattr_init(&p->f_attr); |
| 713 | nfs_fattr_init(&p->dir_attr); |
Benny Halevy | 578e458 | 2009-06-18 22:01:23 -0400 | [diff] [blame] | 714 | p->o_res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 715 | } |
| 716 | |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 717 | static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 718 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 719 | const struct iattr *attrs, |
| 720 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 721 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 722 | struct dentry *parent = dget_parent(path->dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 723 | struct inode *dir = parent->d_inode; |
| 724 | struct nfs_server *server = NFS_SERVER(dir); |
| 725 | struct nfs4_opendata *p; |
| 726 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 727 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 728 | if (p == NULL) |
| 729 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 730 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 731 | if (p->o_arg.seqid == NULL) |
| 732 | goto err_free; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 733 | path_get(path); |
| 734 | p->path = *path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 735 | p->dir = parent; |
| 736 | p->owner = sp; |
| 737 | atomic_inc(&sp->so_count); |
| 738 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 739 | p->o_arg.open_flags = flags; |
| 740 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 741 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 742 | p->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 743 | p->o_arg.name = &p->path.dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 744 | p->o_arg.server = server; |
| 745 | p->o_arg.bitmask = server->attr_bitmask; |
| 746 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 747 | if (flags & O_CREAT) { |
| 748 | u32 *s; |
| 749 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 750 | p->o_arg.u.attrs = &p->attrs; |
| 751 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 752 | s = (u32 *) p->o_arg.u.verifier.data; |
| 753 | s[0] = jiffies; |
| 754 | s[1] = current->pid; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 755 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 756 | p->c_arg.fh = &p->o_res.fh; |
| 757 | p->c_arg.stateid = &p->o_res.stateid; |
| 758 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 759 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 760 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 761 | return p; |
| 762 | err_free: |
| 763 | kfree(p); |
| 764 | err: |
| 765 | dput(parent); |
| 766 | return NULL; |
| 767 | } |
| 768 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 769 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 770 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 771 | struct nfs4_opendata *p = container_of(kref, |
| 772 | struct nfs4_opendata, kref); |
| 773 | |
| 774 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 775 | if (p->state != NULL) |
| 776 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 777 | nfs4_put_state_owner(p->owner); |
| 778 | dput(p->dir); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 779 | path_put(&p->path); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 780 | kfree(p); |
| 781 | } |
| 782 | |
| 783 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 784 | { |
| 785 | if (p != NULL) |
| 786 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 787 | } |
| 788 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 789 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 790 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 791 | int ret; |
| 792 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 793 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 794 | return ret; |
| 795 | } |
| 796 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 797 | 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] | 798 | { |
| 799 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 800 | |
| 801 | if (open_mode & O_EXCL) |
| 802 | goto out; |
| 803 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 804 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 805 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 806 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 807 | break; |
| 808 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 809 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 810 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 811 | break; |
| 812 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 813 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 814 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 815 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 816 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 817 | return ret; |
| 818 | } |
| 819 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 820 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 821 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 822 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 823 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 824 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 825 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 826 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 827 | return 1; |
| 828 | } |
| 829 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 830 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 831 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 832 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 833 | case FMODE_WRITE: |
| 834 | state->n_wronly++; |
| 835 | break; |
| 836 | case FMODE_READ: |
| 837 | state->n_rdonly++; |
| 838 | break; |
| 839 | case FMODE_READ|FMODE_WRITE: |
| 840 | state->n_rdwr++; |
| 841 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 842 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 843 | } |
| 844 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 845 | 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] | 846 | { |
| 847 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 848 | memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); |
| 849 | memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 850 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 851 | case FMODE_READ: |
| 852 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 853 | break; |
| 854 | case FMODE_WRITE: |
| 855 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 856 | break; |
| 857 | case FMODE_READ|FMODE_WRITE: |
| 858 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 859 | } |
| 860 | } |
| 861 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 862 | 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] | 863 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 864 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 865 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 866 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 867 | } |
| 868 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 869 | 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] | 870 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 871 | /* |
| 872 | * Protect the call to nfs4_state_set_mode_locked and |
| 873 | * serialise the stateid update |
| 874 | */ |
| 875 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 876 | if (deleg_stateid != NULL) { |
| 877 | memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); |
| 878 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 879 | } |
| 880 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 881 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 882 | write_sequnlock(&state->seqlock); |
| 883 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 884 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 885 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | } |
| 887 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 888 | 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] | 889 | { |
| 890 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 891 | struct nfs_delegation *deleg_cur; |
| 892 | int ret = 0; |
| 893 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 894 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 895 | |
| 896 | rcu_read_lock(); |
| 897 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 898 | if (deleg_cur == NULL) |
| 899 | goto no_delegation; |
| 900 | |
| 901 | spin_lock(&deleg_cur->lock); |
| 902 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 903 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 904 | goto no_delegation_unlock; |
| 905 | |
| 906 | if (delegation == NULL) |
| 907 | delegation = &deleg_cur->stateid; |
| 908 | else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) |
| 909 | goto no_delegation_unlock; |
| 910 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 911 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 912 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 913 | ret = 1; |
| 914 | no_delegation_unlock: |
| 915 | spin_unlock(&deleg_cur->lock); |
| 916 | no_delegation: |
| 917 | rcu_read_unlock(); |
| 918 | |
| 919 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 920 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 921 | ret = 1; |
| 922 | } |
| 923 | |
| 924 | return ret; |
| 925 | } |
| 926 | |
| 927 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 928 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 929 | { |
| 930 | struct nfs_delegation *delegation; |
| 931 | |
| 932 | rcu_read_lock(); |
| 933 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 934 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 935 | rcu_read_unlock(); |
| 936 | return; |
| 937 | } |
| 938 | rcu_read_unlock(); |
| 939 | nfs_inode_return_delegation(inode); |
| 940 | } |
| 941 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 942 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 943 | { |
| 944 | struct nfs4_state *state = opendata->state; |
| 945 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 946 | struct nfs_delegation *delegation; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 947 | int open_mode = opendata->o_arg.open_flags & O_EXCL; |
| 948 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 949 | nfs4_stateid stateid; |
| 950 | int ret = -EAGAIN; |
| 951 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 952 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 953 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 954 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 955 | if (can_open_cached(state, fmode, open_mode)) { |
| 956 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 957 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 958 | goto out_return_state; |
| 959 | } |
| 960 | spin_unlock(&state->owner->so_lock); |
| 961 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 962 | rcu_read_lock(); |
| 963 | delegation = rcu_dereference(nfsi->delegation); |
| 964 | if (delegation == NULL || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 965 | !can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 966 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 967 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 968 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 969 | /* Save the delegation */ |
| 970 | memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); |
| 971 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 972 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 973 | if (ret != 0) |
| 974 | goto out; |
| 975 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 976 | |
| 977 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 978 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 979 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 980 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 981 | out: |
| 982 | return ERR_PTR(ret); |
| 983 | out_return_state: |
| 984 | atomic_inc(&state->count); |
| 985 | return state; |
| 986 | } |
| 987 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 988 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 989 | { |
| 990 | struct inode *inode; |
| 991 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 992 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 993 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 994 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 995 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 996 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 997 | goto out; |
| 998 | } |
| 999 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1000 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1001 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1002 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1003 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, &data->f_attr); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1004 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1005 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1006 | goto err; |
| 1007 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1008 | state = nfs4_get_open_state(inode, data->owner); |
| 1009 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1010 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1011 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1012 | int delegation_flags = 0; |
| 1013 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1014 | rcu_read_lock(); |
| 1015 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1016 | if (delegation) |
| 1017 | delegation_flags = delegation->flags; |
| 1018 | rcu_read_unlock(); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1019 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1020 | nfs_inode_set_delegation(state->inode, |
| 1021 | data->owner->so_cred, |
| 1022 | &data->o_res); |
| 1023 | else |
| 1024 | nfs_inode_reclaim_delegation(state->inode, |
| 1025 | data->owner->so_cred, |
| 1026 | &data->o_res); |
| 1027 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1028 | |
| 1029 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1030 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1031 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1032 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1033 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1034 | err_put_inode: |
| 1035 | iput(inode); |
| 1036 | err: |
| 1037 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1038 | } |
| 1039 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1040 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1041 | { |
| 1042 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1043 | struct nfs_open_context *ctx; |
| 1044 | |
| 1045 | spin_lock(&state->inode->i_lock); |
| 1046 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1047 | if (ctx->state != state) |
| 1048 | continue; |
| 1049 | get_nfs_open_context(ctx); |
| 1050 | spin_unlock(&state->inode->i_lock); |
| 1051 | return ctx; |
| 1052 | } |
| 1053 | spin_unlock(&state->inode->i_lock); |
| 1054 | return ERR_PTR(-ENOENT); |
| 1055 | } |
| 1056 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1057 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1058 | { |
| 1059 | struct nfs4_opendata *opendata; |
| 1060 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1061 | opendata = nfs4_opendata_alloc(&ctx->path, state->owner, 0, 0, NULL, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1062 | if (opendata == NULL) |
| 1063 | return ERR_PTR(-ENOMEM); |
| 1064 | opendata->state = state; |
| 1065 | atomic_inc(&state->count); |
| 1066 | return opendata; |
| 1067 | } |
| 1068 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1069 | 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] | 1070 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1071 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1072 | int ret; |
| 1073 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1074 | opendata->o_arg.open_flags = 0; |
| 1075 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1076 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1077 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1078 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1079 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1080 | if (ret != 0) |
| 1081 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1082 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1083 | if (IS_ERR(newstate)) |
| 1084 | return PTR_ERR(newstate); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1085 | nfs4_close_state(&opendata->path, newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1086 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1087 | return 0; |
| 1088 | } |
| 1089 | |
| 1090 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1091 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1092 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1093 | int ret; |
| 1094 | |
| 1095 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1096 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1097 | smp_rmb(); |
| 1098 | if (state->n_rdwr != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1099 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1100 | if (ret != 0) |
| 1101 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1102 | if (newstate != state) |
| 1103 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1104 | } |
| 1105 | if (state->n_wronly != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1106 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1107 | if (ret != 0) |
| 1108 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1109 | if (newstate != state) |
| 1110 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1111 | } |
| 1112 | if (state->n_rdonly != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1113 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1114 | if (ret != 0) |
| 1115 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1116 | if (newstate != state) |
| 1117 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1118 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1119 | /* |
| 1120 | * We may have performed cached opens for all three recoveries. |
| 1121 | * Check if we need to update the current stateid. |
| 1122 | */ |
| 1123 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
| 1124 | memcmp(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)) != 0) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1125 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1126 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1127 | memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1128 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1129 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1130 | return 0; |
| 1131 | } |
| 1132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | /* |
| 1134 | * OPEN_RECLAIM: |
| 1135 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1137 | 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] | 1138 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1139 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1140 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1141 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | int status; |
| 1143 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1144 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1145 | if (IS_ERR(opendata)) |
| 1146 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1147 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1148 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1149 | rcu_read_lock(); |
| 1150 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1151 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1152 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1153 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1154 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1155 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1156 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | return status; |
| 1158 | } |
| 1159 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1160 | 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] | 1161 | { |
| 1162 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1163 | struct nfs4_exception exception = { }; |
| 1164 | int err; |
| 1165 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1166 | err = _nfs4_do_open_reclaim(ctx, state); |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 1167 | if (err != -NFS4ERR_DELAY && err != -EKEYEXPIRED) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1168 | break; |
| 1169 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | } while (exception.retry); |
| 1171 | return err; |
| 1172 | } |
| 1173 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1174 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1175 | { |
| 1176 | struct nfs_open_context *ctx; |
| 1177 | int ret; |
| 1178 | |
| 1179 | ctx = nfs4_state_find_open_context(state); |
| 1180 | if (IS_ERR(ctx)) |
| 1181 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1182 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1183 | put_nfs_open_context(ctx); |
| 1184 | return ret; |
| 1185 | } |
| 1186 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1187 | static int _nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1189 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1190 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1192 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1193 | if (IS_ERR(opendata)) |
| 1194 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1195 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1196 | memcpy(opendata->o_arg.u.delegation.data, stateid->data, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1197 | sizeof(opendata->o_arg.u.delegation.data)); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1198 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1199 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1200 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | } |
| 1202 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1203 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | { |
| 1205 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1206 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | int err; |
| 1208 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1209 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | switch (err) { |
| 1211 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1212 | case -ENOENT: |
| 1213 | case -ESTALE: |
| 1214 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1215 | case -NFS4ERR_BADSESSION: |
| 1216 | case -NFS4ERR_BADSLOT: |
| 1217 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1218 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1219 | case -NFS4ERR_DEADSESSION: |
| 1220 | nfs4_schedule_state_recovery( |
| 1221 | server->nfs_client); |
| 1222 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | case -NFS4ERR_STALE_CLIENTID: |
| 1224 | case -NFS4ERR_STALE_STATEID: |
| 1225 | case -NFS4ERR_EXPIRED: |
| 1226 | /* Don't recall a delegation if it was lost */ |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1227 | nfs4_schedule_state_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1228 | goto out; |
| 1229 | case -ERESTARTSYS: |
| 1230 | /* |
| 1231 | * The show must go on: exit, but mark the |
| 1232 | * stateid as needing recovery. |
| 1233 | */ |
| 1234 | case -NFS4ERR_ADMIN_REVOKED: |
| 1235 | case -NFS4ERR_BAD_STATEID: |
| 1236 | nfs4_state_mark_reclaim_nograce(server->nfs_client, state); |
| 1237 | case -ENOMEM: |
| 1238 | err = 0; |
| 1239 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | } |
| 1241 | err = nfs4_handle_exception(server, err, &exception); |
| 1242 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1243 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | return err; |
| 1245 | } |
| 1246 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1247 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1248 | { |
| 1249 | struct nfs4_opendata *data = calldata; |
| 1250 | |
| 1251 | data->rpc_status = task->tk_status; |
| 1252 | if (RPC_ASSASSINATED(task)) |
| 1253 | return; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1254 | if (data->rpc_status == 0) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1255 | memcpy(data->o_res.stateid.data, data->c_res.stateid.data, |
| 1256 | sizeof(data->o_res.stateid.data)); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1257 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1258 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1259 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1260 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | static void nfs4_open_confirm_release(void *calldata) |
| 1264 | { |
| 1265 | struct nfs4_opendata *data = calldata; |
| 1266 | struct nfs4_state *state = NULL; |
| 1267 | |
| 1268 | /* If this request hasn't been cancelled, do nothing */ |
| 1269 | if (data->cancelled == 0) |
| 1270 | goto out_free; |
| 1271 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1272 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1273 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1274 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1275 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1276 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1277 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1278 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1282 | .rpc_call_done = nfs4_open_confirm_done, |
| 1283 | .rpc_release = nfs4_open_confirm_release, |
| 1284 | }; |
| 1285 | |
| 1286 | /* |
| 1287 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1288 | */ |
| 1289 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1290 | { |
| 1291 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1292 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1293 | struct rpc_message msg = { |
| 1294 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1295 | .rpc_argp = &data->c_arg, |
| 1296 | .rpc_resp = &data->c_res, |
| 1297 | .rpc_cred = data->owner->so_cred, |
| 1298 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1299 | struct rpc_task_setup task_setup_data = { |
| 1300 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1301 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1302 | .callback_ops = &nfs4_open_confirm_ops, |
| 1303 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1304 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1305 | .flags = RPC_TASK_ASYNC, |
| 1306 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | int status; |
| 1308 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1309 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1310 | data->rpc_done = 0; |
| 1311 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1312 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1313 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1314 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1315 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1316 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1317 | if (status != 0) { |
| 1318 | data->cancelled = 1; |
| 1319 | smp_wmb(); |
| 1320 | } else |
| 1321 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1322 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | return status; |
| 1324 | } |
| 1325 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1326 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1328 | struct nfs4_opendata *data = calldata; |
| 1329 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1330 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1331 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1332 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1333 | /* |
| 1334 | * Check if we still need to send an OPEN call, or if we can use |
| 1335 | * a delegation instead. |
| 1336 | */ |
| 1337 | if (data->state != NULL) { |
| 1338 | struct nfs_delegation *delegation; |
| 1339 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1340 | 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] | 1341 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1342 | rcu_read_lock(); |
| 1343 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
| 1344 | if (delegation != NULL && |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1345 | test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1346 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1347 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1348 | } |
| 1349 | rcu_read_unlock(); |
| 1350 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1351 | /* Update sequence id. */ |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1352 | data->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1353 | data->o_arg.clientid = sp->so_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1354 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1355 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1356 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1357 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1358 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1359 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1360 | &data->o_arg.seq_args, |
| 1361 | &data->o_res.seq_res, 1, task)) |
| 1362 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1363 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1364 | return; |
| 1365 | out_no_action: |
| 1366 | task->tk_action = NULL; |
| 1367 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1368 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1370 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1371 | { |
| 1372 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1373 | nfs4_open_prepare(task, calldata); |
| 1374 | } |
| 1375 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1376 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1377 | { |
| 1378 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1380 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1381 | |
Trond Myklebust | d61e612 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 1382 | nfs4_sequence_done(data->o_arg.server, &data->o_res.seq_res, |
| 1383 | task->tk_status); |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1384 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1385 | if (RPC_ASSASSINATED(task)) |
| 1386 | return; |
| 1387 | if (task->tk_status == 0) { |
| 1388 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1389 | case S_IFREG: |
| 1390 | break; |
| 1391 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1392 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1393 | break; |
| 1394 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1395 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1396 | break; |
| 1397 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1398 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1399 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1400 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1401 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1402 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1403 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1404 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1405 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1406 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1407 | static void nfs4_open_release(void *calldata) |
| 1408 | { |
| 1409 | struct nfs4_opendata *data = calldata; |
| 1410 | struct nfs4_state *state = NULL; |
| 1411 | |
| 1412 | /* If this request hasn't been cancelled, do nothing */ |
| 1413 | if (data->cancelled == 0) |
| 1414 | goto out_free; |
| 1415 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1416 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1417 | goto out_free; |
| 1418 | /* In case we need an open_confirm, no cleanup! */ |
| 1419 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1420 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1421 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1422 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1423 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1424 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1425 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1429 | .rpc_call_prepare = nfs4_open_prepare, |
| 1430 | .rpc_call_done = nfs4_open_done, |
| 1431 | .rpc_release = nfs4_open_release, |
| 1432 | }; |
| 1433 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1434 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1435 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1436 | .rpc_call_done = nfs4_open_done, |
| 1437 | .rpc_release = nfs4_open_release, |
| 1438 | }; |
| 1439 | |
| 1440 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1441 | { |
| 1442 | struct inode *dir = data->dir->d_inode; |
| 1443 | struct nfs_server *server = NFS_SERVER(dir); |
| 1444 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1445 | struct nfs_openres *o_res = &data->o_res; |
| 1446 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1447 | struct rpc_message msg = { |
| 1448 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1449 | .rpc_argp = o_arg, |
| 1450 | .rpc_resp = o_res, |
| 1451 | .rpc_cred = data->owner->so_cred, |
| 1452 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1453 | struct rpc_task_setup task_setup_data = { |
| 1454 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1455 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1456 | .callback_ops = &nfs4_open_ops, |
| 1457 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1458 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1459 | .flags = RPC_TASK_ASYNC, |
| 1460 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1461 | int status; |
| 1462 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1463 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1464 | data->rpc_done = 0; |
| 1465 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1466 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1467 | if (isrecover) |
| 1468 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1469 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1470 | if (IS_ERR(task)) |
| 1471 | return PTR_ERR(task); |
| 1472 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1473 | if (status != 0) { |
| 1474 | data->cancelled = 1; |
| 1475 | smp_wmb(); |
| 1476 | } else |
| 1477 | status = data->rpc_status; |
| 1478 | rpc_put_task(task); |
| 1479 | |
| 1480 | return status; |
| 1481 | } |
| 1482 | |
| 1483 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1484 | { |
| 1485 | struct inode *dir = data->dir->d_inode; |
| 1486 | struct nfs_openres *o_res = &data->o_res; |
| 1487 | int status; |
| 1488 | |
| 1489 | status = nfs4_run_open_task(data, 1); |
| 1490 | if (status != 0 || !data->rpc_done) |
| 1491 | return status; |
| 1492 | |
| 1493 | nfs_refresh_inode(dir, o_res->dir_attr); |
| 1494 | |
| 1495 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1496 | status = _nfs4_proc_open_confirm(data); |
| 1497 | if (status != 0) |
| 1498 | return status; |
| 1499 | } |
| 1500 | |
| 1501 | return status; |
| 1502 | } |
| 1503 | |
| 1504 | /* |
| 1505 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1506 | */ |
| 1507 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1508 | { |
| 1509 | struct inode *dir = data->dir->d_inode; |
| 1510 | struct nfs_server *server = NFS_SERVER(dir); |
| 1511 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1512 | struct nfs_openres *o_res = &data->o_res; |
| 1513 | int status; |
| 1514 | |
| 1515 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1516 | if (status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1517 | return status; |
| 1518 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1519 | if (o_arg->open_flags & O_CREAT) { |
| 1520 | update_changeattr(dir, &o_res->cinfo); |
| 1521 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
| 1522 | } else |
| 1523 | nfs_refresh_inode(dir, o_res->dir_attr); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1524 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1525 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1527 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1529 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | } |
| 1531 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1532 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1533 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | } |
| 1535 | |
Trond Myklebust | 10afec9 | 2007-05-14 17:16:04 -0400 | [diff] [blame] | 1536 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1537 | { |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1538 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1539 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1540 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1541 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1542 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1543 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1544 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1545 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1546 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1547 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1548 | break; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1549 | nfs4_schedule_state_recovery(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1550 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1551 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1552 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1553 | } |
| 1554 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | /* |
| 1556 | * OPEN_EXPIRED: |
| 1557 | * reclaim state on the server after a network partition. |
| 1558 | * Assumes caller holds the appropriate lock |
| 1559 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1560 | 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] | 1561 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1562 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1563 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1565 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1566 | if (IS_ERR(opendata)) |
| 1567 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1568 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1569 | if (ret == -ESTALE) |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1570 | d_drop(ctx->path.dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1571 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1572 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | } |
| 1574 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1575 | 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] | 1576 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1577 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1578 | struct nfs4_exception exception = { }; |
| 1579 | int err; |
| 1580 | |
| 1581 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1582 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1583 | switch (err) { |
| 1584 | default: |
| 1585 | goto out; |
| 1586 | case -NFS4ERR_GRACE: |
| 1587 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 1588 | case -EKEYEXPIRED: |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1589 | nfs4_handle_exception(server, err, &exception); |
| 1590 | err = 0; |
| 1591 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1592 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1593 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1594 | return err; |
| 1595 | } |
| 1596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1598 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1600 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1602 | ctx = nfs4_state_find_open_context(state); |
| 1603 | if (IS_ERR(ctx)) |
| 1604 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1605 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1606 | put_nfs_open_context(ctx); |
| 1607 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | } |
| 1609 | |
| 1610 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1611 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1612 | * fields corresponding to attributes that were used to store the verifier. |
| 1613 | * Make sure we clobber those fields in the later setattr call |
| 1614 | */ |
| 1615 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1616 | { |
| 1617 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1618 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1619 | sattr->ia_valid |= ATTR_ATIME; |
| 1620 | |
| 1621 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1622 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1623 | sattr->ia_valid |= ATTR_MTIME; |
| 1624 | } |
| 1625 | |
| 1626 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1627 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1629 | static int _nfs4_do_open(struct inode *dir, struct path *path, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred, struct nfs4_state **res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | { |
| 1631 | struct nfs4_state_owner *sp; |
| 1632 | struct nfs4_state *state = NULL; |
| 1633 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1634 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1635 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | |
| 1637 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | status = -ENOMEM; |
| 1639 | if (!(sp = nfs4_get_state_owner(server, cred))) { |
| 1640 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1641 | goto out_err; |
| 1642 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1643 | status = nfs4_recover_expired_lease(server); |
| 1644 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1645 | goto err_put_state_owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1646 | if (path->dentry->d_inode != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1647 | nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1648 | status = -ENOMEM; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1649 | opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1650 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1651 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1653 | if (path->dentry->d_inode != NULL) |
| 1654 | opendata->state = nfs4_get_open_state(path->dentry->d_inode, sp); |
| 1655 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1656 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1658 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1660 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1661 | status = PTR_ERR(state); |
| 1662 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1663 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1664 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1665 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1666 | |
| 1667 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1668 | nfs4_exclusive_attrset(opendata, sattr); |
| 1669 | |
| 1670 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1671 | status = nfs4_do_setattr(state->inode, cred, |
| 1672 | opendata->o_res.f_attr, sattr, |
| 1673 | state); |
| 1674 | if (status == 0) |
| 1675 | nfs_setattr_update_inode(state->inode, sattr); |
| 1676 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1677 | } |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1678 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | *res = state; |
| 1681 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1682 | err_opendata_put: |
| 1683 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1684 | err_put_state_owner: |
| 1685 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1687 | *res = NULL; |
| 1688 | return status; |
| 1689 | } |
| 1690 | |
| 1691 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1692 | static struct nfs4_state *nfs4_do_open(struct inode *dir, struct path *path, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | { |
| 1694 | struct nfs4_exception exception = { }; |
| 1695 | struct nfs4_state *res; |
| 1696 | int status; |
| 1697 | |
| 1698 | do { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1699 | status = _nfs4_do_open(dir, path, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | if (status == 0) |
| 1701 | break; |
| 1702 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1703 | * book-keeping w.r.t. state-changing operations |
| 1704 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1705 | * It is actually a sign of a bug on the client or on the server. |
| 1706 | * |
| 1707 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1708 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | * have unhashed the old state_owner for us, and that we can |
| 1710 | * therefore safely retry using a new one. We should still warn |
| 1711 | * the user though... |
| 1712 | */ |
| 1713 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1714 | printk(KERN_WARNING "NFS: v4 server %s " |
| 1715 | " returned a bad sequence-id error!\n", |
| 1716 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | exception.retry = 1; |
| 1718 | continue; |
| 1719 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1720 | /* |
| 1721 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1722 | * state before it received the OPEN_CONFIRM. |
| 1723 | * Recover by retrying the request as per the discussion |
| 1724 | * on Page 181 of RFC3530. |
| 1725 | */ |
| 1726 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1727 | exception.retry = 1; |
| 1728 | continue; |
| 1729 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1730 | if (status == -EAGAIN) { |
| 1731 | /* We must have found a delegation */ |
| 1732 | exception.retry = 1; |
| 1733 | continue; |
| 1734 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1736 | status, &exception)); |
| 1737 | } while (exception.retry); |
| 1738 | return res; |
| 1739 | } |
| 1740 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1741 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1742 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1743 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1745 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1747 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | .iap = sattr, |
| 1749 | .server = server, |
| 1750 | .bitmask = server->attr_bitmask, |
| 1751 | }; |
| 1752 | struct nfs_setattrres res = { |
| 1753 | .fattr = fattr, |
| 1754 | .server = server, |
| 1755 | }; |
| 1756 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1757 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1758 | .rpc_argp = &arg, |
| 1759 | .rpc_resp = &res, |
| 1760 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1762 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1763 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1764 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1765 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1767 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { |
| 1768 | /* Use that stateid */ |
| 1769 | } else if (state != NULL) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1770 | nfs4_copy_stateid(&arg.stateid, state, current->files); |
| 1771 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); |
| 1773 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1774 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1775 | if (status == 0 && state != NULL) |
| 1776 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1777 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | } |
| 1779 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1780 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1781 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1782 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1784 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | struct nfs4_exception exception = { }; |
| 1786 | int err; |
| 1787 | do { |
| 1788 | err = nfs4_handle_exception(server, |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1789 | _nfs4_do_setattr(inode, cred, fattr, sattr, state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | &exception); |
| 1791 | } while (exception.retry); |
| 1792 | return err; |
| 1793 | } |
| 1794 | |
| 1795 | struct nfs4_closedata { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1796 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | struct inode *inode; |
| 1798 | struct nfs4_state *state; |
| 1799 | struct nfs_closeargs arg; |
| 1800 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1801 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1802 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | }; |
| 1804 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1805 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1806 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1807 | struct nfs4_closedata *calldata = data; |
| 1808 | struct nfs4_state_owner *sp = calldata->state->owner; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1809 | |
| 1810 | nfs4_put_open_state(calldata->state); |
| 1811 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1812 | nfs4_put_state_owner(sp); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 1813 | path_put(&calldata->path); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1814 | kfree(calldata); |
| 1815 | } |
| 1816 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1817 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 1818 | fmode_t fmode) |
| 1819 | { |
| 1820 | spin_lock(&state->owner->so_lock); |
| 1821 | if (!(fmode & FMODE_READ)) |
| 1822 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1823 | if (!(fmode & FMODE_WRITE)) |
| 1824 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1825 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1826 | spin_unlock(&state->owner->so_lock); |
| 1827 | } |
| 1828 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1829 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1831 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 1834 | |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 1835 | nfs4_sequence_done(server, &calldata->res.seq_res, task->tk_status); |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1836 | if (RPC_ASSASSINATED(task)) |
| 1837 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | /* hmm. we are done with the inode, and in the process of freeing |
| 1839 | * the state_owner. we keep this around to process errors |
| 1840 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | switch (task->tk_status) { |
| 1842 | case 0: |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1843 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1844 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1845 | nfs4_close_clear_stateid_flags(state, |
| 1846 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | break; |
| 1848 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1849 | case -NFS4ERR_OLD_STATEID: |
| 1850 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1852 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1853 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1855 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 1856 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1858 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1859 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | } |
| 1861 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1862 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1864 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1865 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1866 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1867 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1868 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1869 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1870 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1871 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 1872 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1873 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1874 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1875 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1876 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1877 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1878 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1879 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1880 | } |
| 1881 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1882 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1883 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1884 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1885 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1886 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1887 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1888 | |
| 1889 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1890 | /* Note: exit _without_ calling nfs4_close_done */ |
| 1891 | task->tk_action = NULL; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1892 | return; |
| 1893 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1894 | |
| 1895 | if (calldata->arg.fmode == 0) |
| 1896 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
| 1897 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1898 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1899 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1900 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 1901 | &calldata->arg.seq_args, &calldata->res.seq_res, |
| 1902 | 1, task)) |
| 1903 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1904 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | } |
| 1906 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1907 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1908 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1909 | .rpc_call_done = nfs4_close_done, |
| 1910 | .rpc_release = nfs4_free_closedata, |
| 1911 | }; |
| 1912 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | /* |
| 1914 | * It is possible for data to be read/written from a mem-mapped file |
| 1915 | * after the sys_close call (which hits the vfs layer as a flush). |
| 1916 | * This means that we can't safely call nfsv4 close on a file until |
| 1917 | * the inode is cleared. This in turn means that we are not good |
| 1918 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 1919 | * share state even when we are done with one of the three share |
| 1920 | * stateid's in the inode. |
| 1921 | * |
| 1922 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 1923 | */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1924 | int nfs4_do_close(struct path *path, struct nfs4_state *state, gfp_t gfp_mask, int wait) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1926 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1928 | struct nfs4_state_owner *sp = state->owner; |
| 1929 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1930 | struct rpc_message msg = { |
| 1931 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 1932 | .rpc_cred = state->owner->so_cred, |
| 1933 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1934 | struct rpc_task_setup task_setup_data = { |
| 1935 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1936 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1937 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1938 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1939 | .flags = RPC_TASK_ASYNC, |
| 1940 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1941 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1943 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1945 | goto out; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1946 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1948 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1949 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1951 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1952 | if (calldata->arg.seqid == NULL) |
| 1953 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1954 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 1955 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1956 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 1957 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1958 | calldata->res.server = server; |
Andy Adamson | 5f7dbd5 | 2009-04-01 09:22:05 -0400 | [diff] [blame] | 1959 | calldata->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 1960 | path_get(path); |
| 1961 | calldata->path = *path; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1962 | |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1963 | msg.rpc_argp = &calldata->arg, |
| 1964 | msg.rpc_resp = &calldata->res, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1965 | task_setup_data.callback_data = calldata; |
| 1966 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1967 | if (IS_ERR(task)) |
| 1968 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 1969 | status = 0; |
| 1970 | if (wait) |
| 1971 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1972 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 1973 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1974 | out_free_calldata: |
| 1975 | kfree(calldata); |
| 1976 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1977 | nfs4_put_open_state(state); |
| 1978 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1979 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | } |
| 1981 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1982 | static int nfs4_intent_set_file(struct nameidata *nd, struct path *path, struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1983 | { |
| 1984 | struct file *filp; |
Trond Myklebust | 1b45c46 | 2007-07-03 13:04:56 -0400 | [diff] [blame] | 1985 | int ret; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1986 | |
Trond Myklebust | 1b45c46 | 2007-07-03 13:04:56 -0400 | [diff] [blame] | 1987 | /* If the open_intent is for execute, we have an extra check to make */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1988 | if (fmode & FMODE_EXEC) { |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1989 | ret = nfs_may_open(state->inode, |
Trond Myklebust | 1b45c46 | 2007-07-03 13:04:56 -0400 | [diff] [blame] | 1990 | state->owner->so_cred, |
| 1991 | nd->intent.open.flags); |
| 1992 | if (ret < 0) |
| 1993 | goto out_close; |
| 1994 | } |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1995 | filp = lookup_instantiate_filp(nd, path->dentry, NULL); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1996 | if (!IS_ERR(filp)) { |
| 1997 | struct nfs_open_context *ctx; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 1998 | ctx = nfs_file_open_context(filp); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1999 | ctx->state = state; |
Trond Myklebust | 95cf959 | 2006-04-18 13:14:06 -0400 | [diff] [blame] | 2000 | return 0; |
| 2001 | } |
Trond Myklebust | 1b45c46 | 2007-07-03 13:04:56 -0400 | [diff] [blame] | 2002 | ret = PTR_ERR(filp); |
| 2003 | out_close: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2004 | nfs4_close_sync(path, state, fmode & (FMODE_READ|FMODE_WRITE)); |
Trond Myklebust | 1b45c46 | 2007-07-03 13:04:56 -0400 | [diff] [blame] | 2005 | return ret; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | struct dentry * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd) |
| 2010 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2011 | struct path path = { |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 2012 | .mnt = nd->path.mnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2013 | .dentry = dentry, |
| 2014 | }; |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 2015 | struct dentry *parent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | struct iattr attr; |
| 2017 | struct rpc_cred *cred; |
| 2018 | struct nfs4_state *state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2019 | struct dentry *res; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2020 | fmode_t fmode = nd->intent.open.flags & (FMODE_READ | FMODE_WRITE | FMODE_EXEC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | |
| 2022 | if (nd->flags & LOOKUP_CREATE) { |
| 2023 | attr.ia_mode = nd->intent.open.create_mode; |
| 2024 | attr.ia_valid = ATTR_MODE; |
| 2025 | if (!IS_POSIXACL(dir)) |
Al Viro | ce3b0f8 | 2009-03-29 19:08:22 -0400 | [diff] [blame] | 2026 | attr.ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | } else { |
| 2028 | attr.ia_valid = 0; |
| 2029 | BUG_ON(nd->intent.open.flags & O_CREAT); |
| 2030 | } |
| 2031 | |
Trond Myklebust | 98a8e32 | 2008-03-12 12:25:28 -0400 | [diff] [blame] | 2032 | cred = rpc_lookup_cred(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | if (IS_ERR(cred)) |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2034 | return (struct dentry *)cred; |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2035 | parent = dentry->d_parent; |
| 2036 | /* Protect against concurrent sillydeletes */ |
| 2037 | nfs_block_sillyrename(parent); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2038 | state = nfs4_do_open(dir, &path, fmode, nd->intent.open.flags, &attr, cred); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | put_rpccred(cred); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2040 | if (IS_ERR(state)) { |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2041 | if (PTR_ERR(state) == -ENOENT) { |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2042 | d_add(dentry, NULL); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2043 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
| 2044 | } |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2045 | nfs_unblock_sillyrename(parent); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2046 | return (struct dentry *)state; |
| 2047 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2048 | res = d_add_unique(dentry, igrab(state->inode)); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2049 | if (res != NULL) |
Trond Myklebust | deee936 | 2007-08-27 11:33:00 -0400 | [diff] [blame] | 2050 | path.dentry = res; |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2051 | nfs_set_verifier(path.dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2052 | nfs_unblock_sillyrename(parent); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2053 | nfs4_intent_set_file(nd, &path, state, fmode); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2054 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | int |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2058 | nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags, struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2060 | struct path path = { |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 2061 | .mnt = nd->path.mnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2062 | .dentry = dentry, |
| 2063 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | struct rpc_cred *cred; |
| 2065 | struct nfs4_state *state; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2066 | fmode_t fmode = openflags & (FMODE_READ | FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | |
Trond Myklebust | 98a8e32 | 2008-03-12 12:25:28 -0400 | [diff] [blame] | 2068 | cred = rpc_lookup_cred(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | if (IS_ERR(cred)) |
| 2070 | return PTR_ERR(cred); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2071 | state = nfs4_do_open(dir, &path, fmode, openflags, NULL, cred); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | put_rpccred(cred); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2073 | if (IS_ERR(state)) { |
| 2074 | switch (PTR_ERR(state)) { |
| 2075 | case -EPERM: |
| 2076 | case -EACCES: |
| 2077 | case -EDQUOT: |
| 2078 | case -ENOSPC: |
| 2079 | case -EROFS: |
Al Viro | 04287f9 | 2010-04-08 00:06:07 +0100 | [diff] [blame] | 2080 | return PTR_ERR(state); |
Chuck Lever | b87c0ad | 2006-10-19 23:28:42 -0700 | [diff] [blame] | 2081 | default: |
| 2082 | goto out_drop; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2083 | } |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2084 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2085 | if (state->inode == dentry->d_inode) { |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2086 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2087 | nfs4_intent_set_file(nd, &path, state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | return 1; |
| 2089 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2090 | nfs4_close_sync(&path, state, fmode); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2091 | out_drop: |
| 2092 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | return 0; |
| 2094 | } |
| 2095 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2096 | 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] | 2097 | { |
| 2098 | if (ctx->state == NULL) |
| 2099 | return; |
| 2100 | if (is_sync) |
| 2101 | nfs4_close_sync(&ctx->path, ctx->state, ctx->mode); |
| 2102 | else |
| 2103 | nfs4_close_state(&ctx->path, ctx->state, ctx->mode); |
| 2104 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | |
| 2106 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2107 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2108 | struct nfs4_server_caps_arg args = { |
| 2109 | .fhandle = fhandle, |
| 2110 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | struct nfs4_server_caps_res res = {}; |
| 2112 | struct rpc_message msg = { |
| 2113 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2114 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | .rpc_resp = &res, |
| 2116 | }; |
| 2117 | int status; |
| 2118 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2119 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | if (status == 0) { |
| 2121 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2122 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2123 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2124 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2125 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2126 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2128 | server->caps |= NFS_CAP_ACLS; |
| 2129 | if (res.has_links != 0) |
| 2130 | server->caps |= NFS_CAP_HARDLINKS; |
| 2131 | if (res.has_symlinks != 0) |
| 2132 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2133 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2134 | server->caps |= NFS_CAP_FILEID; |
| 2135 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2136 | server->caps |= NFS_CAP_MODE; |
| 2137 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2138 | server->caps |= NFS_CAP_NLINK; |
| 2139 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2140 | server->caps |= NFS_CAP_OWNER; |
| 2141 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2142 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2143 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2144 | server->caps |= NFS_CAP_ATIME; |
| 2145 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2146 | server->caps |= NFS_CAP_CTIME; |
| 2147 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2148 | server->caps |= NFS_CAP_MTIME; |
| 2149 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2150 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2151 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2152 | 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] | 2153 | server->acl_bitmask = res.acl_bitmask; |
| 2154 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | return status; |
| 2157 | } |
| 2158 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2159 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | { |
| 2161 | struct nfs4_exception exception = { }; |
| 2162 | int err; |
| 2163 | do { |
| 2164 | err = nfs4_handle_exception(server, |
| 2165 | _nfs4_server_capabilities(server, fhandle), |
| 2166 | &exception); |
| 2167 | } while (exception.retry); |
| 2168 | return err; |
| 2169 | } |
| 2170 | |
| 2171 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2172 | struct nfs_fsinfo *info) |
| 2173 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | struct nfs4_lookup_root_arg args = { |
| 2175 | .bitmask = nfs4_fattr_bitmap, |
| 2176 | }; |
| 2177 | struct nfs4_lookup_res res = { |
| 2178 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2179 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | .fh = fhandle, |
| 2181 | }; |
| 2182 | struct rpc_message msg = { |
| 2183 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2184 | .rpc_argp = &args, |
| 2185 | .rpc_resp = &res, |
| 2186 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2187 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2188 | nfs_fattr_init(info->fattr); |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 2189 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | } |
| 2191 | |
| 2192 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2193 | struct nfs_fsinfo *info) |
| 2194 | { |
| 2195 | struct nfs4_exception exception = { }; |
| 2196 | int err; |
| 2197 | do { |
| 2198 | err = nfs4_handle_exception(server, |
| 2199 | _nfs4_lookup_root(server, fhandle, info), |
| 2200 | &exception); |
| 2201 | } while (exception.retry); |
| 2202 | return err; |
| 2203 | } |
| 2204 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2205 | /* |
| 2206 | * get the file handle for the "/" directory on the server |
| 2207 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2208 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2209 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | int status; |
| 2212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2213 | status = nfs4_lookup_root(server, fhandle, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | if (status == 0) |
| 2215 | status = nfs4_server_capabilities(server, fhandle); |
| 2216 | if (status == 0) |
| 2217 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2218 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | } |
| 2220 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2221 | /* |
| 2222 | * Get locations and (maybe) other attributes of a referral. |
| 2223 | * Note that we'll actually follow the referral later when |
| 2224 | * we detect fsid mismatch in inode revalidation |
| 2225 | */ |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2226 | static int nfs4_get_referral(struct inode *dir, const struct qstr *name, struct nfs_fattr *fattr, struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2227 | { |
| 2228 | int status = -ENOMEM; |
| 2229 | struct page *page = NULL; |
| 2230 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2231 | |
| 2232 | page = alloc_page(GFP_KERNEL); |
| 2233 | if (page == NULL) |
| 2234 | goto out; |
| 2235 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2236 | if (locations == NULL) |
| 2237 | goto out; |
| 2238 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 2239 | status = nfs4_proc_fs_locations(dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2240 | if (status != 0) |
| 2241 | goto out; |
| 2242 | /* Make sure server returned a different fsid for the referral */ |
| 2243 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2244 | dprintk("%s: server did not return a different fsid for a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2245 | status = -EIO; |
| 2246 | goto out; |
| 2247 | } |
| 2248 | |
| 2249 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
| 2250 | fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL; |
| 2251 | if (!fattr->mode) |
| 2252 | fattr->mode = S_IFDIR; |
| 2253 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2254 | out: |
| 2255 | if (page) |
| 2256 | __free_page(page); |
| 2257 | if (locations) |
| 2258 | kfree(locations); |
| 2259 | return status; |
| 2260 | } |
| 2261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2262 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2263 | { |
| 2264 | struct nfs4_getattr_arg args = { |
| 2265 | .fh = fhandle, |
| 2266 | .bitmask = server->attr_bitmask, |
| 2267 | }; |
| 2268 | struct nfs4_getattr_res res = { |
| 2269 | .fattr = fattr, |
| 2270 | .server = server, |
| 2271 | }; |
| 2272 | struct rpc_message msg = { |
| 2273 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2274 | .rpc_argp = &args, |
| 2275 | .rpc_resp = &res, |
| 2276 | }; |
| 2277 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2278 | nfs_fattr_init(fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2279 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | } |
| 2281 | |
| 2282 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2283 | { |
| 2284 | struct nfs4_exception exception = { }; |
| 2285 | int err; |
| 2286 | do { |
| 2287 | err = nfs4_handle_exception(server, |
| 2288 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2289 | &exception); |
| 2290 | } while (exception.retry); |
| 2291 | return err; |
| 2292 | } |
| 2293 | |
| 2294 | /* |
| 2295 | * The file is not closed if it is opened due to the a request to change |
| 2296 | * the size of the file. The open call will not be needed once the |
| 2297 | * VFS layer lookup-intents are implemented. |
| 2298 | * |
| 2299 | * Close is called when the inode is destroyed. |
| 2300 | * If we haven't opened the file for O_WRONLY, we |
| 2301 | * need to in the size_change case to obtain a stateid. |
| 2302 | * |
| 2303 | * Got race? |
| 2304 | * Because OPEN is always done by name in nfsv4, it is |
| 2305 | * possible that we opened a different file by the same |
| 2306 | * name. We can recognize this race condition, but we |
| 2307 | * can't do anything about it besides returning an error. |
| 2308 | * |
| 2309 | * This will be fixed with VFS changes (lookup-intent). |
| 2310 | */ |
| 2311 | static int |
| 2312 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2313 | struct iattr *sattr) |
| 2314 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2315 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2316 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2317 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | int status; |
| 2319 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2320 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2321 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2322 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2323 | if (sattr->ia_valid & ATTR_FILE) { |
| 2324 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2325 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2326 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2327 | if (ctx) { |
| 2328 | cred = ctx->cred; |
| 2329 | state = ctx->state; |
| 2330 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2334 | if (status == 0) |
| 2335 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | return status; |
| 2337 | } |
| 2338 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2339 | static int _nfs4_proc_lookupfh(struct nfs_server *server, const struct nfs_fh *dirfh, |
| 2340 | const struct qstr *name, struct nfs_fh *fhandle, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2341 | struct nfs_fattr *fattr) |
| 2342 | { |
| 2343 | int status; |
| 2344 | struct nfs4_lookup_arg args = { |
| 2345 | .bitmask = server->attr_bitmask, |
| 2346 | .dir_fh = dirfh, |
| 2347 | .name = name, |
| 2348 | }; |
| 2349 | struct nfs4_lookup_res res = { |
| 2350 | .server = server, |
| 2351 | .fattr = fattr, |
| 2352 | .fh = fhandle, |
| 2353 | }; |
| 2354 | struct rpc_message msg = { |
| 2355 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2356 | .rpc_argp = &args, |
| 2357 | .rpc_resp = &res, |
| 2358 | }; |
| 2359 | |
| 2360 | nfs_fattr_init(fattr); |
| 2361 | |
| 2362 | dprintk("NFS call lookupfh %s\n", name->name); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2363 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2364 | dprintk("NFS reply lookupfh: %d\n", status); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2365 | return status; |
| 2366 | } |
| 2367 | |
| 2368 | static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh, |
| 2369 | struct qstr *name, struct nfs_fh *fhandle, |
| 2370 | struct nfs_fattr *fattr) |
| 2371 | { |
| 2372 | struct nfs4_exception exception = { }; |
| 2373 | int err; |
| 2374 | do { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2375 | err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr); |
| 2376 | /* FIXME: !!!! */ |
| 2377 | if (err == -NFS4ERR_MOVED) { |
| 2378 | err = -EREMOTE; |
| 2379 | break; |
| 2380 | } |
| 2381 | err = nfs4_handle_exception(server, err, &exception); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2382 | } while (exception.retry); |
| 2383 | return err; |
| 2384 | } |
| 2385 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2386 | static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2388 | { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2389 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | |
| 2391 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2392 | status = _nfs4_proc_lookupfh(NFS_SERVER(dir), NFS_FH(dir), name, fhandle, fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2393 | if (status == -NFS4ERR_MOVED) |
| 2394 | status = nfs4_get_referral(dir, name, fattr, fhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | dprintk("NFS reply lookup: %d\n", status); |
| 2396 | return status; |
| 2397 | } |
| 2398 | |
| 2399 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2400 | { |
| 2401 | struct nfs4_exception exception = { }; |
| 2402 | int err; |
| 2403 | do { |
| 2404 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2405 | _nfs4_proc_lookup(dir, name, fhandle, fattr), |
| 2406 | &exception); |
| 2407 | } while (exception.retry); |
| 2408 | return err; |
| 2409 | } |
| 2410 | |
| 2411 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2412 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2413 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | struct nfs4_accessargs args = { |
| 2415 | .fh = NFS_FH(inode), |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2416 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2418 | struct nfs4_accessres res = { |
| 2419 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2420 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2421 | struct rpc_message msg = { |
| 2422 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2423 | .rpc_argp = &args, |
| 2424 | .rpc_resp = &res, |
| 2425 | .rpc_cred = entry->cred, |
| 2426 | }; |
| 2427 | int mode = entry->mask; |
| 2428 | int status; |
| 2429 | |
| 2430 | /* |
| 2431 | * Determine which access bits we want to ask for... |
| 2432 | */ |
| 2433 | if (mode & MAY_READ) |
| 2434 | args.access |= NFS4_ACCESS_READ; |
| 2435 | if (S_ISDIR(inode->i_mode)) { |
| 2436 | if (mode & MAY_WRITE) |
| 2437 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2438 | if (mode & MAY_EXEC) |
| 2439 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2440 | } else { |
| 2441 | if (mode & MAY_WRITE) |
| 2442 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2443 | if (mode & MAY_EXEC) |
| 2444 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2445 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2446 | |
| 2447 | res.fattr = nfs_alloc_fattr(); |
| 2448 | if (res.fattr == NULL) |
| 2449 | return -ENOMEM; |
| 2450 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2451 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2452 | if (!status) { |
| 2453 | entry->mask = 0; |
| 2454 | if (res.access & NFS4_ACCESS_READ) |
| 2455 | entry->mask |= MAY_READ; |
| 2456 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2457 | entry->mask |= MAY_WRITE; |
| 2458 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2459 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2460 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2462 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2463 | return status; |
| 2464 | } |
| 2465 | |
| 2466 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2467 | { |
| 2468 | struct nfs4_exception exception = { }; |
| 2469 | int err; |
| 2470 | do { |
| 2471 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2472 | _nfs4_proc_access(inode, entry), |
| 2473 | &exception); |
| 2474 | } while (exception.retry); |
| 2475 | return err; |
| 2476 | } |
| 2477 | |
| 2478 | /* |
| 2479 | * TODO: For the time being, we don't try to get any attributes |
| 2480 | * along with any of the zero-copy operations READ, READDIR, |
| 2481 | * READLINK, WRITE. |
| 2482 | * |
| 2483 | * In the case of the first three, we want to put the GETATTR |
| 2484 | * after the read-type operation -- this is because it is hard |
| 2485 | * to predict the length of a GETATTR response in v4, and thus |
| 2486 | * align the READ data correctly. This means that the GETATTR |
| 2487 | * may end up partially falling into the page cache, and we should |
| 2488 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2489 | * To do this efficiently, we need to know the total length |
| 2490 | * of data received, which doesn't seem to be available outside |
| 2491 | * of the RPC layer. |
| 2492 | * |
| 2493 | * In the case of WRITE, we also want to put the GETATTR after |
| 2494 | * the operation -- in this case because we want to make sure |
| 2495 | * we get the post-operation mtime and size. This means that |
| 2496 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2497 | * of it which would leave room in the 'tail' iovec. |
| 2498 | * |
| 2499 | * Both of these changes to the XDR layer would in fact be quite |
| 2500 | * minor, but I decided to leave them for a subsequent patch. |
| 2501 | */ |
| 2502 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2503 | unsigned int pgbase, unsigned int pglen) |
| 2504 | { |
| 2505 | struct nfs4_readlink args = { |
| 2506 | .fh = NFS_FH(inode), |
| 2507 | .pgbase = pgbase, |
| 2508 | .pglen = pglen, |
| 2509 | .pages = &page, |
| 2510 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2511 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2512 | struct rpc_message msg = { |
| 2513 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2514 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2515 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2516 | }; |
| 2517 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2518 | return nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2519 | } |
| 2520 | |
| 2521 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2522 | unsigned int pgbase, unsigned int pglen) |
| 2523 | { |
| 2524 | struct nfs4_exception exception = { }; |
| 2525 | int err; |
| 2526 | do { |
| 2527 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2528 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2529 | &exception); |
| 2530 | } while (exception.retry); |
| 2531 | return err; |
| 2532 | } |
| 2533 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | /* |
| 2535 | * Got race? |
| 2536 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2537 | * Until then, this create/open method is prone to inefficiency and race |
| 2538 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2539 | * placed on the wire. |
| 2540 | * |
| 2541 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2542 | * The file will be opened again in the subsequent VFS open call |
| 2543 | * (nfs4_proc_file_open). |
| 2544 | * |
| 2545 | * The open for read will just hang around to be used by any process that |
| 2546 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2547 | */ |
| 2548 | |
| 2549 | static int |
| 2550 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2551 | int flags, struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2552 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2553 | struct path path = { |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 2554 | .mnt = nd->path.mnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2555 | .dentry = dentry, |
| 2556 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2557 | struct nfs4_state *state; |
| 2558 | struct rpc_cred *cred; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2559 | fmode_t fmode = flags & (FMODE_READ | FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2560 | int status = 0; |
| 2561 | |
Trond Myklebust | 98a8e32 | 2008-03-12 12:25:28 -0400 | [diff] [blame] | 2562 | cred = rpc_lookup_cred(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2563 | if (IS_ERR(cred)) { |
| 2564 | status = PTR_ERR(cred); |
| 2565 | goto out; |
| 2566 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2567 | state = nfs4_do_open(dir, &path, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2568 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2569 | if (IS_ERR(state)) { |
| 2570 | status = PTR_ERR(state); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2571 | goto out_putcred; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2572 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2573 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2574 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2575 | if (status == 0 && (nd->flags & LOOKUP_OPEN) != 0) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2576 | status = nfs4_intent_set_file(nd, &path, state, fmode); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2577 | else |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2578 | nfs4_close_sync(&path, state, fmode); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2579 | out_putcred: |
| 2580 | put_rpccred(cred); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2581 | out: |
| 2582 | return status; |
| 2583 | } |
| 2584 | |
| 2585 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2586 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2587 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2588 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2589 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2590 | .name.len = name->len, |
| 2591 | .name.name = name->name, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2592 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2594 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2595 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2596 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2597 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2598 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2599 | .rpc_argp = &args, |
| 2600 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2601 | }; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2602 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2603 | |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2604 | res.dir_attr = nfs_alloc_fattr(); |
| 2605 | if (res.dir_attr == NULL) |
| 2606 | goto out; |
| 2607 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2608 | status = nfs4_call_sync(server, &msg, &args, &res, 1); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2609 | if (status == 0) { |
| 2610 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2611 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2612 | } |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2613 | nfs_free_fattr(res.dir_attr); |
| 2614 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2615 | return status; |
| 2616 | } |
| 2617 | |
| 2618 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2619 | { |
| 2620 | struct nfs4_exception exception = { }; |
| 2621 | int err; |
| 2622 | do { |
| 2623 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2624 | _nfs4_proc_remove(dir, name), |
| 2625 | &exception); |
| 2626 | } while (exception.retry); |
| 2627 | return err; |
| 2628 | } |
| 2629 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2630 | 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] | 2631 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2632 | struct nfs_server *server = NFS_SERVER(dir); |
| 2633 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2634 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2635 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2636 | args->bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2637 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2638 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 | } |
| 2640 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2641 | 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] | 2642 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2643 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2644 | |
Andy Adamson | 472cfbd | 2009-04-01 09:22:24 -0400 | [diff] [blame] | 2645 | nfs4_sequence_done(res->server, &res->seq_res, task->tk_status); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2646 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2647 | return 0; |
| 2648 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2649 | nfs_post_op_update_inode(dir, res->dir_attr); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2650 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2651 | } |
| 2652 | |
| 2653 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2654 | struct inode *new_dir, struct qstr *new_name) |
| 2655 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2656 | struct nfs_server *server = NFS_SERVER(old_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2657 | struct nfs4_rename_arg arg = { |
| 2658 | .old_dir = NFS_FH(old_dir), |
| 2659 | .new_dir = NFS_FH(new_dir), |
| 2660 | .old_name = old_name, |
| 2661 | .new_name = new_name, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2662 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | }; |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2664 | struct nfs4_rename_res res = { |
| 2665 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2666 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | struct rpc_message msg = { |
| 2668 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2669 | .rpc_argp = &arg, |
| 2670 | .rpc_resp = &res, |
| 2671 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2672 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2674 | res.old_fattr = nfs_alloc_fattr(); |
| 2675 | res.new_fattr = nfs_alloc_fattr(); |
| 2676 | if (res.old_fattr == NULL || res.new_fattr == NULL) |
| 2677 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2679 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | if (!status) { |
| 2681 | update_changeattr(old_dir, &res.old_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2682 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | update_changeattr(new_dir, &res.new_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2684 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | } |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2686 | out: |
| 2687 | nfs_free_fattr(res.new_fattr); |
| 2688 | nfs_free_fattr(res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 | return status; |
| 2690 | } |
| 2691 | |
| 2692 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2693 | struct inode *new_dir, struct qstr *new_name) |
| 2694 | { |
| 2695 | struct nfs4_exception exception = { }; |
| 2696 | int err; |
| 2697 | do { |
| 2698 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2699 | _nfs4_proc_rename(old_dir, old_name, |
| 2700 | new_dir, new_name), |
| 2701 | &exception); |
| 2702 | } while (exception.retry); |
| 2703 | return err; |
| 2704 | } |
| 2705 | |
| 2706 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2707 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2708 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2709 | struct nfs4_link_arg arg = { |
| 2710 | .fh = NFS_FH(inode), |
| 2711 | .dir_fh = NFS_FH(dir), |
| 2712 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2713 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2715 | struct nfs4_link_res res = { |
| 2716 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2717 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2718 | struct rpc_message msg = { |
| 2719 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2720 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2721 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2723 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2724 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2725 | res.fattr = nfs_alloc_fattr(); |
| 2726 | res.dir_attr = nfs_alloc_fattr(); |
| 2727 | if (res.fattr == NULL || res.dir_attr == NULL) |
| 2728 | goto out; |
| 2729 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2730 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2731 | if (!status) { |
| 2732 | update_changeattr(dir, &res.cinfo); |
| 2733 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2734 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2735 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2736 | out: |
| 2737 | nfs_free_fattr(res.dir_attr); |
| 2738 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | return status; |
| 2740 | } |
| 2741 | |
| 2742 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2743 | { |
| 2744 | struct nfs4_exception exception = { }; |
| 2745 | int err; |
| 2746 | do { |
| 2747 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2748 | _nfs4_proc_link(inode, dir, name), |
| 2749 | &exception); |
| 2750 | } while (exception.retry); |
| 2751 | return err; |
| 2752 | } |
| 2753 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2754 | struct nfs4_createdata { |
| 2755 | struct rpc_message msg; |
| 2756 | struct nfs4_create_arg arg; |
| 2757 | struct nfs4_create_res res; |
| 2758 | struct nfs_fh fh; |
| 2759 | struct nfs_fattr fattr; |
| 2760 | struct nfs_fattr dir_fattr; |
| 2761 | }; |
| 2762 | |
| 2763 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 2764 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 2765 | { |
| 2766 | struct nfs4_createdata *data; |
| 2767 | |
| 2768 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2769 | if (data != NULL) { |
| 2770 | struct nfs_server *server = NFS_SERVER(dir); |
| 2771 | |
| 2772 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 2773 | data->msg.rpc_argp = &data->arg; |
| 2774 | data->msg.rpc_resp = &data->res; |
| 2775 | data->arg.dir_fh = NFS_FH(dir); |
| 2776 | data->arg.server = server; |
| 2777 | data->arg.name = name; |
| 2778 | data->arg.attrs = sattr; |
| 2779 | data->arg.ftype = ftype; |
| 2780 | data->arg.bitmask = server->attr_bitmask; |
| 2781 | data->res.server = server; |
| 2782 | data->res.fh = &data->fh; |
| 2783 | data->res.fattr = &data->fattr; |
| 2784 | data->res.dir_fattr = &data->dir_fattr; |
| 2785 | nfs_fattr_init(data->res.fattr); |
| 2786 | nfs_fattr_init(data->res.dir_fattr); |
| 2787 | } |
| 2788 | return data; |
| 2789 | } |
| 2790 | |
| 2791 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 2792 | { |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2793 | int status = nfs4_call_sync(NFS_SERVER(dir), &data->msg, |
| 2794 | &data->arg, &data->res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2795 | if (status == 0) { |
| 2796 | update_changeattr(dir, &data->res.dir_cinfo); |
| 2797 | nfs_post_op_update_inode(dir, data->res.dir_fattr); |
| 2798 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 2799 | } |
| 2800 | return status; |
| 2801 | } |
| 2802 | |
| 2803 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 2804 | { |
| 2805 | kfree(data); |
| 2806 | } |
| 2807 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2808 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2809 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2811 | struct nfs4_createdata *data; |
| 2812 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2813 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2814 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2815 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2816 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2817 | status = -ENOMEM; |
| 2818 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 2819 | if (data == NULL) |
| 2820 | goto out; |
| 2821 | |
| 2822 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 2823 | data->arg.u.symlink.pages = &page; |
| 2824 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2825 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2826 | status = nfs4_do_create(dir, dentry, data); |
| 2827 | |
| 2828 | nfs4_free_createdata(data); |
| 2829 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | return status; |
| 2831 | } |
| 2832 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2833 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2834 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | { |
| 2836 | struct nfs4_exception exception = { }; |
| 2837 | int err; |
| 2838 | do { |
| 2839 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2840 | _nfs4_proc_symlink(dir, dentry, page, |
| 2841 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2842 | &exception); |
| 2843 | } while (exception.retry); |
| 2844 | return err; |
| 2845 | } |
| 2846 | |
| 2847 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2848 | struct iattr *sattr) |
| 2849 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2850 | struct nfs4_createdata *data; |
| 2851 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2853 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 2854 | if (data == NULL) |
| 2855 | goto out; |
| 2856 | |
| 2857 | status = nfs4_do_create(dir, dentry, data); |
| 2858 | |
| 2859 | nfs4_free_createdata(data); |
| 2860 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2861 | return status; |
| 2862 | } |
| 2863 | |
| 2864 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2865 | struct iattr *sattr) |
| 2866 | { |
| 2867 | struct nfs4_exception exception = { }; |
| 2868 | int err; |
| 2869 | do { |
| 2870 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2871 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 2872 | &exception); |
| 2873 | } while (exception.retry); |
| 2874 | return err; |
| 2875 | } |
| 2876 | |
| 2877 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
| 2878 | u64 cookie, struct page *page, unsigned int count, int plus) |
| 2879 | { |
| 2880 | struct inode *dir = dentry->d_inode; |
| 2881 | struct nfs4_readdir_arg args = { |
| 2882 | .fh = NFS_FH(dir), |
| 2883 | .pages = &page, |
| 2884 | .pgbase = 0, |
| 2885 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 2886 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | }; |
| 2888 | struct nfs4_readdir_res res; |
| 2889 | struct rpc_message msg = { |
| 2890 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 2891 | .rpc_argp = &args, |
| 2892 | .rpc_resp = &res, |
| 2893 | .rpc_cred = cred, |
| 2894 | }; |
| 2895 | int status; |
| 2896 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2897 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 2898 | dentry->d_parent->d_name.name, |
| 2899 | dentry->d_name.name, |
| 2900 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 2902 | res.pgbase = args.pgbase; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2903 | status = nfs4_call_sync(NFS_SERVER(dir), &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2904 | if (status == 0) |
| 2905 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 2906 | |
| 2907 | nfs_invalidate_atime(dir); |
| 2908 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2909 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2910 | return status; |
| 2911 | } |
| 2912 | |
| 2913 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
| 2914 | u64 cookie, struct page *page, unsigned int count, int plus) |
| 2915 | { |
| 2916 | struct nfs4_exception exception = { }; |
| 2917 | int err; |
| 2918 | do { |
| 2919 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 2920 | _nfs4_proc_readdir(dentry, cred, cookie, |
| 2921 | page, count, plus), |
| 2922 | &exception); |
| 2923 | } while (exception.retry); |
| 2924 | return err; |
| 2925 | } |
| 2926 | |
| 2927 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2928 | struct iattr *sattr, dev_t rdev) |
| 2929 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2930 | struct nfs4_createdata *data; |
| 2931 | int mode = sattr->ia_mode; |
| 2932 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | |
| 2934 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 2935 | BUG_ON(!S_ISFIFO(mode) && !S_ISBLK(mode) && !S_ISCHR(mode) && !S_ISSOCK(mode)); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2936 | |
| 2937 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 2938 | if (data == NULL) |
| 2939 | goto out; |
| 2940 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2942 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2943 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2944 | data->arg.ftype = NF4BLK; |
| 2945 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 2946 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | } |
| 2948 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2949 | data->arg.ftype = NF4CHR; |
| 2950 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 2951 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2952 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2953 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2954 | status = nfs4_do_create(dir, dentry, data); |
| 2955 | |
| 2956 | nfs4_free_createdata(data); |
| 2957 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2958 | return status; |
| 2959 | } |
| 2960 | |
| 2961 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2962 | struct iattr *sattr, dev_t rdev) |
| 2963 | { |
| 2964 | struct nfs4_exception exception = { }; |
| 2965 | int err; |
| 2966 | do { |
| 2967 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2968 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 2969 | &exception); |
| 2970 | } while (exception.retry); |
| 2971 | return err; |
| 2972 | } |
| 2973 | |
| 2974 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2975 | struct nfs_fsstat *fsstat) |
| 2976 | { |
| 2977 | struct nfs4_statfs_arg args = { |
| 2978 | .fh = fhandle, |
| 2979 | .bitmask = server->attr_bitmask, |
| 2980 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 2981 | struct nfs4_statfs_res res = { |
| 2982 | .fsstat = fsstat, |
| 2983 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | struct rpc_message msg = { |
| 2985 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 2986 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 2987 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | }; |
| 2989 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2990 | nfs_fattr_init(fsstat->fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2991 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | } |
| 2993 | |
| 2994 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 2995 | { |
| 2996 | struct nfs4_exception exception = { }; |
| 2997 | int err; |
| 2998 | do { |
| 2999 | err = nfs4_handle_exception(server, |
| 3000 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3001 | &exception); |
| 3002 | } while (exception.retry); |
| 3003 | return err; |
| 3004 | } |
| 3005 | |
| 3006 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3007 | struct nfs_fsinfo *fsinfo) |
| 3008 | { |
| 3009 | struct nfs4_fsinfo_arg args = { |
| 3010 | .fh = fhandle, |
| 3011 | .bitmask = server->attr_bitmask, |
| 3012 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3013 | struct nfs4_fsinfo_res res = { |
| 3014 | .fsinfo = fsinfo, |
| 3015 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | struct rpc_message msg = { |
| 3017 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3018 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3019 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3020 | }; |
| 3021 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3022 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3023 | } |
| 3024 | |
| 3025 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3026 | { |
| 3027 | struct nfs4_exception exception = { }; |
| 3028 | int err; |
| 3029 | |
| 3030 | do { |
| 3031 | err = nfs4_handle_exception(server, |
| 3032 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3033 | &exception); |
| 3034 | } while (exception.retry); |
| 3035 | return err; |
| 3036 | } |
| 3037 | |
| 3038 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3039 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3040 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3041 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3042 | } |
| 3043 | |
| 3044 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3045 | struct nfs_pathconf *pathconf) |
| 3046 | { |
| 3047 | struct nfs4_pathconf_arg args = { |
| 3048 | .fh = fhandle, |
| 3049 | .bitmask = server->attr_bitmask, |
| 3050 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3051 | struct nfs4_pathconf_res res = { |
| 3052 | .pathconf = pathconf, |
| 3053 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | struct rpc_message msg = { |
| 3055 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3056 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3057 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | }; |
| 3059 | |
| 3060 | /* None of the pathconf attributes are mandatory to implement */ |
| 3061 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3062 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3063 | return 0; |
| 3064 | } |
| 3065 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3066 | nfs_fattr_init(pathconf->fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3067 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3068 | } |
| 3069 | |
| 3070 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3071 | struct nfs_pathconf *pathconf) |
| 3072 | { |
| 3073 | struct nfs4_exception exception = { }; |
| 3074 | int err; |
| 3075 | |
| 3076 | do { |
| 3077 | err = nfs4_handle_exception(server, |
| 3078 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3079 | &exception); |
| 3080 | } while (exception.retry); |
| 3081 | return err; |
| 3082 | } |
| 3083 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3084 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | { |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3086 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3087 | |
Andy Adamson | f11c88a | 2009-04-01 09:22:25 -0400 | [diff] [blame] | 3088 | dprintk("--> %s\n", __func__); |
| 3089 | |
Andy Adamson | f11c88a | 2009-04-01 09:22:25 -0400 | [diff] [blame] | 3090 | nfs4_sequence_done(server, &data->res.seq_res, task->tk_status); |
| 3091 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3092 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3093 | nfs_restart_rpc(task, server->nfs_client); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3094 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3096 | |
| 3097 | nfs_invalidate_atime(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3098 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3099 | renew_lease(server, data->timestamp); |
| 3100 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | } |
| 3102 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3103 | 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] | 3104 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3105 | data->timestamp = jiffies; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3106 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3107 | } |
| 3108 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3109 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3111 | struct inode *inode = data->inode; |
| 3112 | |
Andy Adamson | def6ed7 | 2009-04-01 09:22:26 -0400 | [diff] [blame] | 3113 | nfs4_sequence_done(NFS_SERVER(inode), &data->res.seq_res, |
| 3114 | task->tk_status); |
| 3115 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3116 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3117 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3118 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3120 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 3122 | nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3123 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3124 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3125 | } |
| 3126 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3127 | 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] | 3128 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3129 | struct nfs_server *server = NFS_SERVER(data->inode); |
| 3130 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3131 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3132 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | data->timestamp = jiffies; |
| 3134 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3135 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3136 | } |
| 3137 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3138 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | struct inode *inode = data->inode; |
| 3141 | |
Andy Adamson | 21d9a85 | 2009-04-01 09:22:27 -0400 | [diff] [blame] | 3142 | nfs4_sequence_done(NFS_SERVER(inode), &data->res.seq_res, |
| 3143 | task->tk_status); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3144 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3145 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3146 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3147 | } |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 3148 | nfs_refresh_inode(inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3149 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | } |
| 3151 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3152 | static void nfs4_proc_commit_setup(struct nfs_write_data *data, struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3154 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3156 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3157 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3158 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | } |
| 3160 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3161 | struct nfs4_renewdata { |
| 3162 | struct nfs_client *client; |
| 3163 | unsigned long timestamp; |
| 3164 | }; |
| 3165 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | /* |
| 3167 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3168 | * standalone procedure for queueing an asynchronous RENEW. |
| 3169 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3170 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3171 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3172 | struct nfs4_renewdata *data = calldata; |
| 3173 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3174 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3175 | if (atomic_read(&clp->cl_count) > 1) |
| 3176 | nfs4_schedule_state_renewal(clp); |
| 3177 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3178 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3179 | } |
| 3180 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3181 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3183 | struct nfs4_renewdata *data = calldata; |
| 3184 | struct nfs_client *clp = data->client; |
| 3185 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3186 | |
| 3187 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3188 | /* Unless we're shutting down, schedule state recovery! */ |
| 3189 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) != 0) |
| 3190 | nfs4_schedule_state_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | return; |
| 3192 | } |
| 3193 | spin_lock(&clp->cl_lock); |
| 3194 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 3195 | clp->cl_last_renewal = timestamp; |
| 3196 | spin_unlock(&clp->cl_lock); |
| 3197 | } |
| 3198 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3199 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3200 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3201 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3202 | }; |
| 3203 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3204 | int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3205 | { |
| 3206 | struct rpc_message msg = { |
| 3207 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3208 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3209 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3211 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3213 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3214 | return -EIO; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3215 | data = kmalloc(sizeof(*data), GFP_KERNEL); |
| 3216 | if (data == NULL) |
| 3217 | return -ENOMEM; |
| 3218 | data->client = clp; |
| 3219 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3221 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3222 | } |
| 3223 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3224 | int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | { |
| 3226 | struct rpc_message msg = { |
| 3227 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3228 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3229 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3230 | }; |
| 3231 | unsigned long now = jiffies; |
| 3232 | int status; |
| 3233 | |
| 3234 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3235 | if (status < 0) |
| 3236 | return status; |
| 3237 | spin_lock(&clp->cl_lock); |
| 3238 | if (time_before(clp->cl_last_renewal,now)) |
| 3239 | clp->cl_last_renewal = now; |
| 3240 | spin_unlock(&clp->cl_lock); |
| 3241 | return 0; |
| 3242 | } |
| 3243 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3244 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3245 | { |
| 3246 | return (server->caps & NFS_CAP_ACLS) |
| 3247 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3248 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3249 | } |
| 3250 | |
| 3251 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3252 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3253 | * the stack. |
| 3254 | */ |
| 3255 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3256 | |
| 3257 | static void buf_to_pages(const void *buf, size_t buflen, |
| 3258 | struct page **pages, unsigned int *pgbase) |
| 3259 | { |
| 3260 | const void *p = buf; |
| 3261 | |
| 3262 | *pgbase = offset_in_page(buf); |
| 3263 | p -= *pgbase; |
| 3264 | while (p < buf + buflen) { |
| 3265 | *(pages++) = virt_to_page(p); |
| 3266 | p += PAGE_CACHE_SIZE; |
| 3267 | } |
| 3268 | } |
| 3269 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3270 | struct nfs4_cached_acl { |
| 3271 | int cached; |
| 3272 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3273 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3274 | }; |
| 3275 | |
| 3276 | 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] | 3277 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3278 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3279 | |
| 3280 | spin_lock(&inode->i_lock); |
| 3281 | kfree(nfsi->nfs4_acl); |
| 3282 | nfsi->nfs4_acl = acl; |
| 3283 | spin_unlock(&inode->i_lock); |
| 3284 | } |
| 3285 | |
| 3286 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3287 | { |
| 3288 | nfs4_set_cached_acl(inode, NULL); |
| 3289 | } |
| 3290 | |
| 3291 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3292 | { |
| 3293 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3294 | struct nfs4_cached_acl *acl; |
| 3295 | int ret = -ENOENT; |
| 3296 | |
| 3297 | spin_lock(&inode->i_lock); |
| 3298 | acl = nfsi->nfs4_acl; |
| 3299 | if (acl == NULL) |
| 3300 | goto out; |
| 3301 | if (buf == NULL) /* user is just asking for length */ |
| 3302 | goto out_len; |
| 3303 | if (acl->cached == 0) |
| 3304 | goto out; |
| 3305 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3306 | if (acl->len > buflen) |
| 3307 | goto out; |
| 3308 | memcpy(buf, acl->data, acl->len); |
| 3309 | out_len: |
| 3310 | ret = acl->len; |
| 3311 | out: |
| 3312 | spin_unlock(&inode->i_lock); |
| 3313 | return ret; |
| 3314 | } |
| 3315 | |
| 3316 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) |
| 3317 | { |
| 3318 | struct nfs4_cached_acl *acl; |
| 3319 | |
| 3320 | if (buf && acl_len <= PAGE_SIZE) { |
| 3321 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3322 | if (acl == NULL) |
| 3323 | goto out; |
| 3324 | acl->cached = 1; |
| 3325 | memcpy(acl->data, buf, acl_len); |
| 3326 | } else { |
| 3327 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3328 | if (acl == NULL) |
| 3329 | goto out; |
| 3330 | acl->cached = 0; |
| 3331 | } |
| 3332 | acl->len = acl_len; |
| 3333 | out: |
| 3334 | nfs4_set_cached_acl(inode, acl); |
| 3335 | } |
| 3336 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3337 | 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] | 3338 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3339 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3340 | struct nfs_getaclargs args = { |
| 3341 | .fh = NFS_FH(inode), |
| 3342 | .acl_pages = pages, |
| 3343 | .acl_len = buflen, |
| 3344 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3345 | struct nfs_getaclres res = { |
| 3346 | .acl_len = buflen, |
| 3347 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3348 | void *resp_buf; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3349 | struct rpc_message msg = { |
| 3350 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3351 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3352 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3353 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3354 | struct page *localpage = NULL; |
| 3355 | int ret; |
| 3356 | |
| 3357 | if (buflen < PAGE_SIZE) { |
| 3358 | /* As long as we're doing a round trip to the server anyway, |
| 3359 | * let's be prepared for a page of acl data. */ |
| 3360 | localpage = alloc_page(GFP_KERNEL); |
| 3361 | resp_buf = page_address(localpage); |
| 3362 | if (localpage == NULL) |
| 3363 | return -ENOMEM; |
| 3364 | args.acl_pages[0] = localpage; |
| 3365 | args.acl_pgbase = 0; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3366 | args.acl_len = PAGE_SIZE; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3367 | } else { |
| 3368 | resp_buf = buf; |
| 3369 | buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase); |
| 3370 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3371 | ret = nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3372 | if (ret) |
| 3373 | goto out_free; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3374 | if (res.acl_len > args.acl_len) |
| 3375 | nfs4_write_cached_acl(inode, NULL, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3376 | else |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3377 | nfs4_write_cached_acl(inode, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3378 | if (buf) { |
| 3379 | ret = -ERANGE; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3380 | if (res.acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3381 | goto out_free; |
| 3382 | if (localpage) |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3383 | memcpy(buf, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3384 | } |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3385 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3386 | out_free: |
| 3387 | if (localpage) |
| 3388 | __free_page(localpage); |
| 3389 | return ret; |
| 3390 | } |
| 3391 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3392 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3393 | { |
| 3394 | struct nfs4_exception exception = { }; |
| 3395 | ssize_t ret; |
| 3396 | do { |
| 3397 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3398 | if (ret >= 0) |
| 3399 | break; |
| 3400 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3401 | } while (exception.retry); |
| 3402 | return ret; |
| 3403 | } |
| 3404 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3405 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3406 | { |
| 3407 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3408 | int ret; |
| 3409 | |
| 3410 | if (!nfs4_server_supports_acls(server)) |
| 3411 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3412 | ret = nfs_revalidate_inode(server, inode); |
| 3413 | if (ret < 0) |
| 3414 | return ret; |
| 3415 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3416 | if (ret != -ENOENT) |
| 3417 | return ret; |
| 3418 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3419 | } |
| 3420 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3421 | 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] | 3422 | { |
| 3423 | struct nfs_server *server = NFS_SERVER(inode); |
| 3424 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3425 | struct nfs_setaclargs arg = { |
| 3426 | .fh = NFS_FH(inode), |
| 3427 | .acl_pages = pages, |
| 3428 | .acl_len = buflen, |
| 3429 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3430 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3431 | struct rpc_message msg = { |
| 3432 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3433 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3434 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3435 | }; |
| 3436 | int ret; |
| 3437 | |
| 3438 | if (!nfs4_server_supports_acls(server)) |
| 3439 | return -EOPNOTSUPP; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3440 | nfs_inode_return_delegation(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3441 | buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3442 | ret = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3443 | nfs_access_zap_cache(inode); |
| 3444 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3445 | return ret; |
| 3446 | } |
| 3447 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3448 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3449 | { |
| 3450 | struct nfs4_exception exception = { }; |
| 3451 | int err; |
| 3452 | do { |
| 3453 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3454 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3455 | &exception); |
| 3456 | } while (exception.retry); |
| 3457 | return err; |
| 3458 | } |
| 3459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3460 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3461 | 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] | 3462 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3463 | struct nfs_client *clp = server->nfs_client; |
| 3464 | |
| 3465 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | return 0; |
| 3467 | switch(task->tk_status) { |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3468 | case -NFS4ERR_ADMIN_REVOKED: |
| 3469 | case -NFS4ERR_BAD_STATEID: |
| 3470 | case -NFS4ERR_OPENMODE: |
| 3471 | if (state == NULL) |
| 3472 | break; |
| 3473 | nfs4_state_mark_reclaim_nograce(clp, state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3474 | goto do_state_recovery; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3475 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3476 | if (state == NULL) |
| 3477 | break; |
| 3478 | nfs4_state_mark_reclaim_reboot(clp, state); |
| 3479 | case -NFS4ERR_STALE_CLIENTID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3480 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3481 | goto do_state_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3482 | #if defined(CONFIG_NFS_V4_1) |
| 3483 | case -NFS4ERR_BADSESSION: |
| 3484 | case -NFS4ERR_BADSLOT: |
| 3485 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3486 | case -NFS4ERR_DEADSESSION: |
| 3487 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3488 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3489 | case -NFS4ERR_SEQ_MISORDERED: |
| 3490 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3491 | task->tk_status); |
Andy Adamson | 0b9e2d4 | 2009-12-04 16:02:14 -0500 | [diff] [blame] | 3492 | nfs4_schedule_state_recovery(clp); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3493 | task->tk_status = 0; |
| 3494 | return -EAGAIN; |
| 3495 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3497 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3498 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3499 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3501 | task->tk_status = 0; |
| 3502 | return -EAGAIN; |
| 3503 | case -NFS4ERR_OLD_STATEID: |
| 3504 | task->tk_status = 0; |
| 3505 | return -EAGAIN; |
| 3506 | } |
| 3507 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3508 | return 0; |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3509 | do_state_recovery: |
| 3510 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 3511 | nfs4_schedule_state_recovery(clp); |
| 3512 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3513 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3514 | task->tk_status = 0; |
| 3515 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3516 | } |
| 3517 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3518 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 3519 | unsigned short port, struct rpc_cred *cred, |
| 3520 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3521 | { |
| 3522 | nfs4_verifier sc_verifier; |
| 3523 | struct nfs4_setclientid setclientid = { |
| 3524 | .sc_verifier = &sc_verifier, |
| 3525 | .sc_prog = program, |
| 3526 | }; |
| 3527 | struct rpc_message msg = { |
| 3528 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3529 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3530 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3531 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3532 | }; |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3533 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3534 | int loop = 0; |
| 3535 | int status; |
| 3536 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3537 | p = (__be32*)sc_verifier.data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3538 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 3539 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 3540 | |
| 3541 | for(;;) { |
| 3542 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3543 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3544 | clp->cl_ipaddr, |
| 3545 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3546 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3547 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3548 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3549 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3550 | clp->cl_id_uniquifier); |
| 3551 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3552 | sizeof(setclientid.sc_netid), |
| 3553 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3554 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3556 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3557 | clp->cl_ipaddr, port >> 8, port & 255); |
| 3558 | |
| 3559 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3560 | if (status != -NFS4ERR_CLID_INUSE) |
| 3561 | break; |
| 3562 | if (signalled()) |
| 3563 | break; |
| 3564 | if (loop++ & 1) |
| 3565 | ssleep(clp->cl_lease_time + 1); |
| 3566 | else |
| 3567 | if (++clp->cl_id_uniquifier == 0) |
| 3568 | break; |
| 3569 | } |
| 3570 | return status; |
| 3571 | } |
| 3572 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3573 | static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
| 3574 | struct nfs4_setclientid_res *arg, |
| 3575 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3576 | { |
| 3577 | struct nfs_fsinfo fsinfo; |
| 3578 | struct rpc_message msg = { |
| 3579 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3580 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3581 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3582 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3583 | }; |
| 3584 | unsigned long now; |
| 3585 | int status; |
| 3586 | |
| 3587 | now = jiffies; |
| 3588 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3589 | if (status == 0) { |
| 3590 | spin_lock(&clp->cl_lock); |
| 3591 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 3592 | clp->cl_last_renewal = now; |
| 3593 | spin_unlock(&clp->cl_lock); |
| 3594 | } |
| 3595 | return status; |
| 3596 | } |
| 3597 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3598 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
| 3599 | struct nfs4_setclientid_res *arg, |
| 3600 | struct rpc_cred *cred) |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3601 | { |
Benny Halevy | 77e0367 | 2008-06-24 20:25:57 +0300 | [diff] [blame] | 3602 | long timeout = 0; |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3603 | int err; |
| 3604 | do { |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3605 | err = _nfs4_proc_setclientid_confirm(clp, arg, cred); |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3606 | switch (err) { |
| 3607 | case 0: |
| 3608 | return err; |
| 3609 | case -NFS4ERR_RESOURCE: |
| 3610 | /* The IBM lawyers misread another document! */ |
| 3611 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3612 | case -EKEYEXPIRED: |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3613 | err = nfs4_delay(clp->cl_rpcclient, &timeout); |
| 3614 | } |
| 3615 | } while (err == 0); |
| 3616 | return err; |
| 3617 | } |
| 3618 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3619 | struct nfs4_delegreturndata { |
| 3620 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3621 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3622 | struct nfs_fh fh; |
| 3623 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3624 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3625 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3626 | int rpc_status; |
| 3627 | }; |
| 3628 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3629 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 3630 | { |
| 3631 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3632 | |
Trond Myklebust | d61e612 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 3633 | nfs4_sequence_done(data->res.server, &data->res.seq_res, |
| 3634 | task->tk_status); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3635 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3636 | switch (task->tk_status) { |
| 3637 | case -NFS4ERR_STALE_STATEID: |
| 3638 | case -NFS4ERR_EXPIRED: |
| 3639 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3640 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3641 | break; |
| 3642 | default: |
| 3643 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 3644 | -EAGAIN) { |
| 3645 | nfs_restart_rpc(task, data->res.server->nfs_client); |
| 3646 | return; |
| 3647 | } |
| 3648 | } |
| 3649 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3650 | } |
| 3651 | |
| 3652 | static void nfs4_delegreturn_release(void *calldata) |
| 3653 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3654 | kfree(calldata); |
| 3655 | } |
| 3656 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3657 | #if defined(CONFIG_NFS_V4_1) |
| 3658 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 3659 | { |
| 3660 | struct nfs4_delegreturndata *d_data; |
| 3661 | |
| 3662 | d_data = (struct nfs4_delegreturndata *)data; |
| 3663 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3664 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3665 | &d_data->args.seq_args, |
| 3666 | &d_data->res.seq_res, 1, task)) |
| 3667 | return; |
| 3668 | rpc_call_start(task); |
| 3669 | } |
| 3670 | #endif /* CONFIG_NFS_V4_1 */ |
| 3671 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 3672 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3673 | #if defined(CONFIG_NFS_V4_1) |
| 3674 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 3675 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3676 | .rpc_call_done = nfs4_delegreturn_done, |
| 3677 | .rpc_release = nfs4_delegreturn_release, |
| 3678 | }; |
| 3679 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3680 | 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] | 3681 | { |
| 3682 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3683 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3684 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3685 | struct rpc_message msg = { |
| 3686 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 3687 | .rpc_cred = cred, |
| 3688 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3689 | struct rpc_task_setup task_setup_data = { |
| 3690 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3691 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3692 | .callback_ops = &nfs4_delegreturn_ops, |
| 3693 | .flags = RPC_TASK_ASYNC, |
| 3694 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3695 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3696 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3697 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3698 | if (data == NULL) |
| 3699 | return -ENOMEM; |
| 3700 | data->args.fhandle = &data->fh; |
| 3701 | data->args.stateid = &data->stateid; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3702 | data->args.bitmask = server->attr_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3703 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
| 3704 | memcpy(&data->stateid, stateid, sizeof(data->stateid)); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3705 | data->res.fattr = &data->fattr; |
| 3706 | data->res.server = server; |
Andy Adamson | 5f7dbd5 | 2009-04-01 09:22:05 -0400 | [diff] [blame] | 3707 | data->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3708 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3709 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3710 | data->rpc_status = 0; |
| 3711 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3712 | task_setup_data.callback_data = data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3713 | msg.rpc_argp = &data->args, |
| 3714 | msg.rpc_resp = &data->res, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3715 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 3716 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3717 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3718 | if (!issync) |
| 3719 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3720 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3721 | if (status != 0) |
| 3722 | goto out; |
| 3723 | status = data->rpc_status; |
| 3724 | if (status != 0) |
| 3725 | goto out; |
| 3726 | nfs_refresh_inode(inode, &data->fattr); |
| 3727 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3728 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3729 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3730 | } |
| 3731 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3732 | 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] | 3733 | { |
| 3734 | struct nfs_server *server = NFS_SERVER(inode); |
| 3735 | struct nfs4_exception exception = { }; |
| 3736 | int err; |
| 3737 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3738 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3739 | switch (err) { |
| 3740 | case -NFS4ERR_STALE_STATEID: |
| 3741 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3742 | case 0: |
| 3743 | return 0; |
| 3744 | } |
| 3745 | err = nfs4_handle_exception(server, err, &exception); |
| 3746 | } while (exception.retry); |
| 3747 | return err; |
| 3748 | } |
| 3749 | |
| 3750 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 3751 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 3752 | |
| 3753 | /* |
| 3754 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 3755 | */ |
| 3756 | static unsigned long |
| 3757 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 3758 | { |
Matthew Wilcox | 150030b | 2007-12-06 16:24:39 -0500 | [diff] [blame] | 3759 | schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3760 | timeout <<= 1; |
| 3761 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 3762 | return NFS4_LOCK_MAXTIMEOUT; |
| 3763 | return timeout; |
| 3764 | } |
| 3765 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3766 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3767 | { |
| 3768 | struct inode *inode = state->inode; |
| 3769 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3770 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3771 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3772 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3773 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3774 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3775 | struct nfs_lockt_res res = { |
| 3776 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3777 | }; |
| 3778 | struct rpc_message msg = { |
| 3779 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 3780 | .rpc_argp = &arg, |
| 3781 | .rpc_resp = &res, |
| 3782 | .rpc_cred = state->owner->so_cred, |
| 3783 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3784 | struct nfs4_lock_state *lsp; |
| 3785 | int status; |
| 3786 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3787 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3788 | status = nfs4_set_lock_state(state, request); |
| 3789 | if (status != 0) |
| 3790 | goto out; |
| 3791 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 3792 | arg.lock_owner.id = lsp->ls_id.id; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3793 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3794 | switch (status) { |
| 3795 | case 0: |
| 3796 | request->fl_type = F_UNLCK; |
| 3797 | break; |
| 3798 | case -NFS4ERR_DENIED: |
| 3799 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3800 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 3801 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3802 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3803 | return status; |
| 3804 | } |
| 3805 | |
| 3806 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3807 | { |
| 3808 | struct nfs4_exception exception = { }; |
| 3809 | int err; |
| 3810 | |
| 3811 | do { |
| 3812 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 3813 | _nfs4_proc_getlk(state, cmd, request), |
| 3814 | &exception); |
| 3815 | } while (exception.retry); |
| 3816 | return err; |
| 3817 | } |
| 3818 | |
| 3819 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 3820 | { |
| 3821 | int res = 0; |
| 3822 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 3823 | case FL_POSIX: |
| 3824 | res = posix_lock_file_wait(file, fl); |
| 3825 | break; |
| 3826 | case FL_FLOCK: |
| 3827 | res = flock_lock_file_wait(file, fl); |
| 3828 | break; |
| 3829 | default: |
| 3830 | BUG(); |
| 3831 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3832 | return res; |
| 3833 | } |
| 3834 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3835 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3836 | struct nfs_locku_args arg; |
| 3837 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3838 | struct nfs4_lock_state *lsp; |
| 3839 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3840 | struct file_lock fl; |
| 3841 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3842 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3843 | }; |
| 3844 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3845 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 3846 | struct nfs_open_context *ctx, |
| 3847 | struct nfs4_lock_state *lsp, |
| 3848 | struct nfs_seqid *seqid) |
| 3849 | { |
| 3850 | struct nfs4_unlockdata *p; |
| 3851 | struct inode *inode = lsp->ls_state->inode; |
| 3852 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3853 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3854 | if (p == NULL) |
| 3855 | return NULL; |
| 3856 | p->arg.fh = NFS_FH(inode); |
| 3857 | p->arg.fl = &p->fl; |
| 3858 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3859 | p->res.seqid = seqid; |
Andy Adamson | 5f7dbd5 | 2009-04-01 09:22:05 -0400 | [diff] [blame] | 3860 | p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3861 | p->arg.stateid = &lsp->ls_stateid; |
| 3862 | p->lsp = lsp; |
| 3863 | atomic_inc(&lsp->ls_count); |
| 3864 | /* Ensure we don't close file until we're done freeing locks! */ |
| 3865 | p->ctx = get_nfs_open_context(ctx); |
| 3866 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 3867 | p->server = NFS_SERVER(inode); |
| 3868 | return p; |
| 3869 | } |
| 3870 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3871 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3872 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3873 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3874 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3875 | nfs4_put_lock_state(calldata->lsp); |
| 3876 | put_nfs_open_context(calldata->ctx); |
| 3877 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3878 | } |
| 3879 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3880 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3881 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3882 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3883 | |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 3884 | nfs4_sequence_done(calldata->server, &calldata->res.seq_res, |
| 3885 | task->tk_status); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3886 | if (RPC_ASSASSINATED(task)) |
| 3887 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3888 | switch (task->tk_status) { |
| 3889 | case 0: |
| 3890 | memcpy(calldata->lsp->ls_stateid.data, |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3891 | calldata->res.stateid.data, |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3892 | sizeof(calldata->lsp->ls_stateid.data)); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3893 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3894 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3895 | case -NFS4ERR_BAD_STATEID: |
| 3896 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3897 | case -NFS4ERR_STALE_STATEID: |
| 3898 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3899 | break; |
| 3900 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3901 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3902 | nfs_restart_rpc(task, |
Trond Myklebust | d61e612 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 3903 | calldata->server->nfs_client); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3904 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3905 | } |
| 3906 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3907 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3908 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3909 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3910 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3911 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3912 | return; |
| 3913 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3914 | /* Note: exit _without_ running nfs4_locku_done */ |
| 3915 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3916 | return; |
| 3917 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3918 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3919 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 3920 | &calldata->arg.seq_args, |
| 3921 | &calldata->res.seq_res, 1, task)) |
| 3922 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3923 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3924 | } |
| 3925 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3926 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3927 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3928 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3929 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3930 | }; |
| 3931 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3932 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 3933 | struct nfs_open_context *ctx, |
| 3934 | struct nfs4_lock_state *lsp, |
| 3935 | struct nfs_seqid *seqid) |
| 3936 | { |
| 3937 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3938 | struct rpc_message msg = { |
| 3939 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 3940 | .rpc_cred = ctx->cred, |
| 3941 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3942 | struct rpc_task_setup task_setup_data = { |
| 3943 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3944 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3945 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3946 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3947 | .flags = RPC_TASK_ASYNC, |
| 3948 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3949 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 3950 | /* Ensure this is an unlock - when canceling a lock, the |
| 3951 | * canceled lock is passed in, and it won't be an unlock. |
| 3952 | */ |
| 3953 | fl->fl_type = F_UNLCK; |
| 3954 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3955 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 3956 | if (data == NULL) { |
| 3957 | nfs_free_seqid(seqid); |
| 3958 | return ERR_PTR(-ENOMEM); |
| 3959 | } |
| 3960 | |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3961 | msg.rpc_argp = &data->arg, |
| 3962 | msg.rpc_resp = &data->res, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3963 | task_setup_data.callback_data = data; |
| 3964 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3965 | } |
| 3966 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3967 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3968 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3969 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3970 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3971 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3972 | struct rpc_task *task; |
| 3973 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 3974 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3975 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3976 | status = nfs4_set_lock_state(state, request); |
| 3977 | /* Unlock _before_ we do the RPC call */ |
| 3978 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3979 | down_read(&nfsi->rwsem); |
| 3980 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 3981 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3982 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3983 | } |
| 3984 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3985 | if (status != 0) |
| 3986 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 3987 | /* Is this a delegated lock? */ |
| 3988 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3989 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3990 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3991 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3992 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3993 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3994 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 3995 | 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] | 3996 | status = PTR_ERR(task); |
| 3997 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3998 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3999 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4000 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4001 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4002 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4003 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4004 | } |
| 4005 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4006 | struct nfs4_lockdata { |
| 4007 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4008 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4009 | struct nfs4_lock_state *lsp; |
| 4010 | struct nfs_open_context *ctx; |
| 4011 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4012 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4013 | int rpc_status; |
| 4014 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4015 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4016 | }; |
| 4017 | |
| 4018 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4019 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4020 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4021 | { |
| 4022 | struct nfs4_lockdata *p; |
| 4023 | struct inode *inode = lsp->ls_state->inode; |
| 4024 | struct nfs_server *server = NFS_SERVER(inode); |
| 4025 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4026 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4027 | if (p == NULL) |
| 4028 | return NULL; |
| 4029 | |
| 4030 | p->arg.fh = NFS_FH(inode); |
| 4031 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4032 | 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] | 4033 | if (p->arg.open_seqid == NULL) |
| 4034 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4035 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4036 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4037 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4038 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4039 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 4040 | p->arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4041 | p->res.lock_seqid = p->arg.lock_seqid; |
Andy Adamson | 5f7dbd5 | 2009-04-01 09:22:05 -0400 | [diff] [blame] | 4042 | p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4043 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4044 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4045 | atomic_inc(&lsp->ls_count); |
| 4046 | p->ctx = get_nfs_open_context(ctx); |
| 4047 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4048 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4049 | out_free_seqid: |
| 4050 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4051 | out_free: |
| 4052 | kfree(p); |
| 4053 | return NULL; |
| 4054 | } |
| 4055 | |
| 4056 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4057 | { |
| 4058 | struct nfs4_lockdata *data = calldata; |
| 4059 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4060 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4061 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4062 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4063 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4064 | /* Do we need to do an open_to_lock_owner? */ |
| 4065 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4066 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4067 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4068 | data->arg.open_stateid = &state->stateid; |
| 4069 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4070 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4071 | } else |
| 4072 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4073 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4074 | if (nfs4_setup_sequence(data->server, |
| 4075 | &data->arg.seq_args, |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4076 | &data->res.seq_res, 1, task)) |
| 4077 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4078 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4079 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4080 | } |
| 4081 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4082 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4083 | { |
| 4084 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4085 | nfs4_lock_prepare(task, calldata); |
| 4086 | } |
| 4087 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4088 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4089 | { |
| 4090 | struct nfs4_lockdata *data = calldata; |
| 4091 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4092 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4093 | |
Trond Myklebust | d61e612 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 4094 | nfs4_sequence_done(data->server, &data->res.seq_res, |
| 4095 | task->tk_status); |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4096 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4097 | data->rpc_status = task->tk_status; |
| 4098 | if (RPC_ASSASSINATED(task)) |
| 4099 | goto out; |
| 4100 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4101 | if (data->rpc_status == 0) |
| 4102 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4103 | else |
| 4104 | goto out; |
| 4105 | } |
| 4106 | if (data->rpc_status == 0) { |
| 4107 | memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, |
| 4108 | sizeof(data->lsp->ls_stateid.data)); |
| 4109 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Trond Myklebust | 88be9f9 | 2007-06-05 10:42:27 -0400 | [diff] [blame] | 4110 | renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4111 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4112 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4113 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4114 | } |
| 4115 | |
| 4116 | static void nfs4_lock_release(void *calldata) |
| 4117 | { |
| 4118 | struct nfs4_lockdata *data = calldata; |
| 4119 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4120 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4121 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4122 | if (data->cancelled != 0) { |
| 4123 | struct rpc_task *task; |
| 4124 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4125 | data->arg.lock_seqid); |
| 4126 | if (!IS_ERR(task)) |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4127 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4128 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4129 | } else |
| 4130 | nfs_free_seqid(data->arg.lock_seqid); |
| 4131 | nfs4_put_lock_state(data->lsp); |
| 4132 | put_nfs_open_context(data->ctx); |
| 4133 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4134 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4135 | } |
| 4136 | |
| 4137 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4138 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4139 | .rpc_call_done = nfs4_lock_done, |
| 4140 | .rpc_release = nfs4_lock_release, |
| 4141 | }; |
| 4142 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4143 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4144 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4145 | .rpc_call_done = nfs4_lock_done, |
| 4146 | .rpc_release = nfs4_lock_release, |
| 4147 | }; |
| 4148 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4149 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4150 | { |
| 4151 | struct nfs_client *clp = server->nfs_client; |
| 4152 | struct nfs4_state *state = lsp->ls_state; |
| 4153 | |
| 4154 | switch (error) { |
| 4155 | case -NFS4ERR_ADMIN_REVOKED: |
| 4156 | case -NFS4ERR_BAD_STATEID: |
| 4157 | case -NFS4ERR_EXPIRED: |
| 4158 | if (new_lock_owner != 0 || |
| 4159 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
| 4160 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 4161 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4162 | break; |
| 4163 | case -NFS4ERR_STALE_STATEID: |
| 4164 | if (new_lock_owner != 0 || |
| 4165 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
| 4166 | nfs4_state_mark_reclaim_reboot(clp, state); |
| 4167 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4168 | }; |
| 4169 | } |
| 4170 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4171 | 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] | 4172 | { |
| 4173 | struct nfs4_lockdata *data; |
| 4174 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4175 | struct rpc_message msg = { |
| 4176 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4177 | .rpc_cred = state->owner->so_cred, |
| 4178 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4179 | struct rpc_task_setup task_setup_data = { |
| 4180 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4181 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4182 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4183 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4184 | .flags = RPC_TASK_ASYNC, |
| 4185 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4186 | int ret; |
| 4187 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4188 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4189 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4190 | fl->fl_u.nfs4_fl.owner, |
| 4191 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4192 | if (data == NULL) |
| 4193 | return -ENOMEM; |
| 4194 | if (IS_SETLKW(cmd)) |
| 4195 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4196 | if (recovery_type > NFS_LOCK_NEW) { |
| 4197 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4198 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4199 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4200 | } |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4201 | msg.rpc_argp = &data->arg, |
| 4202 | msg.rpc_resp = &data->res, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4203 | task_setup_data.callback_data = data; |
| 4204 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4205 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4206 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4207 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4208 | if (ret == 0) { |
| 4209 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4210 | if (ret) |
| 4211 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4212 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4213 | } else |
| 4214 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4215 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4216 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4217 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4218 | } |
| 4219 | |
| 4220 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4221 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4222 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4223 | struct nfs4_exception exception = { }; |
| 4224 | int err; |
| 4225 | |
| 4226 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4227 | /* Cache the lock if possible... */ |
| 4228 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4229 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4230 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 4231 | if (err != -NFS4ERR_DELAY && err != -EKEYEXPIRED) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4232 | break; |
| 4233 | nfs4_handle_exception(server, err, &exception); |
| 4234 | } while (exception.retry); |
| 4235 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4236 | } |
| 4237 | |
| 4238 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4239 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4240 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4241 | struct nfs4_exception exception = { }; |
| 4242 | int err; |
| 4243 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4244 | err = nfs4_set_lock_state(state, request); |
| 4245 | if (err != 0) |
| 4246 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4247 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4248 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4249 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4250 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4251 | switch (err) { |
| 4252 | default: |
| 4253 | goto out; |
| 4254 | case -NFS4ERR_GRACE: |
| 4255 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 4256 | case -EKEYEXPIRED: |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4257 | nfs4_handle_exception(server, err, &exception); |
| 4258 | err = 0; |
| 4259 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4260 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4261 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4262 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4263 | } |
| 4264 | |
| 4265 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4266 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4267 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4268 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4269 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4270 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4271 | if ((fl_flags & FL_POSIX) && |
| 4272 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4273 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4274 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4275 | status = nfs4_set_lock_state(state, request); |
| 4276 | if (status != 0) |
| 4277 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4278 | request->fl_flags |= FL_ACCESS; |
| 4279 | status = do_vfs_lock(request->fl_file, request); |
| 4280 | if (status < 0) |
| 4281 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4282 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4283 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4284 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4285 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4286 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4287 | status = do_vfs_lock(request->fl_file, request); |
| 4288 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4289 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4290 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4291 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4292 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4293 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4294 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4295 | if (do_vfs_lock(request->fl_file, request) < 0) |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4296 | printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4297 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4298 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4299 | out: |
| 4300 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4301 | return status; |
| 4302 | } |
| 4303 | |
| 4304 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4305 | { |
| 4306 | struct nfs4_exception exception = { }; |
| 4307 | int err; |
| 4308 | |
| 4309 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4310 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4311 | if (err == -NFS4ERR_DENIED) |
| 4312 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4313 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4314 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4315 | } while (exception.retry); |
| 4316 | return err; |
| 4317 | } |
| 4318 | |
| 4319 | static int |
| 4320 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4321 | { |
| 4322 | struct nfs_open_context *ctx; |
| 4323 | struct nfs4_state *state; |
| 4324 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4325 | int status; |
| 4326 | |
| 4327 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4328 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4329 | state = ctx->state; |
| 4330 | |
| 4331 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4332 | return -EINVAL; |
| 4333 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4334 | if (IS_GETLK(cmd)) { |
| 4335 | if (state != NULL) |
| 4336 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4337 | return 0; |
| 4338 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4339 | |
| 4340 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4341 | return -EINVAL; |
| 4342 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4343 | if (request->fl_type == F_UNLCK) { |
| 4344 | if (state != NULL) |
| 4345 | return nfs4_proc_unlck(state, cmd, request); |
| 4346 | return 0; |
| 4347 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4348 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4349 | if (state == NULL) |
| 4350 | return -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4351 | do { |
| 4352 | status = nfs4_proc_setlk(state, cmd, request); |
| 4353 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4354 | break; |
| 4355 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4356 | status = -ERESTARTSYS; |
| 4357 | if (signalled()) |
| 4358 | break; |
| 4359 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4360 | return status; |
| 4361 | } |
| 4362 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4363 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4364 | { |
| 4365 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4366 | struct nfs4_exception exception = { }; |
| 4367 | int err; |
| 4368 | |
| 4369 | err = nfs4_set_lock_state(state, fl); |
| 4370 | if (err != 0) |
| 4371 | goto out; |
| 4372 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4373 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4374 | switch (err) { |
| 4375 | default: |
| 4376 | printk(KERN_ERR "%s: unhandled error %d.\n", |
| 4377 | __func__, err); |
| 4378 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4379 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4380 | goto out; |
| 4381 | case -NFS4ERR_EXPIRED: |
| 4382 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4383 | case -NFS4ERR_STALE_STATEID: |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4384 | case -NFS4ERR_BADSESSION: |
| 4385 | case -NFS4ERR_BADSLOT: |
| 4386 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4387 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4388 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4389 | nfs4_schedule_state_recovery(server->nfs_client); |
| 4390 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4391 | case -ERESTARTSYS: |
| 4392 | /* |
| 4393 | * The show must go on: exit, but mark the |
| 4394 | * stateid as needing recovery. |
| 4395 | */ |
| 4396 | case -NFS4ERR_ADMIN_REVOKED: |
| 4397 | case -NFS4ERR_BAD_STATEID: |
| 4398 | case -NFS4ERR_OPENMODE: |
| 4399 | nfs4_state_mark_reclaim_nograce(server->nfs_client, state); |
| 4400 | err = 0; |
| 4401 | goto out; |
| 4402 | case -ENOMEM: |
| 4403 | case -NFS4ERR_DENIED: |
| 4404 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4405 | err = 0; |
| 4406 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4407 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 4408 | case -EKEYEXPIRED: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4409 | break; |
| 4410 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4411 | err = nfs4_handle_exception(server, err, &exception); |
| 4412 | } while (exception.retry); |
| 4413 | out: |
| 4414 | return err; |
| 4415 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4416 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4417 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4418 | |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4419 | int nfs4_setxattr(struct dentry *dentry, const char *key, const void *buf, |
| 4420 | size_t buflen, int flags) |
| 4421 | { |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4422 | struct inode *inode = dentry->d_inode; |
| 4423 | |
| 4424 | if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0) |
| 4425 | return -EOPNOTSUPP; |
| 4426 | |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4427 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4428 | } |
| 4429 | |
| 4430 | /* The getxattr man page suggests returning -ENODATA for unknown attributes, |
| 4431 | * and that's what we'll do for e.g. user attributes that haven't been set. |
| 4432 | * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported |
| 4433 | * attributes in kernel-managed attribute namespaces. */ |
| 4434 | ssize_t nfs4_getxattr(struct dentry *dentry, const char *key, void *buf, |
| 4435 | size_t buflen) |
| 4436 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4437 | struct inode *inode = dentry->d_inode; |
| 4438 | |
| 4439 | if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0) |
| 4440 | return -EOPNOTSUPP; |
| 4441 | |
| 4442 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4443 | } |
| 4444 | |
| 4445 | ssize_t nfs4_listxattr(struct dentry *dentry, char *buf, size_t buflen) |
| 4446 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4447 | size_t len = strlen(XATTR_NAME_NFSV4_ACL) + 1; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4448 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4449 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4450 | return 0; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4451 | if (buf && buflen < len) |
| 4452 | return -ERANGE; |
| 4453 | if (buf) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4454 | memcpy(buf, XATTR_NAME_NFSV4_ACL, len); |
| 4455 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4456 | } |
| 4457 | |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4458 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4459 | { |
| 4460 | if (!((fattr->valid & NFS_ATTR_FATTR_FILEID) && |
| 4461 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
| 4462 | (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL))) |
| 4463 | return; |
| 4464 | |
| 4465 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 4466 | NFS_ATTR_FATTR_NLINK; |
| 4467 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4468 | fattr->nlink = 2; |
| 4469 | } |
| 4470 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 4471 | int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 4472 | struct nfs4_fs_locations *fs_locations, struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4473 | { |
| 4474 | struct nfs_server *server = NFS_SERVER(dir); |
| 4475 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4476 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 4477 | [1] = FATTR4_WORD1_MOUNTED_ON_FILEID, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4478 | }; |
| 4479 | struct nfs4_fs_locations_arg args = { |
| 4480 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4481 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4482 | .page = page, |
| 4483 | .bitmask = bitmask, |
| 4484 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4485 | struct nfs4_fs_locations_res res = { |
| 4486 | .fs_locations = fs_locations, |
| 4487 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4488 | struct rpc_message msg = { |
| 4489 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4490 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4491 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4492 | }; |
| 4493 | int status; |
| 4494 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4495 | dprintk("%s: start\n", __func__); |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4496 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4497 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 4498 | fs_locations->nlocations = 0; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 4499 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4500 | nfs_fixup_referral_attributes(&fs_locations->fattr); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4501 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4502 | return status; |
| 4503 | } |
| 4504 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4505 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4506 | /* |
| 4507 | * nfs4_proc_exchange_id() |
| 4508 | * |
| 4509 | * Since the clientid has expired, all compounds using sessions |
| 4510 | * associated with the stale clientid will be returning |
| 4511 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 4512 | * be in some phase of session reset. |
| 4513 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 4514 | 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] | 4515 | { |
| 4516 | nfs4_verifier verifier; |
| 4517 | struct nfs41_exchange_id_args args = { |
| 4518 | .client = clp, |
| 4519 | .flags = clp->cl_exchange_flags, |
| 4520 | }; |
| 4521 | struct nfs41_exchange_id_res res = { |
| 4522 | .client = clp, |
| 4523 | }; |
| 4524 | int status; |
| 4525 | struct rpc_message msg = { |
| 4526 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 4527 | .rpc_argp = &args, |
| 4528 | .rpc_resp = &res, |
| 4529 | .rpc_cred = cred, |
| 4530 | }; |
| 4531 | __be32 *p; |
| 4532 | |
| 4533 | dprintk("--> %s\n", __func__); |
| 4534 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 4535 | |
Alexandros Batsakis | 7b183d0 | 2009-12-05 13:33:25 -0500 | [diff] [blame] | 4536 | /* Remove server-only flags */ |
| 4537 | args.flags &= ~EXCHGID4_FLAG_CONFIRMED_R; |
| 4538 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4539 | p = (u32 *)verifier.data; |
| 4540 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 4541 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 4542 | args.verifier = &verifier; |
| 4543 | |
| 4544 | while (1) { |
| 4545 | args.id_len = scnprintf(args.id, sizeof(args.id), |
| 4546 | "%s/%s %u", |
| 4547 | clp->cl_ipaddr, |
| 4548 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4549 | RPC_DISPLAY_ADDR), |
| 4550 | clp->cl_id_uniquifier); |
| 4551 | |
| 4552 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 4553 | |
Andy Adamson | 180b62a | 2010-03-02 13:19:36 -0500 | [diff] [blame] | 4554 | if (status != -NFS4ERR_CLID_INUSE) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4555 | break; |
| 4556 | |
| 4557 | if (signalled()) |
| 4558 | break; |
| 4559 | |
| 4560 | if (++clp->cl_id_uniquifier == 0) |
| 4561 | break; |
| 4562 | } |
| 4563 | |
| 4564 | dprintk("<-- %s status= %d\n", __func__, status); |
| 4565 | return status; |
| 4566 | } |
| 4567 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4568 | struct nfs4_get_lease_time_data { |
| 4569 | struct nfs4_get_lease_time_args *args; |
| 4570 | struct nfs4_get_lease_time_res *res; |
| 4571 | struct nfs_client *clp; |
| 4572 | }; |
| 4573 | |
| 4574 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 4575 | void *calldata) |
| 4576 | { |
| 4577 | int ret; |
| 4578 | struct nfs4_get_lease_time_data *data = |
| 4579 | (struct nfs4_get_lease_time_data *)calldata; |
| 4580 | |
| 4581 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4582 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4583 | /* just setup sequence, do not trigger session recovery |
| 4584 | since we're invoked within one */ |
| 4585 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4586 | &data->args->la_seq_args, |
| 4587 | &data->res->lr_seq_res, 0, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4588 | |
| 4589 | BUG_ON(ret == -EAGAIN); |
| 4590 | rpc_call_start(task); |
| 4591 | dprintk("<-- %s\n", __func__); |
| 4592 | } |
| 4593 | |
| 4594 | /* |
| 4595 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 4596 | * from sequence operation or clientid errors. |
| 4597 | */ |
| 4598 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 4599 | { |
| 4600 | struct nfs4_get_lease_time_data *data = |
| 4601 | (struct nfs4_get_lease_time_data *)calldata; |
| 4602 | |
| 4603 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4604 | nfs41_sequence_done(&data->res->lr_seq_res); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4605 | switch (task->tk_status) { |
| 4606 | case -NFS4ERR_DELAY: |
| 4607 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 4608 | case -EKEYEXPIRED: |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4609 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 4610 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 4611 | task->tk_status = 0; |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 4612 | nfs_restart_rpc(task, data->clp); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4613 | return; |
| 4614 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4615 | dprintk("<-- %s\n", __func__); |
| 4616 | } |
| 4617 | |
| 4618 | struct rpc_call_ops nfs4_get_lease_time_ops = { |
| 4619 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 4620 | .rpc_call_done = nfs4_get_lease_time_done, |
| 4621 | }; |
| 4622 | |
| 4623 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 4624 | { |
| 4625 | struct rpc_task *task; |
| 4626 | struct nfs4_get_lease_time_args args; |
| 4627 | struct nfs4_get_lease_time_res res = { |
| 4628 | .lr_fsinfo = fsinfo, |
| 4629 | }; |
| 4630 | struct nfs4_get_lease_time_data data = { |
| 4631 | .args = &args, |
| 4632 | .res = &res, |
| 4633 | .clp = clp, |
| 4634 | }; |
| 4635 | struct rpc_message msg = { |
| 4636 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 4637 | .rpc_argp = &args, |
| 4638 | .rpc_resp = &res, |
| 4639 | }; |
| 4640 | struct rpc_task_setup task_setup = { |
| 4641 | .rpc_client = clp->cl_rpcclient, |
| 4642 | .rpc_message = &msg, |
| 4643 | .callback_ops = &nfs4_get_lease_time_ops, |
| 4644 | .callback_data = &data |
| 4645 | }; |
| 4646 | int status; |
| 4647 | |
| 4648 | res.lr_seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
| 4649 | dprintk("--> %s\n", __func__); |
| 4650 | task = rpc_run_task(&task_setup); |
| 4651 | |
| 4652 | if (IS_ERR(task)) |
| 4653 | status = PTR_ERR(task); |
| 4654 | else { |
| 4655 | status = task->tk_status; |
| 4656 | rpc_put_task(task); |
| 4657 | } |
| 4658 | dprintk("<-- %s return %d\n", __func__, status); |
| 4659 | |
| 4660 | return status; |
| 4661 | } |
| 4662 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4663 | /* |
| 4664 | * Reset a slot table |
| 4665 | */ |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4666 | static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 4667 | int ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4668 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4669 | struct nfs4_slot *new = NULL; |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4670 | int i; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4671 | int ret = 0; |
| 4672 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4673 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 4674 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4675 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4676 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 4677 | if (max_reqs != tbl->max_slots) { |
| 4678 | ret = -ENOMEM; |
| 4679 | new = kmalloc(max_reqs * sizeof(struct nfs4_slot), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4680 | GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4681 | if (!new) |
| 4682 | goto out; |
| 4683 | ret = 0; |
| 4684 | kfree(tbl->slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4685 | } |
| 4686 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4687 | if (new) { |
| 4688 | tbl->slots = new; |
| 4689 | tbl->max_slots = max_reqs; |
| 4690 | } |
| 4691 | for (i = 0; i < tbl->max_slots; ++i) |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4692 | tbl->slots[i].seq_nr = ivalue; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4693 | spin_unlock(&tbl->slot_tbl_lock); |
| 4694 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4695 | tbl, tbl->slots, tbl->max_slots); |
| 4696 | out: |
| 4697 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4698 | return ret; |
| 4699 | } |
| 4700 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4701 | /* |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4702 | * Reset the forechannel and backchannel slot tables |
| 4703 | */ |
| 4704 | static int nfs4_reset_slot_tables(struct nfs4_session *session) |
| 4705 | { |
| 4706 | int status; |
| 4707 | |
| 4708 | status = nfs4_reset_slot_table(&session->fc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4709 | session->fc_attrs.max_reqs, 1); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4710 | if (status) |
| 4711 | return status; |
| 4712 | |
| 4713 | status = nfs4_reset_slot_table(&session->bc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4714 | session->bc_attrs.max_reqs, 0); |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4715 | return status; |
| 4716 | } |
| 4717 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4718 | /* Destroy the slot table */ |
| 4719 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 4720 | { |
| 4721 | if (session->fc_slot_table.slots != NULL) { |
| 4722 | kfree(session->fc_slot_table.slots); |
| 4723 | session->fc_slot_table.slots = NULL; |
| 4724 | } |
| 4725 | if (session->bc_slot_table.slots != NULL) { |
| 4726 | kfree(session->bc_slot_table.slots); |
| 4727 | session->bc_slot_table.slots = NULL; |
| 4728 | } |
| 4729 | return; |
| 4730 | } |
| 4731 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4732 | /* |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4733 | * Initialize slot table |
| 4734 | */ |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4735 | static int nfs4_init_slot_table(struct nfs4_slot_table *tbl, |
| 4736 | int max_slots, int ivalue) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4737 | { |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4738 | struct nfs4_slot *slot; |
| 4739 | int ret = -ENOMEM; |
| 4740 | |
| 4741 | BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE); |
| 4742 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4743 | dprintk("--> %s: max_reqs=%u\n", __func__, max_slots); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4744 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4745 | slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4746 | if (!slot) |
| 4747 | goto out; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4748 | ret = 0; |
| 4749 | |
| 4750 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4751 | tbl->max_slots = max_slots; |
| 4752 | tbl->slots = slot; |
| 4753 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 4754 | spin_unlock(&tbl->slot_tbl_lock); |
| 4755 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4756 | tbl, tbl->slots, tbl->max_slots); |
| 4757 | out: |
| 4758 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4759 | return ret; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4760 | } |
| 4761 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4762 | /* |
| 4763 | * Initialize the forechannel and backchannel tables |
| 4764 | */ |
| 4765 | static int nfs4_init_slot_tables(struct nfs4_session *session) |
| 4766 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4767 | struct nfs4_slot_table *tbl; |
| 4768 | int status = 0; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4769 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4770 | tbl = &session->fc_slot_table; |
| 4771 | if (tbl->slots == NULL) { |
| 4772 | status = nfs4_init_slot_table(tbl, |
| 4773 | session->fc_attrs.max_reqs, 1); |
| 4774 | if (status) |
| 4775 | return status; |
| 4776 | } |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4777 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4778 | tbl = &session->bc_slot_table; |
| 4779 | if (tbl->slots == NULL) { |
| 4780 | status = nfs4_init_slot_table(tbl, |
| 4781 | session->bc_attrs.max_reqs, 0); |
| 4782 | if (status) |
| 4783 | nfs4_destroy_slot_tables(session); |
| 4784 | } |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4785 | |
| 4786 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4787 | } |
| 4788 | |
| 4789 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 4790 | { |
| 4791 | struct nfs4_session *session; |
| 4792 | struct nfs4_slot_table *tbl; |
| 4793 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4794 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4795 | if (!session) |
| 4796 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 4797 | |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 4798 | init_completion(&session->complete); |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 4799 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4800 | tbl = &session->fc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 4801 | tbl->highest_used_slotid = -1; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4802 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4803 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4804 | |
| 4805 | tbl = &session->bc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 4806 | tbl->highest_used_slotid = -1; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4807 | spin_lock_init(&tbl->slot_tbl_lock); |
| 4808 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
| 4809 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame^] | 4810 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 4811 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4812 | session->clp = clp; |
| 4813 | return session; |
| 4814 | } |
| 4815 | |
| 4816 | void nfs4_destroy_session(struct nfs4_session *session) |
| 4817 | { |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 4818 | nfs4_proc_destroy_session(session); |
| 4819 | dprintk("%s Destroy backchannel for xprt %p\n", |
| 4820 | __func__, session->clp->cl_rpcclient->cl_xprt); |
| 4821 | xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt, |
| 4822 | NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4823 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4824 | kfree(session); |
| 4825 | } |
| 4826 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4827 | /* |
| 4828 | * Initialize the values to be used by the client in CREATE_SESSION |
| 4829 | * If nfs4_init_session set the fore channel request and response sizes, |
| 4830 | * use them. |
| 4831 | * |
| 4832 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 4833 | * always set csa_cachethis to FALSE because the current implementation |
| 4834 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 4835 | */ |
| 4836 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 4837 | { |
| 4838 | struct nfs4_session *session = args->client->cl_session; |
| 4839 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 4840 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 4841 | |
| 4842 | if (mxrqst_sz == 0) |
| 4843 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 4844 | if (mxresp_sz == 0) |
| 4845 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 4846 | /* Fore channel attributes */ |
| 4847 | args->fc_attrs.headerpadsz = 0; |
| 4848 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 4849 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4850 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
| 4851 | args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs; |
| 4852 | |
| 4853 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 4854 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4855 | __func__, |
| 4856 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 4857 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4858 | |
| 4859 | /* Back channel attributes */ |
| 4860 | args->bc_attrs.headerpadsz = 0; |
| 4861 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 4862 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 4863 | args->bc_attrs.max_resp_sz_cached = 0; |
| 4864 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 4865 | args->bc_attrs.max_reqs = 1; |
| 4866 | |
| 4867 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 4868 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 4869 | __func__, |
| 4870 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 4871 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 4872 | args->bc_attrs.max_reqs); |
| 4873 | } |
| 4874 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4875 | static int _verify_channel_attr(char *chan, char *attr_name, u32 sent, u32 rcvd) |
| 4876 | { |
| 4877 | if (rcvd <= sent) |
| 4878 | return 0; |
| 4879 | printk(KERN_WARNING "%s: Session INVALID: %s channel %s increased. " |
| 4880 | "sent=%u rcvd=%u\n", __func__, chan, attr_name, sent, rcvd); |
| 4881 | return -EINVAL; |
| 4882 | } |
| 4883 | |
| 4884 | #define _verify_fore_channel_attr(_name_) \ |
| 4885 | _verify_channel_attr("fore", #_name_, \ |
| 4886 | args->fc_attrs._name_, \ |
| 4887 | session->fc_attrs._name_) |
| 4888 | |
| 4889 | #define _verify_back_channel_attr(_name_) \ |
| 4890 | _verify_channel_attr("back", #_name_, \ |
| 4891 | args->bc_attrs._name_, \ |
| 4892 | session->bc_attrs._name_) |
| 4893 | |
| 4894 | /* |
| 4895 | * The server is not allowed to increase the fore channel header pad size, |
| 4896 | * maximum response size, or maximum number of operations. |
| 4897 | * |
| 4898 | * The back channel attributes are only negotiatied down: We send what the |
| 4899 | * (back channel) server insists upon. |
| 4900 | */ |
| 4901 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 4902 | struct nfs4_session *session) |
| 4903 | { |
| 4904 | int ret = 0; |
| 4905 | |
| 4906 | ret |= _verify_fore_channel_attr(headerpadsz); |
| 4907 | ret |= _verify_fore_channel_attr(max_resp_sz); |
| 4908 | ret |= _verify_fore_channel_attr(max_ops); |
| 4909 | |
| 4910 | ret |= _verify_back_channel_attr(headerpadsz); |
| 4911 | ret |= _verify_back_channel_attr(max_rqst_sz); |
| 4912 | ret |= _verify_back_channel_attr(max_resp_sz); |
| 4913 | ret |= _verify_back_channel_attr(max_resp_sz_cached); |
| 4914 | ret |= _verify_back_channel_attr(max_ops); |
| 4915 | ret |= _verify_back_channel_attr(max_reqs); |
| 4916 | |
| 4917 | return ret; |
| 4918 | } |
| 4919 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4920 | static int _nfs4_proc_create_session(struct nfs_client *clp) |
| 4921 | { |
| 4922 | struct nfs4_session *session = clp->cl_session; |
| 4923 | struct nfs41_create_session_args args = { |
| 4924 | .client = clp, |
| 4925 | .cb_program = NFS4_CALLBACK, |
| 4926 | }; |
| 4927 | struct nfs41_create_session_res res = { |
| 4928 | .client = clp, |
| 4929 | }; |
| 4930 | struct rpc_message msg = { |
| 4931 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 4932 | .rpc_argp = &args, |
| 4933 | .rpc_resp = &res, |
| 4934 | }; |
| 4935 | int status; |
| 4936 | |
| 4937 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 4938 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4939 | |
| 4940 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); |
| 4941 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4942 | if (!status) |
| 4943 | /* Verify the session's negotiated channel_attrs values */ |
| 4944 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4945 | if (!status) { |
| 4946 | /* Increment the clientid slot sequence id */ |
| 4947 | clp->cl_seqid++; |
| 4948 | } |
| 4949 | |
| 4950 | return status; |
| 4951 | } |
| 4952 | |
| 4953 | /* |
| 4954 | * Issues a CREATE_SESSION operation to the server. |
| 4955 | * It is the responsibility of the caller to verify the session is |
| 4956 | * expired before calling this routine. |
| 4957 | */ |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4958 | int nfs4_proc_create_session(struct nfs_client *clp) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4959 | { |
| 4960 | int status; |
| 4961 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4962 | struct nfs4_session *session = clp->cl_session; |
| 4963 | |
| 4964 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 4965 | |
| 4966 | status = _nfs4_proc_create_session(clp); |
| 4967 | if (status) |
| 4968 | goto out; |
| 4969 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4970 | /* Init and reset the fore channel */ |
| 4971 | status = nfs4_init_slot_tables(session); |
| 4972 | dprintk("slot table initialization returned %d\n", status); |
| 4973 | if (status) |
| 4974 | goto out; |
| 4975 | status = nfs4_reset_slot_tables(session); |
| 4976 | dprintk("slot table reset returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4977 | if (status) |
| 4978 | goto out; |
| 4979 | |
| 4980 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 4981 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 4982 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4983 | out: |
| 4984 | dprintk("<-- %s\n", __func__); |
| 4985 | return status; |
| 4986 | } |
| 4987 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 4988 | /* |
| 4989 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 4990 | * The caller must serialize access to this routine. |
| 4991 | */ |
| 4992 | int nfs4_proc_destroy_session(struct nfs4_session *session) |
| 4993 | { |
| 4994 | int status = 0; |
| 4995 | struct rpc_message msg; |
| 4996 | |
| 4997 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 4998 | |
| 4999 | /* session is still being setup */ |
| 5000 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5001 | return status; |
| 5002 | |
| 5003 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; |
| 5004 | msg.rpc_argp = session; |
| 5005 | msg.rpc_resp = NULL; |
| 5006 | msg.rpc_cred = NULL; |
| 5007 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); |
| 5008 | |
| 5009 | if (status) |
| 5010 | printk(KERN_WARNING |
| 5011 | "Got error %d from the server on DESTROY_SESSION. " |
| 5012 | "Session has been destroyed regardless...\n", status); |
| 5013 | |
| 5014 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5015 | return status; |
| 5016 | } |
| 5017 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5018 | int nfs4_init_session(struct nfs_server *server) |
| 5019 | { |
| 5020 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5021 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5022 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5023 | int ret; |
| 5024 | |
| 5025 | if (!nfs4_has_session(clp)) |
| 5026 | return 0; |
| 5027 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame^] | 5028 | session = clp->cl_session; |
| 5029 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5030 | return 0; |
| 5031 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5032 | rsize = server->rsize; |
| 5033 | if (rsize == 0) |
| 5034 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5035 | wsize = server->wsize; |
| 5036 | if (wsize == 0) |
| 5037 | wsize = NFS_MAX_FILE_IO_SIZE; |
| 5038 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5039 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5040 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5041 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5042 | ret = nfs4_recover_expired_lease(server); |
| 5043 | if (!ret) |
| 5044 | ret = nfs4_check_client_ready(clp); |
| 5045 | return ret; |
| 5046 | } |
| 5047 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5048 | /* |
| 5049 | * Renew the cl_session lease. |
| 5050 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5051 | struct nfs4_sequence_data { |
| 5052 | struct nfs_client *clp; |
| 5053 | struct nfs4_sequence_args args; |
| 5054 | struct nfs4_sequence_res res; |
| 5055 | }; |
| 5056 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5057 | static void nfs41_sequence_release(void *data) |
| 5058 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5059 | struct nfs4_sequence_data *calldata = data; |
| 5060 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5061 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5062 | if (atomic_read(&clp->cl_count) > 1) |
| 5063 | nfs4_schedule_state_renewal(clp); |
| 5064 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5065 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5066 | } |
| 5067 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5068 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5069 | { |
| 5070 | switch(task->tk_status) { |
| 5071 | case -NFS4ERR_DELAY: |
| 5072 | case -EKEYEXPIRED: |
| 5073 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5074 | return -EAGAIN; |
| 5075 | default: |
| 5076 | nfs4_schedule_state_recovery(clp); |
| 5077 | } |
| 5078 | return 0; |
| 5079 | } |
| 5080 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5081 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5082 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5083 | struct nfs4_sequence_data *calldata = data; |
| 5084 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5085 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5086 | nfs41_sequence_done(task->tk_msg.rpc_resp); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5087 | |
| 5088 | if (task->tk_status < 0) { |
| 5089 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5090 | if (atomic_read(&clp->cl_count) == 1) |
| 5091 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5092 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5093 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5094 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5095 | return; |
| 5096 | } |
| 5097 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5098 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5099 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5100 | dprintk("<-- %s\n", __func__); |
| 5101 | } |
| 5102 | |
| 5103 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5104 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5105 | struct nfs4_sequence_data *calldata = data; |
| 5106 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5107 | struct nfs4_sequence_args *args; |
| 5108 | struct nfs4_sequence_res *res; |
| 5109 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5110 | args = task->tk_msg.rpc_argp; |
| 5111 | res = task->tk_msg.rpc_resp; |
| 5112 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5113 | if (nfs41_setup_sequence(clp->cl_session, args, res, 0, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5114 | return; |
| 5115 | rpc_call_start(task); |
| 5116 | } |
| 5117 | |
| 5118 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5119 | .rpc_call_done = nfs41_sequence_call_done, |
| 5120 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5121 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5122 | }; |
| 5123 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5124 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5125 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5126 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5127 | struct rpc_message msg = { |
| 5128 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5129 | .rpc_cred = cred, |
| 5130 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5131 | struct rpc_task_setup task_setup_data = { |
| 5132 | .rpc_client = clp->cl_rpcclient, |
| 5133 | .rpc_message = &msg, |
| 5134 | .callback_ops = &nfs41_sequence_ops, |
| 5135 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5136 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5137 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5138 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5139 | return ERR_PTR(-EIO); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5140 | calldata = kmalloc(sizeof(*calldata), GFP_NOFS); |
| 5141 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5142 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5143 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5144 | } |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5145 | calldata->res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
| 5146 | msg.rpc_argp = &calldata->args; |
| 5147 | msg.rpc_resp = &calldata->res; |
| 5148 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5149 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5150 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5151 | return rpc_run_task(&task_setup_data); |
| 5152 | } |
| 5153 | |
| 5154 | static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5155 | { |
| 5156 | struct rpc_task *task; |
| 5157 | int ret = 0; |
| 5158 | |
| 5159 | task = _nfs41_proc_sequence(clp, cred); |
| 5160 | if (IS_ERR(task)) |
| 5161 | ret = PTR_ERR(task); |
| 5162 | else |
| 5163 | rpc_put_task(task); |
| 5164 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5165 | return ret; |
| 5166 | } |
| 5167 | |
| 5168 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5169 | { |
| 5170 | struct rpc_task *task; |
| 5171 | int ret; |
| 5172 | |
| 5173 | task = _nfs41_proc_sequence(clp, cred); |
| 5174 | if (IS_ERR(task)) { |
| 5175 | ret = PTR_ERR(task); |
| 5176 | goto out; |
| 5177 | } |
| 5178 | ret = rpc_wait_for_completion_task(task); |
| 5179 | if (!ret) |
| 5180 | ret = task->tk_status; |
| 5181 | rpc_put_task(task); |
| 5182 | out: |
| 5183 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5184 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5185 | } |
| 5186 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5187 | struct nfs4_reclaim_complete_data { |
| 5188 | struct nfs_client *clp; |
| 5189 | struct nfs41_reclaim_complete_args arg; |
| 5190 | struct nfs41_reclaim_complete_res res; |
| 5191 | }; |
| 5192 | |
| 5193 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5194 | { |
| 5195 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5196 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5197 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5198 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5199 | &calldata->arg.seq_args, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5200 | &calldata->res.seq_res, 0, task)) |
| 5201 | return; |
| 5202 | |
| 5203 | rpc_call_start(task); |
| 5204 | } |
| 5205 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5206 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5207 | { |
| 5208 | switch(task->tk_status) { |
| 5209 | case 0: |
| 5210 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5211 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5212 | break; |
| 5213 | case -NFS4ERR_DELAY: |
| 5214 | case -EKEYEXPIRED: |
| 5215 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5216 | return -EAGAIN; |
| 5217 | default: |
| 5218 | nfs4_schedule_state_recovery(clp); |
| 5219 | } |
| 5220 | return 0; |
| 5221 | } |
| 5222 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5223 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5224 | { |
| 5225 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5226 | struct nfs_client *clp = calldata->clp; |
| 5227 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5228 | |
| 5229 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5230 | nfs41_sequence_done(res); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5231 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5232 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5233 | rpc_restart_call_prepare(task); |
| 5234 | return; |
| 5235 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5236 | dprintk("<-- %s\n", __func__); |
| 5237 | } |
| 5238 | |
| 5239 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5240 | { |
| 5241 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5242 | |
| 5243 | kfree(calldata); |
| 5244 | } |
| 5245 | |
| 5246 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5247 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5248 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5249 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5250 | }; |
| 5251 | |
| 5252 | /* |
| 5253 | * Issue a global reclaim complete. |
| 5254 | */ |
| 5255 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5256 | { |
| 5257 | struct nfs4_reclaim_complete_data *calldata; |
| 5258 | struct rpc_task *task; |
| 5259 | struct rpc_message msg = { |
| 5260 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5261 | }; |
| 5262 | struct rpc_task_setup task_setup_data = { |
| 5263 | .rpc_client = clp->cl_rpcclient, |
| 5264 | .rpc_message = &msg, |
| 5265 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5266 | .flags = RPC_TASK_ASYNC, |
| 5267 | }; |
| 5268 | int status = -ENOMEM; |
| 5269 | |
| 5270 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5271 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5272 | if (calldata == NULL) |
| 5273 | goto out; |
| 5274 | calldata->clp = clp; |
| 5275 | calldata->arg.one_fs = 0; |
| 5276 | calldata->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
| 5277 | |
| 5278 | msg.rpc_argp = &calldata->arg; |
| 5279 | msg.rpc_resp = &calldata->res; |
| 5280 | task_setup_data.callback_data = calldata; |
| 5281 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5282 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5283 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5284 | goto out; |
| 5285 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5286 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5287 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5288 | out: |
| 5289 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5290 | return status; |
| 5291 | } |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5292 | #endif /* CONFIG_NFS_V4_1 */ |
| 5293 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5294 | struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5295 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5296 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5297 | .recover_open = nfs4_open_reclaim, |
| 5298 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5299 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5300 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5301 | }; |
| 5302 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5303 | #if defined(CONFIG_NFS_V4_1) |
| 5304 | struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
| 5305 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 5306 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 5307 | .recover_open = nfs4_open_reclaim, |
| 5308 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5309 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5310 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5311 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5312 | }; |
| 5313 | #endif /* CONFIG_NFS_V4_1 */ |
| 5314 | |
| 5315 | struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5316 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5317 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5318 | .recover_open = nfs4_open_expired, |
| 5319 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5320 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5321 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5322 | }; |
| 5323 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5324 | #if defined(CONFIG_NFS_V4_1) |
| 5325 | struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
| 5326 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 5327 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
| 5328 | .recover_open = nfs4_open_expired, |
| 5329 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5330 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5331 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5332 | }; |
| 5333 | #endif /* CONFIG_NFS_V4_1 */ |
| 5334 | |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5335 | struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
| 5336 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5337 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5338 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5339 | }; |
| 5340 | |
| 5341 | #if defined(CONFIG_NFS_V4_1) |
| 5342 | struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
| 5343 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5344 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5345 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5346 | }; |
| 5347 | #endif |
| 5348 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5349 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 5350 | .minor_version = 0, |
| 5351 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5352 | .validate_stateid = nfs4_validate_delegation_stateid, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5353 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 5354 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 5355 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5356 | }; |
| 5357 | |
| 5358 | #if defined(CONFIG_NFS_V4_1) |
| 5359 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 5360 | .minor_version = 1, |
| 5361 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5362 | .validate_stateid = nfs41_validate_delegation_stateid, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5363 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 5364 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 5365 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5366 | }; |
| 5367 | #endif |
| 5368 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5369 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 5370 | [0] = &nfs_v4_0_minor_ops, |
| 5371 | #if defined(CONFIG_NFS_V4_1) |
| 5372 | [1] = &nfs_v4_1_minor_ops, |
| 5373 | #endif |
| 5374 | }; |
| 5375 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 5376 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5377 | .permission = nfs_permission, |
| 5378 | .getattr = nfs_getattr, |
| 5379 | .setattr = nfs_setattr, |
| 5380 | .getxattr = nfs4_getxattr, |
| 5381 | .setxattr = nfs4_setxattr, |
| 5382 | .listxattr = nfs4_listxattr, |
| 5383 | }; |
| 5384 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 5385 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5386 | .version = 4, /* protocol version */ |
| 5387 | .dentry_ops = &nfs4_dentry_operations, |
| 5388 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5389 | .file_inode_ops = &nfs4_file_inode_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5390 | .getroot = nfs4_proc_get_root, |
| 5391 | .getattr = nfs4_proc_getattr, |
| 5392 | .setattr = nfs4_proc_setattr, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5393 | .lookupfh = nfs4_proc_lookupfh, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5394 | .lookup = nfs4_proc_lookup, |
| 5395 | .access = nfs4_proc_access, |
| 5396 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5397 | .create = nfs4_proc_create, |
| 5398 | .remove = nfs4_proc_remove, |
| 5399 | .unlink_setup = nfs4_proc_unlink_setup, |
| 5400 | .unlink_done = nfs4_proc_unlink_done, |
| 5401 | .rename = nfs4_proc_rename, |
| 5402 | .link = nfs4_proc_link, |
| 5403 | .symlink = nfs4_proc_symlink, |
| 5404 | .mkdir = nfs4_proc_mkdir, |
| 5405 | .rmdir = nfs4_proc_remove, |
| 5406 | .readdir = nfs4_proc_readdir, |
| 5407 | .mknod = nfs4_proc_mknod, |
| 5408 | .statfs = nfs4_proc_statfs, |
| 5409 | .fsinfo = nfs4_proc_fsinfo, |
| 5410 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 5411 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5412 | .decode_dirent = nfs4_decode_dirent, |
| 5413 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5414 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5415 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5416 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5417 | .commit_setup = nfs4_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5418 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5419 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5420 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 5421 | .close_context = nfs4_close_context, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5422 | }; |
| 5423 | |
| 5424 | /* |
| 5425 | * Local variables: |
| 5426 | * c-basic-offset: 8 |
| 5427 | * End: |
| 5428 | */ |