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> |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 44 | #include <linux/sunrpc/gss_api.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/nfs.h> |
| 46 | #include <linux/nfs4.h> |
| 47 | #include <linux/nfs_fs.h> |
| 48 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 49 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 51 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 52 | #include <linux/module.h> |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 53 | #include <linux/sunrpc/bc_xprt.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 54 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 55 | #include <linux/utsname.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 57 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 59 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 60 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 61 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 62 | #include "pnfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 65 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 66 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 68 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 69 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 70 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 71 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 72 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 73 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | 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] | 75 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 76 | static int _nfs4_proc_lookup(struct rpc_clnt *client, struct inode *dir, |
| 77 | const struct qstr *name, struct nfs_fh *fhandle, |
| 78 | struct nfs_fattr *fattr); |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 79 | 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] | 80 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 81 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 82 | struct nfs4_state *state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 85 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 87 | if (err >= -1000) |
| 88 | return err; |
| 89 | switch (err) { |
| 90 | case -NFS4ERR_RESOURCE: |
| 91 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 92 | case -NFS4ERR_WRONGSEC: |
| 93 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 94 | case -NFS4ERR_BADOWNER: |
| 95 | case -NFS4ERR_BADNAME: |
| 96 | return -EINVAL; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 97 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 99 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 100 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 102 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /* |
| 106 | * This is our standard bitmap for GETATTR requests. |
| 107 | */ |
| 108 | const u32 nfs4_fattr_bitmap[2] = { |
| 109 | FATTR4_WORD0_TYPE |
| 110 | | FATTR4_WORD0_CHANGE |
| 111 | | FATTR4_WORD0_SIZE |
| 112 | | FATTR4_WORD0_FSID |
| 113 | | FATTR4_WORD0_FILEID, |
| 114 | FATTR4_WORD1_MODE |
| 115 | | FATTR4_WORD1_NUMLINKS |
| 116 | | FATTR4_WORD1_OWNER |
| 117 | | FATTR4_WORD1_OWNER_GROUP |
| 118 | | FATTR4_WORD1_RAWDEV |
| 119 | | FATTR4_WORD1_SPACE_USED |
| 120 | | FATTR4_WORD1_TIME_ACCESS |
| 121 | | FATTR4_WORD1_TIME_METADATA |
| 122 | | FATTR4_WORD1_TIME_MODIFY |
| 123 | }; |
| 124 | |
| 125 | const u32 nfs4_statfs_bitmap[2] = { |
| 126 | FATTR4_WORD0_FILES_AVAIL |
| 127 | | FATTR4_WORD0_FILES_FREE |
| 128 | | FATTR4_WORD0_FILES_TOTAL, |
| 129 | FATTR4_WORD1_SPACE_AVAIL |
| 130 | | FATTR4_WORD1_SPACE_FREE |
| 131 | | FATTR4_WORD1_SPACE_TOTAL |
| 132 | }; |
| 133 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 134 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | FATTR4_WORD0_MAXLINK |
| 136 | | FATTR4_WORD0_MAXNAME, |
| 137 | 0 |
| 138 | }; |
| 139 | |
| 140 | const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE |
| 141 | | FATTR4_WORD0_MAXREAD |
| 142 | | FATTR4_WORD0_MAXWRITE |
| 143 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 144 | FATTR4_WORD1_TIME_DELTA |
Andy Adamson | 504913f | 2010-10-20 00:17:57 -0400 | [diff] [blame] | 145 | | FATTR4_WORD1_FS_LAYOUT_TYPES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | }; |
| 147 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 148 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 149 | FATTR4_WORD0_TYPE |
| 150 | | FATTR4_WORD0_CHANGE |
| 151 | | FATTR4_WORD0_SIZE |
| 152 | | FATTR4_WORD0_FSID |
| 153 | | FATTR4_WORD0_FILEID |
| 154 | | FATTR4_WORD0_FS_LOCATIONS, |
| 155 | FATTR4_WORD1_MODE |
| 156 | | FATTR4_WORD1_NUMLINKS |
| 157 | | FATTR4_WORD1_OWNER |
| 158 | | FATTR4_WORD1_OWNER_GROUP |
| 159 | | FATTR4_WORD1_RAWDEV |
| 160 | | FATTR4_WORD1_SPACE_USED |
| 161 | | FATTR4_WORD1_TIME_ACCESS |
| 162 | | FATTR4_WORD1_TIME_METADATA |
| 163 | | FATTR4_WORD1_TIME_MODIFY |
| 164 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 165 | }; |
| 166 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 167 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | struct nfs4_readdir_arg *readdir) |
| 169 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 170 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | BUG_ON(readdir->count < 80); |
| 173 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 174 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 176 | return; |
| 177 | } |
| 178 | |
| 179 | readdir->cookie = 0; |
| 180 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 181 | if (cookie == 2) |
| 182 | return; |
| 183 | |
| 184 | /* |
| 185 | * NFSv4 servers do not return entries for '.' and '..' |
| 186 | * Therefore, we fake these entries here. We let '.' |
| 187 | * have cookie 0 and '..' have cookie 1. Note that |
| 188 | * when talking to the server, we always send cookie 0 |
| 189 | * instead of 1 or 2. |
| 190 | */ |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 191 | start = p = kmap_atomic(*readdir->pages, KM_USER0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | if (cookie == 0) { |
| 194 | *p++ = xdr_one; /* next */ |
| 195 | *p++ = xdr_zero; /* cookie, first word */ |
| 196 | *p++ = xdr_one; /* cookie, second word */ |
| 197 | *p++ = xdr_one; /* entry len */ |
| 198 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 199 | p++; |
| 200 | *p++ = xdr_one; /* bitmap length */ |
| 201 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 202 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 203 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | *p++ = xdr_one; /* next */ |
| 207 | *p++ = xdr_zero; /* cookie, first word */ |
| 208 | *p++ = xdr_two; /* cookie, second word */ |
| 209 | *p++ = xdr_two; /* entry len */ |
| 210 | memcpy(p, "..\0\0", 4); /* entry */ |
| 211 | p++; |
| 212 | *p++ = xdr_one; /* bitmap length */ |
| 213 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 214 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 215 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
| 217 | readdir->pgbase = (char *)p - (char *)start; |
| 218 | readdir->count -= readdir->pgbase; |
| 219 | kunmap_atomic(start, KM_USER0); |
| 220 | } |
| 221 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 222 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 223 | { |
| 224 | int res; |
| 225 | |
| 226 | might_sleep(); |
| 227 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 228 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 229 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 230 | return res; |
| 231 | } |
| 232 | |
| 233 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 234 | { |
| 235 | int res = 0; |
| 236 | |
| 237 | might_sleep(); |
| 238 | |
| 239 | if (*timeout <= 0) |
| 240 | *timeout = NFS4_POLL_RETRY_MIN; |
| 241 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 242 | *timeout = NFS4_POLL_RETRY_MAX; |
| 243 | schedule_timeout_killable(*timeout); |
| 244 | if (fatal_signal_pending(current)) |
| 245 | res = -ERESTARTSYS; |
| 246 | *timeout <<= 1; |
| 247 | return res; |
| 248 | } |
| 249 | |
| 250 | /* This is the error handling routine for processes that are allowed |
| 251 | * to sleep. |
| 252 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 253 | static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 254 | { |
| 255 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 256 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 257 | int ret = errorcode; |
| 258 | |
| 259 | exception->retry = 0; |
| 260 | switch(errorcode) { |
| 261 | case 0: |
| 262 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 263 | case -NFS4ERR_ADMIN_REVOKED: |
| 264 | case -NFS4ERR_BAD_STATEID: |
| 265 | case -NFS4ERR_OPENMODE: |
| 266 | if (state == NULL) |
| 267 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 268 | nfs4_schedule_stateid_recovery(server, state); |
| 269 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 270 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 271 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 272 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 273 | nfs4_schedule_lease_recovery(clp); |
| 274 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 275 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 276 | case -NFS4ERR_BADSESSION: |
| 277 | case -NFS4ERR_BADSLOT: |
| 278 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 279 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 280 | case -NFS4ERR_DEADSESSION: |
| 281 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 282 | case -NFS4ERR_SEQ_MISORDERED: |
| 283 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 284 | errorcode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 285 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 286 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 287 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 288 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 289 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 290 | if (exception->timeout > HZ) { |
| 291 | /* We have retried a decent amount, time to |
| 292 | * fail |
| 293 | */ |
| 294 | ret = -EBUSY; |
| 295 | break; |
| 296 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 297 | case -NFS4ERR_GRACE: |
| 298 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 299 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 300 | ret = nfs4_delay(server->client, &exception->timeout); |
| 301 | if (ret != 0) |
| 302 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 303 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 304 | case -NFS4ERR_OLD_STATEID: |
| 305 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 306 | break; |
| 307 | case -NFS4ERR_BADOWNER: |
| 308 | /* The following works around a Linux server bug! */ |
| 309 | case -NFS4ERR_BADNAME: |
| 310 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 311 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 312 | exception->retry = 1; |
| 313 | printk(KERN_WARNING "NFS: v4 server %s " |
| 314 | "does not accept raw " |
| 315 | "uid/gids. " |
| 316 | "Reenabling the idmapper.\n", |
| 317 | server->nfs_client->cl_hostname); |
| 318 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 319 | } |
| 320 | /* We failed to handle the error */ |
| 321 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 322 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 323 | ret = nfs4_wait_clnt_recover(clp); |
| 324 | if (ret == 0) |
| 325 | exception->retry = 1; |
| 326 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 330 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | spin_lock(&clp->cl_lock); |
| 333 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 334 | clp->cl_last_renewal = timestamp; |
| 335 | spin_unlock(&clp->cl_lock); |
| 336 | } |
| 337 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 338 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 339 | { |
| 340 | do_renew_lease(server->nfs_client, timestamp); |
| 341 | } |
| 342 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 343 | #if defined(CONFIG_NFS_V4_1) |
| 344 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 345 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 346 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 347 | * |
| 348 | * freeing a slot is trivially done by clearing its respective bit |
| 349 | * in the bitmap. |
| 350 | * If the freed slotid equals highest_used_slotid we want to update it |
| 351 | * so that the server would be able to size down the slot table if needed, |
| 352 | * otherwise we know that the highest_used_slotid is still in use. |
| 353 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 354 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 355 | * highest slotid in use. |
| 356 | * If none found, highest_used_slotid is set to -1. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 357 | * |
| 358 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 359 | */ |
| 360 | static void |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 361 | 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] | 362 | { |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 363 | int free_slotid = free_slot - tbl->slots; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 364 | int slotid = free_slotid; |
| 365 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 366 | BUG_ON(slotid < 0 || slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 367 | /* clear used bit in bitmap */ |
| 368 | __clear_bit(slotid, tbl->used_slots); |
| 369 | |
| 370 | /* update highest_used_slotid when it is freed */ |
| 371 | if (slotid == tbl->highest_used_slotid) { |
| 372 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 373 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 374 | tbl->highest_used_slotid = slotid; |
| 375 | else |
| 376 | tbl->highest_used_slotid = -1; |
| 377 | } |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 378 | dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__, |
| 379 | free_slotid, tbl->highest_used_slotid); |
| 380 | } |
| 381 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 382 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 383 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 384 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 385 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 386 | { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 387 | struct rpc_task *task; |
| 388 | |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 389 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 390 | task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq); |
| 391 | if (task) |
| 392 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 393 | return; |
| 394 | } |
| 395 | |
| 396 | if (ses->fc_slot_table.highest_used_slotid != -1) |
| 397 | return; |
| 398 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 399 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 400 | complete(&ses->fc_slot_table.complete); |
| 401 | } |
| 402 | |
| 403 | /* |
| 404 | * Signal state manager thread if session back channel is drained |
| 405 | */ |
| 406 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 407 | { |
| 408 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
| 409 | ses->bc_slot_table.highest_used_slotid != -1) |
| 410 | return; |
| 411 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 412 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 413 | } |
| 414 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 415 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 416 | { |
| 417 | struct nfs4_slot_table *tbl; |
| 418 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 419 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 420 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 421 | /* just wake up the next guy waiting since |
| 422 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 423 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 424 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 425 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 426 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 427 | spin_lock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 428 | nfs4_free_slot(tbl, res->sr_slot); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 429 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 430 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 431 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 432 | } |
| 433 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 434 | 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] | 435 | { |
| 436 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 437 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 438 | |
| 439 | /* |
| 440 | * sr_status remains 1 if an RPC level error occurred. The server |
| 441 | * may or may not have processed the sequence operation.. |
| 442 | * Proceed as if the server received and processed the sequence |
| 443 | * operation. |
| 444 | */ |
| 445 | if (res->sr_status == 1) |
| 446 | res->sr_status = NFS_OK; |
| 447 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 448 | /* don't increment the sequence number if the task wasn't sent */ |
| 449 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 450 | goto out; |
| 451 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 452 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 453 | switch (res->sr_status) { |
| 454 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 455 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 456 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 457 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 458 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 459 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 460 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 461 | if (res->sr_status_flags != 0) |
| 462 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 463 | break; |
| 464 | case -NFS4ERR_DELAY: |
| 465 | /* The server detected a resend of the RPC call and |
| 466 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 467 | * of RFC5661. |
| 468 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 469 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 470 | __func__, |
| 471 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 472 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 473 | goto out_retry; |
| 474 | default: |
| 475 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 476 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 477 | } |
| 478 | out: |
| 479 | /* The session may be reset by one of the error handlers. */ |
| 480 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 481 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 482 | return 1; |
| 483 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 484 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 485 | goto out; |
| 486 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 487 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 488 | } |
| 489 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 490 | static int nfs4_sequence_done(struct rpc_task *task, |
| 491 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 492 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 493 | if (res->sr_session == NULL) |
| 494 | return 1; |
| 495 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 496 | } |
| 497 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 498 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 499 | * nfs4_find_slot - efficiently look for a free slot |
| 500 | * |
| 501 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 502 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 503 | * and respectively set up the sequence operation args. |
| 504 | * 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] | 505 | * |
| 506 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 507 | */ |
| 508 | static u8 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 509 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 510 | { |
| 511 | int slotid; |
| 512 | u8 ret_id = NFS4_MAX_SLOT_TABLE; |
| 513 | BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE); |
| 514 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 515 | dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n", |
| 516 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 517 | tbl->max_slots); |
| 518 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 519 | if (slotid >= tbl->max_slots) |
| 520 | goto out; |
| 521 | __set_bit(slotid, tbl->used_slots); |
| 522 | if (slotid > tbl->highest_used_slotid) |
| 523 | tbl->highest_used_slotid = slotid; |
| 524 | ret_id = slotid; |
| 525 | out: |
| 526 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 527 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 528 | return ret_id; |
| 529 | } |
| 530 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 531 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 532 | struct nfs4_sequence_args *args, |
| 533 | struct nfs4_sequence_res *res, |
| 534 | int cache_reply, |
| 535 | struct rpc_task *task) |
| 536 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 537 | struct nfs4_slot *slot; |
| 538 | struct nfs4_slot_table *tbl; |
| 539 | u8 slotid; |
| 540 | |
| 541 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 542 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 543 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 544 | return 0; |
| 545 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 546 | tbl = &session->fc_slot_table; |
| 547 | |
| 548 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 549 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 550 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 551 | /* |
| 552 | * The state manager will wait until the slot table is empty. |
| 553 | * Schedule the reset thread |
| 554 | */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 555 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 556 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 557 | dprintk("%s Schedule Session Reset\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 558 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 559 | } |
| 560 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 561 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 562 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 563 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 564 | spin_unlock(&tbl->slot_tbl_lock); |
| 565 | dprintk("%s enforce FIFO order\n", __func__); |
| 566 | return -EAGAIN; |
| 567 | } |
| 568 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 569 | slotid = nfs4_find_slot(tbl); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 570 | if (slotid == NFS4_MAX_SLOT_TABLE) { |
| 571 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 572 | spin_unlock(&tbl->slot_tbl_lock); |
| 573 | dprintk("<-- %s: no free slots\n", __func__); |
| 574 | return -EAGAIN; |
| 575 | } |
| 576 | spin_unlock(&tbl->slot_tbl_lock); |
| 577 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 578 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 579 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 580 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 581 | args->sa_slotid = slotid; |
| 582 | args->sa_cache_this = cache_reply; |
| 583 | |
| 584 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 585 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 586 | res->sr_session = session; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 587 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 588 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 589 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 590 | /* |
| 591 | * sr_status is only set in decode_sequence, and so will remain |
| 592 | * set to 1 if an rpc level failure occurs. |
| 593 | */ |
| 594 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 595 | return 0; |
| 596 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 597 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 598 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 599 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 600 | struct nfs4_sequence_args *args, |
| 601 | struct nfs4_sequence_res *res, |
| 602 | int cache_reply, |
| 603 | struct rpc_task *task) |
| 604 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 605 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 606 | int ret = 0; |
| 607 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 608 | if (session == NULL) { |
| 609 | args->sa_session = NULL; |
| 610 | res->sr_session = NULL; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 611 | goto out; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 612 | } |
| 613 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 614 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 615 | __func__, session->clp, session, res->sr_slot ? |
| 616 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 617 | |
| 618 | ret = nfs41_setup_sequence(session, args, res, cache_reply, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 619 | task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 620 | out: |
| 621 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 622 | return ret; |
| 623 | } |
| 624 | |
| 625 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 626 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 627 | struct nfs4_sequence_args *seq_args; |
| 628 | struct nfs4_sequence_res *seq_res; |
| 629 | int cache_reply; |
| 630 | }; |
| 631 | |
| 632 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 633 | { |
| 634 | struct nfs41_call_sync_data *data = calldata; |
| 635 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 636 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 637 | |
| 638 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 639 | data->seq_res, data->cache_reply, task)) |
| 640 | return; |
| 641 | rpc_call_start(task); |
| 642 | } |
| 643 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 644 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 645 | { |
| 646 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 647 | nfs41_call_sync_prepare(task, calldata); |
| 648 | } |
| 649 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 650 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 651 | { |
| 652 | struct nfs41_call_sync_data *data = calldata; |
| 653 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 654 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 655 | } |
| 656 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 657 | struct rpc_call_ops nfs41_call_sync_ops = { |
| 658 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 659 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 660 | }; |
| 661 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 662 | struct rpc_call_ops nfs41_call_priv_sync_ops = { |
| 663 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 664 | .rpc_call_done = nfs41_call_sync_done, |
| 665 | }; |
| 666 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 667 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 668 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 669 | struct rpc_message *msg, |
| 670 | struct nfs4_sequence_args *args, |
| 671 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 672 | int cache_reply, |
| 673 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 674 | { |
| 675 | int ret; |
| 676 | struct rpc_task *task; |
| 677 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 678 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 679 | .seq_args = args, |
| 680 | .seq_res = res, |
| 681 | .cache_reply = cache_reply, |
| 682 | }; |
| 683 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 684 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 685 | .rpc_message = msg, |
| 686 | .callback_ops = &nfs41_call_sync_ops, |
| 687 | .callback_data = &data |
| 688 | }; |
| 689 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 690 | res->sr_slot = NULL; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 691 | if (privileged) |
| 692 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 693 | task = rpc_run_task(&task_setup); |
| 694 | if (IS_ERR(task)) |
| 695 | ret = PTR_ERR(task); |
| 696 | else { |
| 697 | ret = task->tk_status; |
| 698 | rpc_put_task(task); |
| 699 | } |
| 700 | return ret; |
| 701 | } |
| 702 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 703 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 704 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 705 | struct rpc_message *msg, |
| 706 | struct nfs4_sequence_args *args, |
| 707 | struct nfs4_sequence_res *res, |
| 708 | int cache_reply) |
| 709 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 710 | return nfs4_call_sync_sequence(clnt, server, msg, args, res, cache_reply, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 711 | } |
| 712 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 713 | #else |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 714 | static int nfs4_sequence_done(struct rpc_task *task, |
| 715 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 716 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 717 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 718 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 719 | #endif /* CONFIG_NFS_V4_1 */ |
| 720 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 721 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 722 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 723 | struct rpc_message *msg, |
| 724 | struct nfs4_sequence_args *args, |
| 725 | struct nfs4_sequence_res *res, |
| 726 | int cache_reply) |
| 727 | { |
Benny Halevy | f375297 | 2009-04-01 09:22:04 -0400 | [diff] [blame] | 728 | args->sa_session = res->sr_session = NULL; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 729 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 730 | } |
| 731 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 732 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 733 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 734 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 735 | struct rpc_message *msg, |
| 736 | struct nfs4_sequence_args *args, |
| 737 | struct nfs4_sequence_res *res, |
| 738 | int cache_reply) |
| 739 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 740 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 741 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 742 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 743 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 744 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 746 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 748 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 749 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA; |
| 750 | if (!cinfo->atomic || cinfo->before != nfsi->change_attr) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 751 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 752 | nfsi->change_attr = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 753 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | } |
| 755 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 756 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 757 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 758 | struct nfs_openargs o_arg; |
| 759 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 760 | struct nfs_open_confirmargs c_arg; |
| 761 | struct nfs_open_confirmres c_res; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 762 | struct nfs_fattr f_attr; |
| 763 | struct nfs_fattr dir_attr; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 764 | struct path path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 765 | struct dentry *dir; |
| 766 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 767 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 768 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 769 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 770 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 771 | int rpc_status; |
| 772 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 773 | }; |
| 774 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 775 | |
| 776 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 777 | { |
| 778 | p->o_res.f_attr = &p->f_attr; |
| 779 | p->o_res.dir_attr = &p->dir_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 780 | p->o_res.seqid = p->o_arg.seqid; |
| 781 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 782 | p->o_res.server = p->o_arg.server; |
| 783 | nfs_fattr_init(&p->f_attr); |
| 784 | nfs_fattr_init(&p->dir_attr); |
| 785 | } |
| 786 | |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 787 | static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 788 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 789 | const struct iattr *attrs, |
| 790 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 791 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 792 | struct dentry *parent = dget_parent(path->dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 793 | struct inode *dir = parent->d_inode; |
| 794 | struct nfs_server *server = NFS_SERVER(dir); |
| 795 | struct nfs4_opendata *p; |
| 796 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 797 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 798 | if (p == NULL) |
| 799 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 800 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 801 | if (p->o_arg.seqid == NULL) |
| 802 | goto err_free; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 803 | path_get(path); |
| 804 | p->path = *path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 805 | p->dir = parent; |
| 806 | p->owner = sp; |
| 807 | atomic_inc(&sp->so_count); |
| 808 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 809 | p->o_arg.open_flags = flags; |
| 810 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 811 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 812 | p->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 813 | p->o_arg.name = &p->path.dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 814 | p->o_arg.server = server; |
| 815 | p->o_arg.bitmask = server->attr_bitmask; |
| 816 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 817 | if (flags & O_CREAT) { |
| 818 | u32 *s; |
| 819 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 820 | p->o_arg.u.attrs = &p->attrs; |
| 821 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 822 | s = (u32 *) p->o_arg.u.verifier.data; |
| 823 | s[0] = jiffies; |
| 824 | s[1] = current->pid; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 825 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 826 | p->c_arg.fh = &p->o_res.fh; |
| 827 | p->c_arg.stateid = &p->o_res.stateid; |
| 828 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 829 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 830 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 831 | return p; |
| 832 | err_free: |
| 833 | kfree(p); |
| 834 | err: |
| 835 | dput(parent); |
| 836 | return NULL; |
| 837 | } |
| 838 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 839 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 840 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 841 | struct nfs4_opendata *p = container_of(kref, |
| 842 | struct nfs4_opendata, kref); |
| 843 | |
| 844 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 845 | if (p->state != NULL) |
| 846 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 847 | nfs4_put_state_owner(p->owner); |
| 848 | dput(p->dir); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 849 | path_put(&p->path); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 850 | kfree(p); |
| 851 | } |
| 852 | |
| 853 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 854 | { |
| 855 | if (p != NULL) |
| 856 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 857 | } |
| 858 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 859 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 860 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 861 | int ret; |
| 862 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 863 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 864 | return ret; |
| 865 | } |
| 866 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 867 | 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] | 868 | { |
| 869 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 870 | |
| 871 | if (open_mode & O_EXCL) |
| 872 | goto out; |
| 873 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 874 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 875 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 876 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 877 | break; |
| 878 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 879 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 880 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 881 | break; |
| 882 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 883 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 884 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 885 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 886 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 887 | return ret; |
| 888 | } |
| 889 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 890 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 891 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 892 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 893 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 894 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 895 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 896 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 897 | return 1; |
| 898 | } |
| 899 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 900 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 901 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 902 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 903 | case FMODE_WRITE: |
| 904 | state->n_wronly++; |
| 905 | break; |
| 906 | case FMODE_READ: |
| 907 | state->n_rdonly++; |
| 908 | break; |
| 909 | case FMODE_READ|FMODE_WRITE: |
| 910 | state->n_rdwr++; |
| 911 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 912 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 913 | } |
| 914 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 915 | 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] | 916 | { |
| 917 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 918 | memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); |
| 919 | memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 920 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 921 | case FMODE_READ: |
| 922 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 923 | break; |
| 924 | case FMODE_WRITE: |
| 925 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 926 | break; |
| 927 | case FMODE_READ|FMODE_WRITE: |
| 928 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 929 | } |
| 930 | } |
| 931 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 932 | 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] | 933 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 934 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 935 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 936 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 937 | } |
| 938 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 939 | 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] | 940 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 941 | /* |
| 942 | * Protect the call to nfs4_state_set_mode_locked and |
| 943 | * serialise the stateid update |
| 944 | */ |
| 945 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 946 | if (deleg_stateid != NULL) { |
| 947 | memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); |
| 948 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 949 | } |
| 950 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 951 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 952 | write_sequnlock(&state->seqlock); |
| 953 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 954 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 955 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | } |
| 957 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 958 | 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] | 959 | { |
| 960 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 961 | struct nfs_delegation *deleg_cur; |
| 962 | int ret = 0; |
| 963 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 964 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 965 | |
| 966 | rcu_read_lock(); |
| 967 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 968 | if (deleg_cur == NULL) |
| 969 | goto no_delegation; |
| 970 | |
| 971 | spin_lock(&deleg_cur->lock); |
| 972 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 973 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 974 | goto no_delegation_unlock; |
| 975 | |
| 976 | if (delegation == NULL) |
| 977 | delegation = &deleg_cur->stateid; |
| 978 | else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) |
| 979 | goto no_delegation_unlock; |
| 980 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 981 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 982 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 983 | ret = 1; |
| 984 | no_delegation_unlock: |
| 985 | spin_unlock(&deleg_cur->lock); |
| 986 | no_delegation: |
| 987 | rcu_read_unlock(); |
| 988 | |
| 989 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 990 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 991 | ret = 1; |
| 992 | } |
| 993 | |
| 994 | return ret; |
| 995 | } |
| 996 | |
| 997 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 998 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 999 | { |
| 1000 | struct nfs_delegation *delegation; |
| 1001 | |
| 1002 | rcu_read_lock(); |
| 1003 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1004 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1005 | rcu_read_unlock(); |
| 1006 | return; |
| 1007 | } |
| 1008 | rcu_read_unlock(); |
| 1009 | nfs_inode_return_delegation(inode); |
| 1010 | } |
| 1011 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1012 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1013 | { |
| 1014 | struct nfs4_state *state = opendata->state; |
| 1015 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1016 | struct nfs_delegation *delegation; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1017 | int open_mode = opendata->o_arg.open_flags & O_EXCL; |
| 1018 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1019 | nfs4_stateid stateid; |
| 1020 | int ret = -EAGAIN; |
| 1021 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1022 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1023 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1024 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1025 | if (can_open_cached(state, fmode, open_mode)) { |
| 1026 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1027 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1028 | goto out_return_state; |
| 1029 | } |
| 1030 | spin_unlock(&state->owner->so_lock); |
| 1031 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1032 | rcu_read_lock(); |
| 1033 | delegation = rcu_dereference(nfsi->delegation); |
| 1034 | if (delegation == NULL || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1035 | !can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1036 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1037 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1038 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1039 | /* Save the delegation */ |
| 1040 | memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); |
| 1041 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1042 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1043 | if (ret != 0) |
| 1044 | goto out; |
| 1045 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1046 | |
| 1047 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1048 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1049 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1050 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1051 | out: |
| 1052 | return ERR_PTR(ret); |
| 1053 | out_return_state: |
| 1054 | atomic_inc(&state->count); |
| 1055 | return state; |
| 1056 | } |
| 1057 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1058 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1059 | { |
| 1060 | struct inode *inode; |
| 1061 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1062 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1063 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1064 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1065 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1066 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1067 | goto out; |
| 1068 | } |
| 1069 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1070 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1071 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1072 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1073 | 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] | 1074 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1075 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1076 | goto err; |
| 1077 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1078 | state = nfs4_get_open_state(inode, data->owner); |
| 1079 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1080 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1081 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1082 | int delegation_flags = 0; |
| 1083 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1084 | rcu_read_lock(); |
| 1085 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1086 | if (delegation) |
| 1087 | delegation_flags = delegation->flags; |
| 1088 | rcu_read_unlock(); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1089 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1090 | nfs_inode_set_delegation(state->inode, |
| 1091 | data->owner->so_cred, |
| 1092 | &data->o_res); |
| 1093 | else |
| 1094 | nfs_inode_reclaim_delegation(state->inode, |
| 1095 | data->owner->so_cred, |
| 1096 | &data->o_res); |
| 1097 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1098 | |
| 1099 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1100 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1101 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1102 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1103 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1104 | err_put_inode: |
| 1105 | iput(inode); |
| 1106 | err: |
| 1107 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1108 | } |
| 1109 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1110 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1111 | { |
| 1112 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1113 | struct nfs_open_context *ctx; |
| 1114 | |
| 1115 | spin_lock(&state->inode->i_lock); |
| 1116 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1117 | if (ctx->state != state) |
| 1118 | continue; |
| 1119 | get_nfs_open_context(ctx); |
| 1120 | spin_unlock(&state->inode->i_lock); |
| 1121 | return ctx; |
| 1122 | } |
| 1123 | spin_unlock(&state->inode->i_lock); |
| 1124 | return ERR_PTR(-ENOENT); |
| 1125 | } |
| 1126 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1127 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1128 | { |
| 1129 | struct nfs4_opendata *opendata; |
| 1130 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1131 | 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] | 1132 | if (opendata == NULL) |
| 1133 | return ERR_PTR(-ENOMEM); |
| 1134 | opendata->state = state; |
| 1135 | atomic_inc(&state->count); |
| 1136 | return opendata; |
| 1137 | } |
| 1138 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1139 | 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] | 1140 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1141 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1142 | int ret; |
| 1143 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1144 | opendata->o_arg.open_flags = 0; |
| 1145 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1146 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1147 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1148 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1149 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1150 | if (ret != 0) |
| 1151 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1152 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1153 | if (IS_ERR(newstate)) |
| 1154 | return PTR_ERR(newstate); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1155 | nfs4_close_state(&opendata->path, newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1156 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1157 | return 0; |
| 1158 | } |
| 1159 | |
| 1160 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1161 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1162 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1163 | int ret; |
| 1164 | |
| 1165 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1166 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1167 | smp_rmb(); |
| 1168 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1169 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1170 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1171 | if (ret != 0) |
| 1172 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1173 | if (newstate != state) |
| 1174 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1175 | } |
| 1176 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1177 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1178 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1179 | if (ret != 0) |
| 1180 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1181 | if (newstate != state) |
| 1182 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1183 | } |
| 1184 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1185 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1186 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1187 | if (ret != 0) |
| 1188 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1189 | if (newstate != state) |
| 1190 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1191 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1192 | /* |
| 1193 | * We may have performed cached opens for all three recoveries. |
| 1194 | * Check if we need to update the current stateid. |
| 1195 | */ |
| 1196 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
| 1197 | 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] | 1198 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1199 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1200 | memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1201 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1202 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1203 | return 0; |
| 1204 | } |
| 1205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | /* |
| 1207 | * OPEN_RECLAIM: |
| 1208 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1210 | 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] | 1211 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1212 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1213 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1214 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | int status; |
| 1216 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1217 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1218 | if (IS_ERR(opendata)) |
| 1219 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1220 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1221 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1222 | rcu_read_lock(); |
| 1223 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1224 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1225 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1226 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1227 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1228 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1229 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | return status; |
| 1231 | } |
| 1232 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1233 | 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] | 1234 | { |
| 1235 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1236 | struct nfs4_exception exception = { }; |
| 1237 | int err; |
| 1238 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1239 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1240 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1241 | break; |
| 1242 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | } while (exception.retry); |
| 1244 | return err; |
| 1245 | } |
| 1246 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1247 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1248 | { |
| 1249 | struct nfs_open_context *ctx; |
| 1250 | int ret; |
| 1251 | |
| 1252 | ctx = nfs4_state_find_open_context(state); |
| 1253 | if (IS_ERR(ctx)) |
| 1254 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1255 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1256 | put_nfs_open_context(ctx); |
| 1257 | return ret; |
| 1258 | } |
| 1259 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1260 | 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] | 1261 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1262 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1263 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1265 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1266 | if (IS_ERR(opendata)) |
| 1267 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1268 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1269 | memcpy(opendata->o_arg.u.delegation.data, stateid->data, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1270 | sizeof(opendata->o_arg.u.delegation.data)); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1271 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1272 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1273 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | } |
| 1275 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1276 | 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] | 1277 | { |
| 1278 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1279 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | int err; |
| 1281 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1282 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | switch (err) { |
| 1284 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1285 | case -ENOENT: |
| 1286 | case -ESTALE: |
| 1287 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1288 | case -NFS4ERR_BADSESSION: |
| 1289 | case -NFS4ERR_BADSLOT: |
| 1290 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1291 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1292 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1293 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1294 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | case -NFS4ERR_STALE_CLIENTID: |
| 1296 | case -NFS4ERR_STALE_STATEID: |
| 1297 | case -NFS4ERR_EXPIRED: |
| 1298 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1299 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1300 | goto out; |
| 1301 | case -ERESTARTSYS: |
| 1302 | /* |
| 1303 | * The show must go on: exit, but mark the |
| 1304 | * stateid as needing recovery. |
| 1305 | */ |
| 1306 | case -NFS4ERR_ADMIN_REVOKED: |
| 1307 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1308 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1309 | case -EKEYEXPIRED: |
| 1310 | /* |
| 1311 | * User RPCSEC_GSS context has expired. |
| 1312 | * We cannot recover this stateid now, so |
| 1313 | * skip it and allow recovery thread to |
| 1314 | * proceed. |
| 1315 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1316 | case -ENOMEM: |
| 1317 | err = 0; |
| 1318 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | } |
| 1320 | err = nfs4_handle_exception(server, err, &exception); |
| 1321 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1322 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | return err; |
| 1324 | } |
| 1325 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1326 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1327 | { |
| 1328 | struct nfs4_opendata *data = calldata; |
| 1329 | |
| 1330 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1331 | if (data->rpc_status == 0) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1332 | memcpy(data->o_res.stateid.data, data->c_res.stateid.data, |
| 1333 | sizeof(data->o_res.stateid.data)); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1334 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1335 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1336 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1337 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | static void nfs4_open_confirm_release(void *calldata) |
| 1341 | { |
| 1342 | struct nfs4_opendata *data = calldata; |
| 1343 | struct nfs4_state *state = NULL; |
| 1344 | |
| 1345 | /* If this request hasn't been cancelled, do nothing */ |
| 1346 | if (data->cancelled == 0) |
| 1347 | goto out_free; |
| 1348 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1349 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1350 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1351 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1352 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1353 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1354 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1355 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1359 | .rpc_call_done = nfs4_open_confirm_done, |
| 1360 | .rpc_release = nfs4_open_confirm_release, |
| 1361 | }; |
| 1362 | |
| 1363 | /* |
| 1364 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1365 | */ |
| 1366 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1367 | { |
| 1368 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1369 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1370 | struct rpc_message msg = { |
| 1371 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1372 | .rpc_argp = &data->c_arg, |
| 1373 | .rpc_resp = &data->c_res, |
| 1374 | .rpc_cred = data->owner->so_cred, |
| 1375 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1376 | struct rpc_task_setup task_setup_data = { |
| 1377 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1378 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1379 | .callback_ops = &nfs4_open_confirm_ops, |
| 1380 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1381 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1382 | .flags = RPC_TASK_ASYNC, |
| 1383 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | int status; |
| 1385 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1386 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1387 | data->rpc_done = 0; |
| 1388 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1389 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1390 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1391 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1392 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1393 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1394 | if (status != 0) { |
| 1395 | data->cancelled = 1; |
| 1396 | smp_wmb(); |
| 1397 | } else |
| 1398 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1399 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | return status; |
| 1401 | } |
| 1402 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1403 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1405 | struct nfs4_opendata *data = calldata; |
| 1406 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1407 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1408 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1409 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1410 | /* |
| 1411 | * Check if we still need to send an OPEN call, or if we can use |
| 1412 | * a delegation instead. |
| 1413 | */ |
| 1414 | if (data->state != NULL) { |
| 1415 | struct nfs_delegation *delegation; |
| 1416 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1417 | 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] | 1418 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1419 | rcu_read_lock(); |
| 1420 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
| 1421 | if (delegation != NULL && |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1422 | test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1423 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1424 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1425 | } |
| 1426 | rcu_read_unlock(); |
| 1427 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1428 | /* Update sequence id. */ |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1429 | data->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1430 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1431 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1432 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1433 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1434 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1435 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1436 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1437 | &data->o_arg.seq_args, |
| 1438 | &data->o_res.seq_res, 1, task)) |
| 1439 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1440 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1441 | return; |
| 1442 | out_no_action: |
| 1443 | task->tk_action = NULL; |
| 1444 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1445 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1447 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1448 | { |
| 1449 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1450 | nfs4_open_prepare(task, calldata); |
| 1451 | } |
| 1452 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1453 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1454 | { |
| 1455 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1457 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1458 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1459 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1460 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1461 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1462 | if (task->tk_status == 0) { |
| 1463 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1464 | case S_IFREG: |
| 1465 | break; |
| 1466 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1467 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1468 | break; |
| 1469 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1470 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1471 | break; |
| 1472 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1473 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1474 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1475 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1476 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1477 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1478 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1479 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1480 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1481 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1482 | static void nfs4_open_release(void *calldata) |
| 1483 | { |
| 1484 | struct nfs4_opendata *data = calldata; |
| 1485 | struct nfs4_state *state = NULL; |
| 1486 | |
| 1487 | /* If this request hasn't been cancelled, do nothing */ |
| 1488 | if (data->cancelled == 0) |
| 1489 | goto out_free; |
| 1490 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1491 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1492 | goto out_free; |
| 1493 | /* In case we need an open_confirm, no cleanup! */ |
| 1494 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1495 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1496 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1497 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1498 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1499 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1500 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1504 | .rpc_call_prepare = nfs4_open_prepare, |
| 1505 | .rpc_call_done = nfs4_open_done, |
| 1506 | .rpc_release = nfs4_open_release, |
| 1507 | }; |
| 1508 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1509 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1510 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1511 | .rpc_call_done = nfs4_open_done, |
| 1512 | .rpc_release = nfs4_open_release, |
| 1513 | }; |
| 1514 | |
| 1515 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1516 | { |
| 1517 | struct inode *dir = data->dir->d_inode; |
| 1518 | struct nfs_server *server = NFS_SERVER(dir); |
| 1519 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1520 | struct nfs_openres *o_res = &data->o_res; |
| 1521 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1522 | struct rpc_message msg = { |
| 1523 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1524 | .rpc_argp = o_arg, |
| 1525 | .rpc_resp = o_res, |
| 1526 | .rpc_cred = data->owner->so_cred, |
| 1527 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1528 | struct rpc_task_setup task_setup_data = { |
| 1529 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1530 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1531 | .callback_ops = &nfs4_open_ops, |
| 1532 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1533 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1534 | .flags = RPC_TASK_ASYNC, |
| 1535 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1536 | int status; |
| 1537 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1538 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1539 | data->rpc_done = 0; |
| 1540 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1541 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1542 | if (isrecover) |
| 1543 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1544 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1545 | if (IS_ERR(task)) |
| 1546 | return PTR_ERR(task); |
| 1547 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1548 | if (status != 0) { |
| 1549 | data->cancelled = 1; |
| 1550 | smp_wmb(); |
| 1551 | } else |
| 1552 | status = data->rpc_status; |
| 1553 | rpc_put_task(task); |
| 1554 | |
| 1555 | return status; |
| 1556 | } |
| 1557 | |
| 1558 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1559 | { |
| 1560 | struct inode *dir = data->dir->d_inode; |
| 1561 | struct nfs_openres *o_res = &data->o_res; |
| 1562 | int status; |
| 1563 | |
| 1564 | status = nfs4_run_open_task(data, 1); |
| 1565 | if (status != 0 || !data->rpc_done) |
| 1566 | return status; |
| 1567 | |
| 1568 | nfs_refresh_inode(dir, o_res->dir_attr); |
| 1569 | |
| 1570 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1571 | status = _nfs4_proc_open_confirm(data); |
| 1572 | if (status != 0) |
| 1573 | return status; |
| 1574 | } |
| 1575 | |
| 1576 | return status; |
| 1577 | } |
| 1578 | |
| 1579 | /* |
| 1580 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1581 | */ |
| 1582 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1583 | { |
| 1584 | struct inode *dir = data->dir->d_inode; |
| 1585 | struct nfs_server *server = NFS_SERVER(dir); |
| 1586 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1587 | struct nfs_openres *o_res = &data->o_res; |
| 1588 | int status; |
| 1589 | |
| 1590 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1591 | if (status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1592 | return status; |
| 1593 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1594 | if (o_arg->open_flags & O_CREAT) { |
| 1595 | update_changeattr(dir, &o_res->cinfo); |
| 1596 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
| 1597 | } else |
| 1598 | nfs_refresh_inode(dir, o_res->dir_attr); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1599 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1600 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1602 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1604 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | } |
| 1606 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1607 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1608 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | } |
| 1610 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1611 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1612 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1613 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1614 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1615 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1616 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1617 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1618 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1619 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1620 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1621 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1622 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1623 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1624 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1625 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1626 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1627 | } |
| 1628 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1629 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1630 | { |
| 1631 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1632 | } |
| 1633 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | /* |
| 1635 | * OPEN_EXPIRED: |
| 1636 | * reclaim state on the server after a network partition. |
| 1637 | * Assumes caller holds the appropriate lock |
| 1638 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1639 | 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] | 1640 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1641 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1642 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1644 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1645 | if (IS_ERR(opendata)) |
| 1646 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1647 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1648 | if (ret == -ESTALE) |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1649 | d_drop(ctx->path.dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1650 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1651 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | } |
| 1653 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1654 | 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] | 1655 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1656 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1657 | struct nfs4_exception exception = { }; |
| 1658 | int err; |
| 1659 | |
| 1660 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1661 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1662 | switch (err) { |
| 1663 | default: |
| 1664 | goto out; |
| 1665 | case -NFS4ERR_GRACE: |
| 1666 | case -NFS4ERR_DELAY: |
| 1667 | nfs4_handle_exception(server, err, &exception); |
| 1668 | err = 0; |
| 1669 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1670 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1671 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1672 | return err; |
| 1673 | } |
| 1674 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1676 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1678 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1680 | ctx = nfs4_state_find_open_context(state); |
| 1681 | if (IS_ERR(ctx)) |
| 1682 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1683 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1684 | put_nfs_open_context(ctx); |
| 1685 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | } |
| 1687 | |
| 1688 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1689 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1690 | * fields corresponding to attributes that were used to store the verifier. |
| 1691 | * Make sure we clobber those fields in the later setattr call |
| 1692 | */ |
| 1693 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1694 | { |
| 1695 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1696 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1697 | sattr->ia_valid |= ATTR_ATIME; |
| 1698 | |
| 1699 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1700 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1701 | sattr->ia_valid |= ATTR_MTIME; |
| 1702 | } |
| 1703 | |
| 1704 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1705 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1707 | 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] | 1708 | { |
| 1709 | struct nfs4_state_owner *sp; |
| 1710 | struct nfs4_state *state = NULL; |
| 1711 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1712 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1713 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | |
| 1715 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | status = -ENOMEM; |
| 1717 | if (!(sp = nfs4_get_state_owner(server, cred))) { |
| 1718 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1719 | goto out_err; |
| 1720 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1721 | status = nfs4_recover_expired_lease(server); |
| 1722 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1723 | goto err_put_state_owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1724 | if (path->dentry->d_inode != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1725 | nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1726 | status = -ENOMEM; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1727 | opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1728 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1729 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1731 | if (path->dentry->d_inode != NULL) |
| 1732 | opendata->state = nfs4_get_open_state(path->dentry->d_inode, sp); |
| 1733 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1734 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1736 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1738 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1739 | status = PTR_ERR(state); |
| 1740 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1741 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1742 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1743 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1744 | |
| 1745 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1746 | nfs4_exclusive_attrset(opendata, sattr); |
| 1747 | |
| 1748 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1749 | status = nfs4_do_setattr(state->inode, cred, |
| 1750 | opendata->o_res.f_attr, sattr, |
| 1751 | state); |
| 1752 | if (status == 0) |
| 1753 | nfs_setattr_update_inode(state->inode, sattr); |
| 1754 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1755 | } |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1756 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | *res = state; |
| 1759 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1760 | err_opendata_put: |
| 1761 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1762 | err_put_state_owner: |
| 1763 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1764 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | *res = NULL; |
| 1766 | return status; |
| 1767 | } |
| 1768 | |
| 1769 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1770 | 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] | 1771 | { |
| 1772 | struct nfs4_exception exception = { }; |
| 1773 | struct nfs4_state *res; |
| 1774 | int status; |
| 1775 | |
| 1776 | do { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1777 | status = _nfs4_do_open(dir, path, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | if (status == 0) |
| 1779 | break; |
| 1780 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1781 | * book-keeping w.r.t. state-changing operations |
| 1782 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1783 | * It is actually a sign of a bug on the client or on the server. |
| 1784 | * |
| 1785 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1786 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | * have unhashed the old state_owner for us, and that we can |
| 1788 | * therefore safely retry using a new one. We should still warn |
| 1789 | * the user though... |
| 1790 | */ |
| 1791 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1792 | printk(KERN_WARNING "NFS: v4 server %s " |
| 1793 | " returned a bad sequence-id error!\n", |
| 1794 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | exception.retry = 1; |
| 1796 | continue; |
| 1797 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1798 | /* |
| 1799 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1800 | * state before it received the OPEN_CONFIRM. |
| 1801 | * Recover by retrying the request as per the discussion |
| 1802 | * on Page 181 of RFC3530. |
| 1803 | */ |
| 1804 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1805 | exception.retry = 1; |
| 1806 | continue; |
| 1807 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1808 | if (status == -EAGAIN) { |
| 1809 | /* We must have found a delegation */ |
| 1810 | exception.retry = 1; |
| 1811 | continue; |
| 1812 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1814 | status, &exception)); |
| 1815 | } while (exception.retry); |
| 1816 | return res; |
| 1817 | } |
| 1818 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1819 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1820 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1821 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1823 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1825 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | .iap = sattr, |
| 1827 | .server = server, |
| 1828 | .bitmask = server->attr_bitmask, |
| 1829 | }; |
| 1830 | struct nfs_setattrres res = { |
| 1831 | .fattr = fattr, |
| 1832 | .server = server, |
| 1833 | }; |
| 1834 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1835 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1836 | .rpc_argp = &arg, |
| 1837 | .rpc_resp = &res, |
| 1838 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1840 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1841 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1843 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1845 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { |
| 1846 | /* Use that stateid */ |
| 1847 | } else if (state != NULL) { |
Trond Myklebust | 77041ed | 2010-07-01 12:49:11 -0400 | [diff] [blame] | 1848 | nfs4_copy_stateid(&arg.stateid, state, current->files, current->tgid); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1849 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); |
| 1851 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1852 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1853 | if (status == 0 && state != NULL) |
| 1854 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1855 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | } |
| 1857 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1858 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1859 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1860 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1862 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | struct nfs4_exception exception = { }; |
| 1864 | int err; |
| 1865 | do { |
| 1866 | err = nfs4_handle_exception(server, |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1867 | _nfs4_do_setattr(inode, cred, fattr, sattr, state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | &exception); |
| 1869 | } while (exception.retry); |
| 1870 | return err; |
| 1871 | } |
| 1872 | |
| 1873 | struct nfs4_closedata { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1874 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | struct inode *inode; |
| 1876 | struct nfs4_state *state; |
| 1877 | struct nfs_closeargs arg; |
| 1878 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1879 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1880 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1881 | bool roc; |
| 1882 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | }; |
| 1884 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1885 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1886 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1887 | struct nfs4_closedata *calldata = data; |
| 1888 | struct nfs4_state_owner *sp = calldata->state->owner; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1889 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1890 | if (calldata->roc) |
| 1891 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1892 | nfs4_put_open_state(calldata->state); |
| 1893 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1894 | nfs4_put_state_owner(sp); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 1895 | path_put(&calldata->path); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1896 | kfree(calldata); |
| 1897 | } |
| 1898 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1899 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 1900 | fmode_t fmode) |
| 1901 | { |
| 1902 | spin_lock(&state->owner->so_lock); |
| 1903 | if (!(fmode & FMODE_READ)) |
| 1904 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1905 | if (!(fmode & FMODE_WRITE)) |
| 1906 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1907 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1908 | spin_unlock(&state->owner->so_lock); |
| 1909 | } |
| 1910 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1911 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1913 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 1916 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1917 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 1918 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | /* hmm. we are done with the inode, and in the process of freeing |
| 1920 | * the state_owner. we keep this around to process errors |
| 1921 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | switch (task->tk_status) { |
| 1923 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1924 | if (calldata->roc) |
| 1925 | pnfs_roc_set_barrier(state->inode, |
| 1926 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1927 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1928 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1929 | nfs4_close_clear_stateid_flags(state, |
| 1930 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | break; |
| 1932 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1933 | case -NFS4ERR_OLD_STATEID: |
| 1934 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1936 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1937 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1939 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 1940 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1942 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1943 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | } |
| 1945 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1946 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1948 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1949 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1950 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1951 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1952 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1953 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1954 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1955 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 1956 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1957 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1958 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1959 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1960 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1961 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1962 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1963 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1964 | } |
| 1965 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1966 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1967 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1968 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1969 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1970 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1971 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1972 | |
| 1973 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1974 | /* Note: exit _without_ calling nfs4_close_done */ |
| 1975 | task->tk_action = NULL; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1976 | return; |
| 1977 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1978 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1979 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1980 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1981 | if (calldata->roc && |
| 1982 | pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { |
| 1983 | rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, |
| 1984 | task, NULL); |
| 1985 | return; |
| 1986 | } |
| 1987 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1988 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1989 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1990 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1991 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 1992 | &calldata->arg.seq_args, &calldata->res.seq_res, |
| 1993 | 1, task)) |
| 1994 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1995 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | } |
| 1997 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1998 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1999 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2000 | .rpc_call_done = nfs4_close_done, |
| 2001 | .rpc_release = nfs4_free_closedata, |
| 2002 | }; |
| 2003 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | /* |
| 2005 | * It is possible for data to be read/written from a mem-mapped file |
| 2006 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2007 | * This means that we can't safely call nfsv4 close on a file until |
| 2008 | * the inode is cleared. This in turn means that we are not good |
| 2009 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2010 | * share state even when we are done with one of the three share |
| 2011 | * stateid's in the inode. |
| 2012 | * |
| 2013 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2014 | */ |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2015 | 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] | 2016 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2017 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2019 | struct nfs4_state_owner *sp = state->owner; |
| 2020 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2021 | struct rpc_message msg = { |
| 2022 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2023 | .rpc_cred = state->owner->so_cred, |
| 2024 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2025 | struct rpc_task_setup task_setup_data = { |
| 2026 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2027 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2028 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2029 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2030 | .flags = RPC_TASK_ASYNC, |
| 2031 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2032 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2034 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2036 | goto out; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2037 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2039 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2040 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2042 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2043 | if (calldata->arg.seqid == NULL) |
| 2044 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2045 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2046 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2047 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2048 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2049 | calldata->res.server = server; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2050 | calldata->roc = roc; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 2051 | path_get(path); |
| 2052 | calldata->path = *path; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2053 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2054 | msg.rpc_argp = &calldata->arg; |
| 2055 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2056 | task_setup_data.callback_data = calldata; |
| 2057 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2058 | if (IS_ERR(task)) |
| 2059 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2060 | status = 0; |
| 2061 | if (wait) |
| 2062 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2063 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2064 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2065 | out_free_calldata: |
| 2066 | kfree(calldata); |
| 2067 | out: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2068 | if (roc) |
| 2069 | pnfs_roc_release(state->inode); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2070 | nfs4_put_open_state(state); |
| 2071 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2072 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | } |
| 2074 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2075 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2076 | 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] | 2077 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | struct nfs4_state *state; |
| 2079 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2080 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2081 | 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] | 2082 | if (IS_ERR(state)) |
| 2083 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2084 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2085 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | } |
| 2087 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2088 | 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] | 2089 | { |
| 2090 | if (ctx->state == NULL) |
| 2091 | return; |
| 2092 | if (is_sync) |
| 2093 | nfs4_close_sync(&ctx->path, ctx->state, ctx->mode); |
| 2094 | else |
| 2095 | nfs4_close_state(&ctx->path, ctx->state, ctx->mode); |
| 2096 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | |
| 2098 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2099 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2100 | struct nfs4_server_caps_arg args = { |
| 2101 | .fhandle = fhandle, |
| 2102 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | struct nfs4_server_caps_res res = {}; |
| 2104 | struct rpc_message msg = { |
| 2105 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2106 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | .rpc_resp = &res, |
| 2108 | }; |
| 2109 | int status; |
| 2110 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2111 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | if (status == 0) { |
| 2113 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2114 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2115 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2116 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2117 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2118 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2119 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2120 | server->caps |= NFS_CAP_ACLS; |
| 2121 | if (res.has_links != 0) |
| 2122 | server->caps |= NFS_CAP_HARDLINKS; |
| 2123 | if (res.has_symlinks != 0) |
| 2124 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2125 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2126 | server->caps |= NFS_CAP_FILEID; |
| 2127 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2128 | server->caps |= NFS_CAP_MODE; |
| 2129 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2130 | server->caps |= NFS_CAP_NLINK; |
| 2131 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2132 | server->caps |= NFS_CAP_OWNER; |
| 2133 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2134 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2135 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2136 | server->caps |= NFS_CAP_ATIME; |
| 2137 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2138 | server->caps |= NFS_CAP_CTIME; |
| 2139 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2140 | server->caps |= NFS_CAP_MTIME; |
| 2141 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2142 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2143 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2144 | 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] | 2145 | server->acl_bitmask = res.acl_bitmask; |
| 2146 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | return status; |
| 2149 | } |
| 2150 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2151 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2152 | { |
| 2153 | struct nfs4_exception exception = { }; |
| 2154 | int err; |
| 2155 | do { |
| 2156 | err = nfs4_handle_exception(server, |
| 2157 | _nfs4_server_capabilities(server, fhandle), |
| 2158 | &exception); |
| 2159 | } while (exception.retry); |
| 2160 | return err; |
| 2161 | } |
| 2162 | |
| 2163 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2164 | struct nfs_fsinfo *info) |
| 2165 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | struct nfs4_lookup_root_arg args = { |
| 2167 | .bitmask = nfs4_fattr_bitmap, |
| 2168 | }; |
| 2169 | struct nfs4_lookup_res res = { |
| 2170 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2171 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | .fh = fhandle, |
| 2173 | }; |
| 2174 | struct rpc_message msg = { |
| 2175 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2176 | .rpc_argp = &args, |
| 2177 | .rpc_resp = &res, |
| 2178 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2179 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2180 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2181 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | } |
| 2183 | |
| 2184 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2185 | struct nfs_fsinfo *info) |
| 2186 | { |
| 2187 | struct nfs4_exception exception = { }; |
| 2188 | int err; |
| 2189 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2190 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2191 | switch (err) { |
| 2192 | case 0: |
| 2193 | case -NFS4ERR_WRONGSEC: |
| 2194 | break; |
| 2195 | default: |
| 2196 | err = nfs4_handle_exception(server, err, &exception); |
| 2197 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | } while (exception.retry); |
| 2199 | return err; |
| 2200 | } |
| 2201 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2202 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2203 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2204 | { |
| 2205 | struct rpc_auth *auth; |
| 2206 | int ret; |
| 2207 | |
| 2208 | auth = rpcauth_create(flavor, server->client); |
| 2209 | if (!auth) { |
| 2210 | ret = -EIO; |
| 2211 | goto out; |
| 2212 | } |
| 2213 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2214 | out: |
| 2215 | return ret; |
| 2216 | } |
| 2217 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2218 | static int nfs4_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2219 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2221 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2222 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2224 | len = gss_mech_list_pseudoflavors(&flav_array[0]); |
| 2225 | flav_array[len] = RPC_AUTH_NULL; |
| 2226 | len += 1; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2227 | |
| 2228 | for (i = 0; i < len; i++) { |
| 2229 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2230 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2231 | continue; |
| 2232 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2233 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2234 | /* |
| 2235 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2236 | * to access the mount. It could also mean that we tried to mount |
| 2237 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2238 | * existing mount programs don't handle -EACCES very well so it should |
| 2239 | * be mapped to -EPERM instead. |
| 2240 | */ |
| 2241 | if (status == -EACCES) |
| 2242 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2243 | return status; |
| 2244 | } |
| 2245 | |
| 2246 | /* |
| 2247 | * get the file handle for the "/" directory on the server |
| 2248 | */ |
| 2249 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2250 | struct nfs_fsinfo *info) |
| 2251 | { |
| 2252 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2253 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2254 | /* |
| 2255 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2256 | * by nfs4_map_errors() as this function exits. |
| 2257 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2258 | status = nfs4_find_root_sec(server, fhandle, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | if (status == 0) |
| 2260 | status = nfs4_server_capabilities(server, fhandle); |
| 2261 | if (status == 0) |
| 2262 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2263 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2264 | } |
| 2265 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2266 | /* |
| 2267 | * Get locations and (maybe) other attributes of a referral. |
| 2268 | * Note that we'll actually follow the referral later when |
| 2269 | * we detect fsid mismatch in inode revalidation |
| 2270 | */ |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2271 | 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] | 2272 | { |
| 2273 | int status = -ENOMEM; |
| 2274 | struct page *page = NULL; |
| 2275 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2276 | |
| 2277 | page = alloc_page(GFP_KERNEL); |
| 2278 | if (page == NULL) |
| 2279 | goto out; |
| 2280 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2281 | if (locations == NULL) |
| 2282 | goto out; |
| 2283 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 2284 | status = nfs4_proc_fs_locations(dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2285 | if (status != 0) |
| 2286 | goto out; |
| 2287 | /* Make sure server returned a different fsid for the referral */ |
| 2288 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2289 | 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] | 2290 | status = -EIO; |
| 2291 | goto out; |
| 2292 | } |
| 2293 | |
| 2294 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
| 2295 | fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL; |
| 2296 | if (!fattr->mode) |
| 2297 | fattr->mode = S_IFDIR; |
| 2298 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2299 | out: |
| 2300 | if (page) |
| 2301 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2302 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2303 | return status; |
| 2304 | } |
| 2305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2307 | { |
| 2308 | struct nfs4_getattr_arg args = { |
| 2309 | .fh = fhandle, |
| 2310 | .bitmask = server->attr_bitmask, |
| 2311 | }; |
| 2312 | struct nfs4_getattr_res res = { |
| 2313 | .fattr = fattr, |
| 2314 | .server = server, |
| 2315 | }; |
| 2316 | struct rpc_message msg = { |
| 2317 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2318 | .rpc_argp = &args, |
| 2319 | .rpc_resp = &res, |
| 2320 | }; |
| 2321 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2322 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2323 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | } |
| 2325 | |
| 2326 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2327 | { |
| 2328 | struct nfs4_exception exception = { }; |
| 2329 | int err; |
| 2330 | do { |
| 2331 | err = nfs4_handle_exception(server, |
| 2332 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2333 | &exception); |
| 2334 | } while (exception.retry); |
| 2335 | return err; |
| 2336 | } |
| 2337 | |
| 2338 | /* |
| 2339 | * The file is not closed if it is opened due to the a request to change |
| 2340 | * the size of the file. The open call will not be needed once the |
| 2341 | * VFS layer lookup-intents are implemented. |
| 2342 | * |
| 2343 | * Close is called when the inode is destroyed. |
| 2344 | * If we haven't opened the file for O_WRONLY, we |
| 2345 | * need to in the size_change case to obtain a stateid. |
| 2346 | * |
| 2347 | * Got race? |
| 2348 | * Because OPEN is always done by name in nfsv4, it is |
| 2349 | * possible that we opened a different file by the same |
| 2350 | * name. We can recognize this race condition, but we |
| 2351 | * can't do anything about it besides returning an error. |
| 2352 | * |
| 2353 | * This will be fixed with VFS changes (lookup-intent). |
| 2354 | */ |
| 2355 | static int |
| 2356 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2357 | struct iattr *sattr) |
| 2358 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2359 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2360 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2361 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2362 | int status; |
| 2363 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame^] | 2364 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2365 | pnfs_return_layout(inode); |
| 2366 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2367 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2369 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2370 | if (sattr->ia_valid & ATTR_FILE) { |
| 2371 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2372 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2373 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2374 | if (ctx) { |
| 2375 | cred = ctx->cred; |
| 2376 | state = ctx->state; |
| 2377 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2381 | if (status == 0) |
| 2382 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | return status; |
| 2384 | } |
| 2385 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2386 | static int _nfs4_proc_lookupfh(struct rpc_clnt *clnt, struct nfs_server *server, |
| 2387 | const struct nfs_fh *dirfh, const struct qstr *name, |
| 2388 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2389 | { |
| 2390 | int status; |
| 2391 | struct nfs4_lookup_arg args = { |
| 2392 | .bitmask = server->attr_bitmask, |
| 2393 | .dir_fh = dirfh, |
| 2394 | .name = name, |
| 2395 | }; |
| 2396 | struct nfs4_lookup_res res = { |
| 2397 | .server = server, |
| 2398 | .fattr = fattr, |
| 2399 | .fh = fhandle, |
| 2400 | }; |
| 2401 | struct rpc_message msg = { |
| 2402 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2403 | .rpc_argp = &args, |
| 2404 | .rpc_resp = &res, |
| 2405 | }; |
| 2406 | |
| 2407 | nfs_fattr_init(fattr); |
| 2408 | |
| 2409 | dprintk("NFS call lookupfh %s\n", name->name); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2410 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, &res.seq_res, 0); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2411 | dprintk("NFS reply lookupfh: %d\n", status); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2412 | return status; |
| 2413 | } |
| 2414 | |
| 2415 | static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh, |
| 2416 | struct qstr *name, struct nfs_fh *fhandle, |
| 2417 | struct nfs_fattr *fattr) |
| 2418 | { |
| 2419 | struct nfs4_exception exception = { }; |
| 2420 | int err; |
| 2421 | do { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2422 | err = _nfs4_proc_lookupfh(server->client, server, dirfh, name, fhandle, fattr); |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2423 | /* FIXME: !!!! */ |
| 2424 | if (err == -NFS4ERR_MOVED) { |
| 2425 | err = -EREMOTE; |
| 2426 | break; |
| 2427 | } |
| 2428 | err = nfs4_handle_exception(server, err, &exception); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2429 | } while (exception.retry); |
| 2430 | return err; |
| 2431 | } |
| 2432 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2433 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2434 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2435 | struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 | { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2437 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2438 | |
| 2439 | dprintk("NFS call lookup %s\n", name->name); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2440 | status = _nfs4_proc_lookupfh(clnt, NFS_SERVER(dir), NFS_FH(dir), name, fhandle, fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2441 | if (status == -NFS4ERR_MOVED) |
| 2442 | status = nfs4_get_referral(dir, name, fattr, fhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2443 | dprintk("NFS reply lookup: %d\n", status); |
| 2444 | return status; |
| 2445 | } |
| 2446 | |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2447 | void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr, struct nfs_fh *fh) |
| 2448 | { |
| 2449 | memset(fh, 0, sizeof(struct nfs_fh)); |
| 2450 | fattr->fsid.major = 1; |
| 2451 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 2452 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_FSID | NFS_ATTR_FATTR_MOUNTPOINT; |
| 2453 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2454 | fattr->nlink = 2; |
| 2455 | } |
| 2456 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2457 | static int nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, struct qstr *name, |
| 2458 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | { |
| 2460 | struct nfs4_exception exception = { }; |
| 2461 | int err; |
| 2462 | do { |
| 2463 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2464 | _nfs4_proc_lookup(clnt, dir, name, fhandle, fattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2465 | &exception); |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2466 | if (err == -EPERM) |
| 2467 | nfs_fixup_secinfo_attributes(fattr, fhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | } while (exception.retry); |
| 2469 | return err; |
| 2470 | } |
| 2471 | |
| 2472 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2473 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2474 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2475 | struct nfs4_accessargs args = { |
| 2476 | .fh = NFS_FH(inode), |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2477 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2479 | struct nfs4_accessres res = { |
| 2480 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2481 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2482 | struct rpc_message msg = { |
| 2483 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2484 | .rpc_argp = &args, |
| 2485 | .rpc_resp = &res, |
| 2486 | .rpc_cred = entry->cred, |
| 2487 | }; |
| 2488 | int mode = entry->mask; |
| 2489 | int status; |
| 2490 | |
| 2491 | /* |
| 2492 | * Determine which access bits we want to ask for... |
| 2493 | */ |
| 2494 | if (mode & MAY_READ) |
| 2495 | args.access |= NFS4_ACCESS_READ; |
| 2496 | if (S_ISDIR(inode->i_mode)) { |
| 2497 | if (mode & MAY_WRITE) |
| 2498 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2499 | if (mode & MAY_EXEC) |
| 2500 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2501 | } else { |
| 2502 | if (mode & MAY_WRITE) |
| 2503 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2504 | if (mode & MAY_EXEC) |
| 2505 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2506 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2507 | |
| 2508 | res.fattr = nfs_alloc_fattr(); |
| 2509 | if (res.fattr == NULL) |
| 2510 | return -ENOMEM; |
| 2511 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2512 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2513 | if (!status) { |
| 2514 | entry->mask = 0; |
| 2515 | if (res.access & NFS4_ACCESS_READ) |
| 2516 | entry->mask |= MAY_READ; |
| 2517 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2518 | entry->mask |= MAY_WRITE; |
| 2519 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2520 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2521 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2522 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2523 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | return status; |
| 2525 | } |
| 2526 | |
| 2527 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2528 | { |
| 2529 | struct nfs4_exception exception = { }; |
| 2530 | int err; |
| 2531 | do { |
| 2532 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2533 | _nfs4_proc_access(inode, entry), |
| 2534 | &exception); |
| 2535 | } while (exception.retry); |
| 2536 | return err; |
| 2537 | } |
| 2538 | |
| 2539 | /* |
| 2540 | * TODO: For the time being, we don't try to get any attributes |
| 2541 | * along with any of the zero-copy operations READ, READDIR, |
| 2542 | * READLINK, WRITE. |
| 2543 | * |
| 2544 | * In the case of the first three, we want to put the GETATTR |
| 2545 | * after the read-type operation -- this is because it is hard |
| 2546 | * to predict the length of a GETATTR response in v4, and thus |
| 2547 | * align the READ data correctly. This means that the GETATTR |
| 2548 | * may end up partially falling into the page cache, and we should |
| 2549 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2550 | * To do this efficiently, we need to know the total length |
| 2551 | * of data received, which doesn't seem to be available outside |
| 2552 | * of the RPC layer. |
| 2553 | * |
| 2554 | * In the case of WRITE, we also want to put the GETATTR after |
| 2555 | * the operation -- in this case because we want to make sure |
| 2556 | * we get the post-operation mtime and size. This means that |
| 2557 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2558 | * of it which would leave room in the 'tail' iovec. |
| 2559 | * |
| 2560 | * Both of these changes to the XDR layer would in fact be quite |
| 2561 | * minor, but I decided to leave them for a subsequent patch. |
| 2562 | */ |
| 2563 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2564 | unsigned int pgbase, unsigned int pglen) |
| 2565 | { |
| 2566 | struct nfs4_readlink args = { |
| 2567 | .fh = NFS_FH(inode), |
| 2568 | .pgbase = pgbase, |
| 2569 | .pglen = pglen, |
| 2570 | .pages = &page, |
| 2571 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2572 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | struct rpc_message msg = { |
| 2574 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2575 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2576 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2577 | }; |
| 2578 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2579 | return nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2580 | } |
| 2581 | |
| 2582 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2583 | unsigned int pgbase, unsigned int pglen) |
| 2584 | { |
| 2585 | struct nfs4_exception exception = { }; |
| 2586 | int err; |
| 2587 | do { |
| 2588 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2589 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2590 | &exception); |
| 2591 | } while (exception.retry); |
| 2592 | return err; |
| 2593 | } |
| 2594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2595 | /* |
| 2596 | * Got race? |
| 2597 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2598 | * Until then, this create/open method is prone to inefficiency and race |
| 2599 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2600 | * placed on the wire. |
| 2601 | * |
| 2602 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2603 | * The file will be opened again in the subsequent VFS open call |
| 2604 | * (nfs4_proc_file_open). |
| 2605 | * |
| 2606 | * The open for read will just hang around to be used by any process that |
| 2607 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2608 | */ |
| 2609 | |
| 2610 | static int |
| 2611 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2612 | int flags, struct nfs_open_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | { |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2614 | struct path my_path = { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2615 | .dentry = dentry, |
| 2616 | }; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2617 | struct path *path = &my_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2618 | struct nfs4_state *state; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2619 | struct rpc_cred *cred = NULL; |
| 2620 | fmode_t fmode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2621 | int status = 0; |
| 2622 | |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2623 | if (ctx != NULL) { |
| 2624 | cred = ctx->cred; |
| 2625 | path = &ctx->path; |
| 2626 | fmode = ctx->mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | } |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2628 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2629 | state = nfs4_do_open(dir, path, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2630 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | if (IS_ERR(state)) { |
| 2632 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2633 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2634 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2635 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2636 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2637 | if (ctx != NULL) |
| 2638 | ctx->state = state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2639 | else |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2640 | nfs4_close_sync(path, state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2641 | out: |
| 2642 | return status; |
| 2643 | } |
| 2644 | |
| 2645 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2646 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2647 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2648 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2650 | .name.len = name->len, |
| 2651 | .name.name = name->name, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2652 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2654 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2655 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2656 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2657 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2658 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2659 | .rpc_argp = &args, |
| 2660 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2661 | }; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2662 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2664 | res.dir_attr = nfs_alloc_fattr(); |
| 2665 | if (res.dir_attr == NULL) |
| 2666 | goto out; |
| 2667 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2668 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2669 | if (status == 0) { |
| 2670 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2671 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2672 | } |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2673 | nfs_free_fattr(res.dir_attr); |
| 2674 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2675 | return status; |
| 2676 | } |
| 2677 | |
| 2678 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2679 | { |
| 2680 | struct nfs4_exception exception = { }; |
| 2681 | int err; |
| 2682 | do { |
| 2683 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2684 | _nfs4_proc_remove(dir, name), |
| 2685 | &exception); |
| 2686 | } while (exception.retry); |
| 2687 | return err; |
| 2688 | } |
| 2689 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2690 | 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] | 2691 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2692 | struct nfs_server *server = NFS_SERVER(dir); |
| 2693 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2694 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2696 | args->bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2697 | res->server = server; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 2698 | res->seq_res.sr_slot = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2699 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | } |
| 2701 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2702 | 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] | 2703 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2704 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2705 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2706 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2707 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2708 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2709 | return 0; |
| 2710 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2711 | nfs_post_op_update_inode(dir, res->dir_attr); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2712 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2713 | } |
| 2714 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2715 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2716 | { |
| 2717 | struct nfs_server *server = NFS_SERVER(dir); |
| 2718 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2719 | struct nfs_renameres *res = msg->rpc_resp; |
| 2720 | |
| 2721 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
| 2722 | arg->bitmask = server->attr_bitmask; |
| 2723 | res->server = server; |
| 2724 | } |
| 2725 | |
| 2726 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2727 | struct inode *new_dir) |
| 2728 | { |
| 2729 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2730 | |
| 2731 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2732 | return 0; |
| 2733 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2734 | return 0; |
| 2735 | |
| 2736 | update_changeattr(old_dir, &res->old_cinfo); |
| 2737 | nfs_post_op_update_inode(old_dir, res->old_fattr); |
| 2738 | update_changeattr(new_dir, &res->new_cinfo); |
| 2739 | nfs_post_op_update_inode(new_dir, res->new_fattr); |
| 2740 | return 1; |
| 2741 | } |
| 2742 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2743 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2744 | struct inode *new_dir, struct qstr *new_name) |
| 2745 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2746 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2747 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2748 | .old_dir = NFS_FH(old_dir), |
| 2749 | .new_dir = NFS_FH(new_dir), |
| 2750 | .old_name = old_name, |
| 2751 | .new_name = new_name, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2752 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2754 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2755 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2756 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | struct rpc_message msg = { |
| 2758 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2759 | .rpc_argp = &arg, |
| 2760 | .rpc_resp = &res, |
| 2761 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2762 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2763 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2764 | res.old_fattr = nfs_alloc_fattr(); |
| 2765 | res.new_fattr = nfs_alloc_fattr(); |
| 2766 | if (res.old_fattr == NULL || res.new_fattr == NULL) |
| 2767 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2768 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2769 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | if (!status) { |
| 2771 | update_changeattr(old_dir, &res.old_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2772 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2773 | update_changeattr(new_dir, &res.new_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2774 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | } |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2776 | out: |
| 2777 | nfs_free_fattr(res.new_fattr); |
| 2778 | nfs_free_fattr(res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | return status; |
| 2780 | } |
| 2781 | |
| 2782 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2783 | struct inode *new_dir, struct qstr *new_name) |
| 2784 | { |
| 2785 | struct nfs4_exception exception = { }; |
| 2786 | int err; |
| 2787 | do { |
| 2788 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2789 | _nfs4_proc_rename(old_dir, old_name, |
| 2790 | new_dir, new_name), |
| 2791 | &exception); |
| 2792 | } while (exception.retry); |
| 2793 | return err; |
| 2794 | } |
| 2795 | |
| 2796 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2797 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2798 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | struct nfs4_link_arg arg = { |
| 2800 | .fh = NFS_FH(inode), |
| 2801 | .dir_fh = NFS_FH(dir), |
| 2802 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2803 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2805 | struct nfs4_link_res res = { |
| 2806 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2807 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2808 | struct rpc_message msg = { |
| 2809 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2810 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2811 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2813 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2814 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2815 | res.fattr = nfs_alloc_fattr(); |
| 2816 | res.dir_attr = nfs_alloc_fattr(); |
| 2817 | if (res.fattr == NULL || res.dir_attr == NULL) |
| 2818 | goto out; |
| 2819 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2820 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2821 | if (!status) { |
| 2822 | update_changeattr(dir, &res.cinfo); |
| 2823 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2824 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2825 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2826 | out: |
| 2827 | nfs_free_fattr(res.dir_attr); |
| 2828 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | return status; |
| 2830 | } |
| 2831 | |
| 2832 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2833 | { |
| 2834 | struct nfs4_exception exception = { }; |
| 2835 | int err; |
| 2836 | do { |
| 2837 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2838 | _nfs4_proc_link(inode, dir, name), |
| 2839 | &exception); |
| 2840 | } while (exception.retry); |
| 2841 | return err; |
| 2842 | } |
| 2843 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2844 | struct nfs4_createdata { |
| 2845 | struct rpc_message msg; |
| 2846 | struct nfs4_create_arg arg; |
| 2847 | struct nfs4_create_res res; |
| 2848 | struct nfs_fh fh; |
| 2849 | struct nfs_fattr fattr; |
| 2850 | struct nfs_fattr dir_fattr; |
| 2851 | }; |
| 2852 | |
| 2853 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 2854 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 2855 | { |
| 2856 | struct nfs4_createdata *data; |
| 2857 | |
| 2858 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2859 | if (data != NULL) { |
| 2860 | struct nfs_server *server = NFS_SERVER(dir); |
| 2861 | |
| 2862 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 2863 | data->msg.rpc_argp = &data->arg; |
| 2864 | data->msg.rpc_resp = &data->res; |
| 2865 | data->arg.dir_fh = NFS_FH(dir); |
| 2866 | data->arg.server = server; |
| 2867 | data->arg.name = name; |
| 2868 | data->arg.attrs = sattr; |
| 2869 | data->arg.ftype = ftype; |
| 2870 | data->arg.bitmask = server->attr_bitmask; |
| 2871 | data->res.server = server; |
| 2872 | data->res.fh = &data->fh; |
| 2873 | data->res.fattr = &data->fattr; |
| 2874 | data->res.dir_fattr = &data->dir_fattr; |
| 2875 | nfs_fattr_init(data->res.fattr); |
| 2876 | nfs_fattr_init(data->res.dir_fattr); |
| 2877 | } |
| 2878 | return data; |
| 2879 | } |
| 2880 | |
| 2881 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 2882 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2883 | int status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &data->msg, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 2884 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2885 | if (status == 0) { |
| 2886 | update_changeattr(dir, &data->res.dir_cinfo); |
| 2887 | nfs_post_op_update_inode(dir, data->res.dir_fattr); |
| 2888 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 2889 | } |
| 2890 | return status; |
| 2891 | } |
| 2892 | |
| 2893 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 2894 | { |
| 2895 | kfree(data); |
| 2896 | } |
| 2897 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2898 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2899 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2901 | struct nfs4_createdata *data; |
| 2902 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2903 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2904 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2905 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2906 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2907 | status = -ENOMEM; |
| 2908 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 2909 | if (data == NULL) |
| 2910 | goto out; |
| 2911 | |
| 2912 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 2913 | data->arg.u.symlink.pages = &page; |
| 2914 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2915 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2916 | status = nfs4_do_create(dir, dentry, data); |
| 2917 | |
| 2918 | nfs4_free_createdata(data); |
| 2919 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | return status; |
| 2921 | } |
| 2922 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2923 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2924 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | { |
| 2926 | struct nfs4_exception exception = { }; |
| 2927 | int err; |
| 2928 | do { |
| 2929 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2930 | _nfs4_proc_symlink(dir, dentry, page, |
| 2931 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | &exception); |
| 2933 | } while (exception.retry); |
| 2934 | return err; |
| 2935 | } |
| 2936 | |
| 2937 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2938 | struct iattr *sattr) |
| 2939 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2940 | struct nfs4_createdata *data; |
| 2941 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2943 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 2944 | if (data == NULL) |
| 2945 | goto out; |
| 2946 | |
| 2947 | status = nfs4_do_create(dir, dentry, data); |
| 2948 | |
| 2949 | nfs4_free_createdata(data); |
| 2950 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | return status; |
| 2952 | } |
| 2953 | |
| 2954 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2955 | struct iattr *sattr) |
| 2956 | { |
| 2957 | struct nfs4_exception exception = { }; |
| 2958 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2959 | |
| 2960 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2961 | do { |
| 2962 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2963 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 2964 | &exception); |
| 2965 | } while (exception.retry); |
| 2966 | return err; |
| 2967 | } |
| 2968 | |
| 2969 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2970 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2971 | { |
| 2972 | struct inode *dir = dentry->d_inode; |
| 2973 | struct nfs4_readdir_arg args = { |
| 2974 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2975 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2976 | .pgbase = 0, |
| 2977 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 2978 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 2979 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | }; |
| 2981 | struct nfs4_readdir_res res; |
| 2982 | struct rpc_message msg = { |
| 2983 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 2984 | .rpc_argp = &args, |
| 2985 | .rpc_resp = &res, |
| 2986 | .rpc_cred = cred, |
| 2987 | }; |
| 2988 | int status; |
| 2989 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2990 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 2991 | dentry->d_parent->d_name.name, |
| 2992 | dentry->d_name.name, |
| 2993 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 2995 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2996 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 2997 | if (status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 2999 | status += args.pgbase; |
| 3000 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3001 | |
| 3002 | nfs_invalidate_atime(dir); |
| 3003 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3004 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3005 | return status; |
| 3006 | } |
| 3007 | |
| 3008 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3009 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | { |
| 3011 | struct nfs4_exception exception = { }; |
| 3012 | int err; |
| 3013 | do { |
| 3014 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3015 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3016 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | &exception); |
| 3018 | } while (exception.retry); |
| 3019 | return err; |
| 3020 | } |
| 3021 | |
| 3022 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3023 | struct iattr *sattr, dev_t rdev) |
| 3024 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3025 | struct nfs4_createdata *data; |
| 3026 | int mode = sattr->ia_mode; |
| 3027 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3028 | |
| 3029 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 3030 | 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] | 3031 | |
| 3032 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3033 | if (data == NULL) |
| 3034 | goto out; |
| 3035 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3037 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3038 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3039 | data->arg.ftype = NF4BLK; |
| 3040 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3041 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | } |
| 3043 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3044 | data->arg.ftype = NF4CHR; |
| 3045 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3046 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3048 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3049 | status = nfs4_do_create(dir, dentry, data); |
| 3050 | |
| 3051 | nfs4_free_createdata(data); |
| 3052 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3053 | return status; |
| 3054 | } |
| 3055 | |
| 3056 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3057 | struct iattr *sattr, dev_t rdev) |
| 3058 | { |
| 3059 | struct nfs4_exception exception = { }; |
| 3060 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3061 | |
| 3062 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3063 | do { |
| 3064 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3065 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3066 | &exception); |
| 3067 | } while (exception.retry); |
| 3068 | return err; |
| 3069 | } |
| 3070 | |
| 3071 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3072 | struct nfs_fsstat *fsstat) |
| 3073 | { |
| 3074 | struct nfs4_statfs_arg args = { |
| 3075 | .fh = fhandle, |
| 3076 | .bitmask = server->attr_bitmask, |
| 3077 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3078 | struct nfs4_statfs_res res = { |
| 3079 | .fsstat = fsstat, |
| 3080 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3081 | struct rpc_message msg = { |
| 3082 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3083 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3084 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | }; |
| 3086 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3087 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3088 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3089 | } |
| 3090 | |
| 3091 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3092 | { |
| 3093 | struct nfs4_exception exception = { }; |
| 3094 | int err; |
| 3095 | do { |
| 3096 | err = nfs4_handle_exception(server, |
| 3097 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3098 | &exception); |
| 3099 | } while (exception.retry); |
| 3100 | return err; |
| 3101 | } |
| 3102 | |
| 3103 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3104 | struct nfs_fsinfo *fsinfo) |
| 3105 | { |
| 3106 | struct nfs4_fsinfo_arg args = { |
| 3107 | .fh = fhandle, |
| 3108 | .bitmask = server->attr_bitmask, |
| 3109 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3110 | struct nfs4_fsinfo_res res = { |
| 3111 | .fsinfo = fsinfo, |
| 3112 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 | struct rpc_message msg = { |
| 3114 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3115 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3116 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3117 | }; |
| 3118 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3119 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | } |
| 3121 | |
| 3122 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3123 | { |
| 3124 | struct nfs4_exception exception = { }; |
| 3125 | int err; |
| 3126 | |
| 3127 | do { |
| 3128 | err = nfs4_handle_exception(server, |
| 3129 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3130 | &exception); |
| 3131 | } while (exception.retry); |
| 3132 | return err; |
| 3133 | } |
| 3134 | |
| 3135 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3136 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3137 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3138 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3139 | } |
| 3140 | |
| 3141 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3142 | struct nfs_pathconf *pathconf) |
| 3143 | { |
| 3144 | struct nfs4_pathconf_arg args = { |
| 3145 | .fh = fhandle, |
| 3146 | .bitmask = server->attr_bitmask, |
| 3147 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3148 | struct nfs4_pathconf_res res = { |
| 3149 | .pathconf = pathconf, |
| 3150 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | struct rpc_message msg = { |
| 3152 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3153 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3154 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | }; |
| 3156 | |
| 3157 | /* None of the pathconf attributes are mandatory to implement */ |
| 3158 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3159 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3160 | return 0; |
| 3161 | } |
| 3162 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3163 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3164 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3165 | } |
| 3166 | |
| 3167 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3168 | struct nfs_pathconf *pathconf) |
| 3169 | { |
| 3170 | struct nfs4_exception exception = { }; |
| 3171 | int err; |
| 3172 | |
| 3173 | do { |
| 3174 | err = nfs4_handle_exception(server, |
| 3175 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3176 | &exception); |
| 3177 | } while (exception.retry); |
| 3178 | return err; |
| 3179 | } |
| 3180 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3181 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3182 | { |
| 3183 | nfs_invalidate_atime(data->inode); |
| 3184 | } |
| 3185 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3186 | 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] | 3187 | { |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3188 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3189 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3190 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3191 | nfs_restart_rpc(task, server->nfs_client); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3192 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3194 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3195 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3197 | renew_lease(server, data->timestamp); |
| 3198 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | } |
| 3200 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3201 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3202 | { |
| 3203 | |
| 3204 | dprintk("--> %s\n", __func__); |
| 3205 | |
| 3206 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3207 | return -EAGAIN; |
| 3208 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3209 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3210 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3211 | } |
| 3212 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3213 | 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] | 3214 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3215 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3216 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3217 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | } |
| 3219 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3220 | /* Reset the the nfs_read_data to send the read to the MDS. */ |
| 3221 | void nfs4_reset_read(struct rpc_task *task, struct nfs_read_data *data) |
| 3222 | { |
| 3223 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3224 | put_lseg(data->lseg); |
| 3225 | data->lseg = NULL; |
| 3226 | /* offsets will differ in the dense stripe case */ |
| 3227 | data->args.offset = data->mds_offset; |
| 3228 | data->ds_clp = NULL; |
| 3229 | data->args.fh = NFS_FH(data->inode); |
| 3230 | data->read_done_cb = nfs4_read_done_cb; |
| 3231 | task->tk_ops = data->mds_ops; |
| 3232 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3233 | } |
| 3234 | EXPORT_SYMBOL_GPL(nfs4_reset_read); |
| 3235 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3236 | 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] | 3237 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3238 | struct inode *inode = data->inode; |
| 3239 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3240 | 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] | 3241 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3242 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3244 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 3246 | nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3247 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3248 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3249 | } |
| 3250 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3251 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3252 | { |
| 3253 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3254 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3255 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3256 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3257 | } |
| 3258 | |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3259 | /* Reset the the nfs_write_data to send the write to the MDS. */ |
| 3260 | void nfs4_reset_write(struct rpc_task *task, struct nfs_write_data *data) |
| 3261 | { |
| 3262 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3263 | put_lseg(data->lseg); |
| 3264 | data->lseg = NULL; |
| 3265 | data->ds_clp = NULL; |
| 3266 | data->write_done_cb = nfs4_write_done_cb; |
| 3267 | data->args.fh = NFS_FH(data->inode); |
| 3268 | data->args.bitmask = data->res.server->cache_consistency_bitmask; |
| 3269 | data->args.offset = data->mds_offset; |
| 3270 | data->res.fattr = &data->fattr; |
| 3271 | task->tk_ops = data->mds_ops; |
| 3272 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3273 | } |
| 3274 | EXPORT_SYMBOL_GPL(nfs4_reset_write); |
| 3275 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3276 | 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] | 3277 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3278 | struct nfs_server *server = NFS_SERVER(data->inode); |
| 3279 | |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3280 | if (data->lseg) { |
| 3281 | data->args.bitmask = NULL; |
| 3282 | data->res.fattr = NULL; |
| 3283 | } else |
| 3284 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3285 | if (!data->write_done_cb) |
| 3286 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3287 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | data->timestamp = jiffies; |
| 3289 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3290 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3291 | } |
| 3292 | |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3293 | static int nfs4_commit_done_cb(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3294 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3295 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3296 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3297 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3298 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3299 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3300 | } |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 3301 | nfs_refresh_inode(inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3302 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3303 | } |
| 3304 | |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3305 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3306 | { |
| 3307 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3308 | return -EAGAIN; |
| 3309 | return data->write_done_cb(task, data); |
| 3310 | } |
| 3311 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3312 | 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] | 3313 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3314 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3315 | |
| 3316 | if (data->lseg) { |
| 3317 | data->args.bitmask = NULL; |
| 3318 | data->res.fattr = NULL; |
| 3319 | } else |
| 3320 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3321 | if (!data->write_done_cb) |
| 3322 | data->write_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3323 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3324 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3325 | } |
| 3326 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3327 | struct nfs4_renewdata { |
| 3328 | struct nfs_client *client; |
| 3329 | unsigned long timestamp; |
| 3330 | }; |
| 3331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3332 | /* |
| 3333 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3334 | * standalone procedure for queueing an asynchronous RENEW. |
| 3335 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3336 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3337 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3338 | struct nfs4_renewdata *data = calldata; |
| 3339 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3340 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3341 | if (atomic_read(&clp->cl_count) > 1) |
| 3342 | nfs4_schedule_state_renewal(clp); |
| 3343 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3344 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3345 | } |
| 3346 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3347 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3348 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3349 | struct nfs4_renewdata *data = calldata; |
| 3350 | struct nfs_client *clp = data->client; |
| 3351 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3352 | |
| 3353 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3354 | /* Unless we're shutting down, schedule state recovery! */ |
| 3355 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) != 0) |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3356 | nfs4_schedule_lease_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3357 | return; |
| 3358 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3359 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3360 | } |
| 3361 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3362 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3363 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3364 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3365 | }; |
| 3366 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3367 | 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] | 3368 | { |
| 3369 | struct rpc_message msg = { |
| 3370 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3371 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3372 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3374 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3376 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3377 | return -EIO; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3378 | data = kmalloc(sizeof(*data), GFP_KERNEL); |
| 3379 | if (data == NULL) |
| 3380 | return -ENOMEM; |
| 3381 | data->client = clp; |
| 3382 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3383 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3384 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3385 | } |
| 3386 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3387 | int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | { |
| 3389 | struct rpc_message msg = { |
| 3390 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3391 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3392 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | }; |
| 3394 | unsigned long now = jiffies; |
| 3395 | int status; |
| 3396 | |
| 3397 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3398 | if (status < 0) |
| 3399 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3400 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3401 | return 0; |
| 3402 | } |
| 3403 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3404 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3405 | { |
| 3406 | return (server->caps & NFS_CAP_ACLS) |
| 3407 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3408 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3409 | } |
| 3410 | |
| 3411 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3412 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3413 | * the stack. |
| 3414 | */ |
| 3415 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3416 | |
| 3417 | static void buf_to_pages(const void *buf, size_t buflen, |
| 3418 | struct page **pages, unsigned int *pgbase) |
| 3419 | { |
| 3420 | const void *p = buf; |
| 3421 | |
| 3422 | *pgbase = offset_in_page(buf); |
| 3423 | p -= *pgbase; |
| 3424 | while (p < buf + buflen) { |
| 3425 | *(pages++) = virt_to_page(p); |
| 3426 | p += PAGE_CACHE_SIZE; |
| 3427 | } |
| 3428 | } |
| 3429 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3430 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3431 | struct page **pages, unsigned int *pgbase) |
| 3432 | { |
| 3433 | struct page *newpage, **spages; |
| 3434 | int rc = 0; |
| 3435 | size_t len; |
| 3436 | spages = pages; |
| 3437 | |
| 3438 | do { |
Jovi Zhang | 43b7c3f | 2011-03-02 23:19:37 +0000 | [diff] [blame] | 3439 | len = min_t(size_t, PAGE_CACHE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3440 | newpage = alloc_page(GFP_KERNEL); |
| 3441 | |
| 3442 | if (newpage == NULL) |
| 3443 | goto unwind; |
| 3444 | memcpy(page_address(newpage), buf, len); |
| 3445 | buf += len; |
| 3446 | buflen -= len; |
| 3447 | *pages++ = newpage; |
| 3448 | rc++; |
| 3449 | } while (buflen != 0); |
| 3450 | |
| 3451 | return rc; |
| 3452 | |
| 3453 | unwind: |
| 3454 | for(; rc > 0; rc--) |
| 3455 | __free_page(spages[rc-1]); |
| 3456 | return -ENOMEM; |
| 3457 | } |
| 3458 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3459 | struct nfs4_cached_acl { |
| 3460 | int cached; |
| 3461 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3462 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3463 | }; |
| 3464 | |
| 3465 | 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] | 3466 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3467 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3468 | |
| 3469 | spin_lock(&inode->i_lock); |
| 3470 | kfree(nfsi->nfs4_acl); |
| 3471 | nfsi->nfs4_acl = acl; |
| 3472 | spin_unlock(&inode->i_lock); |
| 3473 | } |
| 3474 | |
| 3475 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3476 | { |
| 3477 | nfs4_set_cached_acl(inode, NULL); |
| 3478 | } |
| 3479 | |
| 3480 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3481 | { |
| 3482 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3483 | struct nfs4_cached_acl *acl; |
| 3484 | int ret = -ENOENT; |
| 3485 | |
| 3486 | spin_lock(&inode->i_lock); |
| 3487 | acl = nfsi->nfs4_acl; |
| 3488 | if (acl == NULL) |
| 3489 | goto out; |
| 3490 | if (buf == NULL) /* user is just asking for length */ |
| 3491 | goto out_len; |
| 3492 | if (acl->cached == 0) |
| 3493 | goto out; |
| 3494 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3495 | if (acl->len > buflen) |
| 3496 | goto out; |
| 3497 | memcpy(buf, acl->data, acl->len); |
| 3498 | out_len: |
| 3499 | ret = acl->len; |
| 3500 | out: |
| 3501 | spin_unlock(&inode->i_lock); |
| 3502 | return ret; |
| 3503 | } |
| 3504 | |
| 3505 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) |
| 3506 | { |
| 3507 | struct nfs4_cached_acl *acl; |
| 3508 | |
| 3509 | if (buf && acl_len <= PAGE_SIZE) { |
| 3510 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3511 | if (acl == NULL) |
| 3512 | goto out; |
| 3513 | acl->cached = 1; |
| 3514 | memcpy(acl->data, buf, acl_len); |
| 3515 | } else { |
| 3516 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3517 | if (acl == NULL) |
| 3518 | goto out; |
| 3519 | acl->cached = 0; |
| 3520 | } |
| 3521 | acl->len = acl_len; |
| 3522 | out: |
| 3523 | nfs4_set_cached_acl(inode, acl); |
| 3524 | } |
| 3525 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3526 | 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] | 3527 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3528 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3529 | struct nfs_getaclargs args = { |
| 3530 | .fh = NFS_FH(inode), |
| 3531 | .acl_pages = pages, |
| 3532 | .acl_len = buflen, |
| 3533 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3534 | struct nfs_getaclres res = { |
| 3535 | .acl_len = buflen, |
| 3536 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3537 | void *resp_buf; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3538 | struct rpc_message msg = { |
| 3539 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3540 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3541 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3542 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3543 | struct page *localpage = NULL; |
| 3544 | int ret; |
| 3545 | |
| 3546 | if (buflen < PAGE_SIZE) { |
| 3547 | /* As long as we're doing a round trip to the server anyway, |
| 3548 | * let's be prepared for a page of acl data. */ |
| 3549 | localpage = alloc_page(GFP_KERNEL); |
| 3550 | resp_buf = page_address(localpage); |
| 3551 | if (localpage == NULL) |
| 3552 | return -ENOMEM; |
| 3553 | args.acl_pages[0] = localpage; |
| 3554 | args.acl_pgbase = 0; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3555 | args.acl_len = PAGE_SIZE; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3556 | } else { |
| 3557 | resp_buf = buf; |
| 3558 | buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase); |
| 3559 | } |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3560 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3561 | if (ret) |
| 3562 | goto out_free; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3563 | if (res.acl_len > args.acl_len) |
| 3564 | nfs4_write_cached_acl(inode, NULL, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3565 | else |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3566 | nfs4_write_cached_acl(inode, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3567 | if (buf) { |
| 3568 | ret = -ERANGE; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3569 | if (res.acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3570 | goto out_free; |
| 3571 | if (localpage) |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3572 | memcpy(buf, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3573 | } |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3574 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3575 | out_free: |
| 3576 | if (localpage) |
| 3577 | __free_page(localpage); |
| 3578 | return ret; |
| 3579 | } |
| 3580 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3581 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3582 | { |
| 3583 | struct nfs4_exception exception = { }; |
| 3584 | ssize_t ret; |
| 3585 | do { |
| 3586 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3587 | if (ret >= 0) |
| 3588 | break; |
| 3589 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3590 | } while (exception.retry); |
| 3591 | return ret; |
| 3592 | } |
| 3593 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3594 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3595 | { |
| 3596 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3597 | int ret; |
| 3598 | |
| 3599 | if (!nfs4_server_supports_acls(server)) |
| 3600 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3601 | ret = nfs_revalidate_inode(server, inode); |
| 3602 | if (ret < 0) |
| 3603 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3604 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3605 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3606 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3607 | if (ret != -ENOENT) |
| 3608 | return ret; |
| 3609 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3610 | } |
| 3611 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3612 | 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] | 3613 | { |
| 3614 | struct nfs_server *server = NFS_SERVER(inode); |
| 3615 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3616 | struct nfs_setaclargs arg = { |
| 3617 | .fh = NFS_FH(inode), |
| 3618 | .acl_pages = pages, |
| 3619 | .acl_len = buflen, |
| 3620 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3621 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3622 | struct rpc_message msg = { |
| 3623 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3624 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3625 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3626 | }; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3627 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3628 | |
| 3629 | if (!nfs4_server_supports_acls(server)) |
| 3630 | return -EOPNOTSUPP; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3631 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3632 | if (i < 0) |
| 3633 | return i; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3634 | nfs_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3635 | ret = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3636 | |
| 3637 | /* |
| 3638 | * Free each page after tx, so the only ref left is |
| 3639 | * held by the network stack |
| 3640 | */ |
| 3641 | for (; i > 0; i--) |
| 3642 | put_page(pages[i-1]); |
| 3643 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3644 | /* |
| 3645 | * Acl update can result in inode attribute update. |
| 3646 | * so mark the attribute cache invalid. |
| 3647 | */ |
| 3648 | spin_lock(&inode->i_lock); |
| 3649 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3650 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3651 | nfs_access_zap_cache(inode); |
| 3652 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3653 | return ret; |
| 3654 | } |
| 3655 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3656 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3657 | { |
| 3658 | struct nfs4_exception exception = { }; |
| 3659 | int err; |
| 3660 | do { |
| 3661 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3662 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3663 | &exception); |
| 3664 | } while (exception.retry); |
| 3665 | return err; |
| 3666 | } |
| 3667 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3668 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3669 | 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] | 3670 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3671 | struct nfs_client *clp = server->nfs_client; |
| 3672 | |
| 3673 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3674 | return 0; |
| 3675 | switch(task->tk_status) { |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3676 | case -NFS4ERR_ADMIN_REVOKED: |
| 3677 | case -NFS4ERR_BAD_STATEID: |
| 3678 | case -NFS4ERR_OPENMODE: |
| 3679 | if (state == NULL) |
| 3680 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3681 | nfs4_schedule_stateid_recovery(server, state); |
| 3682 | goto wait_on_recovery; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3683 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3684 | case -NFS4ERR_STALE_CLIENTID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3685 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3686 | nfs4_schedule_lease_recovery(clp); |
| 3687 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3688 | #if defined(CONFIG_NFS_V4_1) |
| 3689 | case -NFS4ERR_BADSESSION: |
| 3690 | case -NFS4ERR_BADSLOT: |
| 3691 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3692 | case -NFS4ERR_DEADSESSION: |
| 3693 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3694 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3695 | case -NFS4ERR_SEQ_MISORDERED: |
| 3696 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3697 | task->tk_status); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3698 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3699 | task->tk_status = 0; |
| 3700 | return -EAGAIN; |
| 3701 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3702 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3703 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3704 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3705 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3706 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3707 | task->tk_status = 0; |
| 3708 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 3709 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3710 | case -NFS4ERR_OLD_STATEID: |
| 3711 | task->tk_status = 0; |
| 3712 | return -EAGAIN; |
| 3713 | } |
| 3714 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3715 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3716 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3717 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3718 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3719 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3720 | task->tk_status = 0; |
| 3721 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3722 | } |
| 3723 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3724 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 3725 | unsigned short port, struct rpc_cred *cred, |
| 3726 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3727 | { |
| 3728 | nfs4_verifier sc_verifier; |
| 3729 | struct nfs4_setclientid setclientid = { |
| 3730 | .sc_verifier = &sc_verifier, |
| 3731 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 3732 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3733 | }; |
| 3734 | struct rpc_message msg = { |
| 3735 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3736 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3737 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3738 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3739 | }; |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3740 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3741 | int loop = 0; |
| 3742 | int status; |
| 3743 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3744 | p = (__be32*)sc_verifier.data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 3746 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 3747 | |
| 3748 | for(;;) { |
| 3749 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3750 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3751 | clp->cl_ipaddr, |
| 3752 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3753 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3754 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3755 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3756 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3757 | clp->cl_id_uniquifier); |
| 3758 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3759 | sizeof(setclientid.sc_netid), |
| 3760 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3761 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3762 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3763 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3764 | clp->cl_ipaddr, port >> 8, port & 255); |
| 3765 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 3766 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3767 | if (status != -NFS4ERR_CLID_INUSE) |
| 3768 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3769 | if (loop != 0) { |
| 3770 | ++clp->cl_id_uniquifier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3771 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3772 | } |
| 3773 | ++loop; |
| 3774 | ssleep(clp->cl_lease_time / HZ + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | } |
| 3776 | return status; |
| 3777 | } |
| 3778 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3779 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3780 | struct nfs4_setclientid_res *arg, |
| 3781 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3782 | { |
| 3783 | struct nfs_fsinfo fsinfo; |
| 3784 | struct rpc_message msg = { |
| 3785 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3786 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3787 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3788 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | }; |
| 3790 | unsigned long now; |
| 3791 | int status; |
| 3792 | |
| 3793 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 3794 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3795 | if (status == 0) { |
| 3796 | spin_lock(&clp->cl_lock); |
| 3797 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 3798 | clp->cl_last_renewal = now; |
| 3799 | spin_unlock(&clp->cl_lock); |
| 3800 | } |
| 3801 | return status; |
| 3802 | } |
| 3803 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3804 | struct nfs4_delegreturndata { |
| 3805 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3806 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3807 | struct nfs_fh fh; |
| 3808 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3809 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3810 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3811 | int rpc_status; |
| 3812 | }; |
| 3813 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3814 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 3815 | { |
| 3816 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3817 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3818 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3819 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3820 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3821 | switch (task->tk_status) { |
| 3822 | case -NFS4ERR_STALE_STATEID: |
| 3823 | case -NFS4ERR_EXPIRED: |
| 3824 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3825 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3826 | break; |
| 3827 | default: |
| 3828 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 3829 | -EAGAIN) { |
| 3830 | nfs_restart_rpc(task, data->res.server->nfs_client); |
| 3831 | return; |
| 3832 | } |
| 3833 | } |
| 3834 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3835 | } |
| 3836 | |
| 3837 | static void nfs4_delegreturn_release(void *calldata) |
| 3838 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3839 | kfree(calldata); |
| 3840 | } |
| 3841 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3842 | #if defined(CONFIG_NFS_V4_1) |
| 3843 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 3844 | { |
| 3845 | struct nfs4_delegreturndata *d_data; |
| 3846 | |
| 3847 | d_data = (struct nfs4_delegreturndata *)data; |
| 3848 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3849 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3850 | &d_data->args.seq_args, |
| 3851 | &d_data->res.seq_res, 1, task)) |
| 3852 | return; |
| 3853 | rpc_call_start(task); |
| 3854 | } |
| 3855 | #endif /* CONFIG_NFS_V4_1 */ |
| 3856 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 3857 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3858 | #if defined(CONFIG_NFS_V4_1) |
| 3859 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 3860 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3861 | .rpc_call_done = nfs4_delegreturn_done, |
| 3862 | .rpc_release = nfs4_delegreturn_release, |
| 3863 | }; |
| 3864 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3865 | 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] | 3866 | { |
| 3867 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3868 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3869 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3870 | struct rpc_message msg = { |
| 3871 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 3872 | .rpc_cred = cred, |
| 3873 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3874 | struct rpc_task_setup task_setup_data = { |
| 3875 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3876 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3877 | .callback_ops = &nfs4_delegreturn_ops, |
| 3878 | .flags = RPC_TASK_ASYNC, |
| 3879 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3880 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3881 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3882 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3883 | if (data == NULL) |
| 3884 | return -ENOMEM; |
| 3885 | data->args.fhandle = &data->fh; |
| 3886 | data->args.stateid = &data->stateid; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3887 | data->args.bitmask = server->attr_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3888 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
| 3889 | memcpy(&data->stateid, stateid, sizeof(data->stateid)); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3890 | data->res.fattr = &data->fattr; |
| 3891 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3892 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3893 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3894 | data->rpc_status = 0; |
| 3895 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3896 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3897 | msg.rpc_argp = &data->args; |
| 3898 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3899 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 3900 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3901 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3902 | if (!issync) |
| 3903 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3904 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3905 | if (status != 0) |
| 3906 | goto out; |
| 3907 | status = data->rpc_status; |
| 3908 | if (status != 0) |
| 3909 | goto out; |
| 3910 | nfs_refresh_inode(inode, &data->fattr); |
| 3911 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3912 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3913 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3914 | } |
| 3915 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3916 | 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] | 3917 | { |
| 3918 | struct nfs_server *server = NFS_SERVER(inode); |
| 3919 | struct nfs4_exception exception = { }; |
| 3920 | int err; |
| 3921 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3922 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3923 | switch (err) { |
| 3924 | case -NFS4ERR_STALE_STATEID: |
| 3925 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3926 | case 0: |
| 3927 | return 0; |
| 3928 | } |
| 3929 | err = nfs4_handle_exception(server, err, &exception); |
| 3930 | } while (exception.retry); |
| 3931 | return err; |
| 3932 | } |
| 3933 | |
| 3934 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 3935 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 3936 | |
| 3937 | /* |
| 3938 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 3939 | */ |
| 3940 | static unsigned long |
| 3941 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 3942 | { |
Matthew Wilcox | 150030b | 2007-12-06 16:24:39 -0500 | [diff] [blame] | 3943 | schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3944 | timeout <<= 1; |
| 3945 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 3946 | return NFS4_LOCK_MAXTIMEOUT; |
| 3947 | return timeout; |
| 3948 | } |
| 3949 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3950 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3951 | { |
| 3952 | struct inode *inode = state->inode; |
| 3953 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3954 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3955 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3956 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3957 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3958 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3959 | struct nfs_lockt_res res = { |
| 3960 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3961 | }; |
| 3962 | struct rpc_message msg = { |
| 3963 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 3964 | .rpc_argp = &arg, |
| 3965 | .rpc_resp = &res, |
| 3966 | .rpc_cred = state->owner->so_cred, |
| 3967 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3968 | struct nfs4_lock_state *lsp; |
| 3969 | int status; |
| 3970 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3971 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3972 | status = nfs4_set_lock_state(state, request); |
| 3973 | if (status != 0) |
| 3974 | goto out; |
| 3975 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 3976 | arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 3977 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3978 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3979 | switch (status) { |
| 3980 | case 0: |
| 3981 | request->fl_type = F_UNLCK; |
| 3982 | break; |
| 3983 | case -NFS4ERR_DENIED: |
| 3984 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3985 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 3986 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3987 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3988 | return status; |
| 3989 | } |
| 3990 | |
| 3991 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3992 | { |
| 3993 | struct nfs4_exception exception = { }; |
| 3994 | int err; |
| 3995 | |
| 3996 | do { |
| 3997 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 3998 | _nfs4_proc_getlk(state, cmd, request), |
| 3999 | &exception); |
| 4000 | } while (exception.retry); |
| 4001 | return err; |
| 4002 | } |
| 4003 | |
| 4004 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4005 | { |
| 4006 | int res = 0; |
| 4007 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4008 | case FL_POSIX: |
| 4009 | res = posix_lock_file_wait(file, fl); |
| 4010 | break; |
| 4011 | case FL_FLOCK: |
| 4012 | res = flock_lock_file_wait(file, fl); |
| 4013 | break; |
| 4014 | default: |
| 4015 | BUG(); |
| 4016 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 | return res; |
| 4018 | } |
| 4019 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4020 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4021 | struct nfs_locku_args arg; |
| 4022 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4023 | struct nfs4_lock_state *lsp; |
| 4024 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4025 | struct file_lock fl; |
| 4026 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4027 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4028 | }; |
| 4029 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4030 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4031 | struct nfs_open_context *ctx, |
| 4032 | struct nfs4_lock_state *lsp, |
| 4033 | struct nfs_seqid *seqid) |
| 4034 | { |
| 4035 | struct nfs4_unlockdata *p; |
| 4036 | struct inode *inode = lsp->ls_state->inode; |
| 4037 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4038 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4039 | if (p == NULL) |
| 4040 | return NULL; |
| 4041 | p->arg.fh = NFS_FH(inode); |
| 4042 | p->arg.fl = &p->fl; |
| 4043 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4044 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4045 | p->arg.stateid = &lsp->ls_stateid; |
| 4046 | p->lsp = lsp; |
| 4047 | atomic_inc(&lsp->ls_count); |
| 4048 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4049 | p->ctx = get_nfs_open_context(ctx); |
| 4050 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4051 | p->server = NFS_SERVER(inode); |
| 4052 | return p; |
| 4053 | } |
| 4054 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4055 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4056 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4057 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4058 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4059 | nfs4_put_lock_state(calldata->lsp); |
| 4060 | put_nfs_open_context(calldata->ctx); |
| 4061 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4062 | } |
| 4063 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4064 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4065 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4066 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4067 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4068 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4069 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4070 | switch (task->tk_status) { |
| 4071 | case 0: |
| 4072 | memcpy(calldata->lsp->ls_stateid.data, |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4073 | calldata->res.stateid.data, |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4074 | sizeof(calldata->lsp->ls_stateid.data)); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4075 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4076 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4077 | case -NFS4ERR_BAD_STATEID: |
| 4078 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4079 | case -NFS4ERR_STALE_STATEID: |
| 4080 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4081 | break; |
| 4082 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4083 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 4084 | nfs_restart_rpc(task, |
Trond Myklebust | d61e612 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 4085 | calldata->server->nfs_client); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4086 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4087 | } |
| 4088 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4089 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4090 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4091 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4092 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4093 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4094 | return; |
| 4095 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4096 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4097 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4098 | return; |
| 4099 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4100 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4101 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4102 | &calldata->arg.seq_args, |
| 4103 | &calldata->res.seq_res, 1, task)) |
| 4104 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4105 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4106 | } |
| 4107 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4108 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4109 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4110 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4111 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4112 | }; |
| 4113 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4114 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4115 | struct nfs_open_context *ctx, |
| 4116 | struct nfs4_lock_state *lsp, |
| 4117 | struct nfs_seqid *seqid) |
| 4118 | { |
| 4119 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4120 | struct rpc_message msg = { |
| 4121 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4122 | .rpc_cred = ctx->cred, |
| 4123 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4124 | struct rpc_task_setup task_setup_data = { |
| 4125 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4126 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4127 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4128 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4129 | .flags = RPC_TASK_ASYNC, |
| 4130 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4131 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4132 | /* Ensure this is an unlock - when canceling a lock, the |
| 4133 | * canceled lock is passed in, and it won't be an unlock. |
| 4134 | */ |
| 4135 | fl->fl_type = F_UNLCK; |
| 4136 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4137 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4138 | if (data == NULL) { |
| 4139 | nfs_free_seqid(seqid); |
| 4140 | return ERR_PTR(-ENOMEM); |
| 4141 | } |
| 4142 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4143 | msg.rpc_argp = &data->arg; |
| 4144 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4145 | task_setup_data.callback_data = data; |
| 4146 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4147 | } |
| 4148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4149 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4150 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4151 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4152 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4153 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4154 | struct rpc_task *task; |
| 4155 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4156 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4157 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4158 | status = nfs4_set_lock_state(state, request); |
| 4159 | /* Unlock _before_ we do the RPC call */ |
| 4160 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4161 | down_read(&nfsi->rwsem); |
| 4162 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4163 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4164 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4165 | } |
| 4166 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4167 | if (status != 0) |
| 4168 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4169 | /* Is this a delegated lock? */ |
| 4170 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4171 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4172 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4173 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4174 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4175 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4176 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4177 | 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] | 4178 | status = PTR_ERR(task); |
| 4179 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4180 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4181 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4182 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4183 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4184 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4185 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4186 | } |
| 4187 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4188 | struct nfs4_lockdata { |
| 4189 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4190 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4191 | struct nfs4_lock_state *lsp; |
| 4192 | struct nfs_open_context *ctx; |
| 4193 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4194 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4195 | int rpc_status; |
| 4196 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4197 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4198 | }; |
| 4199 | |
| 4200 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4201 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4202 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4203 | { |
| 4204 | struct nfs4_lockdata *p; |
| 4205 | struct inode *inode = lsp->ls_state->inode; |
| 4206 | struct nfs_server *server = NFS_SERVER(inode); |
| 4207 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4208 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4209 | if (p == NULL) |
| 4210 | return NULL; |
| 4211 | |
| 4212 | p->arg.fh = NFS_FH(inode); |
| 4213 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4214 | 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] | 4215 | if (p->arg.open_seqid == NULL) |
| 4216 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4217 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4218 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4219 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4220 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4221 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 4222 | p->arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4223 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4224 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4225 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4226 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4227 | atomic_inc(&lsp->ls_count); |
| 4228 | p->ctx = get_nfs_open_context(ctx); |
| 4229 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4230 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4231 | out_free_seqid: |
| 4232 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4233 | out_free: |
| 4234 | kfree(p); |
| 4235 | return NULL; |
| 4236 | } |
| 4237 | |
| 4238 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4239 | { |
| 4240 | struct nfs4_lockdata *data = calldata; |
| 4241 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4242 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4243 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4244 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4245 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4246 | /* Do we need to do an open_to_lock_owner? */ |
| 4247 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4248 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4249 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4250 | data->arg.open_stateid = &state->stateid; |
| 4251 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4252 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4253 | } else |
| 4254 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4255 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4256 | if (nfs4_setup_sequence(data->server, |
| 4257 | &data->arg.seq_args, |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4258 | &data->res.seq_res, 1, task)) |
| 4259 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4260 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4261 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4262 | } |
| 4263 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4264 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4265 | { |
| 4266 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4267 | nfs4_lock_prepare(task, calldata); |
| 4268 | } |
| 4269 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4270 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4271 | { |
| 4272 | struct nfs4_lockdata *data = calldata; |
| 4273 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4274 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4275 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4276 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4277 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4278 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4279 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4280 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4281 | if (data->rpc_status == 0) |
| 4282 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4283 | else |
| 4284 | goto out; |
| 4285 | } |
| 4286 | if (data->rpc_status == 0) { |
| 4287 | memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, |
| 4288 | sizeof(data->lsp->ls_stateid.data)); |
| 4289 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Trond Myklebust | 88be9f9 | 2007-06-05 10:42:27 -0400 | [diff] [blame] | 4290 | renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4291 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4292 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4293 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4294 | } |
| 4295 | |
| 4296 | static void nfs4_lock_release(void *calldata) |
| 4297 | { |
| 4298 | struct nfs4_lockdata *data = calldata; |
| 4299 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4300 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4301 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4302 | if (data->cancelled != 0) { |
| 4303 | struct rpc_task *task; |
| 4304 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4305 | data->arg.lock_seqid); |
| 4306 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4307 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4308 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4309 | } else |
| 4310 | nfs_free_seqid(data->arg.lock_seqid); |
| 4311 | nfs4_put_lock_state(data->lsp); |
| 4312 | put_nfs_open_context(data->ctx); |
| 4313 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4314 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4315 | } |
| 4316 | |
| 4317 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4318 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4319 | .rpc_call_done = nfs4_lock_done, |
| 4320 | .rpc_release = nfs4_lock_release, |
| 4321 | }; |
| 4322 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4323 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4324 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4325 | .rpc_call_done = nfs4_lock_done, |
| 4326 | .rpc_release = nfs4_lock_release, |
| 4327 | }; |
| 4328 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4329 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4330 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4331 | switch (error) { |
| 4332 | case -NFS4ERR_ADMIN_REVOKED: |
| 4333 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4334 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4335 | if (new_lock_owner != 0 || |
| 4336 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4337 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4338 | break; |
| 4339 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4340 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4341 | case -NFS4ERR_EXPIRED: |
| 4342 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4343 | }; |
| 4344 | } |
| 4345 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4346 | 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] | 4347 | { |
| 4348 | struct nfs4_lockdata *data; |
| 4349 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4350 | struct rpc_message msg = { |
| 4351 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4352 | .rpc_cred = state->owner->so_cred, |
| 4353 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4354 | struct rpc_task_setup task_setup_data = { |
| 4355 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4356 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4357 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4358 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4359 | .flags = RPC_TASK_ASYNC, |
| 4360 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4361 | int ret; |
| 4362 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4363 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4364 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4365 | fl->fl_u.nfs4_fl.owner, |
| 4366 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4367 | if (data == NULL) |
| 4368 | return -ENOMEM; |
| 4369 | if (IS_SETLKW(cmd)) |
| 4370 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4371 | if (recovery_type > NFS_LOCK_NEW) { |
| 4372 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4373 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4374 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4375 | } |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4376 | msg.rpc_argp = &data->arg; |
| 4377 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4378 | task_setup_data.callback_data = data; |
| 4379 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4380 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4381 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4382 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4383 | if (ret == 0) { |
| 4384 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4385 | if (ret) |
| 4386 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4387 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4388 | } else |
| 4389 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4390 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4391 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4392 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4393 | } |
| 4394 | |
| 4395 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4396 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4397 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4398 | struct nfs4_exception exception = { }; |
| 4399 | int err; |
| 4400 | |
| 4401 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4402 | /* Cache the lock if possible... */ |
| 4403 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4404 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4405 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4406 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4407 | break; |
| 4408 | nfs4_handle_exception(server, err, &exception); |
| 4409 | } while (exception.retry); |
| 4410 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4411 | } |
| 4412 | |
| 4413 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4414 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4415 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4416 | struct nfs4_exception exception = { }; |
| 4417 | int err; |
| 4418 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4419 | err = nfs4_set_lock_state(state, request); |
| 4420 | if (err != 0) |
| 4421 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4422 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4423 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4424 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4425 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4426 | switch (err) { |
| 4427 | default: |
| 4428 | goto out; |
| 4429 | case -NFS4ERR_GRACE: |
| 4430 | case -NFS4ERR_DELAY: |
| 4431 | nfs4_handle_exception(server, err, &exception); |
| 4432 | err = 0; |
| 4433 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4434 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4435 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4436 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4437 | } |
| 4438 | |
| 4439 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4440 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4441 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4442 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4443 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4444 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4445 | if ((fl_flags & FL_POSIX) && |
| 4446 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4447 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4448 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4449 | status = nfs4_set_lock_state(state, request); |
| 4450 | if (status != 0) |
| 4451 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4452 | request->fl_flags |= FL_ACCESS; |
| 4453 | status = do_vfs_lock(request->fl_file, request); |
| 4454 | if (status < 0) |
| 4455 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4456 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4457 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4458 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4459 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4460 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4461 | status = do_vfs_lock(request->fl_file, request); |
| 4462 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4463 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4464 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4465 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4466 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4467 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4468 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4469 | if (do_vfs_lock(request->fl_file, request) < 0) |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4470 | 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] | 4471 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4472 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4473 | out: |
| 4474 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4475 | return status; |
| 4476 | } |
| 4477 | |
| 4478 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4479 | { |
| 4480 | struct nfs4_exception exception = { }; |
| 4481 | int err; |
| 4482 | |
| 4483 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4484 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4485 | if (err == -NFS4ERR_DENIED) |
| 4486 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4487 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4488 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4489 | } while (exception.retry); |
| 4490 | return err; |
| 4491 | } |
| 4492 | |
| 4493 | static int |
| 4494 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4495 | { |
| 4496 | struct nfs_open_context *ctx; |
| 4497 | struct nfs4_state *state; |
| 4498 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4499 | int status; |
| 4500 | |
| 4501 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4502 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4503 | state = ctx->state; |
| 4504 | |
| 4505 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4506 | return -EINVAL; |
| 4507 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4508 | if (IS_GETLK(cmd)) { |
| 4509 | if (state != NULL) |
| 4510 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4511 | return 0; |
| 4512 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4513 | |
| 4514 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4515 | return -EINVAL; |
| 4516 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4517 | if (request->fl_type == F_UNLCK) { |
| 4518 | if (state != NULL) |
| 4519 | return nfs4_proc_unlck(state, cmd, request); |
| 4520 | return 0; |
| 4521 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4523 | if (state == NULL) |
| 4524 | return -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4525 | do { |
| 4526 | status = nfs4_proc_setlk(state, cmd, request); |
| 4527 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4528 | break; |
| 4529 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4530 | status = -ERESTARTSYS; |
| 4531 | if (signalled()) |
| 4532 | break; |
| 4533 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4534 | return status; |
| 4535 | } |
| 4536 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4537 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4538 | { |
| 4539 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4540 | struct nfs4_exception exception = { }; |
| 4541 | int err; |
| 4542 | |
| 4543 | err = nfs4_set_lock_state(state, fl); |
| 4544 | if (err != 0) |
| 4545 | goto out; |
| 4546 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4547 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4548 | switch (err) { |
| 4549 | default: |
| 4550 | printk(KERN_ERR "%s: unhandled error %d.\n", |
| 4551 | __func__, err); |
| 4552 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4553 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4554 | goto out; |
| 4555 | case -NFS4ERR_EXPIRED: |
| 4556 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4557 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4558 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4559 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4560 | case -NFS4ERR_BADSESSION: |
| 4561 | case -NFS4ERR_BADSLOT: |
| 4562 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4563 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4564 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4565 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4566 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4567 | case -ERESTARTSYS: |
| 4568 | /* |
| 4569 | * The show must go on: exit, but mark the |
| 4570 | * stateid as needing recovery. |
| 4571 | */ |
| 4572 | case -NFS4ERR_ADMIN_REVOKED: |
| 4573 | case -NFS4ERR_BAD_STATEID: |
| 4574 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4575 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4576 | err = 0; |
| 4577 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4578 | case -EKEYEXPIRED: |
| 4579 | /* |
| 4580 | * User RPCSEC_GSS context has expired. |
| 4581 | * We cannot recover this stateid now, so |
| 4582 | * skip it and allow recovery thread to |
| 4583 | * proceed. |
| 4584 | */ |
| 4585 | err = 0; |
| 4586 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4587 | case -ENOMEM: |
| 4588 | case -NFS4ERR_DENIED: |
| 4589 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4590 | err = 0; |
| 4591 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4592 | case -NFS4ERR_DELAY: |
| 4593 | break; |
| 4594 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4595 | err = nfs4_handle_exception(server, err, &exception); |
| 4596 | } while (exception.retry); |
| 4597 | out: |
| 4598 | return err; |
| 4599 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4600 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4601 | static void nfs4_release_lockowner_release(void *calldata) |
| 4602 | { |
| 4603 | kfree(calldata); |
| 4604 | } |
| 4605 | |
| 4606 | const struct rpc_call_ops nfs4_release_lockowner_ops = { |
| 4607 | .rpc_release = nfs4_release_lockowner_release, |
| 4608 | }; |
| 4609 | |
| 4610 | void nfs4_release_lockowner(const struct nfs4_lock_state *lsp) |
| 4611 | { |
| 4612 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
| 4613 | struct nfs_release_lockowner_args *args; |
| 4614 | struct rpc_message msg = { |
| 4615 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 4616 | }; |
| 4617 | |
| 4618 | if (server->nfs_client->cl_mvops->minor_version != 0) |
| 4619 | return; |
| 4620 | args = kmalloc(sizeof(*args), GFP_NOFS); |
| 4621 | if (!args) |
| 4622 | return; |
| 4623 | args->lock_owner.clientid = server->nfs_client->cl_clientid; |
| 4624 | args->lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4625 | args->lock_owner.s_dev = server->s_dev; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4626 | msg.rpc_argp = args; |
| 4627 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args); |
| 4628 | } |
| 4629 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4630 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4631 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4632 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 4633 | const void *buf, size_t buflen, |
| 4634 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4635 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4636 | if (strcmp(key, "") != 0) |
| 4637 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4638 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4639 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4640 | } |
| 4641 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4642 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 4643 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4644 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4645 | if (strcmp(key, "") != 0) |
| 4646 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4647 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4648 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4649 | } |
| 4650 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4651 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 4652 | size_t list_len, const char *name, |
| 4653 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4654 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4655 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4656 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4657 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4658 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4659 | |
| 4660 | if (list && len <= list_len) |
| 4661 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4662 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4663 | } |
| 4664 | |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4665 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4666 | { |
| 4667 | if (!((fattr->valid & NFS_ATTR_FATTR_FILEID) && |
| 4668 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
| 4669 | (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL))) |
| 4670 | return; |
| 4671 | |
| 4672 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 4673 | NFS_ATTR_FATTR_NLINK; |
| 4674 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4675 | fattr->nlink = 2; |
| 4676 | } |
| 4677 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 4678 | int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 4679 | struct nfs4_fs_locations *fs_locations, struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4680 | { |
| 4681 | struct nfs_server *server = NFS_SERVER(dir); |
| 4682 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4683 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 4684 | [1] = FATTR4_WORD1_MOUNTED_ON_FILEID, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4685 | }; |
| 4686 | struct nfs4_fs_locations_arg args = { |
| 4687 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4688 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4689 | .page = page, |
| 4690 | .bitmask = bitmask, |
| 4691 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4692 | struct nfs4_fs_locations_res res = { |
| 4693 | .fs_locations = fs_locations, |
| 4694 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4695 | struct rpc_message msg = { |
| 4696 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4697 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4698 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4699 | }; |
| 4700 | int status; |
| 4701 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4702 | dprintk("%s: start\n", __func__); |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4703 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4704 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 4705 | fs_locations->nlocations = 0; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4706 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4707 | nfs_fixup_referral_attributes(&fs_locations->fattr); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4708 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4709 | return status; |
| 4710 | } |
| 4711 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 4712 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4713 | { |
| 4714 | int status; |
| 4715 | struct nfs4_secinfo_arg args = { |
| 4716 | .dir_fh = NFS_FH(dir), |
| 4717 | .name = name, |
| 4718 | }; |
| 4719 | struct nfs4_secinfo_res res = { |
| 4720 | .flavors = flavors, |
| 4721 | }; |
| 4722 | struct rpc_message msg = { |
| 4723 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 4724 | .rpc_argp = &args, |
| 4725 | .rpc_resp = &res, |
| 4726 | }; |
| 4727 | |
| 4728 | dprintk("NFS call secinfo %s\n", name->name); |
| 4729 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 4730 | dprintk("NFS reply secinfo: %d\n", status); |
| 4731 | return status; |
| 4732 | } |
| 4733 | |
| 4734 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4735 | { |
| 4736 | struct nfs4_exception exception = { }; |
| 4737 | int err; |
| 4738 | do { |
| 4739 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 4740 | _nfs4_proc_secinfo(dir, name, flavors), |
| 4741 | &exception); |
| 4742 | } while (exception.retry); |
| 4743 | return err; |
| 4744 | } |
| 4745 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4746 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4747 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4748 | * Check the exchange flags returned by the server for invalid flags, having |
| 4749 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 4750 | * DS flags set. |
| 4751 | */ |
| 4752 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 4753 | { |
| 4754 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 4755 | goto out_inval; |
| 4756 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 4757 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 4758 | goto out_inval; |
| 4759 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 4760 | goto out_inval; |
| 4761 | return NFS_OK; |
| 4762 | out_inval: |
| 4763 | return -NFS4ERR_INVAL; |
| 4764 | } |
| 4765 | |
| 4766 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4767 | * nfs4_proc_exchange_id() |
| 4768 | * |
| 4769 | * Since the clientid has expired, all compounds using sessions |
| 4770 | * associated with the stale clientid will be returning |
| 4771 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 4772 | * be in some phase of session reset. |
| 4773 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 4774 | 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] | 4775 | { |
| 4776 | nfs4_verifier verifier; |
| 4777 | struct nfs41_exchange_id_args args = { |
| 4778 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4779 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4780 | }; |
| 4781 | struct nfs41_exchange_id_res res = { |
| 4782 | .client = clp, |
| 4783 | }; |
| 4784 | int status; |
| 4785 | struct rpc_message msg = { |
| 4786 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 4787 | .rpc_argp = &args, |
| 4788 | .rpc_resp = &res, |
| 4789 | .rpc_cred = cred, |
| 4790 | }; |
| 4791 | __be32 *p; |
| 4792 | |
| 4793 | dprintk("--> %s\n", __func__); |
| 4794 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 4795 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4796 | p = (u32 *)verifier.data; |
| 4797 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 4798 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 4799 | args.verifier = &verifier; |
| 4800 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4801 | args.id_len = scnprintf(args.id, sizeof(args.id), |
| 4802 | "%s/%s.%s/%u", |
| 4803 | clp->cl_ipaddr, |
| 4804 | init_utsname()->nodename, |
| 4805 | init_utsname()->domainname, |
| 4806 | clp->cl_rpcclient->cl_auth->au_flavor); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4807 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4808 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4809 | if (!status) |
| 4810 | status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4811 | dprintk("<-- %s status= %d\n", __func__, status); |
| 4812 | return status; |
| 4813 | } |
| 4814 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4815 | struct nfs4_get_lease_time_data { |
| 4816 | struct nfs4_get_lease_time_args *args; |
| 4817 | struct nfs4_get_lease_time_res *res; |
| 4818 | struct nfs_client *clp; |
| 4819 | }; |
| 4820 | |
| 4821 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 4822 | void *calldata) |
| 4823 | { |
| 4824 | int ret; |
| 4825 | struct nfs4_get_lease_time_data *data = |
| 4826 | (struct nfs4_get_lease_time_data *)calldata; |
| 4827 | |
| 4828 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4829 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4830 | /* just setup sequence, do not trigger session recovery |
| 4831 | since we're invoked within one */ |
| 4832 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4833 | &data->args->la_seq_args, |
| 4834 | &data->res->lr_seq_res, 0, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4835 | |
| 4836 | BUG_ON(ret == -EAGAIN); |
| 4837 | rpc_call_start(task); |
| 4838 | dprintk("<-- %s\n", __func__); |
| 4839 | } |
| 4840 | |
| 4841 | /* |
| 4842 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 4843 | * from sequence operation or clientid errors. |
| 4844 | */ |
| 4845 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 4846 | { |
| 4847 | struct nfs4_get_lease_time_data *data = |
| 4848 | (struct nfs4_get_lease_time_data *)calldata; |
| 4849 | |
| 4850 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4851 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 4852 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4853 | switch (task->tk_status) { |
| 4854 | case -NFS4ERR_DELAY: |
| 4855 | case -NFS4ERR_GRACE: |
| 4856 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 4857 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 4858 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4859 | /* fall through */ |
| 4860 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 4861 | nfs_restart_rpc(task, data->clp); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4862 | return; |
| 4863 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4864 | dprintk("<-- %s\n", __func__); |
| 4865 | } |
| 4866 | |
| 4867 | struct rpc_call_ops nfs4_get_lease_time_ops = { |
| 4868 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 4869 | .rpc_call_done = nfs4_get_lease_time_done, |
| 4870 | }; |
| 4871 | |
| 4872 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 4873 | { |
| 4874 | struct rpc_task *task; |
| 4875 | struct nfs4_get_lease_time_args args; |
| 4876 | struct nfs4_get_lease_time_res res = { |
| 4877 | .lr_fsinfo = fsinfo, |
| 4878 | }; |
| 4879 | struct nfs4_get_lease_time_data data = { |
| 4880 | .args = &args, |
| 4881 | .res = &res, |
| 4882 | .clp = clp, |
| 4883 | }; |
| 4884 | struct rpc_message msg = { |
| 4885 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 4886 | .rpc_argp = &args, |
| 4887 | .rpc_resp = &res, |
| 4888 | }; |
| 4889 | struct rpc_task_setup task_setup = { |
| 4890 | .rpc_client = clp->cl_rpcclient, |
| 4891 | .rpc_message = &msg, |
| 4892 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4893 | .callback_data = &data, |
| 4894 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4895 | }; |
| 4896 | int status; |
| 4897 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4898 | dprintk("--> %s\n", __func__); |
| 4899 | task = rpc_run_task(&task_setup); |
| 4900 | |
| 4901 | if (IS_ERR(task)) |
| 4902 | status = PTR_ERR(task); |
| 4903 | else { |
| 4904 | status = task->tk_status; |
| 4905 | rpc_put_task(task); |
| 4906 | } |
| 4907 | dprintk("<-- %s return %d\n", __func__, status); |
| 4908 | |
| 4909 | return status; |
| 4910 | } |
| 4911 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4912 | /* |
| 4913 | * Reset a slot table |
| 4914 | */ |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4915 | static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 4916 | int ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4917 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4918 | struct nfs4_slot *new = NULL; |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4919 | int i; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4920 | int ret = 0; |
| 4921 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4922 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 4923 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4924 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4925 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 4926 | if (max_reqs != tbl->max_slots) { |
| 4927 | ret = -ENOMEM; |
| 4928 | new = kmalloc(max_reqs * sizeof(struct nfs4_slot), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4929 | GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4930 | if (!new) |
| 4931 | goto out; |
| 4932 | ret = 0; |
| 4933 | kfree(tbl->slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4934 | } |
| 4935 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4936 | if (new) { |
| 4937 | tbl->slots = new; |
| 4938 | tbl->max_slots = max_reqs; |
| 4939 | } |
| 4940 | for (i = 0; i < tbl->max_slots; ++i) |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4941 | tbl->slots[i].seq_nr = ivalue; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4942 | spin_unlock(&tbl->slot_tbl_lock); |
| 4943 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4944 | tbl, tbl->slots, tbl->max_slots); |
| 4945 | out: |
| 4946 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4947 | return ret; |
| 4948 | } |
| 4949 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4950 | /* |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4951 | * Reset the forechannel and backchannel slot tables |
| 4952 | */ |
| 4953 | static int nfs4_reset_slot_tables(struct nfs4_session *session) |
| 4954 | { |
| 4955 | int status; |
| 4956 | |
| 4957 | status = nfs4_reset_slot_table(&session->fc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4958 | session->fc_attrs.max_reqs, 1); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4959 | if (status) |
| 4960 | return status; |
| 4961 | |
| 4962 | status = nfs4_reset_slot_table(&session->bc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4963 | session->bc_attrs.max_reqs, 0); |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4964 | return status; |
| 4965 | } |
| 4966 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4967 | /* Destroy the slot table */ |
| 4968 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 4969 | { |
| 4970 | if (session->fc_slot_table.slots != NULL) { |
| 4971 | kfree(session->fc_slot_table.slots); |
| 4972 | session->fc_slot_table.slots = NULL; |
| 4973 | } |
| 4974 | if (session->bc_slot_table.slots != NULL) { |
| 4975 | kfree(session->bc_slot_table.slots); |
| 4976 | session->bc_slot_table.slots = NULL; |
| 4977 | } |
| 4978 | return; |
| 4979 | } |
| 4980 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4981 | /* |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4982 | * Initialize slot table |
| 4983 | */ |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4984 | static int nfs4_init_slot_table(struct nfs4_slot_table *tbl, |
| 4985 | int max_slots, int ivalue) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4986 | { |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4987 | struct nfs4_slot *slot; |
| 4988 | int ret = -ENOMEM; |
| 4989 | |
| 4990 | BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE); |
| 4991 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4992 | dprintk("--> %s: max_reqs=%u\n", __func__, max_slots); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4993 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4994 | slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4995 | if (!slot) |
| 4996 | goto out; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4997 | ret = 0; |
| 4998 | |
| 4999 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5000 | tbl->max_slots = max_slots; |
| 5001 | tbl->slots = slot; |
| 5002 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 5003 | spin_unlock(&tbl->slot_tbl_lock); |
| 5004 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5005 | tbl, tbl->slots, tbl->max_slots); |
| 5006 | out: |
| 5007 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5008 | return ret; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5009 | } |
| 5010 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5011 | /* |
| 5012 | * Initialize the forechannel and backchannel tables |
| 5013 | */ |
| 5014 | static int nfs4_init_slot_tables(struct nfs4_session *session) |
| 5015 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5016 | struct nfs4_slot_table *tbl; |
| 5017 | int status = 0; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5018 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5019 | tbl = &session->fc_slot_table; |
| 5020 | if (tbl->slots == NULL) { |
| 5021 | status = nfs4_init_slot_table(tbl, |
| 5022 | session->fc_attrs.max_reqs, 1); |
| 5023 | if (status) |
| 5024 | return status; |
| 5025 | } |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5026 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5027 | tbl = &session->bc_slot_table; |
| 5028 | if (tbl->slots == NULL) { |
| 5029 | status = nfs4_init_slot_table(tbl, |
| 5030 | session->bc_attrs.max_reqs, 0); |
| 5031 | if (status) |
| 5032 | nfs4_destroy_slot_tables(session); |
| 5033 | } |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5034 | |
| 5035 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5036 | } |
| 5037 | |
| 5038 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 5039 | { |
| 5040 | struct nfs4_session *session; |
| 5041 | struct nfs4_slot_table *tbl; |
| 5042 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5043 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5044 | if (!session) |
| 5045 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 5046 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5047 | tbl = &session->fc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 5048 | tbl->highest_used_slotid = -1; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5049 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5050 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5051 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5052 | |
| 5053 | tbl = &session->bc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 5054 | tbl->highest_used_slotid = -1; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5055 | spin_lock_init(&tbl->slot_tbl_lock); |
| 5056 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5057 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5058 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5059 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 5060 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5061 | session->clp = clp; |
| 5062 | return session; |
| 5063 | } |
| 5064 | |
| 5065 | void nfs4_destroy_session(struct nfs4_session *session) |
| 5066 | { |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5067 | nfs4_proc_destroy_session(session); |
| 5068 | dprintk("%s Destroy backchannel for xprt %p\n", |
| 5069 | __func__, session->clp->cl_rpcclient->cl_xprt); |
| 5070 | xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt, |
| 5071 | NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5072 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5073 | kfree(session); |
| 5074 | } |
| 5075 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5076 | /* |
| 5077 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5078 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5079 | * use them. |
| 5080 | * |
| 5081 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5082 | * always set csa_cachethis to FALSE because the current implementation |
| 5083 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5084 | */ |
| 5085 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5086 | { |
| 5087 | struct nfs4_session *session = args->client->cl_session; |
| 5088 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 5089 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 5090 | |
| 5091 | if (mxrqst_sz == 0) |
| 5092 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5093 | if (mxresp_sz == 0) |
| 5094 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5095 | /* Fore channel attributes */ |
| 5096 | args->fc_attrs.headerpadsz = 0; |
| 5097 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5098 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5099 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
| 5100 | args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs; |
| 5101 | |
| 5102 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5103 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5104 | __func__, |
| 5105 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5106 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5107 | |
| 5108 | /* Back channel attributes */ |
| 5109 | args->bc_attrs.headerpadsz = 0; |
| 5110 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5111 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5112 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5113 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5114 | args->bc_attrs.max_reqs = 1; |
| 5115 | |
| 5116 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5117 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5118 | __func__, |
| 5119 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5120 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5121 | args->bc_attrs.max_reqs); |
| 5122 | } |
| 5123 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5124 | 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] | 5125 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5126 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5127 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5128 | |
| 5129 | if (rcvd->headerpadsz > sent->headerpadsz) |
| 5130 | return -EINVAL; |
| 5131 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5132 | return -EINVAL; |
| 5133 | /* |
| 5134 | * Our requested max_ops is the minimum we need; we're not |
| 5135 | * prepared to break up compounds into smaller pieces than that. |
| 5136 | * So, no point even trying to continue if the server won't |
| 5137 | * cooperate: |
| 5138 | */ |
| 5139 | if (rcvd->max_ops < sent->max_ops) |
| 5140 | return -EINVAL; |
| 5141 | if (rcvd->max_reqs == 0) |
| 5142 | return -EINVAL; |
| 5143 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5144 | } |
| 5145 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5146 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5147 | { |
| 5148 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5149 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5150 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5151 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5152 | return -EINVAL; |
| 5153 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5154 | return -EINVAL; |
| 5155 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5156 | return -EINVAL; |
| 5157 | /* These would render the backchannel useless: */ |
| 5158 | if (rcvd->max_ops == 0) |
| 5159 | return -EINVAL; |
| 5160 | if (rcvd->max_reqs == 0) |
| 5161 | return -EINVAL; |
| 5162 | return 0; |
| 5163 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5164 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5165 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5166 | struct nfs4_session *session) |
| 5167 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5168 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5169 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5170 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5171 | if (ret) |
| 5172 | return ret; |
| 5173 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5174 | } |
| 5175 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5176 | static int _nfs4_proc_create_session(struct nfs_client *clp) |
| 5177 | { |
| 5178 | struct nfs4_session *session = clp->cl_session; |
| 5179 | struct nfs41_create_session_args args = { |
| 5180 | .client = clp, |
| 5181 | .cb_program = NFS4_CALLBACK, |
| 5182 | }; |
| 5183 | struct nfs41_create_session_res res = { |
| 5184 | .client = clp, |
| 5185 | }; |
| 5186 | struct rpc_message msg = { |
| 5187 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5188 | .rpc_argp = &args, |
| 5189 | .rpc_resp = &res, |
| 5190 | }; |
| 5191 | int status; |
| 5192 | |
| 5193 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5194 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5195 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5196 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5197 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5198 | if (!status) |
| 5199 | /* Verify the session's negotiated channel_attrs values */ |
| 5200 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5201 | if (!status) { |
| 5202 | /* Increment the clientid slot sequence id */ |
| 5203 | clp->cl_seqid++; |
| 5204 | } |
| 5205 | |
| 5206 | return status; |
| 5207 | } |
| 5208 | |
| 5209 | /* |
| 5210 | * Issues a CREATE_SESSION operation to the server. |
| 5211 | * It is the responsibility of the caller to verify the session is |
| 5212 | * expired before calling this routine. |
| 5213 | */ |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5214 | int nfs4_proc_create_session(struct nfs_client *clp) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5215 | { |
| 5216 | int status; |
| 5217 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5218 | struct nfs4_session *session = clp->cl_session; |
| 5219 | |
| 5220 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5221 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5222 | status = _nfs4_proc_create_session(clp); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5223 | if (status) |
| 5224 | goto out; |
| 5225 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5226 | /* Init and reset the fore channel */ |
| 5227 | status = nfs4_init_slot_tables(session); |
| 5228 | dprintk("slot table initialization returned %d\n", status); |
| 5229 | if (status) |
| 5230 | goto out; |
| 5231 | status = nfs4_reset_slot_tables(session); |
| 5232 | dprintk("slot table reset returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5233 | if (status) |
| 5234 | goto out; |
| 5235 | |
| 5236 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5237 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5238 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5239 | out: |
| 5240 | dprintk("<-- %s\n", __func__); |
| 5241 | return status; |
| 5242 | } |
| 5243 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5244 | /* |
| 5245 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5246 | * The caller must serialize access to this routine. |
| 5247 | */ |
| 5248 | int nfs4_proc_destroy_session(struct nfs4_session *session) |
| 5249 | { |
| 5250 | int status = 0; |
| 5251 | struct rpc_message msg; |
| 5252 | |
| 5253 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5254 | |
| 5255 | /* session is still being setup */ |
| 5256 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5257 | return status; |
| 5258 | |
| 5259 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; |
| 5260 | msg.rpc_argp = session; |
| 5261 | msg.rpc_resp = NULL; |
| 5262 | msg.rpc_cred = NULL; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5263 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5264 | |
| 5265 | if (status) |
| 5266 | printk(KERN_WARNING |
| 5267 | "Got error %d from the server on DESTROY_SESSION. " |
| 5268 | "Session has been destroyed regardless...\n", status); |
| 5269 | |
| 5270 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5271 | return status; |
| 5272 | } |
| 5273 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5274 | int nfs4_init_session(struct nfs_server *server) |
| 5275 | { |
| 5276 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5277 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5278 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5279 | int ret; |
| 5280 | |
| 5281 | if (!nfs4_has_session(clp)) |
| 5282 | return 0; |
| 5283 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5284 | session = clp->cl_session; |
| 5285 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5286 | return 0; |
| 5287 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5288 | rsize = server->rsize; |
| 5289 | if (rsize == 0) |
| 5290 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5291 | wsize = server->wsize; |
| 5292 | if (wsize == 0) |
| 5293 | wsize = NFS_MAX_FILE_IO_SIZE; |
| 5294 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5295 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5296 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5297 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5298 | ret = nfs4_recover_expired_lease(server); |
| 5299 | if (!ret) |
| 5300 | ret = nfs4_check_client_ready(clp); |
| 5301 | return ret; |
| 5302 | } |
| 5303 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5304 | int nfs4_init_ds_session(struct nfs_client *clp) |
| 5305 | { |
| 5306 | struct nfs4_session *session = clp->cl_session; |
| 5307 | int ret; |
| 5308 | |
| 5309 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5310 | return 0; |
| 5311 | |
| 5312 | ret = nfs4_client_recover_expired_lease(clp); |
| 5313 | if (!ret) |
| 5314 | /* Test for the DS role */ |
| 5315 | if (!is_ds_client(clp)) |
| 5316 | ret = -ENODEV; |
| 5317 | if (!ret) |
| 5318 | ret = nfs4_check_client_ready(clp); |
| 5319 | return ret; |
| 5320 | |
| 5321 | } |
| 5322 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 5323 | |
| 5324 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5325 | /* |
| 5326 | * Renew the cl_session lease. |
| 5327 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5328 | struct nfs4_sequence_data { |
| 5329 | struct nfs_client *clp; |
| 5330 | struct nfs4_sequence_args args; |
| 5331 | struct nfs4_sequence_res res; |
| 5332 | }; |
| 5333 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5334 | static void nfs41_sequence_release(void *data) |
| 5335 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5336 | struct nfs4_sequence_data *calldata = data; |
| 5337 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5338 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5339 | if (atomic_read(&clp->cl_count) > 1) |
| 5340 | nfs4_schedule_state_renewal(clp); |
| 5341 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5342 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5343 | } |
| 5344 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5345 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5346 | { |
| 5347 | switch(task->tk_status) { |
| 5348 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5349 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5350 | return -EAGAIN; |
| 5351 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5352 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5353 | } |
| 5354 | return 0; |
| 5355 | } |
| 5356 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5357 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5358 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5359 | struct nfs4_sequence_data *calldata = data; |
| 5360 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5361 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5362 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5363 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5364 | |
| 5365 | if (task->tk_status < 0) { |
| 5366 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5367 | if (atomic_read(&clp->cl_count) == 1) |
| 5368 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5369 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5370 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5371 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5372 | return; |
| 5373 | } |
| 5374 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5375 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5376 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5377 | dprintk("<-- %s\n", __func__); |
| 5378 | } |
| 5379 | |
| 5380 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5381 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5382 | struct nfs4_sequence_data *calldata = data; |
| 5383 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5384 | struct nfs4_sequence_args *args; |
| 5385 | struct nfs4_sequence_res *res; |
| 5386 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5387 | args = task->tk_msg.rpc_argp; |
| 5388 | res = task->tk_msg.rpc_resp; |
| 5389 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5390 | if (nfs41_setup_sequence(clp->cl_session, args, res, 0, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5391 | return; |
| 5392 | rpc_call_start(task); |
| 5393 | } |
| 5394 | |
| 5395 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5396 | .rpc_call_done = nfs41_sequence_call_done, |
| 5397 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5398 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5399 | }; |
| 5400 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5401 | 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] | 5402 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5403 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5404 | struct rpc_message msg = { |
| 5405 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5406 | .rpc_cred = cred, |
| 5407 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5408 | struct rpc_task_setup task_setup_data = { |
| 5409 | .rpc_client = clp->cl_rpcclient, |
| 5410 | .rpc_message = &msg, |
| 5411 | .callback_ops = &nfs41_sequence_ops, |
| 5412 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5413 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5414 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5415 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5416 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5417 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5418 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5419 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5420 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5421 | } |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5422 | msg.rpc_argp = &calldata->args; |
| 5423 | msg.rpc_resp = &calldata->res; |
| 5424 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5425 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5426 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5427 | return rpc_run_task(&task_setup_data); |
| 5428 | } |
| 5429 | |
| 5430 | static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5431 | { |
| 5432 | struct rpc_task *task; |
| 5433 | int ret = 0; |
| 5434 | |
| 5435 | task = _nfs41_proc_sequence(clp, cred); |
| 5436 | if (IS_ERR(task)) |
| 5437 | ret = PTR_ERR(task); |
| 5438 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5439 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5440 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5441 | return ret; |
| 5442 | } |
| 5443 | |
| 5444 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5445 | { |
| 5446 | struct rpc_task *task; |
| 5447 | int ret; |
| 5448 | |
| 5449 | task = _nfs41_proc_sequence(clp, cred); |
| 5450 | if (IS_ERR(task)) { |
| 5451 | ret = PTR_ERR(task); |
| 5452 | goto out; |
| 5453 | } |
| 5454 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5455 | if (!ret) { |
| 5456 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5457 | |
| 5458 | if (task->tk_status == 0) |
| 5459 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5460 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5461 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5462 | rpc_put_task(task); |
| 5463 | out: |
| 5464 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5465 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5466 | } |
| 5467 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5468 | struct nfs4_reclaim_complete_data { |
| 5469 | struct nfs_client *clp; |
| 5470 | struct nfs41_reclaim_complete_args arg; |
| 5471 | struct nfs41_reclaim_complete_res res; |
| 5472 | }; |
| 5473 | |
| 5474 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5475 | { |
| 5476 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5477 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5478 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5479 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5480 | &calldata->arg.seq_args, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5481 | &calldata->res.seq_res, 0, task)) |
| 5482 | return; |
| 5483 | |
| 5484 | rpc_call_start(task); |
| 5485 | } |
| 5486 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5487 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5488 | { |
| 5489 | switch(task->tk_status) { |
| 5490 | case 0: |
| 5491 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5492 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5493 | break; |
| 5494 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5495 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5496 | /* fall through */ |
| 5497 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5498 | return -EAGAIN; |
| 5499 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5500 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5501 | } |
| 5502 | return 0; |
| 5503 | } |
| 5504 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5505 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5506 | { |
| 5507 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5508 | struct nfs_client *clp = calldata->clp; |
| 5509 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5510 | |
| 5511 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5512 | if (!nfs41_sequence_done(task, res)) |
| 5513 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5514 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5515 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5516 | rpc_restart_call_prepare(task); |
| 5517 | return; |
| 5518 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5519 | dprintk("<-- %s\n", __func__); |
| 5520 | } |
| 5521 | |
| 5522 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5523 | { |
| 5524 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5525 | |
| 5526 | kfree(calldata); |
| 5527 | } |
| 5528 | |
| 5529 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5530 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5531 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5532 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5533 | }; |
| 5534 | |
| 5535 | /* |
| 5536 | * Issue a global reclaim complete. |
| 5537 | */ |
| 5538 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5539 | { |
| 5540 | struct nfs4_reclaim_complete_data *calldata; |
| 5541 | struct rpc_task *task; |
| 5542 | struct rpc_message msg = { |
| 5543 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5544 | }; |
| 5545 | struct rpc_task_setup task_setup_data = { |
| 5546 | .rpc_client = clp->cl_rpcclient, |
| 5547 | .rpc_message = &msg, |
| 5548 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5549 | .flags = RPC_TASK_ASYNC, |
| 5550 | }; |
| 5551 | int status = -ENOMEM; |
| 5552 | |
| 5553 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5554 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5555 | if (calldata == NULL) |
| 5556 | goto out; |
| 5557 | calldata->clp = clp; |
| 5558 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5559 | |
| 5560 | msg.rpc_argp = &calldata->arg; |
| 5561 | msg.rpc_resp = &calldata->res; |
| 5562 | task_setup_data.callback_data = calldata; |
| 5563 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5564 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5565 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5566 | goto out; |
| 5567 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 5568 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5569 | if (status == 0) |
| 5570 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5571 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5572 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5573 | out: |
| 5574 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5575 | return status; |
| 5576 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5577 | |
| 5578 | static void |
| 5579 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 5580 | { |
| 5581 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5582 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5583 | |
| 5584 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5585 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 5586 | * right now covering the LAYOUTGET we are about to send. |
| 5587 | * However, that is not so catastrophic, and there seems |
| 5588 | * to be no way to prevent it completely. |
| 5589 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5590 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
| 5591 | &lgp->res.seq_res, 0, task)) |
| 5592 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5593 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 5594 | NFS_I(lgp->args.inode)->layout, |
| 5595 | lgp->args.ctx->state)) { |
| 5596 | rpc_exit(task, NFS4_OK); |
| 5597 | return; |
| 5598 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5599 | rpc_call_start(task); |
| 5600 | } |
| 5601 | |
| 5602 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 5603 | { |
| 5604 | struct nfs4_layoutget *lgp = calldata; |
| 5605 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5606 | |
| 5607 | dprintk("--> %s\n", __func__); |
| 5608 | |
| 5609 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 5610 | return; |
| 5611 | |
| 5612 | switch (task->tk_status) { |
| 5613 | case 0: |
| 5614 | break; |
| 5615 | case -NFS4ERR_LAYOUTTRYLATER: |
| 5616 | case -NFS4ERR_RECALLCONFLICT: |
| 5617 | task->tk_status = -NFS4ERR_DELAY; |
| 5618 | /* Fall through */ |
| 5619 | default: |
| 5620 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5621 | rpc_restart_call_prepare(task); |
| 5622 | return; |
| 5623 | } |
| 5624 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5625 | dprintk("<-- %s\n", __func__); |
| 5626 | } |
| 5627 | |
| 5628 | static void nfs4_layoutget_release(void *calldata) |
| 5629 | { |
| 5630 | struct nfs4_layoutget *lgp = calldata; |
| 5631 | |
| 5632 | dprintk("--> %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5633 | put_nfs_open_context(lgp->args.ctx); |
| 5634 | kfree(calldata); |
| 5635 | dprintk("<-- %s\n", __func__); |
| 5636 | } |
| 5637 | |
| 5638 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 5639 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 5640 | .rpc_call_done = nfs4_layoutget_done, |
| 5641 | .rpc_release = nfs4_layoutget_release, |
| 5642 | }; |
| 5643 | |
| 5644 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) |
| 5645 | { |
| 5646 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5647 | struct rpc_task *task; |
| 5648 | struct rpc_message msg = { |
| 5649 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 5650 | .rpc_argp = &lgp->args, |
| 5651 | .rpc_resp = &lgp->res, |
| 5652 | }; |
| 5653 | struct rpc_task_setup task_setup_data = { |
| 5654 | .rpc_client = server->client, |
| 5655 | .rpc_message = &msg, |
| 5656 | .callback_ops = &nfs4_layoutget_call_ops, |
| 5657 | .callback_data = lgp, |
| 5658 | .flags = RPC_TASK_ASYNC, |
| 5659 | }; |
| 5660 | int status = 0; |
| 5661 | |
| 5662 | dprintk("--> %s\n", __func__); |
| 5663 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 5664 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5665 | lgp->res.seq_res.sr_slot = NULL; |
| 5666 | task = rpc_run_task(&task_setup_data); |
| 5667 | if (IS_ERR(task)) |
| 5668 | return PTR_ERR(task); |
| 5669 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5670 | if (status == 0) |
| 5671 | status = task->tk_status; |
| 5672 | if (status == 0) |
| 5673 | status = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5674 | rpc_put_task(task); |
| 5675 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5676 | return status; |
| 5677 | } |
| 5678 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5679 | static void |
| 5680 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 5681 | { |
| 5682 | struct nfs4_layoutreturn *lrp = calldata; |
| 5683 | |
| 5684 | dprintk("--> %s\n", __func__); |
| 5685 | if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, |
| 5686 | &lrp->res.seq_res, 0, task)) |
| 5687 | return; |
| 5688 | rpc_call_start(task); |
| 5689 | } |
| 5690 | |
| 5691 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 5692 | { |
| 5693 | struct nfs4_layoutreturn *lrp = calldata; |
| 5694 | struct nfs_server *server; |
| 5695 | |
| 5696 | dprintk("--> %s\n", __func__); |
| 5697 | |
| 5698 | if (!nfs4_sequence_done(task, &lrp->res.seq_res)) |
| 5699 | return; |
| 5700 | |
| 5701 | server = NFS_SERVER(lrp->args.inode); |
| 5702 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5703 | nfs_restart_rpc(task, lrp->clp); |
| 5704 | return; |
| 5705 | } |
| 5706 | if (task->tk_status == 0) { |
| 5707 | struct pnfs_layout_hdr *lo = NFS_I(lrp->args.inode)->layout; |
| 5708 | |
| 5709 | if (lrp->res.lrs_present) { |
| 5710 | spin_lock(&lo->plh_inode->i_lock); |
| 5711 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 5712 | spin_unlock(&lo->plh_inode->i_lock); |
| 5713 | } else |
| 5714 | BUG_ON(!list_empty(&lo->plh_segs)); |
| 5715 | } |
| 5716 | dprintk("<-- %s\n", __func__); |
| 5717 | } |
| 5718 | |
| 5719 | static void nfs4_layoutreturn_release(void *calldata) |
| 5720 | { |
| 5721 | struct nfs4_layoutreturn *lrp = calldata; |
| 5722 | |
| 5723 | dprintk("--> %s\n", __func__); |
| 5724 | put_layout_hdr(NFS_I(lrp->args.inode)->layout); |
| 5725 | kfree(calldata); |
| 5726 | dprintk("<-- %s\n", __func__); |
| 5727 | } |
| 5728 | |
| 5729 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 5730 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 5731 | .rpc_call_done = nfs4_layoutreturn_done, |
| 5732 | .rpc_release = nfs4_layoutreturn_release, |
| 5733 | }; |
| 5734 | |
| 5735 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 5736 | { |
| 5737 | struct rpc_task *task; |
| 5738 | struct rpc_message msg = { |
| 5739 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 5740 | .rpc_argp = &lrp->args, |
| 5741 | .rpc_resp = &lrp->res, |
| 5742 | }; |
| 5743 | struct rpc_task_setup task_setup_data = { |
| 5744 | .rpc_client = lrp->clp->cl_rpcclient, |
| 5745 | .rpc_message = &msg, |
| 5746 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 5747 | .callback_data = lrp, |
| 5748 | }; |
| 5749 | int status; |
| 5750 | |
| 5751 | dprintk("--> %s\n", __func__); |
| 5752 | task = rpc_run_task(&task_setup_data); |
| 5753 | if (IS_ERR(task)) |
| 5754 | return PTR_ERR(task); |
| 5755 | status = task->tk_status; |
| 5756 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5757 | rpc_put_task(task); |
| 5758 | return status; |
| 5759 | } |
| 5760 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5761 | static int |
| 5762 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5763 | { |
| 5764 | struct nfs4_getdeviceinfo_args args = { |
| 5765 | .pdev = pdev, |
| 5766 | }; |
| 5767 | struct nfs4_getdeviceinfo_res res = { |
| 5768 | .pdev = pdev, |
| 5769 | }; |
| 5770 | struct rpc_message msg = { |
| 5771 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 5772 | .rpc_argp = &args, |
| 5773 | .rpc_resp = &res, |
| 5774 | }; |
| 5775 | int status; |
| 5776 | |
| 5777 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5778 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5779 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5780 | |
| 5781 | return status; |
| 5782 | } |
| 5783 | |
| 5784 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5785 | { |
| 5786 | struct nfs4_exception exception = { }; |
| 5787 | int err; |
| 5788 | |
| 5789 | do { |
| 5790 | err = nfs4_handle_exception(server, |
| 5791 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 5792 | &exception); |
| 5793 | } while (exception.retry); |
| 5794 | return err; |
| 5795 | } |
| 5796 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 5797 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5798 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 5799 | { |
| 5800 | struct nfs4_layoutcommit_data *data = calldata; |
| 5801 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 5802 | |
| 5803 | if (nfs4_setup_sequence(server, &data->args.seq_args, |
| 5804 | &data->res.seq_res, 1, task)) |
| 5805 | return; |
| 5806 | rpc_call_start(task); |
| 5807 | } |
| 5808 | |
| 5809 | static void |
| 5810 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 5811 | { |
| 5812 | struct nfs4_layoutcommit_data *data = calldata; |
| 5813 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 5814 | |
| 5815 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5816 | return; |
| 5817 | |
| 5818 | switch (task->tk_status) { /* Just ignore these failures */ |
| 5819 | case NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 5820 | case NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 5821 | case NFS4ERR_BADLAYOUT: /* no layout */ |
| 5822 | case NFS4ERR_GRACE: /* loca_recalim always false */ |
| 5823 | task->tk_status = 0; |
| 5824 | } |
| 5825 | |
| 5826 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5827 | nfs_restart_rpc(task, server->nfs_client); |
| 5828 | return; |
| 5829 | } |
| 5830 | |
| 5831 | if (task->tk_status == 0) |
| 5832 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 5833 | data->res.fattr); |
| 5834 | } |
| 5835 | |
| 5836 | static void nfs4_layoutcommit_release(void *calldata) |
| 5837 | { |
| 5838 | struct nfs4_layoutcommit_data *data = calldata; |
| 5839 | |
| 5840 | /* Matched by references in pnfs_set_layoutcommit */ |
| 5841 | put_lseg(data->lseg); |
| 5842 | put_rpccred(data->cred); |
| 5843 | kfree(data); |
| 5844 | } |
| 5845 | |
| 5846 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 5847 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 5848 | .rpc_call_done = nfs4_layoutcommit_done, |
| 5849 | .rpc_release = nfs4_layoutcommit_release, |
| 5850 | }; |
| 5851 | |
| 5852 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 5853 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5854 | { |
| 5855 | struct rpc_message msg = { |
| 5856 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 5857 | .rpc_argp = &data->args, |
| 5858 | .rpc_resp = &data->res, |
| 5859 | .rpc_cred = data->cred, |
| 5860 | }; |
| 5861 | struct rpc_task_setup task_setup_data = { |
| 5862 | .task = &data->task, |
| 5863 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 5864 | .rpc_message = &msg, |
| 5865 | .callback_ops = &nfs4_layoutcommit_ops, |
| 5866 | .callback_data = data, |
| 5867 | .flags = RPC_TASK_ASYNC, |
| 5868 | }; |
| 5869 | struct rpc_task *task; |
| 5870 | int status = 0; |
| 5871 | |
| 5872 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 5873 | "lbw: %llu inode %lu\n", |
| 5874 | data->task.tk_pid, sync, |
| 5875 | data->args.lastbytewritten, |
| 5876 | data->args.inode->i_ino); |
| 5877 | |
| 5878 | task = rpc_run_task(&task_setup_data); |
| 5879 | if (IS_ERR(task)) |
| 5880 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 5881 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5882 | goto out; |
| 5883 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5884 | if (status != 0) |
| 5885 | goto out; |
| 5886 | status = task->tk_status; |
| 5887 | out: |
| 5888 | dprintk("%s: status %d\n", __func__, status); |
| 5889 | rpc_put_task(task); |
| 5890 | return status; |
| 5891 | } |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5892 | #endif /* CONFIG_NFS_V4_1 */ |
| 5893 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5894 | struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5895 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5896 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5897 | .recover_open = nfs4_open_reclaim, |
| 5898 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5899 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5900 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5901 | }; |
| 5902 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5903 | #if defined(CONFIG_NFS_V4_1) |
| 5904 | struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
| 5905 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 5906 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 5907 | .recover_open = nfs4_open_reclaim, |
| 5908 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5909 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5910 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5911 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5912 | }; |
| 5913 | #endif /* CONFIG_NFS_V4_1 */ |
| 5914 | |
| 5915 | struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5916 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5917 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5918 | .recover_open = nfs4_open_expired, |
| 5919 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5920 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5921 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5922 | }; |
| 5923 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5924 | #if defined(CONFIG_NFS_V4_1) |
| 5925 | struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
| 5926 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 5927 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
| 5928 | .recover_open = nfs4_open_expired, |
| 5929 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5930 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5931 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5932 | }; |
| 5933 | #endif /* CONFIG_NFS_V4_1 */ |
| 5934 | |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5935 | struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
| 5936 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5937 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5938 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5939 | }; |
| 5940 | |
| 5941 | #if defined(CONFIG_NFS_V4_1) |
| 5942 | struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
| 5943 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5944 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5945 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5946 | }; |
| 5947 | #endif |
| 5948 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5949 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 5950 | .minor_version = 0, |
| 5951 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5952 | .validate_stateid = nfs4_validate_delegation_stateid, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5953 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 5954 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 5955 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5956 | }; |
| 5957 | |
| 5958 | #if defined(CONFIG_NFS_V4_1) |
| 5959 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 5960 | .minor_version = 1, |
| 5961 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5962 | .validate_stateid = nfs41_validate_delegation_stateid, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5963 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 5964 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 5965 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5966 | }; |
| 5967 | #endif |
| 5968 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5969 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 5970 | [0] = &nfs_v4_0_minor_ops, |
| 5971 | #if defined(CONFIG_NFS_V4_1) |
| 5972 | [1] = &nfs_v4_1_minor_ops, |
| 5973 | #endif |
| 5974 | }; |
| 5975 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 5976 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5977 | .permission = nfs_permission, |
| 5978 | .getattr = nfs_getattr, |
| 5979 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5980 | .getxattr = generic_getxattr, |
| 5981 | .setxattr = generic_setxattr, |
| 5982 | .listxattr = generic_listxattr, |
| 5983 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5984 | }; |
| 5985 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 5986 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5987 | .version = 4, /* protocol version */ |
| 5988 | .dentry_ops = &nfs4_dentry_operations, |
| 5989 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5990 | .file_inode_ops = &nfs4_file_inode_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5991 | .getroot = nfs4_proc_get_root, |
| 5992 | .getattr = nfs4_proc_getattr, |
| 5993 | .setattr = nfs4_proc_setattr, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5994 | .lookupfh = nfs4_proc_lookupfh, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5995 | .lookup = nfs4_proc_lookup, |
| 5996 | .access = nfs4_proc_access, |
| 5997 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5998 | .create = nfs4_proc_create, |
| 5999 | .remove = nfs4_proc_remove, |
| 6000 | .unlink_setup = nfs4_proc_unlink_setup, |
| 6001 | .unlink_done = nfs4_proc_unlink_done, |
| 6002 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6003 | .rename_setup = nfs4_proc_rename_setup, |
| 6004 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6005 | .link = nfs4_proc_link, |
| 6006 | .symlink = nfs4_proc_symlink, |
| 6007 | .mkdir = nfs4_proc_mkdir, |
| 6008 | .rmdir = nfs4_proc_remove, |
| 6009 | .readdir = nfs4_proc_readdir, |
| 6010 | .mknod = nfs4_proc_mknod, |
| 6011 | .statfs = nfs4_proc_statfs, |
| 6012 | .fsinfo = nfs4_proc_fsinfo, |
| 6013 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6014 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6015 | .decode_dirent = nfs4_decode_dirent, |
| 6016 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6017 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6018 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6019 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6020 | .commit_setup = nfs4_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6021 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6022 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6023 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6024 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6025 | .open_context = nfs4_atomic_open, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6026 | .init_client = nfs4_init_client, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6027 | .secinfo = nfs4_proc_secinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6028 | }; |
| 6029 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6030 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6031 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6032 | .list = nfs4_xattr_list_nfs4_acl, |
| 6033 | .get = nfs4_xattr_get_nfs4_acl, |
| 6034 | .set = nfs4_xattr_set_nfs4_acl, |
| 6035 | }; |
| 6036 | |
| 6037 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6038 | &nfs4_xattr_nfs4_acl_handler, |
| 6039 | NULL |
| 6040 | }; |
| 6041 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6042 | /* |
| 6043 | * Local variables: |
| 6044 | * c-basic-offset: 8 |
| 6045 | * End: |
| 6046 | */ |