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); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 83 | #ifdef CONFIG_NFS_V4_1 |
| 84 | static int nfs41_test_stateid(struct nfs_server *, struct nfs4_state *); |
| 85 | static int nfs41_free_stateid(struct nfs_server *, struct nfs4_state *); |
| 86 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 88 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 90 | if (err >= -1000) |
| 91 | return err; |
| 92 | switch (err) { |
| 93 | case -NFS4ERR_RESOURCE: |
| 94 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 95 | case -NFS4ERR_WRONGSEC: |
| 96 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 97 | case -NFS4ERR_BADOWNER: |
| 98 | case -NFS4ERR_BADNAME: |
| 99 | return -EINVAL; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 100 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 102 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 103 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 105 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /* |
| 109 | * This is our standard bitmap for GETATTR requests. |
| 110 | */ |
| 111 | const u32 nfs4_fattr_bitmap[2] = { |
| 112 | FATTR4_WORD0_TYPE |
| 113 | | FATTR4_WORD0_CHANGE |
| 114 | | FATTR4_WORD0_SIZE |
| 115 | | FATTR4_WORD0_FSID |
| 116 | | FATTR4_WORD0_FILEID, |
| 117 | FATTR4_WORD1_MODE |
| 118 | | FATTR4_WORD1_NUMLINKS |
| 119 | | FATTR4_WORD1_OWNER |
| 120 | | FATTR4_WORD1_OWNER_GROUP |
| 121 | | FATTR4_WORD1_RAWDEV |
| 122 | | FATTR4_WORD1_SPACE_USED |
| 123 | | FATTR4_WORD1_TIME_ACCESS |
| 124 | | FATTR4_WORD1_TIME_METADATA |
| 125 | | FATTR4_WORD1_TIME_MODIFY |
| 126 | }; |
| 127 | |
| 128 | const u32 nfs4_statfs_bitmap[2] = { |
| 129 | FATTR4_WORD0_FILES_AVAIL |
| 130 | | FATTR4_WORD0_FILES_FREE |
| 131 | | FATTR4_WORD0_FILES_TOTAL, |
| 132 | FATTR4_WORD1_SPACE_AVAIL |
| 133 | | FATTR4_WORD1_SPACE_FREE |
| 134 | | FATTR4_WORD1_SPACE_TOTAL |
| 135 | }; |
| 136 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 137 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | FATTR4_WORD0_MAXLINK |
| 139 | | FATTR4_WORD0_MAXNAME, |
| 140 | 0 |
| 141 | }; |
| 142 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 143 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | | FATTR4_WORD0_MAXREAD |
| 145 | | FATTR4_WORD0_MAXWRITE |
| 146 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 147 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 148 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 149 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | }; |
| 151 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 152 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 153 | FATTR4_WORD0_TYPE |
| 154 | | FATTR4_WORD0_CHANGE |
| 155 | | FATTR4_WORD0_SIZE |
| 156 | | FATTR4_WORD0_FSID |
| 157 | | FATTR4_WORD0_FILEID |
| 158 | | FATTR4_WORD0_FS_LOCATIONS, |
| 159 | FATTR4_WORD1_MODE |
| 160 | | FATTR4_WORD1_NUMLINKS |
| 161 | | FATTR4_WORD1_OWNER |
| 162 | | FATTR4_WORD1_OWNER_GROUP |
| 163 | | FATTR4_WORD1_RAWDEV |
| 164 | | FATTR4_WORD1_SPACE_USED |
| 165 | | FATTR4_WORD1_TIME_ACCESS |
| 166 | | FATTR4_WORD1_TIME_METADATA |
| 167 | | FATTR4_WORD1_TIME_MODIFY |
| 168 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 169 | }; |
| 170 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 171 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | struct nfs4_readdir_arg *readdir) |
| 173 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 174 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
| 176 | BUG_ON(readdir->count < 80); |
| 177 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 178 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 180 | return; |
| 181 | } |
| 182 | |
| 183 | readdir->cookie = 0; |
| 184 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 185 | if (cookie == 2) |
| 186 | return; |
| 187 | |
| 188 | /* |
| 189 | * NFSv4 servers do not return entries for '.' and '..' |
| 190 | * Therefore, we fake these entries here. We let '.' |
| 191 | * have cookie 0 and '..' have cookie 1. Note that |
| 192 | * when talking to the server, we always send cookie 0 |
| 193 | * instead of 1 or 2. |
| 194 | */ |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 195 | start = p = kmap_atomic(*readdir->pages, KM_USER0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
| 197 | if (cookie == 0) { |
| 198 | *p++ = xdr_one; /* next */ |
| 199 | *p++ = xdr_zero; /* cookie, first word */ |
| 200 | *p++ = xdr_one; /* cookie, second word */ |
| 201 | *p++ = xdr_one; /* entry len */ |
| 202 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 203 | p++; |
| 204 | *p++ = xdr_one; /* bitmap length */ |
| 205 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 206 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 207 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | *p++ = xdr_one; /* next */ |
| 211 | *p++ = xdr_zero; /* cookie, first word */ |
| 212 | *p++ = xdr_two; /* cookie, second word */ |
| 213 | *p++ = xdr_two; /* entry len */ |
| 214 | memcpy(p, "..\0\0", 4); /* entry */ |
| 215 | p++; |
| 216 | *p++ = xdr_one; /* bitmap length */ |
| 217 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 218 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 219 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
| 221 | readdir->pgbase = (char *)p - (char *)start; |
| 222 | readdir->count -= readdir->pgbase; |
| 223 | kunmap_atomic(start, KM_USER0); |
| 224 | } |
| 225 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 226 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 227 | { |
| 228 | int res; |
| 229 | |
| 230 | might_sleep(); |
| 231 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 232 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 233 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 234 | return res; |
| 235 | } |
| 236 | |
| 237 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 238 | { |
| 239 | int res = 0; |
| 240 | |
| 241 | might_sleep(); |
| 242 | |
| 243 | if (*timeout <= 0) |
| 244 | *timeout = NFS4_POLL_RETRY_MIN; |
| 245 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 246 | *timeout = NFS4_POLL_RETRY_MAX; |
| 247 | schedule_timeout_killable(*timeout); |
| 248 | if (fatal_signal_pending(current)) |
| 249 | res = -ERESTARTSYS; |
| 250 | *timeout <<= 1; |
| 251 | return res; |
| 252 | } |
| 253 | |
| 254 | /* This is the error handling routine for processes that are allowed |
| 255 | * to sleep. |
| 256 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 257 | 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] | 258 | { |
| 259 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 260 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 261 | int ret = errorcode; |
| 262 | |
| 263 | exception->retry = 0; |
| 264 | switch(errorcode) { |
| 265 | case 0: |
| 266 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 267 | case -NFS4ERR_ADMIN_REVOKED: |
| 268 | case -NFS4ERR_BAD_STATEID: |
| 269 | case -NFS4ERR_OPENMODE: |
| 270 | if (state == NULL) |
| 271 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 272 | nfs4_schedule_stateid_recovery(server, state); |
| 273 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 274 | case -NFS4ERR_EXPIRED: |
| 275 | if (state != NULL) |
| 276 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 277 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 278 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 279 | nfs4_schedule_lease_recovery(clp); |
| 280 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 281 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 282 | case -NFS4ERR_BADSESSION: |
| 283 | case -NFS4ERR_BADSLOT: |
| 284 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 285 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 286 | case -NFS4ERR_DEADSESSION: |
| 287 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 288 | case -NFS4ERR_SEQ_MISORDERED: |
| 289 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 290 | errorcode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 291 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 292 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 293 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 294 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 295 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 296 | if (exception->timeout > HZ) { |
| 297 | /* We have retried a decent amount, time to |
| 298 | * fail |
| 299 | */ |
| 300 | ret = -EBUSY; |
| 301 | break; |
| 302 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 303 | case -NFS4ERR_GRACE: |
| 304 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 305 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 306 | ret = nfs4_delay(server->client, &exception->timeout); |
| 307 | if (ret != 0) |
| 308 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 309 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 310 | case -NFS4ERR_OLD_STATEID: |
| 311 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 312 | break; |
| 313 | case -NFS4ERR_BADOWNER: |
| 314 | /* The following works around a Linux server bug! */ |
| 315 | case -NFS4ERR_BADNAME: |
| 316 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 317 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 318 | exception->retry = 1; |
| 319 | printk(KERN_WARNING "NFS: v4 server %s " |
| 320 | "does not accept raw " |
| 321 | "uid/gids. " |
| 322 | "Reenabling the idmapper.\n", |
| 323 | server->nfs_client->cl_hostname); |
| 324 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 325 | } |
| 326 | /* We failed to handle the error */ |
| 327 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 328 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 329 | ret = nfs4_wait_clnt_recover(clp); |
| 330 | if (ret == 0) |
| 331 | exception->retry = 1; |
| 332 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 336 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | spin_lock(&clp->cl_lock); |
| 339 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 340 | clp->cl_last_renewal = timestamp; |
| 341 | spin_unlock(&clp->cl_lock); |
| 342 | } |
| 343 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 344 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 345 | { |
| 346 | do_renew_lease(server->nfs_client, timestamp); |
| 347 | } |
| 348 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 349 | #if defined(CONFIG_NFS_V4_1) |
| 350 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 351 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 352 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 353 | * |
| 354 | * freeing a slot is trivially done by clearing its respective bit |
| 355 | * in the bitmap. |
| 356 | * If the freed slotid equals highest_used_slotid we want to update it |
| 357 | * so that the server would be able to size down the slot table if needed, |
| 358 | * otherwise we know that the highest_used_slotid is still in use. |
| 359 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 360 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 361 | * highest slotid in use. |
| 362 | * If none found, highest_used_slotid is set to -1. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 363 | * |
| 364 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 365 | */ |
| 366 | static void |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 367 | 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] | 368 | { |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 369 | int free_slotid = free_slot - tbl->slots; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 370 | int slotid = free_slotid; |
| 371 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 372 | BUG_ON(slotid < 0 || slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 373 | /* clear used bit in bitmap */ |
| 374 | __clear_bit(slotid, tbl->used_slots); |
| 375 | |
| 376 | /* update highest_used_slotid when it is freed */ |
| 377 | if (slotid == tbl->highest_used_slotid) { |
| 378 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 379 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 380 | tbl->highest_used_slotid = slotid; |
| 381 | else |
| 382 | tbl->highest_used_slotid = -1; |
| 383 | } |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 384 | dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__, |
| 385 | free_slotid, tbl->highest_used_slotid); |
| 386 | } |
| 387 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 388 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 389 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 390 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 391 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 392 | { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 393 | struct rpc_task *task; |
| 394 | |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 395 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 396 | task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq); |
| 397 | if (task) |
| 398 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 399 | return; |
| 400 | } |
| 401 | |
| 402 | if (ses->fc_slot_table.highest_used_slotid != -1) |
| 403 | return; |
| 404 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 405 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 406 | complete(&ses->fc_slot_table.complete); |
| 407 | } |
| 408 | |
| 409 | /* |
| 410 | * Signal state manager thread if session back channel is drained |
| 411 | */ |
| 412 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 413 | { |
| 414 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
| 415 | ses->bc_slot_table.highest_used_slotid != -1) |
| 416 | return; |
| 417 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 418 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 419 | } |
| 420 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 421 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 422 | { |
| 423 | struct nfs4_slot_table *tbl; |
| 424 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 425 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 426 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 427 | /* just wake up the next guy waiting since |
| 428 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 429 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 430 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 431 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 432 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 433 | spin_lock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 434 | nfs4_free_slot(tbl, res->sr_slot); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 435 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 436 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 437 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 438 | } |
| 439 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 440 | 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] | 441 | { |
| 442 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 443 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 444 | |
| 445 | /* |
| 446 | * sr_status remains 1 if an RPC level error occurred. The server |
| 447 | * may or may not have processed the sequence operation.. |
| 448 | * Proceed as if the server received and processed the sequence |
| 449 | * operation. |
| 450 | */ |
| 451 | if (res->sr_status == 1) |
| 452 | res->sr_status = NFS_OK; |
| 453 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 454 | /* don't increment the sequence number if the task wasn't sent */ |
| 455 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 456 | goto out; |
| 457 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 458 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 459 | switch (res->sr_status) { |
| 460 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 461 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 462 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 463 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 464 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 465 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 466 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 467 | if (res->sr_status_flags != 0) |
| 468 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 469 | break; |
| 470 | case -NFS4ERR_DELAY: |
| 471 | /* The server detected a resend of the RPC call and |
| 472 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 473 | * of RFC5661. |
| 474 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 475 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 476 | __func__, |
| 477 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 478 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 479 | goto out_retry; |
| 480 | default: |
| 481 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 482 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 483 | } |
| 484 | out: |
| 485 | /* The session may be reset by one of the error handlers. */ |
| 486 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 487 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 488 | return 1; |
| 489 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 490 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 491 | goto out; |
| 492 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 493 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 494 | } |
| 495 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 496 | static int nfs4_sequence_done(struct rpc_task *task, |
| 497 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 498 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 499 | if (res->sr_session == NULL) |
| 500 | return 1; |
| 501 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 502 | } |
| 503 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 504 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 505 | * nfs4_find_slot - efficiently look for a free slot |
| 506 | * |
| 507 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 508 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 509 | * and respectively set up the sequence operation args. |
| 510 | * 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] | 511 | * |
| 512 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 513 | */ |
| 514 | static u8 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 515 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 516 | { |
| 517 | int slotid; |
| 518 | u8 ret_id = NFS4_MAX_SLOT_TABLE; |
| 519 | BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE); |
| 520 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 521 | dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n", |
| 522 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 523 | tbl->max_slots); |
| 524 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 525 | if (slotid >= tbl->max_slots) |
| 526 | goto out; |
| 527 | __set_bit(slotid, tbl->used_slots); |
| 528 | if (slotid > tbl->highest_used_slotid) |
| 529 | tbl->highest_used_slotid = slotid; |
| 530 | ret_id = slotid; |
| 531 | out: |
| 532 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 533 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 534 | return ret_id; |
| 535 | } |
| 536 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 537 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 538 | struct nfs4_sequence_args *args, |
| 539 | struct nfs4_sequence_res *res, |
| 540 | int cache_reply, |
| 541 | struct rpc_task *task) |
| 542 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 543 | struct nfs4_slot *slot; |
| 544 | struct nfs4_slot_table *tbl; |
| 545 | u8 slotid; |
| 546 | |
| 547 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 548 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 549 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 550 | return 0; |
| 551 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 552 | tbl = &session->fc_slot_table; |
| 553 | |
| 554 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 555 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 556 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 557 | /* |
| 558 | * The state manager will wait until the slot table is empty. |
| 559 | * Schedule the reset thread |
| 560 | */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 561 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 562 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 563 | dprintk("%s Schedule Session Reset\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 564 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 565 | } |
| 566 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 567 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 568 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 569 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 570 | spin_unlock(&tbl->slot_tbl_lock); |
| 571 | dprintk("%s enforce FIFO order\n", __func__); |
| 572 | return -EAGAIN; |
| 573 | } |
| 574 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 575 | slotid = nfs4_find_slot(tbl); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 576 | if (slotid == NFS4_MAX_SLOT_TABLE) { |
| 577 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 578 | spin_unlock(&tbl->slot_tbl_lock); |
| 579 | dprintk("<-- %s: no free slots\n", __func__); |
| 580 | return -EAGAIN; |
| 581 | } |
| 582 | spin_unlock(&tbl->slot_tbl_lock); |
| 583 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 584 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 585 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 586 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 587 | args->sa_slotid = slotid; |
| 588 | args->sa_cache_this = cache_reply; |
| 589 | |
| 590 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 591 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 592 | res->sr_session = session; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 593 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 594 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 595 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 596 | /* |
| 597 | * sr_status is only set in decode_sequence, and so will remain |
| 598 | * set to 1 if an rpc level failure occurs. |
| 599 | */ |
| 600 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 601 | return 0; |
| 602 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 603 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 604 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 605 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 606 | struct nfs4_sequence_args *args, |
| 607 | struct nfs4_sequence_res *res, |
| 608 | int cache_reply, |
| 609 | struct rpc_task *task) |
| 610 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 611 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 612 | int ret = 0; |
| 613 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 614 | if (session == NULL) { |
| 615 | args->sa_session = NULL; |
| 616 | res->sr_session = NULL; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 617 | goto out; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 618 | } |
| 619 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 620 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 621 | __func__, session->clp, session, res->sr_slot ? |
| 622 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 623 | |
| 624 | ret = nfs41_setup_sequence(session, args, res, cache_reply, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 625 | task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 626 | out: |
| 627 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 628 | return ret; |
| 629 | } |
| 630 | |
| 631 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 632 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 633 | struct nfs4_sequence_args *seq_args; |
| 634 | struct nfs4_sequence_res *seq_res; |
| 635 | int cache_reply; |
| 636 | }; |
| 637 | |
| 638 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 639 | { |
| 640 | struct nfs41_call_sync_data *data = calldata; |
| 641 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 642 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 643 | |
| 644 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 645 | data->seq_res, data->cache_reply, task)) |
| 646 | return; |
| 647 | rpc_call_start(task); |
| 648 | } |
| 649 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 650 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 651 | { |
| 652 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 653 | nfs41_call_sync_prepare(task, calldata); |
| 654 | } |
| 655 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 656 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 657 | { |
| 658 | struct nfs41_call_sync_data *data = calldata; |
| 659 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 660 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 661 | } |
| 662 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 663 | struct rpc_call_ops nfs41_call_sync_ops = { |
| 664 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 665 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 666 | }; |
| 667 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 668 | struct rpc_call_ops nfs41_call_priv_sync_ops = { |
| 669 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 670 | .rpc_call_done = nfs41_call_sync_done, |
| 671 | }; |
| 672 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 673 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 674 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 675 | struct rpc_message *msg, |
| 676 | struct nfs4_sequence_args *args, |
| 677 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 678 | int cache_reply, |
| 679 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 680 | { |
| 681 | int ret; |
| 682 | struct rpc_task *task; |
| 683 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 684 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 685 | .seq_args = args, |
| 686 | .seq_res = res, |
| 687 | .cache_reply = cache_reply, |
| 688 | }; |
| 689 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 690 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 691 | .rpc_message = msg, |
| 692 | .callback_ops = &nfs41_call_sync_ops, |
| 693 | .callback_data = &data |
| 694 | }; |
| 695 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 696 | res->sr_slot = NULL; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 697 | if (privileged) |
| 698 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 699 | task = rpc_run_task(&task_setup); |
| 700 | if (IS_ERR(task)) |
| 701 | ret = PTR_ERR(task); |
| 702 | else { |
| 703 | ret = task->tk_status; |
| 704 | rpc_put_task(task); |
| 705 | } |
| 706 | return ret; |
| 707 | } |
| 708 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 709 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 710 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 711 | struct rpc_message *msg, |
| 712 | struct nfs4_sequence_args *args, |
| 713 | struct nfs4_sequence_res *res, |
| 714 | int cache_reply) |
| 715 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 716 | 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] | 717 | } |
| 718 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 719 | #else |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 720 | static int nfs4_sequence_done(struct rpc_task *task, |
| 721 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 722 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 723 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 724 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 725 | #endif /* CONFIG_NFS_V4_1 */ |
| 726 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 727 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 728 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 729 | struct rpc_message *msg, |
| 730 | struct nfs4_sequence_args *args, |
| 731 | struct nfs4_sequence_res *res, |
| 732 | int cache_reply) |
| 733 | { |
Benny Halevy | f375297 | 2009-04-01 09:22:04 -0400 | [diff] [blame] | 734 | args->sa_session = res->sr_session = NULL; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 735 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 736 | } |
| 737 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 738 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 739 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 740 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 741 | struct rpc_message *msg, |
| 742 | struct nfs4_sequence_args *args, |
| 743 | struct nfs4_sequence_res *res, |
| 744 | int cache_reply) |
| 745 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 746 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 747 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 748 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 749 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 750 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 752 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 754 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 755 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA; |
| 756 | if (!cinfo->atomic || cinfo->before != nfsi->change_attr) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 757 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 758 | nfsi->change_attr = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 759 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | } |
| 761 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 762 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 763 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 764 | struct nfs_openargs o_arg; |
| 765 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 766 | struct nfs_open_confirmargs c_arg; |
| 767 | struct nfs_open_confirmres c_res; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 768 | struct nfs_fattr f_attr; |
| 769 | struct nfs_fattr dir_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 770 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 771 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 772 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 773 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 774 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 775 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 776 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 777 | int rpc_status; |
| 778 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 779 | }; |
| 780 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 781 | |
| 782 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 783 | { |
| 784 | p->o_res.f_attr = &p->f_attr; |
| 785 | p->o_res.dir_attr = &p->dir_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 786 | p->o_res.seqid = p->o_arg.seqid; |
| 787 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 788 | p->o_res.server = p->o_arg.server; |
| 789 | nfs_fattr_init(&p->f_attr); |
| 790 | nfs_fattr_init(&p->dir_attr); |
| 791 | } |
| 792 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 793 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 794 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 795 | const struct iattr *attrs, |
| 796 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 797 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 798 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 799 | struct inode *dir = parent->d_inode; |
| 800 | struct nfs_server *server = NFS_SERVER(dir); |
| 801 | struct nfs4_opendata *p; |
| 802 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 803 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 804 | if (p == NULL) |
| 805 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 806 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 807 | if (p->o_arg.seqid == NULL) |
| 808 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 809 | nfs_sb_active(dentry->d_sb); |
| 810 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 811 | p->dir = parent; |
| 812 | p->owner = sp; |
| 813 | atomic_inc(&sp->so_count); |
| 814 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 815 | p->o_arg.open_flags = flags; |
| 816 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 817 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 818 | p->o_arg.id = sp->so_owner_id.id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 819 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 820 | p->o_arg.server = server; |
| 821 | p->o_arg.bitmask = server->attr_bitmask; |
| 822 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 823 | if (flags & O_CREAT) { |
| 824 | u32 *s; |
| 825 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 826 | p->o_arg.u.attrs = &p->attrs; |
| 827 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 828 | s = (u32 *) p->o_arg.u.verifier.data; |
| 829 | s[0] = jiffies; |
| 830 | s[1] = current->pid; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 831 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 832 | p->c_arg.fh = &p->o_res.fh; |
| 833 | p->c_arg.stateid = &p->o_res.stateid; |
| 834 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 835 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 836 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 837 | return p; |
| 838 | err_free: |
| 839 | kfree(p); |
| 840 | err: |
| 841 | dput(parent); |
| 842 | return NULL; |
| 843 | } |
| 844 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 845 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 846 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 847 | struct nfs4_opendata *p = container_of(kref, |
| 848 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 849 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 850 | |
| 851 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 852 | if (p->state != NULL) |
| 853 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 854 | nfs4_put_state_owner(p->owner); |
| 855 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 856 | dput(p->dentry); |
| 857 | nfs_sb_deactive(sb); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 858 | kfree(p); |
| 859 | } |
| 860 | |
| 861 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 862 | { |
| 863 | if (p != NULL) |
| 864 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 865 | } |
| 866 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 867 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 868 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 869 | int ret; |
| 870 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 871 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 872 | return ret; |
| 873 | } |
| 874 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 875 | 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] | 876 | { |
| 877 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 878 | |
| 879 | if (open_mode & O_EXCL) |
| 880 | goto out; |
| 881 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 882 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 883 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 884 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 885 | break; |
| 886 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 887 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 888 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 889 | break; |
| 890 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 891 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 892 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 893 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 894 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 895 | return ret; |
| 896 | } |
| 897 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 898 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 899 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 900 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 901 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 902 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 903 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 904 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 905 | return 1; |
| 906 | } |
| 907 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 908 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 909 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 910 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 911 | case FMODE_WRITE: |
| 912 | state->n_wronly++; |
| 913 | break; |
| 914 | case FMODE_READ: |
| 915 | state->n_rdonly++; |
| 916 | break; |
| 917 | case FMODE_READ|FMODE_WRITE: |
| 918 | state->n_rdwr++; |
| 919 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 920 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 921 | } |
| 922 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 923 | 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] | 924 | { |
| 925 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 926 | memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); |
| 927 | memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 928 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 929 | case FMODE_READ: |
| 930 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 931 | break; |
| 932 | case FMODE_WRITE: |
| 933 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 934 | break; |
| 935 | case FMODE_READ|FMODE_WRITE: |
| 936 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 937 | } |
| 938 | } |
| 939 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 940 | 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] | 941 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 942 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 943 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 944 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 945 | } |
| 946 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 947 | 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] | 948 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 949 | /* |
| 950 | * Protect the call to nfs4_state_set_mode_locked and |
| 951 | * serialise the stateid update |
| 952 | */ |
| 953 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 954 | if (deleg_stateid != NULL) { |
| 955 | memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); |
| 956 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 957 | } |
| 958 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 959 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 960 | write_sequnlock(&state->seqlock); |
| 961 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 962 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 963 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | } |
| 965 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 966 | 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] | 967 | { |
| 968 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 969 | struct nfs_delegation *deleg_cur; |
| 970 | int ret = 0; |
| 971 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 972 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 973 | |
| 974 | rcu_read_lock(); |
| 975 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 976 | if (deleg_cur == NULL) |
| 977 | goto no_delegation; |
| 978 | |
| 979 | spin_lock(&deleg_cur->lock); |
| 980 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 981 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 982 | goto no_delegation_unlock; |
| 983 | |
| 984 | if (delegation == NULL) |
| 985 | delegation = &deleg_cur->stateid; |
| 986 | else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) |
| 987 | goto no_delegation_unlock; |
| 988 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 989 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 990 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 991 | ret = 1; |
| 992 | no_delegation_unlock: |
| 993 | spin_unlock(&deleg_cur->lock); |
| 994 | no_delegation: |
| 995 | rcu_read_unlock(); |
| 996 | |
| 997 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 998 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 999 | ret = 1; |
| 1000 | } |
| 1001 | |
| 1002 | return ret; |
| 1003 | } |
| 1004 | |
| 1005 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1006 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1007 | { |
| 1008 | struct nfs_delegation *delegation; |
| 1009 | |
| 1010 | rcu_read_lock(); |
| 1011 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1012 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1013 | rcu_read_unlock(); |
| 1014 | return; |
| 1015 | } |
| 1016 | rcu_read_unlock(); |
| 1017 | nfs_inode_return_delegation(inode); |
| 1018 | } |
| 1019 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1020 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1021 | { |
| 1022 | struct nfs4_state *state = opendata->state; |
| 1023 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1024 | struct nfs_delegation *delegation; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1025 | int open_mode = opendata->o_arg.open_flags & O_EXCL; |
| 1026 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1027 | nfs4_stateid stateid; |
| 1028 | int ret = -EAGAIN; |
| 1029 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1030 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1031 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1032 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1033 | if (can_open_cached(state, fmode, open_mode)) { |
| 1034 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1035 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1036 | goto out_return_state; |
| 1037 | } |
| 1038 | spin_unlock(&state->owner->so_lock); |
| 1039 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1040 | rcu_read_lock(); |
| 1041 | delegation = rcu_dereference(nfsi->delegation); |
| 1042 | if (delegation == NULL || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1043 | !can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1044 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1045 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1046 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1047 | /* Save the delegation */ |
| 1048 | memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); |
| 1049 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1050 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1051 | if (ret != 0) |
| 1052 | goto out; |
| 1053 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1054 | |
| 1055 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1056 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1057 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1058 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1059 | out: |
| 1060 | return ERR_PTR(ret); |
| 1061 | out_return_state: |
| 1062 | atomic_inc(&state->count); |
| 1063 | return state; |
| 1064 | } |
| 1065 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1066 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1067 | { |
| 1068 | struct inode *inode; |
| 1069 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1070 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1071 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1072 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1073 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1074 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1075 | goto out; |
| 1076 | } |
| 1077 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1078 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1079 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1080 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1081 | 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] | 1082 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1083 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1084 | goto err; |
| 1085 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1086 | state = nfs4_get_open_state(inode, data->owner); |
| 1087 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1088 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1089 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1090 | int delegation_flags = 0; |
| 1091 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1092 | rcu_read_lock(); |
| 1093 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1094 | if (delegation) |
| 1095 | delegation_flags = delegation->flags; |
| 1096 | rcu_read_unlock(); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1097 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1098 | nfs_inode_set_delegation(state->inode, |
| 1099 | data->owner->so_cred, |
| 1100 | &data->o_res); |
| 1101 | else |
| 1102 | nfs_inode_reclaim_delegation(state->inode, |
| 1103 | data->owner->so_cred, |
| 1104 | &data->o_res); |
| 1105 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1106 | |
| 1107 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1108 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1109 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1110 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1111 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1112 | err_put_inode: |
| 1113 | iput(inode); |
| 1114 | err: |
| 1115 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1116 | } |
| 1117 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1118 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1119 | { |
| 1120 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1121 | struct nfs_open_context *ctx; |
| 1122 | |
| 1123 | spin_lock(&state->inode->i_lock); |
| 1124 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1125 | if (ctx->state != state) |
| 1126 | continue; |
| 1127 | get_nfs_open_context(ctx); |
| 1128 | spin_unlock(&state->inode->i_lock); |
| 1129 | return ctx; |
| 1130 | } |
| 1131 | spin_unlock(&state->inode->i_lock); |
| 1132 | return ERR_PTR(-ENOENT); |
| 1133 | } |
| 1134 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1135 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1136 | { |
| 1137 | struct nfs4_opendata *opendata; |
| 1138 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1139 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, NULL, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1140 | if (opendata == NULL) |
| 1141 | return ERR_PTR(-ENOMEM); |
| 1142 | opendata->state = state; |
| 1143 | atomic_inc(&state->count); |
| 1144 | return opendata; |
| 1145 | } |
| 1146 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1147 | 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] | 1148 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1149 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1150 | int ret; |
| 1151 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1152 | opendata->o_arg.open_flags = 0; |
| 1153 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1154 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1155 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1156 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1157 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1158 | if (ret != 0) |
| 1159 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1160 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1161 | if (IS_ERR(newstate)) |
| 1162 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1163 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1164 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1165 | return 0; |
| 1166 | } |
| 1167 | |
| 1168 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1169 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1170 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1171 | int ret; |
| 1172 | |
| 1173 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1174 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1175 | smp_rmb(); |
| 1176 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1177 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1178 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|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_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1185 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1186 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &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 | } |
| 1192 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1193 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1194 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1195 | if (ret != 0) |
| 1196 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1197 | if (newstate != state) |
| 1198 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1199 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1200 | /* |
| 1201 | * We may have performed cached opens for all three recoveries. |
| 1202 | * Check if we need to update the current stateid. |
| 1203 | */ |
| 1204 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
| 1205 | 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] | 1206 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1207 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1208 | memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1209 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1210 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1211 | return 0; |
| 1212 | } |
| 1213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | /* |
| 1215 | * OPEN_RECLAIM: |
| 1216 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1218 | 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] | 1219 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1220 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1221 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1222 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | int status; |
| 1224 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1225 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1226 | if (IS_ERR(opendata)) |
| 1227 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1228 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1229 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1230 | rcu_read_lock(); |
| 1231 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1232 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1233 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1234 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1235 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1236 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1237 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | return status; |
| 1239 | } |
| 1240 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1241 | 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] | 1242 | { |
| 1243 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1244 | struct nfs4_exception exception = { }; |
| 1245 | int err; |
| 1246 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1247 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1248 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1249 | break; |
| 1250 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | } while (exception.retry); |
| 1252 | return err; |
| 1253 | } |
| 1254 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1255 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1256 | { |
| 1257 | struct nfs_open_context *ctx; |
| 1258 | int ret; |
| 1259 | |
| 1260 | ctx = nfs4_state_find_open_context(state); |
| 1261 | if (IS_ERR(ctx)) |
| 1262 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1263 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1264 | put_nfs_open_context(ctx); |
| 1265 | return ret; |
| 1266 | } |
| 1267 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1268 | 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] | 1269 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1270 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1271 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1273 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1274 | if (IS_ERR(opendata)) |
| 1275 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1276 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1277 | memcpy(opendata->o_arg.u.delegation.data, stateid->data, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1278 | sizeof(opendata->o_arg.u.delegation.data)); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1279 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1280 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1281 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1284 | 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] | 1285 | { |
| 1286 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1287 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | int err; |
| 1289 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1290 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | switch (err) { |
| 1292 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1293 | case -ENOENT: |
| 1294 | case -ESTALE: |
| 1295 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1296 | case -NFS4ERR_BADSESSION: |
| 1297 | case -NFS4ERR_BADSLOT: |
| 1298 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1299 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1300 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1301 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1302 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | case -NFS4ERR_STALE_CLIENTID: |
| 1304 | case -NFS4ERR_STALE_STATEID: |
| 1305 | case -NFS4ERR_EXPIRED: |
| 1306 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1307 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1308 | goto out; |
| 1309 | case -ERESTARTSYS: |
| 1310 | /* |
| 1311 | * The show must go on: exit, but mark the |
| 1312 | * stateid as needing recovery. |
| 1313 | */ |
| 1314 | case -NFS4ERR_ADMIN_REVOKED: |
| 1315 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1316 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1317 | case -EKEYEXPIRED: |
| 1318 | /* |
| 1319 | * User RPCSEC_GSS context has expired. |
| 1320 | * We cannot recover this stateid now, so |
| 1321 | * skip it and allow recovery thread to |
| 1322 | * proceed. |
| 1323 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1324 | case -ENOMEM: |
| 1325 | err = 0; |
| 1326 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | } |
| 1328 | err = nfs4_handle_exception(server, err, &exception); |
| 1329 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1330 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | return err; |
| 1332 | } |
| 1333 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1334 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1335 | { |
| 1336 | struct nfs4_opendata *data = calldata; |
| 1337 | |
| 1338 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1339 | if (data->rpc_status == 0) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1340 | memcpy(data->o_res.stateid.data, data->c_res.stateid.data, |
| 1341 | sizeof(data->o_res.stateid.data)); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1342 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1343 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1344 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1345 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | static void nfs4_open_confirm_release(void *calldata) |
| 1349 | { |
| 1350 | struct nfs4_opendata *data = calldata; |
| 1351 | struct nfs4_state *state = NULL; |
| 1352 | |
| 1353 | /* If this request hasn't been cancelled, do nothing */ |
| 1354 | if (data->cancelled == 0) |
| 1355 | goto out_free; |
| 1356 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1357 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1358 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1359 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1360 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1361 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1362 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1363 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1367 | .rpc_call_done = nfs4_open_confirm_done, |
| 1368 | .rpc_release = nfs4_open_confirm_release, |
| 1369 | }; |
| 1370 | |
| 1371 | /* |
| 1372 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1373 | */ |
| 1374 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1375 | { |
| 1376 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1377 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1378 | struct rpc_message msg = { |
| 1379 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1380 | .rpc_argp = &data->c_arg, |
| 1381 | .rpc_resp = &data->c_res, |
| 1382 | .rpc_cred = data->owner->so_cred, |
| 1383 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1384 | struct rpc_task_setup task_setup_data = { |
| 1385 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1386 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1387 | .callback_ops = &nfs4_open_confirm_ops, |
| 1388 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1389 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1390 | .flags = RPC_TASK_ASYNC, |
| 1391 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | int status; |
| 1393 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1394 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1395 | data->rpc_done = 0; |
| 1396 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1397 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1398 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1399 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1400 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1401 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1402 | if (status != 0) { |
| 1403 | data->cancelled = 1; |
| 1404 | smp_wmb(); |
| 1405 | } else |
| 1406 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1407 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | return status; |
| 1409 | } |
| 1410 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1411 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1413 | struct nfs4_opendata *data = calldata; |
| 1414 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1415 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1416 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1417 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1418 | /* |
| 1419 | * Check if we still need to send an OPEN call, or if we can use |
| 1420 | * a delegation instead. |
| 1421 | */ |
| 1422 | if (data->state != NULL) { |
| 1423 | struct nfs_delegation *delegation; |
| 1424 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1425 | 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] | 1426 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1427 | rcu_read_lock(); |
| 1428 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
| 1429 | if (delegation != NULL && |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1430 | test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1431 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1432 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1433 | } |
| 1434 | rcu_read_unlock(); |
| 1435 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1436 | /* Update sequence id. */ |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1437 | data->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1438 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1439 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1440 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1441 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1442 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1443 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1444 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1445 | &data->o_arg.seq_args, |
| 1446 | &data->o_res.seq_res, 1, task)) |
| 1447 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1448 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1449 | return; |
| 1450 | out_no_action: |
| 1451 | task->tk_action = NULL; |
| 1452 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1453 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1455 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1456 | { |
| 1457 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1458 | nfs4_open_prepare(task, calldata); |
| 1459 | } |
| 1460 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1461 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1462 | { |
| 1463 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1465 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1466 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1467 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1468 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1469 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1470 | if (task->tk_status == 0) { |
| 1471 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1472 | case S_IFREG: |
| 1473 | break; |
| 1474 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1475 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1476 | break; |
| 1477 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1478 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1479 | break; |
| 1480 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1481 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1482 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1483 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1484 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1485 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1486 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1487 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1488 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1489 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1490 | static void nfs4_open_release(void *calldata) |
| 1491 | { |
| 1492 | struct nfs4_opendata *data = calldata; |
| 1493 | struct nfs4_state *state = NULL; |
| 1494 | |
| 1495 | /* If this request hasn't been cancelled, do nothing */ |
| 1496 | if (data->cancelled == 0) |
| 1497 | goto out_free; |
| 1498 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1499 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1500 | goto out_free; |
| 1501 | /* In case we need an open_confirm, no cleanup! */ |
| 1502 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1503 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1504 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1505 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1506 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1507 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1508 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1512 | .rpc_call_prepare = nfs4_open_prepare, |
| 1513 | .rpc_call_done = nfs4_open_done, |
| 1514 | .rpc_release = nfs4_open_release, |
| 1515 | }; |
| 1516 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1517 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1518 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1519 | .rpc_call_done = nfs4_open_done, |
| 1520 | .rpc_release = nfs4_open_release, |
| 1521 | }; |
| 1522 | |
| 1523 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1524 | { |
| 1525 | struct inode *dir = data->dir->d_inode; |
| 1526 | struct nfs_server *server = NFS_SERVER(dir); |
| 1527 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1528 | struct nfs_openres *o_res = &data->o_res; |
| 1529 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1530 | struct rpc_message msg = { |
| 1531 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1532 | .rpc_argp = o_arg, |
| 1533 | .rpc_resp = o_res, |
| 1534 | .rpc_cred = data->owner->so_cred, |
| 1535 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1536 | struct rpc_task_setup task_setup_data = { |
| 1537 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1538 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1539 | .callback_ops = &nfs4_open_ops, |
| 1540 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1541 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1542 | .flags = RPC_TASK_ASYNC, |
| 1543 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1544 | int status; |
| 1545 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1546 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1547 | data->rpc_done = 0; |
| 1548 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1549 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1550 | if (isrecover) |
| 1551 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1552 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1553 | if (IS_ERR(task)) |
| 1554 | return PTR_ERR(task); |
| 1555 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1556 | if (status != 0) { |
| 1557 | data->cancelled = 1; |
| 1558 | smp_wmb(); |
| 1559 | } else |
| 1560 | status = data->rpc_status; |
| 1561 | rpc_put_task(task); |
| 1562 | |
| 1563 | return status; |
| 1564 | } |
| 1565 | |
| 1566 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1567 | { |
| 1568 | struct inode *dir = data->dir->d_inode; |
| 1569 | struct nfs_openres *o_res = &data->o_res; |
| 1570 | int status; |
| 1571 | |
| 1572 | status = nfs4_run_open_task(data, 1); |
| 1573 | if (status != 0 || !data->rpc_done) |
| 1574 | return status; |
| 1575 | |
| 1576 | nfs_refresh_inode(dir, o_res->dir_attr); |
| 1577 | |
| 1578 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1579 | status = _nfs4_proc_open_confirm(data); |
| 1580 | if (status != 0) |
| 1581 | return status; |
| 1582 | } |
| 1583 | |
| 1584 | return status; |
| 1585 | } |
| 1586 | |
| 1587 | /* |
| 1588 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1589 | */ |
| 1590 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1591 | { |
| 1592 | struct inode *dir = data->dir->d_inode; |
| 1593 | struct nfs_server *server = NFS_SERVER(dir); |
| 1594 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1595 | struct nfs_openres *o_res = &data->o_res; |
| 1596 | int status; |
| 1597 | |
| 1598 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1599 | if (status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1600 | return status; |
| 1601 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1602 | if (o_arg->open_flags & O_CREAT) { |
| 1603 | update_changeattr(dir, &o_res->cinfo); |
| 1604 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
| 1605 | } else |
| 1606 | nfs_refresh_inode(dir, o_res->dir_attr); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1607 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1608 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1610 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1612 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | } |
| 1614 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1615 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1616 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | } |
| 1618 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1619 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1620 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1621 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1622 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1623 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1624 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1625 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1626 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1627 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1628 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1629 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1630 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1631 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1632 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1633 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1634 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1635 | } |
| 1636 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1637 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1638 | { |
| 1639 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1640 | } |
| 1641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | /* |
| 1643 | * OPEN_EXPIRED: |
| 1644 | * reclaim state on the server after a network partition. |
| 1645 | * Assumes caller holds the appropriate lock |
| 1646 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1647 | 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] | 1648 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1649 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1650 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1652 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1653 | if (IS_ERR(opendata)) |
| 1654 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1655 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1656 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1657 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1658 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1659 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | } |
| 1661 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1662 | 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] | 1663 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1664 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1665 | struct nfs4_exception exception = { }; |
| 1666 | int err; |
| 1667 | |
| 1668 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1669 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1670 | switch (err) { |
| 1671 | default: |
| 1672 | goto out; |
| 1673 | case -NFS4ERR_GRACE: |
| 1674 | case -NFS4ERR_DELAY: |
| 1675 | nfs4_handle_exception(server, err, &exception); |
| 1676 | err = 0; |
| 1677 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1678 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1679 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1680 | return err; |
| 1681 | } |
| 1682 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1684 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1686 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1687 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1688 | ctx = nfs4_state_find_open_context(state); |
| 1689 | if (IS_ERR(ctx)) |
| 1690 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1691 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1692 | put_nfs_open_context(ctx); |
| 1693 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | } |
| 1695 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1696 | #if defined(CONFIG_NFS_V4_1) |
| 1697 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1698 | { |
| 1699 | int status; |
| 1700 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1701 | |
| 1702 | status = nfs41_test_stateid(server, state); |
| 1703 | if (status == NFS_OK) |
| 1704 | return 0; |
| 1705 | nfs41_free_stateid(server, state); |
| 1706 | return nfs4_open_expired(sp, state); |
| 1707 | } |
| 1708 | #endif |
| 1709 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1711 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1712 | * fields corresponding to attributes that were used to store the verifier. |
| 1713 | * Make sure we clobber those fields in the later setattr call |
| 1714 | */ |
| 1715 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1716 | { |
| 1717 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1718 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1719 | sattr->ia_valid |= ATTR_ATIME; |
| 1720 | |
| 1721 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1722 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1723 | sattr->ia_valid |= ATTR_MTIME; |
| 1724 | } |
| 1725 | |
| 1726 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1727 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | */ |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1729 | static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, 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] | 1730 | { |
| 1731 | struct nfs4_state_owner *sp; |
| 1732 | struct nfs4_state *state = NULL; |
| 1733 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1734 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1735 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | |
| 1737 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1738 | status = -ENOMEM; |
| 1739 | if (!(sp = nfs4_get_state_owner(server, cred))) { |
| 1740 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1741 | goto out_err; |
| 1742 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1743 | status = nfs4_recover_expired_lease(server); |
| 1744 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1745 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1746 | if (dentry->d_inode != NULL) |
| 1747 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1748 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1749 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1750 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1751 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1753 | if (dentry->d_inode != NULL) |
| 1754 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1755 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1756 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1758 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1760 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1761 | status = PTR_ERR(state); |
| 1762 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1763 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1764 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1765 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1766 | |
| 1767 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1768 | nfs4_exclusive_attrset(opendata, sattr); |
| 1769 | |
| 1770 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1771 | status = nfs4_do_setattr(state->inode, cred, |
| 1772 | opendata->o_res.f_attr, sattr, |
| 1773 | state); |
| 1774 | if (status == 0) |
| 1775 | nfs_setattr_update_inode(state->inode, sattr); |
| 1776 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1777 | } |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1778 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | *res = state; |
| 1781 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1782 | err_opendata_put: |
| 1783 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1784 | err_put_state_owner: |
| 1785 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | *res = NULL; |
| 1788 | return status; |
| 1789 | } |
| 1790 | |
| 1791 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1792 | static struct nfs4_state *nfs4_do_open(struct inode *dir, struct dentry *dentry, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | { |
| 1794 | struct nfs4_exception exception = { }; |
| 1795 | struct nfs4_state *res; |
| 1796 | int status; |
| 1797 | |
| 1798 | do { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1799 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | if (status == 0) |
| 1801 | break; |
| 1802 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1803 | * book-keeping w.r.t. state-changing operations |
| 1804 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1805 | * It is actually a sign of a bug on the client or on the server. |
| 1806 | * |
| 1807 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1808 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | * have unhashed the old state_owner for us, and that we can |
| 1810 | * therefore safely retry using a new one. We should still warn |
| 1811 | * the user though... |
| 1812 | */ |
| 1813 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1814 | printk(KERN_WARNING "NFS: v4 server %s " |
| 1815 | " returned a bad sequence-id error!\n", |
| 1816 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | exception.retry = 1; |
| 1818 | continue; |
| 1819 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1820 | /* |
| 1821 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1822 | * state before it received the OPEN_CONFIRM. |
| 1823 | * Recover by retrying the request as per the discussion |
| 1824 | * on Page 181 of RFC3530. |
| 1825 | */ |
| 1826 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1827 | exception.retry = 1; |
| 1828 | continue; |
| 1829 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1830 | if (status == -EAGAIN) { |
| 1831 | /* We must have found a delegation */ |
| 1832 | exception.retry = 1; |
| 1833 | continue; |
| 1834 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1836 | status, &exception)); |
| 1837 | } while (exception.retry); |
| 1838 | return res; |
| 1839 | } |
| 1840 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1841 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1842 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1843 | struct nfs4_state *state) |
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 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1847 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | .iap = sattr, |
| 1849 | .server = server, |
| 1850 | .bitmask = server->attr_bitmask, |
| 1851 | }; |
| 1852 | struct nfs_setattrres res = { |
| 1853 | .fattr = fattr, |
| 1854 | .server = server, |
| 1855 | }; |
| 1856 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1857 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1858 | .rpc_argp = &arg, |
| 1859 | .rpc_resp = &res, |
| 1860 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1862 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1863 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1865 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1867 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { |
| 1868 | /* Use that stateid */ |
| 1869 | } else if (state != NULL) { |
Trond Myklebust | 77041ed | 2010-07-01 12:49:11 -0400 | [diff] [blame] | 1870 | nfs4_copy_stateid(&arg.stateid, state, current->files, current->tgid); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1871 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); |
| 1873 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1874 | 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] | 1875 | if (status == 0 && state != NULL) |
| 1876 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1877 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | } |
| 1879 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1880 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1881 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1882 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1884 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | struct nfs4_exception exception = { }; |
| 1886 | int err; |
| 1887 | do { |
| 1888 | err = nfs4_handle_exception(server, |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1889 | _nfs4_do_setattr(inode, cred, fattr, sattr, state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | &exception); |
| 1891 | } while (exception.retry); |
| 1892 | return err; |
| 1893 | } |
| 1894 | |
| 1895 | struct nfs4_closedata { |
| 1896 | struct inode *inode; |
| 1897 | struct nfs4_state *state; |
| 1898 | struct nfs_closeargs arg; |
| 1899 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1900 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1901 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1902 | bool roc; |
| 1903 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | }; |
| 1905 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1906 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1907 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1908 | struct nfs4_closedata *calldata = data; |
| 1909 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1910 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1911 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1912 | if (calldata->roc) |
| 1913 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1914 | nfs4_put_open_state(calldata->state); |
| 1915 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1916 | nfs4_put_state_owner(sp); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1917 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1918 | kfree(calldata); |
| 1919 | } |
| 1920 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1921 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 1922 | fmode_t fmode) |
| 1923 | { |
| 1924 | spin_lock(&state->owner->so_lock); |
| 1925 | if (!(fmode & FMODE_READ)) |
| 1926 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1927 | if (!(fmode & FMODE_WRITE)) |
| 1928 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1929 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1930 | spin_unlock(&state->owner->so_lock); |
| 1931 | } |
| 1932 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1933 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1935 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 1938 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1939 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 1940 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | /* hmm. we are done with the inode, and in the process of freeing |
| 1942 | * the state_owner. we keep this around to process errors |
| 1943 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | switch (task->tk_status) { |
| 1945 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1946 | if (calldata->roc) |
| 1947 | pnfs_roc_set_barrier(state->inode, |
| 1948 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1949 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1950 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1951 | nfs4_close_clear_stateid_flags(state, |
| 1952 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | break; |
| 1954 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1955 | case -NFS4ERR_OLD_STATEID: |
| 1956 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1958 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1959 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1961 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 1962 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1964 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1965 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | } |
| 1967 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1968 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1970 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1971 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1972 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1973 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1974 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1975 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1976 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1977 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 1978 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1979 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1980 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1981 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1982 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1983 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1984 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1985 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1986 | } |
| 1987 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1988 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1989 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1990 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1991 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1992 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1993 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1994 | |
| 1995 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1996 | /* Note: exit _without_ calling nfs4_close_done */ |
| 1997 | task->tk_action = NULL; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1998 | return; |
| 1999 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2000 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2001 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2002 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2003 | if (calldata->roc && |
| 2004 | pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { |
| 2005 | rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, |
| 2006 | task, NULL); |
| 2007 | return; |
| 2008 | } |
| 2009 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2010 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2011 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2012 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2013 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 2014 | &calldata->arg.seq_args, &calldata->res.seq_res, |
| 2015 | 1, task)) |
| 2016 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2017 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | } |
| 2019 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2020 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2021 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2022 | .rpc_call_done = nfs4_close_done, |
| 2023 | .rpc_release = nfs4_free_closedata, |
| 2024 | }; |
| 2025 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | /* |
| 2027 | * It is possible for data to be read/written from a mem-mapped file |
| 2028 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2029 | * This means that we can't safely call nfsv4 close on a file until |
| 2030 | * the inode is cleared. This in turn means that we are not good |
| 2031 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2032 | * share state even when we are done with one of the three share |
| 2033 | * stateid's in the inode. |
| 2034 | * |
| 2035 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2036 | */ |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2037 | int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait, bool roc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2039 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2041 | struct nfs4_state_owner *sp = state->owner; |
| 2042 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2043 | struct rpc_message msg = { |
| 2044 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2045 | .rpc_cred = state->owner->so_cred, |
| 2046 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2047 | struct rpc_task_setup task_setup_data = { |
| 2048 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2049 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2050 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2051 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2052 | .flags = RPC_TASK_ASYNC, |
| 2053 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2054 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2056 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2058 | goto out; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2059 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2061 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2062 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2064 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2065 | if (calldata->arg.seqid == NULL) |
| 2066 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2067 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2068 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2069 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2070 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2071 | calldata->res.server = server; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2072 | calldata->roc = roc; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2073 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2074 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2075 | msg.rpc_argp = &calldata->arg; |
| 2076 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2077 | task_setup_data.callback_data = calldata; |
| 2078 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2079 | if (IS_ERR(task)) |
| 2080 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2081 | status = 0; |
| 2082 | if (wait) |
| 2083 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2084 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2085 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2086 | out_free_calldata: |
| 2087 | kfree(calldata); |
| 2088 | out: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2089 | if (roc) |
| 2090 | pnfs_roc_release(state->inode); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2091 | nfs4_put_open_state(state); |
| 2092 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2093 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | } |
| 2095 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2096 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2097 | 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] | 2098 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | struct nfs4_state *state; |
| 2100 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2101 | /* Protect against concurrent sillydeletes */ |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2102 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, ctx->cred); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2103 | if (IS_ERR(state)) |
| 2104 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2105 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2106 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | } |
| 2108 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2109 | 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] | 2110 | { |
| 2111 | if (ctx->state == NULL) |
| 2112 | return; |
| 2113 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2114 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2115 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2116 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2117 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | |
| 2119 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2120 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2121 | struct nfs4_server_caps_arg args = { |
| 2122 | .fhandle = fhandle, |
| 2123 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | struct nfs4_server_caps_res res = {}; |
| 2125 | struct rpc_message msg = { |
| 2126 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2127 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | .rpc_resp = &res, |
| 2129 | }; |
| 2130 | int status; |
| 2131 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2132 | 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] | 2133 | if (status == 0) { |
| 2134 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2135 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2136 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2137 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2138 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2139 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2141 | server->caps |= NFS_CAP_ACLS; |
| 2142 | if (res.has_links != 0) |
| 2143 | server->caps |= NFS_CAP_HARDLINKS; |
| 2144 | if (res.has_symlinks != 0) |
| 2145 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2146 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2147 | server->caps |= NFS_CAP_FILEID; |
| 2148 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2149 | server->caps |= NFS_CAP_MODE; |
| 2150 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2151 | server->caps |= NFS_CAP_NLINK; |
| 2152 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2153 | server->caps |= NFS_CAP_OWNER; |
| 2154 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2155 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2156 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2157 | server->caps |= NFS_CAP_ATIME; |
| 2158 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2159 | server->caps |= NFS_CAP_CTIME; |
| 2160 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2161 | server->caps |= NFS_CAP_MTIME; |
| 2162 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2163 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2164 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2165 | 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] | 2166 | server->acl_bitmask = res.acl_bitmask; |
| 2167 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | return status; |
| 2170 | } |
| 2171 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2172 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | { |
| 2174 | struct nfs4_exception exception = { }; |
| 2175 | int err; |
| 2176 | do { |
| 2177 | err = nfs4_handle_exception(server, |
| 2178 | _nfs4_server_capabilities(server, fhandle), |
| 2179 | &exception); |
| 2180 | } while (exception.retry); |
| 2181 | return err; |
| 2182 | } |
| 2183 | |
| 2184 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2185 | struct nfs_fsinfo *info) |
| 2186 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | struct nfs4_lookup_root_arg args = { |
| 2188 | .bitmask = nfs4_fattr_bitmap, |
| 2189 | }; |
| 2190 | struct nfs4_lookup_res res = { |
| 2191 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2192 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | .fh = fhandle, |
| 2194 | }; |
| 2195 | struct rpc_message msg = { |
| 2196 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2197 | .rpc_argp = &args, |
| 2198 | .rpc_resp = &res, |
| 2199 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2200 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2201 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2202 | 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] | 2203 | } |
| 2204 | |
| 2205 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2206 | struct nfs_fsinfo *info) |
| 2207 | { |
| 2208 | struct nfs4_exception exception = { }; |
| 2209 | int err; |
| 2210 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2211 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2212 | switch (err) { |
| 2213 | case 0: |
| 2214 | case -NFS4ERR_WRONGSEC: |
| 2215 | break; |
| 2216 | default: |
| 2217 | err = nfs4_handle_exception(server, err, &exception); |
| 2218 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | } while (exception.retry); |
| 2220 | return err; |
| 2221 | } |
| 2222 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2223 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2224 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2225 | { |
| 2226 | struct rpc_auth *auth; |
| 2227 | int ret; |
| 2228 | |
| 2229 | auth = rpcauth_create(flavor, server->client); |
| 2230 | if (!auth) { |
| 2231 | ret = -EIO; |
| 2232 | goto out; |
| 2233 | } |
| 2234 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2235 | out: |
| 2236 | return ret; |
| 2237 | } |
| 2238 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2239 | 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] | 2240 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2241 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2242 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2243 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2244 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2245 | len = gss_mech_list_pseudoflavors(&flav_array[0]); |
| 2246 | flav_array[len] = RPC_AUTH_NULL; |
| 2247 | len += 1; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2248 | |
| 2249 | for (i = 0; i < len; i++) { |
| 2250 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2251 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2252 | continue; |
| 2253 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2254 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2255 | /* |
| 2256 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2257 | * to access the mount. It could also mean that we tried to mount |
| 2258 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2259 | * existing mount programs don't handle -EACCES very well so it should |
| 2260 | * be mapped to -EPERM instead. |
| 2261 | */ |
| 2262 | if (status == -EACCES) |
| 2263 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2264 | return status; |
| 2265 | } |
| 2266 | |
| 2267 | /* |
| 2268 | * get the file handle for the "/" directory on the server |
| 2269 | */ |
| 2270 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2271 | struct nfs_fsinfo *info) |
| 2272 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2273 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2274 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2275 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2276 | /* |
| 2277 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2278 | * by nfs4_map_errors() as this function exits. |
| 2279 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2280 | status = nfs_v4_minor_ops[minor_version]->find_root_sec(server, fhandle, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2281 | if (status == 0) |
| 2282 | status = nfs4_server_capabilities(server, fhandle); |
| 2283 | if (status == 0) |
| 2284 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2285 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | } |
| 2287 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2288 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2289 | /* |
| 2290 | * Get locations and (maybe) other attributes of a referral. |
| 2291 | * Note that we'll actually follow the referral later when |
| 2292 | * we detect fsid mismatch in inode revalidation |
| 2293 | */ |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2294 | static int nfs4_get_referral(struct inode *dir, const struct qstr *name, |
| 2295 | struct nfs_fattr *fattr, struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2296 | { |
| 2297 | int status = -ENOMEM; |
| 2298 | struct page *page = NULL; |
| 2299 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2300 | |
| 2301 | page = alloc_page(GFP_KERNEL); |
| 2302 | if (page == NULL) |
| 2303 | goto out; |
| 2304 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2305 | if (locations == NULL) |
| 2306 | goto out; |
| 2307 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 2308 | status = nfs4_proc_fs_locations(dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2309 | if (status != 0) |
| 2310 | goto out; |
| 2311 | /* Make sure server returned a different fsid for the referral */ |
| 2312 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2313 | dprintk("%s: server did not return a different fsid for" |
| 2314 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2315 | status = -EIO; |
| 2316 | goto out; |
| 2317 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2318 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2319 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2320 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2321 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2322 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2323 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2324 | out: |
| 2325 | if (page) |
| 2326 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2327 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2328 | return status; |
| 2329 | } |
| 2330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2331 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2332 | { |
| 2333 | struct nfs4_getattr_arg args = { |
| 2334 | .fh = fhandle, |
| 2335 | .bitmask = server->attr_bitmask, |
| 2336 | }; |
| 2337 | struct nfs4_getattr_res res = { |
| 2338 | .fattr = fattr, |
| 2339 | .server = server, |
| 2340 | }; |
| 2341 | struct rpc_message msg = { |
| 2342 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2343 | .rpc_argp = &args, |
| 2344 | .rpc_resp = &res, |
| 2345 | }; |
| 2346 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2347 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2348 | 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] | 2349 | } |
| 2350 | |
| 2351 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2352 | { |
| 2353 | struct nfs4_exception exception = { }; |
| 2354 | int err; |
| 2355 | do { |
| 2356 | err = nfs4_handle_exception(server, |
| 2357 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2358 | &exception); |
| 2359 | } while (exception.retry); |
| 2360 | return err; |
| 2361 | } |
| 2362 | |
| 2363 | /* |
| 2364 | * The file is not closed if it is opened due to the a request to change |
| 2365 | * the size of the file. The open call will not be needed once the |
| 2366 | * VFS layer lookup-intents are implemented. |
| 2367 | * |
| 2368 | * Close is called when the inode is destroyed. |
| 2369 | * If we haven't opened the file for O_WRONLY, we |
| 2370 | * need to in the size_change case to obtain a stateid. |
| 2371 | * |
| 2372 | * Got race? |
| 2373 | * Because OPEN is always done by name in nfsv4, it is |
| 2374 | * possible that we opened a different file by the same |
| 2375 | * name. We can recognize this race condition, but we |
| 2376 | * can't do anything about it besides returning an error. |
| 2377 | * |
| 2378 | * This will be fixed with VFS changes (lookup-intent). |
| 2379 | */ |
| 2380 | static int |
| 2381 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2382 | struct iattr *sattr) |
| 2383 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2384 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2385 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2386 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | int status; |
| 2388 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2389 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2390 | pnfs_return_layout(inode); |
| 2391 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2392 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2393 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2394 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2395 | if (sattr->ia_valid & ATTR_FILE) { |
| 2396 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2397 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2398 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2399 | if (ctx) { |
| 2400 | cred = ctx->cred; |
| 2401 | state = ctx->state; |
| 2402 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2403 | } |
| 2404 | |
| 2405 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2406 | if (status == 0) |
| 2407 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | return status; |
| 2409 | } |
| 2410 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2411 | static int _nfs4_proc_lookupfh(struct rpc_clnt *clnt, struct nfs_server *server, |
| 2412 | const struct nfs_fh *dirfh, const struct qstr *name, |
| 2413 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2414 | { |
| 2415 | int status; |
| 2416 | struct nfs4_lookup_arg args = { |
| 2417 | .bitmask = server->attr_bitmask, |
| 2418 | .dir_fh = dirfh, |
| 2419 | .name = name, |
| 2420 | }; |
| 2421 | struct nfs4_lookup_res res = { |
| 2422 | .server = server, |
| 2423 | .fattr = fattr, |
| 2424 | .fh = fhandle, |
| 2425 | }; |
| 2426 | struct rpc_message msg = { |
| 2427 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2428 | .rpc_argp = &args, |
| 2429 | .rpc_resp = &res, |
| 2430 | }; |
| 2431 | |
| 2432 | nfs_fattr_init(fattr); |
| 2433 | |
| 2434 | dprintk("NFS call lookupfh %s\n", name->name); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2435 | 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] | 2436 | dprintk("NFS reply lookupfh: %d\n", status); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2437 | return status; |
| 2438 | } |
| 2439 | |
| 2440 | static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh, |
| 2441 | struct qstr *name, struct nfs_fh *fhandle, |
| 2442 | struct nfs_fattr *fattr) |
| 2443 | { |
| 2444 | struct nfs4_exception exception = { }; |
| 2445 | int err; |
| 2446 | do { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2447 | err = _nfs4_proc_lookupfh(server->client, server, dirfh, name, fhandle, fattr); |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2448 | /* FIXME: !!!! */ |
| 2449 | if (err == -NFS4ERR_MOVED) { |
| 2450 | err = -EREMOTE; |
| 2451 | break; |
| 2452 | } |
| 2453 | err = nfs4_handle_exception(server, err, &exception); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2454 | } while (exception.retry); |
| 2455 | return err; |
| 2456 | } |
| 2457 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2458 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2459 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2460 | struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2462 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2463 | |
| 2464 | dprintk("NFS call lookup %s\n", name->name); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2465 | 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] | 2466 | if (status == -NFS4ERR_MOVED) |
| 2467 | status = nfs4_get_referral(dir, name, fattr, fhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | dprintk("NFS reply lookup: %d\n", status); |
| 2469 | return status; |
| 2470 | } |
| 2471 | |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2472 | void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr, struct nfs_fh *fh) |
| 2473 | { |
| 2474 | memset(fh, 0, sizeof(struct nfs_fh)); |
| 2475 | fattr->fsid.major = 1; |
| 2476 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 2477 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_FSID | NFS_ATTR_FATTR_MOUNTPOINT; |
| 2478 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2479 | fattr->nlink = 2; |
| 2480 | } |
| 2481 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2482 | static int nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, struct qstr *name, |
| 2483 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | { |
| 2485 | struct nfs4_exception exception = { }; |
| 2486 | int err; |
| 2487 | do { |
| 2488 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2489 | _nfs4_proc_lookup(clnt, dir, name, fhandle, fattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2490 | &exception); |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2491 | if (err == -EPERM) |
| 2492 | nfs_fixup_secinfo_attributes(fattr, fhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2493 | } while (exception.retry); |
| 2494 | return err; |
| 2495 | } |
| 2496 | |
| 2497 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2498 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2499 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | struct nfs4_accessargs args = { |
| 2501 | .fh = NFS_FH(inode), |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2502 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2503 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2504 | struct nfs4_accessres res = { |
| 2505 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2506 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | struct rpc_message msg = { |
| 2508 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2509 | .rpc_argp = &args, |
| 2510 | .rpc_resp = &res, |
| 2511 | .rpc_cred = entry->cred, |
| 2512 | }; |
| 2513 | int mode = entry->mask; |
| 2514 | int status; |
| 2515 | |
| 2516 | /* |
| 2517 | * Determine which access bits we want to ask for... |
| 2518 | */ |
| 2519 | if (mode & MAY_READ) |
| 2520 | args.access |= NFS4_ACCESS_READ; |
| 2521 | if (S_ISDIR(inode->i_mode)) { |
| 2522 | if (mode & MAY_WRITE) |
| 2523 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2524 | if (mode & MAY_EXEC) |
| 2525 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2526 | } else { |
| 2527 | if (mode & MAY_WRITE) |
| 2528 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2529 | if (mode & MAY_EXEC) |
| 2530 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2531 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2532 | |
| 2533 | res.fattr = nfs_alloc_fattr(); |
| 2534 | if (res.fattr == NULL) |
| 2535 | return -ENOMEM; |
| 2536 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2537 | 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] | 2538 | if (!status) { |
| 2539 | entry->mask = 0; |
| 2540 | if (res.access & NFS4_ACCESS_READ) |
| 2541 | entry->mask |= MAY_READ; |
| 2542 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2543 | entry->mask |= MAY_WRITE; |
| 2544 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2545 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2546 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2547 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2548 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2549 | return status; |
| 2550 | } |
| 2551 | |
| 2552 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2553 | { |
| 2554 | struct nfs4_exception exception = { }; |
| 2555 | int err; |
| 2556 | do { |
| 2557 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2558 | _nfs4_proc_access(inode, entry), |
| 2559 | &exception); |
| 2560 | } while (exception.retry); |
| 2561 | return err; |
| 2562 | } |
| 2563 | |
| 2564 | /* |
| 2565 | * TODO: For the time being, we don't try to get any attributes |
| 2566 | * along with any of the zero-copy operations READ, READDIR, |
| 2567 | * READLINK, WRITE. |
| 2568 | * |
| 2569 | * In the case of the first three, we want to put the GETATTR |
| 2570 | * after the read-type operation -- this is because it is hard |
| 2571 | * to predict the length of a GETATTR response in v4, and thus |
| 2572 | * align the READ data correctly. This means that the GETATTR |
| 2573 | * may end up partially falling into the page cache, and we should |
| 2574 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2575 | * To do this efficiently, we need to know the total length |
| 2576 | * of data received, which doesn't seem to be available outside |
| 2577 | * of the RPC layer. |
| 2578 | * |
| 2579 | * In the case of WRITE, we also want to put the GETATTR after |
| 2580 | * the operation -- in this case because we want to make sure |
| 2581 | * we get the post-operation mtime and size. This means that |
| 2582 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2583 | * of it which would leave room in the 'tail' iovec. |
| 2584 | * |
| 2585 | * Both of these changes to the XDR layer would in fact be quite |
| 2586 | * minor, but I decided to leave them for a subsequent patch. |
| 2587 | */ |
| 2588 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2589 | unsigned int pgbase, unsigned int pglen) |
| 2590 | { |
| 2591 | struct nfs4_readlink args = { |
| 2592 | .fh = NFS_FH(inode), |
| 2593 | .pgbase = pgbase, |
| 2594 | .pglen = pglen, |
| 2595 | .pages = &page, |
| 2596 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2597 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2598 | struct rpc_message msg = { |
| 2599 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2600 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2601 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | }; |
| 2603 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2604 | 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] | 2605 | } |
| 2606 | |
| 2607 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2608 | unsigned int pgbase, unsigned int pglen) |
| 2609 | { |
| 2610 | struct nfs4_exception exception = { }; |
| 2611 | int err; |
| 2612 | do { |
| 2613 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2614 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2615 | &exception); |
| 2616 | } while (exception.retry); |
| 2617 | return err; |
| 2618 | } |
| 2619 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2620 | /* |
| 2621 | * Got race? |
| 2622 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2623 | * Until then, this create/open method is prone to inefficiency and race |
| 2624 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2625 | * placed on the wire. |
| 2626 | * |
| 2627 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2628 | * The file will be opened again in the subsequent VFS open call |
| 2629 | * (nfs4_proc_file_open). |
| 2630 | * |
| 2631 | * The open for read will just hang around to be used by any process that |
| 2632 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2633 | */ |
| 2634 | |
| 2635 | static int |
| 2636 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2637 | int flags, struct nfs_open_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2638 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2639 | struct dentry *de = dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 | struct nfs4_state *state; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2641 | struct rpc_cred *cred = NULL; |
| 2642 | fmode_t fmode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2643 | int status = 0; |
| 2644 | |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2645 | if (ctx != NULL) { |
| 2646 | cred = ctx->cred; |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2647 | de = ctx->dentry; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2648 | fmode = ctx->mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | } |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2650 | sattr->ia_mode &= ~current_umask(); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2651 | state = nfs4_do_open(dir, de, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2652 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | if (IS_ERR(state)) { |
| 2654 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2655 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2657 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2658 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2659 | if (ctx != NULL) |
| 2660 | ctx->state = state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2661 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2662 | nfs4_close_sync(state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | out: |
| 2664 | return status; |
| 2665 | } |
| 2666 | |
| 2667 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2668 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2669 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2670 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2672 | .name.len = name->len, |
| 2673 | .name.name = name->name, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2674 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2675 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2676 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2677 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2678 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2679 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2680 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2681 | .rpc_argp = &args, |
| 2682 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | }; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2684 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2686 | res.dir_attr = nfs_alloc_fattr(); |
| 2687 | if (res.dir_attr == NULL) |
| 2688 | goto out; |
| 2689 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2690 | 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] | 2691 | if (status == 0) { |
| 2692 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2693 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2694 | } |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2695 | nfs_free_fattr(res.dir_attr); |
| 2696 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2697 | return status; |
| 2698 | } |
| 2699 | |
| 2700 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2701 | { |
| 2702 | struct nfs4_exception exception = { }; |
| 2703 | int err; |
| 2704 | do { |
| 2705 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2706 | _nfs4_proc_remove(dir, name), |
| 2707 | &exception); |
| 2708 | } while (exception.retry); |
| 2709 | return err; |
| 2710 | } |
| 2711 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2712 | 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] | 2713 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2714 | struct nfs_server *server = NFS_SERVER(dir); |
| 2715 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2716 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2718 | args->bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2719 | res->server = server; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 2720 | res->seq_res.sr_slot = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2721 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | } |
| 2723 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2724 | 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] | 2725 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2726 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2727 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2728 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2729 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2730 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2731 | return 0; |
| 2732 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2733 | nfs_post_op_update_inode(dir, res->dir_attr); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2734 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | } |
| 2736 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2737 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2738 | { |
| 2739 | struct nfs_server *server = NFS_SERVER(dir); |
| 2740 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2741 | struct nfs_renameres *res = msg->rpc_resp; |
| 2742 | |
| 2743 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
| 2744 | arg->bitmask = server->attr_bitmask; |
| 2745 | res->server = server; |
| 2746 | } |
| 2747 | |
| 2748 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2749 | struct inode *new_dir) |
| 2750 | { |
| 2751 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2752 | |
| 2753 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2754 | return 0; |
| 2755 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2756 | return 0; |
| 2757 | |
| 2758 | update_changeattr(old_dir, &res->old_cinfo); |
| 2759 | nfs_post_op_update_inode(old_dir, res->old_fattr); |
| 2760 | update_changeattr(new_dir, &res->new_cinfo); |
| 2761 | nfs_post_op_update_inode(new_dir, res->new_fattr); |
| 2762 | return 1; |
| 2763 | } |
| 2764 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2766 | struct inode *new_dir, struct qstr *new_name) |
| 2767 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2768 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2769 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | .old_dir = NFS_FH(old_dir), |
| 2771 | .new_dir = NFS_FH(new_dir), |
| 2772 | .old_name = old_name, |
| 2773 | .new_name = new_name, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2774 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2776 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2777 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2778 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | struct rpc_message msg = { |
| 2780 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2781 | .rpc_argp = &arg, |
| 2782 | .rpc_resp = &res, |
| 2783 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2784 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2785 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2786 | res.old_fattr = nfs_alloc_fattr(); |
| 2787 | res.new_fattr = nfs_alloc_fattr(); |
| 2788 | if (res.old_fattr == NULL || res.new_fattr == NULL) |
| 2789 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2791 | 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] | 2792 | if (!status) { |
| 2793 | update_changeattr(old_dir, &res.old_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2794 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2795 | update_changeattr(new_dir, &res.new_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2796 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2797 | } |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2798 | out: |
| 2799 | nfs_free_fattr(res.new_fattr); |
| 2800 | nfs_free_fattr(res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | return status; |
| 2802 | } |
| 2803 | |
| 2804 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2805 | struct inode *new_dir, struct qstr *new_name) |
| 2806 | { |
| 2807 | struct nfs4_exception exception = { }; |
| 2808 | int err; |
| 2809 | do { |
| 2810 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2811 | _nfs4_proc_rename(old_dir, old_name, |
| 2812 | new_dir, new_name), |
| 2813 | &exception); |
| 2814 | } while (exception.retry); |
| 2815 | return err; |
| 2816 | } |
| 2817 | |
| 2818 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2819 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2820 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | struct nfs4_link_arg arg = { |
| 2822 | .fh = NFS_FH(inode), |
| 2823 | .dir_fh = NFS_FH(dir), |
| 2824 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2825 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2826 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2827 | struct nfs4_link_res res = { |
| 2828 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2829 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | struct rpc_message msg = { |
| 2831 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2832 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2833 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2835 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2837 | res.fattr = nfs_alloc_fattr(); |
| 2838 | res.dir_attr = nfs_alloc_fattr(); |
| 2839 | if (res.fattr == NULL || res.dir_attr == NULL) |
| 2840 | goto out; |
| 2841 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2842 | 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] | 2843 | if (!status) { |
| 2844 | update_changeattr(dir, &res.cinfo); |
| 2845 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2846 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2847 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2848 | out: |
| 2849 | nfs_free_fattr(res.dir_attr); |
| 2850 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | return status; |
| 2852 | } |
| 2853 | |
| 2854 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2855 | { |
| 2856 | struct nfs4_exception exception = { }; |
| 2857 | int err; |
| 2858 | do { |
| 2859 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2860 | _nfs4_proc_link(inode, dir, name), |
| 2861 | &exception); |
| 2862 | } while (exception.retry); |
| 2863 | return err; |
| 2864 | } |
| 2865 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2866 | struct nfs4_createdata { |
| 2867 | struct rpc_message msg; |
| 2868 | struct nfs4_create_arg arg; |
| 2869 | struct nfs4_create_res res; |
| 2870 | struct nfs_fh fh; |
| 2871 | struct nfs_fattr fattr; |
| 2872 | struct nfs_fattr dir_fattr; |
| 2873 | }; |
| 2874 | |
| 2875 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 2876 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 2877 | { |
| 2878 | struct nfs4_createdata *data; |
| 2879 | |
| 2880 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2881 | if (data != NULL) { |
| 2882 | struct nfs_server *server = NFS_SERVER(dir); |
| 2883 | |
| 2884 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 2885 | data->msg.rpc_argp = &data->arg; |
| 2886 | data->msg.rpc_resp = &data->res; |
| 2887 | data->arg.dir_fh = NFS_FH(dir); |
| 2888 | data->arg.server = server; |
| 2889 | data->arg.name = name; |
| 2890 | data->arg.attrs = sattr; |
| 2891 | data->arg.ftype = ftype; |
| 2892 | data->arg.bitmask = server->attr_bitmask; |
| 2893 | data->res.server = server; |
| 2894 | data->res.fh = &data->fh; |
| 2895 | data->res.fattr = &data->fattr; |
| 2896 | data->res.dir_fattr = &data->dir_fattr; |
| 2897 | nfs_fattr_init(data->res.fattr); |
| 2898 | nfs_fattr_init(data->res.dir_fattr); |
| 2899 | } |
| 2900 | return data; |
| 2901 | } |
| 2902 | |
| 2903 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 2904 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2905 | 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] | 2906 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2907 | if (status == 0) { |
| 2908 | update_changeattr(dir, &data->res.dir_cinfo); |
| 2909 | nfs_post_op_update_inode(dir, data->res.dir_fattr); |
| 2910 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 2911 | } |
| 2912 | return status; |
| 2913 | } |
| 2914 | |
| 2915 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 2916 | { |
| 2917 | kfree(data); |
| 2918 | } |
| 2919 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2920 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2921 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2923 | struct nfs4_createdata *data; |
| 2924 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2926 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2927 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2928 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2929 | status = -ENOMEM; |
| 2930 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 2931 | if (data == NULL) |
| 2932 | goto out; |
| 2933 | |
| 2934 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 2935 | data->arg.u.symlink.pages = &page; |
| 2936 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2937 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2938 | status = nfs4_do_create(dir, dentry, data); |
| 2939 | |
| 2940 | nfs4_free_createdata(data); |
| 2941 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | return status; |
| 2943 | } |
| 2944 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2945 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2946 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | { |
| 2948 | struct nfs4_exception exception = { }; |
| 2949 | int err; |
| 2950 | do { |
| 2951 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2952 | _nfs4_proc_symlink(dir, dentry, page, |
| 2953 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2954 | &exception); |
| 2955 | } while (exception.retry); |
| 2956 | return err; |
| 2957 | } |
| 2958 | |
| 2959 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2960 | struct iattr *sattr) |
| 2961 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2962 | struct nfs4_createdata *data; |
| 2963 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2964 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2965 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 2966 | if (data == NULL) |
| 2967 | goto out; |
| 2968 | |
| 2969 | status = nfs4_do_create(dir, dentry, data); |
| 2970 | |
| 2971 | nfs4_free_createdata(data); |
| 2972 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | return status; |
| 2974 | } |
| 2975 | |
| 2976 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2977 | struct iattr *sattr) |
| 2978 | { |
| 2979 | struct nfs4_exception exception = { }; |
| 2980 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2981 | |
| 2982 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2983 | do { |
| 2984 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2985 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 2986 | &exception); |
| 2987 | } while (exception.retry); |
| 2988 | return err; |
| 2989 | } |
| 2990 | |
| 2991 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2992 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2993 | { |
| 2994 | struct inode *dir = dentry->d_inode; |
| 2995 | struct nfs4_readdir_arg args = { |
| 2996 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2997 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | .pgbase = 0, |
| 2999 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3000 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3001 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | }; |
| 3003 | struct nfs4_readdir_res res; |
| 3004 | struct rpc_message msg = { |
| 3005 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3006 | .rpc_argp = &args, |
| 3007 | .rpc_resp = &res, |
| 3008 | .rpc_cred = cred, |
| 3009 | }; |
| 3010 | int status; |
| 3011 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3012 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3013 | dentry->d_parent->d_name.name, |
| 3014 | dentry->d_name.name, |
| 3015 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 3017 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3018 | 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] | 3019 | if (status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3020 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3021 | status += args.pgbase; |
| 3022 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3023 | |
| 3024 | nfs_invalidate_atime(dir); |
| 3025 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3026 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3027 | return status; |
| 3028 | } |
| 3029 | |
| 3030 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3031 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | { |
| 3033 | struct nfs4_exception exception = { }; |
| 3034 | int err; |
| 3035 | do { |
| 3036 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3037 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3038 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | &exception); |
| 3040 | } while (exception.retry); |
| 3041 | return err; |
| 3042 | } |
| 3043 | |
| 3044 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3045 | struct iattr *sattr, dev_t rdev) |
| 3046 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3047 | struct nfs4_createdata *data; |
| 3048 | int mode = sattr->ia_mode; |
| 3049 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | |
| 3051 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 3052 | 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] | 3053 | |
| 3054 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3055 | if (data == NULL) |
| 3056 | goto out; |
| 3057 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3059 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3061 | data->arg.ftype = NF4BLK; |
| 3062 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3063 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | } |
| 3065 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3066 | data->arg.ftype = NF4CHR; |
| 3067 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3068 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3069 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3071 | status = nfs4_do_create(dir, dentry, data); |
| 3072 | |
| 3073 | nfs4_free_createdata(data); |
| 3074 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3075 | return status; |
| 3076 | } |
| 3077 | |
| 3078 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3079 | struct iattr *sattr, dev_t rdev) |
| 3080 | { |
| 3081 | struct nfs4_exception exception = { }; |
| 3082 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3083 | |
| 3084 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | do { |
| 3086 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3087 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3088 | &exception); |
| 3089 | } while (exception.retry); |
| 3090 | return err; |
| 3091 | } |
| 3092 | |
| 3093 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3094 | struct nfs_fsstat *fsstat) |
| 3095 | { |
| 3096 | struct nfs4_statfs_arg args = { |
| 3097 | .fh = fhandle, |
| 3098 | .bitmask = server->attr_bitmask, |
| 3099 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3100 | struct nfs4_statfs_res res = { |
| 3101 | .fsstat = fsstat, |
| 3102 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | struct rpc_message msg = { |
| 3104 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3105 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3106 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3107 | }; |
| 3108 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3109 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3110 | 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] | 3111 | } |
| 3112 | |
| 3113 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3114 | { |
| 3115 | struct nfs4_exception exception = { }; |
| 3116 | int err; |
| 3117 | do { |
| 3118 | err = nfs4_handle_exception(server, |
| 3119 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3120 | &exception); |
| 3121 | } while (exception.retry); |
| 3122 | return err; |
| 3123 | } |
| 3124 | |
| 3125 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3126 | struct nfs_fsinfo *fsinfo) |
| 3127 | { |
| 3128 | struct nfs4_fsinfo_arg args = { |
| 3129 | .fh = fhandle, |
| 3130 | .bitmask = server->attr_bitmask, |
| 3131 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3132 | struct nfs4_fsinfo_res res = { |
| 3133 | .fsinfo = fsinfo, |
| 3134 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3135 | struct rpc_message msg = { |
| 3136 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3137 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3138 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | }; |
| 3140 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3141 | 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] | 3142 | } |
| 3143 | |
| 3144 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3145 | { |
| 3146 | struct nfs4_exception exception = { }; |
| 3147 | int err; |
| 3148 | |
| 3149 | do { |
| 3150 | err = nfs4_handle_exception(server, |
| 3151 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3152 | &exception); |
| 3153 | } while (exception.retry); |
| 3154 | return err; |
| 3155 | } |
| 3156 | |
| 3157 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3158 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3159 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3160 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3161 | } |
| 3162 | |
| 3163 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3164 | struct nfs_pathconf *pathconf) |
| 3165 | { |
| 3166 | struct nfs4_pathconf_arg args = { |
| 3167 | .fh = fhandle, |
| 3168 | .bitmask = server->attr_bitmask, |
| 3169 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3170 | struct nfs4_pathconf_res res = { |
| 3171 | .pathconf = pathconf, |
| 3172 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | struct rpc_message msg = { |
| 3174 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3175 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3176 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | }; |
| 3178 | |
| 3179 | /* None of the pathconf attributes are mandatory to implement */ |
| 3180 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3181 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3182 | return 0; |
| 3183 | } |
| 3184 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3185 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3186 | 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] | 3187 | } |
| 3188 | |
| 3189 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3190 | struct nfs_pathconf *pathconf) |
| 3191 | { |
| 3192 | struct nfs4_exception exception = { }; |
| 3193 | int err; |
| 3194 | |
| 3195 | do { |
| 3196 | err = nfs4_handle_exception(server, |
| 3197 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3198 | &exception); |
| 3199 | } while (exception.retry); |
| 3200 | return err; |
| 3201 | } |
| 3202 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3203 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3204 | { |
| 3205 | nfs_invalidate_atime(data->inode); |
| 3206 | } |
| 3207 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3208 | 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] | 3209 | { |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3210 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3211 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3212 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3213 | nfs_restart_rpc(task, server->nfs_client); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3214 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3215 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3216 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3217 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3219 | renew_lease(server, data->timestamp); |
| 3220 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | } |
| 3222 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3223 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3224 | { |
| 3225 | |
| 3226 | dprintk("--> %s\n", __func__); |
| 3227 | |
| 3228 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3229 | return -EAGAIN; |
| 3230 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3231 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3232 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3233 | } |
| 3234 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3235 | 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] | 3236 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3237 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3238 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3239 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | } |
| 3241 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3242 | /* Reset the the nfs_read_data to send the read to the MDS. */ |
| 3243 | void nfs4_reset_read(struct rpc_task *task, struct nfs_read_data *data) |
| 3244 | { |
| 3245 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3246 | put_lseg(data->lseg); |
| 3247 | data->lseg = NULL; |
| 3248 | /* offsets will differ in the dense stripe case */ |
| 3249 | data->args.offset = data->mds_offset; |
| 3250 | data->ds_clp = NULL; |
| 3251 | data->args.fh = NFS_FH(data->inode); |
| 3252 | data->read_done_cb = nfs4_read_done_cb; |
| 3253 | task->tk_ops = data->mds_ops; |
| 3254 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3255 | } |
| 3256 | EXPORT_SYMBOL_GPL(nfs4_reset_read); |
| 3257 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3258 | 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] | 3259 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | struct inode *inode = data->inode; |
| 3261 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3262 | 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] | 3263 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3264 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3266 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3267 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 3268 | nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3269 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3270 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3271 | } |
| 3272 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3273 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3274 | { |
| 3275 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3276 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3277 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3278 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3279 | } |
| 3280 | |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3281 | /* Reset the the nfs_write_data to send the write to the MDS. */ |
| 3282 | void nfs4_reset_write(struct rpc_task *task, struct nfs_write_data *data) |
| 3283 | { |
| 3284 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3285 | put_lseg(data->lseg); |
| 3286 | data->lseg = NULL; |
| 3287 | data->ds_clp = NULL; |
| 3288 | data->write_done_cb = nfs4_write_done_cb; |
| 3289 | data->args.fh = NFS_FH(data->inode); |
| 3290 | data->args.bitmask = data->res.server->cache_consistency_bitmask; |
| 3291 | data->args.offset = data->mds_offset; |
| 3292 | data->res.fattr = &data->fattr; |
| 3293 | task->tk_ops = data->mds_ops; |
| 3294 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3295 | } |
| 3296 | EXPORT_SYMBOL_GPL(nfs4_reset_write); |
| 3297 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3298 | 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] | 3299 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3300 | struct nfs_server *server = NFS_SERVER(data->inode); |
| 3301 | |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3302 | if (data->lseg) { |
| 3303 | data->args.bitmask = NULL; |
| 3304 | data->res.fattr = NULL; |
| 3305 | } else |
| 3306 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3307 | if (!data->write_done_cb) |
| 3308 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3309 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3310 | data->timestamp = jiffies; |
| 3311 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3312 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3313 | } |
| 3314 | |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3315 | 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] | 3316 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3317 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3318 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3319 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3320 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3321 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3322 | } |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 3323 | nfs_refresh_inode(inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3324 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3325 | } |
| 3326 | |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3327 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3328 | { |
| 3329 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3330 | return -EAGAIN; |
| 3331 | return data->write_done_cb(task, data); |
| 3332 | } |
| 3333 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3334 | 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] | 3335 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3336 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3337 | |
| 3338 | if (data->lseg) { |
| 3339 | data->args.bitmask = NULL; |
| 3340 | data->res.fattr = NULL; |
| 3341 | } else |
| 3342 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3343 | if (!data->write_done_cb) |
| 3344 | data->write_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3345 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3346 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3347 | } |
| 3348 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3349 | struct nfs4_renewdata { |
| 3350 | struct nfs_client *client; |
| 3351 | unsigned long timestamp; |
| 3352 | }; |
| 3353 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | /* |
| 3355 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3356 | * standalone procedure for queueing an asynchronous RENEW. |
| 3357 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3358 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3359 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3360 | struct nfs4_renewdata *data = calldata; |
| 3361 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3362 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3363 | if (atomic_read(&clp->cl_count) > 1) |
| 3364 | nfs4_schedule_state_renewal(clp); |
| 3365 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3366 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3367 | } |
| 3368 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3369 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3370 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3371 | struct nfs4_renewdata *data = calldata; |
| 3372 | struct nfs_client *clp = data->client; |
| 3373 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | |
| 3375 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3376 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3377 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3378 | return; |
| 3379 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3380 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3381 | return; |
| 3382 | } |
| 3383 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3384 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3385 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3386 | } |
| 3387 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3388 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3389 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3390 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3391 | }; |
| 3392 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3393 | static int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | { |
| 3395 | struct rpc_message msg = { |
| 3396 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3397 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3398 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3399 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3400 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3401 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3402 | if (renew_flags == 0) |
| 3403 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3404 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3405 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3406 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3407 | if (data == NULL) |
| 3408 | return -ENOMEM; |
| 3409 | data->client = clp; |
| 3410 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3411 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3412 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | } |
| 3414 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3415 | static int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3416 | { |
| 3417 | struct rpc_message msg = { |
| 3418 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3419 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3420 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | }; |
| 3422 | unsigned long now = jiffies; |
| 3423 | int status; |
| 3424 | |
| 3425 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3426 | if (status < 0) |
| 3427 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3428 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3429 | return 0; |
| 3430 | } |
| 3431 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3432 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3433 | { |
| 3434 | return (server->caps & NFS_CAP_ACLS) |
| 3435 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3436 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3437 | } |
| 3438 | |
| 3439 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3440 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3441 | * the stack. |
| 3442 | */ |
| 3443 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3444 | |
| 3445 | static void buf_to_pages(const void *buf, size_t buflen, |
| 3446 | struct page **pages, unsigned int *pgbase) |
| 3447 | { |
| 3448 | const void *p = buf; |
| 3449 | |
| 3450 | *pgbase = offset_in_page(buf); |
| 3451 | p -= *pgbase; |
| 3452 | while (p < buf + buflen) { |
| 3453 | *(pages++) = virt_to_page(p); |
| 3454 | p += PAGE_CACHE_SIZE; |
| 3455 | } |
| 3456 | } |
| 3457 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3458 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3459 | struct page **pages, unsigned int *pgbase) |
| 3460 | { |
| 3461 | struct page *newpage, **spages; |
| 3462 | int rc = 0; |
| 3463 | size_t len; |
| 3464 | spages = pages; |
| 3465 | |
| 3466 | do { |
Jovi Zhang | 43b7c3f | 2011-03-02 23:19:37 +0000 | [diff] [blame] | 3467 | len = min_t(size_t, PAGE_CACHE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3468 | newpage = alloc_page(GFP_KERNEL); |
| 3469 | |
| 3470 | if (newpage == NULL) |
| 3471 | goto unwind; |
| 3472 | memcpy(page_address(newpage), buf, len); |
| 3473 | buf += len; |
| 3474 | buflen -= len; |
| 3475 | *pages++ = newpage; |
| 3476 | rc++; |
| 3477 | } while (buflen != 0); |
| 3478 | |
| 3479 | return rc; |
| 3480 | |
| 3481 | unwind: |
| 3482 | for(; rc > 0; rc--) |
| 3483 | __free_page(spages[rc-1]); |
| 3484 | return -ENOMEM; |
| 3485 | } |
| 3486 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3487 | struct nfs4_cached_acl { |
| 3488 | int cached; |
| 3489 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3490 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3491 | }; |
| 3492 | |
| 3493 | 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] | 3494 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3495 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3496 | |
| 3497 | spin_lock(&inode->i_lock); |
| 3498 | kfree(nfsi->nfs4_acl); |
| 3499 | nfsi->nfs4_acl = acl; |
| 3500 | spin_unlock(&inode->i_lock); |
| 3501 | } |
| 3502 | |
| 3503 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3504 | { |
| 3505 | nfs4_set_cached_acl(inode, NULL); |
| 3506 | } |
| 3507 | |
| 3508 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3509 | { |
| 3510 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3511 | struct nfs4_cached_acl *acl; |
| 3512 | int ret = -ENOENT; |
| 3513 | |
| 3514 | spin_lock(&inode->i_lock); |
| 3515 | acl = nfsi->nfs4_acl; |
| 3516 | if (acl == NULL) |
| 3517 | goto out; |
| 3518 | if (buf == NULL) /* user is just asking for length */ |
| 3519 | goto out_len; |
| 3520 | if (acl->cached == 0) |
| 3521 | goto out; |
| 3522 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3523 | if (acl->len > buflen) |
| 3524 | goto out; |
| 3525 | memcpy(buf, acl->data, acl->len); |
| 3526 | out_len: |
| 3527 | ret = acl->len; |
| 3528 | out: |
| 3529 | spin_unlock(&inode->i_lock); |
| 3530 | return ret; |
| 3531 | } |
| 3532 | |
| 3533 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) |
| 3534 | { |
| 3535 | struct nfs4_cached_acl *acl; |
| 3536 | |
| 3537 | if (buf && acl_len <= PAGE_SIZE) { |
| 3538 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3539 | if (acl == NULL) |
| 3540 | goto out; |
| 3541 | acl->cached = 1; |
| 3542 | memcpy(acl->data, buf, acl_len); |
| 3543 | } else { |
| 3544 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3545 | if (acl == NULL) |
| 3546 | goto out; |
| 3547 | acl->cached = 0; |
| 3548 | } |
| 3549 | acl->len = acl_len; |
| 3550 | out: |
| 3551 | nfs4_set_cached_acl(inode, acl); |
| 3552 | } |
| 3553 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3554 | 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] | 3555 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3556 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3557 | struct nfs_getaclargs args = { |
| 3558 | .fh = NFS_FH(inode), |
| 3559 | .acl_pages = pages, |
| 3560 | .acl_len = buflen, |
| 3561 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3562 | struct nfs_getaclres res = { |
| 3563 | .acl_len = buflen, |
| 3564 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3565 | void *resp_buf; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3566 | struct rpc_message msg = { |
| 3567 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3568 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3569 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3570 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3571 | struct page *localpage = NULL; |
| 3572 | int ret; |
| 3573 | |
| 3574 | if (buflen < PAGE_SIZE) { |
| 3575 | /* As long as we're doing a round trip to the server anyway, |
| 3576 | * let's be prepared for a page of acl data. */ |
| 3577 | localpage = alloc_page(GFP_KERNEL); |
| 3578 | resp_buf = page_address(localpage); |
| 3579 | if (localpage == NULL) |
| 3580 | return -ENOMEM; |
| 3581 | args.acl_pages[0] = localpage; |
| 3582 | args.acl_pgbase = 0; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3583 | args.acl_len = PAGE_SIZE; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3584 | } else { |
| 3585 | resp_buf = buf; |
| 3586 | buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase); |
| 3587 | } |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3588 | 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] | 3589 | if (ret) |
| 3590 | goto out_free; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3591 | if (res.acl_len > args.acl_len) |
| 3592 | nfs4_write_cached_acl(inode, NULL, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3593 | else |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3594 | nfs4_write_cached_acl(inode, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3595 | if (buf) { |
| 3596 | ret = -ERANGE; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3597 | if (res.acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3598 | goto out_free; |
| 3599 | if (localpage) |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3600 | memcpy(buf, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3601 | } |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3602 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3603 | out_free: |
| 3604 | if (localpage) |
| 3605 | __free_page(localpage); |
| 3606 | return ret; |
| 3607 | } |
| 3608 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3609 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3610 | { |
| 3611 | struct nfs4_exception exception = { }; |
| 3612 | ssize_t ret; |
| 3613 | do { |
| 3614 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3615 | if (ret >= 0) |
| 3616 | break; |
| 3617 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3618 | } while (exception.retry); |
| 3619 | return ret; |
| 3620 | } |
| 3621 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3622 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3623 | { |
| 3624 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3625 | int ret; |
| 3626 | |
| 3627 | if (!nfs4_server_supports_acls(server)) |
| 3628 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3629 | ret = nfs_revalidate_inode(server, inode); |
| 3630 | if (ret < 0) |
| 3631 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3632 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3633 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3634 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3635 | if (ret != -ENOENT) |
| 3636 | return ret; |
| 3637 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3638 | } |
| 3639 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3640 | 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] | 3641 | { |
| 3642 | struct nfs_server *server = NFS_SERVER(inode); |
| 3643 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3644 | struct nfs_setaclargs arg = { |
| 3645 | .fh = NFS_FH(inode), |
| 3646 | .acl_pages = pages, |
| 3647 | .acl_len = buflen, |
| 3648 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3649 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3650 | struct rpc_message msg = { |
| 3651 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3652 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3653 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3654 | }; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3655 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3656 | |
| 3657 | if (!nfs4_server_supports_acls(server)) |
| 3658 | return -EOPNOTSUPP; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3659 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3660 | if (i < 0) |
| 3661 | return i; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3662 | nfs_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3663 | 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] | 3664 | |
| 3665 | /* |
| 3666 | * Free each page after tx, so the only ref left is |
| 3667 | * held by the network stack |
| 3668 | */ |
| 3669 | for (; i > 0; i--) |
| 3670 | put_page(pages[i-1]); |
| 3671 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3672 | /* |
| 3673 | * Acl update can result in inode attribute update. |
| 3674 | * so mark the attribute cache invalid. |
| 3675 | */ |
| 3676 | spin_lock(&inode->i_lock); |
| 3677 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3678 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3679 | nfs_access_zap_cache(inode); |
| 3680 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3681 | return ret; |
| 3682 | } |
| 3683 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3684 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3685 | { |
| 3686 | struct nfs4_exception exception = { }; |
| 3687 | int err; |
| 3688 | do { |
| 3689 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3690 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3691 | &exception); |
| 3692 | } while (exception.retry); |
| 3693 | return err; |
| 3694 | } |
| 3695 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3697 | 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] | 3698 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3699 | struct nfs_client *clp = server->nfs_client; |
| 3700 | |
| 3701 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3702 | return 0; |
| 3703 | switch(task->tk_status) { |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3704 | case -NFS4ERR_ADMIN_REVOKED: |
| 3705 | case -NFS4ERR_BAD_STATEID: |
| 3706 | case -NFS4ERR_OPENMODE: |
| 3707 | if (state == NULL) |
| 3708 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3709 | nfs4_schedule_stateid_recovery(server, state); |
| 3710 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 3711 | case -NFS4ERR_EXPIRED: |
| 3712 | if (state != NULL) |
| 3713 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3714 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3715 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3716 | nfs4_schedule_lease_recovery(clp); |
| 3717 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3718 | #if defined(CONFIG_NFS_V4_1) |
| 3719 | case -NFS4ERR_BADSESSION: |
| 3720 | case -NFS4ERR_BADSLOT: |
| 3721 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3722 | case -NFS4ERR_DEADSESSION: |
| 3723 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3724 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3725 | case -NFS4ERR_SEQ_MISORDERED: |
| 3726 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3727 | task->tk_status); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3728 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3729 | task->tk_status = 0; |
| 3730 | return -EAGAIN; |
| 3731 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3732 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3733 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3734 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3735 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3736 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3737 | task->tk_status = 0; |
| 3738 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 3739 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3740 | case -NFS4ERR_OLD_STATEID: |
| 3741 | task->tk_status = 0; |
| 3742 | return -EAGAIN; |
| 3743 | } |
| 3744 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3745 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3746 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3747 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3748 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3749 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3750 | task->tk_status = 0; |
| 3751 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3752 | } |
| 3753 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3754 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 3755 | unsigned short port, struct rpc_cred *cred, |
| 3756 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3757 | { |
| 3758 | nfs4_verifier sc_verifier; |
| 3759 | struct nfs4_setclientid setclientid = { |
| 3760 | .sc_verifier = &sc_verifier, |
| 3761 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 3762 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3763 | }; |
| 3764 | struct rpc_message msg = { |
| 3765 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3766 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3767 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3768 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3769 | }; |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3770 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3771 | int loop = 0; |
| 3772 | int status; |
| 3773 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3774 | p = (__be32*)sc_verifier.data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 3776 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 3777 | |
| 3778 | for(;;) { |
| 3779 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3780 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3781 | clp->cl_ipaddr, |
| 3782 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3783 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3784 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3785 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3786 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3787 | clp->cl_id_uniquifier); |
| 3788 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3789 | sizeof(setclientid.sc_netid), |
| 3790 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3791 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3793 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3794 | clp->cl_ipaddr, port >> 8, port & 255); |
| 3795 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 3796 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3797 | if (status != -NFS4ERR_CLID_INUSE) |
| 3798 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3799 | if (loop != 0) { |
| 3800 | ++clp->cl_id_uniquifier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3801 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3802 | } |
| 3803 | ++loop; |
| 3804 | ssleep(clp->cl_lease_time / HZ + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3805 | } |
| 3806 | return status; |
| 3807 | } |
| 3808 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3809 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3810 | struct nfs4_setclientid_res *arg, |
| 3811 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | { |
| 3813 | struct nfs_fsinfo fsinfo; |
| 3814 | struct rpc_message msg = { |
| 3815 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3816 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3817 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3818 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | }; |
| 3820 | unsigned long now; |
| 3821 | int status; |
| 3822 | |
| 3823 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 3824 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3825 | if (status == 0) { |
| 3826 | spin_lock(&clp->cl_lock); |
| 3827 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 3828 | clp->cl_last_renewal = now; |
| 3829 | spin_unlock(&clp->cl_lock); |
| 3830 | } |
| 3831 | return status; |
| 3832 | } |
| 3833 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3834 | struct nfs4_delegreturndata { |
| 3835 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3836 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3837 | struct nfs_fh fh; |
| 3838 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3839 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3840 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3841 | int rpc_status; |
| 3842 | }; |
| 3843 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3844 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 3845 | { |
| 3846 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3847 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3848 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3849 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3850 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3851 | switch (task->tk_status) { |
| 3852 | case -NFS4ERR_STALE_STATEID: |
| 3853 | case -NFS4ERR_EXPIRED: |
| 3854 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3855 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3856 | break; |
| 3857 | default: |
| 3858 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 3859 | -EAGAIN) { |
| 3860 | nfs_restart_rpc(task, data->res.server->nfs_client); |
| 3861 | return; |
| 3862 | } |
| 3863 | } |
| 3864 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3865 | } |
| 3866 | |
| 3867 | static void nfs4_delegreturn_release(void *calldata) |
| 3868 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3869 | kfree(calldata); |
| 3870 | } |
| 3871 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3872 | #if defined(CONFIG_NFS_V4_1) |
| 3873 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 3874 | { |
| 3875 | struct nfs4_delegreturndata *d_data; |
| 3876 | |
| 3877 | d_data = (struct nfs4_delegreturndata *)data; |
| 3878 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3879 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3880 | &d_data->args.seq_args, |
| 3881 | &d_data->res.seq_res, 1, task)) |
| 3882 | return; |
| 3883 | rpc_call_start(task); |
| 3884 | } |
| 3885 | #endif /* CONFIG_NFS_V4_1 */ |
| 3886 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 3887 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3888 | #if defined(CONFIG_NFS_V4_1) |
| 3889 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 3890 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3891 | .rpc_call_done = nfs4_delegreturn_done, |
| 3892 | .rpc_release = nfs4_delegreturn_release, |
| 3893 | }; |
| 3894 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3895 | 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] | 3896 | { |
| 3897 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3898 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3899 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3900 | struct rpc_message msg = { |
| 3901 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 3902 | .rpc_cred = cred, |
| 3903 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3904 | struct rpc_task_setup task_setup_data = { |
| 3905 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3906 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3907 | .callback_ops = &nfs4_delegreturn_ops, |
| 3908 | .flags = RPC_TASK_ASYNC, |
| 3909 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3910 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3911 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3912 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3913 | if (data == NULL) |
| 3914 | return -ENOMEM; |
| 3915 | data->args.fhandle = &data->fh; |
| 3916 | data->args.stateid = &data->stateid; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3917 | data->args.bitmask = server->attr_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3918 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
| 3919 | memcpy(&data->stateid, stateid, sizeof(data->stateid)); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3920 | data->res.fattr = &data->fattr; |
| 3921 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3922 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3923 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3924 | data->rpc_status = 0; |
| 3925 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3926 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3927 | msg.rpc_argp = &data->args; |
| 3928 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3929 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 3930 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3931 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3932 | if (!issync) |
| 3933 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3934 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3935 | if (status != 0) |
| 3936 | goto out; |
| 3937 | status = data->rpc_status; |
| 3938 | if (status != 0) |
| 3939 | goto out; |
| 3940 | nfs_refresh_inode(inode, &data->fattr); |
| 3941 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3942 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3943 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3944 | } |
| 3945 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3946 | 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] | 3947 | { |
| 3948 | struct nfs_server *server = NFS_SERVER(inode); |
| 3949 | struct nfs4_exception exception = { }; |
| 3950 | int err; |
| 3951 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3952 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3953 | switch (err) { |
| 3954 | case -NFS4ERR_STALE_STATEID: |
| 3955 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3956 | case 0: |
| 3957 | return 0; |
| 3958 | } |
| 3959 | err = nfs4_handle_exception(server, err, &exception); |
| 3960 | } while (exception.retry); |
| 3961 | return err; |
| 3962 | } |
| 3963 | |
| 3964 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 3965 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 3966 | |
| 3967 | /* |
| 3968 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 3969 | */ |
| 3970 | static unsigned long |
| 3971 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 3972 | { |
Matthew Wilcox | 150030b | 2007-12-06 16:24:39 -0500 | [diff] [blame] | 3973 | schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3974 | timeout <<= 1; |
| 3975 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 3976 | return NFS4_LOCK_MAXTIMEOUT; |
| 3977 | return timeout; |
| 3978 | } |
| 3979 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3980 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3981 | { |
| 3982 | struct inode *inode = state->inode; |
| 3983 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3984 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3985 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3986 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3987 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3988 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3989 | struct nfs_lockt_res res = { |
| 3990 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3991 | }; |
| 3992 | struct rpc_message msg = { |
| 3993 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 3994 | .rpc_argp = &arg, |
| 3995 | .rpc_resp = &res, |
| 3996 | .rpc_cred = state->owner->so_cred, |
| 3997 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3998 | struct nfs4_lock_state *lsp; |
| 3999 | int status; |
| 4000 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4001 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4002 | status = nfs4_set_lock_state(state, request); |
| 4003 | if (status != 0) |
| 4004 | goto out; |
| 4005 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 4006 | arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4007 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4008 | 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] | 4009 | switch (status) { |
| 4010 | case 0: |
| 4011 | request->fl_type = F_UNLCK; |
| 4012 | break; |
| 4013 | case -NFS4ERR_DENIED: |
| 4014 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4015 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4016 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4017 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4018 | return status; |
| 4019 | } |
| 4020 | |
| 4021 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4022 | { |
| 4023 | struct nfs4_exception exception = { }; |
| 4024 | int err; |
| 4025 | |
| 4026 | do { |
| 4027 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4028 | _nfs4_proc_getlk(state, cmd, request), |
| 4029 | &exception); |
| 4030 | } while (exception.retry); |
| 4031 | return err; |
| 4032 | } |
| 4033 | |
| 4034 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4035 | { |
| 4036 | int res = 0; |
| 4037 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4038 | case FL_POSIX: |
| 4039 | res = posix_lock_file_wait(file, fl); |
| 4040 | break; |
| 4041 | case FL_FLOCK: |
| 4042 | res = flock_lock_file_wait(file, fl); |
| 4043 | break; |
| 4044 | default: |
| 4045 | BUG(); |
| 4046 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | return res; |
| 4048 | } |
| 4049 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4050 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4051 | struct nfs_locku_args arg; |
| 4052 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4053 | struct nfs4_lock_state *lsp; |
| 4054 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4055 | struct file_lock fl; |
| 4056 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4057 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4058 | }; |
| 4059 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4060 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4061 | struct nfs_open_context *ctx, |
| 4062 | struct nfs4_lock_state *lsp, |
| 4063 | struct nfs_seqid *seqid) |
| 4064 | { |
| 4065 | struct nfs4_unlockdata *p; |
| 4066 | struct inode *inode = lsp->ls_state->inode; |
| 4067 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4068 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4069 | if (p == NULL) |
| 4070 | return NULL; |
| 4071 | p->arg.fh = NFS_FH(inode); |
| 4072 | p->arg.fl = &p->fl; |
| 4073 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4074 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4075 | p->arg.stateid = &lsp->ls_stateid; |
| 4076 | p->lsp = lsp; |
| 4077 | atomic_inc(&lsp->ls_count); |
| 4078 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4079 | p->ctx = get_nfs_open_context(ctx); |
| 4080 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4081 | p->server = NFS_SERVER(inode); |
| 4082 | return p; |
| 4083 | } |
| 4084 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4085 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4086 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4087 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4088 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4089 | nfs4_put_lock_state(calldata->lsp); |
| 4090 | put_nfs_open_context(calldata->ctx); |
| 4091 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4092 | } |
| 4093 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4094 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4095 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4096 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4097 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4098 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4099 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4100 | switch (task->tk_status) { |
| 4101 | case 0: |
| 4102 | memcpy(calldata->lsp->ls_stateid.data, |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4103 | calldata->res.stateid.data, |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4104 | sizeof(calldata->lsp->ls_stateid.data)); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4105 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4106 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4107 | case -NFS4ERR_BAD_STATEID: |
| 4108 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4109 | case -NFS4ERR_STALE_STATEID: |
| 4110 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4111 | break; |
| 4112 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4113 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 4114 | nfs_restart_rpc(task, |
Trond Myklebust | d61e612 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 4115 | calldata->server->nfs_client); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4116 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4117 | } |
| 4118 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4119 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4120 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4121 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4122 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4123 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4124 | return; |
| 4125 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4126 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4127 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4128 | return; |
| 4129 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4130 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4131 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4132 | &calldata->arg.seq_args, |
| 4133 | &calldata->res.seq_res, 1, task)) |
| 4134 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4135 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4136 | } |
| 4137 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4138 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4139 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4140 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4141 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4142 | }; |
| 4143 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4144 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4145 | struct nfs_open_context *ctx, |
| 4146 | struct nfs4_lock_state *lsp, |
| 4147 | struct nfs_seqid *seqid) |
| 4148 | { |
| 4149 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4150 | struct rpc_message msg = { |
| 4151 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4152 | .rpc_cred = ctx->cred, |
| 4153 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4154 | struct rpc_task_setup task_setup_data = { |
| 4155 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4156 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4157 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4158 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4159 | .flags = RPC_TASK_ASYNC, |
| 4160 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4161 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4162 | /* Ensure this is an unlock - when canceling a lock, the |
| 4163 | * canceled lock is passed in, and it won't be an unlock. |
| 4164 | */ |
| 4165 | fl->fl_type = F_UNLCK; |
| 4166 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4167 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4168 | if (data == NULL) { |
| 4169 | nfs_free_seqid(seqid); |
| 4170 | return ERR_PTR(-ENOMEM); |
| 4171 | } |
| 4172 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4173 | msg.rpc_argp = &data->arg; |
| 4174 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4175 | task_setup_data.callback_data = data; |
| 4176 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4177 | } |
| 4178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4180 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4181 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4182 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4183 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4184 | struct rpc_task *task; |
| 4185 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4186 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4187 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4188 | status = nfs4_set_lock_state(state, request); |
| 4189 | /* Unlock _before_ we do the RPC call */ |
| 4190 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4191 | down_read(&nfsi->rwsem); |
| 4192 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4193 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4194 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4195 | } |
| 4196 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4197 | if (status != 0) |
| 4198 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4199 | /* Is this a delegated lock? */ |
| 4200 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4201 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4202 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4203 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4204 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4205 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4206 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4207 | 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] | 4208 | status = PTR_ERR(task); |
| 4209 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4210 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4211 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4212 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4213 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4214 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4215 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4216 | } |
| 4217 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4218 | struct nfs4_lockdata { |
| 4219 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4220 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4221 | struct nfs4_lock_state *lsp; |
| 4222 | struct nfs_open_context *ctx; |
| 4223 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4224 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4225 | int rpc_status; |
| 4226 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4227 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4228 | }; |
| 4229 | |
| 4230 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4231 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4232 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4233 | { |
| 4234 | struct nfs4_lockdata *p; |
| 4235 | struct inode *inode = lsp->ls_state->inode; |
| 4236 | struct nfs_server *server = NFS_SERVER(inode); |
| 4237 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4238 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4239 | if (p == NULL) |
| 4240 | return NULL; |
| 4241 | |
| 4242 | p->arg.fh = NFS_FH(inode); |
| 4243 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4244 | 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] | 4245 | if (p->arg.open_seqid == NULL) |
| 4246 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4247 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4248 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4249 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4250 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4251 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 4252 | p->arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4253 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4254 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4255 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4256 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4257 | atomic_inc(&lsp->ls_count); |
| 4258 | p->ctx = get_nfs_open_context(ctx); |
| 4259 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4260 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4261 | out_free_seqid: |
| 4262 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4263 | out_free: |
| 4264 | kfree(p); |
| 4265 | return NULL; |
| 4266 | } |
| 4267 | |
| 4268 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4269 | { |
| 4270 | struct nfs4_lockdata *data = calldata; |
| 4271 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4272 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4273 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4274 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4275 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4276 | /* Do we need to do an open_to_lock_owner? */ |
| 4277 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4278 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4279 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4280 | data->arg.open_stateid = &state->stateid; |
| 4281 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4282 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4283 | } else |
| 4284 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4285 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4286 | if (nfs4_setup_sequence(data->server, |
| 4287 | &data->arg.seq_args, |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4288 | &data->res.seq_res, 1, task)) |
| 4289 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4290 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4291 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4292 | } |
| 4293 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4294 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4295 | { |
| 4296 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4297 | nfs4_lock_prepare(task, calldata); |
| 4298 | } |
| 4299 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4300 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4301 | { |
| 4302 | struct nfs4_lockdata *data = calldata; |
| 4303 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4304 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4305 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4306 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4307 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4308 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4309 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4310 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4311 | if (data->rpc_status == 0) |
| 4312 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4313 | else |
| 4314 | goto out; |
| 4315 | } |
| 4316 | if (data->rpc_status == 0) { |
| 4317 | memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, |
| 4318 | sizeof(data->lsp->ls_stateid.data)); |
| 4319 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4320 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4321 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4322 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4323 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4324 | } |
| 4325 | |
| 4326 | static void nfs4_lock_release(void *calldata) |
| 4327 | { |
| 4328 | struct nfs4_lockdata *data = calldata; |
| 4329 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4330 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4331 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4332 | if (data->cancelled != 0) { |
| 4333 | struct rpc_task *task; |
| 4334 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4335 | data->arg.lock_seqid); |
| 4336 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4337 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4338 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4339 | } else |
| 4340 | nfs_free_seqid(data->arg.lock_seqid); |
| 4341 | nfs4_put_lock_state(data->lsp); |
| 4342 | put_nfs_open_context(data->ctx); |
| 4343 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4344 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4345 | } |
| 4346 | |
| 4347 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4348 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4349 | .rpc_call_done = nfs4_lock_done, |
| 4350 | .rpc_release = nfs4_lock_release, |
| 4351 | }; |
| 4352 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4353 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4354 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4355 | .rpc_call_done = nfs4_lock_done, |
| 4356 | .rpc_release = nfs4_lock_release, |
| 4357 | }; |
| 4358 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4359 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4360 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4361 | switch (error) { |
| 4362 | case -NFS4ERR_ADMIN_REVOKED: |
| 4363 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4364 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4365 | if (new_lock_owner != 0 || |
| 4366 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4367 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4368 | break; |
| 4369 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4370 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4371 | case -NFS4ERR_EXPIRED: |
| 4372 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4373 | }; |
| 4374 | } |
| 4375 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4376 | 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] | 4377 | { |
| 4378 | struct nfs4_lockdata *data; |
| 4379 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4380 | struct rpc_message msg = { |
| 4381 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4382 | .rpc_cred = state->owner->so_cred, |
| 4383 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4384 | struct rpc_task_setup task_setup_data = { |
| 4385 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4386 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4387 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4388 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4389 | .flags = RPC_TASK_ASYNC, |
| 4390 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4391 | int ret; |
| 4392 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4393 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4394 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4395 | fl->fl_u.nfs4_fl.owner, |
| 4396 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4397 | if (data == NULL) |
| 4398 | return -ENOMEM; |
| 4399 | if (IS_SETLKW(cmd)) |
| 4400 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4401 | if (recovery_type > NFS_LOCK_NEW) { |
| 4402 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4403 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4404 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4405 | } |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4406 | msg.rpc_argp = &data->arg; |
| 4407 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4408 | task_setup_data.callback_data = data; |
| 4409 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4410 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4411 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4412 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4413 | if (ret == 0) { |
| 4414 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4415 | if (ret) |
| 4416 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4417 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4418 | } else |
| 4419 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4420 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4421 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4422 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4423 | } |
| 4424 | |
| 4425 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4426 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4427 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4428 | struct nfs4_exception exception = { }; |
| 4429 | int err; |
| 4430 | |
| 4431 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4432 | /* Cache the lock if possible... */ |
| 4433 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4434 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4435 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4436 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4437 | break; |
| 4438 | nfs4_handle_exception(server, err, &exception); |
| 4439 | } while (exception.retry); |
| 4440 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4441 | } |
| 4442 | |
| 4443 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4444 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4445 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4446 | struct nfs4_exception exception = { }; |
| 4447 | int err; |
| 4448 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4449 | err = nfs4_set_lock_state(state, request); |
| 4450 | if (err != 0) |
| 4451 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4452 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4453 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4454 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4455 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4456 | switch (err) { |
| 4457 | default: |
| 4458 | goto out; |
| 4459 | case -NFS4ERR_GRACE: |
| 4460 | case -NFS4ERR_DELAY: |
| 4461 | nfs4_handle_exception(server, err, &exception); |
| 4462 | err = 0; |
| 4463 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4464 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4465 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4466 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4467 | } |
| 4468 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4469 | #if defined(CONFIG_NFS_V4_1) |
| 4470 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4471 | { |
| 4472 | int status; |
| 4473 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4474 | |
| 4475 | status = nfs41_test_stateid(server, state); |
| 4476 | if (status == NFS_OK) |
| 4477 | return 0; |
| 4478 | nfs41_free_stateid(server, state); |
| 4479 | return nfs4_lock_expired(state, request); |
| 4480 | } |
| 4481 | #endif |
| 4482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4483 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4484 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4485 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4486 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4487 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4488 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4489 | if ((fl_flags & FL_POSIX) && |
| 4490 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4491 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4492 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4493 | status = nfs4_set_lock_state(state, request); |
| 4494 | if (status != 0) |
| 4495 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4496 | request->fl_flags |= FL_ACCESS; |
| 4497 | status = do_vfs_lock(request->fl_file, request); |
| 4498 | if (status < 0) |
| 4499 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4500 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4501 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4502 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4503 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4504 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4505 | status = do_vfs_lock(request->fl_file, request); |
| 4506 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4507 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4508 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4509 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4510 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4511 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4512 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4513 | if (do_vfs_lock(request->fl_file, request) < 0) |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4514 | 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] | 4515 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4516 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4517 | out: |
| 4518 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4519 | return status; |
| 4520 | } |
| 4521 | |
| 4522 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4523 | { |
| 4524 | struct nfs4_exception exception = { }; |
| 4525 | int err; |
| 4526 | |
| 4527 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4528 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4529 | if (err == -NFS4ERR_DENIED) |
| 4530 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4531 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4532 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4533 | } while (exception.retry); |
| 4534 | return err; |
| 4535 | } |
| 4536 | |
| 4537 | static int |
| 4538 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4539 | { |
| 4540 | struct nfs_open_context *ctx; |
| 4541 | struct nfs4_state *state; |
| 4542 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4543 | int status; |
| 4544 | |
| 4545 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4546 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4547 | state = ctx->state; |
| 4548 | |
| 4549 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4550 | return -EINVAL; |
| 4551 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4552 | if (IS_GETLK(cmd)) { |
| 4553 | if (state != NULL) |
| 4554 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4555 | return 0; |
| 4556 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4557 | |
| 4558 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4559 | return -EINVAL; |
| 4560 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4561 | if (request->fl_type == F_UNLCK) { |
| 4562 | if (state != NULL) |
| 4563 | return nfs4_proc_unlck(state, cmd, request); |
| 4564 | return 0; |
| 4565 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4566 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4567 | if (state == NULL) |
| 4568 | return -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4569 | do { |
| 4570 | status = nfs4_proc_setlk(state, cmd, request); |
| 4571 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4572 | break; |
| 4573 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4574 | status = -ERESTARTSYS; |
| 4575 | if (signalled()) |
| 4576 | break; |
| 4577 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4578 | return status; |
| 4579 | } |
| 4580 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4581 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4582 | { |
| 4583 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4584 | struct nfs4_exception exception = { }; |
| 4585 | int err; |
| 4586 | |
| 4587 | err = nfs4_set_lock_state(state, fl); |
| 4588 | if (err != 0) |
| 4589 | goto out; |
| 4590 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4591 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4592 | switch (err) { |
| 4593 | default: |
| 4594 | printk(KERN_ERR "%s: unhandled error %d.\n", |
| 4595 | __func__, err); |
| 4596 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4597 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4598 | goto out; |
| 4599 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4600 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4601 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4602 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4603 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4604 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4605 | case -NFS4ERR_BADSESSION: |
| 4606 | case -NFS4ERR_BADSLOT: |
| 4607 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4608 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4609 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4610 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4611 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4612 | case -ERESTARTSYS: |
| 4613 | /* |
| 4614 | * The show must go on: exit, but mark the |
| 4615 | * stateid as needing recovery. |
| 4616 | */ |
| 4617 | case -NFS4ERR_ADMIN_REVOKED: |
| 4618 | case -NFS4ERR_BAD_STATEID: |
| 4619 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4620 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4621 | err = 0; |
| 4622 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4623 | case -EKEYEXPIRED: |
| 4624 | /* |
| 4625 | * User RPCSEC_GSS context has expired. |
| 4626 | * We cannot recover this stateid now, so |
| 4627 | * skip it and allow recovery thread to |
| 4628 | * proceed. |
| 4629 | */ |
| 4630 | err = 0; |
| 4631 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4632 | case -ENOMEM: |
| 4633 | case -NFS4ERR_DENIED: |
| 4634 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4635 | err = 0; |
| 4636 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4637 | case -NFS4ERR_DELAY: |
| 4638 | break; |
| 4639 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4640 | err = nfs4_handle_exception(server, err, &exception); |
| 4641 | } while (exception.retry); |
| 4642 | out: |
| 4643 | return err; |
| 4644 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4645 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4646 | static void nfs4_release_lockowner_release(void *calldata) |
| 4647 | { |
| 4648 | kfree(calldata); |
| 4649 | } |
| 4650 | |
| 4651 | const struct rpc_call_ops nfs4_release_lockowner_ops = { |
| 4652 | .rpc_release = nfs4_release_lockowner_release, |
| 4653 | }; |
| 4654 | |
| 4655 | void nfs4_release_lockowner(const struct nfs4_lock_state *lsp) |
| 4656 | { |
| 4657 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
| 4658 | struct nfs_release_lockowner_args *args; |
| 4659 | struct rpc_message msg = { |
| 4660 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 4661 | }; |
| 4662 | |
| 4663 | if (server->nfs_client->cl_mvops->minor_version != 0) |
| 4664 | return; |
| 4665 | args = kmalloc(sizeof(*args), GFP_NOFS); |
| 4666 | if (!args) |
| 4667 | return; |
| 4668 | args->lock_owner.clientid = server->nfs_client->cl_clientid; |
| 4669 | args->lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4670 | args->lock_owner.s_dev = server->s_dev; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4671 | msg.rpc_argp = args; |
| 4672 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args); |
| 4673 | } |
| 4674 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4675 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4676 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4677 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 4678 | const void *buf, size_t buflen, |
| 4679 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4680 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4681 | if (strcmp(key, "") != 0) |
| 4682 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4683 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4684 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4685 | } |
| 4686 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4687 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 4688 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4689 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4690 | if (strcmp(key, "") != 0) |
| 4691 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4692 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4693 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4694 | } |
| 4695 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4696 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 4697 | size_t list_len, const char *name, |
| 4698 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4699 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4700 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4701 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4702 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4703 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4704 | |
| 4705 | if (list && len <= list_len) |
| 4706 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4707 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4708 | } |
| 4709 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4710 | /* |
| 4711 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 4712 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4713 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4714 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4715 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 4716 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 4717 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
| 4718 | (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4719 | return; |
| 4720 | |
| 4721 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 4722 | NFS_ATTR_FATTR_NLINK; |
| 4723 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4724 | fattr->nlink = 2; |
| 4725 | } |
| 4726 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 4727 | int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 4728 | struct nfs4_fs_locations *fs_locations, struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4729 | { |
| 4730 | struct nfs_server *server = NFS_SERVER(dir); |
| 4731 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4732 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4733 | }; |
| 4734 | struct nfs4_fs_locations_arg args = { |
| 4735 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4736 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4737 | .page = page, |
| 4738 | .bitmask = bitmask, |
| 4739 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4740 | struct nfs4_fs_locations_res res = { |
| 4741 | .fs_locations = fs_locations, |
| 4742 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4743 | struct rpc_message msg = { |
| 4744 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4745 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4746 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4747 | }; |
| 4748 | int status; |
| 4749 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4750 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4751 | |
| 4752 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 4753 | * is not supported */ |
| 4754 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 4755 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 4756 | else |
| 4757 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 4758 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4759 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4760 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 4761 | fs_locations->nlocations = 0; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4762 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4763 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4764 | return status; |
| 4765 | } |
| 4766 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 4767 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4768 | { |
| 4769 | int status; |
| 4770 | struct nfs4_secinfo_arg args = { |
| 4771 | .dir_fh = NFS_FH(dir), |
| 4772 | .name = name, |
| 4773 | }; |
| 4774 | struct nfs4_secinfo_res res = { |
| 4775 | .flavors = flavors, |
| 4776 | }; |
| 4777 | struct rpc_message msg = { |
| 4778 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 4779 | .rpc_argp = &args, |
| 4780 | .rpc_resp = &res, |
| 4781 | }; |
| 4782 | |
| 4783 | dprintk("NFS call secinfo %s\n", name->name); |
| 4784 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 4785 | dprintk("NFS reply secinfo: %d\n", status); |
| 4786 | return status; |
| 4787 | } |
| 4788 | |
| 4789 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4790 | { |
| 4791 | struct nfs4_exception exception = { }; |
| 4792 | int err; |
| 4793 | do { |
| 4794 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 4795 | _nfs4_proc_secinfo(dir, name, flavors), |
| 4796 | &exception); |
| 4797 | } while (exception.retry); |
| 4798 | return err; |
| 4799 | } |
| 4800 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4801 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4802 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4803 | * Check the exchange flags returned by the server for invalid flags, having |
| 4804 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 4805 | * DS flags set. |
| 4806 | */ |
| 4807 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 4808 | { |
| 4809 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 4810 | goto out_inval; |
| 4811 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 4812 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 4813 | goto out_inval; |
| 4814 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 4815 | goto out_inval; |
| 4816 | return NFS_OK; |
| 4817 | out_inval: |
| 4818 | return -NFS4ERR_INVAL; |
| 4819 | } |
| 4820 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4821 | static bool |
| 4822 | nfs41_same_server_scope(struct server_scope *a, struct server_scope *b) |
| 4823 | { |
| 4824 | if (a->server_scope_sz == b->server_scope_sz && |
| 4825 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 4826 | return true; |
| 4827 | |
| 4828 | return false; |
| 4829 | } |
| 4830 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4831 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4832 | * nfs4_proc_exchange_id() |
| 4833 | * |
| 4834 | * Since the clientid has expired, all compounds using sessions |
| 4835 | * associated with the stale clientid will be returning |
| 4836 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 4837 | * be in some phase of session reset. |
| 4838 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 4839 | 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] | 4840 | { |
| 4841 | nfs4_verifier verifier; |
| 4842 | struct nfs41_exchange_id_args args = { |
| 4843 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4844 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4845 | }; |
| 4846 | struct nfs41_exchange_id_res res = { |
| 4847 | .client = clp, |
| 4848 | }; |
| 4849 | int status; |
| 4850 | struct rpc_message msg = { |
| 4851 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 4852 | .rpc_argp = &args, |
| 4853 | .rpc_resp = &res, |
| 4854 | .rpc_cred = cred, |
| 4855 | }; |
| 4856 | __be32 *p; |
| 4857 | |
| 4858 | dprintk("--> %s\n", __func__); |
| 4859 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 4860 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4861 | p = (u32 *)verifier.data; |
| 4862 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 4863 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 4864 | args.verifier = &verifier; |
| 4865 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4866 | args.id_len = scnprintf(args.id, sizeof(args.id), |
| 4867 | "%s/%s.%s/%u", |
| 4868 | clp->cl_ipaddr, |
| 4869 | init_utsname()->nodename, |
| 4870 | init_utsname()->domainname, |
| 4871 | clp->cl_rpcclient->cl_auth->au_flavor); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4872 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4873 | res.server_scope = kzalloc(sizeof(struct server_scope), GFP_KERNEL); |
| 4874 | if (unlikely(!res.server_scope)) |
| 4875 | return -ENOMEM; |
| 4876 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4877 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4878 | if (!status) |
| 4879 | status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4880 | |
| 4881 | if (!status) { |
| 4882 | if (clp->server_scope && |
| 4883 | !nfs41_same_server_scope(clp->server_scope, |
| 4884 | res.server_scope)) { |
| 4885 | dprintk("%s: server_scope mismatch detected\n", |
| 4886 | __func__); |
| 4887 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 4888 | kfree(clp->server_scope); |
| 4889 | clp->server_scope = NULL; |
| 4890 | } |
| 4891 | |
| 4892 | if (!clp->server_scope) |
| 4893 | clp->server_scope = res.server_scope; |
| 4894 | else |
| 4895 | kfree(res.server_scope); |
| 4896 | } |
| 4897 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4898 | dprintk("<-- %s status= %d\n", __func__, status); |
| 4899 | return status; |
| 4900 | } |
| 4901 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4902 | struct nfs4_get_lease_time_data { |
| 4903 | struct nfs4_get_lease_time_args *args; |
| 4904 | struct nfs4_get_lease_time_res *res; |
| 4905 | struct nfs_client *clp; |
| 4906 | }; |
| 4907 | |
| 4908 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 4909 | void *calldata) |
| 4910 | { |
| 4911 | int ret; |
| 4912 | struct nfs4_get_lease_time_data *data = |
| 4913 | (struct nfs4_get_lease_time_data *)calldata; |
| 4914 | |
| 4915 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4916 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4917 | /* just setup sequence, do not trigger session recovery |
| 4918 | since we're invoked within one */ |
| 4919 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4920 | &data->args->la_seq_args, |
| 4921 | &data->res->lr_seq_res, 0, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4922 | |
| 4923 | BUG_ON(ret == -EAGAIN); |
| 4924 | rpc_call_start(task); |
| 4925 | dprintk("<-- %s\n", __func__); |
| 4926 | } |
| 4927 | |
| 4928 | /* |
| 4929 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 4930 | * from sequence operation or clientid errors. |
| 4931 | */ |
| 4932 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 4933 | { |
| 4934 | struct nfs4_get_lease_time_data *data = |
| 4935 | (struct nfs4_get_lease_time_data *)calldata; |
| 4936 | |
| 4937 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4938 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 4939 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4940 | switch (task->tk_status) { |
| 4941 | case -NFS4ERR_DELAY: |
| 4942 | case -NFS4ERR_GRACE: |
| 4943 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 4944 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 4945 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4946 | /* fall through */ |
| 4947 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 4948 | nfs_restart_rpc(task, data->clp); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4949 | return; |
| 4950 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4951 | dprintk("<-- %s\n", __func__); |
| 4952 | } |
| 4953 | |
| 4954 | struct rpc_call_ops nfs4_get_lease_time_ops = { |
| 4955 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 4956 | .rpc_call_done = nfs4_get_lease_time_done, |
| 4957 | }; |
| 4958 | |
| 4959 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 4960 | { |
| 4961 | struct rpc_task *task; |
| 4962 | struct nfs4_get_lease_time_args args; |
| 4963 | struct nfs4_get_lease_time_res res = { |
| 4964 | .lr_fsinfo = fsinfo, |
| 4965 | }; |
| 4966 | struct nfs4_get_lease_time_data data = { |
| 4967 | .args = &args, |
| 4968 | .res = &res, |
| 4969 | .clp = clp, |
| 4970 | }; |
| 4971 | struct rpc_message msg = { |
| 4972 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 4973 | .rpc_argp = &args, |
| 4974 | .rpc_resp = &res, |
| 4975 | }; |
| 4976 | struct rpc_task_setup task_setup = { |
| 4977 | .rpc_client = clp->cl_rpcclient, |
| 4978 | .rpc_message = &msg, |
| 4979 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4980 | .callback_data = &data, |
| 4981 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4982 | }; |
| 4983 | int status; |
| 4984 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4985 | dprintk("--> %s\n", __func__); |
| 4986 | task = rpc_run_task(&task_setup); |
| 4987 | |
| 4988 | if (IS_ERR(task)) |
| 4989 | status = PTR_ERR(task); |
| 4990 | else { |
| 4991 | status = task->tk_status; |
| 4992 | rpc_put_task(task); |
| 4993 | } |
| 4994 | dprintk("<-- %s return %d\n", __func__, status); |
| 4995 | |
| 4996 | return status; |
| 4997 | } |
| 4998 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4999 | /* |
| 5000 | * Reset a slot table |
| 5001 | */ |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5002 | static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 5003 | int ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5004 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5005 | struct nfs4_slot *new = NULL; |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5006 | int i; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5007 | int ret = 0; |
| 5008 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5009 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 5010 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5011 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5012 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 5013 | if (max_reqs != tbl->max_slots) { |
| 5014 | ret = -ENOMEM; |
| 5015 | new = kmalloc(max_reqs * sizeof(struct nfs4_slot), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5016 | GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5017 | if (!new) |
| 5018 | goto out; |
| 5019 | ret = 0; |
| 5020 | kfree(tbl->slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5021 | } |
| 5022 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5023 | if (new) { |
| 5024 | tbl->slots = new; |
| 5025 | tbl->max_slots = max_reqs; |
| 5026 | } |
| 5027 | for (i = 0; i < tbl->max_slots; ++i) |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5028 | tbl->slots[i].seq_nr = ivalue; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5029 | spin_unlock(&tbl->slot_tbl_lock); |
| 5030 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5031 | tbl, tbl->slots, tbl->max_slots); |
| 5032 | out: |
| 5033 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5034 | return ret; |
| 5035 | } |
| 5036 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5037 | /* |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5038 | * Reset the forechannel and backchannel slot tables |
| 5039 | */ |
| 5040 | static int nfs4_reset_slot_tables(struct nfs4_session *session) |
| 5041 | { |
| 5042 | int status; |
| 5043 | |
| 5044 | status = nfs4_reset_slot_table(&session->fc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5045 | session->fc_attrs.max_reqs, 1); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5046 | if (status) |
| 5047 | return status; |
| 5048 | |
| 5049 | status = nfs4_reset_slot_table(&session->bc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5050 | session->bc_attrs.max_reqs, 0); |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5051 | return status; |
| 5052 | } |
| 5053 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5054 | /* Destroy the slot table */ |
| 5055 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 5056 | { |
| 5057 | if (session->fc_slot_table.slots != NULL) { |
| 5058 | kfree(session->fc_slot_table.slots); |
| 5059 | session->fc_slot_table.slots = NULL; |
| 5060 | } |
| 5061 | if (session->bc_slot_table.slots != NULL) { |
| 5062 | kfree(session->bc_slot_table.slots); |
| 5063 | session->bc_slot_table.slots = NULL; |
| 5064 | } |
| 5065 | return; |
| 5066 | } |
| 5067 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5068 | /* |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5069 | * Initialize slot table |
| 5070 | */ |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5071 | static int nfs4_init_slot_table(struct nfs4_slot_table *tbl, |
| 5072 | int max_slots, int ivalue) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5073 | { |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5074 | struct nfs4_slot *slot; |
| 5075 | int ret = -ENOMEM; |
| 5076 | |
| 5077 | BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE); |
| 5078 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5079 | dprintk("--> %s: max_reqs=%u\n", __func__, max_slots); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5080 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5081 | slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5082 | if (!slot) |
| 5083 | goto out; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5084 | ret = 0; |
| 5085 | |
| 5086 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5087 | tbl->max_slots = max_slots; |
| 5088 | tbl->slots = slot; |
| 5089 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 5090 | spin_unlock(&tbl->slot_tbl_lock); |
| 5091 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5092 | tbl, tbl->slots, tbl->max_slots); |
| 5093 | out: |
| 5094 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5095 | return ret; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5096 | } |
| 5097 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5098 | /* |
| 5099 | * Initialize the forechannel and backchannel tables |
| 5100 | */ |
| 5101 | static int nfs4_init_slot_tables(struct nfs4_session *session) |
| 5102 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5103 | struct nfs4_slot_table *tbl; |
| 5104 | int status = 0; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5105 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5106 | tbl = &session->fc_slot_table; |
| 5107 | if (tbl->slots == NULL) { |
| 5108 | status = nfs4_init_slot_table(tbl, |
| 5109 | session->fc_attrs.max_reqs, 1); |
| 5110 | if (status) |
| 5111 | return status; |
| 5112 | } |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5113 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5114 | tbl = &session->bc_slot_table; |
| 5115 | if (tbl->slots == NULL) { |
| 5116 | status = nfs4_init_slot_table(tbl, |
| 5117 | session->bc_attrs.max_reqs, 0); |
| 5118 | if (status) |
| 5119 | nfs4_destroy_slot_tables(session); |
| 5120 | } |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5121 | |
| 5122 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5123 | } |
| 5124 | |
| 5125 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 5126 | { |
| 5127 | struct nfs4_session *session; |
| 5128 | struct nfs4_slot_table *tbl; |
| 5129 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5130 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5131 | if (!session) |
| 5132 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 5133 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5134 | tbl = &session->fc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 5135 | tbl->highest_used_slotid = -1; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5136 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5137 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5138 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5139 | |
| 5140 | tbl = &session->bc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 5141 | tbl->highest_used_slotid = -1; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5142 | spin_lock_init(&tbl->slot_tbl_lock); |
| 5143 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5144 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5145 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5146 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 5147 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5148 | session->clp = clp; |
| 5149 | return session; |
| 5150 | } |
| 5151 | |
| 5152 | void nfs4_destroy_session(struct nfs4_session *session) |
| 5153 | { |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5154 | nfs4_proc_destroy_session(session); |
| 5155 | dprintk("%s Destroy backchannel for xprt %p\n", |
| 5156 | __func__, session->clp->cl_rpcclient->cl_xprt); |
| 5157 | xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt, |
| 5158 | NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5159 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5160 | kfree(session); |
| 5161 | } |
| 5162 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5163 | /* |
| 5164 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5165 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5166 | * use them. |
| 5167 | * |
| 5168 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5169 | * always set csa_cachethis to FALSE because the current implementation |
| 5170 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5171 | */ |
| 5172 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5173 | { |
| 5174 | struct nfs4_session *session = args->client->cl_session; |
| 5175 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 5176 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 5177 | |
| 5178 | if (mxrqst_sz == 0) |
| 5179 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5180 | if (mxresp_sz == 0) |
| 5181 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5182 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5183 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5184 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5185 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
| 5186 | args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs; |
| 5187 | |
| 5188 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5189 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5190 | __func__, |
| 5191 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5192 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5193 | |
| 5194 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5195 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5196 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5197 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5198 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5199 | args->bc_attrs.max_reqs = 1; |
| 5200 | |
| 5201 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5202 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5203 | __func__, |
| 5204 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5205 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5206 | args->bc_attrs.max_reqs); |
| 5207 | } |
| 5208 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5209 | 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] | 5210 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5211 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5212 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5213 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5214 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5215 | return -EINVAL; |
| 5216 | /* |
| 5217 | * Our requested max_ops is the minimum we need; we're not |
| 5218 | * prepared to break up compounds into smaller pieces than that. |
| 5219 | * So, no point even trying to continue if the server won't |
| 5220 | * cooperate: |
| 5221 | */ |
| 5222 | if (rcvd->max_ops < sent->max_ops) |
| 5223 | return -EINVAL; |
| 5224 | if (rcvd->max_reqs == 0) |
| 5225 | return -EINVAL; |
| 5226 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5227 | } |
| 5228 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5229 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5230 | { |
| 5231 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5232 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5233 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5234 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5235 | return -EINVAL; |
| 5236 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5237 | return -EINVAL; |
| 5238 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5239 | return -EINVAL; |
| 5240 | /* These would render the backchannel useless: */ |
| 5241 | if (rcvd->max_ops == 0) |
| 5242 | return -EINVAL; |
| 5243 | if (rcvd->max_reqs == 0) |
| 5244 | return -EINVAL; |
| 5245 | return 0; |
| 5246 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5247 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5248 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5249 | struct nfs4_session *session) |
| 5250 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5251 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5252 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5253 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5254 | if (ret) |
| 5255 | return ret; |
| 5256 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5257 | } |
| 5258 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5259 | static int _nfs4_proc_create_session(struct nfs_client *clp) |
| 5260 | { |
| 5261 | struct nfs4_session *session = clp->cl_session; |
| 5262 | struct nfs41_create_session_args args = { |
| 5263 | .client = clp, |
| 5264 | .cb_program = NFS4_CALLBACK, |
| 5265 | }; |
| 5266 | struct nfs41_create_session_res res = { |
| 5267 | .client = clp, |
| 5268 | }; |
| 5269 | struct rpc_message msg = { |
| 5270 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5271 | .rpc_argp = &args, |
| 5272 | .rpc_resp = &res, |
| 5273 | }; |
| 5274 | int status; |
| 5275 | |
| 5276 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5277 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5278 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5279 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5280 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5281 | if (!status) |
| 5282 | /* Verify the session's negotiated channel_attrs values */ |
| 5283 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5284 | if (!status) { |
| 5285 | /* Increment the clientid slot sequence id */ |
| 5286 | clp->cl_seqid++; |
| 5287 | } |
| 5288 | |
| 5289 | return status; |
| 5290 | } |
| 5291 | |
| 5292 | /* |
| 5293 | * Issues a CREATE_SESSION operation to the server. |
| 5294 | * It is the responsibility of the caller to verify the session is |
| 5295 | * expired before calling this routine. |
| 5296 | */ |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5297 | int nfs4_proc_create_session(struct nfs_client *clp) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5298 | { |
| 5299 | int status; |
| 5300 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5301 | struct nfs4_session *session = clp->cl_session; |
| 5302 | |
| 5303 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5304 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5305 | status = _nfs4_proc_create_session(clp); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5306 | if (status) |
| 5307 | goto out; |
| 5308 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5309 | /* Init and reset the fore channel */ |
| 5310 | status = nfs4_init_slot_tables(session); |
| 5311 | dprintk("slot table initialization returned %d\n", status); |
| 5312 | if (status) |
| 5313 | goto out; |
| 5314 | status = nfs4_reset_slot_tables(session); |
| 5315 | dprintk("slot table reset returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5316 | if (status) |
| 5317 | goto out; |
| 5318 | |
| 5319 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5320 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5321 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5322 | out: |
| 5323 | dprintk("<-- %s\n", __func__); |
| 5324 | return status; |
| 5325 | } |
| 5326 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5327 | /* |
| 5328 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5329 | * The caller must serialize access to this routine. |
| 5330 | */ |
| 5331 | int nfs4_proc_destroy_session(struct nfs4_session *session) |
| 5332 | { |
| 5333 | int status = 0; |
| 5334 | struct rpc_message msg; |
| 5335 | |
| 5336 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5337 | |
| 5338 | /* session is still being setup */ |
| 5339 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5340 | return status; |
| 5341 | |
| 5342 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; |
| 5343 | msg.rpc_argp = session; |
| 5344 | msg.rpc_resp = NULL; |
| 5345 | msg.rpc_cred = NULL; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5346 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5347 | |
| 5348 | if (status) |
| 5349 | printk(KERN_WARNING |
| 5350 | "Got error %d from the server on DESTROY_SESSION. " |
| 5351 | "Session has been destroyed regardless...\n", status); |
| 5352 | |
| 5353 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5354 | return status; |
| 5355 | } |
| 5356 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5357 | int nfs4_init_session(struct nfs_server *server) |
| 5358 | { |
| 5359 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5360 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5361 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5362 | int ret; |
| 5363 | |
| 5364 | if (!nfs4_has_session(clp)) |
| 5365 | return 0; |
| 5366 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5367 | session = clp->cl_session; |
| 5368 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5369 | return 0; |
| 5370 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5371 | rsize = server->rsize; |
| 5372 | if (rsize == 0) |
| 5373 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5374 | wsize = server->wsize; |
| 5375 | if (wsize == 0) |
| 5376 | wsize = NFS_MAX_FILE_IO_SIZE; |
| 5377 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5378 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5379 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5380 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5381 | ret = nfs4_recover_expired_lease(server); |
| 5382 | if (!ret) |
| 5383 | ret = nfs4_check_client_ready(clp); |
| 5384 | return ret; |
| 5385 | } |
| 5386 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5387 | int nfs4_init_ds_session(struct nfs_client *clp) |
| 5388 | { |
| 5389 | struct nfs4_session *session = clp->cl_session; |
| 5390 | int ret; |
| 5391 | |
| 5392 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5393 | return 0; |
| 5394 | |
| 5395 | ret = nfs4_client_recover_expired_lease(clp); |
| 5396 | if (!ret) |
| 5397 | /* Test for the DS role */ |
| 5398 | if (!is_ds_client(clp)) |
| 5399 | ret = -ENODEV; |
| 5400 | if (!ret) |
| 5401 | ret = nfs4_check_client_ready(clp); |
| 5402 | return ret; |
| 5403 | |
| 5404 | } |
| 5405 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 5406 | |
| 5407 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5408 | /* |
| 5409 | * Renew the cl_session lease. |
| 5410 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5411 | struct nfs4_sequence_data { |
| 5412 | struct nfs_client *clp; |
| 5413 | struct nfs4_sequence_args args; |
| 5414 | struct nfs4_sequence_res res; |
| 5415 | }; |
| 5416 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5417 | static void nfs41_sequence_release(void *data) |
| 5418 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5419 | struct nfs4_sequence_data *calldata = data; |
| 5420 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5421 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5422 | if (atomic_read(&clp->cl_count) > 1) |
| 5423 | nfs4_schedule_state_renewal(clp); |
| 5424 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5425 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5426 | } |
| 5427 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5428 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5429 | { |
| 5430 | switch(task->tk_status) { |
| 5431 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5432 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5433 | return -EAGAIN; |
| 5434 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5435 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5436 | } |
| 5437 | return 0; |
| 5438 | } |
| 5439 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5440 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5441 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5442 | struct nfs4_sequence_data *calldata = data; |
| 5443 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5444 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5445 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5446 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5447 | |
| 5448 | if (task->tk_status < 0) { |
| 5449 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5450 | if (atomic_read(&clp->cl_count) == 1) |
| 5451 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5452 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5453 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5454 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5455 | return; |
| 5456 | } |
| 5457 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5458 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5459 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5460 | dprintk("<-- %s\n", __func__); |
| 5461 | } |
| 5462 | |
| 5463 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5464 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5465 | struct nfs4_sequence_data *calldata = data; |
| 5466 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5467 | struct nfs4_sequence_args *args; |
| 5468 | struct nfs4_sequence_res *res; |
| 5469 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5470 | args = task->tk_msg.rpc_argp; |
| 5471 | res = task->tk_msg.rpc_resp; |
| 5472 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5473 | if (nfs41_setup_sequence(clp->cl_session, args, res, 0, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5474 | return; |
| 5475 | rpc_call_start(task); |
| 5476 | } |
| 5477 | |
| 5478 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5479 | .rpc_call_done = nfs41_sequence_call_done, |
| 5480 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5481 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5482 | }; |
| 5483 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5484 | 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] | 5485 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5486 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5487 | struct rpc_message msg = { |
| 5488 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5489 | .rpc_cred = cred, |
| 5490 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5491 | struct rpc_task_setup task_setup_data = { |
| 5492 | .rpc_client = clp->cl_rpcclient, |
| 5493 | .rpc_message = &msg, |
| 5494 | .callback_ops = &nfs41_sequence_ops, |
| 5495 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5496 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5497 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5498 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5499 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5500 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5501 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5502 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5503 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5504 | } |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5505 | msg.rpc_argp = &calldata->args; |
| 5506 | msg.rpc_resp = &calldata->res; |
| 5507 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5508 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5509 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5510 | return rpc_run_task(&task_setup_data); |
| 5511 | } |
| 5512 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5513 | static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5514 | { |
| 5515 | struct rpc_task *task; |
| 5516 | int ret = 0; |
| 5517 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5518 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 5519 | return 0; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5520 | task = _nfs41_proc_sequence(clp, cred); |
| 5521 | if (IS_ERR(task)) |
| 5522 | ret = PTR_ERR(task); |
| 5523 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5524 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5525 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5526 | return ret; |
| 5527 | } |
| 5528 | |
| 5529 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5530 | { |
| 5531 | struct rpc_task *task; |
| 5532 | int ret; |
| 5533 | |
| 5534 | task = _nfs41_proc_sequence(clp, cred); |
| 5535 | if (IS_ERR(task)) { |
| 5536 | ret = PTR_ERR(task); |
| 5537 | goto out; |
| 5538 | } |
| 5539 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5540 | if (!ret) { |
| 5541 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5542 | |
| 5543 | if (task->tk_status == 0) |
| 5544 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5545 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5546 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5547 | rpc_put_task(task); |
| 5548 | out: |
| 5549 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5550 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5551 | } |
| 5552 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5553 | struct nfs4_reclaim_complete_data { |
| 5554 | struct nfs_client *clp; |
| 5555 | struct nfs41_reclaim_complete_args arg; |
| 5556 | struct nfs41_reclaim_complete_res res; |
| 5557 | }; |
| 5558 | |
| 5559 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5560 | { |
| 5561 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5562 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5563 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5564 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5565 | &calldata->arg.seq_args, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5566 | &calldata->res.seq_res, 0, task)) |
| 5567 | return; |
| 5568 | |
| 5569 | rpc_call_start(task); |
| 5570 | } |
| 5571 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5572 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5573 | { |
| 5574 | switch(task->tk_status) { |
| 5575 | case 0: |
| 5576 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5577 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5578 | break; |
| 5579 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5580 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5581 | /* fall through */ |
| 5582 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5583 | return -EAGAIN; |
| 5584 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5585 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5586 | } |
| 5587 | return 0; |
| 5588 | } |
| 5589 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5590 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5591 | { |
| 5592 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5593 | struct nfs_client *clp = calldata->clp; |
| 5594 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5595 | |
| 5596 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5597 | if (!nfs41_sequence_done(task, res)) |
| 5598 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5599 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5600 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5601 | rpc_restart_call_prepare(task); |
| 5602 | return; |
| 5603 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5604 | dprintk("<-- %s\n", __func__); |
| 5605 | } |
| 5606 | |
| 5607 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5608 | { |
| 5609 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5610 | |
| 5611 | kfree(calldata); |
| 5612 | } |
| 5613 | |
| 5614 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5615 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5616 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5617 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5618 | }; |
| 5619 | |
| 5620 | /* |
| 5621 | * Issue a global reclaim complete. |
| 5622 | */ |
| 5623 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5624 | { |
| 5625 | struct nfs4_reclaim_complete_data *calldata; |
| 5626 | struct rpc_task *task; |
| 5627 | struct rpc_message msg = { |
| 5628 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5629 | }; |
| 5630 | struct rpc_task_setup task_setup_data = { |
| 5631 | .rpc_client = clp->cl_rpcclient, |
| 5632 | .rpc_message = &msg, |
| 5633 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5634 | .flags = RPC_TASK_ASYNC, |
| 5635 | }; |
| 5636 | int status = -ENOMEM; |
| 5637 | |
| 5638 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5639 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5640 | if (calldata == NULL) |
| 5641 | goto out; |
| 5642 | calldata->clp = clp; |
| 5643 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5644 | |
| 5645 | msg.rpc_argp = &calldata->arg; |
| 5646 | msg.rpc_resp = &calldata->res; |
| 5647 | task_setup_data.callback_data = calldata; |
| 5648 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5649 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5650 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5651 | goto out; |
| 5652 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 5653 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5654 | if (status == 0) |
| 5655 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5656 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5657 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5658 | out: |
| 5659 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5660 | return status; |
| 5661 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5662 | |
| 5663 | static void |
| 5664 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 5665 | { |
| 5666 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5667 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5668 | |
| 5669 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5670 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 5671 | * right now covering the LAYOUTGET we are about to send. |
| 5672 | * However, that is not so catastrophic, and there seems |
| 5673 | * to be no way to prevent it completely. |
| 5674 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5675 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
| 5676 | &lgp->res.seq_res, 0, task)) |
| 5677 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5678 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 5679 | NFS_I(lgp->args.inode)->layout, |
| 5680 | lgp->args.ctx->state)) { |
| 5681 | rpc_exit(task, NFS4_OK); |
| 5682 | return; |
| 5683 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5684 | rpc_call_start(task); |
| 5685 | } |
| 5686 | |
| 5687 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 5688 | { |
| 5689 | struct nfs4_layoutget *lgp = calldata; |
| 5690 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5691 | |
| 5692 | dprintk("--> %s\n", __func__); |
| 5693 | |
| 5694 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 5695 | return; |
| 5696 | |
| 5697 | switch (task->tk_status) { |
| 5698 | case 0: |
| 5699 | break; |
| 5700 | case -NFS4ERR_LAYOUTTRYLATER: |
| 5701 | case -NFS4ERR_RECALLCONFLICT: |
| 5702 | task->tk_status = -NFS4ERR_DELAY; |
| 5703 | /* Fall through */ |
| 5704 | default: |
| 5705 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5706 | rpc_restart_call_prepare(task); |
| 5707 | return; |
| 5708 | } |
| 5709 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5710 | dprintk("<-- %s\n", __func__); |
| 5711 | } |
| 5712 | |
| 5713 | static void nfs4_layoutget_release(void *calldata) |
| 5714 | { |
| 5715 | struct nfs4_layoutget *lgp = calldata; |
| 5716 | |
| 5717 | dprintk("--> %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5718 | put_nfs_open_context(lgp->args.ctx); |
| 5719 | kfree(calldata); |
| 5720 | dprintk("<-- %s\n", __func__); |
| 5721 | } |
| 5722 | |
| 5723 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 5724 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 5725 | .rpc_call_done = nfs4_layoutget_done, |
| 5726 | .rpc_release = nfs4_layoutget_release, |
| 5727 | }; |
| 5728 | |
| 5729 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) |
| 5730 | { |
| 5731 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5732 | struct rpc_task *task; |
| 5733 | struct rpc_message msg = { |
| 5734 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 5735 | .rpc_argp = &lgp->args, |
| 5736 | .rpc_resp = &lgp->res, |
| 5737 | }; |
| 5738 | struct rpc_task_setup task_setup_data = { |
| 5739 | .rpc_client = server->client, |
| 5740 | .rpc_message = &msg, |
| 5741 | .callback_ops = &nfs4_layoutget_call_ops, |
| 5742 | .callback_data = lgp, |
| 5743 | .flags = RPC_TASK_ASYNC, |
| 5744 | }; |
| 5745 | int status = 0; |
| 5746 | |
| 5747 | dprintk("--> %s\n", __func__); |
| 5748 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 5749 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5750 | lgp->res.seq_res.sr_slot = NULL; |
| 5751 | task = rpc_run_task(&task_setup_data); |
| 5752 | if (IS_ERR(task)) |
| 5753 | return PTR_ERR(task); |
| 5754 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5755 | if (status == 0) |
| 5756 | status = task->tk_status; |
| 5757 | if (status == 0) |
| 5758 | status = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5759 | rpc_put_task(task); |
| 5760 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5761 | return status; |
| 5762 | } |
| 5763 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5764 | static void |
| 5765 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 5766 | { |
| 5767 | struct nfs4_layoutreturn *lrp = calldata; |
| 5768 | |
| 5769 | dprintk("--> %s\n", __func__); |
| 5770 | if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, |
| 5771 | &lrp->res.seq_res, 0, task)) |
| 5772 | return; |
| 5773 | rpc_call_start(task); |
| 5774 | } |
| 5775 | |
| 5776 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 5777 | { |
| 5778 | struct nfs4_layoutreturn *lrp = calldata; |
| 5779 | struct nfs_server *server; |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 5780 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5781 | |
| 5782 | dprintk("--> %s\n", __func__); |
| 5783 | |
| 5784 | if (!nfs4_sequence_done(task, &lrp->res.seq_res)) |
| 5785 | return; |
| 5786 | |
| 5787 | server = NFS_SERVER(lrp->args.inode); |
| 5788 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5789 | nfs_restart_rpc(task, lrp->clp); |
| 5790 | return; |
| 5791 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 5792 | spin_lock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5793 | if (task->tk_status == 0) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5794 | if (lrp->res.lrs_present) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5795 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5796 | } else |
| 5797 | BUG_ON(!list_empty(&lo->plh_segs)); |
| 5798 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 5799 | lo->plh_block_lgets--; |
| 5800 | spin_unlock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5801 | dprintk("<-- %s\n", __func__); |
| 5802 | } |
| 5803 | |
| 5804 | static void nfs4_layoutreturn_release(void *calldata) |
| 5805 | { |
| 5806 | struct nfs4_layoutreturn *lrp = calldata; |
| 5807 | |
| 5808 | dprintk("--> %s\n", __func__); |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 5809 | put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5810 | kfree(calldata); |
| 5811 | dprintk("<-- %s\n", __func__); |
| 5812 | } |
| 5813 | |
| 5814 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 5815 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 5816 | .rpc_call_done = nfs4_layoutreturn_done, |
| 5817 | .rpc_release = nfs4_layoutreturn_release, |
| 5818 | }; |
| 5819 | |
| 5820 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 5821 | { |
| 5822 | struct rpc_task *task; |
| 5823 | struct rpc_message msg = { |
| 5824 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 5825 | .rpc_argp = &lrp->args, |
| 5826 | .rpc_resp = &lrp->res, |
| 5827 | }; |
| 5828 | struct rpc_task_setup task_setup_data = { |
| 5829 | .rpc_client = lrp->clp->cl_rpcclient, |
| 5830 | .rpc_message = &msg, |
| 5831 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 5832 | .callback_data = lrp, |
| 5833 | }; |
| 5834 | int status; |
| 5835 | |
| 5836 | dprintk("--> %s\n", __func__); |
| 5837 | task = rpc_run_task(&task_setup_data); |
| 5838 | if (IS_ERR(task)) |
| 5839 | return PTR_ERR(task); |
| 5840 | status = task->tk_status; |
| 5841 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5842 | rpc_put_task(task); |
| 5843 | return status; |
| 5844 | } |
| 5845 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 5846 | /* |
| 5847 | * Retrieve the list of Data Server devices from the MDS. |
| 5848 | */ |
| 5849 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 5850 | const struct nfs_fh *fh, |
| 5851 | struct pnfs_devicelist *devlist) |
| 5852 | { |
| 5853 | struct nfs4_getdevicelist_args args = { |
| 5854 | .fh = fh, |
| 5855 | .layoutclass = server->pnfs_curr_ld->id, |
| 5856 | }; |
| 5857 | struct nfs4_getdevicelist_res res = { |
| 5858 | .devlist = devlist, |
| 5859 | }; |
| 5860 | struct rpc_message msg = { |
| 5861 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 5862 | .rpc_argp = &args, |
| 5863 | .rpc_resp = &res, |
| 5864 | }; |
| 5865 | int status; |
| 5866 | |
| 5867 | dprintk("--> %s\n", __func__); |
| 5868 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 5869 | &res.seq_res, 0); |
| 5870 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5871 | return status; |
| 5872 | } |
| 5873 | |
| 5874 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 5875 | const struct nfs_fh *fh, |
| 5876 | struct pnfs_devicelist *devlist) |
| 5877 | { |
| 5878 | struct nfs4_exception exception = { }; |
| 5879 | int err; |
| 5880 | |
| 5881 | do { |
| 5882 | err = nfs4_handle_exception(server, |
| 5883 | _nfs4_getdevicelist(server, fh, devlist), |
| 5884 | &exception); |
| 5885 | } while (exception.retry); |
| 5886 | |
| 5887 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 5888 | err, devlist->num_devs); |
| 5889 | |
| 5890 | return err; |
| 5891 | } |
| 5892 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 5893 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5894 | static int |
| 5895 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5896 | { |
| 5897 | struct nfs4_getdeviceinfo_args args = { |
| 5898 | .pdev = pdev, |
| 5899 | }; |
| 5900 | struct nfs4_getdeviceinfo_res res = { |
| 5901 | .pdev = pdev, |
| 5902 | }; |
| 5903 | struct rpc_message msg = { |
| 5904 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 5905 | .rpc_argp = &args, |
| 5906 | .rpc_resp = &res, |
| 5907 | }; |
| 5908 | int status; |
| 5909 | |
| 5910 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5911 | 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] | 5912 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5913 | |
| 5914 | return status; |
| 5915 | } |
| 5916 | |
| 5917 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5918 | { |
| 5919 | struct nfs4_exception exception = { }; |
| 5920 | int err; |
| 5921 | |
| 5922 | do { |
| 5923 | err = nfs4_handle_exception(server, |
| 5924 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 5925 | &exception); |
| 5926 | } while (exception.retry); |
| 5927 | return err; |
| 5928 | } |
| 5929 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 5930 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5931 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 5932 | { |
| 5933 | struct nfs4_layoutcommit_data *data = calldata; |
| 5934 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 5935 | |
| 5936 | if (nfs4_setup_sequence(server, &data->args.seq_args, |
| 5937 | &data->res.seq_res, 1, task)) |
| 5938 | return; |
| 5939 | rpc_call_start(task); |
| 5940 | } |
| 5941 | |
| 5942 | static void |
| 5943 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 5944 | { |
| 5945 | struct nfs4_layoutcommit_data *data = calldata; |
| 5946 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 5947 | |
| 5948 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5949 | return; |
| 5950 | |
| 5951 | switch (task->tk_status) { /* Just ignore these failures */ |
| 5952 | case NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 5953 | case NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 5954 | case NFS4ERR_BADLAYOUT: /* no layout */ |
| 5955 | case NFS4ERR_GRACE: /* loca_recalim always false */ |
| 5956 | task->tk_status = 0; |
| 5957 | } |
| 5958 | |
| 5959 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5960 | nfs_restart_rpc(task, server->nfs_client); |
| 5961 | return; |
| 5962 | } |
| 5963 | |
| 5964 | if (task->tk_status == 0) |
| 5965 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 5966 | data->res.fattr); |
| 5967 | } |
| 5968 | |
| 5969 | static void nfs4_layoutcommit_release(void *calldata) |
| 5970 | { |
| 5971 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 5972 | struct pnfs_layout_segment *lseg, *tmp; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5973 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 5974 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5975 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 5976 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 5977 | list_del_init(&lseg->pls_lc_list); |
| 5978 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 5979 | &lseg->pls_flags)) |
| 5980 | put_lseg(lseg); |
| 5981 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5982 | put_rpccred(data->cred); |
| 5983 | kfree(data); |
| 5984 | } |
| 5985 | |
| 5986 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 5987 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 5988 | .rpc_call_done = nfs4_layoutcommit_done, |
| 5989 | .rpc_release = nfs4_layoutcommit_release, |
| 5990 | }; |
| 5991 | |
| 5992 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 5993 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5994 | { |
| 5995 | struct rpc_message msg = { |
| 5996 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 5997 | .rpc_argp = &data->args, |
| 5998 | .rpc_resp = &data->res, |
| 5999 | .rpc_cred = data->cred, |
| 6000 | }; |
| 6001 | struct rpc_task_setup task_setup_data = { |
| 6002 | .task = &data->task, |
| 6003 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6004 | .rpc_message = &msg, |
| 6005 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6006 | .callback_data = data, |
| 6007 | .flags = RPC_TASK_ASYNC, |
| 6008 | }; |
| 6009 | struct rpc_task *task; |
| 6010 | int status = 0; |
| 6011 | |
| 6012 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6013 | "lbw: %llu inode %lu\n", |
| 6014 | data->task.tk_pid, sync, |
| 6015 | data->args.lastbytewritten, |
| 6016 | data->args.inode->i_ino); |
| 6017 | |
| 6018 | task = rpc_run_task(&task_setup_data); |
| 6019 | if (IS_ERR(task)) |
| 6020 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6021 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6022 | goto out; |
| 6023 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6024 | if (status != 0) |
| 6025 | goto out; |
| 6026 | status = task->tk_status; |
| 6027 | out: |
| 6028 | dprintk("%s: status %d\n", __func__, status); |
| 6029 | rpc_put_task(task); |
| 6030 | return status; |
| 6031 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6032 | |
| 6033 | static int |
| 6034 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6035 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6036 | { |
| 6037 | struct nfs41_secinfo_no_name_args args = { |
| 6038 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6039 | }; |
| 6040 | struct nfs4_secinfo_res res = { |
| 6041 | .flavors = flavors, |
| 6042 | }; |
| 6043 | struct rpc_message msg = { |
| 6044 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6045 | .rpc_argp = &args, |
| 6046 | .rpc_resp = &res, |
| 6047 | }; |
| 6048 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6049 | } |
| 6050 | |
| 6051 | static int |
| 6052 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6053 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6054 | { |
| 6055 | struct nfs4_exception exception = { }; |
| 6056 | int err; |
| 6057 | do { |
| 6058 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6059 | switch (err) { |
| 6060 | case 0: |
| 6061 | case -NFS4ERR_WRONGSEC: |
| 6062 | case -NFS4ERR_NOTSUPP: |
| 6063 | break; |
| 6064 | default: |
| 6065 | err = nfs4_handle_exception(server, err, &exception); |
| 6066 | } |
| 6067 | } while (exception.retry); |
| 6068 | return err; |
| 6069 | } |
| 6070 | |
| 6071 | static int |
| 6072 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6073 | struct nfs_fsinfo *info) |
| 6074 | { |
| 6075 | int err; |
| 6076 | struct page *page; |
| 6077 | rpc_authflavor_t flavor; |
| 6078 | struct nfs4_secinfo_flavors *flavors; |
| 6079 | |
| 6080 | page = alloc_page(GFP_KERNEL); |
| 6081 | if (!page) { |
| 6082 | err = -ENOMEM; |
| 6083 | goto out; |
| 6084 | } |
| 6085 | |
| 6086 | flavors = page_address(page); |
| 6087 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6088 | |
| 6089 | /* |
| 6090 | * Fall back on "guess and check" method if |
| 6091 | * the server doesn't support SECINFO_NO_NAME |
| 6092 | */ |
| 6093 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6094 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6095 | goto out_freepage; |
| 6096 | } |
| 6097 | if (err) |
| 6098 | goto out_freepage; |
| 6099 | |
| 6100 | flavor = nfs_find_best_sec(flavors); |
| 6101 | if (err == 0) |
| 6102 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6103 | |
| 6104 | out_freepage: |
| 6105 | put_page(page); |
| 6106 | if (err == -EACCES) |
| 6107 | return -EPERM; |
| 6108 | out: |
| 6109 | return err; |
| 6110 | } |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6111 | static int _nfs41_test_stateid(struct nfs_server *server, struct nfs4_state *state) |
| 6112 | { |
| 6113 | int status; |
| 6114 | struct nfs41_test_stateid_args args = { |
| 6115 | .stateid = &state->stateid, |
| 6116 | }; |
| 6117 | struct nfs41_test_stateid_res res; |
| 6118 | struct rpc_message msg = { |
| 6119 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6120 | .rpc_argp = &args, |
| 6121 | .rpc_resp = &res, |
| 6122 | }; |
| 6123 | args.seq_args.sa_session = res.seq_res.sr_session = NULL; |
| 6124 | status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 0, 1); |
| 6125 | return status; |
| 6126 | } |
| 6127 | |
| 6128 | static int nfs41_test_stateid(struct nfs_server *server, struct nfs4_state *state) |
| 6129 | { |
| 6130 | struct nfs4_exception exception = { }; |
| 6131 | int err; |
| 6132 | do { |
| 6133 | err = nfs4_handle_exception(server, |
| 6134 | _nfs41_test_stateid(server, state), |
| 6135 | &exception); |
| 6136 | } while (exception.retry); |
| 6137 | return err; |
| 6138 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6139 | |
| 6140 | static int _nfs4_free_stateid(struct nfs_server *server, struct nfs4_state *state) |
| 6141 | { |
| 6142 | int status; |
| 6143 | struct nfs41_free_stateid_args args = { |
| 6144 | .stateid = &state->stateid, |
| 6145 | }; |
| 6146 | struct nfs41_free_stateid_res res; |
| 6147 | struct rpc_message msg = { |
| 6148 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6149 | .rpc_argp = &args, |
| 6150 | .rpc_resp = &res, |
| 6151 | }; |
| 6152 | |
| 6153 | args.seq_args.sa_session = res.seq_res.sr_session = NULL; |
| 6154 | status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 0, 1); |
| 6155 | return status; |
| 6156 | } |
| 6157 | |
| 6158 | static int nfs41_free_stateid(struct nfs_server *server, struct nfs4_state *state) |
| 6159 | { |
| 6160 | struct nfs4_exception exception = { }; |
| 6161 | int err; |
| 6162 | do { |
| 6163 | err = nfs4_handle_exception(server, |
| 6164 | _nfs4_free_stateid(server, state), |
| 6165 | &exception); |
| 6166 | } while (exception.retry); |
| 6167 | return err; |
| 6168 | } |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6169 | #endif /* CONFIG_NFS_V4_1 */ |
| 6170 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6171 | struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6172 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6173 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6174 | .recover_open = nfs4_open_reclaim, |
| 6175 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6176 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6177 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6178 | }; |
| 6179 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6180 | #if defined(CONFIG_NFS_V4_1) |
| 6181 | struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
| 6182 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6183 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6184 | .recover_open = nfs4_open_reclaim, |
| 6185 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6186 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6187 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6188 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6189 | }; |
| 6190 | #endif /* CONFIG_NFS_V4_1 */ |
| 6191 | |
| 6192 | struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6193 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6194 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6195 | .recover_open = nfs4_open_expired, |
| 6196 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6197 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6198 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6199 | }; |
| 6200 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6201 | #if defined(CONFIG_NFS_V4_1) |
| 6202 | struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
| 6203 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6204 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6205 | .recover_open = nfs41_open_expired, |
| 6206 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6207 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6208 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6209 | }; |
| 6210 | #endif /* CONFIG_NFS_V4_1 */ |
| 6211 | |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6212 | struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
| 6213 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6214 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6215 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6216 | }; |
| 6217 | |
| 6218 | #if defined(CONFIG_NFS_V4_1) |
| 6219 | struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
| 6220 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6221 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6222 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6223 | }; |
| 6224 | #endif |
| 6225 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6226 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6227 | .minor_version = 0, |
| 6228 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6229 | .validate_stateid = nfs4_validate_delegation_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6230 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6231 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6232 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6233 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6234 | }; |
| 6235 | |
| 6236 | #if defined(CONFIG_NFS_V4_1) |
| 6237 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6238 | .minor_version = 1, |
| 6239 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6240 | .validate_stateid = nfs41_validate_delegation_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6241 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6242 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6243 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6244 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6245 | }; |
| 6246 | #endif |
| 6247 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6248 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6249 | [0] = &nfs_v4_0_minor_ops, |
| 6250 | #if defined(CONFIG_NFS_V4_1) |
| 6251 | [1] = &nfs_v4_1_minor_ops, |
| 6252 | #endif |
| 6253 | }; |
| 6254 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6255 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6256 | .permission = nfs_permission, |
| 6257 | .getattr = nfs_getattr, |
| 6258 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6259 | .getxattr = generic_getxattr, |
| 6260 | .setxattr = generic_setxattr, |
| 6261 | .listxattr = generic_listxattr, |
| 6262 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6263 | }; |
| 6264 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6265 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6266 | .version = 4, /* protocol version */ |
| 6267 | .dentry_ops = &nfs4_dentry_operations, |
| 6268 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6269 | .file_inode_ops = &nfs4_file_inode_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6270 | .getroot = nfs4_proc_get_root, |
| 6271 | .getattr = nfs4_proc_getattr, |
| 6272 | .setattr = nfs4_proc_setattr, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6273 | .lookupfh = nfs4_proc_lookupfh, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6274 | .lookup = nfs4_proc_lookup, |
| 6275 | .access = nfs4_proc_access, |
| 6276 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6277 | .create = nfs4_proc_create, |
| 6278 | .remove = nfs4_proc_remove, |
| 6279 | .unlink_setup = nfs4_proc_unlink_setup, |
| 6280 | .unlink_done = nfs4_proc_unlink_done, |
| 6281 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6282 | .rename_setup = nfs4_proc_rename_setup, |
| 6283 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6284 | .link = nfs4_proc_link, |
| 6285 | .symlink = nfs4_proc_symlink, |
| 6286 | .mkdir = nfs4_proc_mkdir, |
| 6287 | .rmdir = nfs4_proc_remove, |
| 6288 | .readdir = nfs4_proc_readdir, |
| 6289 | .mknod = nfs4_proc_mknod, |
| 6290 | .statfs = nfs4_proc_statfs, |
| 6291 | .fsinfo = nfs4_proc_fsinfo, |
| 6292 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6293 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6294 | .decode_dirent = nfs4_decode_dirent, |
| 6295 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6296 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6297 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6298 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6299 | .commit_setup = nfs4_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6300 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6301 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6302 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6303 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6304 | .open_context = nfs4_atomic_open, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6305 | .init_client = nfs4_init_client, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6306 | .secinfo = nfs4_proc_secinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6307 | }; |
| 6308 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6309 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6310 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6311 | .list = nfs4_xattr_list_nfs4_acl, |
| 6312 | .get = nfs4_xattr_get_nfs4_acl, |
| 6313 | .set = nfs4_xattr_set_nfs4_acl, |
| 6314 | }; |
| 6315 | |
| 6316 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6317 | &nfs4_xattr_nfs4_acl_handler, |
| 6318 | NULL |
| 6319 | }; |
| 6320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6321 | /* |
| 6322 | * Local variables: |
| 6323 | * c-basic-offset: 8 |
| 6324 | * End: |
| 6325 | */ |