Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 46 | #include <linux/sunrpc/gss_api.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <linux/nfs.h> |
| 48 | #include <linux/nfs4.h> |
| 49 | #include <linux/nfs_fs.h> |
| 50 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 51 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 53 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 54 | #include <linux/module.h> |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 55 | #include <linux/nfs_idmap.h> |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 56 | #include <linux/sunrpc/bc_xprt.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 57 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 58 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 59 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 61 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 63 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 64 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 65 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 66 | #include "pnfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 69 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 70 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 72 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 73 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 74 | |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 75 | static unsigned short max_session_slots = NFS4_DEF_SLOT_TABLE_SIZE; |
| 76 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 77 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 78 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 79 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | 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] | 81 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 82 | 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] | 83 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 84 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 85 | struct nfs4_state *state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 86 | #ifdef CONFIG_NFS_V4_1 |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 87 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *); |
| 88 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 89 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 91 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 93 | if (err >= -1000) |
| 94 | return err; |
| 95 | switch (err) { |
| 96 | case -NFS4ERR_RESOURCE: |
| 97 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 98 | case -NFS4ERR_WRONGSEC: |
| 99 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 100 | case -NFS4ERR_BADOWNER: |
| 101 | case -NFS4ERR_BADNAME: |
| 102 | return -EINVAL; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 103 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 105 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 106 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 108 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /* |
| 112 | * This is our standard bitmap for GETATTR requests. |
| 113 | */ |
| 114 | const u32 nfs4_fattr_bitmap[2] = { |
| 115 | FATTR4_WORD0_TYPE |
| 116 | | FATTR4_WORD0_CHANGE |
| 117 | | FATTR4_WORD0_SIZE |
| 118 | | FATTR4_WORD0_FSID |
| 119 | | FATTR4_WORD0_FILEID, |
| 120 | FATTR4_WORD1_MODE |
| 121 | | FATTR4_WORD1_NUMLINKS |
| 122 | | FATTR4_WORD1_OWNER |
| 123 | | FATTR4_WORD1_OWNER_GROUP |
| 124 | | FATTR4_WORD1_RAWDEV |
| 125 | | FATTR4_WORD1_SPACE_USED |
| 126 | | FATTR4_WORD1_TIME_ACCESS |
| 127 | | FATTR4_WORD1_TIME_METADATA |
| 128 | | FATTR4_WORD1_TIME_MODIFY |
| 129 | }; |
| 130 | |
| 131 | const u32 nfs4_statfs_bitmap[2] = { |
| 132 | FATTR4_WORD0_FILES_AVAIL |
| 133 | | FATTR4_WORD0_FILES_FREE |
| 134 | | FATTR4_WORD0_FILES_TOTAL, |
| 135 | FATTR4_WORD1_SPACE_AVAIL |
| 136 | | FATTR4_WORD1_SPACE_FREE |
| 137 | | FATTR4_WORD1_SPACE_TOTAL |
| 138 | }; |
| 139 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 140 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | FATTR4_WORD0_MAXLINK |
| 142 | | FATTR4_WORD0_MAXNAME, |
| 143 | 0 |
| 144 | }; |
| 145 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 146 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | | FATTR4_WORD0_MAXREAD |
| 148 | | FATTR4_WORD0_MAXWRITE |
| 149 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 150 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 151 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 152 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | }; |
| 154 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 155 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 156 | FATTR4_WORD0_TYPE |
| 157 | | FATTR4_WORD0_CHANGE |
| 158 | | FATTR4_WORD0_SIZE |
| 159 | | FATTR4_WORD0_FSID |
| 160 | | FATTR4_WORD0_FILEID |
| 161 | | FATTR4_WORD0_FS_LOCATIONS, |
| 162 | FATTR4_WORD1_MODE |
| 163 | | FATTR4_WORD1_NUMLINKS |
| 164 | | FATTR4_WORD1_OWNER |
| 165 | | FATTR4_WORD1_OWNER_GROUP |
| 166 | | FATTR4_WORD1_RAWDEV |
| 167 | | FATTR4_WORD1_SPACE_USED |
| 168 | | FATTR4_WORD1_TIME_ACCESS |
| 169 | | FATTR4_WORD1_TIME_METADATA |
| 170 | | FATTR4_WORD1_TIME_MODIFY |
| 171 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 172 | }; |
| 173 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 174 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | struct nfs4_readdir_arg *readdir) |
| 176 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 177 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
| 179 | BUG_ON(readdir->count < 80); |
| 180 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 181 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | readdir->cookie = 0; |
| 187 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 188 | if (cookie == 2) |
| 189 | return; |
| 190 | |
| 191 | /* |
| 192 | * NFSv4 servers do not return entries for '.' and '..' |
| 193 | * Therefore, we fake these entries here. We let '.' |
| 194 | * have cookie 0 and '..' have cookie 1. Note that |
| 195 | * when talking to the server, we always send cookie 0 |
| 196 | * instead of 1 or 2. |
| 197 | */ |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 198 | start = p = kmap_atomic(*readdir->pages, KM_USER0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | if (cookie == 0) { |
| 201 | *p++ = xdr_one; /* next */ |
| 202 | *p++ = xdr_zero; /* cookie, first word */ |
| 203 | *p++ = xdr_one; /* cookie, second word */ |
| 204 | *p++ = xdr_one; /* entry len */ |
| 205 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 206 | p++; |
| 207 | *p++ = xdr_one; /* bitmap length */ |
| 208 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 209 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 210 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | *p++ = xdr_one; /* next */ |
| 214 | *p++ = xdr_zero; /* cookie, first word */ |
| 215 | *p++ = xdr_two; /* cookie, second word */ |
| 216 | *p++ = xdr_two; /* entry len */ |
| 217 | memcpy(p, "..\0\0", 4); /* entry */ |
| 218 | p++; |
| 219 | *p++ = xdr_one; /* bitmap length */ |
| 220 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 221 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 222 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
| 224 | readdir->pgbase = (char *)p - (char *)start; |
| 225 | readdir->count -= readdir->pgbase; |
| 226 | kunmap_atomic(start, KM_USER0); |
| 227 | } |
| 228 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 229 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 230 | { |
| 231 | int res; |
| 232 | |
| 233 | might_sleep(); |
| 234 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 235 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 236 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 237 | return res; |
| 238 | } |
| 239 | |
| 240 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 241 | { |
| 242 | int res = 0; |
| 243 | |
| 244 | might_sleep(); |
| 245 | |
| 246 | if (*timeout <= 0) |
| 247 | *timeout = NFS4_POLL_RETRY_MIN; |
| 248 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 249 | *timeout = NFS4_POLL_RETRY_MAX; |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 250 | freezable_schedule_timeout_killable(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 251 | if (fatal_signal_pending(current)) |
| 252 | res = -ERESTARTSYS; |
| 253 | *timeout <<= 1; |
| 254 | return res; |
| 255 | } |
| 256 | |
| 257 | /* This is the error handling routine for processes that are allowed |
| 258 | * to sleep. |
| 259 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 260 | 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] | 261 | { |
| 262 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 263 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 264 | int ret = errorcode; |
| 265 | |
| 266 | exception->retry = 0; |
| 267 | switch(errorcode) { |
| 268 | case 0: |
| 269 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 270 | case -NFS4ERR_ADMIN_REVOKED: |
| 271 | case -NFS4ERR_BAD_STATEID: |
| 272 | case -NFS4ERR_OPENMODE: |
| 273 | if (state == NULL) |
| 274 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 275 | nfs4_schedule_stateid_recovery(server, state); |
| 276 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 277 | case -NFS4ERR_EXPIRED: |
| 278 | if (state != NULL) |
| 279 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 280 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 281 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 282 | nfs4_schedule_lease_recovery(clp); |
| 283 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 284 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 285 | case -NFS4ERR_BADSESSION: |
| 286 | case -NFS4ERR_BADSLOT: |
| 287 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 288 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 289 | case -NFS4ERR_DEADSESSION: |
| 290 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 291 | case -NFS4ERR_SEQ_MISORDERED: |
| 292 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 293 | errorcode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 294 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 295 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 296 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 297 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 298 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 299 | if (exception->timeout > HZ) { |
| 300 | /* We have retried a decent amount, time to |
| 301 | * fail |
| 302 | */ |
| 303 | ret = -EBUSY; |
| 304 | break; |
| 305 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 306 | case -NFS4ERR_GRACE: |
| 307 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 308 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 309 | ret = nfs4_delay(server->client, &exception->timeout); |
| 310 | if (ret != 0) |
| 311 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 312 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 313 | case -NFS4ERR_OLD_STATEID: |
| 314 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 315 | break; |
| 316 | case -NFS4ERR_BADOWNER: |
| 317 | /* The following works around a Linux server bug! */ |
| 318 | case -NFS4ERR_BADNAME: |
| 319 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 320 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 321 | exception->retry = 1; |
| 322 | printk(KERN_WARNING "NFS: v4 server %s " |
| 323 | "does not accept raw " |
| 324 | "uid/gids. " |
| 325 | "Reenabling the idmapper.\n", |
| 326 | server->nfs_client->cl_hostname); |
| 327 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 328 | } |
| 329 | /* We failed to handle the error */ |
| 330 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 331 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 332 | ret = nfs4_wait_clnt_recover(clp); |
| 333 | if (ret == 0) |
| 334 | exception->retry = 1; |
| 335 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 339 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | spin_lock(&clp->cl_lock); |
| 342 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 343 | clp->cl_last_renewal = timestamp; |
| 344 | spin_unlock(&clp->cl_lock); |
| 345 | } |
| 346 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 347 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 348 | { |
| 349 | do_renew_lease(server->nfs_client, timestamp); |
| 350 | } |
| 351 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 352 | #if defined(CONFIG_NFS_V4_1) |
| 353 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 354 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 355 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 356 | * |
| 357 | * freeing a slot is trivially done by clearing its respective bit |
| 358 | * in the bitmap. |
| 359 | * If the freed slotid equals highest_used_slotid we want to update it |
| 360 | * so that the server would be able to size down the slot table if needed, |
| 361 | * otherwise we know that the highest_used_slotid is still in use. |
| 362 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 363 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 364 | * highest slotid in use. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 365 | * If none found, highest_used_slotid is set to NFS4_NO_SLOT. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 366 | * |
| 367 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 368 | */ |
| 369 | static void |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 370 | nfs4_free_slot(struct nfs4_slot_table *tbl, u32 slotid) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 371 | { |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 372 | BUG_ON(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 |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 382 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 383 | } |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 384 | dprintk("%s: slotid %u highest_used_slotid %d\n", __func__, |
| 385 | slotid, tbl->highest_used_slotid); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 386 | } |
| 387 | |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 388 | bool nfs4_set_task_privileged(struct rpc_task *task, void *dummy) |
| 389 | { |
| 390 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 391 | return true; |
| 392 | } |
| 393 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 394 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 395 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 396 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 397 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 398 | { |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 399 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 400 | rpc_wake_up_first(&ses->fc_slot_table.slot_tbl_waitq, |
| 401 | nfs4_set_task_privileged, NULL); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 402 | return; |
| 403 | } |
| 404 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 405 | if (ses->fc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 406 | return; |
| 407 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 408 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 409 | complete(&ses->fc_slot_table.complete); |
| 410 | } |
| 411 | |
| 412 | /* |
| 413 | * Signal state manager thread if session back channel is drained |
| 414 | */ |
| 415 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 416 | { |
| 417 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 418 | ses->bc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 419 | return; |
| 420 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 421 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 422 | } |
| 423 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 424 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 425 | { |
| 426 | struct nfs4_slot_table *tbl; |
| 427 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 428 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 429 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 430 | /* just wake up the next guy waiting since |
| 431 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 432 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 433 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 434 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 435 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 436 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | aabd0b4 | 2011-11-09 13:58:22 -0500 | [diff] [blame] | 437 | nfs4_free_slot(tbl, res->sr_slot - tbl->slots); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 438 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 439 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 440 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 441 | } |
| 442 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 443 | 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] | 444 | { |
| 445 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 446 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 447 | |
| 448 | /* |
| 449 | * sr_status remains 1 if an RPC level error occurred. The server |
| 450 | * may or may not have processed the sequence operation.. |
| 451 | * Proceed as if the server received and processed the sequence |
| 452 | * operation. |
| 453 | */ |
| 454 | if (res->sr_status == 1) |
| 455 | res->sr_status = NFS_OK; |
| 456 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 457 | /* don't increment the sequence number if the task wasn't sent */ |
| 458 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 459 | goto out; |
| 460 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 461 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 462 | switch (res->sr_status) { |
| 463 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 464 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 465 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 466 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 467 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 468 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 469 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 470 | if (res->sr_status_flags != 0) |
| 471 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 472 | break; |
| 473 | case -NFS4ERR_DELAY: |
| 474 | /* The server detected a resend of the RPC call and |
| 475 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 476 | * of RFC5661. |
| 477 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 478 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 479 | __func__, |
| 480 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 481 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 482 | goto out_retry; |
| 483 | default: |
| 484 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 485 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 486 | } |
| 487 | out: |
| 488 | /* The session may be reset by one of the error handlers. */ |
| 489 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 490 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 491 | return 1; |
| 492 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 493 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 494 | goto out; |
| 495 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 496 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 497 | } |
| 498 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 499 | static int nfs4_sequence_done(struct rpc_task *task, |
| 500 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 501 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 502 | if (res->sr_session == NULL) |
| 503 | return 1; |
| 504 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 505 | } |
| 506 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 507 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 508 | * nfs4_find_slot - efficiently look for a free slot |
| 509 | * |
| 510 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 511 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 512 | * and respectively set up the sequence operation args. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 513 | * The slot number is returned if found, or NFS4_NO_SLOT otherwise. |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 514 | * |
| 515 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 516 | */ |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 517 | static u32 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 518 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 519 | { |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 520 | u32 slotid; |
| 521 | u32 ret_id = NFS4_NO_SLOT; |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 522 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 523 | dprintk("--> %s used_slots=%04lx highest_used=%u max_slots=%u\n", |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 524 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 525 | tbl->max_slots); |
| 526 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 527 | if (slotid >= tbl->max_slots) |
| 528 | goto out; |
| 529 | __set_bit(slotid, tbl->used_slots); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 530 | if (slotid > tbl->highest_used_slotid || |
| 531 | tbl->highest_used_slotid == NFS4_NO_SLOT) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 532 | tbl->highest_used_slotid = slotid; |
| 533 | ret_id = slotid; |
| 534 | out: |
| 535 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 536 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 537 | return ret_id; |
| 538 | } |
| 539 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 540 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 541 | struct nfs4_sequence_res *res, int cache_reply) |
| 542 | { |
| 543 | args->sa_session = NULL; |
| 544 | args->sa_cache_this = 0; |
| 545 | if (cache_reply) |
| 546 | args->sa_cache_this = 1; |
| 547 | res->sr_session = NULL; |
| 548 | res->sr_slot = NULL; |
| 549 | } |
| 550 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 551 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 552 | struct nfs4_sequence_args *args, |
| 553 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 554 | struct rpc_task *task) |
| 555 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 556 | struct nfs4_slot *slot; |
| 557 | struct nfs4_slot_table *tbl; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 558 | u32 slotid; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 559 | |
| 560 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 561 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 562 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 563 | return 0; |
| 564 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 565 | tbl = &session->fc_slot_table; |
| 566 | |
| 567 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 568 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 569 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 570 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 571 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 572 | spin_unlock(&tbl->slot_tbl_lock); |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 573 | dprintk("%s session is draining\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 574 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 575 | } |
| 576 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 577 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 578 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 579 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 580 | spin_unlock(&tbl->slot_tbl_lock); |
| 581 | dprintk("%s enforce FIFO order\n", __func__); |
| 582 | return -EAGAIN; |
| 583 | } |
| 584 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 585 | slotid = nfs4_find_slot(tbl); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 586 | if (slotid == NFS4_NO_SLOT) { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 587 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 588 | spin_unlock(&tbl->slot_tbl_lock); |
| 589 | dprintk("<-- %s: no free slots\n", __func__); |
| 590 | return -EAGAIN; |
| 591 | } |
| 592 | spin_unlock(&tbl->slot_tbl_lock); |
| 593 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 594 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 595 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 596 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 597 | args->sa_slotid = slotid; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 598 | |
| 599 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 600 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 601 | res->sr_session = session; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 602 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 603 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 604 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 605 | /* |
| 606 | * sr_status is only set in decode_sequence, and so will remain |
| 607 | * set to 1 if an rpc level failure occurs. |
| 608 | */ |
| 609 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 610 | return 0; |
| 611 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 612 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 613 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 614 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 615 | struct nfs4_sequence_args *args, |
| 616 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 617 | struct rpc_task *task) |
| 618 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 619 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 620 | int ret = 0; |
| 621 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 622 | if (session == NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 623 | goto out; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 624 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 625 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 626 | __func__, session->clp, session, res->sr_slot ? |
| 627 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 628 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 629 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 630 | out: |
| 631 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 632 | return ret; |
| 633 | } |
| 634 | |
| 635 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 636 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 637 | struct nfs4_sequence_args *seq_args; |
| 638 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 639 | }; |
| 640 | |
| 641 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 642 | { |
| 643 | struct nfs41_call_sync_data *data = calldata; |
| 644 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 645 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 646 | |
| 647 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 648 | data->seq_res, task)) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 649 | return; |
| 650 | rpc_call_start(task); |
| 651 | } |
| 652 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 653 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 654 | { |
| 655 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 656 | nfs41_call_sync_prepare(task, calldata); |
| 657 | } |
| 658 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 659 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 660 | { |
| 661 | struct nfs41_call_sync_data *data = calldata; |
| 662 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 663 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 664 | } |
| 665 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 666 | struct rpc_call_ops nfs41_call_sync_ops = { |
| 667 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 668 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 669 | }; |
| 670 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 671 | struct rpc_call_ops nfs41_call_priv_sync_ops = { |
| 672 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 673 | .rpc_call_done = nfs41_call_sync_done, |
| 674 | }; |
| 675 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 676 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 677 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 678 | struct rpc_message *msg, |
| 679 | struct nfs4_sequence_args *args, |
| 680 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 681 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 682 | { |
| 683 | int ret; |
| 684 | struct rpc_task *task; |
| 685 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 686 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 687 | .seq_args = args, |
| 688 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 689 | }; |
| 690 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 691 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 692 | .rpc_message = msg, |
| 693 | .callback_ops = &nfs41_call_sync_ops, |
| 694 | .callback_data = &data |
| 695 | }; |
| 696 | |
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 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 716 | nfs41_init_sequence(args, res, cache_reply); |
| 717 | return nfs4_call_sync_sequence(clnt, server, msg, args, res, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 718 | } |
| 719 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 720 | #else |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 721 | static inline |
| 722 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 723 | struct nfs4_sequence_res *res, int cache_reply) |
| 724 | { |
| 725 | } |
| 726 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 727 | static int nfs4_sequence_done(struct rpc_task *task, |
| 728 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 729 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 730 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 731 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 732 | #endif /* CONFIG_NFS_V4_1 */ |
| 733 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 734 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 735 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 736 | struct rpc_message *msg, |
| 737 | struct nfs4_sequence_args *args, |
| 738 | struct nfs4_sequence_res *res, |
| 739 | int cache_reply) |
| 740 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 741 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 742 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 743 | } |
| 744 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 745 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 746 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 747 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 748 | struct rpc_message *msg, |
| 749 | struct nfs4_sequence_args *args, |
| 750 | struct nfs4_sequence_res *res, |
| 751 | int cache_reply) |
| 752 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 753 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 754 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 755 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 756 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 757 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 759 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 761 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 762 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 763 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 764 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 765 | dir->i_version = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 766 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | } |
| 768 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 769 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 770 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 771 | struct nfs_openargs o_arg; |
| 772 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 773 | struct nfs_open_confirmargs c_arg; |
| 774 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 775 | struct nfs4_string owner_name; |
| 776 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 777 | struct nfs_fattr f_attr; |
| 778 | struct nfs_fattr dir_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 779 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 780 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 781 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 782 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 783 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 784 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 785 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 786 | int rpc_status; |
| 787 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 788 | }; |
| 789 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 790 | |
| 791 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 792 | { |
| 793 | p->o_res.f_attr = &p->f_attr; |
| 794 | p->o_res.dir_attr = &p->dir_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 795 | p->o_res.seqid = p->o_arg.seqid; |
| 796 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 797 | p->o_res.server = p->o_arg.server; |
| 798 | nfs_fattr_init(&p->f_attr); |
| 799 | nfs_fattr_init(&p->dir_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 800 | nfs_fattr_init_names(&p->f_attr, &p->owner_name, &p->group_name); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 801 | } |
| 802 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 803 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 804 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 805 | const struct iattr *attrs, |
| 806 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 807 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 808 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 809 | struct inode *dir = parent->d_inode; |
| 810 | struct nfs_server *server = NFS_SERVER(dir); |
| 811 | struct nfs4_opendata *p; |
| 812 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 813 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 814 | if (p == NULL) |
| 815 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 816 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 817 | if (p->o_arg.seqid == NULL) |
| 818 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 819 | nfs_sb_active(dentry->d_sb); |
| 820 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 821 | p->dir = parent; |
| 822 | p->owner = sp; |
| 823 | atomic_inc(&sp->so_count); |
| 824 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 825 | p->o_arg.open_flags = flags; |
| 826 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 827 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 828 | p->o_arg.id = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 829 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 830 | p->o_arg.server = server; |
| 831 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 832 | p->o_arg.dir_bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 833 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 834 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 835 | u32 *s; |
| 836 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 837 | p->o_arg.u.attrs = &p->attrs; |
| 838 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 839 | s = (u32 *) p->o_arg.u.verifier.data; |
| 840 | s[0] = jiffies; |
| 841 | s[1] = current->pid; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 842 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 843 | p->c_arg.fh = &p->o_res.fh; |
| 844 | p->c_arg.stateid = &p->o_res.stateid; |
| 845 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 846 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 847 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 848 | return p; |
| 849 | err_free: |
| 850 | kfree(p); |
| 851 | err: |
| 852 | dput(parent); |
| 853 | return NULL; |
| 854 | } |
| 855 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 856 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 857 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 858 | struct nfs4_opendata *p = container_of(kref, |
| 859 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 860 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 861 | |
| 862 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 863 | if (p->state != NULL) |
| 864 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 865 | nfs4_put_state_owner(p->owner); |
| 866 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 867 | dput(p->dentry); |
| 868 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 869 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 870 | kfree(p); |
| 871 | } |
| 872 | |
| 873 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 874 | { |
| 875 | if (p != NULL) |
| 876 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 877 | } |
| 878 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 879 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 880 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 881 | int ret; |
| 882 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 883 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 884 | return ret; |
| 885 | } |
| 886 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 887 | 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] | 888 | { |
| 889 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 890 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 891 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 892 | goto out; |
| 893 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 894 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 895 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 896 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 897 | break; |
| 898 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 899 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 900 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 901 | break; |
| 902 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 903 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 904 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 905 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 906 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 907 | return ret; |
| 908 | } |
| 909 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 910 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 911 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 912 | if (delegation == NULL) |
| 913 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 914 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 915 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 916 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 917 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 918 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 919 | return 1; |
| 920 | } |
| 921 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 922 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 923 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 924 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 925 | case FMODE_WRITE: |
| 926 | state->n_wronly++; |
| 927 | break; |
| 928 | case FMODE_READ: |
| 929 | state->n_rdonly++; |
| 930 | break; |
| 931 | case FMODE_READ|FMODE_WRITE: |
| 932 | state->n_rdwr++; |
| 933 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 934 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 935 | } |
| 936 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 937 | 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] | 938 | { |
| 939 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 940 | memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); |
| 941 | memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 942 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 943 | case FMODE_READ: |
| 944 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 945 | break; |
| 946 | case FMODE_WRITE: |
| 947 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 948 | break; |
| 949 | case FMODE_READ|FMODE_WRITE: |
| 950 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 951 | } |
| 952 | } |
| 953 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 954 | 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] | 955 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 956 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 957 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 958 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 959 | } |
| 960 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 961 | 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] | 962 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 963 | /* |
| 964 | * Protect the call to nfs4_state_set_mode_locked and |
| 965 | * serialise the stateid update |
| 966 | */ |
| 967 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 968 | if (deleg_stateid != NULL) { |
| 969 | memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); |
| 970 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 971 | } |
| 972 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 973 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 974 | write_sequnlock(&state->seqlock); |
| 975 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 976 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 977 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | } |
| 979 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 980 | 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] | 981 | { |
| 982 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 983 | struct nfs_delegation *deleg_cur; |
| 984 | int ret = 0; |
| 985 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 986 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 987 | |
| 988 | rcu_read_lock(); |
| 989 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 990 | if (deleg_cur == NULL) |
| 991 | goto no_delegation; |
| 992 | |
| 993 | spin_lock(&deleg_cur->lock); |
| 994 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 995 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 996 | goto no_delegation_unlock; |
| 997 | |
| 998 | if (delegation == NULL) |
| 999 | delegation = &deleg_cur->stateid; |
| 1000 | else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) |
| 1001 | goto no_delegation_unlock; |
| 1002 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1003 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1004 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1005 | ret = 1; |
| 1006 | no_delegation_unlock: |
| 1007 | spin_unlock(&deleg_cur->lock); |
| 1008 | no_delegation: |
| 1009 | rcu_read_unlock(); |
| 1010 | |
| 1011 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1012 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1013 | ret = 1; |
| 1014 | } |
| 1015 | |
| 1016 | return ret; |
| 1017 | } |
| 1018 | |
| 1019 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1020 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1021 | { |
| 1022 | struct nfs_delegation *delegation; |
| 1023 | |
| 1024 | rcu_read_lock(); |
| 1025 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1026 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1027 | rcu_read_unlock(); |
| 1028 | return; |
| 1029 | } |
| 1030 | rcu_read_unlock(); |
| 1031 | nfs_inode_return_delegation(inode); |
| 1032 | } |
| 1033 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1034 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1035 | { |
| 1036 | struct nfs4_state *state = opendata->state; |
| 1037 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1038 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1039 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1040 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1041 | nfs4_stateid stateid; |
| 1042 | int ret = -EAGAIN; |
| 1043 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1044 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1045 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1046 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1047 | if (can_open_cached(state, fmode, open_mode)) { |
| 1048 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1049 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1050 | goto out_return_state; |
| 1051 | } |
| 1052 | spin_unlock(&state->owner->so_lock); |
| 1053 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1054 | rcu_read_lock(); |
| 1055 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1056 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1057 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1058 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1059 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1060 | /* Save the delegation */ |
| 1061 | memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); |
| 1062 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1063 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1064 | if (ret != 0) |
| 1065 | goto out; |
| 1066 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1067 | |
| 1068 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1069 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1070 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1071 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1072 | out: |
| 1073 | return ERR_PTR(ret); |
| 1074 | out_return_state: |
| 1075 | atomic_inc(&state->count); |
| 1076 | return state; |
| 1077 | } |
| 1078 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1079 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1080 | { |
| 1081 | struct inode *inode; |
| 1082 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1083 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1084 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1085 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1086 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1087 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1088 | goto out; |
| 1089 | } |
| 1090 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1091 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1092 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1093 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1094 | 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] | 1095 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1096 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1097 | goto err; |
| 1098 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1099 | state = nfs4_get_open_state(inode, data->owner); |
| 1100 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1101 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1102 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1103 | int delegation_flags = 0; |
| 1104 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1105 | rcu_read_lock(); |
| 1106 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1107 | if (delegation) |
| 1108 | delegation_flags = delegation->flags; |
| 1109 | rcu_read_unlock(); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1110 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1111 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1112 | "returning a delegation for " |
| 1113 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1114 | NFS_CLIENT(inode)->cl_server); |
| 1115 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1116 | nfs_inode_set_delegation(state->inode, |
| 1117 | data->owner->so_cred, |
| 1118 | &data->o_res); |
| 1119 | else |
| 1120 | nfs_inode_reclaim_delegation(state->inode, |
| 1121 | data->owner->so_cred, |
| 1122 | &data->o_res); |
| 1123 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1124 | |
| 1125 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1126 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1127 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1128 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1129 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1130 | err_put_inode: |
| 1131 | iput(inode); |
| 1132 | err: |
| 1133 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1134 | } |
| 1135 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1136 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1137 | { |
| 1138 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1139 | struct nfs_open_context *ctx; |
| 1140 | |
| 1141 | spin_lock(&state->inode->i_lock); |
| 1142 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1143 | if (ctx->state != state) |
| 1144 | continue; |
| 1145 | get_nfs_open_context(ctx); |
| 1146 | spin_unlock(&state->inode->i_lock); |
| 1147 | return ctx; |
| 1148 | } |
| 1149 | spin_unlock(&state->inode->i_lock); |
| 1150 | return ERR_PTR(-ENOENT); |
| 1151 | } |
| 1152 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1153 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1154 | { |
| 1155 | struct nfs4_opendata *opendata; |
| 1156 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1157 | 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] | 1158 | if (opendata == NULL) |
| 1159 | return ERR_PTR(-ENOMEM); |
| 1160 | opendata->state = state; |
| 1161 | atomic_inc(&state->count); |
| 1162 | return opendata; |
| 1163 | } |
| 1164 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1165 | 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] | 1166 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1167 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1168 | int ret; |
| 1169 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1170 | opendata->o_arg.open_flags = 0; |
| 1171 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1172 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1173 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1174 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1175 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1176 | if (ret != 0) |
| 1177 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1178 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1179 | if (IS_ERR(newstate)) |
| 1180 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1181 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1182 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1183 | return 0; |
| 1184 | } |
| 1185 | |
| 1186 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1187 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1188 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1189 | int ret; |
| 1190 | |
| 1191 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1192 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1193 | smp_rmb(); |
| 1194 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1195 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1196 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1197 | if (ret != 0) |
| 1198 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1199 | if (newstate != state) |
| 1200 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1201 | } |
| 1202 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1203 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1204 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1205 | if (ret != 0) |
| 1206 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1207 | if (newstate != state) |
| 1208 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1209 | } |
| 1210 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1211 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1212 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1213 | if (ret != 0) |
| 1214 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1215 | if (newstate != state) |
| 1216 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1217 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1218 | /* |
| 1219 | * We may have performed cached opens for all three recoveries. |
| 1220 | * Check if we need to update the current stateid. |
| 1221 | */ |
| 1222 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
| 1223 | 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] | 1224 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1225 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1226 | memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1227 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1228 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1229 | return 0; |
| 1230 | } |
| 1231 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | /* |
| 1233 | * OPEN_RECLAIM: |
| 1234 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1236 | 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] | 1237 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1238 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1239 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1240 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | int status; |
| 1242 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1243 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1244 | if (IS_ERR(opendata)) |
| 1245 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1246 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1247 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1248 | rcu_read_lock(); |
| 1249 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1250 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1251 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1252 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1253 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1254 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1255 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | return status; |
| 1257 | } |
| 1258 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1259 | 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] | 1260 | { |
| 1261 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1262 | struct nfs4_exception exception = { }; |
| 1263 | int err; |
| 1264 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1265 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1266 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1267 | break; |
| 1268 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | } while (exception.retry); |
| 1270 | return err; |
| 1271 | } |
| 1272 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1273 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1274 | { |
| 1275 | struct nfs_open_context *ctx; |
| 1276 | int ret; |
| 1277 | |
| 1278 | ctx = nfs4_state_find_open_context(state); |
| 1279 | if (IS_ERR(ctx)) |
| 1280 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1281 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1282 | put_nfs_open_context(ctx); |
| 1283 | return ret; |
| 1284 | } |
| 1285 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1286 | 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] | 1287 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1288 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1289 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1291 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1292 | if (IS_ERR(opendata)) |
| 1293 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1294 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1295 | memcpy(opendata->o_arg.u.delegation.data, stateid->data, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1296 | sizeof(opendata->o_arg.u.delegation.data)); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1297 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1298 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1299 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | } |
| 1301 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1302 | 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] | 1303 | { |
| 1304 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1305 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | int err; |
| 1307 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1308 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | switch (err) { |
| 1310 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1311 | case -ENOENT: |
| 1312 | case -ESTALE: |
| 1313 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1314 | case -NFS4ERR_BADSESSION: |
| 1315 | case -NFS4ERR_BADSLOT: |
| 1316 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1317 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1318 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1319 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1320 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | case -NFS4ERR_STALE_CLIENTID: |
| 1322 | case -NFS4ERR_STALE_STATEID: |
| 1323 | case -NFS4ERR_EXPIRED: |
| 1324 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1325 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1326 | goto out; |
| 1327 | case -ERESTARTSYS: |
| 1328 | /* |
| 1329 | * The show must go on: exit, but mark the |
| 1330 | * stateid as needing recovery. |
| 1331 | */ |
| 1332 | case -NFS4ERR_ADMIN_REVOKED: |
| 1333 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1334 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1335 | case -EKEYEXPIRED: |
| 1336 | /* |
| 1337 | * User RPCSEC_GSS context has expired. |
| 1338 | * We cannot recover this stateid now, so |
| 1339 | * skip it and allow recovery thread to |
| 1340 | * proceed. |
| 1341 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1342 | case -ENOMEM: |
| 1343 | err = 0; |
| 1344 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | } |
| 1346 | err = nfs4_handle_exception(server, err, &exception); |
| 1347 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1348 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | return err; |
| 1350 | } |
| 1351 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1352 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1353 | { |
| 1354 | struct nfs4_opendata *data = calldata; |
| 1355 | |
| 1356 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1357 | if (data->rpc_status == 0) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1358 | memcpy(data->o_res.stateid.data, data->c_res.stateid.data, |
| 1359 | sizeof(data->o_res.stateid.data)); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1360 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1361 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1362 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1363 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | static void nfs4_open_confirm_release(void *calldata) |
| 1367 | { |
| 1368 | struct nfs4_opendata *data = calldata; |
| 1369 | struct nfs4_state *state = NULL; |
| 1370 | |
| 1371 | /* If this request hasn't been cancelled, do nothing */ |
| 1372 | if (data->cancelled == 0) |
| 1373 | goto out_free; |
| 1374 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1375 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1376 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1377 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1378 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1379 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1380 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1381 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1385 | .rpc_call_done = nfs4_open_confirm_done, |
| 1386 | .rpc_release = nfs4_open_confirm_release, |
| 1387 | }; |
| 1388 | |
| 1389 | /* |
| 1390 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1391 | */ |
| 1392 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1393 | { |
| 1394 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1395 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1396 | struct rpc_message msg = { |
| 1397 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1398 | .rpc_argp = &data->c_arg, |
| 1399 | .rpc_resp = &data->c_res, |
| 1400 | .rpc_cred = data->owner->so_cred, |
| 1401 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1402 | struct rpc_task_setup task_setup_data = { |
| 1403 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1404 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1405 | .callback_ops = &nfs4_open_confirm_ops, |
| 1406 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1407 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1408 | .flags = RPC_TASK_ASYNC, |
| 1409 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | int status; |
| 1411 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1412 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1413 | data->rpc_done = 0; |
| 1414 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1415 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1416 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1417 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1418 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1419 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1420 | if (status != 0) { |
| 1421 | data->cancelled = 1; |
| 1422 | smp_wmb(); |
| 1423 | } else |
| 1424 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1425 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | return status; |
| 1427 | } |
| 1428 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1429 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1431 | struct nfs4_opendata *data = calldata; |
| 1432 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1433 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1434 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1435 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1436 | /* |
| 1437 | * Check if we still need to send an OPEN call, or if we can use |
| 1438 | * a delegation instead. |
| 1439 | */ |
| 1440 | if (data->state != NULL) { |
| 1441 | struct nfs_delegation *delegation; |
| 1442 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1443 | 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] | 1444 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1445 | rcu_read_lock(); |
| 1446 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1447 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1448 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1449 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1450 | rcu_read_unlock(); |
| 1451 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1452 | /* Update sequence id. */ |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1453 | data->o_arg.id = sp->so_seqid.owner_id; |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1454 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1455 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1456 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1457 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1458 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1459 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1460 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1461 | &data->o_arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1462 | &data->o_res.seq_res, task)) |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1463 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1464 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1465 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1466 | unlock_no_action: |
| 1467 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1468 | out_no_action: |
| 1469 | task->tk_action = NULL; |
| 1470 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1471 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1473 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1474 | { |
| 1475 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1476 | nfs4_open_prepare(task, calldata); |
| 1477 | } |
| 1478 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1479 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1480 | { |
| 1481 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1483 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1484 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1485 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1486 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1487 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1488 | if (task->tk_status == 0) { |
| 1489 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1490 | case S_IFREG: |
| 1491 | break; |
| 1492 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1493 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1494 | break; |
| 1495 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1496 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1497 | break; |
| 1498 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1499 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1500 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1501 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1502 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1503 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1504 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1505 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1506 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1507 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1508 | static void nfs4_open_release(void *calldata) |
| 1509 | { |
| 1510 | struct nfs4_opendata *data = calldata; |
| 1511 | struct nfs4_state *state = NULL; |
| 1512 | |
| 1513 | /* If this request hasn't been cancelled, do nothing */ |
| 1514 | if (data->cancelled == 0) |
| 1515 | goto out_free; |
| 1516 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1517 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1518 | goto out_free; |
| 1519 | /* In case we need an open_confirm, no cleanup! */ |
| 1520 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1521 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1522 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1523 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1524 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1525 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1526 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1530 | .rpc_call_prepare = nfs4_open_prepare, |
| 1531 | .rpc_call_done = nfs4_open_done, |
| 1532 | .rpc_release = nfs4_open_release, |
| 1533 | }; |
| 1534 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1535 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1536 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1537 | .rpc_call_done = nfs4_open_done, |
| 1538 | .rpc_release = nfs4_open_release, |
| 1539 | }; |
| 1540 | |
| 1541 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1542 | { |
| 1543 | struct inode *dir = data->dir->d_inode; |
| 1544 | struct nfs_server *server = NFS_SERVER(dir); |
| 1545 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1546 | struct nfs_openres *o_res = &data->o_res; |
| 1547 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1548 | struct rpc_message msg = { |
| 1549 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1550 | .rpc_argp = o_arg, |
| 1551 | .rpc_resp = o_res, |
| 1552 | .rpc_cred = data->owner->so_cred, |
| 1553 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1554 | struct rpc_task_setup task_setup_data = { |
| 1555 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1556 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1557 | .callback_ops = &nfs4_open_ops, |
| 1558 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1559 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1560 | .flags = RPC_TASK_ASYNC, |
| 1561 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1562 | int status; |
| 1563 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1564 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1565 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1566 | data->rpc_done = 0; |
| 1567 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1568 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1569 | if (isrecover) |
| 1570 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1571 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1572 | if (IS_ERR(task)) |
| 1573 | return PTR_ERR(task); |
| 1574 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1575 | if (status != 0) { |
| 1576 | data->cancelled = 1; |
| 1577 | smp_wmb(); |
| 1578 | } else |
| 1579 | status = data->rpc_status; |
| 1580 | rpc_put_task(task); |
| 1581 | |
| 1582 | return status; |
| 1583 | } |
| 1584 | |
| 1585 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1586 | { |
| 1587 | struct inode *dir = data->dir->d_inode; |
| 1588 | struct nfs_openres *o_res = &data->o_res; |
| 1589 | int status; |
| 1590 | |
| 1591 | status = nfs4_run_open_task(data, 1); |
| 1592 | if (status != 0 || !data->rpc_done) |
| 1593 | return status; |
| 1594 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1595 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1596 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1597 | nfs_refresh_inode(dir, o_res->dir_attr); |
| 1598 | |
| 1599 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1600 | status = _nfs4_proc_open_confirm(data); |
| 1601 | if (status != 0) |
| 1602 | return status; |
| 1603 | } |
| 1604 | |
| 1605 | return status; |
| 1606 | } |
| 1607 | |
| 1608 | /* |
| 1609 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1610 | */ |
| 1611 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1612 | { |
| 1613 | struct inode *dir = data->dir->d_inode; |
| 1614 | struct nfs_server *server = NFS_SERVER(dir); |
| 1615 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1616 | struct nfs_openres *o_res = &data->o_res; |
| 1617 | int status; |
| 1618 | |
| 1619 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1620 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1621 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1622 | if (status != 0) { |
| 1623 | if (status == -NFS4ERR_BADNAME && |
| 1624 | !(o_arg->open_flags & O_CREAT)) |
| 1625 | return -ENOENT; |
| 1626 | return status; |
| 1627 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1628 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1629 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1630 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1631 | if (o_arg->open_flags & O_CREAT) { |
| 1632 | update_changeattr(dir, &o_res->cinfo); |
| 1633 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
| 1634 | } else |
| 1635 | nfs_refresh_inode(dir, o_res->dir_attr); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1636 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1637 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1639 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1641 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | } |
| 1643 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1644 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1645 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | } |
| 1647 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1648 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1649 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1650 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1651 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1652 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1653 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1654 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1655 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1656 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1657 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1658 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1659 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1660 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1661 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1662 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1663 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1664 | } |
| 1665 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1666 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1667 | { |
| 1668 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1669 | } |
| 1670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | /* |
| 1672 | * OPEN_EXPIRED: |
| 1673 | * reclaim state on the server after a network partition. |
| 1674 | * Assumes caller holds the appropriate lock |
| 1675 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1676 | 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] | 1677 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1678 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1679 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1681 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1682 | if (IS_ERR(opendata)) |
| 1683 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1684 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1685 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1686 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1687 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1688 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | } |
| 1690 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1691 | 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] | 1692 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1693 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1694 | struct nfs4_exception exception = { }; |
| 1695 | int err; |
| 1696 | |
| 1697 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1698 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1699 | switch (err) { |
| 1700 | default: |
| 1701 | goto out; |
| 1702 | case -NFS4ERR_GRACE: |
| 1703 | case -NFS4ERR_DELAY: |
| 1704 | nfs4_handle_exception(server, err, &exception); |
| 1705 | err = 0; |
| 1706 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1707 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1708 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1709 | return err; |
| 1710 | } |
| 1711 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1713 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1715 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1717 | ctx = nfs4_state_find_open_context(state); |
| 1718 | if (IS_ERR(ctx)) |
| 1719 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1720 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1721 | put_nfs_open_context(ctx); |
| 1722 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | } |
| 1724 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1725 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1726 | static int nfs41_check_expired_stateid(struct nfs4_state *state, nfs4_stateid *stateid, unsigned int flags) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1727 | { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1728 | int status = NFS_OK; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1729 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1730 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1731 | if (state->flags & flags) { |
| 1732 | status = nfs41_test_stateid(server, stateid); |
| 1733 | if (status != NFS_OK) { |
| 1734 | nfs41_free_stateid(server, stateid); |
| 1735 | state->flags &= ~flags; |
| 1736 | } |
| 1737 | } |
| 1738 | return status; |
| 1739 | } |
| 1740 | |
| 1741 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1742 | { |
| 1743 | int deleg_status, open_status; |
| 1744 | int deleg_flags = 1 << NFS_DELEGATED_STATE; |
| 1745 | int open_flags = (1 << NFS_O_RDONLY_STATE) | (1 << NFS_O_WRONLY_STATE) | (1 << NFS_O_RDWR_STATE); |
| 1746 | |
| 1747 | deleg_status = nfs41_check_expired_stateid(state, &state->stateid, deleg_flags); |
| 1748 | open_status = nfs41_check_expired_stateid(state, &state->open_stateid, open_flags); |
| 1749 | |
| 1750 | if ((deleg_status == NFS_OK) && (open_status == NFS_OK)) |
| 1751 | return NFS_OK; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1752 | return nfs4_open_expired(sp, state); |
| 1753 | } |
| 1754 | #endif |
| 1755 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1757 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1758 | * fields corresponding to attributes that were used to store the verifier. |
| 1759 | * Make sure we clobber those fields in the later setattr call |
| 1760 | */ |
| 1761 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1762 | { |
| 1763 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1764 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1765 | sattr->ia_valid |= ATTR_ATIME; |
| 1766 | |
| 1767 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1768 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1769 | sattr->ia_valid |= ATTR_MTIME; |
| 1770 | } |
| 1771 | |
| 1772 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1773 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | */ |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1775 | 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] | 1776 | { |
| 1777 | struct nfs4_state_owner *sp; |
| 1778 | struct nfs4_state *state = NULL; |
| 1779 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1780 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1781 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | |
| 1783 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1785 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1786 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1788 | goto out_err; |
| 1789 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1790 | status = nfs4_recover_expired_lease(server); |
| 1791 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1792 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1793 | if (dentry->d_inode != NULL) |
| 1794 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1795 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1796 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1797 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1798 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1800 | if (dentry->d_inode != NULL) |
| 1801 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1802 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1803 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1805 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1807 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1808 | status = PTR_ERR(state); |
| 1809 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1810 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1811 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1812 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1813 | |
| 1814 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1815 | nfs4_exclusive_attrset(opendata, sattr); |
| 1816 | |
| 1817 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1818 | status = nfs4_do_setattr(state->inode, cred, |
| 1819 | opendata->o_res.f_attr, sattr, |
| 1820 | state); |
| 1821 | if (status == 0) |
| 1822 | nfs_setattr_update_inode(state->inode, sattr); |
| 1823 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1824 | } |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1825 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | *res = state; |
| 1828 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1829 | err_opendata_put: |
| 1830 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1831 | err_put_state_owner: |
| 1832 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | *res = NULL; |
| 1835 | return status; |
| 1836 | } |
| 1837 | |
| 1838 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1839 | 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] | 1840 | { |
| 1841 | struct nfs4_exception exception = { }; |
| 1842 | struct nfs4_state *res; |
| 1843 | int status; |
| 1844 | |
| 1845 | do { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1846 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | if (status == 0) |
| 1848 | break; |
| 1849 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1850 | * book-keeping w.r.t. state-changing operations |
| 1851 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1852 | * It is actually a sign of a bug on the client or on the server. |
| 1853 | * |
| 1854 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1855 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | * have unhashed the old state_owner for us, and that we can |
| 1857 | * therefore safely retry using a new one. We should still warn |
| 1858 | * the user though... |
| 1859 | */ |
| 1860 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1861 | printk(KERN_WARNING "NFS: v4 server %s " |
| 1862 | " returned a bad sequence-id error!\n", |
| 1863 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | exception.retry = 1; |
| 1865 | continue; |
| 1866 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1867 | /* |
| 1868 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1869 | * state before it received the OPEN_CONFIRM. |
| 1870 | * Recover by retrying the request as per the discussion |
| 1871 | * on Page 181 of RFC3530. |
| 1872 | */ |
| 1873 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1874 | exception.retry = 1; |
| 1875 | continue; |
| 1876 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1877 | if (status == -EAGAIN) { |
| 1878 | /* We must have found a delegation */ |
| 1879 | exception.retry = 1; |
| 1880 | continue; |
| 1881 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1883 | status, &exception)); |
| 1884 | } while (exception.retry); |
| 1885 | return res; |
| 1886 | } |
| 1887 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1888 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1889 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1890 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1892 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1894 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | .iap = sattr, |
| 1896 | .server = server, |
| 1897 | .bitmask = server->attr_bitmask, |
| 1898 | }; |
| 1899 | struct nfs_setattrres res = { |
| 1900 | .fattr = fattr, |
| 1901 | .server = server, |
| 1902 | }; |
| 1903 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1904 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1905 | .rpc_argp = &arg, |
| 1906 | .rpc_resp = &res, |
| 1907 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1909 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1910 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1912 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1914 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { |
| 1915 | /* Use that stateid */ |
| 1916 | } else if (state != NULL) { |
Trond Myklebust | 77041ed | 2010-07-01 12:49:11 -0400 | [diff] [blame] | 1917 | nfs4_copy_stateid(&arg.stateid, state, current->files, current->tgid); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1918 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); |
| 1920 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1921 | 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] | 1922 | if (status == 0 && state != NULL) |
| 1923 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1924 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | } |
| 1926 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1927 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1928 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1929 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1931 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | struct nfs4_exception exception = { }; |
| 1933 | int err; |
| 1934 | do { |
| 1935 | err = nfs4_handle_exception(server, |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1936 | _nfs4_do_setattr(inode, cred, fattr, sattr, state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | &exception); |
| 1938 | } while (exception.retry); |
| 1939 | return err; |
| 1940 | } |
| 1941 | |
| 1942 | struct nfs4_closedata { |
| 1943 | struct inode *inode; |
| 1944 | struct nfs4_state *state; |
| 1945 | struct nfs_closeargs arg; |
| 1946 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1947 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1948 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1949 | bool roc; |
| 1950 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | }; |
| 1952 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1953 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1954 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1955 | struct nfs4_closedata *calldata = data; |
| 1956 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1957 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1958 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1959 | if (calldata->roc) |
| 1960 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1961 | nfs4_put_open_state(calldata->state); |
| 1962 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1963 | nfs4_put_state_owner(sp); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1964 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1965 | kfree(calldata); |
| 1966 | } |
| 1967 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1968 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 1969 | fmode_t fmode) |
| 1970 | { |
| 1971 | spin_lock(&state->owner->so_lock); |
| 1972 | if (!(fmode & FMODE_READ)) |
| 1973 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1974 | if (!(fmode & FMODE_WRITE)) |
| 1975 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1976 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1977 | spin_unlock(&state->owner->so_lock); |
| 1978 | } |
| 1979 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1980 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1982 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 1985 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1986 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 1987 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | /* hmm. we are done with the inode, and in the process of freeing |
| 1989 | * the state_owner. we keep this around to process errors |
| 1990 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | switch (task->tk_status) { |
| 1992 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1993 | if (calldata->roc) |
| 1994 | pnfs_roc_set_barrier(state->inode, |
| 1995 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1996 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1997 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1998 | nfs4_close_clear_stateid_flags(state, |
| 1999 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | break; |
| 2001 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2002 | case -NFS4ERR_OLD_STATEID: |
| 2003 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2005 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2006 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2008 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2009 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2011 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2012 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2015 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2017 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2018 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2019 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2020 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2021 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2022 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2023 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2024 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2025 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2026 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2027 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2028 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2029 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2030 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2031 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2032 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2033 | } |
| 2034 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2035 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2036 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2037 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2038 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2039 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2040 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2041 | |
| 2042 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2043 | /* Note: exit _without_ calling nfs4_close_done */ |
| 2044 | task->tk_action = NULL; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2045 | return; |
| 2046 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2047 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2048 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2049 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2050 | if (calldata->roc && |
| 2051 | pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { |
| 2052 | rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, |
| 2053 | task, NULL); |
| 2054 | return; |
| 2055 | } |
| 2056 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2057 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2058 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2059 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2060 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2061 | &calldata->arg.seq_args, |
| 2062 | &calldata->res.seq_res, |
| 2063 | task)) |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 2064 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2065 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | } |
| 2067 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2068 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2069 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2070 | .rpc_call_done = nfs4_close_done, |
| 2071 | .rpc_release = nfs4_free_closedata, |
| 2072 | }; |
| 2073 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | /* |
| 2075 | * It is possible for data to be read/written from a mem-mapped file |
| 2076 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2077 | * This means that we can't safely call nfsv4 close on a file until |
| 2078 | * the inode is cleared. This in turn means that we are not good |
| 2079 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2080 | * share state even when we are done with one of the three share |
| 2081 | * stateid's in the inode. |
| 2082 | * |
| 2083 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2084 | */ |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2085 | 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] | 2086 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2087 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2089 | struct nfs4_state_owner *sp = state->owner; |
| 2090 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2091 | struct rpc_message msg = { |
| 2092 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2093 | .rpc_cred = state->owner->so_cred, |
| 2094 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2095 | struct rpc_task_setup task_setup_data = { |
| 2096 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2097 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2098 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2099 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2100 | .flags = RPC_TASK_ASYNC, |
| 2101 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2102 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2104 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2106 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2107 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2108 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2110 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2111 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2113 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2114 | if (calldata->arg.seqid == NULL) |
| 2115 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2116 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2117 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2118 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2119 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2120 | calldata->res.server = server; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2121 | calldata->roc = roc; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2122 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2123 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2124 | msg.rpc_argp = &calldata->arg; |
| 2125 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2126 | task_setup_data.callback_data = calldata; |
| 2127 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2128 | if (IS_ERR(task)) |
| 2129 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2130 | status = 0; |
| 2131 | if (wait) |
| 2132 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2133 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2134 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2135 | out_free_calldata: |
| 2136 | kfree(calldata); |
| 2137 | out: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2138 | if (roc) |
| 2139 | pnfs_roc_release(state->inode); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2140 | nfs4_put_open_state(state); |
| 2141 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2142 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | } |
| 2144 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2145 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2146 | 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] | 2147 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | struct nfs4_state *state; |
| 2149 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2150 | /* Protect against concurrent sillydeletes */ |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2151 | 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] | 2152 | if (IS_ERR(state)) |
| 2153 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2154 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2155 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | } |
| 2157 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2158 | 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] | 2159 | { |
| 2160 | if (ctx->state == NULL) |
| 2161 | return; |
| 2162 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2163 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2164 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2165 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2166 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2167 | |
| 2168 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2169 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2170 | struct nfs4_server_caps_arg args = { |
| 2171 | .fhandle = fhandle, |
| 2172 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | struct nfs4_server_caps_res res = {}; |
| 2174 | struct rpc_message msg = { |
| 2175 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2176 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | .rpc_resp = &res, |
| 2178 | }; |
| 2179 | int status; |
| 2180 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2181 | 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] | 2182 | if (status == 0) { |
| 2183 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2184 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2185 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2186 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2187 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2188 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2190 | server->caps |= NFS_CAP_ACLS; |
| 2191 | if (res.has_links != 0) |
| 2192 | server->caps |= NFS_CAP_HARDLINKS; |
| 2193 | if (res.has_symlinks != 0) |
| 2194 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2195 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2196 | server->caps |= NFS_CAP_FILEID; |
| 2197 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2198 | server->caps |= NFS_CAP_MODE; |
| 2199 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2200 | server->caps |= NFS_CAP_NLINK; |
| 2201 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2202 | server->caps |= NFS_CAP_OWNER; |
| 2203 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2204 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2205 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2206 | server->caps |= NFS_CAP_ATIME; |
| 2207 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2208 | server->caps |= NFS_CAP_CTIME; |
| 2209 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2210 | server->caps |= NFS_CAP_MTIME; |
| 2211 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2212 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2213 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2214 | 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] | 2215 | server->acl_bitmask = res.acl_bitmask; |
| 2216 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2217 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | return status; |
| 2219 | } |
| 2220 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2221 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | { |
| 2223 | struct nfs4_exception exception = { }; |
| 2224 | int err; |
| 2225 | do { |
| 2226 | err = nfs4_handle_exception(server, |
| 2227 | _nfs4_server_capabilities(server, fhandle), |
| 2228 | &exception); |
| 2229 | } while (exception.retry); |
| 2230 | return err; |
| 2231 | } |
| 2232 | |
| 2233 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2234 | struct nfs_fsinfo *info) |
| 2235 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | struct nfs4_lookup_root_arg args = { |
| 2237 | .bitmask = nfs4_fattr_bitmap, |
| 2238 | }; |
| 2239 | struct nfs4_lookup_res res = { |
| 2240 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2241 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | .fh = fhandle, |
| 2243 | }; |
| 2244 | struct rpc_message msg = { |
| 2245 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2246 | .rpc_argp = &args, |
| 2247 | .rpc_resp = &res, |
| 2248 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2249 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2250 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2251 | 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] | 2252 | } |
| 2253 | |
| 2254 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2255 | struct nfs_fsinfo *info) |
| 2256 | { |
| 2257 | struct nfs4_exception exception = { }; |
| 2258 | int err; |
| 2259 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2260 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2261 | switch (err) { |
| 2262 | case 0: |
| 2263 | case -NFS4ERR_WRONGSEC: |
| 2264 | break; |
| 2265 | default: |
| 2266 | err = nfs4_handle_exception(server, err, &exception); |
| 2267 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | } while (exception.retry); |
| 2269 | return err; |
| 2270 | } |
| 2271 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2272 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2273 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2274 | { |
| 2275 | struct rpc_auth *auth; |
| 2276 | int ret; |
| 2277 | |
| 2278 | auth = rpcauth_create(flavor, server->client); |
| 2279 | if (!auth) { |
| 2280 | ret = -EIO; |
| 2281 | goto out; |
| 2282 | } |
| 2283 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2284 | out: |
| 2285 | return ret; |
| 2286 | } |
| 2287 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2288 | 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] | 2289 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2291 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2292 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2294 | len = gss_mech_list_pseudoflavors(&flav_array[0]); |
| 2295 | flav_array[len] = RPC_AUTH_NULL; |
| 2296 | len += 1; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2297 | |
| 2298 | for (i = 0; i < len; i++) { |
| 2299 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2300 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2301 | continue; |
| 2302 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2303 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2304 | /* |
| 2305 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2306 | * to access the mount. It could also mean that we tried to mount |
| 2307 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2308 | * existing mount programs don't handle -EACCES very well so it should |
| 2309 | * be mapped to -EPERM instead. |
| 2310 | */ |
| 2311 | if (status == -EACCES) |
| 2312 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2313 | return status; |
| 2314 | } |
| 2315 | |
| 2316 | /* |
| 2317 | * get the file handle for the "/" directory on the server |
| 2318 | */ |
| 2319 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2320 | struct nfs_fsinfo *info) |
| 2321 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2322 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2323 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2324 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2325 | /* |
| 2326 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2327 | * by nfs4_map_errors() as this function exits. |
| 2328 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2329 | 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] | 2330 | if (status == 0) |
| 2331 | status = nfs4_server_capabilities(server, fhandle); |
| 2332 | if (status == 0) |
| 2333 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2334 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 | } |
| 2336 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2337 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2338 | /* |
| 2339 | * Get locations and (maybe) other attributes of a referral. |
| 2340 | * Note that we'll actually follow the referral later when |
| 2341 | * we detect fsid mismatch in inode revalidation |
| 2342 | */ |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2343 | static int nfs4_get_referral(struct inode *dir, const struct qstr *name, |
| 2344 | struct nfs_fattr *fattr, struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2345 | { |
| 2346 | int status = -ENOMEM; |
| 2347 | struct page *page = NULL; |
| 2348 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2349 | |
| 2350 | page = alloc_page(GFP_KERNEL); |
| 2351 | if (page == NULL) |
| 2352 | goto out; |
| 2353 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2354 | if (locations == NULL) |
| 2355 | goto out; |
| 2356 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 2357 | status = nfs4_proc_fs_locations(dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2358 | if (status != 0) |
| 2359 | goto out; |
| 2360 | /* Make sure server returned a different fsid for the referral */ |
| 2361 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2362 | dprintk("%s: server did not return a different fsid for" |
| 2363 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2364 | status = -EIO; |
| 2365 | goto out; |
| 2366 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2367 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2368 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2369 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2370 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2371 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2372 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2373 | out: |
| 2374 | if (page) |
| 2375 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2376 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2377 | return status; |
| 2378 | } |
| 2379 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2381 | { |
| 2382 | struct nfs4_getattr_arg args = { |
| 2383 | .fh = fhandle, |
| 2384 | .bitmask = server->attr_bitmask, |
| 2385 | }; |
| 2386 | struct nfs4_getattr_res res = { |
| 2387 | .fattr = fattr, |
| 2388 | .server = server, |
| 2389 | }; |
| 2390 | struct rpc_message msg = { |
| 2391 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2392 | .rpc_argp = &args, |
| 2393 | .rpc_resp = &res, |
| 2394 | }; |
| 2395 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2396 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2397 | 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] | 2398 | } |
| 2399 | |
| 2400 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2401 | { |
| 2402 | struct nfs4_exception exception = { }; |
| 2403 | int err; |
| 2404 | do { |
| 2405 | err = nfs4_handle_exception(server, |
| 2406 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2407 | &exception); |
| 2408 | } while (exception.retry); |
| 2409 | return err; |
| 2410 | } |
| 2411 | |
| 2412 | /* |
| 2413 | * The file is not closed if it is opened due to the a request to change |
| 2414 | * the size of the file. The open call will not be needed once the |
| 2415 | * VFS layer lookup-intents are implemented. |
| 2416 | * |
| 2417 | * Close is called when the inode is destroyed. |
| 2418 | * If we haven't opened the file for O_WRONLY, we |
| 2419 | * need to in the size_change case to obtain a stateid. |
| 2420 | * |
| 2421 | * Got race? |
| 2422 | * Because OPEN is always done by name in nfsv4, it is |
| 2423 | * possible that we opened a different file by the same |
| 2424 | * name. We can recognize this race condition, but we |
| 2425 | * can't do anything about it besides returning an error. |
| 2426 | * |
| 2427 | * This will be fixed with VFS changes (lookup-intent). |
| 2428 | */ |
| 2429 | static int |
| 2430 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2431 | struct iattr *sattr) |
| 2432 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2433 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2434 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2435 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 | int status; |
| 2437 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2438 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2439 | pnfs_return_layout(inode); |
| 2440 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2441 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2443 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2444 | if (sattr->ia_valid & ATTR_FILE) { |
| 2445 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2446 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2447 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2448 | if (ctx) { |
| 2449 | cred = ctx->cred; |
| 2450 | state = ctx->state; |
| 2451 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2452 | } |
| 2453 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 2454 | /* Deal with open(O_TRUNC) */ |
| 2455 | if (sattr->ia_valid & ATTR_OPEN) |
| 2456 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2457 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2458 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2459 | if (status == 0) |
| 2460 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | return status; |
| 2462 | } |
| 2463 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2464 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2465 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2466 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2467 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2468 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2469 | int status; |
| 2470 | struct nfs4_lookup_arg args = { |
| 2471 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2472 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2473 | .name = name, |
| 2474 | }; |
| 2475 | struct nfs4_lookup_res res = { |
| 2476 | .server = server, |
| 2477 | .fattr = fattr, |
| 2478 | .fh = fhandle, |
| 2479 | }; |
| 2480 | struct rpc_message msg = { |
| 2481 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2482 | .rpc_argp = &args, |
| 2483 | .rpc_resp = &res, |
| 2484 | }; |
| 2485 | |
| 2486 | nfs_fattr_init(fattr); |
| 2487 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2489 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2490 | dprintk("NFS reply lookup: %d\n", status); |
| 2491 | return status; |
| 2492 | } |
| 2493 | |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2494 | void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr, struct nfs_fh *fh) |
| 2495 | { |
| 2496 | memset(fh, 0, sizeof(struct nfs_fh)); |
| 2497 | fattr->fsid.major = 1; |
| 2498 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 2499 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_FSID | NFS_ATTR_FATTR_MOUNTPOINT; |
| 2500 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2501 | fattr->nlink = 2; |
| 2502 | } |
| 2503 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2504 | static int nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, struct qstr *name, |
| 2505 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | { |
| 2507 | struct nfs4_exception exception = { }; |
| 2508 | int err; |
| 2509 | do { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2510 | int status; |
| 2511 | |
| 2512 | status = _nfs4_proc_lookup(clnt, dir, name, fhandle, fattr); |
| 2513 | switch (status) { |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2514 | case -NFS4ERR_BADNAME: |
| 2515 | return -ENOENT; |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2516 | case -NFS4ERR_MOVED: |
Trond Myklebust | a6f498a | 2011-11-07 15:50:32 -0500 | [diff] [blame] | 2517 | return nfs4_get_referral(dir, name, fattr, fhandle); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2518 | case -NFS4ERR_WRONGSEC: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2519 | nfs_fixup_secinfo_attributes(fattr, fhandle); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2520 | } |
| 2521 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2522 | status, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2523 | } while (exception.retry); |
| 2524 | return err; |
| 2525 | } |
| 2526 | |
| 2527 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2528 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2529 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | struct nfs4_accessargs args = { |
| 2531 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2532 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2533 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2534 | struct nfs4_accessres res = { |
| 2535 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2536 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | struct rpc_message msg = { |
| 2538 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2539 | .rpc_argp = &args, |
| 2540 | .rpc_resp = &res, |
| 2541 | .rpc_cred = entry->cred, |
| 2542 | }; |
| 2543 | int mode = entry->mask; |
| 2544 | int status; |
| 2545 | |
| 2546 | /* |
| 2547 | * Determine which access bits we want to ask for... |
| 2548 | */ |
| 2549 | if (mode & MAY_READ) |
| 2550 | args.access |= NFS4_ACCESS_READ; |
| 2551 | if (S_ISDIR(inode->i_mode)) { |
| 2552 | if (mode & MAY_WRITE) |
| 2553 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2554 | if (mode & MAY_EXEC) |
| 2555 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2556 | } else { |
| 2557 | if (mode & MAY_WRITE) |
| 2558 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2559 | if (mode & MAY_EXEC) |
| 2560 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2561 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2562 | |
| 2563 | res.fattr = nfs_alloc_fattr(); |
| 2564 | if (res.fattr == NULL) |
| 2565 | return -ENOMEM; |
| 2566 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2567 | 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] | 2568 | if (!status) { |
| 2569 | entry->mask = 0; |
| 2570 | if (res.access & NFS4_ACCESS_READ) |
| 2571 | entry->mask |= MAY_READ; |
| 2572 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2573 | entry->mask |= MAY_WRITE; |
| 2574 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2575 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2576 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2577 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2578 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | return status; |
| 2580 | } |
| 2581 | |
| 2582 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2583 | { |
| 2584 | struct nfs4_exception exception = { }; |
| 2585 | int err; |
| 2586 | do { |
| 2587 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2588 | _nfs4_proc_access(inode, entry), |
| 2589 | &exception); |
| 2590 | } while (exception.retry); |
| 2591 | return err; |
| 2592 | } |
| 2593 | |
| 2594 | /* |
| 2595 | * TODO: For the time being, we don't try to get any attributes |
| 2596 | * along with any of the zero-copy operations READ, READDIR, |
| 2597 | * READLINK, WRITE. |
| 2598 | * |
| 2599 | * In the case of the first three, we want to put the GETATTR |
| 2600 | * after the read-type operation -- this is because it is hard |
| 2601 | * to predict the length of a GETATTR response in v4, and thus |
| 2602 | * align the READ data correctly. This means that the GETATTR |
| 2603 | * may end up partially falling into the page cache, and we should |
| 2604 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2605 | * To do this efficiently, we need to know the total length |
| 2606 | * of data received, which doesn't seem to be available outside |
| 2607 | * of the RPC layer. |
| 2608 | * |
| 2609 | * In the case of WRITE, we also want to put the GETATTR after |
| 2610 | * the operation -- in this case because we want to make sure |
| 2611 | * we get the post-operation mtime and size. This means that |
| 2612 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2613 | * of it which would leave room in the 'tail' iovec. |
| 2614 | * |
| 2615 | * Both of these changes to the XDR layer would in fact be quite |
| 2616 | * minor, but I decided to leave them for a subsequent patch. |
| 2617 | */ |
| 2618 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2619 | unsigned int pgbase, unsigned int pglen) |
| 2620 | { |
| 2621 | struct nfs4_readlink args = { |
| 2622 | .fh = NFS_FH(inode), |
| 2623 | .pgbase = pgbase, |
| 2624 | .pglen = pglen, |
| 2625 | .pages = &page, |
| 2626 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2627 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2628 | struct rpc_message msg = { |
| 2629 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2630 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2631 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2632 | }; |
| 2633 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2634 | 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] | 2635 | } |
| 2636 | |
| 2637 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2638 | unsigned int pgbase, unsigned int pglen) |
| 2639 | { |
| 2640 | struct nfs4_exception exception = { }; |
| 2641 | int err; |
| 2642 | do { |
| 2643 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2644 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2645 | &exception); |
| 2646 | } while (exception.retry); |
| 2647 | return err; |
| 2648 | } |
| 2649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2650 | /* |
| 2651 | * Got race? |
| 2652 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2653 | * Until then, this create/open method is prone to inefficiency and race |
| 2654 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2655 | * placed on the wire. |
| 2656 | * |
| 2657 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2658 | * The file will be opened again in the subsequent VFS open call |
| 2659 | * (nfs4_proc_file_open). |
| 2660 | * |
| 2661 | * The open for read will just hang around to be used by any process that |
| 2662 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2663 | */ |
| 2664 | |
| 2665 | static int |
| 2666 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2667 | int flags, struct nfs_open_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2669 | struct dentry *de = dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | struct nfs4_state *state; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2671 | struct rpc_cred *cred = NULL; |
| 2672 | fmode_t fmode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 | int status = 0; |
| 2674 | |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2675 | if (ctx != NULL) { |
| 2676 | cred = ctx->cred; |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2677 | de = ctx->dentry; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2678 | fmode = ctx->mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2679 | } |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2680 | sattr->ia_mode &= ~current_umask(); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2681 | state = nfs4_do_open(dir, de, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2682 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | if (IS_ERR(state)) { |
| 2684 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2685 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2686 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2687 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2688 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2689 | if (ctx != NULL) |
| 2690 | ctx->state = state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2691 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2692 | nfs4_close_sync(state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2693 | out: |
| 2694 | return status; |
| 2695 | } |
| 2696 | |
| 2697 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2698 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2699 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2700 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2702 | .name.len = name->len, |
| 2703 | .name.name = name->name, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2704 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2706 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2707 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2708 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2709 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2710 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2711 | .rpc_argp = &args, |
| 2712 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2713 | }; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2714 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2716 | res.dir_attr = nfs_alloc_fattr(); |
| 2717 | if (res.dir_attr == NULL) |
| 2718 | goto out; |
| 2719 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2720 | 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] | 2721 | if (status == 0) { |
| 2722 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2723 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2724 | } |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2725 | nfs_free_fattr(res.dir_attr); |
| 2726 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2727 | return status; |
| 2728 | } |
| 2729 | |
| 2730 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2731 | { |
| 2732 | struct nfs4_exception exception = { }; |
| 2733 | int err; |
| 2734 | do { |
| 2735 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2736 | _nfs4_proc_remove(dir, name), |
| 2737 | &exception); |
| 2738 | } while (exception.retry); |
| 2739 | return err; |
| 2740 | } |
| 2741 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2742 | 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] | 2743 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2744 | struct nfs_server *server = NFS_SERVER(dir); |
| 2745 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2746 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2748 | args->bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2749 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2751 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2752 | } |
| 2753 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2754 | 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] | 2755 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2756 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2757 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2758 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2759 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2760 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2761 | return 0; |
| 2762 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2763 | nfs_post_op_update_inode(dir, res->dir_attr); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2764 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | } |
| 2766 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2767 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2768 | { |
| 2769 | struct nfs_server *server = NFS_SERVER(dir); |
| 2770 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2771 | struct nfs_renameres *res = msg->rpc_resp; |
| 2772 | |
| 2773 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
| 2774 | arg->bitmask = server->attr_bitmask; |
| 2775 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2776 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2780 | struct inode *new_dir) |
| 2781 | { |
| 2782 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2783 | |
| 2784 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2785 | return 0; |
| 2786 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2787 | return 0; |
| 2788 | |
| 2789 | update_changeattr(old_dir, &res->old_cinfo); |
| 2790 | nfs_post_op_update_inode(old_dir, res->old_fattr); |
| 2791 | update_changeattr(new_dir, &res->new_cinfo); |
| 2792 | nfs_post_op_update_inode(new_dir, res->new_fattr); |
| 2793 | return 1; |
| 2794 | } |
| 2795 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2797 | struct inode *new_dir, struct qstr *new_name) |
| 2798 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2799 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2800 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | .old_dir = NFS_FH(old_dir), |
| 2802 | .new_dir = NFS_FH(new_dir), |
| 2803 | .old_name = old_name, |
| 2804 | .new_name = new_name, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2805 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2807 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2808 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2809 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | struct rpc_message msg = { |
| 2811 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2812 | .rpc_argp = &arg, |
| 2813 | .rpc_resp = &res, |
| 2814 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2815 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2817 | res.old_fattr = nfs_alloc_fattr(); |
| 2818 | res.new_fattr = nfs_alloc_fattr(); |
| 2819 | if (res.old_fattr == NULL || res.new_fattr == NULL) |
| 2820 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2822 | 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] | 2823 | if (!status) { |
| 2824 | update_changeattr(old_dir, &res.old_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2825 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2826 | update_changeattr(new_dir, &res.new_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2827 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2828 | } |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2829 | out: |
| 2830 | nfs_free_fattr(res.new_fattr); |
| 2831 | nfs_free_fattr(res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | return status; |
| 2833 | } |
| 2834 | |
| 2835 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2836 | struct inode *new_dir, struct qstr *new_name) |
| 2837 | { |
| 2838 | struct nfs4_exception exception = { }; |
| 2839 | int err; |
| 2840 | do { |
| 2841 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2842 | _nfs4_proc_rename(old_dir, old_name, |
| 2843 | new_dir, new_name), |
| 2844 | &exception); |
| 2845 | } while (exception.retry); |
| 2846 | return err; |
| 2847 | } |
| 2848 | |
| 2849 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2850 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2851 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | struct nfs4_link_arg arg = { |
| 2853 | .fh = NFS_FH(inode), |
| 2854 | .dir_fh = NFS_FH(dir), |
| 2855 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2856 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2858 | struct nfs4_link_res res = { |
| 2859 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2860 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2861 | struct rpc_message msg = { |
| 2862 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2863 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2864 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2866 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2867 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2868 | res.fattr = nfs_alloc_fattr(); |
| 2869 | res.dir_attr = nfs_alloc_fattr(); |
| 2870 | if (res.fattr == NULL || res.dir_attr == NULL) |
| 2871 | goto out; |
| 2872 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2873 | 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] | 2874 | if (!status) { |
| 2875 | update_changeattr(dir, &res.cinfo); |
| 2876 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2877 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2878 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2879 | out: |
| 2880 | nfs_free_fattr(res.dir_attr); |
| 2881 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | return status; |
| 2883 | } |
| 2884 | |
| 2885 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2886 | { |
| 2887 | struct nfs4_exception exception = { }; |
| 2888 | int err; |
| 2889 | do { |
| 2890 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2891 | _nfs4_proc_link(inode, dir, name), |
| 2892 | &exception); |
| 2893 | } while (exception.retry); |
| 2894 | return err; |
| 2895 | } |
| 2896 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2897 | struct nfs4_createdata { |
| 2898 | struct rpc_message msg; |
| 2899 | struct nfs4_create_arg arg; |
| 2900 | struct nfs4_create_res res; |
| 2901 | struct nfs_fh fh; |
| 2902 | struct nfs_fattr fattr; |
| 2903 | struct nfs_fattr dir_fattr; |
| 2904 | }; |
| 2905 | |
| 2906 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 2907 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 2908 | { |
| 2909 | struct nfs4_createdata *data; |
| 2910 | |
| 2911 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2912 | if (data != NULL) { |
| 2913 | struct nfs_server *server = NFS_SERVER(dir); |
| 2914 | |
| 2915 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 2916 | data->msg.rpc_argp = &data->arg; |
| 2917 | data->msg.rpc_resp = &data->res; |
| 2918 | data->arg.dir_fh = NFS_FH(dir); |
| 2919 | data->arg.server = server; |
| 2920 | data->arg.name = name; |
| 2921 | data->arg.attrs = sattr; |
| 2922 | data->arg.ftype = ftype; |
| 2923 | data->arg.bitmask = server->attr_bitmask; |
| 2924 | data->res.server = server; |
| 2925 | data->res.fh = &data->fh; |
| 2926 | data->res.fattr = &data->fattr; |
| 2927 | data->res.dir_fattr = &data->dir_fattr; |
| 2928 | nfs_fattr_init(data->res.fattr); |
| 2929 | nfs_fattr_init(data->res.dir_fattr); |
| 2930 | } |
| 2931 | return data; |
| 2932 | } |
| 2933 | |
| 2934 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 2935 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2936 | 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] | 2937 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2938 | if (status == 0) { |
| 2939 | update_changeattr(dir, &data->res.dir_cinfo); |
| 2940 | nfs_post_op_update_inode(dir, data->res.dir_fattr); |
| 2941 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 2942 | } |
| 2943 | return status; |
| 2944 | } |
| 2945 | |
| 2946 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 2947 | { |
| 2948 | kfree(data); |
| 2949 | } |
| 2950 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2951 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2952 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2953 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2954 | struct nfs4_createdata *data; |
| 2955 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2957 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2958 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2959 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2960 | status = -ENOMEM; |
| 2961 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 2962 | if (data == NULL) |
| 2963 | goto out; |
| 2964 | |
| 2965 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 2966 | data->arg.u.symlink.pages = &page; |
| 2967 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 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 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2976 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2977 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | { |
| 2979 | struct nfs4_exception exception = { }; |
| 2980 | int err; |
| 2981 | do { |
| 2982 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2983 | _nfs4_proc_symlink(dir, dentry, page, |
| 2984 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2985 | &exception); |
| 2986 | } while (exception.retry); |
| 2987 | return err; |
| 2988 | } |
| 2989 | |
| 2990 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2991 | struct iattr *sattr) |
| 2992 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2993 | struct nfs4_createdata *data; |
| 2994 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2996 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 2997 | if (data == NULL) |
| 2998 | goto out; |
| 2999 | |
| 3000 | status = nfs4_do_create(dir, dentry, data); |
| 3001 | |
| 3002 | nfs4_free_createdata(data); |
| 3003 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3004 | return status; |
| 3005 | } |
| 3006 | |
| 3007 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3008 | struct iattr *sattr) |
| 3009 | { |
| 3010 | struct nfs4_exception exception = { }; |
| 3011 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3012 | |
| 3013 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3014 | do { |
| 3015 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3016 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3017 | &exception); |
| 3018 | } while (exception.retry); |
| 3019 | return err; |
| 3020 | } |
| 3021 | |
| 3022 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3023 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3024 | { |
| 3025 | struct inode *dir = dentry->d_inode; |
| 3026 | struct nfs4_readdir_arg args = { |
| 3027 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3028 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | .pgbase = 0, |
| 3030 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3031 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3032 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | }; |
| 3034 | struct nfs4_readdir_res res; |
| 3035 | struct rpc_message msg = { |
| 3036 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3037 | .rpc_argp = &args, |
| 3038 | .rpc_resp = &res, |
| 3039 | .rpc_cred = cred, |
| 3040 | }; |
| 3041 | int status; |
| 3042 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3043 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3044 | dentry->d_parent->d_name.name, |
| 3045 | dentry->d_name.name, |
| 3046 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 3048 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3049 | 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] | 3050 | if (status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3052 | status += args.pgbase; |
| 3053 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3054 | |
| 3055 | nfs_invalidate_atime(dir); |
| 3056 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3057 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | return status; |
| 3059 | } |
| 3060 | |
| 3061 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3062 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3063 | { |
| 3064 | struct nfs4_exception exception = { }; |
| 3065 | int err; |
| 3066 | do { |
| 3067 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3068 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3069 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | &exception); |
| 3071 | } while (exception.retry); |
| 3072 | return err; |
| 3073 | } |
| 3074 | |
| 3075 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3076 | struct iattr *sattr, dev_t rdev) |
| 3077 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3078 | struct nfs4_createdata *data; |
| 3079 | int mode = sattr->ia_mode; |
| 3080 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3081 | |
| 3082 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 3083 | 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] | 3084 | |
| 3085 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3086 | if (data == NULL) |
| 3087 | goto out; |
| 3088 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3089 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3090 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3092 | data->arg.ftype = NF4BLK; |
| 3093 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3094 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | } |
| 3096 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3097 | data->arg.ftype = NF4CHR; |
| 3098 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3099 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3100 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3102 | status = nfs4_do_create(dir, dentry, data); |
| 3103 | |
| 3104 | nfs4_free_createdata(data); |
| 3105 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | return status; |
| 3107 | } |
| 3108 | |
| 3109 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3110 | struct iattr *sattr, dev_t rdev) |
| 3111 | { |
| 3112 | struct nfs4_exception exception = { }; |
| 3113 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3114 | |
| 3115 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3116 | do { |
| 3117 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3118 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3119 | &exception); |
| 3120 | } while (exception.retry); |
| 3121 | return err; |
| 3122 | } |
| 3123 | |
| 3124 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3125 | struct nfs_fsstat *fsstat) |
| 3126 | { |
| 3127 | struct nfs4_statfs_arg args = { |
| 3128 | .fh = fhandle, |
| 3129 | .bitmask = server->attr_bitmask, |
| 3130 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3131 | struct nfs4_statfs_res res = { |
| 3132 | .fsstat = fsstat, |
| 3133 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | struct rpc_message msg = { |
| 3135 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3136 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3137 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3138 | }; |
| 3139 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3140 | nfs_fattr_init(fsstat->fattr); |
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_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3145 | { |
| 3146 | struct nfs4_exception exception = { }; |
| 3147 | int err; |
| 3148 | do { |
| 3149 | err = nfs4_handle_exception(server, |
| 3150 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3151 | &exception); |
| 3152 | } while (exception.retry); |
| 3153 | return err; |
| 3154 | } |
| 3155 | |
| 3156 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3157 | struct nfs_fsinfo *fsinfo) |
| 3158 | { |
| 3159 | struct nfs4_fsinfo_arg args = { |
| 3160 | .fh = fhandle, |
| 3161 | .bitmask = server->attr_bitmask, |
| 3162 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3163 | struct nfs4_fsinfo_res res = { |
| 3164 | .fsinfo = fsinfo, |
| 3165 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | struct rpc_message msg = { |
| 3167 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3168 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3169 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3170 | }; |
| 3171 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3172 | 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] | 3173 | } |
| 3174 | |
| 3175 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3176 | { |
| 3177 | struct nfs4_exception exception = { }; |
| 3178 | int err; |
| 3179 | |
| 3180 | do { |
| 3181 | err = nfs4_handle_exception(server, |
| 3182 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3183 | &exception); |
| 3184 | } while (exception.retry); |
| 3185 | return err; |
| 3186 | } |
| 3187 | |
| 3188 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3189 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3190 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3192 | } |
| 3193 | |
| 3194 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3195 | struct nfs_pathconf *pathconf) |
| 3196 | { |
| 3197 | struct nfs4_pathconf_arg args = { |
| 3198 | .fh = fhandle, |
| 3199 | .bitmask = server->attr_bitmask, |
| 3200 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3201 | struct nfs4_pathconf_res res = { |
| 3202 | .pathconf = pathconf, |
| 3203 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | struct rpc_message msg = { |
| 3205 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3206 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3207 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | }; |
| 3209 | |
| 3210 | /* None of the pathconf attributes are mandatory to implement */ |
| 3211 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3212 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3213 | return 0; |
| 3214 | } |
| 3215 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3216 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3217 | 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] | 3218 | } |
| 3219 | |
| 3220 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3221 | struct nfs_pathconf *pathconf) |
| 3222 | { |
| 3223 | struct nfs4_exception exception = { }; |
| 3224 | int err; |
| 3225 | |
| 3226 | do { |
| 3227 | err = nfs4_handle_exception(server, |
| 3228 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3229 | &exception); |
| 3230 | } while (exception.retry); |
| 3231 | return err; |
| 3232 | } |
| 3233 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3234 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3235 | { |
| 3236 | nfs_invalidate_atime(data->inode); |
| 3237 | } |
| 3238 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3239 | 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] | 3240 | { |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3241 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3243 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3244 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3245 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3247 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3248 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3249 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3250 | renew_lease(server, data->timestamp); |
| 3251 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3252 | } |
| 3253 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3254 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3255 | { |
| 3256 | |
| 3257 | dprintk("--> %s\n", __func__); |
| 3258 | |
| 3259 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3260 | return -EAGAIN; |
| 3261 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3262 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3263 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3264 | } |
| 3265 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3266 | 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] | 3267 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3268 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3269 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3270 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3271 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | } |
| 3273 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3274 | /* Reset the the nfs_read_data to send the read to the MDS. */ |
| 3275 | void nfs4_reset_read(struct rpc_task *task, struct nfs_read_data *data) |
| 3276 | { |
| 3277 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3278 | put_lseg(data->lseg); |
| 3279 | data->lseg = NULL; |
| 3280 | /* offsets will differ in the dense stripe case */ |
| 3281 | data->args.offset = data->mds_offset; |
| 3282 | data->ds_clp = NULL; |
| 3283 | data->args.fh = NFS_FH(data->inode); |
| 3284 | data->read_done_cb = nfs4_read_done_cb; |
| 3285 | task->tk_ops = data->mds_ops; |
| 3286 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3287 | } |
| 3288 | EXPORT_SYMBOL_GPL(nfs4_reset_read); |
| 3289 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3290 | 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] | 3291 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3292 | struct inode *inode = data->inode; |
| 3293 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3294 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3295 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3296 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3297 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3298 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3299 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 3300 | nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3301 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3302 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3303 | } |
| 3304 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3305 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3306 | { |
| 3307 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3308 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3309 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3310 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3311 | } |
| 3312 | |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3313 | /* Reset the the nfs_write_data to send the write to the MDS. */ |
| 3314 | void nfs4_reset_write(struct rpc_task *task, struct nfs_write_data *data) |
| 3315 | { |
| 3316 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3317 | put_lseg(data->lseg); |
| 3318 | data->lseg = NULL; |
| 3319 | data->ds_clp = NULL; |
| 3320 | data->write_done_cb = nfs4_write_done_cb; |
| 3321 | data->args.fh = NFS_FH(data->inode); |
| 3322 | data->args.bitmask = data->res.server->cache_consistency_bitmask; |
| 3323 | data->args.offset = data->mds_offset; |
| 3324 | data->res.fattr = &data->fattr; |
| 3325 | task->tk_ops = data->mds_ops; |
| 3326 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3327 | } |
| 3328 | EXPORT_SYMBOL_GPL(nfs4_reset_write); |
| 3329 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3330 | 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] | 3331 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3332 | struct nfs_server *server = NFS_SERVER(data->inode); |
| 3333 | |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3334 | if (data->lseg) { |
| 3335 | data->args.bitmask = NULL; |
| 3336 | data->res.fattr = NULL; |
| 3337 | } else |
| 3338 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3339 | if (!data->write_done_cb) |
| 3340 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3341 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3342 | data->timestamp = jiffies; |
| 3343 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3344 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3345 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3346 | } |
| 3347 | |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3348 | 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] | 3349 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3351 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3352 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3353 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3354 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | } |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 3356 | nfs_refresh_inode(inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3357 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3358 | } |
| 3359 | |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3360 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3361 | { |
| 3362 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3363 | return -EAGAIN; |
| 3364 | return data->write_done_cb(task, data); |
| 3365 | } |
| 3366 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3367 | 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] | 3368 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3369 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3370 | |
| 3371 | if (data->lseg) { |
| 3372 | data->args.bitmask = NULL; |
| 3373 | data->res.fattr = NULL; |
| 3374 | } else |
| 3375 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3376 | if (!data->write_done_cb) |
| 3377 | data->write_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3378 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3379 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3380 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | } |
| 3382 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3383 | struct nfs4_renewdata { |
| 3384 | struct nfs_client *client; |
| 3385 | unsigned long timestamp; |
| 3386 | }; |
| 3387 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | /* |
| 3389 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3390 | * standalone procedure for queueing an asynchronous RENEW. |
| 3391 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3392 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3393 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3394 | struct nfs4_renewdata *data = calldata; |
| 3395 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3396 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3397 | if (atomic_read(&clp->cl_count) > 1) |
| 3398 | nfs4_schedule_state_renewal(clp); |
| 3399 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3400 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3401 | } |
| 3402 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3403 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3404 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3405 | struct nfs4_renewdata *data = calldata; |
| 3406 | struct nfs_client *clp = data->client; |
| 3407 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3408 | |
| 3409 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3410 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3411 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3412 | return; |
| 3413 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3414 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3415 | return; |
| 3416 | } |
| 3417 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3419 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | } |
| 3421 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3422 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3423 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3424 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3425 | }; |
| 3426 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3427 | 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] | 3428 | { |
| 3429 | struct rpc_message msg = { |
| 3430 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3431 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3432 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3433 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3434 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3436 | if (renew_flags == 0) |
| 3437 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3438 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3439 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3440 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3441 | if (data == NULL) |
| 3442 | return -ENOMEM; |
| 3443 | data->client = clp; |
| 3444 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3445 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3446 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3447 | } |
| 3448 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3449 | 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] | 3450 | { |
| 3451 | struct rpc_message msg = { |
| 3452 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3453 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3454 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | }; |
| 3456 | unsigned long now = jiffies; |
| 3457 | int status; |
| 3458 | |
| 3459 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3460 | if (status < 0) |
| 3461 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3462 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3463 | return 0; |
| 3464 | } |
| 3465 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3466 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3467 | { |
| 3468 | return (server->caps & NFS_CAP_ACLS) |
| 3469 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3470 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3471 | } |
| 3472 | |
| 3473 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3474 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3475 | * the stack. |
| 3476 | */ |
| 3477 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3478 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3479 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3480 | struct page **pages, unsigned int *pgbase) |
| 3481 | { |
| 3482 | struct page *newpage, **spages; |
| 3483 | int rc = 0; |
| 3484 | size_t len; |
| 3485 | spages = pages; |
| 3486 | |
| 3487 | do { |
Jovi Zhang | 43b7c3f | 2011-03-02 23:19:37 +0000 | [diff] [blame] | 3488 | len = min_t(size_t, PAGE_CACHE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3489 | newpage = alloc_page(GFP_KERNEL); |
| 3490 | |
| 3491 | if (newpage == NULL) |
| 3492 | goto unwind; |
| 3493 | memcpy(page_address(newpage), buf, len); |
| 3494 | buf += len; |
| 3495 | buflen -= len; |
| 3496 | *pages++ = newpage; |
| 3497 | rc++; |
| 3498 | } while (buflen != 0); |
| 3499 | |
| 3500 | return rc; |
| 3501 | |
| 3502 | unwind: |
| 3503 | for(; rc > 0; rc--) |
| 3504 | __free_page(spages[rc-1]); |
| 3505 | return -ENOMEM; |
| 3506 | } |
| 3507 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3508 | struct nfs4_cached_acl { |
| 3509 | int cached; |
| 3510 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3511 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3512 | }; |
| 3513 | |
| 3514 | 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] | 3515 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3516 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3517 | |
| 3518 | spin_lock(&inode->i_lock); |
| 3519 | kfree(nfsi->nfs4_acl); |
| 3520 | nfsi->nfs4_acl = acl; |
| 3521 | spin_unlock(&inode->i_lock); |
| 3522 | } |
| 3523 | |
| 3524 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3525 | { |
| 3526 | nfs4_set_cached_acl(inode, NULL); |
| 3527 | } |
| 3528 | |
| 3529 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3530 | { |
| 3531 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3532 | struct nfs4_cached_acl *acl; |
| 3533 | int ret = -ENOENT; |
| 3534 | |
| 3535 | spin_lock(&inode->i_lock); |
| 3536 | acl = nfsi->nfs4_acl; |
| 3537 | if (acl == NULL) |
| 3538 | goto out; |
| 3539 | if (buf == NULL) /* user is just asking for length */ |
| 3540 | goto out_len; |
| 3541 | if (acl->cached == 0) |
| 3542 | goto out; |
| 3543 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3544 | if (acl->len > buflen) |
| 3545 | goto out; |
| 3546 | memcpy(buf, acl->data, acl->len); |
| 3547 | out_len: |
| 3548 | ret = acl->len; |
| 3549 | out: |
| 3550 | spin_unlock(&inode->i_lock); |
| 3551 | return ret; |
| 3552 | } |
| 3553 | |
| 3554 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) |
| 3555 | { |
| 3556 | struct nfs4_cached_acl *acl; |
| 3557 | |
| 3558 | if (buf && acl_len <= PAGE_SIZE) { |
| 3559 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3560 | if (acl == NULL) |
| 3561 | goto out; |
| 3562 | acl->cached = 1; |
| 3563 | memcpy(acl->data, buf, acl_len); |
| 3564 | } else { |
| 3565 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3566 | if (acl == NULL) |
| 3567 | goto out; |
| 3568 | acl->cached = 0; |
| 3569 | } |
| 3570 | acl->len = acl_len; |
| 3571 | out: |
| 3572 | nfs4_set_cached_acl(inode, acl); |
| 3573 | } |
| 3574 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3575 | /* |
| 3576 | * The getxattr API returns the required buffer length when called with a |
| 3577 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3578 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3579 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3580 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3581 | * the cache. If not so, we throw away the page, and cache the required |
| 3582 | * length. The next getxattr call will then produce another round trip to |
| 3583 | * the server, this time with the input buf of the required size. |
| 3584 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3585 | 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] | 3586 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3587 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3588 | struct nfs_getaclargs args = { |
| 3589 | .fh = NFS_FH(inode), |
| 3590 | .acl_pages = pages, |
| 3591 | .acl_len = buflen, |
| 3592 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3593 | struct nfs_getaclres res = { |
| 3594 | .acl_len = buflen, |
| 3595 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3596 | void *resp_buf; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3597 | struct rpc_message msg = { |
| 3598 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3599 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3600 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3601 | }; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3602 | int ret = -ENOMEM, npages, i, acl_len = 0; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3603 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3604 | npages = (buflen + PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 3605 | /* As long as we're doing a round trip to the server anyway, |
| 3606 | * let's be prepared for a page of acl data. */ |
| 3607 | if (npages == 0) |
| 3608 | npages = 1; |
| 3609 | |
| 3610 | for (i = 0; i < npages; i++) { |
| 3611 | pages[i] = alloc_page(GFP_KERNEL); |
| 3612 | if (!pages[i]) |
| 3613 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3614 | } |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3615 | if (npages > 1) { |
| 3616 | /* for decoding across pages */ |
| 3617 | args.acl_scratch = alloc_page(GFP_KERNEL); |
| 3618 | if (!args.acl_scratch) |
| 3619 | goto out_free; |
| 3620 | } |
| 3621 | args.acl_len = npages * PAGE_SIZE; |
| 3622 | args.acl_pgbase = 0; |
| 3623 | /* Let decode_getfacl know not to fail if the ACL data is larger than |
| 3624 | * the page we send as a guess */ |
| 3625 | if (buf == NULL) |
| 3626 | res.acl_flags |= NFS4_ACL_LEN_REQUEST; |
| 3627 | resp_buf = page_address(pages[0]); |
| 3628 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3629 | dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n", |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3630 | __func__, buf, buflen, npages, args.acl_len); |
| 3631 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 3632 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3633 | if (ret) |
| 3634 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3635 | |
| 3636 | acl_len = res.acl_len - res.acl_data_offset; |
| 3637 | if (acl_len > args.acl_len) |
| 3638 | nfs4_write_cached_acl(inode, NULL, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3639 | else |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3640 | nfs4_write_cached_acl(inode, resp_buf + res.acl_data_offset, |
| 3641 | acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3642 | if (buf) { |
| 3643 | ret = -ERANGE; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3644 | if (acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3645 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3646 | _copy_from_pages(buf, pages, res.acl_data_offset, |
| 3647 | res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3648 | } |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3649 | ret = acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3650 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3651 | for (i = 0; i < npages; i++) |
| 3652 | if (pages[i]) |
| 3653 | __free_page(pages[i]); |
| 3654 | if (args.acl_scratch) |
| 3655 | __free_page(args.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3656 | return ret; |
| 3657 | } |
| 3658 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3659 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3660 | { |
| 3661 | struct nfs4_exception exception = { }; |
| 3662 | ssize_t ret; |
| 3663 | do { |
| 3664 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3665 | if (ret >= 0) |
| 3666 | break; |
| 3667 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3668 | } while (exception.retry); |
| 3669 | return ret; |
| 3670 | } |
| 3671 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3672 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3673 | { |
| 3674 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3675 | int ret; |
| 3676 | |
| 3677 | if (!nfs4_server_supports_acls(server)) |
| 3678 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3679 | ret = nfs_revalidate_inode(server, inode); |
| 3680 | if (ret < 0) |
| 3681 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3682 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3683 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3684 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3685 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3686 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 3687 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3688 | return ret; |
| 3689 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3690 | } |
| 3691 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3692 | 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] | 3693 | { |
| 3694 | struct nfs_server *server = NFS_SERVER(inode); |
| 3695 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3696 | struct nfs_setaclargs arg = { |
| 3697 | .fh = NFS_FH(inode), |
| 3698 | .acl_pages = pages, |
| 3699 | .acl_len = buflen, |
| 3700 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3701 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3702 | struct rpc_message msg = { |
| 3703 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3704 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3705 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3706 | }; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3707 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3708 | |
| 3709 | if (!nfs4_server_supports_acls(server)) |
| 3710 | return -EOPNOTSUPP; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3711 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3712 | if (i < 0) |
| 3713 | return i; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3714 | nfs_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3715 | 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] | 3716 | |
| 3717 | /* |
| 3718 | * Free each page after tx, so the only ref left is |
| 3719 | * held by the network stack |
| 3720 | */ |
| 3721 | for (; i > 0; i--) |
| 3722 | put_page(pages[i-1]); |
| 3723 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3724 | /* |
| 3725 | * Acl update can result in inode attribute update. |
| 3726 | * so mark the attribute cache invalid. |
| 3727 | */ |
| 3728 | spin_lock(&inode->i_lock); |
| 3729 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3730 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3731 | nfs_access_zap_cache(inode); |
| 3732 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3733 | return ret; |
| 3734 | } |
| 3735 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3736 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3737 | { |
| 3738 | struct nfs4_exception exception = { }; |
| 3739 | int err; |
| 3740 | do { |
| 3741 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3742 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3743 | &exception); |
| 3744 | } while (exception.retry); |
| 3745 | return err; |
| 3746 | } |
| 3747 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3748 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3749 | 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] | 3750 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3751 | struct nfs_client *clp = server->nfs_client; |
| 3752 | |
| 3753 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3754 | return 0; |
| 3755 | switch(task->tk_status) { |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3756 | case -NFS4ERR_ADMIN_REVOKED: |
| 3757 | case -NFS4ERR_BAD_STATEID: |
| 3758 | case -NFS4ERR_OPENMODE: |
| 3759 | if (state == NULL) |
| 3760 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3761 | nfs4_schedule_stateid_recovery(server, state); |
| 3762 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 3763 | case -NFS4ERR_EXPIRED: |
| 3764 | if (state != NULL) |
| 3765 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3766 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3767 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3768 | nfs4_schedule_lease_recovery(clp); |
| 3769 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3770 | #if defined(CONFIG_NFS_V4_1) |
| 3771 | case -NFS4ERR_BADSESSION: |
| 3772 | case -NFS4ERR_BADSLOT: |
| 3773 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3774 | case -NFS4ERR_DEADSESSION: |
| 3775 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3776 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3777 | case -NFS4ERR_SEQ_MISORDERED: |
| 3778 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3779 | task->tk_status); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3780 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3781 | task->tk_status = 0; |
| 3782 | return -EAGAIN; |
| 3783 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3784 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3785 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3786 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3787 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3788 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3789 | task->tk_status = 0; |
| 3790 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 3791 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | case -NFS4ERR_OLD_STATEID: |
| 3793 | task->tk_status = 0; |
| 3794 | return -EAGAIN; |
| 3795 | } |
| 3796 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3797 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3798 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3799 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3800 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3801 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3802 | task->tk_status = 0; |
| 3803 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3804 | } |
| 3805 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3806 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 3807 | unsigned short port, struct rpc_cred *cred, |
| 3808 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3809 | { |
| 3810 | nfs4_verifier sc_verifier; |
| 3811 | struct nfs4_setclientid setclientid = { |
| 3812 | .sc_verifier = &sc_verifier, |
| 3813 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 3814 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3815 | }; |
| 3816 | struct rpc_message msg = { |
| 3817 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3818 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3819 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3820 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3821 | }; |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3822 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3823 | int loop = 0; |
| 3824 | int status; |
| 3825 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3826 | p = (__be32*)sc_verifier.data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3827 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 3828 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 3829 | |
| 3830 | for(;;) { |
| 3831 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3832 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3833 | clp->cl_ipaddr, |
| 3834 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3835 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3836 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3837 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3838 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 | clp->cl_id_uniquifier); |
| 3840 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3841 | sizeof(setclientid.sc_netid), |
| 3842 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3843 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3844 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3845 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3846 | clp->cl_ipaddr, port >> 8, port & 255); |
| 3847 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 3848 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3849 | if (status != -NFS4ERR_CLID_INUSE) |
| 3850 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3851 | if (loop != 0) { |
| 3852 | ++clp->cl_id_uniquifier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3853 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3854 | } |
| 3855 | ++loop; |
| 3856 | ssleep(clp->cl_lease_time / HZ + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3857 | } |
| 3858 | return status; |
| 3859 | } |
| 3860 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3861 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3862 | struct nfs4_setclientid_res *arg, |
| 3863 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3864 | { |
| 3865 | struct nfs_fsinfo fsinfo; |
| 3866 | struct rpc_message msg = { |
| 3867 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3868 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3869 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3870 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3871 | }; |
| 3872 | unsigned long now; |
| 3873 | int status; |
| 3874 | |
| 3875 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 3876 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3877 | if (status == 0) { |
| 3878 | spin_lock(&clp->cl_lock); |
| 3879 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 3880 | clp->cl_last_renewal = now; |
| 3881 | spin_unlock(&clp->cl_lock); |
| 3882 | } |
| 3883 | return status; |
| 3884 | } |
| 3885 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3886 | struct nfs4_delegreturndata { |
| 3887 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3888 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3889 | struct nfs_fh fh; |
| 3890 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3891 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3892 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3893 | int rpc_status; |
| 3894 | }; |
| 3895 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3896 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 3897 | { |
| 3898 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3899 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3900 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3901 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3902 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3903 | switch (task->tk_status) { |
| 3904 | case -NFS4ERR_STALE_STATEID: |
| 3905 | case -NFS4ERR_EXPIRED: |
| 3906 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3907 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3908 | break; |
| 3909 | default: |
| 3910 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 3911 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3912 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3913 | return; |
| 3914 | } |
| 3915 | } |
| 3916 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3917 | } |
| 3918 | |
| 3919 | static void nfs4_delegreturn_release(void *calldata) |
| 3920 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3921 | kfree(calldata); |
| 3922 | } |
| 3923 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3924 | #if defined(CONFIG_NFS_V4_1) |
| 3925 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 3926 | { |
| 3927 | struct nfs4_delegreturndata *d_data; |
| 3928 | |
| 3929 | d_data = (struct nfs4_delegreturndata *)data; |
| 3930 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3931 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3932 | &d_data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3933 | &d_data->res.seq_res, task)) |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3934 | return; |
| 3935 | rpc_call_start(task); |
| 3936 | } |
| 3937 | #endif /* CONFIG_NFS_V4_1 */ |
| 3938 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 3939 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3940 | #if defined(CONFIG_NFS_V4_1) |
| 3941 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 3942 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3943 | .rpc_call_done = nfs4_delegreturn_done, |
| 3944 | .rpc_release = nfs4_delegreturn_release, |
| 3945 | }; |
| 3946 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3947 | 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] | 3948 | { |
| 3949 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3950 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3951 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3952 | struct rpc_message msg = { |
| 3953 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 3954 | .rpc_cred = cred, |
| 3955 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3956 | struct rpc_task_setup task_setup_data = { |
| 3957 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3958 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3959 | .callback_ops = &nfs4_delegreturn_ops, |
| 3960 | .flags = RPC_TASK_ASYNC, |
| 3961 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3962 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3963 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3964 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3965 | if (data == NULL) |
| 3966 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3967 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3968 | data->args.fhandle = &data->fh; |
| 3969 | data->args.stateid = &data->stateid; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3970 | data->args.bitmask = server->attr_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3971 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
| 3972 | memcpy(&data->stateid, stateid, sizeof(data->stateid)); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3973 | data->res.fattr = &data->fattr; |
| 3974 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3975 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3976 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3977 | data->rpc_status = 0; |
| 3978 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3979 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3980 | msg.rpc_argp = &data->args; |
| 3981 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3982 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 3983 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3984 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3985 | if (!issync) |
| 3986 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3987 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3988 | if (status != 0) |
| 3989 | goto out; |
| 3990 | status = data->rpc_status; |
| 3991 | if (status != 0) |
| 3992 | goto out; |
| 3993 | nfs_refresh_inode(inode, &data->fattr); |
| 3994 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3995 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3996 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3997 | } |
| 3998 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3999 | 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] | 4000 | { |
| 4001 | struct nfs_server *server = NFS_SERVER(inode); |
| 4002 | struct nfs4_exception exception = { }; |
| 4003 | int err; |
| 4004 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4005 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4006 | switch (err) { |
| 4007 | case -NFS4ERR_STALE_STATEID: |
| 4008 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4009 | case 0: |
| 4010 | return 0; |
| 4011 | } |
| 4012 | err = nfs4_handle_exception(server, err, &exception); |
| 4013 | } while (exception.retry); |
| 4014 | return err; |
| 4015 | } |
| 4016 | |
| 4017 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4018 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4019 | |
| 4020 | /* |
| 4021 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4022 | */ |
| 4023 | static unsigned long |
| 4024 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4025 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4026 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | timeout <<= 1; |
| 4028 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4029 | return NFS4_LOCK_MAXTIMEOUT; |
| 4030 | return timeout; |
| 4031 | } |
| 4032 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4033 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4034 | { |
| 4035 | struct inode *inode = state->inode; |
| 4036 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4037 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4038 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4040 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4041 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4042 | struct nfs_lockt_res res = { |
| 4043 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4044 | }; |
| 4045 | struct rpc_message msg = { |
| 4046 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4047 | .rpc_argp = &arg, |
| 4048 | .rpc_resp = &res, |
| 4049 | .rpc_cred = state->owner->so_cred, |
| 4050 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4051 | struct nfs4_lock_state *lsp; |
| 4052 | int status; |
| 4053 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4054 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4055 | status = nfs4_set_lock_state(state, request); |
| 4056 | if (status != 0) |
| 4057 | goto out; |
| 4058 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4059 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4060 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4061 | 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] | 4062 | switch (status) { |
| 4063 | case 0: |
| 4064 | request->fl_type = F_UNLCK; |
| 4065 | break; |
| 4066 | case -NFS4ERR_DENIED: |
| 4067 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4068 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4069 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4070 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4071 | return status; |
| 4072 | } |
| 4073 | |
| 4074 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4075 | { |
| 4076 | struct nfs4_exception exception = { }; |
| 4077 | int err; |
| 4078 | |
| 4079 | do { |
| 4080 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4081 | _nfs4_proc_getlk(state, cmd, request), |
| 4082 | &exception); |
| 4083 | } while (exception.retry); |
| 4084 | return err; |
| 4085 | } |
| 4086 | |
| 4087 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4088 | { |
| 4089 | int res = 0; |
| 4090 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4091 | case FL_POSIX: |
| 4092 | res = posix_lock_file_wait(file, fl); |
| 4093 | break; |
| 4094 | case FL_FLOCK: |
| 4095 | res = flock_lock_file_wait(file, fl); |
| 4096 | break; |
| 4097 | default: |
| 4098 | BUG(); |
| 4099 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4100 | return res; |
| 4101 | } |
| 4102 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4103 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4104 | struct nfs_locku_args arg; |
| 4105 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4106 | struct nfs4_lock_state *lsp; |
| 4107 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4108 | struct file_lock fl; |
| 4109 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4110 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4111 | }; |
| 4112 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4113 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4114 | struct nfs_open_context *ctx, |
| 4115 | struct nfs4_lock_state *lsp, |
| 4116 | struct nfs_seqid *seqid) |
| 4117 | { |
| 4118 | struct nfs4_unlockdata *p; |
| 4119 | struct inode *inode = lsp->ls_state->inode; |
| 4120 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4121 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4122 | if (p == NULL) |
| 4123 | return NULL; |
| 4124 | p->arg.fh = NFS_FH(inode); |
| 4125 | p->arg.fl = &p->fl; |
| 4126 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4127 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4128 | p->arg.stateid = &lsp->ls_stateid; |
| 4129 | p->lsp = lsp; |
| 4130 | atomic_inc(&lsp->ls_count); |
| 4131 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4132 | p->ctx = get_nfs_open_context(ctx); |
| 4133 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4134 | p->server = NFS_SERVER(inode); |
| 4135 | return p; |
| 4136 | } |
| 4137 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4138 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4139 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4140 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4141 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4142 | nfs4_put_lock_state(calldata->lsp); |
| 4143 | put_nfs_open_context(calldata->ctx); |
| 4144 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4145 | } |
| 4146 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4147 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4148 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4149 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4150 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4151 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4152 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4153 | switch (task->tk_status) { |
| 4154 | case 0: |
| 4155 | memcpy(calldata->lsp->ls_stateid.data, |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4156 | calldata->res.stateid.data, |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4157 | sizeof(calldata->lsp->ls_stateid.data)); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4158 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4159 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4160 | case -NFS4ERR_BAD_STATEID: |
| 4161 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4162 | case -NFS4ERR_STALE_STATEID: |
| 4163 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4164 | break; |
| 4165 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4166 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4167 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4168 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4169 | } |
| 4170 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4171 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4172 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4173 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4174 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4175 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4176 | return; |
| 4177 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4178 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4179 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4180 | return; |
| 4181 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4182 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4183 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4184 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4185 | &calldata->res.seq_res, task)) |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4186 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4187 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4188 | } |
| 4189 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4190 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4191 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4192 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4193 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4194 | }; |
| 4195 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4196 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4197 | struct nfs_open_context *ctx, |
| 4198 | struct nfs4_lock_state *lsp, |
| 4199 | struct nfs_seqid *seqid) |
| 4200 | { |
| 4201 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4202 | struct rpc_message msg = { |
| 4203 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4204 | .rpc_cred = ctx->cred, |
| 4205 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4206 | struct rpc_task_setup task_setup_data = { |
| 4207 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4208 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4209 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4210 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4211 | .flags = RPC_TASK_ASYNC, |
| 4212 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4213 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4214 | /* Ensure this is an unlock - when canceling a lock, the |
| 4215 | * canceled lock is passed in, and it won't be an unlock. |
| 4216 | */ |
| 4217 | fl->fl_type = F_UNLCK; |
| 4218 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4219 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4220 | if (data == NULL) { |
| 4221 | nfs_free_seqid(seqid); |
| 4222 | return ERR_PTR(-ENOMEM); |
| 4223 | } |
| 4224 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4225 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4226 | msg.rpc_argp = &data->arg; |
| 4227 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4228 | task_setup_data.callback_data = data; |
| 4229 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4230 | } |
| 4231 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4232 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4233 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4234 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4235 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4236 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4237 | struct rpc_task *task; |
| 4238 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4239 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4240 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4241 | status = nfs4_set_lock_state(state, request); |
| 4242 | /* Unlock _before_ we do the RPC call */ |
| 4243 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4244 | down_read(&nfsi->rwsem); |
| 4245 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4246 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4247 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4248 | } |
| 4249 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4250 | if (status != 0) |
| 4251 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4252 | /* Is this a delegated lock? */ |
| 4253 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4254 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4255 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4256 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4257 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4258 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4259 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4260 | 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] | 4261 | status = PTR_ERR(task); |
| 4262 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4263 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4264 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4265 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4266 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4267 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4268 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4269 | } |
| 4270 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4271 | struct nfs4_lockdata { |
| 4272 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4273 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4274 | struct nfs4_lock_state *lsp; |
| 4275 | struct nfs_open_context *ctx; |
| 4276 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4277 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4278 | int rpc_status; |
| 4279 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4280 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4281 | }; |
| 4282 | |
| 4283 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4284 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4285 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4286 | { |
| 4287 | struct nfs4_lockdata *p; |
| 4288 | struct inode *inode = lsp->ls_state->inode; |
| 4289 | struct nfs_server *server = NFS_SERVER(inode); |
| 4290 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4291 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4292 | if (p == NULL) |
| 4293 | return NULL; |
| 4294 | |
| 4295 | p->arg.fh = NFS_FH(inode); |
| 4296 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4297 | 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] | 4298 | if (p->arg.open_seqid == NULL) |
| 4299 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4300 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4301 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4302 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4303 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4304 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4305 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4306 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4307 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4308 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4309 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4310 | atomic_inc(&lsp->ls_count); |
| 4311 | p->ctx = get_nfs_open_context(ctx); |
| 4312 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4313 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4314 | out_free_seqid: |
| 4315 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4316 | out_free: |
| 4317 | kfree(p); |
| 4318 | return NULL; |
| 4319 | } |
| 4320 | |
| 4321 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4322 | { |
| 4323 | struct nfs4_lockdata *data = calldata; |
| 4324 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4325 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4326 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4327 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4328 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4329 | /* Do we need to do an open_to_lock_owner? */ |
| 4330 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4331 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4332 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4333 | data->arg.open_stateid = &state->stateid; |
| 4334 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4335 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4336 | } else |
| 4337 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4338 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4339 | if (nfs4_setup_sequence(data->server, |
| 4340 | &data->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4341 | &data->res.seq_res, task)) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4342 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4343 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4344 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4345 | } |
| 4346 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4347 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4348 | { |
| 4349 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4350 | nfs4_lock_prepare(task, calldata); |
| 4351 | } |
| 4352 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4353 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4354 | { |
| 4355 | struct nfs4_lockdata *data = calldata; |
| 4356 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4357 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4358 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4359 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4360 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4361 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4362 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4363 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4364 | if (data->rpc_status == 0) |
| 4365 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4366 | else |
| 4367 | goto out; |
| 4368 | } |
| 4369 | if (data->rpc_status == 0) { |
| 4370 | memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, |
| 4371 | sizeof(data->lsp->ls_stateid.data)); |
| 4372 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4373 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4374 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4375 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4376 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4377 | } |
| 4378 | |
| 4379 | static void nfs4_lock_release(void *calldata) |
| 4380 | { |
| 4381 | struct nfs4_lockdata *data = calldata; |
| 4382 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4383 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4384 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4385 | if (data->cancelled != 0) { |
| 4386 | struct rpc_task *task; |
| 4387 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4388 | data->arg.lock_seqid); |
| 4389 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4390 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4391 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4392 | } else |
| 4393 | nfs_free_seqid(data->arg.lock_seqid); |
| 4394 | nfs4_put_lock_state(data->lsp); |
| 4395 | put_nfs_open_context(data->ctx); |
| 4396 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4397 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4398 | } |
| 4399 | |
| 4400 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4401 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4402 | .rpc_call_done = nfs4_lock_done, |
| 4403 | .rpc_release = nfs4_lock_release, |
| 4404 | }; |
| 4405 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4406 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4407 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4408 | .rpc_call_done = nfs4_lock_done, |
| 4409 | .rpc_release = nfs4_lock_release, |
| 4410 | }; |
| 4411 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4412 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4413 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4414 | switch (error) { |
| 4415 | case -NFS4ERR_ADMIN_REVOKED: |
| 4416 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4417 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4418 | if (new_lock_owner != 0 || |
| 4419 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4420 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4421 | break; |
| 4422 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4423 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4424 | case -NFS4ERR_EXPIRED: |
| 4425 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4426 | }; |
| 4427 | } |
| 4428 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4429 | 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] | 4430 | { |
| 4431 | struct nfs4_lockdata *data; |
| 4432 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4433 | struct rpc_message msg = { |
| 4434 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4435 | .rpc_cred = state->owner->so_cred, |
| 4436 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4437 | struct rpc_task_setup task_setup_data = { |
| 4438 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4439 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4440 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4441 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4442 | .flags = RPC_TASK_ASYNC, |
| 4443 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4444 | int ret; |
| 4445 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4446 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4447 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4448 | fl->fl_u.nfs4_fl.owner, |
| 4449 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4450 | if (data == NULL) |
| 4451 | return -ENOMEM; |
| 4452 | if (IS_SETLKW(cmd)) |
| 4453 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4454 | if (recovery_type > NFS_LOCK_NEW) { |
| 4455 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4456 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4457 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4458 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4459 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4460 | msg.rpc_argp = &data->arg; |
| 4461 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4462 | task_setup_data.callback_data = data; |
| 4463 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4464 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4465 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4466 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4467 | if (ret == 0) { |
| 4468 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4469 | if (ret) |
| 4470 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4471 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4472 | } else |
| 4473 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4474 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4475 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4476 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4477 | } |
| 4478 | |
| 4479 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4480 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4481 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4482 | struct nfs4_exception exception = { }; |
| 4483 | int err; |
| 4484 | |
| 4485 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4486 | /* Cache the lock if possible... */ |
| 4487 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4488 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4489 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4490 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4491 | break; |
| 4492 | nfs4_handle_exception(server, err, &exception); |
| 4493 | } while (exception.retry); |
| 4494 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | } |
| 4496 | |
| 4497 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4498 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4499 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4500 | struct nfs4_exception exception = { }; |
| 4501 | int err; |
| 4502 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4503 | err = nfs4_set_lock_state(state, request); |
| 4504 | if (err != 0) |
| 4505 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4506 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4507 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4508 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4509 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4510 | switch (err) { |
| 4511 | default: |
| 4512 | goto out; |
| 4513 | case -NFS4ERR_GRACE: |
| 4514 | case -NFS4ERR_DELAY: |
| 4515 | nfs4_handle_exception(server, err, &exception); |
| 4516 | err = 0; |
| 4517 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4518 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4519 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4520 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4521 | } |
| 4522 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4523 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4524 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4525 | { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4526 | int status, ret = NFS_OK; |
| 4527 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4528 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4529 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4530 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 4531 | if (lsp->ls_flags & NFS_LOCK_INITIALIZED) { |
| 4532 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 4533 | if (status != NFS_OK) { |
| 4534 | nfs41_free_stateid(server, &lsp->ls_stateid); |
| 4535 | lsp->ls_flags &= ~NFS_LOCK_INITIALIZED; |
| 4536 | ret = status; |
| 4537 | } |
| 4538 | } |
| 4539 | }; |
| 4540 | |
| 4541 | return ret; |
| 4542 | } |
| 4543 | |
| 4544 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4545 | { |
| 4546 | int status = NFS_OK; |
| 4547 | |
| 4548 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 4549 | status = nfs41_check_expired_locks(state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4550 | if (status == NFS_OK) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4551 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4552 | return nfs4_lock_expired(state, request); |
| 4553 | } |
| 4554 | #endif |
| 4555 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4556 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4557 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4558 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4559 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4560 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4561 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4562 | if ((fl_flags & FL_POSIX) && |
| 4563 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4564 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4565 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4566 | status = nfs4_set_lock_state(state, request); |
| 4567 | if (status != 0) |
| 4568 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4569 | request->fl_flags |= FL_ACCESS; |
| 4570 | status = do_vfs_lock(request->fl_file, request); |
| 4571 | if (status < 0) |
| 4572 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4573 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4574 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4575 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4576 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4577 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4578 | status = do_vfs_lock(request->fl_file, request); |
| 4579 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4580 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4581 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4582 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4583 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4584 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4585 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4586 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4587 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 4588 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4589 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4590 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4591 | out: |
| 4592 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4593 | return status; |
| 4594 | } |
| 4595 | |
| 4596 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4597 | { |
| 4598 | struct nfs4_exception exception = { }; |
| 4599 | int err; |
| 4600 | |
| 4601 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4602 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4603 | if (err == -NFS4ERR_DENIED) |
| 4604 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4605 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4606 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4607 | } while (exception.retry); |
| 4608 | return err; |
| 4609 | } |
| 4610 | |
| 4611 | static int |
| 4612 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4613 | { |
| 4614 | struct nfs_open_context *ctx; |
| 4615 | struct nfs4_state *state; |
| 4616 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4617 | int status; |
| 4618 | |
| 4619 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4620 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4621 | state = ctx->state; |
| 4622 | |
| 4623 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4624 | return -EINVAL; |
| 4625 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4626 | if (IS_GETLK(cmd)) { |
| 4627 | if (state != NULL) |
| 4628 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4629 | return 0; |
| 4630 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4631 | |
| 4632 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4633 | return -EINVAL; |
| 4634 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4635 | if (request->fl_type == F_UNLCK) { |
| 4636 | if (state != NULL) |
| 4637 | return nfs4_proc_unlck(state, cmd, request); |
| 4638 | return 0; |
| 4639 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4640 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4641 | if (state == NULL) |
| 4642 | return -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4643 | do { |
| 4644 | status = nfs4_proc_setlk(state, cmd, request); |
| 4645 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4646 | break; |
| 4647 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4648 | status = -ERESTARTSYS; |
| 4649 | if (signalled()) |
| 4650 | break; |
| 4651 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4652 | return status; |
| 4653 | } |
| 4654 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4655 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4656 | { |
| 4657 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4658 | struct nfs4_exception exception = { }; |
| 4659 | int err; |
| 4660 | |
| 4661 | err = nfs4_set_lock_state(state, fl); |
| 4662 | if (err != 0) |
| 4663 | goto out; |
| 4664 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4665 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4666 | switch (err) { |
| 4667 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4668 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 4669 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4670 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4671 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4672 | goto out; |
| 4673 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4674 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4675 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4676 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4677 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4678 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4679 | case -NFS4ERR_BADSESSION: |
| 4680 | case -NFS4ERR_BADSLOT: |
| 4681 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4682 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4683 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4684 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4685 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4686 | case -ERESTARTSYS: |
| 4687 | /* |
| 4688 | * The show must go on: exit, but mark the |
| 4689 | * stateid as needing recovery. |
| 4690 | */ |
| 4691 | case -NFS4ERR_ADMIN_REVOKED: |
| 4692 | case -NFS4ERR_BAD_STATEID: |
| 4693 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4694 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4695 | err = 0; |
| 4696 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4697 | case -EKEYEXPIRED: |
| 4698 | /* |
| 4699 | * User RPCSEC_GSS context has expired. |
| 4700 | * We cannot recover this stateid now, so |
| 4701 | * skip it and allow recovery thread to |
| 4702 | * proceed. |
| 4703 | */ |
| 4704 | err = 0; |
| 4705 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4706 | case -ENOMEM: |
| 4707 | case -NFS4ERR_DENIED: |
| 4708 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4709 | err = 0; |
| 4710 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4711 | case -NFS4ERR_DELAY: |
| 4712 | break; |
| 4713 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4714 | err = nfs4_handle_exception(server, err, &exception); |
| 4715 | } while (exception.retry); |
| 4716 | out: |
| 4717 | return err; |
| 4718 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4719 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4720 | static void nfs4_release_lockowner_release(void *calldata) |
| 4721 | { |
| 4722 | kfree(calldata); |
| 4723 | } |
| 4724 | |
| 4725 | const struct rpc_call_ops nfs4_release_lockowner_ops = { |
| 4726 | .rpc_release = nfs4_release_lockowner_release, |
| 4727 | }; |
| 4728 | |
| 4729 | void nfs4_release_lockowner(const struct nfs4_lock_state *lsp) |
| 4730 | { |
| 4731 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
| 4732 | struct nfs_release_lockowner_args *args; |
| 4733 | struct rpc_message msg = { |
| 4734 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 4735 | }; |
| 4736 | |
| 4737 | if (server->nfs_client->cl_mvops->minor_version != 0) |
| 4738 | return; |
| 4739 | args = kmalloc(sizeof(*args), GFP_NOFS); |
| 4740 | if (!args) |
| 4741 | return; |
| 4742 | args->lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4743 | args->lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4744 | args->lock_owner.s_dev = server->s_dev; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4745 | msg.rpc_argp = args; |
| 4746 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args); |
| 4747 | } |
| 4748 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4749 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4750 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4751 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 4752 | const void *buf, size_t buflen, |
| 4753 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4754 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4755 | if (strcmp(key, "") != 0) |
| 4756 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4757 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4758 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4759 | } |
| 4760 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4761 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 4762 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4763 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4764 | if (strcmp(key, "") != 0) |
| 4765 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4766 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4767 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4768 | } |
| 4769 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4770 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 4771 | size_t list_len, const char *name, |
| 4772 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4773 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4774 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4775 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4776 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4777 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4778 | |
| 4779 | if (list && len <= list_len) |
| 4780 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4781 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4782 | } |
| 4783 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4784 | /* |
| 4785 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 4786 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4787 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4788 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4789 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 4790 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 4791 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
| 4792 | (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4793 | return; |
| 4794 | |
| 4795 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 4796 | NFS_ATTR_FATTR_NLINK; |
| 4797 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4798 | fattr->nlink = 2; |
| 4799 | } |
| 4800 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 4801 | int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 4802 | struct nfs4_fs_locations *fs_locations, struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4803 | { |
| 4804 | struct nfs_server *server = NFS_SERVER(dir); |
| 4805 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4806 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4807 | }; |
| 4808 | struct nfs4_fs_locations_arg args = { |
| 4809 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4810 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4811 | .page = page, |
| 4812 | .bitmask = bitmask, |
| 4813 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4814 | struct nfs4_fs_locations_res res = { |
| 4815 | .fs_locations = fs_locations, |
| 4816 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4817 | struct rpc_message msg = { |
| 4818 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4819 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4820 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4821 | }; |
| 4822 | int status; |
| 4823 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4824 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4825 | |
| 4826 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 4827 | * is not supported */ |
| 4828 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 4829 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 4830 | else |
| 4831 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 4832 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4833 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4834 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 4835 | fs_locations->nlocations = 0; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4836 | 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] | 4837 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4838 | return status; |
| 4839 | } |
| 4840 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 4841 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4842 | { |
| 4843 | int status; |
| 4844 | struct nfs4_secinfo_arg args = { |
| 4845 | .dir_fh = NFS_FH(dir), |
| 4846 | .name = name, |
| 4847 | }; |
| 4848 | struct nfs4_secinfo_res res = { |
| 4849 | .flavors = flavors, |
| 4850 | }; |
| 4851 | struct rpc_message msg = { |
| 4852 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 4853 | .rpc_argp = &args, |
| 4854 | .rpc_resp = &res, |
| 4855 | }; |
| 4856 | |
| 4857 | dprintk("NFS call secinfo %s\n", name->name); |
| 4858 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 4859 | dprintk("NFS reply secinfo: %d\n", status); |
| 4860 | return status; |
| 4861 | } |
| 4862 | |
| 4863 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4864 | { |
| 4865 | struct nfs4_exception exception = { }; |
| 4866 | int err; |
| 4867 | do { |
| 4868 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 4869 | _nfs4_proc_secinfo(dir, name, flavors), |
| 4870 | &exception); |
| 4871 | } while (exception.retry); |
| 4872 | return err; |
| 4873 | } |
| 4874 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4875 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4876 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4877 | * Check the exchange flags returned by the server for invalid flags, having |
| 4878 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 4879 | * DS flags set. |
| 4880 | */ |
| 4881 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 4882 | { |
| 4883 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 4884 | goto out_inval; |
| 4885 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 4886 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 4887 | goto out_inval; |
| 4888 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 4889 | goto out_inval; |
| 4890 | return NFS_OK; |
| 4891 | out_inval: |
| 4892 | return -NFS4ERR_INVAL; |
| 4893 | } |
| 4894 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4895 | static bool |
| 4896 | nfs41_same_server_scope(struct server_scope *a, struct server_scope *b) |
| 4897 | { |
| 4898 | if (a->server_scope_sz == b->server_scope_sz && |
| 4899 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 4900 | return true; |
| 4901 | |
| 4902 | return false; |
| 4903 | } |
| 4904 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4905 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4906 | * nfs4_proc_exchange_id() |
| 4907 | * |
| 4908 | * Since the clientid has expired, all compounds using sessions |
| 4909 | * associated with the stale clientid will be returning |
| 4910 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 4911 | * be in some phase of session reset. |
| 4912 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 4913 | 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] | 4914 | { |
| 4915 | nfs4_verifier verifier; |
| 4916 | struct nfs41_exchange_id_args args = { |
| 4917 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4918 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4919 | }; |
| 4920 | struct nfs41_exchange_id_res res = { |
| 4921 | .client = clp, |
| 4922 | }; |
| 4923 | int status; |
| 4924 | struct rpc_message msg = { |
| 4925 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 4926 | .rpc_argp = &args, |
| 4927 | .rpc_resp = &res, |
| 4928 | .rpc_cred = cred, |
| 4929 | }; |
| 4930 | __be32 *p; |
| 4931 | |
| 4932 | dprintk("--> %s\n", __func__); |
| 4933 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 4934 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4935 | p = (u32 *)verifier.data; |
| 4936 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 4937 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 4938 | args.verifier = &verifier; |
| 4939 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4940 | args.id_len = scnprintf(args.id, sizeof(args.id), |
| 4941 | "%s/%s.%s/%u", |
| 4942 | clp->cl_ipaddr, |
| 4943 | init_utsname()->nodename, |
| 4944 | init_utsname()->domainname, |
| 4945 | clp->cl_rpcclient->cl_auth->au_flavor); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4946 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4947 | res.server_scope = kzalloc(sizeof(struct server_scope), GFP_KERNEL); |
| 4948 | if (unlikely(!res.server_scope)) |
| 4949 | return -ENOMEM; |
| 4950 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4951 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4952 | if (!status) |
| 4953 | status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4954 | |
| 4955 | if (!status) { |
| 4956 | if (clp->server_scope && |
| 4957 | !nfs41_same_server_scope(clp->server_scope, |
| 4958 | res.server_scope)) { |
| 4959 | dprintk("%s: server_scope mismatch detected\n", |
| 4960 | __func__); |
| 4961 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 4962 | kfree(clp->server_scope); |
| 4963 | clp->server_scope = NULL; |
| 4964 | } |
| 4965 | |
| 4966 | if (!clp->server_scope) |
| 4967 | clp->server_scope = res.server_scope; |
| 4968 | else |
| 4969 | kfree(res.server_scope); |
| 4970 | } |
| 4971 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4972 | dprintk("<-- %s status= %d\n", __func__, status); |
| 4973 | return status; |
| 4974 | } |
| 4975 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4976 | struct nfs4_get_lease_time_data { |
| 4977 | struct nfs4_get_lease_time_args *args; |
| 4978 | struct nfs4_get_lease_time_res *res; |
| 4979 | struct nfs_client *clp; |
| 4980 | }; |
| 4981 | |
| 4982 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 4983 | void *calldata) |
| 4984 | { |
| 4985 | int ret; |
| 4986 | struct nfs4_get_lease_time_data *data = |
| 4987 | (struct nfs4_get_lease_time_data *)calldata; |
| 4988 | |
| 4989 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4990 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4991 | /* just setup sequence, do not trigger session recovery |
| 4992 | since we're invoked within one */ |
| 4993 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4994 | &data->args->la_seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4995 | &data->res->lr_seq_res, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4996 | |
| 4997 | BUG_ON(ret == -EAGAIN); |
| 4998 | rpc_call_start(task); |
| 4999 | dprintk("<-- %s\n", __func__); |
| 5000 | } |
| 5001 | |
| 5002 | /* |
| 5003 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5004 | * from sequence operation or clientid errors. |
| 5005 | */ |
| 5006 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5007 | { |
| 5008 | struct nfs4_get_lease_time_data *data = |
| 5009 | (struct nfs4_get_lease_time_data *)calldata; |
| 5010 | |
| 5011 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5012 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5013 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5014 | switch (task->tk_status) { |
| 5015 | case -NFS4ERR_DELAY: |
| 5016 | case -NFS4ERR_GRACE: |
| 5017 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5018 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5019 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5020 | /* fall through */ |
| 5021 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5022 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5023 | return; |
| 5024 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5025 | dprintk("<-- %s\n", __func__); |
| 5026 | } |
| 5027 | |
| 5028 | struct rpc_call_ops nfs4_get_lease_time_ops = { |
| 5029 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5030 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5031 | }; |
| 5032 | |
| 5033 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5034 | { |
| 5035 | struct rpc_task *task; |
| 5036 | struct nfs4_get_lease_time_args args; |
| 5037 | struct nfs4_get_lease_time_res res = { |
| 5038 | .lr_fsinfo = fsinfo, |
| 5039 | }; |
| 5040 | struct nfs4_get_lease_time_data data = { |
| 5041 | .args = &args, |
| 5042 | .res = &res, |
| 5043 | .clp = clp, |
| 5044 | }; |
| 5045 | struct rpc_message msg = { |
| 5046 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5047 | .rpc_argp = &args, |
| 5048 | .rpc_resp = &res, |
| 5049 | }; |
| 5050 | struct rpc_task_setup task_setup = { |
| 5051 | .rpc_client = clp->cl_rpcclient, |
| 5052 | .rpc_message = &msg, |
| 5053 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5054 | .callback_data = &data, |
| 5055 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5056 | }; |
| 5057 | int status; |
| 5058 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5059 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5060 | dprintk("--> %s\n", __func__); |
| 5061 | task = rpc_run_task(&task_setup); |
| 5062 | |
| 5063 | if (IS_ERR(task)) |
| 5064 | status = PTR_ERR(task); |
| 5065 | else { |
| 5066 | status = task->tk_status; |
| 5067 | rpc_put_task(task); |
| 5068 | } |
| 5069 | dprintk("<-- %s return %d\n", __func__, status); |
| 5070 | |
| 5071 | return status; |
| 5072 | } |
| 5073 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5074 | /* |
| 5075 | * Reset a slot table |
| 5076 | */ |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5077 | static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 5078 | int ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5079 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5080 | struct nfs4_slot *new = NULL; |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5081 | int i; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5082 | int ret = 0; |
| 5083 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5084 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 5085 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5086 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5087 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 5088 | if (max_reqs != tbl->max_slots) { |
| 5089 | ret = -ENOMEM; |
| 5090 | new = kmalloc(max_reqs * sizeof(struct nfs4_slot), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5091 | GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5092 | if (!new) |
| 5093 | goto out; |
| 5094 | ret = 0; |
| 5095 | kfree(tbl->slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5096 | } |
| 5097 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5098 | if (new) { |
| 5099 | tbl->slots = new; |
| 5100 | tbl->max_slots = max_reqs; |
| 5101 | } |
| 5102 | for (i = 0; i < tbl->max_slots; ++i) |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5103 | tbl->slots[i].seq_nr = ivalue; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5104 | spin_unlock(&tbl->slot_tbl_lock); |
| 5105 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5106 | tbl, tbl->slots, tbl->max_slots); |
| 5107 | out: |
| 5108 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5109 | return ret; |
| 5110 | } |
| 5111 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5112 | /* Destroy the slot table */ |
| 5113 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 5114 | { |
| 5115 | if (session->fc_slot_table.slots != NULL) { |
| 5116 | kfree(session->fc_slot_table.slots); |
| 5117 | session->fc_slot_table.slots = NULL; |
| 5118 | } |
| 5119 | if (session->bc_slot_table.slots != NULL) { |
| 5120 | kfree(session->bc_slot_table.slots); |
| 5121 | session->bc_slot_table.slots = NULL; |
| 5122 | } |
| 5123 | return; |
| 5124 | } |
| 5125 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5126 | /* |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5127 | * Initialize slot table |
| 5128 | */ |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5129 | static int nfs4_init_slot_table(struct nfs4_slot_table *tbl, |
| 5130 | int max_slots, int ivalue) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5131 | { |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5132 | struct nfs4_slot *slot; |
| 5133 | int ret = -ENOMEM; |
| 5134 | |
| 5135 | BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE); |
| 5136 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5137 | dprintk("--> %s: max_reqs=%u\n", __func__, max_slots); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5138 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5139 | slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5140 | if (!slot) |
| 5141 | goto out; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5142 | ret = 0; |
| 5143 | |
| 5144 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5145 | tbl->max_slots = max_slots; |
| 5146 | tbl->slots = slot; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5147 | tbl->highest_used_slotid = NFS4_NO_SLOT; /* no slot is currently used */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5148 | spin_unlock(&tbl->slot_tbl_lock); |
| 5149 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5150 | tbl, tbl->slots, tbl->max_slots); |
| 5151 | out: |
| 5152 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5153 | return ret; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5154 | } |
| 5155 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5156 | /* |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5157 | * Initialize or reset the forechannel and backchannel tables |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5158 | */ |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5159 | static int nfs4_setup_session_slot_tables(struct nfs4_session *ses) |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5160 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5161 | struct nfs4_slot_table *tbl; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5162 | int status; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5163 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5164 | dprintk("--> %s\n", __func__); |
| 5165 | /* Fore channel */ |
| 5166 | tbl = &ses->fc_slot_table; |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5167 | if (tbl->slots == NULL) { |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5168 | status = nfs4_init_slot_table(tbl, ses->fc_attrs.max_reqs, 1); |
| 5169 | if (status) /* -ENOMEM */ |
| 5170 | return status; |
| 5171 | } else { |
| 5172 | status = nfs4_reset_slot_table(tbl, ses->fc_attrs.max_reqs, 1); |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5173 | if (status) |
| 5174 | return status; |
| 5175 | } |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5176 | /* Back channel */ |
| 5177 | tbl = &ses->bc_slot_table; |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5178 | if (tbl->slots == NULL) { |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5179 | status = nfs4_init_slot_table(tbl, ses->bc_attrs.max_reqs, 0); |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5180 | if (status) |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5181 | /* Fore and back channel share a connection so get |
| 5182 | * both slot tables or neither */ |
| 5183 | nfs4_destroy_slot_tables(ses); |
| 5184 | } else |
| 5185 | status = nfs4_reset_slot_table(tbl, ses->bc_attrs.max_reqs, 0); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5186 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5187 | } |
| 5188 | |
| 5189 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 5190 | { |
| 5191 | struct nfs4_session *session; |
| 5192 | struct nfs4_slot_table *tbl; |
| 5193 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5194 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5195 | if (!session) |
| 5196 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 5197 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5198 | tbl = &session->fc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5199 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5200 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5201 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5202 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5203 | |
| 5204 | tbl = &session->bc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5205 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5206 | spin_lock_init(&tbl->slot_tbl_lock); |
| 5207 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5208 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5209 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5210 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 5211 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5212 | session->clp = clp; |
| 5213 | return session; |
| 5214 | } |
| 5215 | |
| 5216 | void nfs4_destroy_session(struct nfs4_session *session) |
| 5217 | { |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5218 | nfs4_proc_destroy_session(session); |
| 5219 | dprintk("%s Destroy backchannel for xprt %p\n", |
| 5220 | __func__, session->clp->cl_rpcclient->cl_xprt); |
| 5221 | xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt, |
| 5222 | NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5223 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5224 | kfree(session); |
| 5225 | } |
| 5226 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5227 | /* |
| 5228 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5229 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5230 | * use them. |
| 5231 | * |
| 5232 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5233 | * always set csa_cachethis to FALSE because the current implementation |
| 5234 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5235 | */ |
| 5236 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5237 | { |
| 5238 | struct nfs4_session *session = args->client->cl_session; |
| 5239 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 5240 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 5241 | |
| 5242 | if (mxrqst_sz == 0) |
| 5243 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5244 | if (mxresp_sz == 0) |
| 5245 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5246 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5247 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5248 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5249 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5250 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5251 | |
| 5252 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5253 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5254 | __func__, |
| 5255 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5256 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5257 | |
| 5258 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5259 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5260 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5261 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5262 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5263 | args->bc_attrs.max_reqs = 1; |
| 5264 | |
| 5265 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5266 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5267 | __func__, |
| 5268 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5269 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5270 | args->bc_attrs.max_reqs); |
| 5271 | } |
| 5272 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5273 | 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] | 5274 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5275 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5276 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5277 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5278 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5279 | return -EINVAL; |
| 5280 | /* |
| 5281 | * Our requested max_ops is the minimum we need; we're not |
| 5282 | * prepared to break up compounds into smaller pieces than that. |
| 5283 | * So, no point even trying to continue if the server won't |
| 5284 | * cooperate: |
| 5285 | */ |
| 5286 | if (rcvd->max_ops < sent->max_ops) |
| 5287 | return -EINVAL; |
| 5288 | if (rcvd->max_reqs == 0) |
| 5289 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame^] | 5290 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5291 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5292 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5293 | } |
| 5294 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5295 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5296 | { |
| 5297 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5298 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5299 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5300 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5301 | return -EINVAL; |
| 5302 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5303 | return -EINVAL; |
| 5304 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5305 | return -EINVAL; |
| 5306 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame^] | 5307 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5308 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame^] | 5309 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5310 | return -EINVAL; |
| 5311 | return 0; |
| 5312 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5313 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5314 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5315 | struct nfs4_session *session) |
| 5316 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5317 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5318 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5319 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5320 | if (ret) |
| 5321 | return ret; |
| 5322 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5323 | } |
| 5324 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5325 | static int _nfs4_proc_create_session(struct nfs_client *clp) |
| 5326 | { |
| 5327 | struct nfs4_session *session = clp->cl_session; |
| 5328 | struct nfs41_create_session_args args = { |
| 5329 | .client = clp, |
| 5330 | .cb_program = NFS4_CALLBACK, |
| 5331 | }; |
| 5332 | struct nfs41_create_session_res res = { |
| 5333 | .client = clp, |
| 5334 | }; |
| 5335 | struct rpc_message msg = { |
| 5336 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5337 | .rpc_argp = &args, |
| 5338 | .rpc_resp = &res, |
| 5339 | }; |
| 5340 | int status; |
| 5341 | |
| 5342 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5343 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5344 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5345 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5346 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5347 | if (!status) |
| 5348 | /* Verify the session's negotiated channel_attrs values */ |
| 5349 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5350 | if (!status) { |
| 5351 | /* Increment the clientid slot sequence id */ |
| 5352 | clp->cl_seqid++; |
| 5353 | } |
| 5354 | |
| 5355 | return status; |
| 5356 | } |
| 5357 | |
| 5358 | /* |
| 5359 | * Issues a CREATE_SESSION operation to the server. |
| 5360 | * It is the responsibility of the caller to verify the session is |
| 5361 | * expired before calling this routine. |
| 5362 | */ |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5363 | int nfs4_proc_create_session(struct nfs_client *clp) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5364 | { |
| 5365 | int status; |
| 5366 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5367 | struct nfs4_session *session = clp->cl_session; |
| 5368 | |
| 5369 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5370 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5371 | status = _nfs4_proc_create_session(clp); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5372 | if (status) |
| 5373 | goto out; |
| 5374 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5375 | /* Init or reset the session slot tables */ |
| 5376 | status = nfs4_setup_session_slot_tables(session); |
| 5377 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5378 | if (status) |
| 5379 | goto out; |
| 5380 | |
| 5381 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5382 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5383 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5384 | out: |
| 5385 | dprintk("<-- %s\n", __func__); |
| 5386 | return status; |
| 5387 | } |
| 5388 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5389 | /* |
| 5390 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5391 | * The caller must serialize access to this routine. |
| 5392 | */ |
| 5393 | int nfs4_proc_destroy_session(struct nfs4_session *session) |
| 5394 | { |
| 5395 | int status = 0; |
| 5396 | struct rpc_message msg; |
| 5397 | |
| 5398 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5399 | |
| 5400 | /* session is still being setup */ |
| 5401 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5402 | return status; |
| 5403 | |
| 5404 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; |
| 5405 | msg.rpc_argp = session; |
| 5406 | msg.rpc_resp = NULL; |
| 5407 | msg.rpc_cred = NULL; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5408 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5409 | |
| 5410 | if (status) |
| 5411 | printk(KERN_WARNING |
Weston Andros Adamson | f9fd2d9 | 2012-01-26 13:32:22 -0500 | [diff] [blame] | 5412 | "NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5413 | "Session has been destroyed regardless...\n", status); |
| 5414 | |
| 5415 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5416 | return status; |
| 5417 | } |
| 5418 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5419 | int nfs4_init_session(struct nfs_server *server) |
| 5420 | { |
| 5421 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5422 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5423 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5424 | int ret; |
| 5425 | |
| 5426 | if (!nfs4_has_session(clp)) |
| 5427 | return 0; |
| 5428 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5429 | session = clp->cl_session; |
| 5430 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5431 | return 0; |
| 5432 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5433 | rsize = server->rsize; |
| 5434 | if (rsize == 0) |
| 5435 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5436 | wsize = server->wsize; |
| 5437 | if (wsize == 0) |
| 5438 | wsize = NFS_MAX_FILE_IO_SIZE; |
| 5439 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5440 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5441 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5442 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5443 | ret = nfs4_recover_expired_lease(server); |
| 5444 | if (!ret) |
| 5445 | ret = nfs4_check_client_ready(clp); |
| 5446 | return ret; |
| 5447 | } |
| 5448 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5449 | int nfs4_init_ds_session(struct nfs_client *clp) |
| 5450 | { |
| 5451 | struct nfs4_session *session = clp->cl_session; |
| 5452 | int ret; |
| 5453 | |
| 5454 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5455 | return 0; |
| 5456 | |
| 5457 | ret = nfs4_client_recover_expired_lease(clp); |
| 5458 | if (!ret) |
| 5459 | /* Test for the DS role */ |
| 5460 | if (!is_ds_client(clp)) |
| 5461 | ret = -ENODEV; |
| 5462 | if (!ret) |
| 5463 | ret = nfs4_check_client_ready(clp); |
| 5464 | return ret; |
| 5465 | |
| 5466 | } |
| 5467 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 5468 | |
| 5469 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5470 | /* |
| 5471 | * Renew the cl_session lease. |
| 5472 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5473 | struct nfs4_sequence_data { |
| 5474 | struct nfs_client *clp; |
| 5475 | struct nfs4_sequence_args args; |
| 5476 | struct nfs4_sequence_res res; |
| 5477 | }; |
| 5478 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5479 | static void nfs41_sequence_release(void *data) |
| 5480 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5481 | struct nfs4_sequence_data *calldata = data; |
| 5482 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5483 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5484 | if (atomic_read(&clp->cl_count) > 1) |
| 5485 | nfs4_schedule_state_renewal(clp); |
| 5486 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5487 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5488 | } |
| 5489 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5490 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5491 | { |
| 5492 | switch(task->tk_status) { |
| 5493 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5494 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5495 | return -EAGAIN; |
| 5496 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5497 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5498 | } |
| 5499 | return 0; |
| 5500 | } |
| 5501 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5502 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5503 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5504 | struct nfs4_sequence_data *calldata = data; |
| 5505 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5506 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5507 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5508 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5509 | |
| 5510 | if (task->tk_status < 0) { |
| 5511 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5512 | if (atomic_read(&clp->cl_count) == 1) |
| 5513 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5514 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5515 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5516 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5517 | return; |
| 5518 | } |
| 5519 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5520 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5521 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5522 | dprintk("<-- %s\n", __func__); |
| 5523 | } |
| 5524 | |
| 5525 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5526 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5527 | struct nfs4_sequence_data *calldata = data; |
| 5528 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5529 | struct nfs4_sequence_args *args; |
| 5530 | struct nfs4_sequence_res *res; |
| 5531 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5532 | args = task->tk_msg.rpc_argp; |
| 5533 | res = task->tk_msg.rpc_resp; |
| 5534 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5535 | if (nfs41_setup_sequence(clp->cl_session, args, res, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5536 | return; |
| 5537 | rpc_call_start(task); |
| 5538 | } |
| 5539 | |
| 5540 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5541 | .rpc_call_done = nfs41_sequence_call_done, |
| 5542 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5543 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5544 | }; |
| 5545 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5546 | 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] | 5547 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5548 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5549 | struct rpc_message msg = { |
| 5550 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5551 | .rpc_cred = cred, |
| 5552 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5553 | struct rpc_task_setup task_setup_data = { |
| 5554 | .rpc_client = clp->cl_rpcclient, |
| 5555 | .rpc_message = &msg, |
| 5556 | .callback_ops = &nfs41_sequence_ops, |
| 5557 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5558 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5559 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5560 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5561 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5562 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5563 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5564 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5565 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5566 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5567 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5568 | msg.rpc_argp = &calldata->args; |
| 5569 | msg.rpc_resp = &calldata->res; |
| 5570 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5571 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5572 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5573 | return rpc_run_task(&task_setup_data); |
| 5574 | } |
| 5575 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5576 | 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] | 5577 | { |
| 5578 | struct rpc_task *task; |
| 5579 | int ret = 0; |
| 5580 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5581 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 5582 | return 0; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5583 | task = _nfs41_proc_sequence(clp, cred); |
| 5584 | if (IS_ERR(task)) |
| 5585 | ret = PTR_ERR(task); |
| 5586 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5587 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5588 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5589 | return ret; |
| 5590 | } |
| 5591 | |
| 5592 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5593 | { |
| 5594 | struct rpc_task *task; |
| 5595 | int ret; |
| 5596 | |
| 5597 | task = _nfs41_proc_sequence(clp, cred); |
| 5598 | if (IS_ERR(task)) { |
| 5599 | ret = PTR_ERR(task); |
| 5600 | goto out; |
| 5601 | } |
| 5602 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5603 | if (!ret) { |
| 5604 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5605 | |
| 5606 | if (task->tk_status == 0) |
| 5607 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5608 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5609 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5610 | rpc_put_task(task); |
| 5611 | out: |
| 5612 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5613 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5614 | } |
| 5615 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5616 | struct nfs4_reclaim_complete_data { |
| 5617 | struct nfs_client *clp; |
| 5618 | struct nfs41_reclaim_complete_args arg; |
| 5619 | struct nfs41_reclaim_complete_res res; |
| 5620 | }; |
| 5621 | |
| 5622 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5623 | { |
| 5624 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5625 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5626 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5627 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5628 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5629 | &calldata->res.seq_res, task)) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5630 | return; |
| 5631 | |
| 5632 | rpc_call_start(task); |
| 5633 | } |
| 5634 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5635 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5636 | { |
| 5637 | switch(task->tk_status) { |
| 5638 | case 0: |
| 5639 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5640 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5641 | break; |
| 5642 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5643 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5644 | /* fall through */ |
| 5645 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5646 | return -EAGAIN; |
| 5647 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5648 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5649 | } |
| 5650 | return 0; |
| 5651 | } |
| 5652 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5653 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5654 | { |
| 5655 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5656 | struct nfs_client *clp = calldata->clp; |
| 5657 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5658 | |
| 5659 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5660 | if (!nfs41_sequence_done(task, res)) |
| 5661 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5662 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5663 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5664 | rpc_restart_call_prepare(task); |
| 5665 | return; |
| 5666 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5667 | dprintk("<-- %s\n", __func__); |
| 5668 | } |
| 5669 | |
| 5670 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5671 | { |
| 5672 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5673 | |
| 5674 | kfree(calldata); |
| 5675 | } |
| 5676 | |
| 5677 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5678 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5679 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5680 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5681 | }; |
| 5682 | |
| 5683 | /* |
| 5684 | * Issue a global reclaim complete. |
| 5685 | */ |
| 5686 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5687 | { |
| 5688 | struct nfs4_reclaim_complete_data *calldata; |
| 5689 | struct rpc_task *task; |
| 5690 | struct rpc_message msg = { |
| 5691 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5692 | }; |
| 5693 | struct rpc_task_setup task_setup_data = { |
| 5694 | .rpc_client = clp->cl_rpcclient, |
| 5695 | .rpc_message = &msg, |
| 5696 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5697 | .flags = RPC_TASK_ASYNC, |
| 5698 | }; |
| 5699 | int status = -ENOMEM; |
| 5700 | |
| 5701 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5702 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5703 | if (calldata == NULL) |
| 5704 | goto out; |
| 5705 | calldata->clp = clp; |
| 5706 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5707 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5708 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5709 | msg.rpc_argp = &calldata->arg; |
| 5710 | msg.rpc_resp = &calldata->res; |
| 5711 | task_setup_data.callback_data = calldata; |
| 5712 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5713 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5714 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5715 | goto out; |
| 5716 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 5717 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5718 | if (status == 0) |
| 5719 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5720 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5721 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5722 | out: |
| 5723 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5724 | return status; |
| 5725 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5726 | |
| 5727 | static void |
| 5728 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 5729 | { |
| 5730 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5731 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5732 | |
| 5733 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5734 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 5735 | * right now covering the LAYOUTGET we are about to send. |
| 5736 | * However, that is not so catastrophic, and there seems |
| 5737 | * to be no way to prevent it completely. |
| 5738 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5739 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5740 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5741 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5742 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 5743 | NFS_I(lgp->args.inode)->layout, |
| 5744 | lgp->args.ctx->state)) { |
| 5745 | rpc_exit(task, NFS4_OK); |
| 5746 | return; |
| 5747 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5748 | rpc_call_start(task); |
| 5749 | } |
| 5750 | |
| 5751 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 5752 | { |
| 5753 | struct nfs4_layoutget *lgp = calldata; |
| 5754 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5755 | |
| 5756 | dprintk("--> %s\n", __func__); |
| 5757 | |
| 5758 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 5759 | return; |
| 5760 | |
| 5761 | switch (task->tk_status) { |
| 5762 | case 0: |
| 5763 | break; |
| 5764 | case -NFS4ERR_LAYOUTTRYLATER: |
| 5765 | case -NFS4ERR_RECALLCONFLICT: |
| 5766 | task->tk_status = -NFS4ERR_DELAY; |
| 5767 | /* Fall through */ |
| 5768 | default: |
| 5769 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5770 | rpc_restart_call_prepare(task); |
| 5771 | return; |
| 5772 | } |
| 5773 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5774 | dprintk("<-- %s\n", __func__); |
| 5775 | } |
| 5776 | |
| 5777 | static void nfs4_layoutget_release(void *calldata) |
| 5778 | { |
| 5779 | struct nfs4_layoutget *lgp = calldata; |
| 5780 | |
| 5781 | dprintk("--> %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5782 | put_nfs_open_context(lgp->args.ctx); |
| 5783 | kfree(calldata); |
| 5784 | dprintk("<-- %s\n", __func__); |
| 5785 | } |
| 5786 | |
| 5787 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 5788 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 5789 | .rpc_call_done = nfs4_layoutget_done, |
| 5790 | .rpc_release = nfs4_layoutget_release, |
| 5791 | }; |
| 5792 | |
| 5793 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) |
| 5794 | { |
| 5795 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5796 | struct rpc_task *task; |
| 5797 | struct rpc_message msg = { |
| 5798 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 5799 | .rpc_argp = &lgp->args, |
| 5800 | .rpc_resp = &lgp->res, |
| 5801 | }; |
| 5802 | struct rpc_task_setup task_setup_data = { |
| 5803 | .rpc_client = server->client, |
| 5804 | .rpc_message = &msg, |
| 5805 | .callback_ops = &nfs4_layoutget_call_ops, |
| 5806 | .callback_data = lgp, |
| 5807 | .flags = RPC_TASK_ASYNC, |
| 5808 | }; |
| 5809 | int status = 0; |
| 5810 | |
| 5811 | dprintk("--> %s\n", __func__); |
| 5812 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 5813 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5814 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5815 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5816 | task = rpc_run_task(&task_setup_data); |
| 5817 | if (IS_ERR(task)) |
| 5818 | return PTR_ERR(task); |
| 5819 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5820 | if (status == 0) |
| 5821 | status = task->tk_status; |
| 5822 | if (status == 0) |
| 5823 | status = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5824 | rpc_put_task(task); |
| 5825 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5826 | return status; |
| 5827 | } |
| 5828 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5829 | static void |
| 5830 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 5831 | { |
| 5832 | struct nfs4_layoutreturn *lrp = calldata; |
| 5833 | |
| 5834 | dprintk("--> %s\n", __func__); |
| 5835 | if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5836 | &lrp->res.seq_res, task)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5837 | return; |
| 5838 | rpc_call_start(task); |
| 5839 | } |
| 5840 | |
| 5841 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 5842 | { |
| 5843 | struct nfs4_layoutreturn *lrp = calldata; |
| 5844 | struct nfs_server *server; |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 5845 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5846 | |
| 5847 | dprintk("--> %s\n", __func__); |
| 5848 | |
| 5849 | if (!nfs4_sequence_done(task, &lrp->res.seq_res)) |
| 5850 | return; |
| 5851 | |
| 5852 | server = NFS_SERVER(lrp->args.inode); |
| 5853 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5854 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5855 | return; |
| 5856 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 5857 | spin_lock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5858 | if (task->tk_status == 0) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5859 | if (lrp->res.lrs_present) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5860 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5861 | } else |
| 5862 | BUG_ON(!list_empty(&lo->plh_segs)); |
| 5863 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 5864 | lo->plh_block_lgets--; |
| 5865 | spin_unlock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5866 | dprintk("<-- %s\n", __func__); |
| 5867 | } |
| 5868 | |
| 5869 | static void nfs4_layoutreturn_release(void *calldata) |
| 5870 | { |
| 5871 | struct nfs4_layoutreturn *lrp = calldata; |
| 5872 | |
| 5873 | dprintk("--> %s\n", __func__); |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 5874 | put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5875 | kfree(calldata); |
| 5876 | dprintk("<-- %s\n", __func__); |
| 5877 | } |
| 5878 | |
| 5879 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 5880 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 5881 | .rpc_call_done = nfs4_layoutreturn_done, |
| 5882 | .rpc_release = nfs4_layoutreturn_release, |
| 5883 | }; |
| 5884 | |
| 5885 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 5886 | { |
| 5887 | struct rpc_task *task; |
| 5888 | struct rpc_message msg = { |
| 5889 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 5890 | .rpc_argp = &lrp->args, |
| 5891 | .rpc_resp = &lrp->res, |
| 5892 | }; |
| 5893 | struct rpc_task_setup task_setup_data = { |
| 5894 | .rpc_client = lrp->clp->cl_rpcclient, |
| 5895 | .rpc_message = &msg, |
| 5896 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 5897 | .callback_data = lrp, |
| 5898 | }; |
| 5899 | int status; |
| 5900 | |
| 5901 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5902 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5903 | task = rpc_run_task(&task_setup_data); |
| 5904 | if (IS_ERR(task)) |
| 5905 | return PTR_ERR(task); |
| 5906 | status = task->tk_status; |
| 5907 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5908 | rpc_put_task(task); |
| 5909 | return status; |
| 5910 | } |
| 5911 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 5912 | /* |
| 5913 | * Retrieve the list of Data Server devices from the MDS. |
| 5914 | */ |
| 5915 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 5916 | const struct nfs_fh *fh, |
| 5917 | struct pnfs_devicelist *devlist) |
| 5918 | { |
| 5919 | struct nfs4_getdevicelist_args args = { |
| 5920 | .fh = fh, |
| 5921 | .layoutclass = server->pnfs_curr_ld->id, |
| 5922 | }; |
| 5923 | struct nfs4_getdevicelist_res res = { |
| 5924 | .devlist = devlist, |
| 5925 | }; |
| 5926 | struct rpc_message msg = { |
| 5927 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 5928 | .rpc_argp = &args, |
| 5929 | .rpc_resp = &res, |
| 5930 | }; |
| 5931 | int status; |
| 5932 | |
| 5933 | dprintk("--> %s\n", __func__); |
| 5934 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 5935 | &res.seq_res, 0); |
| 5936 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5937 | return status; |
| 5938 | } |
| 5939 | |
| 5940 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 5941 | const struct nfs_fh *fh, |
| 5942 | struct pnfs_devicelist *devlist) |
| 5943 | { |
| 5944 | struct nfs4_exception exception = { }; |
| 5945 | int err; |
| 5946 | |
| 5947 | do { |
| 5948 | err = nfs4_handle_exception(server, |
| 5949 | _nfs4_getdevicelist(server, fh, devlist), |
| 5950 | &exception); |
| 5951 | } while (exception.retry); |
| 5952 | |
| 5953 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 5954 | err, devlist->num_devs); |
| 5955 | |
| 5956 | return err; |
| 5957 | } |
| 5958 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 5959 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5960 | static int |
| 5961 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5962 | { |
| 5963 | struct nfs4_getdeviceinfo_args args = { |
| 5964 | .pdev = pdev, |
| 5965 | }; |
| 5966 | struct nfs4_getdeviceinfo_res res = { |
| 5967 | .pdev = pdev, |
| 5968 | }; |
| 5969 | struct rpc_message msg = { |
| 5970 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 5971 | .rpc_argp = &args, |
| 5972 | .rpc_resp = &res, |
| 5973 | }; |
| 5974 | int status; |
| 5975 | |
| 5976 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5977 | 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] | 5978 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5979 | |
| 5980 | return status; |
| 5981 | } |
| 5982 | |
| 5983 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5984 | { |
| 5985 | struct nfs4_exception exception = { }; |
| 5986 | int err; |
| 5987 | |
| 5988 | do { |
| 5989 | err = nfs4_handle_exception(server, |
| 5990 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 5991 | &exception); |
| 5992 | } while (exception.retry); |
| 5993 | return err; |
| 5994 | } |
| 5995 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 5996 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5997 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 5998 | { |
| 5999 | struct nfs4_layoutcommit_data *data = calldata; |
| 6000 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6001 | |
| 6002 | if (nfs4_setup_sequence(server, &data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6003 | &data->res.seq_res, task)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6004 | return; |
| 6005 | rpc_call_start(task); |
| 6006 | } |
| 6007 | |
| 6008 | static void |
| 6009 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6010 | { |
| 6011 | struct nfs4_layoutcommit_data *data = calldata; |
| 6012 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6013 | |
| 6014 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6015 | return; |
| 6016 | |
| 6017 | switch (task->tk_status) { /* Just ignore these failures */ |
| 6018 | case NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6019 | case NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6020 | case NFS4ERR_BADLAYOUT: /* no layout */ |
| 6021 | case NFS4ERR_GRACE: /* loca_recalim always false */ |
| 6022 | task->tk_status = 0; |
| 6023 | } |
| 6024 | |
| 6025 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6026 | rpc_restart_call_prepare(task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6027 | return; |
| 6028 | } |
| 6029 | |
| 6030 | if (task->tk_status == 0) |
| 6031 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6032 | data->res.fattr); |
| 6033 | } |
| 6034 | |
| 6035 | static void nfs4_layoutcommit_release(void *calldata) |
| 6036 | { |
| 6037 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6038 | struct pnfs_layout_segment *lseg, *tmp; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6039 | unsigned long *bitlock = &NFS_I(data->args.inode)->flags; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6040 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6041 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6042 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6043 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 6044 | list_del_init(&lseg->pls_lc_list); |
| 6045 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 6046 | &lseg->pls_flags)) |
| 6047 | put_lseg(lseg); |
| 6048 | } |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6049 | |
| 6050 | clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); |
| 6051 | smp_mb__after_clear_bit(); |
| 6052 | wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING); |
| 6053 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6054 | put_rpccred(data->cred); |
| 6055 | kfree(data); |
| 6056 | } |
| 6057 | |
| 6058 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6059 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6060 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6061 | .rpc_release = nfs4_layoutcommit_release, |
| 6062 | }; |
| 6063 | |
| 6064 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6065 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6066 | { |
| 6067 | struct rpc_message msg = { |
| 6068 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6069 | .rpc_argp = &data->args, |
| 6070 | .rpc_resp = &data->res, |
| 6071 | .rpc_cred = data->cred, |
| 6072 | }; |
| 6073 | struct rpc_task_setup task_setup_data = { |
| 6074 | .task = &data->task, |
| 6075 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6076 | .rpc_message = &msg, |
| 6077 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6078 | .callback_data = data, |
| 6079 | .flags = RPC_TASK_ASYNC, |
| 6080 | }; |
| 6081 | struct rpc_task *task; |
| 6082 | int status = 0; |
| 6083 | |
| 6084 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6085 | "lbw: %llu inode %lu\n", |
| 6086 | data->task.tk_pid, sync, |
| 6087 | data->args.lastbytewritten, |
| 6088 | data->args.inode->i_ino); |
| 6089 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6090 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6091 | task = rpc_run_task(&task_setup_data); |
| 6092 | if (IS_ERR(task)) |
| 6093 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6094 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6095 | goto out; |
| 6096 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6097 | if (status != 0) |
| 6098 | goto out; |
| 6099 | status = task->tk_status; |
| 6100 | out: |
| 6101 | dprintk("%s: status %d\n", __func__, status); |
| 6102 | rpc_put_task(task); |
| 6103 | return status; |
| 6104 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6105 | |
| 6106 | static int |
| 6107 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6108 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6109 | { |
| 6110 | struct nfs41_secinfo_no_name_args args = { |
| 6111 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6112 | }; |
| 6113 | struct nfs4_secinfo_res res = { |
| 6114 | .flavors = flavors, |
| 6115 | }; |
| 6116 | struct rpc_message msg = { |
| 6117 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6118 | .rpc_argp = &args, |
| 6119 | .rpc_resp = &res, |
| 6120 | }; |
| 6121 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6122 | } |
| 6123 | |
| 6124 | static int |
| 6125 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6126 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6127 | { |
| 6128 | struct nfs4_exception exception = { }; |
| 6129 | int err; |
| 6130 | do { |
| 6131 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6132 | switch (err) { |
| 6133 | case 0: |
| 6134 | case -NFS4ERR_WRONGSEC: |
| 6135 | case -NFS4ERR_NOTSUPP: |
| 6136 | break; |
| 6137 | default: |
| 6138 | err = nfs4_handle_exception(server, err, &exception); |
| 6139 | } |
| 6140 | } while (exception.retry); |
| 6141 | return err; |
| 6142 | } |
| 6143 | |
| 6144 | static int |
| 6145 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6146 | struct nfs_fsinfo *info) |
| 6147 | { |
| 6148 | int err; |
| 6149 | struct page *page; |
| 6150 | rpc_authflavor_t flavor; |
| 6151 | struct nfs4_secinfo_flavors *flavors; |
| 6152 | |
| 6153 | page = alloc_page(GFP_KERNEL); |
| 6154 | if (!page) { |
| 6155 | err = -ENOMEM; |
| 6156 | goto out; |
| 6157 | } |
| 6158 | |
| 6159 | flavors = page_address(page); |
| 6160 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6161 | |
| 6162 | /* |
| 6163 | * Fall back on "guess and check" method if |
| 6164 | * the server doesn't support SECINFO_NO_NAME |
| 6165 | */ |
| 6166 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6167 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6168 | goto out_freepage; |
| 6169 | } |
| 6170 | if (err) |
| 6171 | goto out_freepage; |
| 6172 | |
| 6173 | flavor = nfs_find_best_sec(flavors); |
| 6174 | if (err == 0) |
| 6175 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6176 | |
| 6177 | out_freepage: |
| 6178 | put_page(page); |
| 6179 | if (err == -EACCES) |
| 6180 | return -EPERM; |
| 6181 | out: |
| 6182 | return err; |
| 6183 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6184 | |
| 6185 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6186 | { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6187 | int status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6188 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6189 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6190 | }; |
| 6191 | struct nfs41_test_stateid_res res; |
| 6192 | struct rpc_message msg = { |
| 6193 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6194 | .rpc_argp = &args, |
| 6195 | .rpc_resp = &res, |
| 6196 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6197 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6198 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6199 | status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
| 6200 | |
| 6201 | if (status == NFS_OK) |
| 6202 | return res.status; |
| 6203 | return status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6204 | } |
| 6205 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6206 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6207 | { |
| 6208 | struct nfs4_exception exception = { }; |
| 6209 | int err; |
| 6210 | do { |
| 6211 | err = nfs4_handle_exception(server, |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6212 | _nfs41_test_stateid(server, stateid), |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6213 | &exception); |
| 6214 | } while (exception.retry); |
| 6215 | return err; |
| 6216 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6217 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6218 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6219 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6220 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6221 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6222 | }; |
| 6223 | struct nfs41_free_stateid_res res; |
| 6224 | struct rpc_message msg = { |
| 6225 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6226 | .rpc_argp = &args, |
| 6227 | .rpc_resp = &res, |
| 6228 | }; |
| 6229 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6230 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6231 | return nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6232 | } |
| 6233 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6234 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6235 | { |
| 6236 | struct nfs4_exception exception = { }; |
| 6237 | int err; |
| 6238 | do { |
| 6239 | err = nfs4_handle_exception(server, |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6240 | _nfs4_free_stateid(server, stateid), |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6241 | &exception); |
| 6242 | } while (exception.retry); |
| 6243 | return err; |
| 6244 | } |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6245 | #endif /* CONFIG_NFS_V4_1 */ |
| 6246 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6247 | struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6248 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6249 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6250 | .recover_open = nfs4_open_reclaim, |
| 6251 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6252 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6253 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6254 | }; |
| 6255 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6256 | #if defined(CONFIG_NFS_V4_1) |
| 6257 | struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
| 6258 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6259 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6260 | .recover_open = nfs4_open_reclaim, |
| 6261 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6262 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6263 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6264 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6265 | }; |
| 6266 | #endif /* CONFIG_NFS_V4_1 */ |
| 6267 | |
| 6268 | struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6269 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6270 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6271 | .recover_open = nfs4_open_expired, |
| 6272 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6273 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6274 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6275 | }; |
| 6276 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6277 | #if defined(CONFIG_NFS_V4_1) |
| 6278 | struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
| 6279 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6280 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6281 | .recover_open = nfs41_open_expired, |
| 6282 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6283 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6284 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6285 | }; |
| 6286 | #endif /* CONFIG_NFS_V4_1 */ |
| 6287 | |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6288 | struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
| 6289 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6290 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6291 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6292 | }; |
| 6293 | |
| 6294 | #if defined(CONFIG_NFS_V4_1) |
| 6295 | struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
| 6296 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6297 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6298 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6299 | }; |
| 6300 | #endif |
| 6301 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6302 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6303 | .minor_version = 0, |
| 6304 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6305 | .validate_stateid = nfs4_validate_delegation_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6306 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6307 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6308 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6309 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6310 | }; |
| 6311 | |
| 6312 | #if defined(CONFIG_NFS_V4_1) |
| 6313 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6314 | .minor_version = 1, |
| 6315 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6316 | .validate_stateid = nfs41_validate_delegation_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6317 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6318 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6319 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6320 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6321 | }; |
| 6322 | #endif |
| 6323 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6324 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6325 | [0] = &nfs_v4_0_minor_ops, |
| 6326 | #if defined(CONFIG_NFS_V4_1) |
| 6327 | [1] = &nfs_v4_1_minor_ops, |
| 6328 | #endif |
| 6329 | }; |
| 6330 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6331 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6332 | .permission = nfs_permission, |
| 6333 | .getattr = nfs_getattr, |
| 6334 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6335 | .getxattr = generic_getxattr, |
| 6336 | .setxattr = generic_setxattr, |
| 6337 | .listxattr = generic_listxattr, |
| 6338 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6339 | }; |
| 6340 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6341 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6342 | .version = 4, /* protocol version */ |
| 6343 | .dentry_ops = &nfs4_dentry_operations, |
| 6344 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6345 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 6346 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6347 | .getroot = nfs4_proc_get_root, |
| 6348 | .getattr = nfs4_proc_getattr, |
| 6349 | .setattr = nfs4_proc_setattr, |
| 6350 | .lookup = nfs4_proc_lookup, |
| 6351 | .access = nfs4_proc_access, |
| 6352 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6353 | .create = nfs4_proc_create, |
| 6354 | .remove = nfs4_proc_remove, |
| 6355 | .unlink_setup = nfs4_proc_unlink_setup, |
| 6356 | .unlink_done = nfs4_proc_unlink_done, |
| 6357 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6358 | .rename_setup = nfs4_proc_rename_setup, |
| 6359 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6360 | .link = nfs4_proc_link, |
| 6361 | .symlink = nfs4_proc_symlink, |
| 6362 | .mkdir = nfs4_proc_mkdir, |
| 6363 | .rmdir = nfs4_proc_remove, |
| 6364 | .readdir = nfs4_proc_readdir, |
| 6365 | .mknod = nfs4_proc_mknod, |
| 6366 | .statfs = nfs4_proc_statfs, |
| 6367 | .fsinfo = nfs4_proc_fsinfo, |
| 6368 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6369 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6370 | .decode_dirent = nfs4_decode_dirent, |
| 6371 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6372 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6373 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6374 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6375 | .commit_setup = nfs4_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6376 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6377 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6378 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6379 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6380 | .open_context = nfs4_atomic_open, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6381 | .init_client = nfs4_init_client, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6382 | .secinfo = nfs4_proc_secinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6383 | }; |
| 6384 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6385 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6386 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6387 | .list = nfs4_xattr_list_nfs4_acl, |
| 6388 | .get = nfs4_xattr_get_nfs4_acl, |
| 6389 | .set = nfs4_xattr_set_nfs4_acl, |
| 6390 | }; |
| 6391 | |
| 6392 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6393 | &nfs4_xattr_nfs4_acl_handler, |
| 6394 | NULL |
| 6395 | }; |
| 6396 | |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 6397 | module_param(max_session_slots, ushort, 0644); |
| 6398 | MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 " |
| 6399 | "requests the client will negotiate"); |
| 6400 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6401 | /* |
| 6402 | * Local variables: |
| 6403 | * c-basic-offset: 8 |
| 6404 | * End: |
| 6405 | */ |