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> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 52 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 53 | #include <linux/utsname.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 55 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 57 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 58 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 59 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 60 | #include "pnfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 63 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 64 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 66 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 67 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 68 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 69 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 70 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 71 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | 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] | 73 | 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] | 74 | static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
| 75 | 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] | 76 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 77 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 78 | struct nfs4_state *state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 81 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 83 | if (err >= -1000) |
| 84 | return err; |
| 85 | switch (err) { |
| 86 | case -NFS4ERR_RESOURCE: |
| 87 | return -EREMOTEIO; |
| 88 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 90 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 91 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 93 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /* |
| 97 | * This is our standard bitmap for GETATTR requests. |
| 98 | */ |
| 99 | const u32 nfs4_fattr_bitmap[2] = { |
| 100 | FATTR4_WORD0_TYPE |
| 101 | | FATTR4_WORD0_CHANGE |
| 102 | | FATTR4_WORD0_SIZE |
| 103 | | FATTR4_WORD0_FSID |
| 104 | | FATTR4_WORD0_FILEID, |
| 105 | FATTR4_WORD1_MODE |
| 106 | | FATTR4_WORD1_NUMLINKS |
| 107 | | FATTR4_WORD1_OWNER |
| 108 | | FATTR4_WORD1_OWNER_GROUP |
| 109 | | FATTR4_WORD1_RAWDEV |
| 110 | | FATTR4_WORD1_SPACE_USED |
| 111 | | FATTR4_WORD1_TIME_ACCESS |
| 112 | | FATTR4_WORD1_TIME_METADATA |
| 113 | | FATTR4_WORD1_TIME_MODIFY |
| 114 | }; |
| 115 | |
| 116 | const u32 nfs4_statfs_bitmap[2] = { |
| 117 | FATTR4_WORD0_FILES_AVAIL |
| 118 | | FATTR4_WORD0_FILES_FREE |
| 119 | | FATTR4_WORD0_FILES_TOTAL, |
| 120 | FATTR4_WORD1_SPACE_AVAIL |
| 121 | | FATTR4_WORD1_SPACE_FREE |
| 122 | | FATTR4_WORD1_SPACE_TOTAL |
| 123 | }; |
| 124 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 125 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | FATTR4_WORD0_MAXLINK |
| 127 | | FATTR4_WORD0_MAXNAME, |
| 128 | 0 |
| 129 | }; |
| 130 | |
| 131 | const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE |
| 132 | | FATTR4_WORD0_MAXREAD |
| 133 | | FATTR4_WORD0_MAXWRITE |
| 134 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 135 | FATTR4_WORD1_TIME_DELTA |
Andy Adamson | 504913f | 2010-10-20 00:17:57 -0400 | [diff] [blame] | 136 | | FATTR4_WORD1_FS_LAYOUT_TYPES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | }; |
| 138 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 139 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 140 | FATTR4_WORD0_TYPE |
| 141 | | FATTR4_WORD0_CHANGE |
| 142 | | FATTR4_WORD0_SIZE |
| 143 | | FATTR4_WORD0_FSID |
| 144 | | FATTR4_WORD0_FILEID |
| 145 | | FATTR4_WORD0_FS_LOCATIONS, |
| 146 | FATTR4_WORD1_MODE |
| 147 | | FATTR4_WORD1_NUMLINKS |
| 148 | | FATTR4_WORD1_OWNER |
| 149 | | FATTR4_WORD1_OWNER_GROUP |
| 150 | | FATTR4_WORD1_RAWDEV |
| 151 | | FATTR4_WORD1_SPACE_USED |
| 152 | | FATTR4_WORD1_TIME_ACCESS |
| 153 | | FATTR4_WORD1_TIME_METADATA |
| 154 | | FATTR4_WORD1_TIME_MODIFY |
| 155 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 156 | }; |
| 157 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 158 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | struct nfs4_readdir_arg *readdir) |
| 160 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 161 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
| 163 | BUG_ON(readdir->count < 80); |
| 164 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 165 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 167 | return; |
| 168 | } |
| 169 | |
| 170 | readdir->cookie = 0; |
| 171 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 172 | if (cookie == 2) |
| 173 | return; |
| 174 | |
| 175 | /* |
| 176 | * NFSv4 servers do not return entries for '.' and '..' |
| 177 | * Therefore, we fake these entries here. We let '.' |
| 178 | * have cookie 0 and '..' have cookie 1. Note that |
| 179 | * when talking to the server, we always send cookie 0 |
| 180 | * instead of 1 or 2. |
| 181 | */ |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 182 | start = p = kmap_atomic(*readdir->pages, KM_USER0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
| 184 | if (cookie == 0) { |
| 185 | *p++ = xdr_one; /* next */ |
| 186 | *p++ = xdr_zero; /* cookie, first word */ |
| 187 | *p++ = xdr_one; /* cookie, second word */ |
| 188 | *p++ = xdr_one; /* entry len */ |
| 189 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 190 | p++; |
| 191 | *p++ = xdr_one; /* bitmap length */ |
| 192 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 193 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 194 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | *p++ = xdr_one; /* next */ |
| 198 | *p++ = xdr_zero; /* cookie, first word */ |
| 199 | *p++ = xdr_two; /* cookie, second word */ |
| 200 | *p++ = xdr_two; /* entry len */ |
| 201 | memcpy(p, "..\0\0", 4); /* entry */ |
| 202 | p++; |
| 203 | *p++ = xdr_one; /* bitmap length */ |
| 204 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 205 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 206 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
| 208 | readdir->pgbase = (char *)p - (char *)start; |
| 209 | readdir->count -= readdir->pgbase; |
| 210 | kunmap_atomic(start, KM_USER0); |
| 211 | } |
| 212 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 213 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 214 | { |
| 215 | int res; |
| 216 | |
| 217 | might_sleep(); |
| 218 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 219 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 220 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 221 | return res; |
| 222 | } |
| 223 | |
| 224 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 225 | { |
| 226 | int res = 0; |
| 227 | |
| 228 | might_sleep(); |
| 229 | |
| 230 | if (*timeout <= 0) |
| 231 | *timeout = NFS4_POLL_RETRY_MIN; |
| 232 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 233 | *timeout = NFS4_POLL_RETRY_MAX; |
| 234 | schedule_timeout_killable(*timeout); |
| 235 | if (fatal_signal_pending(current)) |
| 236 | res = -ERESTARTSYS; |
| 237 | *timeout <<= 1; |
| 238 | return res; |
| 239 | } |
| 240 | |
| 241 | /* This is the error handling routine for processes that are allowed |
| 242 | * to sleep. |
| 243 | */ |
| 244 | static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 245 | { |
| 246 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 247 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 248 | int ret = errorcode; |
| 249 | |
| 250 | exception->retry = 0; |
| 251 | switch(errorcode) { |
| 252 | case 0: |
| 253 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 254 | case -NFS4ERR_ADMIN_REVOKED: |
| 255 | case -NFS4ERR_BAD_STATEID: |
| 256 | case -NFS4ERR_OPENMODE: |
| 257 | if (state == NULL) |
| 258 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 259 | nfs4_schedule_stateid_recovery(server, state); |
| 260 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 261 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 262 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 263 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 264 | nfs4_schedule_lease_recovery(clp); |
| 265 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 266 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 267 | case -NFS4ERR_BADSESSION: |
| 268 | case -NFS4ERR_BADSLOT: |
| 269 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 270 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 271 | case -NFS4ERR_DEADSESSION: |
| 272 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 273 | case -NFS4ERR_SEQ_MISORDERED: |
| 274 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 275 | errorcode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 276 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 277 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 278 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 279 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 280 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 281 | if (exception->timeout > HZ) { |
| 282 | /* We have retried a decent amount, time to |
| 283 | * fail |
| 284 | */ |
| 285 | ret = -EBUSY; |
| 286 | break; |
| 287 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 288 | case -NFS4ERR_GRACE: |
| 289 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 290 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 291 | ret = nfs4_delay(server->client, &exception->timeout); |
| 292 | if (ret != 0) |
| 293 | break; |
| 294 | case -NFS4ERR_OLD_STATEID: |
| 295 | exception->retry = 1; |
| 296 | } |
| 297 | /* We failed to handle the error */ |
| 298 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 299 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 300 | ret = nfs4_wait_clnt_recover(clp); |
| 301 | if (ret == 0) |
| 302 | exception->retry = 1; |
| 303 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 307 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | { |
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 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 315 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 316 | { |
| 317 | do_renew_lease(server->nfs_client, timestamp); |
| 318 | } |
| 319 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 320 | #if defined(CONFIG_NFS_V4_1) |
| 321 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 322 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 323 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 324 | * |
| 325 | * freeing a slot is trivially done by clearing its respective bit |
| 326 | * in the bitmap. |
| 327 | * If the freed slotid equals highest_used_slotid we want to update it |
| 328 | * so that the server would be able to size down the slot table if needed, |
| 329 | * otherwise we know that the highest_used_slotid is still in use. |
| 330 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 331 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 332 | * highest slotid in use. |
| 333 | * If none found, highest_used_slotid is set to -1. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 334 | * |
| 335 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 336 | */ |
| 337 | static void |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 338 | nfs4_free_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *free_slot) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 339 | { |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 340 | int free_slotid = free_slot - tbl->slots; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 341 | int slotid = free_slotid; |
| 342 | |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 343 | BUG_ON(slotid < 0 || slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 344 | /* clear used bit in bitmap */ |
| 345 | __clear_bit(slotid, tbl->used_slots); |
| 346 | |
| 347 | /* update highest_used_slotid when it is freed */ |
| 348 | if (slotid == tbl->highest_used_slotid) { |
| 349 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 350 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 351 | tbl->highest_used_slotid = slotid; |
| 352 | else |
| 353 | tbl->highest_used_slotid = -1; |
| 354 | } |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 355 | dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__, |
| 356 | free_slotid, tbl->highest_used_slotid); |
| 357 | } |
| 358 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 359 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 360 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 361 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 362 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 363 | { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 364 | struct rpc_task *task; |
| 365 | |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 366 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 367 | task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq); |
| 368 | if (task) |
| 369 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 370 | return; |
| 371 | } |
| 372 | |
| 373 | if (ses->fc_slot_table.highest_used_slotid != -1) |
| 374 | return; |
| 375 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 376 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 377 | complete(&ses->fc_slot_table.complete); |
| 378 | } |
| 379 | |
| 380 | /* |
| 381 | * Signal state manager thread if session back channel is drained |
| 382 | */ |
| 383 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 384 | { |
| 385 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
| 386 | ses->bc_slot_table.highest_used_slotid != -1) |
| 387 | return; |
| 388 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 389 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 390 | } |
| 391 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 392 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 393 | { |
| 394 | struct nfs4_slot_table *tbl; |
| 395 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 396 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 397 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 398 | /* just wake up the next guy waiting since |
| 399 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 400 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 401 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 402 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 403 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 404 | spin_lock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 405 | nfs4_free_slot(tbl, res->sr_slot); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 406 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 407 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 408 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 409 | } |
| 410 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 411 | static int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 412 | { |
| 413 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 414 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 415 | |
| 416 | /* |
| 417 | * sr_status remains 1 if an RPC level error occurred. The server |
| 418 | * may or may not have processed the sequence operation.. |
| 419 | * Proceed as if the server received and processed the sequence |
| 420 | * operation. |
| 421 | */ |
| 422 | if (res->sr_status == 1) |
| 423 | res->sr_status = NFS_OK; |
| 424 | |
| 425 | /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */ |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 426 | if (!res->sr_slot) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 427 | goto out; |
| 428 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 429 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 430 | switch (res->sr_status) { |
| 431 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 432 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 433 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 434 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 435 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 436 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 437 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 438 | if (res->sr_status_flags != 0) |
| 439 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 440 | break; |
| 441 | case -NFS4ERR_DELAY: |
| 442 | /* The server detected a resend of the RPC call and |
| 443 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 444 | * of RFC5661. |
| 445 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 446 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 447 | __func__, |
| 448 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 449 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 450 | goto out_retry; |
| 451 | default: |
| 452 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 453 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 454 | } |
| 455 | out: |
| 456 | /* The session may be reset by one of the error handlers. */ |
| 457 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 458 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 459 | return 1; |
| 460 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 461 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 462 | goto out; |
| 463 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 464 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 465 | } |
| 466 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 467 | static int nfs4_sequence_done(struct rpc_task *task, |
| 468 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 469 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 470 | if (res->sr_session == NULL) |
| 471 | return 1; |
| 472 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 473 | } |
| 474 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 475 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 476 | * nfs4_find_slot - efficiently look for a free slot |
| 477 | * |
| 478 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 479 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 480 | * and respectively set up the sequence operation args. |
| 481 | * 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] | 482 | * |
| 483 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 484 | */ |
| 485 | static u8 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 486 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 487 | { |
| 488 | int slotid; |
| 489 | u8 ret_id = NFS4_MAX_SLOT_TABLE; |
| 490 | BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE); |
| 491 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 492 | dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n", |
| 493 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 494 | tbl->max_slots); |
| 495 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 496 | if (slotid >= tbl->max_slots) |
| 497 | goto out; |
| 498 | __set_bit(slotid, tbl->used_slots); |
| 499 | if (slotid > tbl->highest_used_slotid) |
| 500 | tbl->highest_used_slotid = slotid; |
| 501 | ret_id = slotid; |
| 502 | out: |
| 503 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 504 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 505 | return ret_id; |
| 506 | } |
| 507 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 508 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 509 | struct nfs4_sequence_args *args, |
| 510 | struct nfs4_sequence_res *res, |
| 511 | int cache_reply, |
| 512 | struct rpc_task *task) |
| 513 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 514 | struct nfs4_slot *slot; |
| 515 | struct nfs4_slot_table *tbl; |
| 516 | u8 slotid; |
| 517 | |
| 518 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 519 | /* slot already allocated? */ |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 520 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 521 | return 0; |
| 522 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 523 | tbl = &session->fc_slot_table; |
| 524 | |
| 525 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 526 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 527 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 528 | /* |
| 529 | * The state manager will wait until the slot table is empty. |
| 530 | * Schedule the reset thread |
| 531 | */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 532 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 533 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 534 | dprintk("%s Schedule Session Reset\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 535 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 536 | } |
| 537 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 538 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 539 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 540 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 541 | spin_unlock(&tbl->slot_tbl_lock); |
| 542 | dprintk("%s enforce FIFO order\n", __func__); |
| 543 | return -EAGAIN; |
| 544 | } |
| 545 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 546 | slotid = nfs4_find_slot(tbl); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 547 | if (slotid == NFS4_MAX_SLOT_TABLE) { |
| 548 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 549 | spin_unlock(&tbl->slot_tbl_lock); |
| 550 | dprintk("<-- %s: no free slots\n", __func__); |
| 551 | return -EAGAIN; |
| 552 | } |
| 553 | spin_unlock(&tbl->slot_tbl_lock); |
| 554 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 555 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 556 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 557 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 558 | args->sa_slotid = slotid; |
| 559 | args->sa_cache_this = cache_reply; |
| 560 | |
| 561 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 562 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 563 | res->sr_session = session; |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 564 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 565 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 566 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 567 | /* |
| 568 | * sr_status is only set in decode_sequence, and so will remain |
| 569 | * set to 1 if an rpc level failure occurs. |
| 570 | */ |
| 571 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 572 | return 0; |
| 573 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 574 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 575 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 576 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 577 | struct nfs4_sequence_args *args, |
| 578 | struct nfs4_sequence_res *res, |
| 579 | int cache_reply, |
| 580 | struct rpc_task *task) |
| 581 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 582 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 583 | int ret = 0; |
| 584 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 585 | if (session == NULL) { |
| 586 | args->sa_session = NULL; |
| 587 | res->sr_session = NULL; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 588 | goto out; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 589 | } |
| 590 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 591 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 592 | __func__, session->clp, session, res->sr_slot ? |
| 593 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 594 | |
| 595 | ret = nfs41_setup_sequence(session, args, res, cache_reply, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 596 | task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 597 | out: |
| 598 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 599 | return ret; |
| 600 | } |
| 601 | |
| 602 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 603 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 604 | struct nfs4_sequence_args *seq_args; |
| 605 | struct nfs4_sequence_res *seq_res; |
| 606 | int cache_reply; |
| 607 | }; |
| 608 | |
| 609 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 610 | { |
| 611 | struct nfs41_call_sync_data *data = calldata; |
| 612 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 613 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 614 | |
| 615 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 616 | data->seq_res, data->cache_reply, task)) |
| 617 | return; |
| 618 | rpc_call_start(task); |
| 619 | } |
| 620 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 621 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 622 | { |
| 623 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 624 | nfs41_call_sync_prepare(task, calldata); |
| 625 | } |
| 626 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 627 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 628 | { |
| 629 | struct nfs41_call_sync_data *data = calldata; |
| 630 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 631 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 632 | } |
| 633 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 634 | struct rpc_call_ops nfs41_call_sync_ops = { |
| 635 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 636 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 637 | }; |
| 638 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 639 | struct rpc_call_ops nfs41_call_priv_sync_ops = { |
| 640 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 641 | .rpc_call_done = nfs41_call_sync_done, |
| 642 | }; |
| 643 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 644 | static int nfs4_call_sync_sequence(struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 645 | struct rpc_message *msg, |
| 646 | struct nfs4_sequence_args *args, |
| 647 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 648 | int cache_reply, |
| 649 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 650 | { |
| 651 | int ret; |
| 652 | struct rpc_task *task; |
| 653 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 654 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 655 | .seq_args = args, |
| 656 | .seq_res = res, |
| 657 | .cache_reply = cache_reply, |
| 658 | }; |
| 659 | struct rpc_task_setup task_setup = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 660 | .rpc_client = server->client, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 661 | .rpc_message = msg, |
| 662 | .callback_ops = &nfs41_call_sync_ops, |
| 663 | .callback_data = &data |
| 664 | }; |
| 665 | |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 666 | res->sr_slot = NULL; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 667 | if (privileged) |
| 668 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 669 | task = rpc_run_task(&task_setup); |
| 670 | if (IS_ERR(task)) |
| 671 | ret = PTR_ERR(task); |
| 672 | else { |
| 673 | ret = task->tk_status; |
| 674 | rpc_put_task(task); |
| 675 | } |
| 676 | return ret; |
| 677 | } |
| 678 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 679 | int _nfs4_call_sync_session(struct nfs_server *server, |
| 680 | struct rpc_message *msg, |
| 681 | struct nfs4_sequence_args *args, |
| 682 | struct nfs4_sequence_res *res, |
| 683 | int cache_reply) |
| 684 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 685 | return nfs4_call_sync_sequence(server, msg, args, res, cache_reply, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 686 | } |
| 687 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 688 | #else |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 689 | static int nfs4_sequence_done(struct rpc_task *task, |
| 690 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 691 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 692 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 693 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 694 | #endif /* CONFIG_NFS_V4_1 */ |
| 695 | |
| 696 | int _nfs4_call_sync(struct nfs_server *server, |
| 697 | struct rpc_message *msg, |
| 698 | struct nfs4_sequence_args *args, |
| 699 | struct nfs4_sequence_res *res, |
| 700 | int cache_reply) |
| 701 | { |
Benny Halevy | f375297 | 2009-04-01 09:22:04 -0400 | [diff] [blame] | 702 | args->sa_session = res->sr_session = NULL; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 703 | return rpc_call_sync(server->client, msg, 0); |
| 704 | } |
| 705 | |
| 706 | #define nfs4_call_sync(server, msg, args, res, cache_reply) \ |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 707 | (server)->nfs_client->cl_mvops->call_sync((server), (msg), &(args)->seq_args, \ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 708 | &(res)->seq_res, (cache_reply)) |
| 709 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 710 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 712 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 714 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 715 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA; |
| 716 | if (!cinfo->atomic || cinfo->before != nfsi->change_attr) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 717 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 718 | nfsi->change_attr = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 719 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | } |
| 721 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 722 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 723 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 724 | struct nfs_openargs o_arg; |
| 725 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 726 | struct nfs_open_confirmargs c_arg; |
| 727 | struct nfs_open_confirmres c_res; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 728 | struct nfs_fattr f_attr; |
| 729 | struct nfs_fattr dir_attr; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 730 | struct path path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 731 | struct dentry *dir; |
| 732 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 733 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 734 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 735 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 736 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 737 | int rpc_status; |
| 738 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 739 | }; |
| 740 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 741 | |
| 742 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 743 | { |
| 744 | p->o_res.f_attr = &p->f_attr; |
| 745 | p->o_res.dir_attr = &p->dir_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 746 | p->o_res.seqid = p->o_arg.seqid; |
| 747 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 748 | p->o_res.server = p->o_arg.server; |
| 749 | nfs_fattr_init(&p->f_attr); |
| 750 | nfs_fattr_init(&p->dir_attr); |
| 751 | } |
| 752 | |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 753 | static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 754 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 755 | const struct iattr *attrs, |
| 756 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 757 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 758 | struct dentry *parent = dget_parent(path->dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 759 | struct inode *dir = parent->d_inode; |
| 760 | struct nfs_server *server = NFS_SERVER(dir); |
| 761 | struct nfs4_opendata *p; |
| 762 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 763 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 764 | if (p == NULL) |
| 765 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 766 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 767 | if (p->o_arg.seqid == NULL) |
| 768 | goto err_free; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 769 | path_get(path); |
| 770 | p->path = *path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 771 | p->dir = parent; |
| 772 | p->owner = sp; |
| 773 | atomic_inc(&sp->so_count); |
| 774 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 775 | p->o_arg.open_flags = flags; |
| 776 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 777 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 778 | p->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 779 | p->o_arg.name = &p->path.dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 780 | p->o_arg.server = server; |
| 781 | p->o_arg.bitmask = server->attr_bitmask; |
| 782 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 783 | if (flags & O_CREAT) { |
| 784 | u32 *s; |
| 785 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 786 | p->o_arg.u.attrs = &p->attrs; |
| 787 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 788 | s = (u32 *) p->o_arg.u.verifier.data; |
| 789 | s[0] = jiffies; |
| 790 | s[1] = current->pid; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 791 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 792 | p->c_arg.fh = &p->o_res.fh; |
| 793 | p->c_arg.stateid = &p->o_res.stateid; |
| 794 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 795 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 796 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 797 | return p; |
| 798 | err_free: |
| 799 | kfree(p); |
| 800 | err: |
| 801 | dput(parent); |
| 802 | return NULL; |
| 803 | } |
| 804 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 805 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 806 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 807 | struct nfs4_opendata *p = container_of(kref, |
| 808 | struct nfs4_opendata, kref); |
| 809 | |
| 810 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 811 | if (p->state != NULL) |
| 812 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 813 | nfs4_put_state_owner(p->owner); |
| 814 | dput(p->dir); |
Jan Blunck | 31f31db | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 815 | path_put(&p->path); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 816 | kfree(p); |
| 817 | } |
| 818 | |
| 819 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 820 | { |
| 821 | if (p != NULL) |
| 822 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 823 | } |
| 824 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 825 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 826 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 827 | int ret; |
| 828 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 829 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 830 | return ret; |
| 831 | } |
| 832 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 833 | 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] | 834 | { |
| 835 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 836 | |
| 837 | if (open_mode & O_EXCL) |
| 838 | goto out; |
| 839 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 840 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 841 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 842 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 843 | break; |
| 844 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 845 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 846 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 847 | break; |
| 848 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 849 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 850 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 851 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 852 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 853 | return ret; |
| 854 | } |
| 855 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 856 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 857 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 858 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 859 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 860 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 861 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 862 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 863 | return 1; |
| 864 | } |
| 865 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 866 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 867 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 868 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 869 | case FMODE_WRITE: |
| 870 | state->n_wronly++; |
| 871 | break; |
| 872 | case FMODE_READ: |
| 873 | state->n_rdonly++; |
| 874 | break; |
| 875 | case FMODE_READ|FMODE_WRITE: |
| 876 | state->n_rdwr++; |
| 877 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 878 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 879 | } |
| 880 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 881 | 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] | 882 | { |
| 883 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 884 | memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); |
| 885 | memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 886 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 887 | case FMODE_READ: |
| 888 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 889 | break; |
| 890 | case FMODE_WRITE: |
| 891 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 892 | break; |
| 893 | case FMODE_READ|FMODE_WRITE: |
| 894 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 895 | } |
| 896 | } |
| 897 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 898 | 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] | 899 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 900 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 901 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 902 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 903 | } |
| 904 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 905 | 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] | 906 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 907 | /* |
| 908 | * Protect the call to nfs4_state_set_mode_locked and |
| 909 | * serialise the stateid update |
| 910 | */ |
| 911 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 912 | if (deleg_stateid != NULL) { |
| 913 | memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); |
| 914 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 915 | } |
| 916 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 917 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 918 | write_sequnlock(&state->seqlock); |
| 919 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 920 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 921 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | } |
| 923 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 924 | 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] | 925 | { |
| 926 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 927 | struct nfs_delegation *deleg_cur; |
| 928 | int ret = 0; |
| 929 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 930 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 931 | |
| 932 | rcu_read_lock(); |
| 933 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 934 | if (deleg_cur == NULL) |
| 935 | goto no_delegation; |
| 936 | |
| 937 | spin_lock(&deleg_cur->lock); |
| 938 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 939 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 940 | goto no_delegation_unlock; |
| 941 | |
| 942 | if (delegation == NULL) |
| 943 | delegation = &deleg_cur->stateid; |
| 944 | else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) |
| 945 | goto no_delegation_unlock; |
| 946 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 947 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 948 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 949 | ret = 1; |
| 950 | no_delegation_unlock: |
| 951 | spin_unlock(&deleg_cur->lock); |
| 952 | no_delegation: |
| 953 | rcu_read_unlock(); |
| 954 | |
| 955 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 956 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 957 | ret = 1; |
| 958 | } |
| 959 | |
| 960 | return ret; |
| 961 | } |
| 962 | |
| 963 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 964 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 965 | { |
| 966 | struct nfs_delegation *delegation; |
| 967 | |
| 968 | rcu_read_lock(); |
| 969 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 970 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 971 | rcu_read_unlock(); |
| 972 | return; |
| 973 | } |
| 974 | rcu_read_unlock(); |
| 975 | nfs_inode_return_delegation(inode); |
| 976 | } |
| 977 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 978 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 979 | { |
| 980 | struct nfs4_state *state = opendata->state; |
| 981 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 982 | struct nfs_delegation *delegation; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 983 | int open_mode = opendata->o_arg.open_flags & O_EXCL; |
| 984 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 985 | nfs4_stateid stateid; |
| 986 | int ret = -EAGAIN; |
| 987 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 988 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 989 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 990 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 991 | if (can_open_cached(state, fmode, open_mode)) { |
| 992 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 993 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 994 | goto out_return_state; |
| 995 | } |
| 996 | spin_unlock(&state->owner->so_lock); |
| 997 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 998 | rcu_read_lock(); |
| 999 | delegation = rcu_dereference(nfsi->delegation); |
| 1000 | if (delegation == NULL || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1001 | !can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1002 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1003 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1004 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1005 | /* Save the delegation */ |
| 1006 | memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); |
| 1007 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1008 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1009 | if (ret != 0) |
| 1010 | goto out; |
| 1011 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1012 | |
| 1013 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1014 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1015 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1016 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1017 | out: |
| 1018 | return ERR_PTR(ret); |
| 1019 | out_return_state: |
| 1020 | atomic_inc(&state->count); |
| 1021 | return state; |
| 1022 | } |
| 1023 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1024 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1025 | { |
| 1026 | struct inode *inode; |
| 1027 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1028 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1029 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1030 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1031 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1032 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1033 | goto out; |
| 1034 | } |
| 1035 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1036 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1037 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1038 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1039 | 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] | 1040 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1041 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1042 | goto err; |
| 1043 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1044 | state = nfs4_get_open_state(inode, data->owner); |
| 1045 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1046 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1047 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1048 | int delegation_flags = 0; |
| 1049 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1050 | rcu_read_lock(); |
| 1051 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1052 | if (delegation) |
| 1053 | delegation_flags = delegation->flags; |
| 1054 | rcu_read_unlock(); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1055 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1056 | nfs_inode_set_delegation(state->inode, |
| 1057 | data->owner->so_cred, |
| 1058 | &data->o_res); |
| 1059 | else |
| 1060 | nfs_inode_reclaim_delegation(state->inode, |
| 1061 | data->owner->so_cred, |
| 1062 | &data->o_res); |
| 1063 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1064 | |
| 1065 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1066 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1067 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1068 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1069 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1070 | err_put_inode: |
| 1071 | iput(inode); |
| 1072 | err: |
| 1073 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1074 | } |
| 1075 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1076 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1077 | { |
| 1078 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1079 | struct nfs_open_context *ctx; |
| 1080 | |
| 1081 | spin_lock(&state->inode->i_lock); |
| 1082 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1083 | if (ctx->state != state) |
| 1084 | continue; |
| 1085 | get_nfs_open_context(ctx); |
| 1086 | spin_unlock(&state->inode->i_lock); |
| 1087 | return ctx; |
| 1088 | } |
| 1089 | spin_unlock(&state->inode->i_lock); |
| 1090 | return ERR_PTR(-ENOENT); |
| 1091 | } |
| 1092 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1093 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1094 | { |
| 1095 | struct nfs4_opendata *opendata; |
| 1096 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1097 | 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] | 1098 | if (opendata == NULL) |
| 1099 | return ERR_PTR(-ENOMEM); |
| 1100 | opendata->state = state; |
| 1101 | atomic_inc(&state->count); |
| 1102 | return opendata; |
| 1103 | } |
| 1104 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1105 | 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] | 1106 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1107 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1108 | int ret; |
| 1109 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1110 | opendata->o_arg.open_flags = 0; |
| 1111 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1112 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1113 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1114 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1115 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1116 | if (ret != 0) |
| 1117 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1118 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1119 | if (IS_ERR(newstate)) |
| 1120 | return PTR_ERR(newstate); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1121 | nfs4_close_state(&opendata->path, newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1122 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1123 | return 0; |
| 1124 | } |
| 1125 | |
| 1126 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1127 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1128 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1129 | int ret; |
| 1130 | |
| 1131 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1132 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1133 | smp_rmb(); |
| 1134 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1135 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1136 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1137 | if (ret != 0) |
| 1138 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1139 | if (newstate != state) |
| 1140 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1141 | } |
| 1142 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1143 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1144 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1145 | if (ret != 0) |
| 1146 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1147 | if (newstate != state) |
| 1148 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1149 | } |
| 1150 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1151 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1152 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1153 | if (ret != 0) |
| 1154 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1155 | if (newstate != state) |
| 1156 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1157 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1158 | /* |
| 1159 | * We may have performed cached opens for all three recoveries. |
| 1160 | * Check if we need to update the current stateid. |
| 1161 | */ |
| 1162 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
| 1163 | 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] | 1164 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1165 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1166 | memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1167 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1168 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1169 | return 0; |
| 1170 | } |
| 1171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | /* |
| 1173 | * OPEN_RECLAIM: |
| 1174 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1176 | 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] | 1177 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1178 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1179 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1180 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | int status; |
| 1182 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1183 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1184 | if (IS_ERR(opendata)) |
| 1185 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1186 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1187 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1188 | rcu_read_lock(); |
| 1189 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1190 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1191 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1192 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1193 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1194 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1195 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | return status; |
| 1197 | } |
| 1198 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1199 | 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] | 1200 | { |
| 1201 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1202 | struct nfs4_exception exception = { }; |
| 1203 | int err; |
| 1204 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1205 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1206 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1207 | break; |
| 1208 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | } while (exception.retry); |
| 1210 | return err; |
| 1211 | } |
| 1212 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1213 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1214 | { |
| 1215 | struct nfs_open_context *ctx; |
| 1216 | int ret; |
| 1217 | |
| 1218 | ctx = nfs4_state_find_open_context(state); |
| 1219 | if (IS_ERR(ctx)) |
| 1220 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1221 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1222 | put_nfs_open_context(ctx); |
| 1223 | return ret; |
| 1224 | } |
| 1225 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1226 | 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] | 1227 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1228 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1229 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1231 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1232 | if (IS_ERR(opendata)) |
| 1233 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1234 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1235 | memcpy(opendata->o_arg.u.delegation.data, stateid->data, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1236 | sizeof(opendata->o_arg.u.delegation.data)); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1237 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1238 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1239 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | } |
| 1241 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1242 | 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] | 1243 | { |
| 1244 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1245 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | int err; |
| 1247 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1248 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | switch (err) { |
| 1250 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1251 | case -ENOENT: |
| 1252 | case -ESTALE: |
| 1253 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1254 | case -NFS4ERR_BADSESSION: |
| 1255 | case -NFS4ERR_BADSLOT: |
| 1256 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1257 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1258 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1259 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1260 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | case -NFS4ERR_STALE_CLIENTID: |
| 1262 | case -NFS4ERR_STALE_STATEID: |
| 1263 | case -NFS4ERR_EXPIRED: |
| 1264 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1265 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1266 | goto out; |
| 1267 | case -ERESTARTSYS: |
| 1268 | /* |
| 1269 | * The show must go on: exit, but mark the |
| 1270 | * stateid as needing recovery. |
| 1271 | */ |
| 1272 | case -NFS4ERR_ADMIN_REVOKED: |
| 1273 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1274 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1275 | case -EKEYEXPIRED: |
| 1276 | /* |
| 1277 | * User RPCSEC_GSS context has expired. |
| 1278 | * We cannot recover this stateid now, so |
| 1279 | * skip it and allow recovery thread to |
| 1280 | * proceed. |
| 1281 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1282 | case -ENOMEM: |
| 1283 | err = 0; |
| 1284 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | } |
| 1286 | err = nfs4_handle_exception(server, err, &exception); |
| 1287 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1288 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | return err; |
| 1290 | } |
| 1291 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1292 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1293 | { |
| 1294 | struct nfs4_opendata *data = calldata; |
| 1295 | |
| 1296 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1297 | if (data->rpc_status == 0) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1298 | memcpy(data->o_res.stateid.data, data->c_res.stateid.data, |
| 1299 | sizeof(data->o_res.stateid.data)); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1300 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1301 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1302 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1303 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | static void nfs4_open_confirm_release(void *calldata) |
| 1307 | { |
| 1308 | struct nfs4_opendata *data = calldata; |
| 1309 | struct nfs4_state *state = NULL; |
| 1310 | |
| 1311 | /* If this request hasn't been cancelled, do nothing */ |
| 1312 | if (data->cancelled == 0) |
| 1313 | goto out_free; |
| 1314 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1315 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1316 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1317 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1318 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1319 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1320 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1321 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1325 | .rpc_call_done = nfs4_open_confirm_done, |
| 1326 | .rpc_release = nfs4_open_confirm_release, |
| 1327 | }; |
| 1328 | |
| 1329 | /* |
| 1330 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1331 | */ |
| 1332 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1333 | { |
| 1334 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1335 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1336 | struct rpc_message msg = { |
| 1337 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1338 | .rpc_argp = &data->c_arg, |
| 1339 | .rpc_resp = &data->c_res, |
| 1340 | .rpc_cred = data->owner->so_cred, |
| 1341 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1342 | struct rpc_task_setup task_setup_data = { |
| 1343 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1344 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1345 | .callback_ops = &nfs4_open_confirm_ops, |
| 1346 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1347 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1348 | .flags = RPC_TASK_ASYNC, |
| 1349 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | int status; |
| 1351 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1352 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1353 | data->rpc_done = 0; |
| 1354 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1355 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1356 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1357 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1358 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1359 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1360 | if (status != 0) { |
| 1361 | data->cancelled = 1; |
| 1362 | smp_wmb(); |
| 1363 | } else |
| 1364 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1365 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | return status; |
| 1367 | } |
| 1368 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1369 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1371 | struct nfs4_opendata *data = calldata; |
| 1372 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1373 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1374 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1375 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1376 | /* |
| 1377 | * Check if we still need to send an OPEN call, or if we can use |
| 1378 | * a delegation instead. |
| 1379 | */ |
| 1380 | if (data->state != NULL) { |
| 1381 | struct nfs_delegation *delegation; |
| 1382 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1383 | 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] | 1384 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1385 | rcu_read_lock(); |
| 1386 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
| 1387 | if (delegation != NULL && |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1388 | test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1389 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1390 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1391 | } |
| 1392 | rcu_read_unlock(); |
| 1393 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1394 | /* Update sequence id. */ |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1395 | data->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1396 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1397 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1398 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1399 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1400 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1401 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1402 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1403 | &data->o_arg.seq_args, |
| 1404 | &data->o_res.seq_res, 1, task)) |
| 1405 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1406 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1407 | return; |
| 1408 | out_no_action: |
| 1409 | task->tk_action = NULL; |
| 1410 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1411 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1413 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1414 | { |
| 1415 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1416 | nfs4_open_prepare(task, calldata); |
| 1417 | } |
| 1418 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1419 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1420 | { |
| 1421 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1423 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1424 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1425 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1426 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1427 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1428 | if (task->tk_status == 0) { |
| 1429 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1430 | case S_IFREG: |
| 1431 | break; |
| 1432 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1433 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1434 | break; |
| 1435 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1436 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1437 | break; |
| 1438 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1439 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1440 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1441 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1442 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1443 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1444 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1445 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1446 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1447 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1448 | static void nfs4_open_release(void *calldata) |
| 1449 | { |
| 1450 | struct nfs4_opendata *data = calldata; |
| 1451 | struct nfs4_state *state = NULL; |
| 1452 | |
| 1453 | /* If this request hasn't been cancelled, do nothing */ |
| 1454 | if (data->cancelled == 0) |
| 1455 | goto out_free; |
| 1456 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1457 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1458 | goto out_free; |
| 1459 | /* In case we need an open_confirm, no cleanup! */ |
| 1460 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1461 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1462 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1463 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1464 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1465 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1466 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1470 | .rpc_call_prepare = nfs4_open_prepare, |
| 1471 | .rpc_call_done = nfs4_open_done, |
| 1472 | .rpc_release = nfs4_open_release, |
| 1473 | }; |
| 1474 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1475 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1476 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1477 | .rpc_call_done = nfs4_open_done, |
| 1478 | .rpc_release = nfs4_open_release, |
| 1479 | }; |
| 1480 | |
| 1481 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1482 | { |
| 1483 | struct inode *dir = data->dir->d_inode; |
| 1484 | struct nfs_server *server = NFS_SERVER(dir); |
| 1485 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1486 | struct nfs_openres *o_res = &data->o_res; |
| 1487 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1488 | struct rpc_message msg = { |
| 1489 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1490 | .rpc_argp = o_arg, |
| 1491 | .rpc_resp = o_res, |
| 1492 | .rpc_cred = data->owner->so_cred, |
| 1493 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1494 | struct rpc_task_setup task_setup_data = { |
| 1495 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1496 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1497 | .callback_ops = &nfs4_open_ops, |
| 1498 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1499 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1500 | .flags = RPC_TASK_ASYNC, |
| 1501 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1502 | int status; |
| 1503 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1504 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1505 | data->rpc_done = 0; |
| 1506 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1507 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1508 | if (isrecover) |
| 1509 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1510 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1511 | if (IS_ERR(task)) |
| 1512 | return PTR_ERR(task); |
| 1513 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1514 | if (status != 0) { |
| 1515 | data->cancelled = 1; |
| 1516 | smp_wmb(); |
| 1517 | } else |
| 1518 | status = data->rpc_status; |
| 1519 | rpc_put_task(task); |
| 1520 | |
| 1521 | return status; |
| 1522 | } |
| 1523 | |
| 1524 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1525 | { |
| 1526 | struct inode *dir = data->dir->d_inode; |
| 1527 | struct nfs_openres *o_res = &data->o_res; |
| 1528 | int status; |
| 1529 | |
| 1530 | status = nfs4_run_open_task(data, 1); |
| 1531 | if (status != 0 || !data->rpc_done) |
| 1532 | return status; |
| 1533 | |
| 1534 | nfs_refresh_inode(dir, o_res->dir_attr); |
| 1535 | |
| 1536 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1537 | status = _nfs4_proc_open_confirm(data); |
| 1538 | if (status != 0) |
| 1539 | return status; |
| 1540 | } |
| 1541 | |
| 1542 | return status; |
| 1543 | } |
| 1544 | |
| 1545 | /* |
| 1546 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1547 | */ |
| 1548 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1549 | { |
| 1550 | struct inode *dir = data->dir->d_inode; |
| 1551 | struct nfs_server *server = NFS_SERVER(dir); |
| 1552 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1553 | struct nfs_openres *o_res = &data->o_res; |
| 1554 | int status; |
| 1555 | |
| 1556 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1557 | if (status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1558 | return status; |
| 1559 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1560 | if (o_arg->open_flags & O_CREAT) { |
| 1561 | update_changeattr(dir, &o_res->cinfo); |
| 1562 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
| 1563 | } else |
| 1564 | nfs_refresh_inode(dir, o_res->dir_attr); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1565 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1566 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1568 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1570 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | } |
| 1572 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1573 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1574 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | } |
| 1576 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1577 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1578 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1579 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1580 | int ret; |
Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1581 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1582 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1583 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1584 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1585 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1586 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1587 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1588 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1589 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1590 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1591 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1592 | return ret; |
Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1593 | } |
| 1594 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1595 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1596 | { |
| 1597 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1598 | } |
| 1599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | /* |
| 1601 | * OPEN_EXPIRED: |
| 1602 | * reclaim state on the server after a network partition. |
| 1603 | * Assumes caller holds the appropriate lock |
| 1604 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1605 | 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] | 1606 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1607 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1608 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1610 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1611 | if (IS_ERR(opendata)) |
| 1612 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1613 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1614 | if (ret == -ESTALE) |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1615 | d_drop(ctx->path.dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1616 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1617 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | } |
| 1619 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1620 | 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] | 1621 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1622 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1623 | struct nfs4_exception exception = { }; |
| 1624 | int err; |
| 1625 | |
| 1626 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1627 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1628 | switch (err) { |
| 1629 | default: |
| 1630 | goto out; |
| 1631 | case -NFS4ERR_GRACE: |
| 1632 | case -NFS4ERR_DELAY: |
| 1633 | nfs4_handle_exception(server, err, &exception); |
| 1634 | err = 0; |
| 1635 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1636 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1637 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1638 | return err; |
| 1639 | } |
| 1640 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1642 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1644 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1646 | ctx = nfs4_state_find_open_context(state); |
| 1647 | if (IS_ERR(ctx)) |
| 1648 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1649 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1650 | put_nfs_open_context(ctx); |
| 1651 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1655 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1656 | * fields corresponding to attributes that were used to store the verifier. |
| 1657 | * Make sure we clobber those fields in the later setattr call |
| 1658 | */ |
| 1659 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1660 | { |
| 1661 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1662 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1663 | sattr->ia_valid |= ATTR_ATIME; |
| 1664 | |
| 1665 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1666 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1667 | sattr->ia_valid |= ATTR_MTIME; |
| 1668 | } |
| 1669 | |
| 1670 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1671 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1673 | 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] | 1674 | { |
| 1675 | struct nfs4_state_owner *sp; |
| 1676 | struct nfs4_state *state = NULL; |
| 1677 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1678 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1679 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | |
| 1681 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | status = -ENOMEM; |
| 1683 | if (!(sp = nfs4_get_state_owner(server, cred))) { |
| 1684 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1685 | goto out_err; |
| 1686 | } |
Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1687 | status = nfs4_recover_expired_lease(server); |
| 1688 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1689 | goto err_put_state_owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1690 | if (path->dentry->d_inode != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1691 | nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode); |
Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1692 | status = -ENOMEM; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1693 | opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1694 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1695 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1697 | if (path->dentry->d_inode != NULL) |
| 1698 | opendata->state = nfs4_get_open_state(path->dentry->d_inode, sp); |
| 1699 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1700 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1702 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1704 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1705 | status = PTR_ERR(state); |
| 1706 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1707 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1708 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1709 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1710 | |
| 1711 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1712 | nfs4_exclusive_attrset(opendata, sattr); |
| 1713 | |
| 1714 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1715 | status = nfs4_do_setattr(state->inode, cred, |
| 1716 | opendata->o_res.f_attr, sattr, |
| 1717 | state); |
| 1718 | if (status == 0) |
| 1719 | nfs_setattr_update_inode(state->inode, sattr); |
| 1720 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1721 | } |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1722 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | *res = state; |
| 1725 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1726 | err_opendata_put: |
| 1727 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1728 | err_put_state_owner: |
| 1729 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | *res = NULL; |
| 1732 | return status; |
| 1733 | } |
| 1734 | |
| 1735 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1736 | 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] | 1737 | { |
| 1738 | struct nfs4_exception exception = { }; |
| 1739 | struct nfs4_state *res; |
| 1740 | int status; |
| 1741 | |
| 1742 | do { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1743 | status = _nfs4_do_open(dir, path, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | if (status == 0) |
| 1745 | break; |
| 1746 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1747 | * book-keeping w.r.t. state-changing operations |
| 1748 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1749 | * It is actually a sign of a bug on the client or on the server. |
| 1750 | * |
| 1751 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1752 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | * have unhashed the old state_owner for us, and that we can |
| 1754 | * therefore safely retry using a new one. We should still warn |
| 1755 | * the user though... |
| 1756 | */ |
| 1757 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1758 | printk(KERN_WARNING "NFS: v4 server %s " |
| 1759 | " returned a bad sequence-id error!\n", |
| 1760 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | exception.retry = 1; |
| 1762 | continue; |
| 1763 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1764 | /* |
| 1765 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1766 | * state before it received the OPEN_CONFIRM. |
| 1767 | * Recover by retrying the request as per the discussion |
| 1768 | * on Page 181 of RFC3530. |
| 1769 | */ |
| 1770 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1771 | exception.retry = 1; |
| 1772 | continue; |
| 1773 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1774 | if (status == -EAGAIN) { |
| 1775 | /* We must have found a delegation */ |
| 1776 | exception.retry = 1; |
| 1777 | continue; |
| 1778 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1780 | status, &exception)); |
| 1781 | } while (exception.retry); |
| 1782 | return res; |
| 1783 | } |
| 1784 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1785 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1786 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1787 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1789 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1791 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | .iap = sattr, |
| 1793 | .server = server, |
| 1794 | .bitmask = server->attr_bitmask, |
| 1795 | }; |
| 1796 | struct nfs_setattrres res = { |
| 1797 | .fattr = fattr, |
| 1798 | .server = server, |
| 1799 | }; |
| 1800 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1801 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1802 | .rpc_argp = &arg, |
| 1803 | .rpc_resp = &res, |
| 1804 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1806 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1807 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1809 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1811 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { |
| 1812 | /* Use that stateid */ |
| 1813 | } else if (state != NULL) { |
Trond Myklebust | 77041ed | 2010-07-01 12:49:11 -0400 | [diff] [blame] | 1814 | nfs4_copy_stateid(&arg.stateid, state, current->files, current->tgid); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1815 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); |
| 1817 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1818 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1819 | if (status == 0 && state != NULL) |
| 1820 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1821 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1824 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1825 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1826 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1828 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | struct nfs4_exception exception = { }; |
| 1830 | int err; |
| 1831 | do { |
| 1832 | err = nfs4_handle_exception(server, |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1833 | _nfs4_do_setattr(inode, cred, fattr, sattr, state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | &exception); |
| 1835 | } while (exception.retry); |
| 1836 | return err; |
| 1837 | } |
| 1838 | |
| 1839 | struct nfs4_closedata { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1840 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | struct inode *inode; |
| 1842 | struct nfs4_state *state; |
| 1843 | struct nfs_closeargs arg; |
| 1844 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1845 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1846 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1847 | bool roc; |
| 1848 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | }; |
| 1850 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1851 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1852 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1853 | struct nfs4_closedata *calldata = data; |
| 1854 | struct nfs4_state_owner *sp = calldata->state->owner; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1855 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1856 | if (calldata->roc) |
| 1857 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1858 | nfs4_put_open_state(calldata->state); |
| 1859 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1860 | nfs4_put_state_owner(sp); |
Jan Blunck | 31f31db | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 1861 | path_put(&calldata->path); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1862 | kfree(calldata); |
| 1863 | } |
| 1864 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1865 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 1866 | fmode_t fmode) |
| 1867 | { |
| 1868 | spin_lock(&state->owner->so_lock); |
| 1869 | if (!(fmode & FMODE_READ)) |
| 1870 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1871 | if (!(fmode & FMODE_WRITE)) |
| 1872 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1873 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1874 | spin_unlock(&state->owner->so_lock); |
| 1875 | } |
| 1876 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1877 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1879 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 1882 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1883 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 1884 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | /* hmm. we are done with the inode, and in the process of freeing |
| 1886 | * the state_owner. we keep this around to process errors |
| 1887 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | switch (task->tk_status) { |
| 1889 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1890 | if (calldata->roc) |
| 1891 | pnfs_roc_set_barrier(state->inode, |
| 1892 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1893 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1894 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1895 | nfs4_close_clear_stateid_flags(state, |
| 1896 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | break; |
| 1898 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1899 | case -NFS4ERR_OLD_STATEID: |
| 1900 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1902 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1903 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1905 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 1906 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1908 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1909 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | } |
| 1911 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1912 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1914 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1915 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1916 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1917 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1918 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1919 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1920 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1921 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 1922 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1923 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1924 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1925 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1926 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1927 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1928 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1929 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1930 | } |
| 1931 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1932 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1933 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1934 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1935 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1936 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1937 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1938 | |
| 1939 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1940 | /* Note: exit _without_ calling nfs4_close_done */ |
| 1941 | task->tk_action = NULL; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1942 | return; |
| 1943 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1944 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1945 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1946 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1947 | if (calldata->roc && |
| 1948 | pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { |
| 1949 | rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, |
| 1950 | task, NULL); |
| 1951 | return; |
| 1952 | } |
| 1953 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1954 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1955 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1956 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1957 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 1958 | &calldata->arg.seq_args, &calldata->res.seq_res, |
| 1959 | 1, task)) |
| 1960 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1961 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1964 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1965 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1966 | .rpc_call_done = nfs4_close_done, |
| 1967 | .rpc_release = nfs4_free_closedata, |
| 1968 | }; |
| 1969 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | /* |
| 1971 | * It is possible for data to be read/written from a mem-mapped file |
| 1972 | * after the sys_close call (which hits the vfs layer as a flush). |
| 1973 | * This means that we can't safely call nfsv4 close on a file until |
| 1974 | * the inode is cleared. This in turn means that we are not good |
| 1975 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 1976 | * share state even when we are done with one of the three share |
| 1977 | * stateid's in the inode. |
| 1978 | * |
| 1979 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 1980 | */ |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1981 | int nfs4_do_close(struct path *path, struct nfs4_state *state, gfp_t gfp_mask, int wait, bool roc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1983 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1985 | struct nfs4_state_owner *sp = state->owner; |
| 1986 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1987 | struct rpc_message msg = { |
| 1988 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 1989 | .rpc_cred = state->owner->so_cred, |
| 1990 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1991 | struct rpc_task_setup task_setup_data = { |
| 1992 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1993 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1994 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1995 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1996 | .flags = RPC_TASK_ASYNC, |
| 1997 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1998 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2000 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2002 | goto out; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2003 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2005 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2006 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2008 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2009 | if (calldata->arg.seqid == NULL) |
| 2010 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2011 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2012 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2013 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2014 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2015 | calldata->res.server = server; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2016 | calldata->roc = roc; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 2017 | path_get(path); |
| 2018 | calldata->path = *path; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2019 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2020 | msg.rpc_argp = &calldata->arg; |
| 2021 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2022 | task_setup_data.callback_data = calldata; |
| 2023 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2024 | if (IS_ERR(task)) |
| 2025 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2026 | status = 0; |
| 2027 | if (wait) |
| 2028 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2029 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2030 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2031 | out_free_calldata: |
| 2032 | kfree(calldata); |
| 2033 | out: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2034 | if (roc) |
| 2035 | pnfs_roc_release(state->inode); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2036 | nfs4_put_open_state(state); |
| 2037 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2038 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | } |
| 2040 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2041 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2042 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, int open_flags, struct iattr *attr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | struct nfs4_state *state; |
| 2045 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2046 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2047 | state = nfs4_do_open(dir, &ctx->path, ctx->mode, open_flags, attr, ctx->cred); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2048 | if (IS_ERR(state)) |
| 2049 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2050 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2051 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | } |
| 2053 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2054 | 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] | 2055 | { |
| 2056 | if (ctx->state == NULL) |
| 2057 | return; |
| 2058 | if (is_sync) |
| 2059 | nfs4_close_sync(&ctx->path, ctx->state, ctx->mode); |
| 2060 | else |
| 2061 | nfs4_close_state(&ctx->path, ctx->state, ctx->mode); |
| 2062 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | |
| 2064 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2065 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2066 | struct nfs4_server_caps_arg args = { |
| 2067 | .fhandle = fhandle, |
| 2068 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | struct nfs4_server_caps_res res = {}; |
| 2070 | struct rpc_message msg = { |
| 2071 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2072 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | .rpc_resp = &res, |
| 2074 | }; |
| 2075 | int status; |
| 2076 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2077 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | if (status == 0) { |
| 2079 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2080 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2081 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2082 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2083 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2084 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2086 | server->caps |= NFS_CAP_ACLS; |
| 2087 | if (res.has_links != 0) |
| 2088 | server->caps |= NFS_CAP_HARDLINKS; |
| 2089 | if (res.has_symlinks != 0) |
| 2090 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2091 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2092 | server->caps |= NFS_CAP_FILEID; |
| 2093 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2094 | server->caps |= NFS_CAP_MODE; |
| 2095 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2096 | server->caps |= NFS_CAP_NLINK; |
| 2097 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2098 | server->caps |= NFS_CAP_OWNER; |
| 2099 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2100 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2101 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2102 | server->caps |= NFS_CAP_ATIME; |
| 2103 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2104 | server->caps |= NFS_CAP_CTIME; |
| 2105 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2106 | server->caps |= NFS_CAP_MTIME; |
| 2107 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2108 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2109 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2110 | 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] | 2111 | server->acl_bitmask = res.acl_bitmask; |
| 2112 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | return status; |
| 2115 | } |
| 2116 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2117 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | { |
| 2119 | struct nfs4_exception exception = { }; |
| 2120 | int err; |
| 2121 | do { |
| 2122 | err = nfs4_handle_exception(server, |
| 2123 | _nfs4_server_capabilities(server, fhandle), |
| 2124 | &exception); |
| 2125 | } while (exception.retry); |
| 2126 | return err; |
| 2127 | } |
| 2128 | |
| 2129 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2130 | struct nfs_fsinfo *info) |
| 2131 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2132 | struct nfs4_lookup_root_arg args = { |
| 2133 | .bitmask = nfs4_fattr_bitmap, |
| 2134 | }; |
| 2135 | struct nfs4_lookup_res res = { |
| 2136 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2137 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | .fh = fhandle, |
| 2139 | }; |
| 2140 | struct rpc_message msg = { |
| 2141 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2142 | .rpc_argp = &args, |
| 2143 | .rpc_resp = &res, |
| 2144 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2145 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2146 | nfs_fattr_init(info->fattr); |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 2147 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2151 | struct nfs_fsinfo *info) |
| 2152 | { |
| 2153 | struct nfs4_exception exception = { }; |
| 2154 | int err; |
| 2155 | do { |
| 2156 | err = nfs4_handle_exception(server, |
| 2157 | _nfs4_lookup_root(server, fhandle, info), |
| 2158 | &exception); |
| 2159 | } while (exception.retry); |
| 2160 | return err; |
| 2161 | } |
| 2162 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2163 | /* |
| 2164 | * get the file handle for the "/" directory on the server |
| 2165 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | 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] | 2167 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | int status; |
| 2170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | status = nfs4_lookup_root(server, fhandle, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | if (status == 0) |
| 2173 | status = nfs4_server_capabilities(server, fhandle); |
| 2174 | if (status == 0) |
| 2175 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2176 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | } |
| 2178 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2179 | /* |
| 2180 | * Get locations and (maybe) other attributes of a referral. |
| 2181 | * Note that we'll actually follow the referral later when |
| 2182 | * we detect fsid mismatch in inode revalidation |
| 2183 | */ |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2184 | 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] | 2185 | { |
| 2186 | int status = -ENOMEM; |
| 2187 | struct page *page = NULL; |
| 2188 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2189 | |
| 2190 | page = alloc_page(GFP_KERNEL); |
| 2191 | if (page == NULL) |
| 2192 | goto out; |
| 2193 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2194 | if (locations == NULL) |
| 2195 | goto out; |
| 2196 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 2197 | status = nfs4_proc_fs_locations(dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2198 | if (status != 0) |
| 2199 | goto out; |
| 2200 | /* Make sure server returned a different fsid for the referral */ |
| 2201 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2202 | 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] | 2203 | status = -EIO; |
| 2204 | goto out; |
| 2205 | } |
| 2206 | |
| 2207 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
| 2208 | fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL; |
| 2209 | if (!fattr->mode) |
| 2210 | fattr->mode = S_IFDIR; |
| 2211 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2212 | out: |
| 2213 | if (page) |
| 2214 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2215 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2216 | return status; |
| 2217 | } |
| 2218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2220 | { |
| 2221 | struct nfs4_getattr_arg args = { |
| 2222 | .fh = fhandle, |
| 2223 | .bitmask = server->attr_bitmask, |
| 2224 | }; |
| 2225 | struct nfs4_getattr_res res = { |
| 2226 | .fattr = fattr, |
| 2227 | .server = server, |
| 2228 | }; |
| 2229 | struct rpc_message msg = { |
| 2230 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2231 | .rpc_argp = &args, |
| 2232 | .rpc_resp = &res, |
| 2233 | }; |
| 2234 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2235 | nfs_fattr_init(fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2236 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | } |
| 2238 | |
| 2239 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2240 | { |
| 2241 | struct nfs4_exception exception = { }; |
| 2242 | int err; |
| 2243 | do { |
| 2244 | err = nfs4_handle_exception(server, |
| 2245 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2246 | &exception); |
| 2247 | } while (exception.retry); |
| 2248 | return err; |
| 2249 | } |
| 2250 | |
| 2251 | /* |
| 2252 | * The file is not closed if it is opened due to the a request to change |
| 2253 | * the size of the file. The open call will not be needed once the |
| 2254 | * VFS layer lookup-intents are implemented. |
| 2255 | * |
| 2256 | * Close is called when the inode is destroyed. |
| 2257 | * If we haven't opened the file for O_WRONLY, we |
| 2258 | * need to in the size_change case to obtain a stateid. |
| 2259 | * |
| 2260 | * Got race? |
| 2261 | * Because OPEN is always done by name in nfsv4, it is |
| 2262 | * possible that we opened a different file by the same |
| 2263 | * name. We can recognize this race condition, but we |
| 2264 | * can't do anything about it besides returning an error. |
| 2265 | * |
| 2266 | * This will be fixed with VFS changes (lookup-intent). |
| 2267 | */ |
| 2268 | static int |
| 2269 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2270 | struct iattr *sattr) |
| 2271 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2272 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2273 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2274 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | int status; |
| 2276 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2277 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2279 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2280 | if (sattr->ia_valid & ATTR_FILE) { |
| 2281 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2282 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2283 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2284 | if (ctx) { |
| 2285 | cred = ctx->cred; |
| 2286 | state = ctx->state; |
| 2287 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2288 | } |
| 2289 | |
| 2290 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2291 | if (status == 0) |
| 2292 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | return status; |
| 2294 | } |
| 2295 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2296 | static int _nfs4_proc_lookupfh(struct nfs_server *server, const struct nfs_fh *dirfh, |
| 2297 | const struct qstr *name, struct nfs_fh *fhandle, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2298 | struct nfs_fattr *fattr) |
| 2299 | { |
| 2300 | int status; |
| 2301 | struct nfs4_lookup_arg args = { |
| 2302 | .bitmask = server->attr_bitmask, |
| 2303 | .dir_fh = dirfh, |
| 2304 | .name = name, |
| 2305 | }; |
| 2306 | struct nfs4_lookup_res res = { |
| 2307 | .server = server, |
| 2308 | .fattr = fattr, |
| 2309 | .fh = fhandle, |
| 2310 | }; |
| 2311 | struct rpc_message msg = { |
| 2312 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2313 | .rpc_argp = &args, |
| 2314 | .rpc_resp = &res, |
| 2315 | }; |
| 2316 | |
| 2317 | nfs_fattr_init(fattr); |
| 2318 | |
| 2319 | dprintk("NFS call lookupfh %s\n", name->name); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2320 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2321 | dprintk("NFS reply lookupfh: %d\n", status); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2322 | return status; |
| 2323 | } |
| 2324 | |
| 2325 | static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh, |
| 2326 | struct qstr *name, struct nfs_fh *fhandle, |
| 2327 | struct nfs_fattr *fattr) |
| 2328 | { |
| 2329 | struct nfs4_exception exception = { }; |
| 2330 | int err; |
| 2331 | do { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2332 | err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr); |
| 2333 | /* FIXME: !!!! */ |
| 2334 | if (err == -NFS4ERR_MOVED) { |
| 2335 | err = -EREMOTE; |
| 2336 | break; |
| 2337 | } |
| 2338 | err = nfs4_handle_exception(server, err, &exception); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2339 | } while (exception.retry); |
| 2340 | return err; |
| 2341 | } |
| 2342 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2343 | static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2345 | { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2346 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | |
| 2348 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2349 | 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] | 2350 | if (status == -NFS4ERR_MOVED) |
| 2351 | status = nfs4_get_referral(dir, name, fattr, fhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | dprintk("NFS reply lookup: %d\n", status); |
| 2353 | return status; |
| 2354 | } |
| 2355 | |
| 2356 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2357 | { |
| 2358 | struct nfs4_exception exception = { }; |
| 2359 | int err; |
| 2360 | do { |
| 2361 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2362 | _nfs4_proc_lookup(dir, name, fhandle, fattr), |
| 2363 | &exception); |
| 2364 | } while (exception.retry); |
| 2365 | return err; |
| 2366 | } |
| 2367 | |
| 2368 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2369 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2370 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 | struct nfs4_accessargs args = { |
| 2372 | .fh = NFS_FH(inode), |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2373 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2375 | struct nfs4_accessres res = { |
| 2376 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2377 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2378 | struct rpc_message msg = { |
| 2379 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2380 | .rpc_argp = &args, |
| 2381 | .rpc_resp = &res, |
| 2382 | .rpc_cred = entry->cred, |
| 2383 | }; |
| 2384 | int mode = entry->mask; |
| 2385 | int status; |
| 2386 | |
| 2387 | /* |
| 2388 | * Determine which access bits we want to ask for... |
| 2389 | */ |
| 2390 | if (mode & MAY_READ) |
| 2391 | args.access |= NFS4_ACCESS_READ; |
| 2392 | if (S_ISDIR(inode->i_mode)) { |
| 2393 | if (mode & MAY_WRITE) |
| 2394 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2395 | if (mode & MAY_EXEC) |
| 2396 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2397 | } else { |
| 2398 | if (mode & MAY_WRITE) |
| 2399 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2400 | if (mode & MAY_EXEC) |
| 2401 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2402 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2403 | |
| 2404 | res.fattr = nfs_alloc_fattr(); |
| 2405 | if (res.fattr == NULL) |
| 2406 | return -ENOMEM; |
| 2407 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2408 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | if (!status) { |
| 2410 | entry->mask = 0; |
| 2411 | if (res.access & NFS4_ACCESS_READ) |
| 2412 | entry->mask |= MAY_READ; |
| 2413 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2414 | entry->mask |= MAY_WRITE; |
| 2415 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2416 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2417 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2419 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | return status; |
| 2421 | } |
| 2422 | |
| 2423 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2424 | { |
| 2425 | struct nfs4_exception exception = { }; |
| 2426 | int err; |
| 2427 | do { |
| 2428 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2429 | _nfs4_proc_access(inode, entry), |
| 2430 | &exception); |
| 2431 | } while (exception.retry); |
| 2432 | return err; |
| 2433 | } |
| 2434 | |
| 2435 | /* |
| 2436 | * TODO: For the time being, we don't try to get any attributes |
| 2437 | * along with any of the zero-copy operations READ, READDIR, |
| 2438 | * READLINK, WRITE. |
| 2439 | * |
| 2440 | * In the case of the first three, we want to put the GETATTR |
| 2441 | * after the read-type operation -- this is because it is hard |
| 2442 | * to predict the length of a GETATTR response in v4, and thus |
| 2443 | * align the READ data correctly. This means that the GETATTR |
| 2444 | * may end up partially falling into the page cache, and we should |
| 2445 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2446 | * To do this efficiently, we need to know the total length |
| 2447 | * of data received, which doesn't seem to be available outside |
| 2448 | * of the RPC layer. |
| 2449 | * |
| 2450 | * In the case of WRITE, we also want to put the GETATTR after |
| 2451 | * the operation -- in this case because we want to make sure |
| 2452 | * we get the post-operation mtime and size. This means that |
| 2453 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2454 | * of it which would leave room in the 'tail' iovec. |
| 2455 | * |
| 2456 | * Both of these changes to the XDR layer would in fact be quite |
| 2457 | * minor, but I decided to leave them for a subsequent patch. |
| 2458 | */ |
| 2459 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2460 | unsigned int pgbase, unsigned int pglen) |
| 2461 | { |
| 2462 | struct nfs4_readlink args = { |
| 2463 | .fh = NFS_FH(inode), |
| 2464 | .pgbase = pgbase, |
| 2465 | .pglen = pglen, |
| 2466 | .pages = &page, |
| 2467 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2468 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | struct rpc_message msg = { |
| 2470 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2471 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2472 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | }; |
| 2474 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2475 | return nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2476 | } |
| 2477 | |
| 2478 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2479 | unsigned int pgbase, unsigned int pglen) |
| 2480 | { |
| 2481 | struct nfs4_exception exception = { }; |
| 2482 | int err; |
| 2483 | do { |
| 2484 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2485 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2486 | &exception); |
| 2487 | } while (exception.retry); |
| 2488 | return err; |
| 2489 | } |
| 2490 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | /* |
| 2492 | * Got race? |
| 2493 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2494 | * Until then, this create/open method is prone to inefficiency and race |
| 2495 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2496 | * placed on the wire. |
| 2497 | * |
| 2498 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2499 | * The file will be opened again in the subsequent VFS open call |
| 2500 | * (nfs4_proc_file_open). |
| 2501 | * |
| 2502 | * The open for read will just hang around to be used by any process that |
| 2503 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2504 | */ |
| 2505 | |
| 2506 | static int |
| 2507 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2508 | int flags, struct nfs_open_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | { |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2510 | struct path my_path = { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2511 | .dentry = dentry, |
| 2512 | }; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2513 | struct path *path = &my_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | struct nfs4_state *state; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2515 | struct rpc_cred *cred = NULL; |
| 2516 | fmode_t fmode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | int status = 0; |
| 2518 | |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2519 | if (ctx != NULL) { |
| 2520 | cred = ctx->cred; |
| 2521 | path = &ctx->path; |
| 2522 | fmode = ctx->mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2523 | } |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2524 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2525 | state = nfs4_do_open(dir, path, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2526 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 | if (IS_ERR(state)) { |
| 2528 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2529 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2531 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2532 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2533 | if (ctx != NULL) |
| 2534 | ctx->state = state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2535 | else |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2536 | nfs4_close_sync(path, state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | out: |
| 2538 | return status; |
| 2539 | } |
| 2540 | |
| 2541 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2542 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2543 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2544 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2546 | .name.len = name->len, |
| 2547 | .name.name = name->name, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2548 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2549 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2550 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2551 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2552 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2554 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2555 | .rpc_argp = &args, |
| 2556 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2557 | }; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2558 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2559 | |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2560 | res.dir_attr = nfs_alloc_fattr(); |
| 2561 | if (res.dir_attr == NULL) |
| 2562 | goto out; |
| 2563 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2564 | status = nfs4_call_sync(server, &msg, &args, &res, 1); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2565 | if (status == 0) { |
| 2566 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2567 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2568 | } |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2569 | nfs_free_fattr(res.dir_attr); |
| 2570 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2571 | return status; |
| 2572 | } |
| 2573 | |
| 2574 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2575 | { |
| 2576 | struct nfs4_exception exception = { }; |
| 2577 | int err; |
| 2578 | do { |
| 2579 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2580 | _nfs4_proc_remove(dir, name), |
| 2581 | &exception); |
| 2582 | } while (exception.retry); |
| 2583 | return err; |
| 2584 | } |
| 2585 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2586 | 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] | 2587 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2588 | struct nfs_server *server = NFS_SERVER(dir); |
| 2589 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2590 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2592 | args->bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2593 | res->server = server; |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 2594 | res->seq_res.sr_slot = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2595 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2596 | } |
| 2597 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2598 | 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] | 2599 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2600 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2601 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2602 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2603 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2604 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2605 | return 0; |
| 2606 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2607 | nfs_post_op_update_inode(dir, res->dir_attr); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2608 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2609 | } |
| 2610 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2611 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2612 | { |
| 2613 | struct nfs_server *server = NFS_SERVER(dir); |
| 2614 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2615 | struct nfs_renameres *res = msg->rpc_resp; |
| 2616 | |
| 2617 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
| 2618 | arg->bitmask = server->attr_bitmask; |
| 2619 | res->server = server; |
| 2620 | } |
| 2621 | |
| 2622 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2623 | struct inode *new_dir) |
| 2624 | { |
| 2625 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2626 | |
| 2627 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2628 | return 0; |
| 2629 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2630 | return 0; |
| 2631 | |
| 2632 | update_changeattr(old_dir, &res->old_cinfo); |
| 2633 | nfs_post_op_update_inode(old_dir, res->old_fattr); |
| 2634 | update_changeattr(new_dir, &res->new_cinfo); |
| 2635 | nfs_post_op_update_inode(new_dir, res->new_fattr); |
| 2636 | return 1; |
| 2637 | } |
| 2638 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2640 | struct inode *new_dir, struct qstr *new_name) |
| 2641 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2642 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2643 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | .old_dir = NFS_FH(old_dir), |
| 2645 | .new_dir = NFS_FH(new_dir), |
| 2646 | .old_name = old_name, |
| 2647 | .new_name = new_name, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2648 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2650 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2651 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2652 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | struct rpc_message msg = { |
| 2654 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2655 | .rpc_argp = &arg, |
| 2656 | .rpc_resp = &res, |
| 2657 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2658 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2660 | res.old_fattr = nfs_alloc_fattr(); |
| 2661 | res.new_fattr = nfs_alloc_fattr(); |
| 2662 | if (res.old_fattr == NULL || res.new_fattr == NULL) |
| 2663 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2665 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2666 | if (!status) { |
| 2667 | update_changeattr(old_dir, &res.old_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2668 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2669 | update_changeattr(new_dir, &res.new_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2670 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | } |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2672 | out: |
| 2673 | nfs_free_fattr(res.new_fattr); |
| 2674 | nfs_free_fattr(res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2675 | return status; |
| 2676 | } |
| 2677 | |
| 2678 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2679 | struct inode *new_dir, struct qstr *new_name) |
| 2680 | { |
| 2681 | struct nfs4_exception exception = { }; |
| 2682 | int err; |
| 2683 | do { |
| 2684 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2685 | _nfs4_proc_rename(old_dir, old_name, |
| 2686 | new_dir, new_name), |
| 2687 | &exception); |
| 2688 | } while (exception.retry); |
| 2689 | return err; |
| 2690 | } |
| 2691 | |
| 2692 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2693 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2694 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | struct nfs4_link_arg arg = { |
| 2696 | .fh = NFS_FH(inode), |
| 2697 | .dir_fh = NFS_FH(dir), |
| 2698 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2699 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2701 | struct nfs4_link_res res = { |
| 2702 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2703 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | struct rpc_message msg = { |
| 2705 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2706 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2707 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2708 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2709 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2710 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2711 | res.fattr = nfs_alloc_fattr(); |
| 2712 | res.dir_attr = nfs_alloc_fattr(); |
| 2713 | if (res.fattr == NULL || res.dir_attr == NULL) |
| 2714 | goto out; |
| 2715 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2716 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2717 | if (!status) { |
| 2718 | update_changeattr(dir, &res.cinfo); |
| 2719 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2720 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2721 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2722 | out: |
| 2723 | nfs_free_fattr(res.dir_attr); |
| 2724 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2725 | return status; |
| 2726 | } |
| 2727 | |
| 2728 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2729 | { |
| 2730 | struct nfs4_exception exception = { }; |
| 2731 | int err; |
| 2732 | do { |
| 2733 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2734 | _nfs4_proc_link(inode, dir, name), |
| 2735 | &exception); |
| 2736 | } while (exception.retry); |
| 2737 | return err; |
| 2738 | } |
| 2739 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2740 | struct nfs4_createdata { |
| 2741 | struct rpc_message msg; |
| 2742 | struct nfs4_create_arg arg; |
| 2743 | struct nfs4_create_res res; |
| 2744 | struct nfs_fh fh; |
| 2745 | struct nfs_fattr fattr; |
| 2746 | struct nfs_fattr dir_fattr; |
| 2747 | }; |
| 2748 | |
| 2749 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 2750 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 2751 | { |
| 2752 | struct nfs4_createdata *data; |
| 2753 | |
| 2754 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2755 | if (data != NULL) { |
| 2756 | struct nfs_server *server = NFS_SERVER(dir); |
| 2757 | |
| 2758 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 2759 | data->msg.rpc_argp = &data->arg; |
| 2760 | data->msg.rpc_resp = &data->res; |
| 2761 | data->arg.dir_fh = NFS_FH(dir); |
| 2762 | data->arg.server = server; |
| 2763 | data->arg.name = name; |
| 2764 | data->arg.attrs = sattr; |
| 2765 | data->arg.ftype = ftype; |
| 2766 | data->arg.bitmask = server->attr_bitmask; |
| 2767 | data->res.server = server; |
| 2768 | data->res.fh = &data->fh; |
| 2769 | data->res.fattr = &data->fattr; |
| 2770 | data->res.dir_fattr = &data->dir_fattr; |
| 2771 | nfs_fattr_init(data->res.fattr); |
| 2772 | nfs_fattr_init(data->res.dir_fattr); |
| 2773 | } |
| 2774 | return data; |
| 2775 | } |
| 2776 | |
| 2777 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 2778 | { |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2779 | int status = nfs4_call_sync(NFS_SERVER(dir), &data->msg, |
| 2780 | &data->arg, &data->res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2781 | if (status == 0) { |
| 2782 | update_changeattr(dir, &data->res.dir_cinfo); |
| 2783 | nfs_post_op_update_inode(dir, data->res.dir_fattr); |
| 2784 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 2785 | } |
| 2786 | return status; |
| 2787 | } |
| 2788 | |
| 2789 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 2790 | { |
| 2791 | kfree(data); |
| 2792 | } |
| 2793 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2794 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2795 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2797 | struct nfs4_createdata *data; |
| 2798 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2800 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2801 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2802 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2803 | status = -ENOMEM; |
| 2804 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 2805 | if (data == NULL) |
| 2806 | goto out; |
| 2807 | |
| 2808 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 2809 | data->arg.u.symlink.pages = &page; |
| 2810 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2811 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2812 | status = nfs4_do_create(dir, dentry, data); |
| 2813 | |
| 2814 | nfs4_free_createdata(data); |
| 2815 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | return status; |
| 2817 | } |
| 2818 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2819 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2820 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | { |
| 2822 | struct nfs4_exception exception = { }; |
| 2823 | int err; |
| 2824 | do { |
| 2825 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2826 | _nfs4_proc_symlink(dir, dentry, page, |
| 2827 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2828 | &exception); |
| 2829 | } while (exception.retry); |
| 2830 | return err; |
| 2831 | } |
| 2832 | |
| 2833 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2834 | struct iattr *sattr) |
| 2835 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2836 | struct nfs4_createdata *data; |
| 2837 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2838 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2839 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 2840 | if (data == NULL) |
| 2841 | goto out; |
| 2842 | |
| 2843 | status = nfs4_do_create(dir, dentry, data); |
| 2844 | |
| 2845 | nfs4_free_createdata(data); |
| 2846 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | return status; |
| 2848 | } |
| 2849 | |
| 2850 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2851 | struct iattr *sattr) |
| 2852 | { |
| 2853 | struct nfs4_exception exception = { }; |
| 2854 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2855 | |
| 2856 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | do { |
| 2858 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2859 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 2860 | &exception); |
| 2861 | } while (exception.retry); |
| 2862 | return err; |
| 2863 | } |
| 2864 | |
| 2865 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2866 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2867 | { |
| 2868 | struct inode *dir = dentry->d_inode; |
| 2869 | struct nfs4_readdir_arg args = { |
| 2870 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2871 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | .pgbase = 0, |
| 2873 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 2874 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 2875 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2876 | }; |
| 2877 | struct nfs4_readdir_res res; |
| 2878 | struct rpc_message msg = { |
| 2879 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 2880 | .rpc_argp = &args, |
| 2881 | .rpc_resp = &res, |
| 2882 | .rpc_cred = cred, |
| 2883 | }; |
| 2884 | int status; |
| 2885 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2886 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 2887 | dentry->d_parent->d_name.name, |
| 2888 | dentry->d_name.name, |
| 2889 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 2891 | res.pgbase = args.pgbase; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2892 | status = nfs4_call_sync(NFS_SERVER(dir), &msg, &args, &res, 0); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 2893 | if (status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 2895 | status += args.pgbase; |
| 2896 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 2897 | |
| 2898 | nfs_invalidate_atime(dir); |
| 2899 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2900 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | return status; |
| 2902 | } |
| 2903 | |
| 2904 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2905 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | { |
| 2907 | struct nfs4_exception exception = { }; |
| 2908 | int err; |
| 2909 | do { |
| 2910 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 2911 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2912 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | &exception); |
| 2914 | } while (exception.retry); |
| 2915 | return err; |
| 2916 | } |
| 2917 | |
| 2918 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2919 | struct iattr *sattr, dev_t rdev) |
| 2920 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2921 | struct nfs4_createdata *data; |
| 2922 | int mode = sattr->ia_mode; |
| 2923 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2924 | |
| 2925 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 2926 | 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] | 2927 | |
| 2928 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 2929 | if (data == NULL) |
| 2930 | goto out; |
| 2931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2933 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2934 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2935 | data->arg.ftype = NF4BLK; |
| 2936 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 2937 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2938 | } |
| 2939 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2940 | data->arg.ftype = NF4CHR; |
| 2941 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 2942 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2943 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2945 | status = nfs4_do_create(dir, dentry, data); |
| 2946 | |
| 2947 | nfs4_free_createdata(data); |
| 2948 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2949 | return status; |
| 2950 | } |
| 2951 | |
| 2952 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2953 | struct iattr *sattr, dev_t rdev) |
| 2954 | { |
| 2955 | struct nfs4_exception exception = { }; |
| 2956 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2957 | |
| 2958 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2959 | do { |
| 2960 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2961 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 2962 | &exception); |
| 2963 | } while (exception.retry); |
| 2964 | return err; |
| 2965 | } |
| 2966 | |
| 2967 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2968 | struct nfs_fsstat *fsstat) |
| 2969 | { |
| 2970 | struct nfs4_statfs_arg args = { |
| 2971 | .fh = fhandle, |
| 2972 | .bitmask = server->attr_bitmask, |
| 2973 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 2974 | struct nfs4_statfs_res res = { |
| 2975 | .fsstat = fsstat, |
| 2976 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | struct rpc_message msg = { |
| 2978 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 2979 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 2980 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2981 | }; |
| 2982 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2983 | nfs_fattr_init(fsstat->fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2984 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2985 | } |
| 2986 | |
| 2987 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 2988 | { |
| 2989 | struct nfs4_exception exception = { }; |
| 2990 | int err; |
| 2991 | do { |
| 2992 | err = nfs4_handle_exception(server, |
| 2993 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 2994 | &exception); |
| 2995 | } while (exception.retry); |
| 2996 | return err; |
| 2997 | } |
| 2998 | |
| 2999 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3000 | struct nfs_fsinfo *fsinfo) |
| 3001 | { |
| 3002 | struct nfs4_fsinfo_arg args = { |
| 3003 | .fh = fhandle, |
| 3004 | .bitmask = server->attr_bitmask, |
| 3005 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3006 | struct nfs4_fsinfo_res res = { |
| 3007 | .fsinfo = fsinfo, |
| 3008 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | struct rpc_message msg = { |
| 3010 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3011 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3012 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | }; |
| 3014 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3015 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | } |
| 3017 | |
| 3018 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3019 | { |
| 3020 | struct nfs4_exception exception = { }; |
| 3021 | int err; |
| 3022 | |
| 3023 | do { |
| 3024 | err = nfs4_handle_exception(server, |
| 3025 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3026 | &exception); |
| 3027 | } while (exception.retry); |
| 3028 | return err; |
| 3029 | } |
| 3030 | |
| 3031 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3032 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3033 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3035 | } |
| 3036 | |
| 3037 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3038 | struct nfs_pathconf *pathconf) |
| 3039 | { |
| 3040 | struct nfs4_pathconf_arg args = { |
| 3041 | .fh = fhandle, |
| 3042 | .bitmask = server->attr_bitmask, |
| 3043 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3044 | struct nfs4_pathconf_res res = { |
| 3045 | .pathconf = pathconf, |
| 3046 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | struct rpc_message msg = { |
| 3048 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3049 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3050 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | }; |
| 3052 | |
| 3053 | /* None of the pathconf attributes are mandatory to implement */ |
| 3054 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3055 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3056 | return 0; |
| 3057 | } |
| 3058 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3059 | nfs_fattr_init(pathconf->fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3060 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | } |
| 3062 | |
| 3063 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3064 | struct nfs_pathconf *pathconf) |
| 3065 | { |
| 3066 | struct nfs4_exception exception = { }; |
| 3067 | int err; |
| 3068 | |
| 3069 | do { |
| 3070 | err = nfs4_handle_exception(server, |
| 3071 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3072 | &exception); |
| 3073 | } while (exception.retry); |
| 3074 | return err; |
| 3075 | } |
| 3076 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3077 | static int nfs4_read_done_cb(struct rpc_task *task, struct nfs_read_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3078 | { |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3079 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3080 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3081 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3082 | nfs_restart_rpc(task, server->nfs_client); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3083 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3084 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3085 | |
| 3086 | nfs_invalidate_atime(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3087 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3088 | renew_lease(server, data->timestamp); |
| 3089 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3090 | } |
| 3091 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3092 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3093 | { |
| 3094 | |
| 3095 | dprintk("--> %s\n", __func__); |
| 3096 | |
| 3097 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3098 | return -EAGAIN; |
| 3099 | |
| 3100 | return data->read_done_cb(task, data); |
| 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; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3106 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3107 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3108 | } |
| 3109 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3110 | /* Reset the the nfs_read_data to send the read to the MDS. */ |
| 3111 | void nfs4_reset_read(struct rpc_task *task, struct nfs_read_data *data) |
| 3112 | { |
| 3113 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3114 | put_lseg(data->lseg); |
| 3115 | data->lseg = NULL; |
| 3116 | /* offsets will differ in the dense stripe case */ |
| 3117 | data->args.offset = data->mds_offset; |
| 3118 | data->ds_clp = NULL; |
| 3119 | data->args.fh = NFS_FH(data->inode); |
| 3120 | data->read_done_cb = nfs4_read_done_cb; |
| 3121 | task->tk_ops = data->mds_ops; |
| 3122 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3123 | } |
| 3124 | EXPORT_SYMBOL_GPL(nfs4_reset_read); |
| 3125 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame^] | 3126 | static int nfs4_write_done_cb(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3127 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3128 | struct inode *inode = data->inode; |
| 3129 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3130 | 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] | 3131 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3132 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3134 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3135 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 3136 | nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3137 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3138 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | } |
| 3140 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame^] | 3141 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3142 | { |
| 3143 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3144 | return -EAGAIN; |
| 3145 | return data->write_done_cb(task, data); |
| 3146 | } |
| 3147 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3148 | 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] | 3149 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3150 | struct nfs_server *server = NFS_SERVER(data->inode); |
| 3151 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3152 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame^] | 3153 | if (!data->write_done_cb) |
| 3154 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3155 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3156 | data->timestamp = jiffies; |
| 3157 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3158 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | } |
| 3160 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3161 | 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] | 3162 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3163 | struct inode *inode = data->inode; |
| 3164 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3165 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3166 | return -EAGAIN; |
| 3167 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3168 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3169 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3170 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3171 | } |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 3172 | nfs_refresh_inode(inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3173 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3174 | } |
| 3175 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3176 | 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] | 3177 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3178 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3179 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3180 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3181 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3182 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3183 | } |
| 3184 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3185 | struct nfs4_renewdata { |
| 3186 | struct nfs_client *client; |
| 3187 | unsigned long timestamp; |
| 3188 | }; |
| 3189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | /* |
| 3191 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3192 | * standalone procedure for queueing an asynchronous RENEW. |
| 3193 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3194 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3195 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3196 | struct nfs4_renewdata *data = calldata; |
| 3197 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3198 | |
Alexandros Batsakis | 0851de0 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3199 | if (atomic_read(&clp->cl_count) > 1) |
| 3200 | nfs4_schedule_state_renewal(clp); |
| 3201 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3202 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3203 | } |
| 3204 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3205 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3207 | struct nfs4_renewdata *data = calldata; |
| 3208 | struct nfs_client *clp = data->client; |
| 3209 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | |
| 3211 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3212 | /* Unless we're shutting down, schedule state recovery! */ |
| 3213 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) != 0) |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3214 | nfs4_schedule_lease_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3215 | return; |
| 3216 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3217 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | } |
| 3219 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3220 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3221 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3222 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3223 | }; |
| 3224 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3225 | 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] | 3226 | { |
| 3227 | struct rpc_message msg = { |
| 3228 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3229 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3230 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3231 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3232 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3233 | |
Alexandros Batsakis | 0851de0 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3234 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3235 | return -EIO; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3236 | data = kmalloc(sizeof(*data), GFP_KERNEL); |
| 3237 | if (data == NULL) |
| 3238 | return -ENOMEM; |
| 3239 | data->client = clp; |
| 3240 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3241 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3242 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | } |
| 3244 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3245 | int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | { |
| 3247 | struct rpc_message msg = { |
| 3248 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3249 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3250 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3251 | }; |
| 3252 | unsigned long now = jiffies; |
| 3253 | int status; |
| 3254 | |
| 3255 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3256 | if (status < 0) |
| 3257 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3258 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | return 0; |
| 3260 | } |
| 3261 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3262 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3263 | { |
| 3264 | return (server->caps & NFS_CAP_ACLS) |
| 3265 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3266 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3267 | } |
| 3268 | |
| 3269 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3270 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3271 | * the stack. |
| 3272 | */ |
| 3273 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3274 | |
| 3275 | static void buf_to_pages(const void *buf, size_t buflen, |
| 3276 | struct page **pages, unsigned int *pgbase) |
| 3277 | { |
| 3278 | const void *p = buf; |
| 3279 | |
| 3280 | *pgbase = offset_in_page(buf); |
| 3281 | p -= *pgbase; |
| 3282 | while (p < buf + buflen) { |
| 3283 | *(pages++) = virt_to_page(p); |
| 3284 | p += PAGE_CACHE_SIZE; |
| 3285 | } |
| 3286 | } |
| 3287 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3288 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3289 | struct page **pages, unsigned int *pgbase) |
| 3290 | { |
| 3291 | struct page *newpage, **spages; |
| 3292 | int rc = 0; |
| 3293 | size_t len; |
| 3294 | spages = pages; |
| 3295 | |
| 3296 | do { |
Jovi Zhang | 43b7c3f | 2011-03-02 23:19:37 +0000 | [diff] [blame] | 3297 | len = min_t(size_t, PAGE_CACHE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3298 | newpage = alloc_page(GFP_KERNEL); |
| 3299 | |
| 3300 | if (newpage == NULL) |
| 3301 | goto unwind; |
| 3302 | memcpy(page_address(newpage), buf, len); |
| 3303 | buf += len; |
| 3304 | buflen -= len; |
| 3305 | *pages++ = newpage; |
| 3306 | rc++; |
| 3307 | } while (buflen != 0); |
| 3308 | |
| 3309 | return rc; |
| 3310 | |
| 3311 | unwind: |
| 3312 | for(; rc > 0; rc--) |
| 3313 | __free_page(spages[rc-1]); |
| 3314 | return -ENOMEM; |
| 3315 | } |
| 3316 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3317 | struct nfs4_cached_acl { |
| 3318 | int cached; |
| 3319 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3320 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3321 | }; |
| 3322 | |
| 3323 | 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] | 3324 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3325 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3326 | |
| 3327 | spin_lock(&inode->i_lock); |
| 3328 | kfree(nfsi->nfs4_acl); |
| 3329 | nfsi->nfs4_acl = acl; |
| 3330 | spin_unlock(&inode->i_lock); |
| 3331 | } |
| 3332 | |
| 3333 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3334 | { |
| 3335 | nfs4_set_cached_acl(inode, NULL); |
| 3336 | } |
| 3337 | |
| 3338 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3339 | { |
| 3340 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3341 | struct nfs4_cached_acl *acl; |
| 3342 | int ret = -ENOENT; |
| 3343 | |
| 3344 | spin_lock(&inode->i_lock); |
| 3345 | acl = nfsi->nfs4_acl; |
| 3346 | if (acl == NULL) |
| 3347 | goto out; |
| 3348 | if (buf == NULL) /* user is just asking for length */ |
| 3349 | goto out_len; |
| 3350 | if (acl->cached == 0) |
| 3351 | goto out; |
| 3352 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3353 | if (acl->len > buflen) |
| 3354 | goto out; |
| 3355 | memcpy(buf, acl->data, acl->len); |
| 3356 | out_len: |
| 3357 | ret = acl->len; |
| 3358 | out: |
| 3359 | spin_unlock(&inode->i_lock); |
| 3360 | return ret; |
| 3361 | } |
| 3362 | |
| 3363 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) |
| 3364 | { |
| 3365 | struct nfs4_cached_acl *acl; |
| 3366 | |
| 3367 | if (buf && acl_len <= PAGE_SIZE) { |
| 3368 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3369 | if (acl == NULL) |
| 3370 | goto out; |
| 3371 | acl->cached = 1; |
| 3372 | memcpy(acl->data, buf, acl_len); |
| 3373 | } else { |
| 3374 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3375 | if (acl == NULL) |
| 3376 | goto out; |
| 3377 | acl->cached = 0; |
| 3378 | } |
| 3379 | acl->len = acl_len; |
| 3380 | out: |
| 3381 | nfs4_set_cached_acl(inode, acl); |
| 3382 | } |
| 3383 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3384 | 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] | 3385 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3386 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3387 | struct nfs_getaclargs args = { |
| 3388 | .fh = NFS_FH(inode), |
| 3389 | .acl_pages = pages, |
| 3390 | .acl_len = buflen, |
| 3391 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3392 | struct nfs_getaclres res = { |
| 3393 | .acl_len = buflen, |
| 3394 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3395 | void *resp_buf; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3396 | struct rpc_message msg = { |
| 3397 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3398 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3399 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3400 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3401 | struct page *localpage = NULL; |
| 3402 | int ret; |
| 3403 | |
| 3404 | if (buflen < PAGE_SIZE) { |
| 3405 | /* As long as we're doing a round trip to the server anyway, |
| 3406 | * let's be prepared for a page of acl data. */ |
| 3407 | localpage = alloc_page(GFP_KERNEL); |
| 3408 | resp_buf = page_address(localpage); |
| 3409 | if (localpage == NULL) |
| 3410 | return -ENOMEM; |
| 3411 | args.acl_pages[0] = localpage; |
| 3412 | args.acl_pgbase = 0; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3413 | args.acl_len = PAGE_SIZE; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3414 | } else { |
| 3415 | resp_buf = buf; |
| 3416 | buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase); |
| 3417 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3418 | ret = nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3419 | if (ret) |
| 3420 | goto out_free; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3421 | if (res.acl_len > args.acl_len) |
| 3422 | nfs4_write_cached_acl(inode, NULL, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3423 | else |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3424 | nfs4_write_cached_acl(inode, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3425 | if (buf) { |
| 3426 | ret = -ERANGE; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3427 | if (res.acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3428 | goto out_free; |
| 3429 | if (localpage) |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3430 | memcpy(buf, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3431 | } |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3432 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3433 | out_free: |
| 3434 | if (localpage) |
| 3435 | __free_page(localpage); |
| 3436 | return ret; |
| 3437 | } |
| 3438 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3439 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3440 | { |
| 3441 | struct nfs4_exception exception = { }; |
| 3442 | ssize_t ret; |
| 3443 | do { |
| 3444 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3445 | if (ret >= 0) |
| 3446 | break; |
| 3447 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3448 | } while (exception.retry); |
| 3449 | return ret; |
| 3450 | } |
| 3451 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3452 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3453 | { |
| 3454 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3455 | int ret; |
| 3456 | |
| 3457 | if (!nfs4_server_supports_acls(server)) |
| 3458 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3459 | ret = nfs_revalidate_inode(server, inode); |
| 3460 | if (ret < 0) |
| 3461 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3462 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3463 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3464 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3465 | if (ret != -ENOENT) |
| 3466 | return ret; |
| 3467 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3468 | } |
| 3469 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3470 | 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] | 3471 | { |
| 3472 | struct nfs_server *server = NFS_SERVER(inode); |
| 3473 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3474 | struct nfs_setaclargs arg = { |
| 3475 | .fh = NFS_FH(inode), |
| 3476 | .acl_pages = pages, |
| 3477 | .acl_len = buflen, |
| 3478 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3479 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3480 | struct rpc_message msg = { |
| 3481 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3482 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3483 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3484 | }; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3485 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3486 | |
| 3487 | if (!nfs4_server_supports_acls(server)) |
| 3488 | return -EOPNOTSUPP; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3489 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3490 | if (i < 0) |
| 3491 | return i; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3492 | nfs_inode_return_delegation(inode); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3493 | ret = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3494 | |
| 3495 | /* |
| 3496 | * Free each page after tx, so the only ref left is |
| 3497 | * held by the network stack |
| 3498 | */ |
| 3499 | for (; i > 0; i--) |
| 3500 | put_page(pages[i-1]); |
| 3501 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3502 | /* |
| 3503 | * Acl update can result in inode attribute update. |
| 3504 | * so mark the attribute cache invalid. |
| 3505 | */ |
| 3506 | spin_lock(&inode->i_lock); |
| 3507 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3508 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3509 | nfs_access_zap_cache(inode); |
| 3510 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3511 | return ret; |
| 3512 | } |
| 3513 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3514 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3515 | { |
| 3516 | struct nfs4_exception exception = { }; |
| 3517 | int err; |
| 3518 | do { |
| 3519 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3520 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3521 | &exception); |
| 3522 | } while (exception.retry); |
| 3523 | return err; |
| 3524 | } |
| 3525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3526 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3527 | 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] | 3528 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3529 | struct nfs_client *clp = server->nfs_client; |
| 3530 | |
| 3531 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3532 | return 0; |
| 3533 | switch(task->tk_status) { |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3534 | case -NFS4ERR_ADMIN_REVOKED: |
| 3535 | case -NFS4ERR_BAD_STATEID: |
| 3536 | case -NFS4ERR_OPENMODE: |
| 3537 | if (state == NULL) |
| 3538 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3539 | nfs4_schedule_stateid_recovery(server, state); |
| 3540 | goto wait_on_recovery; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3542 | case -NFS4ERR_STALE_CLIENTID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3543 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3544 | nfs4_schedule_lease_recovery(clp); |
| 3545 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3546 | #if defined(CONFIG_NFS_V4_1) |
| 3547 | case -NFS4ERR_BADSESSION: |
| 3548 | case -NFS4ERR_BADSLOT: |
| 3549 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3550 | case -NFS4ERR_DEADSESSION: |
| 3551 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3552 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3553 | case -NFS4ERR_SEQ_MISORDERED: |
| 3554 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3555 | task->tk_status); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3556 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3557 | task->tk_status = 0; |
| 3558 | return -EAGAIN; |
| 3559 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3560 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3561 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3562 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3563 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3564 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3565 | task->tk_status = 0; |
| 3566 | return -EAGAIN; |
| 3567 | case -NFS4ERR_OLD_STATEID: |
| 3568 | task->tk_status = 0; |
| 3569 | return -EAGAIN; |
| 3570 | } |
| 3571 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3572 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3573 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3574 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3575 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3576 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3577 | task->tk_status = 0; |
| 3578 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | } |
| 3580 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3581 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 3582 | unsigned short port, struct rpc_cred *cred, |
| 3583 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3584 | { |
| 3585 | nfs4_verifier sc_verifier; |
| 3586 | struct nfs4_setclientid setclientid = { |
| 3587 | .sc_verifier = &sc_verifier, |
| 3588 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 3589 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | }; |
| 3591 | struct rpc_message msg = { |
| 3592 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3593 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3594 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3595 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3596 | }; |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3597 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3598 | int loop = 0; |
| 3599 | int status; |
| 3600 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3601 | p = (__be32*)sc_verifier.data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3602 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 3603 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 3604 | |
| 3605 | for(;;) { |
| 3606 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3607 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3608 | clp->cl_ipaddr, |
| 3609 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3610 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3611 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3612 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3613 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3614 | clp->cl_id_uniquifier); |
| 3615 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3616 | sizeof(setclientid.sc_netid), |
| 3617 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3618 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3620 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3621 | clp->cl_ipaddr, port >> 8, port & 255); |
| 3622 | |
| 3623 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3624 | if (status != -NFS4ERR_CLID_INUSE) |
| 3625 | break; |
| 3626 | if (signalled()) |
| 3627 | break; |
| 3628 | if (loop++ & 1) |
J. Bruce Fields | 611c96c | 2010-12-13 19:05:46 -0500 | [diff] [blame] | 3629 | ssleep(clp->cl_lease_time / HZ + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | else |
| 3631 | if (++clp->cl_id_uniquifier == 0) |
| 3632 | break; |
| 3633 | } |
| 3634 | return status; |
| 3635 | } |
| 3636 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3637 | static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
| 3638 | struct nfs4_setclientid_res *arg, |
| 3639 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3640 | { |
| 3641 | struct nfs_fsinfo fsinfo; |
| 3642 | struct rpc_message msg = { |
| 3643 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3644 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3645 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3646 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | }; |
| 3648 | unsigned long now; |
| 3649 | int status; |
| 3650 | |
| 3651 | now = jiffies; |
| 3652 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3653 | if (status == 0) { |
| 3654 | spin_lock(&clp->cl_lock); |
| 3655 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 3656 | clp->cl_last_renewal = now; |
| 3657 | spin_unlock(&clp->cl_lock); |
| 3658 | } |
| 3659 | return status; |
| 3660 | } |
| 3661 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3662 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
| 3663 | struct nfs4_setclientid_res *arg, |
| 3664 | struct rpc_cred *cred) |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3665 | { |
Benny Halevy | 77e0367 | 2008-06-24 20:25:57 +0300 | [diff] [blame] | 3666 | long timeout = 0; |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3667 | int err; |
| 3668 | do { |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3669 | err = _nfs4_proc_setclientid_confirm(clp, arg, cred); |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3670 | switch (err) { |
| 3671 | case 0: |
| 3672 | return err; |
| 3673 | case -NFS4ERR_RESOURCE: |
| 3674 | /* The IBM lawyers misread another document! */ |
| 3675 | case -NFS4ERR_DELAY: |
| 3676 | err = nfs4_delay(clp->cl_rpcclient, &timeout); |
| 3677 | } |
| 3678 | } while (err == 0); |
| 3679 | return err; |
| 3680 | } |
| 3681 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3682 | struct nfs4_delegreturndata { |
| 3683 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3684 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3685 | struct nfs_fh fh; |
| 3686 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3687 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3688 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3689 | int rpc_status; |
| 3690 | }; |
| 3691 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3692 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 3693 | { |
| 3694 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3695 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3696 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3697 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3698 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3699 | switch (task->tk_status) { |
| 3700 | case -NFS4ERR_STALE_STATEID: |
| 3701 | case -NFS4ERR_EXPIRED: |
| 3702 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3703 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3704 | break; |
| 3705 | default: |
| 3706 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 3707 | -EAGAIN) { |
| 3708 | nfs_restart_rpc(task, data->res.server->nfs_client); |
| 3709 | return; |
| 3710 | } |
| 3711 | } |
| 3712 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3713 | } |
| 3714 | |
| 3715 | static void nfs4_delegreturn_release(void *calldata) |
| 3716 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3717 | kfree(calldata); |
| 3718 | } |
| 3719 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3720 | #if defined(CONFIG_NFS_V4_1) |
| 3721 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 3722 | { |
| 3723 | struct nfs4_delegreturndata *d_data; |
| 3724 | |
| 3725 | d_data = (struct nfs4_delegreturndata *)data; |
| 3726 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3727 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3728 | &d_data->args.seq_args, |
| 3729 | &d_data->res.seq_res, 1, task)) |
| 3730 | return; |
| 3731 | rpc_call_start(task); |
| 3732 | } |
| 3733 | #endif /* CONFIG_NFS_V4_1 */ |
| 3734 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 3735 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3736 | #if defined(CONFIG_NFS_V4_1) |
| 3737 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 3738 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3739 | .rpc_call_done = nfs4_delegreturn_done, |
| 3740 | .rpc_release = nfs4_delegreturn_release, |
| 3741 | }; |
| 3742 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3743 | 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] | 3744 | { |
| 3745 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3746 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3747 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3748 | struct rpc_message msg = { |
| 3749 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 3750 | .rpc_cred = cred, |
| 3751 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3752 | struct rpc_task_setup task_setup_data = { |
| 3753 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3754 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3755 | .callback_ops = &nfs4_delegreturn_ops, |
| 3756 | .flags = RPC_TASK_ASYNC, |
| 3757 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3758 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3759 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3760 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3761 | if (data == NULL) |
| 3762 | return -ENOMEM; |
| 3763 | data->args.fhandle = &data->fh; |
| 3764 | data->args.stateid = &data->stateid; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3765 | data->args.bitmask = server->attr_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3766 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
| 3767 | memcpy(&data->stateid, stateid, sizeof(data->stateid)); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3768 | data->res.fattr = &data->fattr; |
| 3769 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3770 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3771 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3772 | data->rpc_status = 0; |
| 3773 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3774 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3775 | msg.rpc_argp = &data->args; |
| 3776 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3777 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 3778 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3779 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3780 | if (!issync) |
| 3781 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3782 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3783 | if (status != 0) |
| 3784 | goto out; |
| 3785 | status = data->rpc_status; |
| 3786 | if (status != 0) |
| 3787 | goto out; |
| 3788 | nfs_refresh_inode(inode, &data->fattr); |
| 3789 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3790 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3791 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | } |
| 3793 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3794 | 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] | 3795 | { |
| 3796 | struct nfs_server *server = NFS_SERVER(inode); |
| 3797 | struct nfs4_exception exception = { }; |
| 3798 | int err; |
| 3799 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3800 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3801 | switch (err) { |
| 3802 | case -NFS4ERR_STALE_STATEID: |
| 3803 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3804 | case 0: |
| 3805 | return 0; |
| 3806 | } |
| 3807 | err = nfs4_handle_exception(server, err, &exception); |
| 3808 | } while (exception.retry); |
| 3809 | return err; |
| 3810 | } |
| 3811 | |
| 3812 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 3813 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 3814 | |
| 3815 | /* |
| 3816 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 3817 | */ |
| 3818 | static unsigned long |
| 3819 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 3820 | { |
Matthew Wilcox | 150030b | 2007-12-06 16:24:39 -0500 | [diff] [blame] | 3821 | schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3822 | timeout <<= 1; |
| 3823 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 3824 | return NFS4_LOCK_MAXTIMEOUT; |
| 3825 | return timeout; |
| 3826 | } |
| 3827 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3828 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3829 | { |
| 3830 | struct inode *inode = state->inode; |
| 3831 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3832 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3833 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3834 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3835 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3836 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3837 | struct nfs_lockt_res res = { |
| 3838 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 | }; |
| 3840 | struct rpc_message msg = { |
| 3841 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 3842 | .rpc_argp = &arg, |
| 3843 | .rpc_resp = &res, |
| 3844 | .rpc_cred = state->owner->so_cred, |
| 3845 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3846 | struct nfs4_lock_state *lsp; |
| 3847 | int status; |
| 3848 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3849 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3850 | status = nfs4_set_lock_state(state, request); |
| 3851 | if (status != 0) |
| 3852 | goto out; |
| 3853 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 3854 | arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 3855 | arg.lock_owner.s_dev = server->s_dev; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3856 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3857 | switch (status) { |
| 3858 | case 0: |
| 3859 | request->fl_type = F_UNLCK; |
| 3860 | break; |
| 3861 | case -NFS4ERR_DENIED: |
| 3862 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3863 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 3864 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3865 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3866 | return status; |
| 3867 | } |
| 3868 | |
| 3869 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3870 | { |
| 3871 | struct nfs4_exception exception = { }; |
| 3872 | int err; |
| 3873 | |
| 3874 | do { |
| 3875 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 3876 | _nfs4_proc_getlk(state, cmd, request), |
| 3877 | &exception); |
| 3878 | } while (exception.retry); |
| 3879 | return err; |
| 3880 | } |
| 3881 | |
| 3882 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 3883 | { |
| 3884 | int res = 0; |
| 3885 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 3886 | case FL_POSIX: |
| 3887 | res = posix_lock_file_wait(file, fl); |
| 3888 | break; |
| 3889 | case FL_FLOCK: |
| 3890 | res = flock_lock_file_wait(file, fl); |
| 3891 | break; |
| 3892 | default: |
| 3893 | BUG(); |
| 3894 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3895 | return res; |
| 3896 | } |
| 3897 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3898 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3899 | struct nfs_locku_args arg; |
| 3900 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3901 | struct nfs4_lock_state *lsp; |
| 3902 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3903 | struct file_lock fl; |
| 3904 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3905 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3906 | }; |
| 3907 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3908 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 3909 | struct nfs_open_context *ctx, |
| 3910 | struct nfs4_lock_state *lsp, |
| 3911 | struct nfs_seqid *seqid) |
| 3912 | { |
| 3913 | struct nfs4_unlockdata *p; |
| 3914 | struct inode *inode = lsp->ls_state->inode; |
| 3915 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3916 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3917 | if (p == NULL) |
| 3918 | return NULL; |
| 3919 | p->arg.fh = NFS_FH(inode); |
| 3920 | p->arg.fl = &p->fl; |
| 3921 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3922 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3923 | p->arg.stateid = &lsp->ls_stateid; |
| 3924 | p->lsp = lsp; |
| 3925 | atomic_inc(&lsp->ls_count); |
| 3926 | /* Ensure we don't close file until we're done freeing locks! */ |
| 3927 | p->ctx = get_nfs_open_context(ctx); |
| 3928 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 3929 | p->server = NFS_SERVER(inode); |
| 3930 | return p; |
| 3931 | } |
| 3932 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3933 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3934 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3935 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3936 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3937 | nfs4_put_lock_state(calldata->lsp); |
| 3938 | put_nfs_open_context(calldata->ctx); |
| 3939 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3940 | } |
| 3941 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3942 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3943 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3944 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3945 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3946 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3947 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3948 | switch (task->tk_status) { |
| 3949 | case 0: |
| 3950 | memcpy(calldata->lsp->ls_stateid.data, |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3951 | calldata->res.stateid.data, |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3952 | sizeof(calldata->lsp->ls_stateid.data)); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3953 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3954 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3955 | case -NFS4ERR_BAD_STATEID: |
| 3956 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3957 | case -NFS4ERR_STALE_STATEID: |
| 3958 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3959 | break; |
| 3960 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3961 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3962 | nfs_restart_rpc(task, |
Trond Myklebust | d61e612 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 3963 | calldata->server->nfs_client); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3964 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3965 | } |
| 3966 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3967 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3968 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3969 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3970 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3971 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3972 | return; |
| 3973 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3974 | /* Note: exit _without_ running nfs4_locku_done */ |
| 3975 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3976 | return; |
| 3977 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3978 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3979 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 3980 | &calldata->arg.seq_args, |
| 3981 | &calldata->res.seq_res, 1, task)) |
| 3982 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3983 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3984 | } |
| 3985 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3986 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3987 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3988 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3989 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3990 | }; |
| 3991 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3992 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 3993 | struct nfs_open_context *ctx, |
| 3994 | struct nfs4_lock_state *lsp, |
| 3995 | struct nfs_seqid *seqid) |
| 3996 | { |
| 3997 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3998 | struct rpc_message msg = { |
| 3999 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4000 | .rpc_cred = ctx->cred, |
| 4001 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4002 | struct rpc_task_setup task_setup_data = { |
| 4003 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4004 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4005 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4006 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4007 | .flags = RPC_TASK_ASYNC, |
| 4008 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4009 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4010 | /* Ensure this is an unlock - when canceling a lock, the |
| 4011 | * canceled lock is passed in, and it won't be an unlock. |
| 4012 | */ |
| 4013 | fl->fl_type = F_UNLCK; |
| 4014 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4015 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4016 | if (data == NULL) { |
| 4017 | nfs_free_seqid(seqid); |
| 4018 | return ERR_PTR(-ENOMEM); |
| 4019 | } |
| 4020 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4021 | msg.rpc_argp = &data->arg; |
| 4022 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4023 | task_setup_data.callback_data = data; |
| 4024 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4025 | } |
| 4026 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4028 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4029 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4030 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4031 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4032 | struct rpc_task *task; |
| 4033 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4034 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4035 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4036 | status = nfs4_set_lock_state(state, request); |
| 4037 | /* Unlock _before_ we do the RPC call */ |
| 4038 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4039 | down_read(&nfsi->rwsem); |
| 4040 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4041 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4042 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4043 | } |
| 4044 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4045 | if (status != 0) |
| 4046 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4047 | /* Is this a delegated lock? */ |
| 4048 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4049 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4050 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4051 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4052 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4053 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4054 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4055 | 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] | 4056 | status = PTR_ERR(task); |
| 4057 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4058 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4059 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4060 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4061 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4062 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4063 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | } |
| 4065 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4066 | struct nfs4_lockdata { |
| 4067 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4068 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4069 | struct nfs4_lock_state *lsp; |
| 4070 | struct nfs_open_context *ctx; |
| 4071 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4072 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4073 | int rpc_status; |
| 4074 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4075 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4076 | }; |
| 4077 | |
| 4078 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4079 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4080 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4081 | { |
| 4082 | struct nfs4_lockdata *p; |
| 4083 | struct inode *inode = lsp->ls_state->inode; |
| 4084 | struct nfs_server *server = NFS_SERVER(inode); |
| 4085 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4086 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4087 | if (p == NULL) |
| 4088 | return NULL; |
| 4089 | |
| 4090 | p->arg.fh = NFS_FH(inode); |
| 4091 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4092 | 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] | 4093 | if (p->arg.open_seqid == NULL) |
| 4094 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4095 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4096 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4097 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4098 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4099 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 4100 | p->arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4101 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4102 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4103 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4104 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4105 | atomic_inc(&lsp->ls_count); |
| 4106 | p->ctx = get_nfs_open_context(ctx); |
| 4107 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4108 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4109 | out_free_seqid: |
| 4110 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4111 | out_free: |
| 4112 | kfree(p); |
| 4113 | return NULL; |
| 4114 | } |
| 4115 | |
| 4116 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4117 | { |
| 4118 | struct nfs4_lockdata *data = calldata; |
| 4119 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4120 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4121 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4122 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4123 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4124 | /* Do we need to do an open_to_lock_owner? */ |
| 4125 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4126 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4127 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4128 | data->arg.open_stateid = &state->stateid; |
| 4129 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4130 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4131 | } else |
| 4132 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4133 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4134 | if (nfs4_setup_sequence(data->server, |
| 4135 | &data->arg.seq_args, |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4136 | &data->res.seq_res, 1, task)) |
| 4137 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4138 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4139 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4140 | } |
| 4141 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4142 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4143 | { |
| 4144 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4145 | nfs4_lock_prepare(task, calldata); |
| 4146 | } |
| 4147 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4148 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4149 | { |
| 4150 | struct nfs4_lockdata *data = calldata; |
| 4151 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4152 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4153 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4154 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4155 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4156 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4157 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4158 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4159 | if (data->rpc_status == 0) |
| 4160 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4161 | else |
| 4162 | goto out; |
| 4163 | } |
| 4164 | if (data->rpc_status == 0) { |
| 4165 | memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, |
| 4166 | sizeof(data->lsp->ls_stateid.data)); |
| 4167 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Trond Myklebust | 88be9f9 | 2007-06-05 10:42:27 -0400 | [diff] [blame] | 4168 | renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4169 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4170 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4171 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4172 | } |
| 4173 | |
| 4174 | static void nfs4_lock_release(void *calldata) |
| 4175 | { |
| 4176 | struct nfs4_lockdata *data = calldata; |
| 4177 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4178 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4179 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4180 | if (data->cancelled != 0) { |
| 4181 | struct rpc_task *task; |
| 4182 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4183 | data->arg.lock_seqid); |
| 4184 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4185 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4186 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4187 | } else |
| 4188 | nfs_free_seqid(data->arg.lock_seqid); |
| 4189 | nfs4_put_lock_state(data->lsp); |
| 4190 | put_nfs_open_context(data->ctx); |
| 4191 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4192 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4193 | } |
| 4194 | |
| 4195 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4196 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4197 | .rpc_call_done = nfs4_lock_done, |
| 4198 | .rpc_release = nfs4_lock_release, |
| 4199 | }; |
| 4200 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4201 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4202 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4203 | .rpc_call_done = nfs4_lock_done, |
| 4204 | .rpc_release = nfs4_lock_release, |
| 4205 | }; |
| 4206 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4207 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4208 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4209 | switch (error) { |
| 4210 | case -NFS4ERR_ADMIN_REVOKED: |
| 4211 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4212 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4213 | if (new_lock_owner != 0 || |
| 4214 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4215 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4216 | break; |
| 4217 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4218 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4219 | case -NFS4ERR_EXPIRED: |
| 4220 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4221 | }; |
| 4222 | } |
| 4223 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4224 | 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] | 4225 | { |
| 4226 | struct nfs4_lockdata *data; |
| 4227 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4228 | struct rpc_message msg = { |
| 4229 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4230 | .rpc_cred = state->owner->so_cred, |
| 4231 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4232 | struct rpc_task_setup task_setup_data = { |
| 4233 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4234 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4235 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4236 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4237 | .flags = RPC_TASK_ASYNC, |
| 4238 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4239 | int ret; |
| 4240 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4241 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4242 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4243 | fl->fl_u.nfs4_fl.owner, |
| 4244 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4245 | if (data == NULL) |
| 4246 | return -ENOMEM; |
| 4247 | if (IS_SETLKW(cmd)) |
| 4248 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4249 | if (recovery_type > NFS_LOCK_NEW) { |
| 4250 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4251 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4252 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4253 | } |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4254 | msg.rpc_argp = &data->arg; |
| 4255 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4256 | task_setup_data.callback_data = data; |
| 4257 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4258 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4259 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4260 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4261 | if (ret == 0) { |
| 4262 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4263 | if (ret) |
| 4264 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4265 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4266 | } else |
| 4267 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4268 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4269 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4270 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4271 | } |
| 4272 | |
| 4273 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4274 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4275 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4276 | struct nfs4_exception exception = { }; |
| 4277 | int err; |
| 4278 | |
| 4279 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4280 | /* Cache the lock if possible... */ |
| 4281 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4282 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4283 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4284 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4285 | break; |
| 4286 | nfs4_handle_exception(server, err, &exception); |
| 4287 | } while (exception.retry); |
| 4288 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4289 | } |
| 4290 | |
| 4291 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4292 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4293 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4294 | struct nfs4_exception exception = { }; |
| 4295 | int err; |
| 4296 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4297 | err = nfs4_set_lock_state(state, request); |
| 4298 | if (err != 0) |
| 4299 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4300 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4301 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4302 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4303 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4304 | switch (err) { |
| 4305 | default: |
| 4306 | goto out; |
| 4307 | case -NFS4ERR_GRACE: |
| 4308 | case -NFS4ERR_DELAY: |
| 4309 | nfs4_handle_exception(server, err, &exception); |
| 4310 | err = 0; |
| 4311 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4312 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4313 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4314 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4315 | } |
| 4316 | |
| 4317 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4318 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4319 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4320 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4321 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4322 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4323 | if ((fl_flags & FL_POSIX) && |
| 4324 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4325 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4326 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4327 | status = nfs4_set_lock_state(state, request); |
| 4328 | if (status != 0) |
| 4329 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4330 | request->fl_flags |= FL_ACCESS; |
| 4331 | status = do_vfs_lock(request->fl_file, request); |
| 4332 | if (status < 0) |
| 4333 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4334 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4335 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4336 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4337 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4338 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4339 | status = do_vfs_lock(request->fl_file, request); |
| 4340 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4341 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4342 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4343 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4344 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4345 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4346 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4347 | if (do_vfs_lock(request->fl_file, request) < 0) |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4348 | 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] | 4349 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4350 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4351 | out: |
| 4352 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4353 | return status; |
| 4354 | } |
| 4355 | |
| 4356 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4357 | { |
| 4358 | struct nfs4_exception exception = { }; |
| 4359 | int err; |
| 4360 | |
| 4361 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4362 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4363 | if (err == -NFS4ERR_DENIED) |
| 4364 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4365 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4366 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4367 | } while (exception.retry); |
| 4368 | return err; |
| 4369 | } |
| 4370 | |
| 4371 | static int |
| 4372 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4373 | { |
| 4374 | struct nfs_open_context *ctx; |
| 4375 | struct nfs4_state *state; |
| 4376 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4377 | int status; |
| 4378 | |
| 4379 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4380 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4381 | state = ctx->state; |
| 4382 | |
| 4383 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4384 | return -EINVAL; |
| 4385 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4386 | if (IS_GETLK(cmd)) { |
| 4387 | if (state != NULL) |
| 4388 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4389 | return 0; |
| 4390 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4391 | |
| 4392 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4393 | return -EINVAL; |
| 4394 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4395 | if (request->fl_type == F_UNLCK) { |
| 4396 | if (state != NULL) |
| 4397 | return nfs4_proc_unlck(state, cmd, request); |
| 4398 | return 0; |
| 4399 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4400 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4401 | if (state == NULL) |
| 4402 | return -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4403 | do { |
| 4404 | status = nfs4_proc_setlk(state, cmd, request); |
| 4405 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4406 | break; |
| 4407 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4408 | status = -ERESTARTSYS; |
| 4409 | if (signalled()) |
| 4410 | break; |
| 4411 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4412 | return status; |
| 4413 | } |
| 4414 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4415 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4416 | { |
| 4417 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4418 | struct nfs4_exception exception = { }; |
| 4419 | int err; |
| 4420 | |
| 4421 | err = nfs4_set_lock_state(state, fl); |
| 4422 | if (err != 0) |
| 4423 | goto out; |
| 4424 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4425 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4426 | switch (err) { |
| 4427 | default: |
| 4428 | printk(KERN_ERR "%s: unhandled error %d.\n", |
| 4429 | __func__, err); |
| 4430 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4431 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4432 | goto out; |
| 4433 | case -NFS4ERR_EXPIRED: |
| 4434 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4435 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4436 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4437 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4438 | case -NFS4ERR_BADSESSION: |
| 4439 | case -NFS4ERR_BADSLOT: |
| 4440 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4441 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4442 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4443 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4444 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4445 | case -ERESTARTSYS: |
| 4446 | /* |
| 4447 | * The show must go on: exit, but mark the |
| 4448 | * stateid as needing recovery. |
| 4449 | */ |
| 4450 | case -NFS4ERR_ADMIN_REVOKED: |
| 4451 | case -NFS4ERR_BAD_STATEID: |
| 4452 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4453 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4454 | err = 0; |
| 4455 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4456 | case -EKEYEXPIRED: |
| 4457 | /* |
| 4458 | * User RPCSEC_GSS context has expired. |
| 4459 | * We cannot recover this stateid now, so |
| 4460 | * skip it and allow recovery thread to |
| 4461 | * proceed. |
| 4462 | */ |
| 4463 | err = 0; |
| 4464 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4465 | case -ENOMEM: |
| 4466 | case -NFS4ERR_DENIED: |
| 4467 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4468 | err = 0; |
| 4469 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4470 | case -NFS4ERR_DELAY: |
| 4471 | break; |
| 4472 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4473 | err = nfs4_handle_exception(server, err, &exception); |
| 4474 | } while (exception.retry); |
| 4475 | out: |
| 4476 | return err; |
| 4477 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4478 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4479 | static void nfs4_release_lockowner_release(void *calldata) |
| 4480 | { |
| 4481 | kfree(calldata); |
| 4482 | } |
| 4483 | |
| 4484 | const struct rpc_call_ops nfs4_release_lockowner_ops = { |
| 4485 | .rpc_release = nfs4_release_lockowner_release, |
| 4486 | }; |
| 4487 | |
| 4488 | void nfs4_release_lockowner(const struct nfs4_lock_state *lsp) |
| 4489 | { |
| 4490 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
| 4491 | struct nfs_release_lockowner_args *args; |
| 4492 | struct rpc_message msg = { |
| 4493 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 4494 | }; |
| 4495 | |
| 4496 | if (server->nfs_client->cl_mvops->minor_version != 0) |
| 4497 | return; |
| 4498 | args = kmalloc(sizeof(*args), GFP_NOFS); |
| 4499 | if (!args) |
| 4500 | return; |
| 4501 | args->lock_owner.clientid = server->nfs_client->cl_clientid; |
| 4502 | args->lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4503 | args->lock_owner.s_dev = server->s_dev; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4504 | msg.rpc_argp = args; |
| 4505 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args); |
| 4506 | } |
| 4507 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4508 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4509 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4510 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 4511 | const void *buf, size_t buflen, |
| 4512 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4513 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4514 | if (strcmp(key, "") != 0) |
| 4515 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4516 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4517 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4518 | } |
| 4519 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4520 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 4521 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4522 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4523 | if (strcmp(key, "") != 0) |
| 4524 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4525 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4526 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4527 | } |
| 4528 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4529 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 4530 | size_t list_len, const char *name, |
| 4531 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4532 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4533 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4534 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4535 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4536 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4537 | |
| 4538 | if (list && len <= list_len) |
| 4539 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4540 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4541 | } |
| 4542 | |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4543 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4544 | { |
| 4545 | if (!((fattr->valid & NFS_ATTR_FATTR_FILEID) && |
| 4546 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
| 4547 | (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL))) |
| 4548 | return; |
| 4549 | |
| 4550 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 4551 | NFS_ATTR_FATTR_NLINK; |
| 4552 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4553 | fattr->nlink = 2; |
| 4554 | } |
| 4555 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 4556 | int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 4557 | struct nfs4_fs_locations *fs_locations, struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4558 | { |
| 4559 | struct nfs_server *server = NFS_SERVER(dir); |
| 4560 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4561 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 4562 | [1] = FATTR4_WORD1_MOUNTED_ON_FILEID, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4563 | }; |
| 4564 | struct nfs4_fs_locations_arg args = { |
| 4565 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4566 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4567 | .page = page, |
| 4568 | .bitmask = bitmask, |
| 4569 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4570 | struct nfs4_fs_locations_res res = { |
| 4571 | .fs_locations = fs_locations, |
| 4572 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4573 | struct rpc_message msg = { |
| 4574 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4575 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4576 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4577 | }; |
| 4578 | int status; |
| 4579 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4580 | dprintk("%s: start\n", __func__); |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4581 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4582 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 4583 | fs_locations->nlocations = 0; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 4584 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4585 | nfs_fixup_referral_attributes(&fs_locations->fattr); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4586 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4587 | return status; |
| 4588 | } |
| 4589 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4590 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4591 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4592 | * Check the exchange flags returned by the server for invalid flags, having |
| 4593 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 4594 | * DS flags set. |
| 4595 | */ |
| 4596 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 4597 | { |
| 4598 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 4599 | goto out_inval; |
| 4600 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 4601 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 4602 | goto out_inval; |
| 4603 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 4604 | goto out_inval; |
| 4605 | return NFS_OK; |
| 4606 | out_inval: |
| 4607 | return -NFS4ERR_INVAL; |
| 4608 | } |
| 4609 | |
| 4610 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4611 | * nfs4_proc_exchange_id() |
| 4612 | * |
| 4613 | * Since the clientid has expired, all compounds using sessions |
| 4614 | * associated with the stale clientid will be returning |
| 4615 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 4616 | * be in some phase of session reset. |
| 4617 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 4618 | 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] | 4619 | { |
| 4620 | nfs4_verifier verifier; |
| 4621 | struct nfs41_exchange_id_args args = { |
| 4622 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4623 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4624 | }; |
| 4625 | struct nfs41_exchange_id_res res = { |
| 4626 | .client = clp, |
| 4627 | }; |
| 4628 | int status; |
| 4629 | struct rpc_message msg = { |
| 4630 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 4631 | .rpc_argp = &args, |
| 4632 | .rpc_resp = &res, |
| 4633 | .rpc_cred = cred, |
| 4634 | }; |
| 4635 | __be32 *p; |
| 4636 | |
| 4637 | dprintk("--> %s\n", __func__); |
| 4638 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 4639 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4640 | p = (u32 *)verifier.data; |
| 4641 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 4642 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 4643 | args.verifier = &verifier; |
| 4644 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4645 | args.id_len = scnprintf(args.id, sizeof(args.id), |
| 4646 | "%s/%s.%s/%u", |
| 4647 | clp->cl_ipaddr, |
| 4648 | init_utsname()->nodename, |
| 4649 | init_utsname()->domainname, |
| 4650 | clp->cl_rpcclient->cl_auth->au_flavor); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4651 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4652 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 4653 | if (!status) |
| 4654 | status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4655 | dprintk("<-- %s status= %d\n", __func__, status); |
| 4656 | return status; |
| 4657 | } |
| 4658 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4659 | struct nfs4_get_lease_time_data { |
| 4660 | struct nfs4_get_lease_time_args *args; |
| 4661 | struct nfs4_get_lease_time_res *res; |
| 4662 | struct nfs_client *clp; |
| 4663 | }; |
| 4664 | |
| 4665 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 4666 | void *calldata) |
| 4667 | { |
| 4668 | int ret; |
| 4669 | struct nfs4_get_lease_time_data *data = |
| 4670 | (struct nfs4_get_lease_time_data *)calldata; |
| 4671 | |
| 4672 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4673 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4674 | /* just setup sequence, do not trigger session recovery |
| 4675 | since we're invoked within one */ |
| 4676 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4677 | &data->args->la_seq_args, |
| 4678 | &data->res->lr_seq_res, 0, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4679 | |
| 4680 | BUG_ON(ret == -EAGAIN); |
| 4681 | rpc_call_start(task); |
| 4682 | dprintk("<-- %s\n", __func__); |
| 4683 | } |
| 4684 | |
| 4685 | /* |
| 4686 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 4687 | * from sequence operation or clientid errors. |
| 4688 | */ |
| 4689 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 4690 | { |
| 4691 | struct nfs4_get_lease_time_data *data = |
| 4692 | (struct nfs4_get_lease_time_data *)calldata; |
| 4693 | |
| 4694 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4695 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 4696 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4697 | switch (task->tk_status) { |
| 4698 | case -NFS4ERR_DELAY: |
| 4699 | case -NFS4ERR_GRACE: |
| 4700 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 4701 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 4702 | task->tk_status = 0; |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 4703 | nfs_restart_rpc(task, data->clp); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4704 | return; |
| 4705 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4706 | dprintk("<-- %s\n", __func__); |
| 4707 | } |
| 4708 | |
| 4709 | struct rpc_call_ops nfs4_get_lease_time_ops = { |
| 4710 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 4711 | .rpc_call_done = nfs4_get_lease_time_done, |
| 4712 | }; |
| 4713 | |
| 4714 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 4715 | { |
| 4716 | struct rpc_task *task; |
| 4717 | struct nfs4_get_lease_time_args args; |
| 4718 | struct nfs4_get_lease_time_res res = { |
| 4719 | .lr_fsinfo = fsinfo, |
| 4720 | }; |
| 4721 | struct nfs4_get_lease_time_data data = { |
| 4722 | .args = &args, |
| 4723 | .res = &res, |
| 4724 | .clp = clp, |
| 4725 | }; |
| 4726 | struct rpc_message msg = { |
| 4727 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 4728 | .rpc_argp = &args, |
| 4729 | .rpc_resp = &res, |
| 4730 | }; |
| 4731 | struct rpc_task_setup task_setup = { |
| 4732 | .rpc_client = clp->cl_rpcclient, |
| 4733 | .rpc_message = &msg, |
| 4734 | .callback_ops = &nfs4_get_lease_time_ops, |
| 4735 | .callback_data = &data |
| 4736 | }; |
| 4737 | int status; |
| 4738 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4739 | dprintk("--> %s\n", __func__); |
| 4740 | task = rpc_run_task(&task_setup); |
| 4741 | |
| 4742 | if (IS_ERR(task)) |
| 4743 | status = PTR_ERR(task); |
| 4744 | else { |
| 4745 | status = task->tk_status; |
| 4746 | rpc_put_task(task); |
| 4747 | } |
| 4748 | dprintk("<-- %s return %d\n", __func__, status); |
| 4749 | |
| 4750 | return status; |
| 4751 | } |
| 4752 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4753 | /* |
| 4754 | * Reset a slot table |
| 4755 | */ |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4756 | static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 4757 | int ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4758 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4759 | struct nfs4_slot *new = NULL; |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4760 | int i; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4761 | int ret = 0; |
| 4762 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4763 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 4764 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4765 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4766 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 4767 | if (max_reqs != tbl->max_slots) { |
| 4768 | ret = -ENOMEM; |
| 4769 | new = kmalloc(max_reqs * sizeof(struct nfs4_slot), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4770 | GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4771 | if (!new) |
| 4772 | goto out; |
| 4773 | ret = 0; |
| 4774 | kfree(tbl->slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4775 | } |
| 4776 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4777 | if (new) { |
| 4778 | tbl->slots = new; |
| 4779 | tbl->max_slots = max_reqs; |
| 4780 | } |
| 4781 | for (i = 0; i < tbl->max_slots; ++i) |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4782 | tbl->slots[i].seq_nr = ivalue; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4783 | spin_unlock(&tbl->slot_tbl_lock); |
| 4784 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4785 | tbl, tbl->slots, tbl->max_slots); |
| 4786 | out: |
| 4787 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4788 | return ret; |
| 4789 | } |
| 4790 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4791 | /* |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4792 | * Reset the forechannel and backchannel slot tables |
| 4793 | */ |
| 4794 | static int nfs4_reset_slot_tables(struct nfs4_session *session) |
| 4795 | { |
| 4796 | int status; |
| 4797 | |
| 4798 | status = nfs4_reset_slot_table(&session->fc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4799 | session->fc_attrs.max_reqs, 1); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4800 | if (status) |
| 4801 | return status; |
| 4802 | |
| 4803 | status = nfs4_reset_slot_table(&session->bc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4804 | session->bc_attrs.max_reqs, 0); |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4805 | return status; |
| 4806 | } |
| 4807 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4808 | /* Destroy the slot table */ |
| 4809 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 4810 | { |
| 4811 | if (session->fc_slot_table.slots != NULL) { |
| 4812 | kfree(session->fc_slot_table.slots); |
| 4813 | session->fc_slot_table.slots = NULL; |
| 4814 | } |
| 4815 | if (session->bc_slot_table.slots != NULL) { |
| 4816 | kfree(session->bc_slot_table.slots); |
| 4817 | session->bc_slot_table.slots = NULL; |
| 4818 | } |
| 4819 | return; |
| 4820 | } |
| 4821 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4822 | /* |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4823 | * Initialize slot table |
| 4824 | */ |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4825 | static int nfs4_init_slot_table(struct nfs4_slot_table *tbl, |
| 4826 | int max_slots, int ivalue) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4827 | { |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4828 | struct nfs4_slot *slot; |
| 4829 | int ret = -ENOMEM; |
| 4830 | |
| 4831 | BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE); |
| 4832 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4833 | dprintk("--> %s: max_reqs=%u\n", __func__, max_slots); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4834 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4835 | slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4836 | if (!slot) |
| 4837 | goto out; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4838 | ret = 0; |
| 4839 | |
| 4840 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4841 | tbl->max_slots = max_slots; |
| 4842 | tbl->slots = slot; |
| 4843 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 4844 | spin_unlock(&tbl->slot_tbl_lock); |
| 4845 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4846 | tbl, tbl->slots, tbl->max_slots); |
| 4847 | out: |
| 4848 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4849 | return ret; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4850 | } |
| 4851 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4852 | /* |
| 4853 | * Initialize the forechannel and backchannel tables |
| 4854 | */ |
| 4855 | static int nfs4_init_slot_tables(struct nfs4_session *session) |
| 4856 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4857 | struct nfs4_slot_table *tbl; |
| 4858 | int status = 0; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4859 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4860 | tbl = &session->fc_slot_table; |
| 4861 | if (tbl->slots == NULL) { |
| 4862 | status = nfs4_init_slot_table(tbl, |
| 4863 | session->fc_attrs.max_reqs, 1); |
| 4864 | if (status) |
| 4865 | return status; |
| 4866 | } |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4867 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4868 | tbl = &session->bc_slot_table; |
| 4869 | if (tbl->slots == NULL) { |
| 4870 | status = nfs4_init_slot_table(tbl, |
| 4871 | session->bc_attrs.max_reqs, 0); |
| 4872 | if (status) |
| 4873 | nfs4_destroy_slot_tables(session); |
| 4874 | } |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4875 | |
| 4876 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4877 | } |
| 4878 | |
| 4879 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 4880 | { |
| 4881 | struct nfs4_session *session; |
| 4882 | struct nfs4_slot_table *tbl; |
| 4883 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4884 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4885 | if (!session) |
| 4886 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 4887 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4888 | tbl = &session->fc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 4889 | tbl->highest_used_slotid = -1; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4890 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4891 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 4892 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4893 | |
| 4894 | tbl = &session->bc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 4895 | tbl->highest_used_slotid = -1; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4896 | spin_lock_init(&tbl->slot_tbl_lock); |
| 4897 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 4898 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4899 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 4900 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 4901 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4902 | session->clp = clp; |
| 4903 | return session; |
| 4904 | } |
| 4905 | |
| 4906 | void nfs4_destroy_session(struct nfs4_session *session) |
| 4907 | { |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 4908 | nfs4_proc_destroy_session(session); |
| 4909 | dprintk("%s Destroy backchannel for xprt %p\n", |
| 4910 | __func__, session->clp->cl_rpcclient->cl_xprt); |
| 4911 | xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt, |
| 4912 | NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4913 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4914 | kfree(session); |
| 4915 | } |
| 4916 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4917 | /* |
| 4918 | * Initialize the values to be used by the client in CREATE_SESSION |
| 4919 | * If nfs4_init_session set the fore channel request and response sizes, |
| 4920 | * use them. |
| 4921 | * |
| 4922 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 4923 | * always set csa_cachethis to FALSE because the current implementation |
| 4924 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 4925 | */ |
| 4926 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 4927 | { |
| 4928 | struct nfs4_session *session = args->client->cl_session; |
| 4929 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 4930 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 4931 | |
| 4932 | if (mxrqst_sz == 0) |
| 4933 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 4934 | if (mxresp_sz == 0) |
| 4935 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 4936 | /* Fore channel attributes */ |
| 4937 | args->fc_attrs.headerpadsz = 0; |
| 4938 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 4939 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4940 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
| 4941 | args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs; |
| 4942 | |
| 4943 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 4944 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4945 | __func__, |
| 4946 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 4947 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4948 | |
| 4949 | /* Back channel attributes */ |
| 4950 | args->bc_attrs.headerpadsz = 0; |
| 4951 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 4952 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 4953 | args->bc_attrs.max_resp_sz_cached = 0; |
| 4954 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 4955 | args->bc_attrs.max_reqs = 1; |
| 4956 | |
| 4957 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 4958 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 4959 | __func__, |
| 4960 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 4961 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 4962 | args->bc_attrs.max_reqs); |
| 4963 | } |
| 4964 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4965 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4966 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4967 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 4968 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 4969 | |
| 4970 | if (rcvd->headerpadsz > sent->headerpadsz) |
| 4971 | return -EINVAL; |
| 4972 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 4973 | return -EINVAL; |
| 4974 | /* |
| 4975 | * Our requested max_ops is the minimum we need; we're not |
| 4976 | * prepared to break up compounds into smaller pieces than that. |
| 4977 | * So, no point even trying to continue if the server won't |
| 4978 | * cooperate: |
| 4979 | */ |
| 4980 | if (rcvd->max_ops < sent->max_ops) |
| 4981 | return -EINVAL; |
| 4982 | if (rcvd->max_reqs == 0) |
| 4983 | return -EINVAL; |
| 4984 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4985 | } |
| 4986 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4987 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 4988 | { |
| 4989 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 4990 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4991 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4992 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 4993 | return -EINVAL; |
| 4994 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 4995 | return -EINVAL; |
| 4996 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 4997 | return -EINVAL; |
| 4998 | /* These would render the backchannel useless: */ |
| 4999 | if (rcvd->max_ops == 0) |
| 5000 | return -EINVAL; |
| 5001 | if (rcvd->max_reqs == 0) |
| 5002 | return -EINVAL; |
| 5003 | return 0; |
| 5004 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5005 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5006 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5007 | struct nfs4_session *session) |
| 5008 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5009 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5010 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5011 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5012 | if (ret) |
| 5013 | return ret; |
| 5014 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5015 | } |
| 5016 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5017 | static int _nfs4_proc_create_session(struct nfs_client *clp) |
| 5018 | { |
| 5019 | struct nfs4_session *session = clp->cl_session; |
| 5020 | struct nfs41_create_session_args args = { |
| 5021 | .client = clp, |
| 5022 | .cb_program = NFS4_CALLBACK, |
| 5023 | }; |
| 5024 | struct nfs41_create_session_res res = { |
| 5025 | .client = clp, |
| 5026 | }; |
| 5027 | struct rpc_message msg = { |
| 5028 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5029 | .rpc_argp = &args, |
| 5030 | .rpc_resp = &res, |
| 5031 | }; |
| 5032 | int status; |
| 5033 | |
| 5034 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5035 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5036 | |
| 5037 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); |
| 5038 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5039 | if (!status) |
| 5040 | /* Verify the session's negotiated channel_attrs values */ |
| 5041 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5042 | if (!status) { |
| 5043 | /* Increment the clientid slot sequence id */ |
| 5044 | clp->cl_seqid++; |
| 5045 | } |
| 5046 | |
| 5047 | return status; |
| 5048 | } |
| 5049 | |
| 5050 | /* |
| 5051 | * Issues a CREATE_SESSION operation to the server. |
| 5052 | * It is the responsibility of the caller to verify the session is |
| 5053 | * expired before calling this routine. |
| 5054 | */ |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5055 | int nfs4_proc_create_session(struct nfs_client *clp) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5056 | { |
| 5057 | int status; |
| 5058 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5059 | struct nfs4_session *session = clp->cl_session; |
Ricardo Labiaga | 7d6d63d | 2011-03-09 13:13:44 -0500 | [diff] [blame] | 5060 | long timeout = 0; |
| 5061 | int err; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5062 | |
| 5063 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5064 | |
Ricardo Labiaga | 7d6d63d | 2011-03-09 13:13:44 -0500 | [diff] [blame] | 5065 | do { |
| 5066 | status = _nfs4_proc_create_session(clp); |
| 5067 | if (status == -NFS4ERR_DELAY) { |
| 5068 | err = nfs4_delay(clp->cl_rpcclient, &timeout); |
| 5069 | if (err) |
| 5070 | status = err; |
| 5071 | } |
| 5072 | } while (status == -NFS4ERR_DELAY); |
| 5073 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5074 | if (status) |
| 5075 | goto out; |
| 5076 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5077 | /* Init and reset the fore channel */ |
| 5078 | status = nfs4_init_slot_tables(session); |
| 5079 | dprintk("slot table initialization returned %d\n", status); |
| 5080 | if (status) |
| 5081 | goto out; |
| 5082 | status = nfs4_reset_slot_tables(session); |
| 5083 | dprintk("slot table reset returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5084 | if (status) |
| 5085 | goto out; |
| 5086 | |
| 5087 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5088 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5089 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5090 | out: |
| 5091 | dprintk("<-- %s\n", __func__); |
| 5092 | return status; |
| 5093 | } |
| 5094 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5095 | /* |
| 5096 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5097 | * The caller must serialize access to this routine. |
| 5098 | */ |
| 5099 | int nfs4_proc_destroy_session(struct nfs4_session *session) |
| 5100 | { |
| 5101 | int status = 0; |
| 5102 | struct rpc_message msg; |
| 5103 | |
| 5104 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5105 | |
| 5106 | /* session is still being setup */ |
| 5107 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5108 | return status; |
| 5109 | |
| 5110 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; |
| 5111 | msg.rpc_argp = session; |
| 5112 | msg.rpc_resp = NULL; |
| 5113 | msg.rpc_cred = NULL; |
| 5114 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); |
| 5115 | |
| 5116 | if (status) |
| 5117 | printk(KERN_WARNING |
| 5118 | "Got error %d from the server on DESTROY_SESSION. " |
| 5119 | "Session has been destroyed regardless...\n", status); |
| 5120 | |
| 5121 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5122 | return status; |
| 5123 | } |
| 5124 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5125 | int nfs4_init_session(struct nfs_server *server) |
| 5126 | { |
| 5127 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5128 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5129 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5130 | int ret; |
| 5131 | |
| 5132 | if (!nfs4_has_session(clp)) |
| 5133 | return 0; |
| 5134 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5135 | session = clp->cl_session; |
| 5136 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5137 | return 0; |
| 5138 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5139 | rsize = server->rsize; |
| 5140 | if (rsize == 0) |
| 5141 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5142 | wsize = server->wsize; |
| 5143 | if (wsize == 0) |
| 5144 | wsize = NFS_MAX_FILE_IO_SIZE; |
| 5145 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5146 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5147 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5148 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5149 | ret = nfs4_recover_expired_lease(server); |
| 5150 | if (!ret) |
| 5151 | ret = nfs4_check_client_ready(clp); |
| 5152 | return ret; |
| 5153 | } |
| 5154 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5155 | int nfs4_init_ds_session(struct nfs_client *clp) |
| 5156 | { |
| 5157 | struct nfs4_session *session = clp->cl_session; |
| 5158 | int ret; |
| 5159 | |
| 5160 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5161 | return 0; |
| 5162 | |
| 5163 | ret = nfs4_client_recover_expired_lease(clp); |
| 5164 | if (!ret) |
| 5165 | /* Test for the DS role */ |
| 5166 | if (!is_ds_client(clp)) |
| 5167 | ret = -ENODEV; |
| 5168 | if (!ret) |
| 5169 | ret = nfs4_check_client_ready(clp); |
| 5170 | return ret; |
| 5171 | |
| 5172 | } |
| 5173 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 5174 | |
| 5175 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5176 | /* |
| 5177 | * Renew the cl_session lease. |
| 5178 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5179 | struct nfs4_sequence_data { |
| 5180 | struct nfs_client *clp; |
| 5181 | struct nfs4_sequence_args args; |
| 5182 | struct nfs4_sequence_res res; |
| 5183 | }; |
| 5184 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5185 | static void nfs41_sequence_release(void *data) |
| 5186 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5187 | struct nfs4_sequence_data *calldata = data; |
| 5188 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5189 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5190 | if (atomic_read(&clp->cl_count) > 1) |
| 5191 | nfs4_schedule_state_renewal(clp); |
| 5192 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5193 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5194 | } |
| 5195 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5196 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5197 | { |
| 5198 | switch(task->tk_status) { |
| 5199 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5200 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5201 | return -EAGAIN; |
| 5202 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5203 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5204 | } |
| 5205 | return 0; |
| 5206 | } |
| 5207 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5208 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5209 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5210 | struct nfs4_sequence_data *calldata = data; |
| 5211 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5212 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5213 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5214 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5215 | |
| 5216 | if (task->tk_status < 0) { |
| 5217 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5218 | if (atomic_read(&clp->cl_count) == 1) |
| 5219 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5220 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5221 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5222 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5223 | return; |
| 5224 | } |
| 5225 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5226 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5227 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5228 | dprintk("<-- %s\n", __func__); |
| 5229 | } |
| 5230 | |
| 5231 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5232 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5233 | struct nfs4_sequence_data *calldata = data; |
| 5234 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5235 | struct nfs4_sequence_args *args; |
| 5236 | struct nfs4_sequence_res *res; |
| 5237 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5238 | args = task->tk_msg.rpc_argp; |
| 5239 | res = task->tk_msg.rpc_resp; |
| 5240 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5241 | if (nfs41_setup_sequence(clp->cl_session, args, res, 0, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5242 | return; |
| 5243 | rpc_call_start(task); |
| 5244 | } |
| 5245 | |
| 5246 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5247 | .rpc_call_done = nfs41_sequence_call_done, |
| 5248 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5249 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5250 | }; |
| 5251 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5252 | 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] | 5253 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5254 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5255 | struct rpc_message msg = { |
| 5256 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5257 | .rpc_cred = cred, |
| 5258 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5259 | struct rpc_task_setup task_setup_data = { |
| 5260 | .rpc_client = clp->cl_rpcclient, |
| 5261 | .rpc_message = &msg, |
| 5262 | .callback_ops = &nfs41_sequence_ops, |
| 5263 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5264 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5265 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5266 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5267 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5268 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5269 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5270 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5271 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5272 | } |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5273 | msg.rpc_argp = &calldata->args; |
| 5274 | msg.rpc_resp = &calldata->res; |
| 5275 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5276 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5277 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5278 | return rpc_run_task(&task_setup_data); |
| 5279 | } |
| 5280 | |
| 5281 | static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5282 | { |
| 5283 | struct rpc_task *task; |
| 5284 | int ret = 0; |
| 5285 | |
| 5286 | task = _nfs41_proc_sequence(clp, cred); |
| 5287 | if (IS_ERR(task)) |
| 5288 | ret = PTR_ERR(task); |
| 5289 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5290 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5291 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5292 | return ret; |
| 5293 | } |
| 5294 | |
| 5295 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5296 | { |
| 5297 | struct rpc_task *task; |
| 5298 | int ret; |
| 5299 | |
| 5300 | task = _nfs41_proc_sequence(clp, cred); |
| 5301 | if (IS_ERR(task)) { |
| 5302 | ret = PTR_ERR(task); |
| 5303 | goto out; |
| 5304 | } |
| 5305 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5306 | if (!ret) { |
| 5307 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5308 | |
| 5309 | if (task->tk_status == 0) |
| 5310 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5311 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5312 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5313 | rpc_put_task(task); |
| 5314 | out: |
| 5315 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5316 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5317 | } |
| 5318 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5319 | struct nfs4_reclaim_complete_data { |
| 5320 | struct nfs_client *clp; |
| 5321 | struct nfs41_reclaim_complete_args arg; |
| 5322 | struct nfs41_reclaim_complete_res res; |
| 5323 | }; |
| 5324 | |
| 5325 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5326 | { |
| 5327 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5328 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5329 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5330 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5331 | &calldata->arg.seq_args, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5332 | &calldata->res.seq_res, 0, task)) |
| 5333 | return; |
| 5334 | |
| 5335 | rpc_call_start(task); |
| 5336 | } |
| 5337 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5338 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5339 | { |
| 5340 | switch(task->tk_status) { |
| 5341 | case 0: |
| 5342 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5343 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5344 | break; |
| 5345 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5346 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5347 | return -EAGAIN; |
| 5348 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5349 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5350 | } |
| 5351 | return 0; |
| 5352 | } |
| 5353 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5354 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5355 | { |
| 5356 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5357 | struct nfs_client *clp = calldata->clp; |
| 5358 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5359 | |
| 5360 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5361 | if (!nfs41_sequence_done(task, res)) |
| 5362 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5363 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5364 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5365 | rpc_restart_call_prepare(task); |
| 5366 | return; |
| 5367 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5368 | dprintk("<-- %s\n", __func__); |
| 5369 | } |
| 5370 | |
| 5371 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5372 | { |
| 5373 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5374 | |
| 5375 | kfree(calldata); |
| 5376 | } |
| 5377 | |
| 5378 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5379 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5380 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5381 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5382 | }; |
| 5383 | |
| 5384 | /* |
| 5385 | * Issue a global reclaim complete. |
| 5386 | */ |
| 5387 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5388 | { |
| 5389 | struct nfs4_reclaim_complete_data *calldata; |
| 5390 | struct rpc_task *task; |
| 5391 | struct rpc_message msg = { |
| 5392 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5393 | }; |
| 5394 | struct rpc_task_setup task_setup_data = { |
| 5395 | .rpc_client = clp->cl_rpcclient, |
| 5396 | .rpc_message = &msg, |
| 5397 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5398 | .flags = RPC_TASK_ASYNC, |
| 5399 | }; |
| 5400 | int status = -ENOMEM; |
| 5401 | |
| 5402 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5403 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5404 | if (calldata == NULL) |
| 5405 | goto out; |
| 5406 | calldata->clp = clp; |
| 5407 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5408 | |
| 5409 | msg.rpc_argp = &calldata->arg; |
| 5410 | msg.rpc_resp = &calldata->res; |
| 5411 | task_setup_data.callback_data = calldata; |
| 5412 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5413 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5414 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5415 | goto out; |
| 5416 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 5417 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5418 | if (status == 0) |
| 5419 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5420 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5421 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5422 | out: |
| 5423 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5424 | return status; |
| 5425 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5426 | |
| 5427 | static void |
| 5428 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 5429 | { |
| 5430 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5431 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5432 | |
| 5433 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5434 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 5435 | * right now covering the LAYOUTGET we are about to send. |
| 5436 | * However, that is not so catastrophic, and there seems |
| 5437 | * to be no way to prevent it completely. |
| 5438 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5439 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
| 5440 | &lgp->res.seq_res, 0, task)) |
| 5441 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5442 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 5443 | NFS_I(lgp->args.inode)->layout, |
| 5444 | lgp->args.ctx->state)) { |
| 5445 | rpc_exit(task, NFS4_OK); |
| 5446 | return; |
| 5447 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5448 | rpc_call_start(task); |
| 5449 | } |
| 5450 | |
| 5451 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 5452 | { |
| 5453 | struct nfs4_layoutget *lgp = calldata; |
| 5454 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5455 | |
| 5456 | dprintk("--> %s\n", __func__); |
| 5457 | |
| 5458 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 5459 | return; |
| 5460 | |
| 5461 | switch (task->tk_status) { |
| 5462 | case 0: |
| 5463 | break; |
| 5464 | case -NFS4ERR_LAYOUTTRYLATER: |
| 5465 | case -NFS4ERR_RECALLCONFLICT: |
| 5466 | task->tk_status = -NFS4ERR_DELAY; |
| 5467 | /* Fall through */ |
| 5468 | default: |
| 5469 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5470 | rpc_restart_call_prepare(task); |
| 5471 | return; |
| 5472 | } |
| 5473 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5474 | dprintk("<-- %s\n", __func__); |
| 5475 | } |
| 5476 | |
| 5477 | static void nfs4_layoutget_release(void *calldata) |
| 5478 | { |
| 5479 | struct nfs4_layoutget *lgp = calldata; |
| 5480 | |
| 5481 | dprintk("--> %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5482 | if (lgp->res.layout.buf != NULL) |
| 5483 | free_page((unsigned long) lgp->res.layout.buf); |
| 5484 | put_nfs_open_context(lgp->args.ctx); |
| 5485 | kfree(calldata); |
| 5486 | dprintk("<-- %s\n", __func__); |
| 5487 | } |
| 5488 | |
| 5489 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 5490 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 5491 | .rpc_call_done = nfs4_layoutget_done, |
| 5492 | .rpc_release = nfs4_layoutget_release, |
| 5493 | }; |
| 5494 | |
| 5495 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) |
| 5496 | { |
| 5497 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5498 | struct rpc_task *task; |
| 5499 | struct rpc_message msg = { |
| 5500 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 5501 | .rpc_argp = &lgp->args, |
| 5502 | .rpc_resp = &lgp->res, |
| 5503 | }; |
| 5504 | struct rpc_task_setup task_setup_data = { |
| 5505 | .rpc_client = server->client, |
| 5506 | .rpc_message = &msg, |
| 5507 | .callback_ops = &nfs4_layoutget_call_ops, |
| 5508 | .callback_data = lgp, |
| 5509 | .flags = RPC_TASK_ASYNC, |
| 5510 | }; |
| 5511 | int status = 0; |
| 5512 | |
| 5513 | dprintk("--> %s\n", __func__); |
| 5514 | |
| 5515 | lgp->res.layout.buf = (void *)__get_free_page(GFP_NOFS); |
| 5516 | if (lgp->res.layout.buf == NULL) { |
| 5517 | nfs4_layoutget_release(lgp); |
| 5518 | return -ENOMEM; |
| 5519 | } |
| 5520 | |
| 5521 | lgp->res.seq_res.sr_slot = NULL; |
| 5522 | task = rpc_run_task(&task_setup_data); |
| 5523 | if (IS_ERR(task)) |
| 5524 | return PTR_ERR(task); |
| 5525 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5526 | if (status == 0) |
| 5527 | status = task->tk_status; |
| 5528 | if (status == 0) |
| 5529 | status = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5530 | rpc_put_task(task); |
| 5531 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5532 | return status; |
| 5533 | } |
| 5534 | |
| 5535 | static int |
| 5536 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5537 | { |
| 5538 | struct nfs4_getdeviceinfo_args args = { |
| 5539 | .pdev = pdev, |
| 5540 | }; |
| 5541 | struct nfs4_getdeviceinfo_res res = { |
| 5542 | .pdev = pdev, |
| 5543 | }; |
| 5544 | struct rpc_message msg = { |
| 5545 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 5546 | .rpc_argp = &args, |
| 5547 | .rpc_resp = &res, |
| 5548 | }; |
| 5549 | int status; |
| 5550 | |
| 5551 | dprintk("--> %s\n", __func__); |
| 5552 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
| 5553 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5554 | |
| 5555 | return status; |
| 5556 | } |
| 5557 | |
| 5558 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5559 | { |
| 5560 | struct nfs4_exception exception = { }; |
| 5561 | int err; |
| 5562 | |
| 5563 | do { |
| 5564 | err = nfs4_handle_exception(server, |
| 5565 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 5566 | &exception); |
| 5567 | } while (exception.retry); |
| 5568 | return err; |
| 5569 | } |
| 5570 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 5571 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5572 | #endif /* CONFIG_NFS_V4_1 */ |
| 5573 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5574 | struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5575 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5576 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5577 | .recover_open = nfs4_open_reclaim, |
| 5578 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5579 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5580 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5581 | }; |
| 5582 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5583 | #if defined(CONFIG_NFS_V4_1) |
| 5584 | struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
| 5585 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 5586 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 5587 | .recover_open = nfs4_open_reclaim, |
| 5588 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5589 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5590 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5591 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5592 | }; |
| 5593 | #endif /* CONFIG_NFS_V4_1 */ |
| 5594 | |
| 5595 | struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5596 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5597 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5598 | .recover_open = nfs4_open_expired, |
| 5599 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5600 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5601 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5602 | }; |
| 5603 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5604 | #if defined(CONFIG_NFS_V4_1) |
| 5605 | struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
| 5606 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 5607 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
| 5608 | .recover_open = nfs4_open_expired, |
| 5609 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5610 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5611 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5612 | }; |
| 5613 | #endif /* CONFIG_NFS_V4_1 */ |
| 5614 | |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5615 | struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
| 5616 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5617 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5618 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5619 | }; |
| 5620 | |
| 5621 | #if defined(CONFIG_NFS_V4_1) |
| 5622 | struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
| 5623 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5624 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5625 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5626 | }; |
| 5627 | #endif |
| 5628 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5629 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 5630 | .minor_version = 0, |
| 5631 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5632 | .validate_stateid = nfs4_validate_delegation_stateid, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5633 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 5634 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 5635 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5636 | }; |
| 5637 | |
| 5638 | #if defined(CONFIG_NFS_V4_1) |
| 5639 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 5640 | .minor_version = 1, |
| 5641 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5642 | .validate_stateid = nfs41_validate_delegation_stateid, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5643 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 5644 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 5645 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5646 | }; |
| 5647 | #endif |
| 5648 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5649 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 5650 | [0] = &nfs_v4_0_minor_ops, |
| 5651 | #if defined(CONFIG_NFS_V4_1) |
| 5652 | [1] = &nfs_v4_1_minor_ops, |
| 5653 | #endif |
| 5654 | }; |
| 5655 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 5656 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5657 | .permission = nfs_permission, |
| 5658 | .getattr = nfs_getattr, |
| 5659 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5660 | .getxattr = generic_getxattr, |
| 5661 | .setxattr = generic_setxattr, |
| 5662 | .listxattr = generic_listxattr, |
| 5663 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5664 | }; |
| 5665 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 5666 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5667 | .version = 4, /* protocol version */ |
| 5668 | .dentry_ops = &nfs4_dentry_operations, |
| 5669 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5670 | .file_inode_ops = &nfs4_file_inode_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5671 | .getroot = nfs4_proc_get_root, |
| 5672 | .getattr = nfs4_proc_getattr, |
| 5673 | .setattr = nfs4_proc_setattr, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5674 | .lookupfh = nfs4_proc_lookupfh, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5675 | .lookup = nfs4_proc_lookup, |
| 5676 | .access = nfs4_proc_access, |
| 5677 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5678 | .create = nfs4_proc_create, |
| 5679 | .remove = nfs4_proc_remove, |
| 5680 | .unlink_setup = nfs4_proc_unlink_setup, |
| 5681 | .unlink_done = nfs4_proc_unlink_done, |
| 5682 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 5683 | .rename_setup = nfs4_proc_rename_setup, |
| 5684 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5685 | .link = nfs4_proc_link, |
| 5686 | .symlink = nfs4_proc_symlink, |
| 5687 | .mkdir = nfs4_proc_mkdir, |
| 5688 | .rmdir = nfs4_proc_remove, |
| 5689 | .readdir = nfs4_proc_readdir, |
| 5690 | .mknod = nfs4_proc_mknod, |
| 5691 | .statfs = nfs4_proc_statfs, |
| 5692 | .fsinfo = nfs4_proc_fsinfo, |
| 5693 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 5694 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5695 | .decode_dirent = nfs4_decode_dirent, |
| 5696 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5697 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5698 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5699 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5700 | .commit_setup = nfs4_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5701 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5702 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5703 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 5704 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 5705 | .open_context = nfs4_atomic_open, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 5706 | .init_client = nfs4_init_client, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5707 | }; |
| 5708 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5709 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 5710 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 5711 | .list = nfs4_xattr_list_nfs4_acl, |
| 5712 | .get = nfs4_xattr_get_nfs4_acl, |
| 5713 | .set = nfs4_xattr_set_nfs4_acl, |
| 5714 | }; |
| 5715 | |
| 5716 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 5717 | &nfs4_xattr_nfs4_acl_handler, |
| 5718 | NULL |
| 5719 | }; |
| 5720 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5721 | /* |
| 5722 | * Local variables: |
| 5723 | * c-basic-offset: 8 |
| 5724 | * End: |
| 5725 | */ |