Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 42 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/sunrpc/clnt.h> |
| 44 | #include <linux/nfs.h> |
| 45 | #include <linux/nfs4.h> |
| 46 | #include <linux/nfs_fs.h> |
| 47 | #include <linux/nfs_page.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 49 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 50 | #include <linux/module.h> |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 51 | #include <linux/sunrpc/bc_xprt.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 52 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 53 | #include <linux/utsname.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 55 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 57 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 58 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 59 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 60 | #include "pnfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 63 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 64 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 66 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 67 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 68 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 69 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 70 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 71 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 73 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 74 | static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
| 75 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 76 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 77 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 78 | struct nfs4_state *state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 81 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 83 | if (err >= -1000) |
| 84 | return err; |
| 85 | switch (err) { |
| 86 | case -NFS4ERR_RESOURCE: |
| 87 | return -EREMOTEIO; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 88 | case -NFS4ERR_BADOWNER: |
| 89 | case -NFS4ERR_BADNAME: |
| 90 | return -EINVAL; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 91 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 93 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 94 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 96 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /* |
| 100 | * This is our standard bitmap for GETATTR requests. |
| 101 | */ |
| 102 | const u32 nfs4_fattr_bitmap[2] = { |
| 103 | FATTR4_WORD0_TYPE |
| 104 | | FATTR4_WORD0_CHANGE |
| 105 | | FATTR4_WORD0_SIZE |
| 106 | | FATTR4_WORD0_FSID |
| 107 | | FATTR4_WORD0_FILEID, |
| 108 | FATTR4_WORD1_MODE |
| 109 | | FATTR4_WORD1_NUMLINKS |
| 110 | | FATTR4_WORD1_OWNER |
| 111 | | FATTR4_WORD1_OWNER_GROUP |
| 112 | | FATTR4_WORD1_RAWDEV |
| 113 | | FATTR4_WORD1_SPACE_USED |
| 114 | | FATTR4_WORD1_TIME_ACCESS |
| 115 | | FATTR4_WORD1_TIME_METADATA |
| 116 | | FATTR4_WORD1_TIME_MODIFY |
| 117 | }; |
| 118 | |
| 119 | const u32 nfs4_statfs_bitmap[2] = { |
| 120 | FATTR4_WORD0_FILES_AVAIL |
| 121 | | FATTR4_WORD0_FILES_FREE |
| 122 | | FATTR4_WORD0_FILES_TOTAL, |
| 123 | FATTR4_WORD1_SPACE_AVAIL |
| 124 | | FATTR4_WORD1_SPACE_FREE |
| 125 | | FATTR4_WORD1_SPACE_TOTAL |
| 126 | }; |
| 127 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 128 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | FATTR4_WORD0_MAXLINK |
| 130 | | FATTR4_WORD0_MAXNAME, |
| 131 | 0 |
| 132 | }; |
| 133 | |
| 134 | const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE |
| 135 | | FATTR4_WORD0_MAXREAD |
| 136 | | FATTR4_WORD0_MAXWRITE |
| 137 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 138 | FATTR4_WORD1_TIME_DELTA |
Andy Adamson | 504913f | 2010-10-20 00:17:57 -0400 | [diff] [blame] | 139 | | FATTR4_WORD1_FS_LAYOUT_TYPES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | }; |
| 141 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 142 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 143 | FATTR4_WORD0_TYPE |
| 144 | | FATTR4_WORD0_CHANGE |
| 145 | | FATTR4_WORD0_SIZE |
| 146 | | FATTR4_WORD0_FSID |
| 147 | | FATTR4_WORD0_FILEID |
| 148 | | FATTR4_WORD0_FS_LOCATIONS, |
| 149 | FATTR4_WORD1_MODE |
| 150 | | FATTR4_WORD1_NUMLINKS |
| 151 | | FATTR4_WORD1_OWNER |
| 152 | | FATTR4_WORD1_OWNER_GROUP |
| 153 | | FATTR4_WORD1_RAWDEV |
| 154 | | FATTR4_WORD1_SPACE_USED |
| 155 | | FATTR4_WORD1_TIME_ACCESS |
| 156 | | FATTR4_WORD1_TIME_METADATA |
| 157 | | FATTR4_WORD1_TIME_MODIFY |
| 158 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 159 | }; |
| 160 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 161 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | struct nfs4_readdir_arg *readdir) |
| 163 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 164 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
| 166 | BUG_ON(readdir->count < 80); |
| 167 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 168 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 170 | return; |
| 171 | } |
| 172 | |
| 173 | readdir->cookie = 0; |
| 174 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 175 | if (cookie == 2) |
| 176 | return; |
| 177 | |
| 178 | /* |
| 179 | * NFSv4 servers do not return entries for '.' and '..' |
| 180 | * Therefore, we fake these entries here. We let '.' |
| 181 | * have cookie 0 and '..' have cookie 1. Note that |
| 182 | * when talking to the server, we always send cookie 0 |
| 183 | * instead of 1 or 2. |
| 184 | */ |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 185 | start = p = kmap_atomic(*readdir->pages, KM_USER0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
| 187 | if (cookie == 0) { |
| 188 | *p++ = xdr_one; /* next */ |
| 189 | *p++ = xdr_zero; /* cookie, first word */ |
| 190 | *p++ = xdr_one; /* cookie, second word */ |
| 191 | *p++ = xdr_one; /* entry len */ |
| 192 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 193 | p++; |
| 194 | *p++ = xdr_one; /* bitmap length */ |
| 195 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 196 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 197 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | *p++ = xdr_one; /* next */ |
| 201 | *p++ = xdr_zero; /* cookie, first word */ |
| 202 | *p++ = xdr_two; /* cookie, second word */ |
| 203 | *p++ = xdr_two; /* entry len */ |
| 204 | memcpy(p, "..\0\0", 4); /* entry */ |
| 205 | p++; |
| 206 | *p++ = xdr_one; /* bitmap length */ |
| 207 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 208 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 209 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
| 211 | readdir->pgbase = (char *)p - (char *)start; |
| 212 | readdir->count -= readdir->pgbase; |
| 213 | kunmap_atomic(start, KM_USER0); |
| 214 | } |
| 215 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 216 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 217 | { |
| 218 | int res; |
| 219 | |
| 220 | might_sleep(); |
| 221 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 222 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 223 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 224 | return res; |
| 225 | } |
| 226 | |
| 227 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 228 | { |
| 229 | int res = 0; |
| 230 | |
| 231 | might_sleep(); |
| 232 | |
| 233 | if (*timeout <= 0) |
| 234 | *timeout = NFS4_POLL_RETRY_MIN; |
| 235 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 236 | *timeout = NFS4_POLL_RETRY_MAX; |
| 237 | schedule_timeout_killable(*timeout); |
| 238 | if (fatal_signal_pending(current)) |
| 239 | res = -ERESTARTSYS; |
| 240 | *timeout <<= 1; |
| 241 | return res; |
| 242 | } |
| 243 | |
| 244 | /* This is the error handling routine for processes that are allowed |
| 245 | * to sleep. |
| 246 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame^] | 247 | 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] | 248 | { |
| 249 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 250 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 251 | int ret = errorcode; |
| 252 | |
| 253 | exception->retry = 0; |
| 254 | switch(errorcode) { |
| 255 | case 0: |
| 256 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 257 | case -NFS4ERR_ADMIN_REVOKED: |
| 258 | case -NFS4ERR_BAD_STATEID: |
| 259 | case -NFS4ERR_OPENMODE: |
| 260 | if (state == NULL) |
| 261 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 262 | nfs4_schedule_stateid_recovery(server, state); |
| 263 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 264 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 265 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 266 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 267 | nfs4_schedule_lease_recovery(clp); |
| 268 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 269 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 270 | case -NFS4ERR_BADSESSION: |
| 271 | case -NFS4ERR_BADSLOT: |
| 272 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 273 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 274 | case -NFS4ERR_DEADSESSION: |
| 275 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 276 | case -NFS4ERR_SEQ_MISORDERED: |
| 277 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 278 | errorcode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 279 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 280 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 281 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 282 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 283 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 284 | if (exception->timeout > HZ) { |
| 285 | /* We have retried a decent amount, time to |
| 286 | * fail |
| 287 | */ |
| 288 | ret = -EBUSY; |
| 289 | break; |
| 290 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 291 | case -NFS4ERR_GRACE: |
| 292 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 293 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 294 | ret = nfs4_delay(server->client, &exception->timeout); |
| 295 | if (ret != 0) |
| 296 | break; |
| 297 | case -NFS4ERR_OLD_STATEID: |
| 298 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame^] | 299 | break; |
| 300 | case -NFS4ERR_BADOWNER: |
| 301 | /* The following works around a Linux server bug! */ |
| 302 | case -NFS4ERR_BADNAME: |
| 303 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 304 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 305 | exception->retry = 1; |
| 306 | printk(KERN_WARNING "NFS: v4 server %s " |
| 307 | "does not accept raw " |
| 308 | "uid/gids. " |
| 309 | "Reenabling the idmapper.\n", |
| 310 | server->nfs_client->cl_hostname); |
| 311 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 312 | } |
| 313 | /* We failed to handle the error */ |
| 314 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 315 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 316 | ret = nfs4_wait_clnt_recover(clp); |
| 317 | if (ret == 0) |
| 318 | exception->retry = 1; |
| 319 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 323 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | spin_lock(&clp->cl_lock); |
| 326 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 327 | clp->cl_last_renewal = timestamp; |
| 328 | spin_unlock(&clp->cl_lock); |
| 329 | } |
| 330 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 331 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 332 | { |
| 333 | do_renew_lease(server->nfs_client, timestamp); |
| 334 | } |
| 335 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 336 | #if defined(CONFIG_NFS_V4_1) |
| 337 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 338 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 339 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 340 | * |
| 341 | * freeing a slot is trivially done by clearing its respective bit |
| 342 | * in the bitmap. |
| 343 | * If the freed slotid equals highest_used_slotid we want to update it |
| 344 | * so that the server would be able to size down the slot table if needed, |
| 345 | * otherwise we know that the highest_used_slotid is still in use. |
| 346 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 347 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 348 | * highest slotid in use. |
| 349 | * If none found, highest_used_slotid is set to -1. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 350 | * |
| 351 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 352 | */ |
| 353 | static void |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 354 | nfs4_free_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *free_slot) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 355 | { |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 356 | int free_slotid = free_slot - tbl->slots; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 357 | int slotid = free_slotid; |
| 358 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 359 | BUG_ON(slotid < 0 || slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 360 | /* clear used bit in bitmap */ |
| 361 | __clear_bit(slotid, tbl->used_slots); |
| 362 | |
| 363 | /* update highest_used_slotid when it is freed */ |
| 364 | if (slotid == tbl->highest_used_slotid) { |
| 365 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 366 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 367 | tbl->highest_used_slotid = slotid; |
| 368 | else |
| 369 | tbl->highest_used_slotid = -1; |
| 370 | } |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 371 | dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__, |
| 372 | free_slotid, tbl->highest_used_slotid); |
| 373 | } |
| 374 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 375 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 376 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 377 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 378 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 379 | { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 380 | struct rpc_task *task; |
| 381 | |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 382 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 383 | task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq); |
| 384 | if (task) |
| 385 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 386 | return; |
| 387 | } |
| 388 | |
| 389 | if (ses->fc_slot_table.highest_used_slotid != -1) |
| 390 | return; |
| 391 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 392 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 393 | complete(&ses->fc_slot_table.complete); |
| 394 | } |
| 395 | |
| 396 | /* |
| 397 | * Signal state manager thread if session back channel is drained |
| 398 | */ |
| 399 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 400 | { |
| 401 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
| 402 | ses->bc_slot_table.highest_used_slotid != -1) |
| 403 | return; |
| 404 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 405 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 406 | } |
| 407 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 408 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 409 | { |
| 410 | struct nfs4_slot_table *tbl; |
| 411 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 412 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 413 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 414 | /* just wake up the next guy waiting since |
| 415 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 416 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 417 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 418 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 419 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 420 | spin_lock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 421 | nfs4_free_slot(tbl, res->sr_slot); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 422 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 423 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 424 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 425 | } |
| 426 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 427 | 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] | 428 | { |
| 429 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 430 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 431 | |
| 432 | /* |
| 433 | * sr_status remains 1 if an RPC level error occurred. The server |
| 434 | * may or may not have processed the sequence operation.. |
| 435 | * Proceed as if the server received and processed the sequence |
| 436 | * operation. |
| 437 | */ |
| 438 | if (res->sr_status == 1) |
| 439 | res->sr_status = NFS_OK; |
| 440 | |
| 441 | /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 442 | if (!res->sr_slot) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 443 | goto out; |
| 444 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 445 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 446 | switch (res->sr_status) { |
| 447 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 448 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 449 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 450 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 451 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 452 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 453 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 454 | if (res->sr_status_flags != 0) |
| 455 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 456 | break; |
| 457 | case -NFS4ERR_DELAY: |
| 458 | /* The server detected a resend of the RPC call and |
| 459 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 460 | * of RFC5661. |
| 461 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 462 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 463 | __func__, |
| 464 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 465 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 466 | goto out_retry; |
| 467 | default: |
| 468 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 469 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 470 | } |
| 471 | out: |
| 472 | /* The session may be reset by one of the error handlers. */ |
| 473 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 474 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 475 | return 1; |
| 476 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 477 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 478 | goto out; |
| 479 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 480 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 481 | } |
| 482 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 483 | static int nfs4_sequence_done(struct rpc_task *task, |
| 484 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 485 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 486 | if (res->sr_session == NULL) |
| 487 | return 1; |
| 488 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 489 | } |
| 490 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 491 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 492 | * nfs4_find_slot - efficiently look for a free slot |
| 493 | * |
| 494 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 495 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 496 | * and respectively set up the sequence operation args. |
| 497 | * The slot number is returned if found, or NFS4_MAX_SLOT_TABLE otherwise. |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 498 | * |
| 499 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 500 | */ |
| 501 | static u8 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 502 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 503 | { |
| 504 | int slotid; |
| 505 | u8 ret_id = NFS4_MAX_SLOT_TABLE; |
| 506 | BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE); |
| 507 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 508 | dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n", |
| 509 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 510 | tbl->max_slots); |
| 511 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 512 | if (slotid >= tbl->max_slots) |
| 513 | goto out; |
| 514 | __set_bit(slotid, tbl->used_slots); |
| 515 | if (slotid > tbl->highest_used_slotid) |
| 516 | tbl->highest_used_slotid = slotid; |
| 517 | ret_id = slotid; |
| 518 | out: |
| 519 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 520 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 521 | return ret_id; |
| 522 | } |
| 523 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 524 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 525 | struct nfs4_sequence_args *args, |
| 526 | struct nfs4_sequence_res *res, |
| 527 | int cache_reply, |
| 528 | struct rpc_task *task) |
| 529 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 530 | struct nfs4_slot *slot; |
| 531 | struct nfs4_slot_table *tbl; |
| 532 | u8 slotid; |
| 533 | |
| 534 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 535 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 536 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 537 | return 0; |
| 538 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 539 | tbl = &session->fc_slot_table; |
| 540 | |
| 541 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 542 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 543 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 544 | /* |
| 545 | * The state manager will wait until the slot table is empty. |
| 546 | * Schedule the reset thread |
| 547 | */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 548 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 549 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 550 | dprintk("%s Schedule Session Reset\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 551 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 552 | } |
| 553 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 554 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 555 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 556 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 557 | spin_unlock(&tbl->slot_tbl_lock); |
| 558 | dprintk("%s enforce FIFO order\n", __func__); |
| 559 | return -EAGAIN; |
| 560 | } |
| 561 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 562 | slotid = nfs4_find_slot(tbl); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 563 | if (slotid == NFS4_MAX_SLOT_TABLE) { |
| 564 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 565 | spin_unlock(&tbl->slot_tbl_lock); |
| 566 | dprintk("<-- %s: no free slots\n", __func__); |
| 567 | return -EAGAIN; |
| 568 | } |
| 569 | spin_unlock(&tbl->slot_tbl_lock); |
| 570 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 571 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 572 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 573 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 574 | args->sa_slotid = slotid; |
| 575 | args->sa_cache_this = cache_reply; |
| 576 | |
| 577 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 578 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 579 | res->sr_session = session; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 580 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 581 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 582 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 583 | /* |
| 584 | * sr_status is only set in decode_sequence, and so will remain |
| 585 | * set to 1 if an rpc level failure occurs. |
| 586 | */ |
| 587 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 588 | return 0; |
| 589 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 590 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 591 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 592 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 593 | struct nfs4_sequence_args *args, |
| 594 | struct nfs4_sequence_res *res, |
| 595 | int cache_reply, |
| 596 | struct rpc_task *task) |
| 597 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 598 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 599 | int ret = 0; |
| 600 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 601 | if (session == NULL) { |
| 602 | args->sa_session = NULL; |
| 603 | res->sr_session = NULL; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 604 | goto out; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 605 | } |
| 606 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 607 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 608 | __func__, session->clp, session, res->sr_slot ? |
| 609 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 610 | |
| 611 | ret = nfs41_setup_sequence(session, args, res, cache_reply, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 612 | task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 613 | out: |
| 614 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 615 | return ret; |
| 616 | } |
| 617 | |
| 618 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 619 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 620 | struct nfs4_sequence_args *seq_args; |
| 621 | struct nfs4_sequence_res *seq_res; |
| 622 | int cache_reply; |
| 623 | }; |
| 624 | |
| 625 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 626 | { |
| 627 | struct nfs41_call_sync_data *data = calldata; |
| 628 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 629 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 630 | |
| 631 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 632 | data->seq_res, data->cache_reply, task)) |
| 633 | return; |
| 634 | rpc_call_start(task); |
| 635 | } |
| 636 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 637 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 638 | { |
| 639 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 640 | nfs41_call_sync_prepare(task, calldata); |
| 641 | } |
| 642 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 643 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 644 | { |
| 645 | struct nfs41_call_sync_data *data = calldata; |
| 646 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 647 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 648 | } |
| 649 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 650 | struct rpc_call_ops nfs41_call_sync_ops = { |
| 651 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 652 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 653 | }; |
| 654 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 655 | struct rpc_call_ops nfs41_call_priv_sync_ops = { |
| 656 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 657 | .rpc_call_done = nfs41_call_sync_done, |
| 658 | }; |
| 659 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 660 | static int nfs4_call_sync_sequence(struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 661 | struct rpc_message *msg, |
| 662 | struct nfs4_sequence_args *args, |
| 663 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 664 | int cache_reply, |
| 665 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 666 | { |
| 667 | int ret; |
| 668 | struct rpc_task *task; |
| 669 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 670 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 671 | .seq_args = args, |
| 672 | .seq_res = res, |
| 673 | .cache_reply = cache_reply, |
| 674 | }; |
| 675 | struct rpc_task_setup task_setup = { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 676 | .rpc_client = server->client, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 677 | .rpc_message = msg, |
| 678 | .callback_ops = &nfs41_call_sync_ops, |
| 679 | .callback_data = &data |
| 680 | }; |
| 681 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 682 | res->sr_slot = NULL; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 683 | if (privileged) |
| 684 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 685 | task = rpc_run_task(&task_setup); |
| 686 | if (IS_ERR(task)) |
| 687 | ret = PTR_ERR(task); |
| 688 | else { |
| 689 | ret = task->tk_status; |
| 690 | rpc_put_task(task); |
| 691 | } |
| 692 | return ret; |
| 693 | } |
| 694 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 695 | int _nfs4_call_sync_session(struct nfs_server *server, |
| 696 | struct rpc_message *msg, |
| 697 | struct nfs4_sequence_args *args, |
| 698 | struct nfs4_sequence_res *res, |
| 699 | int cache_reply) |
| 700 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 701 | return nfs4_call_sync_sequence(server, msg, args, res, cache_reply, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 702 | } |
| 703 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 704 | #else |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 705 | static int nfs4_sequence_done(struct rpc_task *task, |
| 706 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 707 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 708 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 709 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 710 | #endif /* CONFIG_NFS_V4_1 */ |
| 711 | |
| 712 | int _nfs4_call_sync(struct nfs_server *server, |
| 713 | struct rpc_message *msg, |
| 714 | struct nfs4_sequence_args *args, |
| 715 | struct nfs4_sequence_res *res, |
| 716 | int cache_reply) |
| 717 | { |
Benny Halevy | f375297 | 2009-04-01 09:22:04 -0400 | [diff] [blame] | 718 | args->sa_session = res->sr_session = NULL; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 719 | return rpc_call_sync(server->client, msg, 0); |
| 720 | } |
| 721 | |
| 722 | #define nfs4_call_sync(server, msg, args, res, cache_reply) \ |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 723 | (server)->nfs_client->cl_mvops->call_sync((server), (msg), &(args)->seq_args, \ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 724 | &(res)->seq_res, (cache_reply)) |
| 725 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 726 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 728 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 730 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 731 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA; |
| 732 | if (!cinfo->atomic || cinfo->before != nfsi->change_attr) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 733 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 734 | nfsi->change_attr = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 735 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | } |
| 737 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 738 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 739 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 740 | struct nfs_openargs o_arg; |
| 741 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 742 | struct nfs_open_confirmargs c_arg; |
| 743 | struct nfs_open_confirmres c_res; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 744 | struct nfs_fattr f_attr; |
| 745 | struct nfs_fattr dir_attr; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 746 | struct path path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 747 | struct dentry *dir; |
| 748 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 749 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 750 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 751 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 752 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 753 | int rpc_status; |
| 754 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 755 | }; |
| 756 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 757 | |
| 758 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 759 | { |
| 760 | p->o_res.f_attr = &p->f_attr; |
| 761 | p->o_res.dir_attr = &p->dir_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 762 | p->o_res.seqid = p->o_arg.seqid; |
| 763 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 764 | p->o_res.server = p->o_arg.server; |
| 765 | nfs_fattr_init(&p->f_attr); |
| 766 | nfs_fattr_init(&p->dir_attr); |
| 767 | } |
| 768 | |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 769 | static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 770 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 771 | const struct iattr *attrs, |
| 772 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 773 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 774 | struct dentry *parent = dget_parent(path->dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 775 | struct inode *dir = parent->d_inode; |
| 776 | struct nfs_server *server = NFS_SERVER(dir); |
| 777 | struct nfs4_opendata *p; |
| 778 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 779 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 780 | if (p == NULL) |
| 781 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 782 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 783 | if (p->o_arg.seqid == NULL) |
| 784 | goto err_free; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 785 | path_get(path); |
| 786 | p->path = *path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 787 | p->dir = parent; |
| 788 | p->owner = sp; |
| 789 | atomic_inc(&sp->so_count); |
| 790 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 791 | p->o_arg.open_flags = flags; |
| 792 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 793 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 794 | p->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 795 | p->o_arg.name = &p->path.dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 796 | p->o_arg.server = server; |
| 797 | p->o_arg.bitmask = server->attr_bitmask; |
| 798 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 799 | if (flags & O_CREAT) { |
| 800 | u32 *s; |
| 801 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 802 | p->o_arg.u.attrs = &p->attrs; |
| 803 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 804 | s = (u32 *) p->o_arg.u.verifier.data; |
| 805 | s[0] = jiffies; |
| 806 | s[1] = current->pid; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 807 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 808 | p->c_arg.fh = &p->o_res.fh; |
| 809 | p->c_arg.stateid = &p->o_res.stateid; |
| 810 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 811 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 812 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 813 | return p; |
| 814 | err_free: |
| 815 | kfree(p); |
| 816 | err: |
| 817 | dput(parent); |
| 818 | return NULL; |
| 819 | } |
| 820 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 821 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 822 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 823 | struct nfs4_opendata *p = container_of(kref, |
| 824 | struct nfs4_opendata, kref); |
| 825 | |
| 826 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 827 | if (p->state != NULL) |
| 828 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 829 | nfs4_put_state_owner(p->owner); |
| 830 | dput(p->dir); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 831 | path_put(&p->path); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 832 | kfree(p); |
| 833 | } |
| 834 | |
| 835 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 836 | { |
| 837 | if (p != NULL) |
| 838 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 839 | } |
| 840 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 841 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 842 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 843 | int ret; |
| 844 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 845 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 846 | return ret; |
| 847 | } |
| 848 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 849 | 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] | 850 | { |
| 851 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 852 | |
| 853 | if (open_mode & O_EXCL) |
| 854 | goto out; |
| 855 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 856 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 857 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 858 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 859 | break; |
| 860 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 861 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 862 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 863 | break; |
| 864 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 865 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 866 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 867 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 868 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 869 | return ret; |
| 870 | } |
| 871 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 872 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 873 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 874 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 875 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 876 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 877 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 878 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 879 | return 1; |
| 880 | } |
| 881 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 882 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 883 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 884 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 885 | case FMODE_WRITE: |
| 886 | state->n_wronly++; |
| 887 | break; |
| 888 | case FMODE_READ: |
| 889 | state->n_rdonly++; |
| 890 | break; |
| 891 | case FMODE_READ|FMODE_WRITE: |
| 892 | state->n_rdwr++; |
| 893 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 894 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 895 | } |
| 896 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 897 | 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] | 898 | { |
| 899 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 900 | memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); |
| 901 | memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 902 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 903 | case FMODE_READ: |
| 904 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 905 | break; |
| 906 | case FMODE_WRITE: |
| 907 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 908 | break; |
| 909 | case FMODE_READ|FMODE_WRITE: |
| 910 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 911 | } |
| 912 | } |
| 913 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 914 | 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] | 915 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 916 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 917 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 918 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 919 | } |
| 920 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 921 | 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] | 922 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 923 | /* |
| 924 | * Protect the call to nfs4_state_set_mode_locked and |
| 925 | * serialise the stateid update |
| 926 | */ |
| 927 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 928 | if (deleg_stateid != NULL) { |
| 929 | memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); |
| 930 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 931 | } |
| 932 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 933 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 934 | write_sequnlock(&state->seqlock); |
| 935 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 936 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 937 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | } |
| 939 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 940 | 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] | 941 | { |
| 942 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 943 | struct nfs_delegation *deleg_cur; |
| 944 | int ret = 0; |
| 945 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 946 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 947 | |
| 948 | rcu_read_lock(); |
| 949 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 950 | if (deleg_cur == NULL) |
| 951 | goto no_delegation; |
| 952 | |
| 953 | spin_lock(&deleg_cur->lock); |
| 954 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 955 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 956 | goto no_delegation_unlock; |
| 957 | |
| 958 | if (delegation == NULL) |
| 959 | delegation = &deleg_cur->stateid; |
| 960 | else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) |
| 961 | goto no_delegation_unlock; |
| 962 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 963 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 964 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 965 | ret = 1; |
| 966 | no_delegation_unlock: |
| 967 | spin_unlock(&deleg_cur->lock); |
| 968 | no_delegation: |
| 969 | rcu_read_unlock(); |
| 970 | |
| 971 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 972 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 973 | ret = 1; |
| 974 | } |
| 975 | |
| 976 | return ret; |
| 977 | } |
| 978 | |
| 979 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 980 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 981 | { |
| 982 | struct nfs_delegation *delegation; |
| 983 | |
| 984 | rcu_read_lock(); |
| 985 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 986 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 987 | rcu_read_unlock(); |
| 988 | return; |
| 989 | } |
| 990 | rcu_read_unlock(); |
| 991 | nfs_inode_return_delegation(inode); |
| 992 | } |
| 993 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 994 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 995 | { |
| 996 | struct nfs4_state *state = opendata->state; |
| 997 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 998 | struct nfs_delegation *delegation; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 999 | int open_mode = opendata->o_arg.open_flags & O_EXCL; |
| 1000 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1001 | nfs4_stateid stateid; |
| 1002 | int ret = -EAGAIN; |
| 1003 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1004 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1005 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1006 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1007 | if (can_open_cached(state, fmode, open_mode)) { |
| 1008 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1009 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1010 | goto out_return_state; |
| 1011 | } |
| 1012 | spin_unlock(&state->owner->so_lock); |
| 1013 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1014 | rcu_read_lock(); |
| 1015 | delegation = rcu_dereference(nfsi->delegation); |
| 1016 | if (delegation == NULL || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1017 | !can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1018 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1019 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1020 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1021 | /* Save the delegation */ |
| 1022 | memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); |
| 1023 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1024 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1025 | if (ret != 0) |
| 1026 | goto out; |
| 1027 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1028 | |
| 1029 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1030 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1031 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1032 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1033 | out: |
| 1034 | return ERR_PTR(ret); |
| 1035 | out_return_state: |
| 1036 | atomic_inc(&state->count); |
| 1037 | return state; |
| 1038 | } |
| 1039 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1040 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1041 | { |
| 1042 | struct inode *inode; |
| 1043 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1044 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1045 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1046 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1047 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1048 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1049 | goto out; |
| 1050 | } |
| 1051 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1052 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1053 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1054 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1055 | 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] | 1056 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1057 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1058 | goto err; |
| 1059 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1060 | state = nfs4_get_open_state(inode, data->owner); |
| 1061 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1062 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1063 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1064 | int delegation_flags = 0; |
| 1065 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1066 | rcu_read_lock(); |
| 1067 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1068 | if (delegation) |
| 1069 | delegation_flags = delegation->flags; |
| 1070 | rcu_read_unlock(); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1071 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1072 | nfs_inode_set_delegation(state->inode, |
| 1073 | data->owner->so_cred, |
| 1074 | &data->o_res); |
| 1075 | else |
| 1076 | nfs_inode_reclaim_delegation(state->inode, |
| 1077 | data->owner->so_cred, |
| 1078 | &data->o_res); |
| 1079 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1080 | |
| 1081 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1082 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1083 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1084 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1085 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1086 | err_put_inode: |
| 1087 | iput(inode); |
| 1088 | err: |
| 1089 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1090 | } |
| 1091 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1092 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1093 | { |
| 1094 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1095 | struct nfs_open_context *ctx; |
| 1096 | |
| 1097 | spin_lock(&state->inode->i_lock); |
| 1098 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1099 | if (ctx->state != state) |
| 1100 | continue; |
| 1101 | get_nfs_open_context(ctx); |
| 1102 | spin_unlock(&state->inode->i_lock); |
| 1103 | return ctx; |
| 1104 | } |
| 1105 | spin_unlock(&state->inode->i_lock); |
| 1106 | return ERR_PTR(-ENOENT); |
| 1107 | } |
| 1108 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1109 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1110 | { |
| 1111 | struct nfs4_opendata *opendata; |
| 1112 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1113 | opendata = nfs4_opendata_alloc(&ctx->path, state->owner, 0, 0, NULL, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1114 | if (opendata == NULL) |
| 1115 | return ERR_PTR(-ENOMEM); |
| 1116 | opendata->state = state; |
| 1117 | atomic_inc(&state->count); |
| 1118 | return opendata; |
| 1119 | } |
| 1120 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1121 | 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] | 1122 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1123 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1124 | int ret; |
| 1125 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1126 | opendata->o_arg.open_flags = 0; |
| 1127 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1128 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1129 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1130 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1131 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1132 | if (ret != 0) |
| 1133 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1134 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1135 | if (IS_ERR(newstate)) |
| 1136 | return PTR_ERR(newstate); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1137 | nfs4_close_state(&opendata->path, newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1138 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1139 | return 0; |
| 1140 | } |
| 1141 | |
| 1142 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1143 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1144 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1145 | int ret; |
| 1146 | |
| 1147 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1148 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1149 | smp_rmb(); |
| 1150 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1151 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1152 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1153 | if (ret != 0) |
| 1154 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1155 | if (newstate != state) |
| 1156 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1157 | } |
| 1158 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1159 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1160 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1161 | if (ret != 0) |
| 1162 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1163 | if (newstate != state) |
| 1164 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1165 | } |
| 1166 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1167 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1168 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1169 | if (ret != 0) |
| 1170 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1171 | if (newstate != state) |
| 1172 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1173 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1174 | /* |
| 1175 | * We may have performed cached opens for all three recoveries. |
| 1176 | * Check if we need to update the current stateid. |
| 1177 | */ |
| 1178 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
| 1179 | 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] | 1180 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1181 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1182 | memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1183 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1184 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1185 | return 0; |
| 1186 | } |
| 1187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | /* |
| 1189 | * OPEN_RECLAIM: |
| 1190 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1192 | 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] | 1193 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1194 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1195 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1196 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | int status; |
| 1198 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1199 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1200 | if (IS_ERR(opendata)) |
| 1201 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1202 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1203 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1204 | rcu_read_lock(); |
| 1205 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1206 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1207 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1208 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1209 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1210 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1211 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | return status; |
| 1213 | } |
| 1214 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1215 | 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] | 1216 | { |
| 1217 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1218 | struct nfs4_exception exception = { }; |
| 1219 | int err; |
| 1220 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1221 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1222 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1223 | break; |
| 1224 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | } while (exception.retry); |
| 1226 | return err; |
| 1227 | } |
| 1228 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1229 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1230 | { |
| 1231 | struct nfs_open_context *ctx; |
| 1232 | int ret; |
| 1233 | |
| 1234 | ctx = nfs4_state_find_open_context(state); |
| 1235 | if (IS_ERR(ctx)) |
| 1236 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1237 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1238 | put_nfs_open_context(ctx); |
| 1239 | return ret; |
| 1240 | } |
| 1241 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1242 | 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] | 1243 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1244 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1245 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1247 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1248 | if (IS_ERR(opendata)) |
| 1249 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1250 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1251 | memcpy(opendata->o_arg.u.delegation.data, stateid->data, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1252 | sizeof(opendata->o_arg.u.delegation.data)); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1253 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1254 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1255 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | } |
| 1257 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1258 | 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] | 1259 | { |
| 1260 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1261 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | int err; |
| 1263 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1264 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | switch (err) { |
| 1266 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1267 | case -ENOENT: |
| 1268 | case -ESTALE: |
| 1269 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1270 | case -NFS4ERR_BADSESSION: |
| 1271 | case -NFS4ERR_BADSLOT: |
| 1272 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1273 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1274 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1275 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1276 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | case -NFS4ERR_STALE_CLIENTID: |
| 1278 | case -NFS4ERR_STALE_STATEID: |
| 1279 | case -NFS4ERR_EXPIRED: |
| 1280 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1281 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1282 | goto out; |
| 1283 | case -ERESTARTSYS: |
| 1284 | /* |
| 1285 | * The show must go on: exit, but mark the |
| 1286 | * stateid as needing recovery. |
| 1287 | */ |
| 1288 | case -NFS4ERR_ADMIN_REVOKED: |
| 1289 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1290 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1291 | case -EKEYEXPIRED: |
| 1292 | /* |
| 1293 | * User RPCSEC_GSS context has expired. |
| 1294 | * We cannot recover this stateid now, so |
| 1295 | * skip it and allow recovery thread to |
| 1296 | * proceed. |
| 1297 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1298 | case -ENOMEM: |
| 1299 | err = 0; |
| 1300 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | } |
| 1302 | err = nfs4_handle_exception(server, err, &exception); |
| 1303 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1304 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | return err; |
| 1306 | } |
| 1307 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1308 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1309 | { |
| 1310 | struct nfs4_opendata *data = calldata; |
| 1311 | |
| 1312 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1313 | if (data->rpc_status == 0) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1314 | memcpy(data->o_res.stateid.data, data->c_res.stateid.data, |
| 1315 | sizeof(data->o_res.stateid.data)); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1316 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1317 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1318 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1319 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | static void nfs4_open_confirm_release(void *calldata) |
| 1323 | { |
| 1324 | struct nfs4_opendata *data = calldata; |
| 1325 | struct nfs4_state *state = NULL; |
| 1326 | |
| 1327 | /* If this request hasn't been cancelled, do nothing */ |
| 1328 | if (data->cancelled == 0) |
| 1329 | goto out_free; |
| 1330 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1331 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1332 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1333 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1334 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1335 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1336 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1337 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1341 | .rpc_call_done = nfs4_open_confirm_done, |
| 1342 | .rpc_release = nfs4_open_confirm_release, |
| 1343 | }; |
| 1344 | |
| 1345 | /* |
| 1346 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1347 | */ |
| 1348 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1349 | { |
| 1350 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1351 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1352 | struct rpc_message msg = { |
| 1353 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1354 | .rpc_argp = &data->c_arg, |
| 1355 | .rpc_resp = &data->c_res, |
| 1356 | .rpc_cred = data->owner->so_cred, |
| 1357 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1358 | struct rpc_task_setup task_setup_data = { |
| 1359 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1360 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1361 | .callback_ops = &nfs4_open_confirm_ops, |
| 1362 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1363 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1364 | .flags = RPC_TASK_ASYNC, |
| 1365 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | int status; |
| 1367 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1368 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1369 | data->rpc_done = 0; |
| 1370 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1371 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1372 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1373 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1374 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1375 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1376 | if (status != 0) { |
| 1377 | data->cancelled = 1; |
| 1378 | smp_wmb(); |
| 1379 | } else |
| 1380 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1381 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | return status; |
| 1383 | } |
| 1384 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1385 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1387 | struct nfs4_opendata *data = calldata; |
| 1388 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1389 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1390 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1391 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1392 | /* |
| 1393 | * Check if we still need to send an OPEN call, or if we can use |
| 1394 | * a delegation instead. |
| 1395 | */ |
| 1396 | if (data->state != NULL) { |
| 1397 | struct nfs_delegation *delegation; |
| 1398 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1399 | 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] | 1400 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1401 | rcu_read_lock(); |
| 1402 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
| 1403 | if (delegation != NULL && |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1404 | test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1405 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1406 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1407 | } |
| 1408 | rcu_read_unlock(); |
| 1409 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1410 | /* Update sequence id. */ |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1411 | data->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1412 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1413 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1414 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1415 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1416 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1417 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1418 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1419 | &data->o_arg.seq_args, |
| 1420 | &data->o_res.seq_res, 1, task)) |
| 1421 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1422 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1423 | return; |
| 1424 | out_no_action: |
| 1425 | task->tk_action = NULL; |
| 1426 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1427 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1429 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1430 | { |
| 1431 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1432 | nfs4_open_prepare(task, calldata); |
| 1433 | } |
| 1434 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1435 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1436 | { |
| 1437 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1439 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1440 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1441 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1442 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1443 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1444 | if (task->tk_status == 0) { |
| 1445 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1446 | case S_IFREG: |
| 1447 | break; |
| 1448 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1449 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1450 | break; |
| 1451 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1452 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1453 | break; |
| 1454 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1455 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1456 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1457 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1458 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1459 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1460 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1461 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1462 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1463 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1464 | static void nfs4_open_release(void *calldata) |
| 1465 | { |
| 1466 | struct nfs4_opendata *data = calldata; |
| 1467 | struct nfs4_state *state = NULL; |
| 1468 | |
| 1469 | /* If this request hasn't been cancelled, do nothing */ |
| 1470 | if (data->cancelled == 0) |
| 1471 | goto out_free; |
| 1472 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1473 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1474 | goto out_free; |
| 1475 | /* In case we need an open_confirm, no cleanup! */ |
| 1476 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1477 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1478 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1479 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1480 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1481 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1482 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1486 | .rpc_call_prepare = nfs4_open_prepare, |
| 1487 | .rpc_call_done = nfs4_open_done, |
| 1488 | .rpc_release = nfs4_open_release, |
| 1489 | }; |
| 1490 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1491 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1492 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1493 | .rpc_call_done = nfs4_open_done, |
| 1494 | .rpc_release = nfs4_open_release, |
| 1495 | }; |
| 1496 | |
| 1497 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1498 | { |
| 1499 | struct inode *dir = data->dir->d_inode; |
| 1500 | struct nfs_server *server = NFS_SERVER(dir); |
| 1501 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1502 | struct nfs_openres *o_res = &data->o_res; |
| 1503 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1504 | struct rpc_message msg = { |
| 1505 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1506 | .rpc_argp = o_arg, |
| 1507 | .rpc_resp = o_res, |
| 1508 | .rpc_cred = data->owner->so_cred, |
| 1509 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1510 | struct rpc_task_setup task_setup_data = { |
| 1511 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1512 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1513 | .callback_ops = &nfs4_open_ops, |
| 1514 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1515 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1516 | .flags = RPC_TASK_ASYNC, |
| 1517 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1518 | int status; |
| 1519 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1520 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1521 | data->rpc_done = 0; |
| 1522 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1523 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1524 | if (isrecover) |
| 1525 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1526 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1527 | if (IS_ERR(task)) |
| 1528 | return PTR_ERR(task); |
| 1529 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1530 | if (status != 0) { |
| 1531 | data->cancelled = 1; |
| 1532 | smp_wmb(); |
| 1533 | } else |
| 1534 | status = data->rpc_status; |
| 1535 | rpc_put_task(task); |
| 1536 | |
| 1537 | return status; |
| 1538 | } |
| 1539 | |
| 1540 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1541 | { |
| 1542 | struct inode *dir = data->dir->d_inode; |
| 1543 | struct nfs_openres *o_res = &data->o_res; |
| 1544 | int status; |
| 1545 | |
| 1546 | status = nfs4_run_open_task(data, 1); |
| 1547 | if (status != 0 || !data->rpc_done) |
| 1548 | return status; |
| 1549 | |
| 1550 | nfs_refresh_inode(dir, o_res->dir_attr); |
| 1551 | |
| 1552 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1553 | status = _nfs4_proc_open_confirm(data); |
| 1554 | if (status != 0) |
| 1555 | return status; |
| 1556 | } |
| 1557 | |
| 1558 | return status; |
| 1559 | } |
| 1560 | |
| 1561 | /* |
| 1562 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1563 | */ |
| 1564 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1565 | { |
| 1566 | struct inode *dir = data->dir->d_inode; |
| 1567 | struct nfs_server *server = NFS_SERVER(dir); |
| 1568 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1569 | struct nfs_openres *o_res = &data->o_res; |
| 1570 | int status; |
| 1571 | |
| 1572 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1573 | if (status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1574 | return status; |
| 1575 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1576 | if (o_arg->open_flags & O_CREAT) { |
| 1577 | update_changeattr(dir, &o_res->cinfo); |
| 1578 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
| 1579 | } else |
| 1580 | nfs_refresh_inode(dir, o_res->dir_attr); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1581 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1582 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1584 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1586 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | } |
| 1588 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1589 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1590 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | } |
| 1592 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1593 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1594 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1595 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1596 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1597 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1598 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1599 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1600 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1601 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1602 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1603 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1604 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1605 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1606 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1607 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1608 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1609 | } |
| 1610 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1611 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1612 | { |
| 1613 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1614 | } |
| 1615 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | /* |
| 1617 | * OPEN_EXPIRED: |
| 1618 | * reclaim state on the server after a network partition. |
| 1619 | * Assumes caller holds the appropriate lock |
| 1620 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1621 | 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] | 1622 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1623 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1624 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1626 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1627 | if (IS_ERR(opendata)) |
| 1628 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1629 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1630 | if (ret == -ESTALE) |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1631 | d_drop(ctx->path.dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1632 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1633 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | } |
| 1635 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1636 | 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] | 1637 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1638 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1639 | struct nfs4_exception exception = { }; |
| 1640 | int err; |
| 1641 | |
| 1642 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1643 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1644 | switch (err) { |
| 1645 | default: |
| 1646 | goto out; |
| 1647 | case -NFS4ERR_GRACE: |
| 1648 | case -NFS4ERR_DELAY: |
| 1649 | nfs4_handle_exception(server, err, &exception); |
| 1650 | err = 0; |
| 1651 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1652 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1653 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1654 | return err; |
| 1655 | } |
| 1656 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1658 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1660 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1662 | ctx = nfs4_state_find_open_context(state); |
| 1663 | if (IS_ERR(ctx)) |
| 1664 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1665 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1666 | put_nfs_open_context(ctx); |
| 1667 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1671 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1672 | * fields corresponding to attributes that were used to store the verifier. |
| 1673 | * Make sure we clobber those fields in the later setattr call |
| 1674 | */ |
| 1675 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1676 | { |
| 1677 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1678 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1679 | sattr->ia_valid |= ATTR_ATIME; |
| 1680 | |
| 1681 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1682 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1683 | sattr->ia_valid |= ATTR_MTIME; |
| 1684 | } |
| 1685 | |
| 1686 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1687 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1689 | static int _nfs4_do_open(struct inode *dir, struct path *path, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred, struct nfs4_state **res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | { |
| 1691 | struct nfs4_state_owner *sp; |
| 1692 | struct nfs4_state *state = NULL; |
| 1693 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1694 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1695 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | |
| 1697 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | status = -ENOMEM; |
| 1699 | if (!(sp = nfs4_get_state_owner(server, cred))) { |
| 1700 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1701 | goto out_err; |
| 1702 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1703 | status = nfs4_recover_expired_lease(server); |
| 1704 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1705 | goto err_put_state_owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1706 | if (path->dentry->d_inode != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1707 | nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1708 | status = -ENOMEM; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1709 | opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1710 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1711 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1713 | if (path->dentry->d_inode != NULL) |
| 1714 | opendata->state = nfs4_get_open_state(path->dentry->d_inode, sp); |
| 1715 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1716 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1718 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1720 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1721 | status = PTR_ERR(state); |
| 1722 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1723 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1724 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1725 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1726 | |
| 1727 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1728 | nfs4_exclusive_attrset(opendata, sattr); |
| 1729 | |
| 1730 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1731 | status = nfs4_do_setattr(state->inode, cred, |
| 1732 | opendata->o_res.f_attr, sattr, |
| 1733 | state); |
| 1734 | if (status == 0) |
| 1735 | nfs_setattr_update_inode(state->inode, sattr); |
| 1736 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1737 | } |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1738 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | *res = state; |
| 1741 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1742 | err_opendata_put: |
| 1743 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1744 | err_put_state_owner: |
| 1745 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | *res = NULL; |
| 1748 | return status; |
| 1749 | } |
| 1750 | |
| 1751 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1752 | static struct nfs4_state *nfs4_do_open(struct inode *dir, struct path *path, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | { |
| 1754 | struct nfs4_exception exception = { }; |
| 1755 | struct nfs4_state *res; |
| 1756 | int status; |
| 1757 | |
| 1758 | do { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1759 | status = _nfs4_do_open(dir, path, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | if (status == 0) |
| 1761 | break; |
| 1762 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1763 | * book-keeping w.r.t. state-changing operations |
| 1764 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1765 | * It is actually a sign of a bug on the client or on the server. |
| 1766 | * |
| 1767 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1768 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | * have unhashed the old state_owner for us, and that we can |
| 1770 | * therefore safely retry using a new one. We should still warn |
| 1771 | * the user though... |
| 1772 | */ |
| 1773 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1774 | printk(KERN_WARNING "NFS: v4 server %s " |
| 1775 | " returned a bad sequence-id error!\n", |
| 1776 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | exception.retry = 1; |
| 1778 | continue; |
| 1779 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1780 | /* |
| 1781 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1782 | * state before it received the OPEN_CONFIRM. |
| 1783 | * Recover by retrying the request as per the discussion |
| 1784 | * on Page 181 of RFC3530. |
| 1785 | */ |
| 1786 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1787 | exception.retry = 1; |
| 1788 | continue; |
| 1789 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1790 | if (status == -EAGAIN) { |
| 1791 | /* We must have found a delegation */ |
| 1792 | exception.retry = 1; |
| 1793 | continue; |
| 1794 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1796 | status, &exception)); |
| 1797 | } while (exception.retry); |
| 1798 | return res; |
| 1799 | } |
| 1800 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1801 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1802 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1803 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1805 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1807 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | .iap = sattr, |
| 1809 | .server = server, |
| 1810 | .bitmask = server->attr_bitmask, |
| 1811 | }; |
| 1812 | struct nfs_setattrres res = { |
| 1813 | .fattr = fattr, |
| 1814 | .server = server, |
| 1815 | }; |
| 1816 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1817 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1818 | .rpc_argp = &arg, |
| 1819 | .rpc_resp = &res, |
| 1820 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1822 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1823 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1825 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1827 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { |
| 1828 | /* Use that stateid */ |
| 1829 | } else if (state != NULL) { |
Trond Myklebust | 77041ed | 2010-07-01 12:49:11 -0400 | [diff] [blame] | 1830 | nfs4_copy_stateid(&arg.stateid, state, current->files, current->tgid); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1831 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); |
| 1833 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1834 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1835 | if (status == 0 && state != NULL) |
| 1836 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1837 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | } |
| 1839 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1840 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1841 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1842 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1844 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | struct nfs4_exception exception = { }; |
| 1846 | int err; |
| 1847 | do { |
| 1848 | err = nfs4_handle_exception(server, |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1849 | _nfs4_do_setattr(inode, cred, fattr, sattr, state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | &exception); |
| 1851 | } while (exception.retry); |
| 1852 | return err; |
| 1853 | } |
| 1854 | |
| 1855 | struct nfs4_closedata { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1856 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | struct inode *inode; |
| 1858 | struct nfs4_state *state; |
| 1859 | struct nfs_closeargs arg; |
| 1860 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1861 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1862 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1863 | bool roc; |
| 1864 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | }; |
| 1866 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1867 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1868 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1869 | struct nfs4_closedata *calldata = data; |
| 1870 | struct nfs4_state_owner *sp = calldata->state->owner; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1871 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1872 | if (calldata->roc) |
| 1873 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1874 | nfs4_put_open_state(calldata->state); |
| 1875 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1876 | nfs4_put_state_owner(sp); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 1877 | path_put(&calldata->path); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1878 | kfree(calldata); |
| 1879 | } |
| 1880 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1881 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 1882 | fmode_t fmode) |
| 1883 | { |
| 1884 | spin_lock(&state->owner->so_lock); |
| 1885 | if (!(fmode & FMODE_READ)) |
| 1886 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1887 | if (!(fmode & FMODE_WRITE)) |
| 1888 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1889 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1890 | spin_unlock(&state->owner->so_lock); |
| 1891 | } |
| 1892 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1893 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1895 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 1898 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1899 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 1900 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | /* hmm. we are done with the inode, and in the process of freeing |
| 1902 | * the state_owner. we keep this around to process errors |
| 1903 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | switch (task->tk_status) { |
| 1905 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1906 | if (calldata->roc) |
| 1907 | pnfs_roc_set_barrier(state->inode, |
| 1908 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1909 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1910 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1911 | nfs4_close_clear_stateid_flags(state, |
| 1912 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | break; |
| 1914 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1915 | case -NFS4ERR_OLD_STATEID: |
| 1916 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1918 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1919 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1921 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 1922 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1924 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1925 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | } |
| 1927 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1928 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1930 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1931 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1932 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1933 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1934 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1935 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1936 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1937 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 1938 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1939 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1940 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1941 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1942 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1943 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1944 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1945 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1946 | } |
| 1947 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1948 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1949 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1950 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1951 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1952 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1953 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1954 | |
| 1955 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1956 | /* Note: exit _without_ calling nfs4_close_done */ |
| 1957 | task->tk_action = NULL; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1958 | return; |
| 1959 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1960 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1961 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1962 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1963 | if (calldata->roc && |
| 1964 | pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { |
| 1965 | rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, |
| 1966 | task, NULL); |
| 1967 | return; |
| 1968 | } |
| 1969 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1970 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1971 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1972 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1973 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 1974 | &calldata->arg.seq_args, &calldata->res.seq_res, |
| 1975 | 1, task)) |
| 1976 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1977 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | } |
| 1979 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1980 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1981 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1982 | .rpc_call_done = nfs4_close_done, |
| 1983 | .rpc_release = nfs4_free_closedata, |
| 1984 | }; |
| 1985 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | /* |
| 1987 | * It is possible for data to be read/written from a mem-mapped file |
| 1988 | * after the sys_close call (which hits the vfs layer as a flush). |
| 1989 | * This means that we can't safely call nfsv4 close on a file until |
| 1990 | * the inode is cleared. This in turn means that we are not good |
| 1991 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 1992 | * share state even when we are done with one of the three share |
| 1993 | * stateid's in the inode. |
| 1994 | * |
| 1995 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 1996 | */ |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1997 | int nfs4_do_close(struct path *path, struct nfs4_state *state, gfp_t gfp_mask, int wait, bool roc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1999 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2001 | struct nfs4_state_owner *sp = state->owner; |
| 2002 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2003 | struct rpc_message msg = { |
| 2004 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2005 | .rpc_cred = state->owner->so_cred, |
| 2006 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2007 | struct rpc_task_setup task_setup_data = { |
| 2008 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2009 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2010 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2011 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2012 | .flags = RPC_TASK_ASYNC, |
| 2013 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2014 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2016 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2018 | goto out; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2019 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2021 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2022 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2024 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2025 | if (calldata->arg.seqid == NULL) |
| 2026 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2027 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2028 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2029 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2030 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2031 | calldata->res.server = server; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2032 | calldata->roc = roc; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 2033 | path_get(path); |
| 2034 | calldata->path = *path; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2035 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2036 | msg.rpc_argp = &calldata->arg; |
| 2037 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2038 | task_setup_data.callback_data = calldata; |
| 2039 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2040 | if (IS_ERR(task)) |
| 2041 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2042 | status = 0; |
| 2043 | if (wait) |
| 2044 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2045 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2046 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2047 | out_free_calldata: |
| 2048 | kfree(calldata); |
| 2049 | out: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2050 | if (roc) |
| 2051 | pnfs_roc_release(state->inode); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2052 | nfs4_put_open_state(state); |
| 2053 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2054 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | } |
| 2056 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2057 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2058 | 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] | 2059 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | struct nfs4_state *state; |
| 2061 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2062 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2063 | state = nfs4_do_open(dir, &ctx->path, ctx->mode, open_flags, attr, ctx->cred); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2064 | if (IS_ERR(state)) |
| 2065 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2066 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2067 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | } |
| 2069 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2070 | 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] | 2071 | { |
| 2072 | if (ctx->state == NULL) |
| 2073 | return; |
| 2074 | if (is_sync) |
| 2075 | nfs4_close_sync(&ctx->path, ctx->state, ctx->mode); |
| 2076 | else |
| 2077 | nfs4_close_state(&ctx->path, ctx->state, ctx->mode); |
| 2078 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | |
| 2080 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2081 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2082 | struct nfs4_server_caps_arg args = { |
| 2083 | .fhandle = fhandle, |
| 2084 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | struct nfs4_server_caps_res res = {}; |
| 2086 | struct rpc_message msg = { |
| 2087 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2088 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | .rpc_resp = &res, |
| 2090 | }; |
| 2091 | int status; |
| 2092 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2093 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | if (status == 0) { |
| 2095 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2096 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2097 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2098 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2099 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2100 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2102 | server->caps |= NFS_CAP_ACLS; |
| 2103 | if (res.has_links != 0) |
| 2104 | server->caps |= NFS_CAP_HARDLINKS; |
| 2105 | if (res.has_symlinks != 0) |
| 2106 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2107 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2108 | server->caps |= NFS_CAP_FILEID; |
| 2109 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2110 | server->caps |= NFS_CAP_MODE; |
| 2111 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2112 | server->caps |= NFS_CAP_NLINK; |
| 2113 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2114 | server->caps |= NFS_CAP_OWNER; |
| 2115 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2116 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2117 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2118 | server->caps |= NFS_CAP_ATIME; |
| 2119 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2120 | server->caps |= NFS_CAP_CTIME; |
| 2121 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2122 | server->caps |= NFS_CAP_MTIME; |
| 2123 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2124 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2125 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2126 | 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] | 2127 | server->acl_bitmask = res.acl_bitmask; |
| 2128 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | return status; |
| 2131 | } |
| 2132 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2133 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | { |
| 2135 | struct nfs4_exception exception = { }; |
| 2136 | int err; |
| 2137 | do { |
| 2138 | err = nfs4_handle_exception(server, |
| 2139 | _nfs4_server_capabilities(server, fhandle), |
| 2140 | &exception); |
| 2141 | } while (exception.retry); |
| 2142 | return err; |
| 2143 | } |
| 2144 | |
| 2145 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2146 | struct nfs_fsinfo *info) |
| 2147 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | struct nfs4_lookup_root_arg args = { |
| 2149 | .bitmask = nfs4_fattr_bitmap, |
| 2150 | }; |
| 2151 | struct nfs4_lookup_res res = { |
| 2152 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2153 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | .fh = fhandle, |
| 2155 | }; |
| 2156 | struct rpc_message msg = { |
| 2157 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2158 | .rpc_argp = &args, |
| 2159 | .rpc_resp = &res, |
| 2160 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2161 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2162 | nfs_fattr_init(info->fattr); |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 2163 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | } |
| 2165 | |
| 2166 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2167 | struct nfs_fsinfo *info) |
| 2168 | { |
| 2169 | struct nfs4_exception exception = { }; |
| 2170 | int err; |
| 2171 | do { |
| 2172 | err = nfs4_handle_exception(server, |
| 2173 | _nfs4_lookup_root(server, fhandle, info), |
| 2174 | &exception); |
| 2175 | } while (exception.retry); |
| 2176 | return err; |
| 2177 | } |
| 2178 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2179 | /* |
| 2180 | * get the file handle for the "/" directory on the server |
| 2181 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2183 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | int status; |
| 2186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | status = nfs4_lookup_root(server, fhandle, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | if (status == 0) |
| 2189 | status = nfs4_server_capabilities(server, fhandle); |
| 2190 | if (status == 0) |
| 2191 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2192 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | } |
| 2194 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2195 | /* |
| 2196 | * Get locations and (maybe) other attributes of a referral. |
| 2197 | * Note that we'll actually follow the referral later when |
| 2198 | * we detect fsid mismatch in inode revalidation |
| 2199 | */ |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2200 | static int nfs4_get_referral(struct inode *dir, const struct qstr *name, struct nfs_fattr *fattr, struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2201 | { |
| 2202 | int status = -ENOMEM; |
| 2203 | struct page *page = NULL; |
| 2204 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2205 | |
| 2206 | page = alloc_page(GFP_KERNEL); |
| 2207 | if (page == NULL) |
| 2208 | goto out; |
| 2209 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2210 | if (locations == NULL) |
| 2211 | goto out; |
| 2212 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 2213 | status = nfs4_proc_fs_locations(dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2214 | if (status != 0) |
| 2215 | goto out; |
| 2216 | /* Make sure server returned a different fsid for the referral */ |
| 2217 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2218 | dprintk("%s: server did not return a different fsid for a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2219 | status = -EIO; |
| 2220 | goto out; |
| 2221 | } |
| 2222 | |
| 2223 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
| 2224 | fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL; |
| 2225 | if (!fattr->mode) |
| 2226 | fattr->mode = S_IFDIR; |
| 2227 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2228 | out: |
| 2229 | if (page) |
| 2230 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2231 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2232 | return status; |
| 2233 | } |
| 2234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2236 | { |
| 2237 | struct nfs4_getattr_arg args = { |
| 2238 | .fh = fhandle, |
| 2239 | .bitmask = server->attr_bitmask, |
| 2240 | }; |
| 2241 | struct nfs4_getattr_res res = { |
| 2242 | .fattr = fattr, |
| 2243 | .server = server, |
| 2244 | }; |
| 2245 | struct rpc_message msg = { |
| 2246 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2247 | .rpc_argp = &args, |
| 2248 | .rpc_resp = &res, |
| 2249 | }; |
| 2250 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2251 | nfs_fattr_init(fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2252 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2256 | { |
| 2257 | struct nfs4_exception exception = { }; |
| 2258 | int err; |
| 2259 | do { |
| 2260 | err = nfs4_handle_exception(server, |
| 2261 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2262 | &exception); |
| 2263 | } while (exception.retry); |
| 2264 | return err; |
| 2265 | } |
| 2266 | |
| 2267 | /* |
| 2268 | * The file is not closed if it is opened due to the a request to change |
| 2269 | * the size of the file. The open call will not be needed once the |
| 2270 | * VFS layer lookup-intents are implemented. |
| 2271 | * |
| 2272 | * Close is called when the inode is destroyed. |
| 2273 | * If we haven't opened the file for O_WRONLY, we |
| 2274 | * need to in the size_change case to obtain a stateid. |
| 2275 | * |
| 2276 | * Got race? |
| 2277 | * Because OPEN is always done by name in nfsv4, it is |
| 2278 | * possible that we opened a different file by the same |
| 2279 | * name. We can recognize this race condition, but we |
| 2280 | * can't do anything about it besides returning an error. |
| 2281 | * |
| 2282 | * This will be fixed with VFS changes (lookup-intent). |
| 2283 | */ |
| 2284 | static int |
| 2285 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2286 | struct iattr *sattr) |
| 2287 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2288 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2289 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2290 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | int status; |
| 2292 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2293 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2295 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2296 | if (sattr->ia_valid & ATTR_FILE) { |
| 2297 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2298 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2299 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2300 | if (ctx) { |
| 2301 | cred = ctx->cred; |
| 2302 | state = ctx->state; |
| 2303 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2304 | } |
| 2305 | |
| 2306 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2307 | if (status == 0) |
| 2308 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | return status; |
| 2310 | } |
| 2311 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2312 | static int _nfs4_proc_lookupfh(struct nfs_server *server, const struct nfs_fh *dirfh, |
| 2313 | const struct qstr *name, struct nfs_fh *fhandle, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2314 | struct nfs_fattr *fattr) |
| 2315 | { |
| 2316 | int status; |
| 2317 | struct nfs4_lookup_arg args = { |
| 2318 | .bitmask = server->attr_bitmask, |
| 2319 | .dir_fh = dirfh, |
| 2320 | .name = name, |
| 2321 | }; |
| 2322 | struct nfs4_lookup_res res = { |
| 2323 | .server = server, |
| 2324 | .fattr = fattr, |
| 2325 | .fh = fhandle, |
| 2326 | }; |
| 2327 | struct rpc_message msg = { |
| 2328 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2329 | .rpc_argp = &args, |
| 2330 | .rpc_resp = &res, |
| 2331 | }; |
| 2332 | |
| 2333 | nfs_fattr_init(fattr); |
| 2334 | |
| 2335 | dprintk("NFS call lookupfh %s\n", name->name); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2336 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2337 | dprintk("NFS reply lookupfh: %d\n", status); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2338 | return status; |
| 2339 | } |
| 2340 | |
| 2341 | static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh, |
| 2342 | struct qstr *name, struct nfs_fh *fhandle, |
| 2343 | struct nfs_fattr *fattr) |
| 2344 | { |
| 2345 | struct nfs4_exception exception = { }; |
| 2346 | int err; |
| 2347 | do { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2348 | err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr); |
| 2349 | /* FIXME: !!!! */ |
| 2350 | if (err == -NFS4ERR_MOVED) { |
| 2351 | err = -EREMOTE; |
| 2352 | break; |
| 2353 | } |
| 2354 | err = nfs4_handle_exception(server, err, &exception); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2355 | } while (exception.retry); |
| 2356 | return err; |
| 2357 | } |
| 2358 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2359 | static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2361 | { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2362 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2363 | |
| 2364 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2365 | status = _nfs4_proc_lookupfh(NFS_SERVER(dir), NFS_FH(dir), name, fhandle, fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2366 | if (status == -NFS4ERR_MOVED) |
| 2367 | status = nfs4_get_referral(dir, name, fattr, fhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | dprintk("NFS reply lookup: %d\n", status); |
| 2369 | return status; |
| 2370 | } |
| 2371 | |
| 2372 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2373 | { |
| 2374 | struct nfs4_exception exception = { }; |
| 2375 | int err; |
| 2376 | do { |
| 2377 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2378 | _nfs4_proc_lookup(dir, name, fhandle, fattr), |
| 2379 | &exception); |
| 2380 | } while (exception.retry); |
| 2381 | return err; |
| 2382 | } |
| 2383 | |
| 2384 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2385 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2386 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | struct nfs4_accessargs args = { |
| 2388 | .fh = NFS_FH(inode), |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2389 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2391 | struct nfs4_accessres res = { |
| 2392 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2393 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | struct rpc_message msg = { |
| 2395 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2396 | .rpc_argp = &args, |
| 2397 | .rpc_resp = &res, |
| 2398 | .rpc_cred = entry->cred, |
| 2399 | }; |
| 2400 | int mode = entry->mask; |
| 2401 | int status; |
| 2402 | |
| 2403 | /* |
| 2404 | * Determine which access bits we want to ask for... |
| 2405 | */ |
| 2406 | if (mode & MAY_READ) |
| 2407 | args.access |= NFS4_ACCESS_READ; |
| 2408 | if (S_ISDIR(inode->i_mode)) { |
| 2409 | if (mode & MAY_WRITE) |
| 2410 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2411 | if (mode & MAY_EXEC) |
| 2412 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2413 | } else { |
| 2414 | if (mode & MAY_WRITE) |
| 2415 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2416 | if (mode & MAY_EXEC) |
| 2417 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2418 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2419 | |
| 2420 | res.fattr = nfs_alloc_fattr(); |
| 2421 | if (res.fattr == NULL) |
| 2422 | return -ENOMEM; |
| 2423 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2424 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2425 | if (!status) { |
| 2426 | entry->mask = 0; |
| 2427 | if (res.access & NFS4_ACCESS_READ) |
| 2428 | entry->mask |= MAY_READ; |
| 2429 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2430 | entry->mask |= MAY_WRITE; |
| 2431 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2432 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2433 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2435 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 | return status; |
| 2437 | } |
| 2438 | |
| 2439 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2440 | { |
| 2441 | struct nfs4_exception exception = { }; |
| 2442 | int err; |
| 2443 | do { |
| 2444 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2445 | _nfs4_proc_access(inode, entry), |
| 2446 | &exception); |
| 2447 | } while (exception.retry); |
| 2448 | return err; |
| 2449 | } |
| 2450 | |
| 2451 | /* |
| 2452 | * TODO: For the time being, we don't try to get any attributes |
| 2453 | * along with any of the zero-copy operations READ, READDIR, |
| 2454 | * READLINK, WRITE. |
| 2455 | * |
| 2456 | * In the case of the first three, we want to put the GETATTR |
| 2457 | * after the read-type operation -- this is because it is hard |
| 2458 | * to predict the length of a GETATTR response in v4, and thus |
| 2459 | * align the READ data correctly. This means that the GETATTR |
| 2460 | * may end up partially falling into the page cache, and we should |
| 2461 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2462 | * To do this efficiently, we need to know the total length |
| 2463 | * of data received, which doesn't seem to be available outside |
| 2464 | * of the RPC layer. |
| 2465 | * |
| 2466 | * In the case of WRITE, we also want to put the GETATTR after |
| 2467 | * the operation -- in this case because we want to make sure |
| 2468 | * we get the post-operation mtime and size. This means that |
| 2469 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2470 | * of it which would leave room in the 'tail' iovec. |
| 2471 | * |
| 2472 | * Both of these changes to the XDR layer would in fact be quite |
| 2473 | * minor, but I decided to leave them for a subsequent patch. |
| 2474 | */ |
| 2475 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2476 | unsigned int pgbase, unsigned int pglen) |
| 2477 | { |
| 2478 | struct nfs4_readlink args = { |
| 2479 | .fh = NFS_FH(inode), |
| 2480 | .pgbase = pgbase, |
| 2481 | .pglen = pglen, |
| 2482 | .pages = &page, |
| 2483 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2484 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2485 | struct rpc_message msg = { |
| 2486 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2487 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2488 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | }; |
| 2490 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2491 | return nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 | } |
| 2493 | |
| 2494 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2495 | unsigned int pgbase, unsigned int pglen) |
| 2496 | { |
| 2497 | struct nfs4_exception exception = { }; |
| 2498 | int err; |
| 2499 | do { |
| 2500 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2501 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2502 | &exception); |
| 2503 | } while (exception.retry); |
| 2504 | return err; |
| 2505 | } |
| 2506 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | /* |
| 2508 | * Got race? |
| 2509 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2510 | * Until then, this create/open method is prone to inefficiency and race |
| 2511 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2512 | * placed on the wire. |
| 2513 | * |
| 2514 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2515 | * The file will be opened again in the subsequent VFS open call |
| 2516 | * (nfs4_proc_file_open). |
| 2517 | * |
| 2518 | * The open for read will just hang around to be used by any process that |
| 2519 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2520 | */ |
| 2521 | |
| 2522 | static int |
| 2523 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2524 | int flags, struct nfs_open_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2525 | { |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2526 | struct path my_path = { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2527 | .dentry = dentry, |
| 2528 | }; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2529 | struct path *path = &my_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | struct nfs4_state *state; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2531 | struct rpc_cred *cred = NULL; |
| 2532 | fmode_t fmode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2533 | int status = 0; |
| 2534 | |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2535 | if (ctx != NULL) { |
| 2536 | cred = ctx->cred; |
| 2537 | path = &ctx->path; |
| 2538 | fmode = ctx->mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2539 | } |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2540 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2541 | state = nfs4_do_open(dir, path, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2542 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2543 | if (IS_ERR(state)) { |
| 2544 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2545 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2546 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2547 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2548 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2549 | if (ctx != NULL) |
| 2550 | ctx->state = state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2551 | else |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2552 | nfs4_close_sync(path, state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 | out: |
| 2554 | return status; |
| 2555 | } |
| 2556 | |
| 2557 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2558 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2559 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2560 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2562 | .name.len = name->len, |
| 2563 | .name.name = name->name, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2564 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2565 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2566 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2567 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2568 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2569 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2570 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2571 | .rpc_argp = &args, |
| 2572 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | }; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2574 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2575 | |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2576 | res.dir_attr = nfs_alloc_fattr(); |
| 2577 | if (res.dir_attr == NULL) |
| 2578 | goto out; |
| 2579 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2580 | status = nfs4_call_sync(server, &msg, &args, &res, 1); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2581 | if (status == 0) { |
| 2582 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2583 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2584 | } |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2585 | nfs_free_fattr(res.dir_attr); |
| 2586 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2587 | return status; |
| 2588 | } |
| 2589 | |
| 2590 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2591 | { |
| 2592 | struct nfs4_exception exception = { }; |
| 2593 | int err; |
| 2594 | do { |
| 2595 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2596 | _nfs4_proc_remove(dir, name), |
| 2597 | &exception); |
| 2598 | } while (exception.retry); |
| 2599 | return err; |
| 2600 | } |
| 2601 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2602 | 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] | 2603 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2604 | struct nfs_server *server = NFS_SERVER(dir); |
| 2605 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2606 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2608 | args->bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2609 | res->server = server; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 2610 | res->seq_res.sr_slot = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2611 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2612 | } |
| 2613 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2614 | 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] | 2615 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2616 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2617 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2618 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2619 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2620 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2621 | return 0; |
| 2622 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2623 | nfs_post_op_update_inode(dir, res->dir_attr); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2624 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2625 | } |
| 2626 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2627 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2628 | { |
| 2629 | struct nfs_server *server = NFS_SERVER(dir); |
| 2630 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2631 | struct nfs_renameres *res = msg->rpc_resp; |
| 2632 | |
| 2633 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
| 2634 | arg->bitmask = server->attr_bitmask; |
| 2635 | res->server = server; |
| 2636 | } |
| 2637 | |
| 2638 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2639 | struct inode *new_dir) |
| 2640 | { |
| 2641 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2642 | |
| 2643 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2644 | return 0; |
| 2645 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2646 | return 0; |
| 2647 | |
| 2648 | update_changeattr(old_dir, &res->old_cinfo); |
| 2649 | nfs_post_op_update_inode(old_dir, res->old_fattr); |
| 2650 | update_changeattr(new_dir, &res->new_cinfo); |
| 2651 | nfs_post_op_update_inode(new_dir, res->new_fattr); |
| 2652 | return 1; |
| 2653 | } |
| 2654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2656 | struct inode *new_dir, struct qstr *new_name) |
| 2657 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2658 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2659 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | .old_dir = NFS_FH(old_dir), |
| 2661 | .new_dir = NFS_FH(new_dir), |
| 2662 | .old_name = old_name, |
| 2663 | .new_name = new_name, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2664 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2665 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2666 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2667 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2668 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2669 | struct rpc_message msg = { |
| 2670 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2671 | .rpc_argp = &arg, |
| 2672 | .rpc_resp = &res, |
| 2673 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2674 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2675 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2676 | res.old_fattr = nfs_alloc_fattr(); |
| 2677 | res.new_fattr = nfs_alloc_fattr(); |
| 2678 | if (res.old_fattr == NULL || res.new_fattr == NULL) |
| 2679 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2681 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2682 | if (!status) { |
| 2683 | update_changeattr(old_dir, &res.old_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2684 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | update_changeattr(new_dir, &res.new_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2686 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2687 | } |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2688 | out: |
| 2689 | nfs_free_fattr(res.new_fattr); |
| 2690 | nfs_free_fattr(res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2691 | return status; |
| 2692 | } |
| 2693 | |
| 2694 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2695 | struct inode *new_dir, struct qstr *new_name) |
| 2696 | { |
| 2697 | struct nfs4_exception exception = { }; |
| 2698 | int err; |
| 2699 | do { |
| 2700 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2701 | _nfs4_proc_rename(old_dir, old_name, |
| 2702 | new_dir, new_name), |
| 2703 | &exception); |
| 2704 | } while (exception.retry); |
| 2705 | return err; |
| 2706 | } |
| 2707 | |
| 2708 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2709 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2710 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2711 | struct nfs4_link_arg arg = { |
| 2712 | .fh = NFS_FH(inode), |
| 2713 | .dir_fh = NFS_FH(dir), |
| 2714 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2715 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2717 | struct nfs4_link_res res = { |
| 2718 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2719 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2720 | struct rpc_message msg = { |
| 2721 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2722 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2723 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2724 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2725 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2726 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2727 | res.fattr = nfs_alloc_fattr(); |
| 2728 | res.dir_attr = nfs_alloc_fattr(); |
| 2729 | if (res.fattr == NULL || res.dir_attr == NULL) |
| 2730 | goto out; |
| 2731 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2732 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2733 | if (!status) { |
| 2734 | update_changeattr(dir, &res.cinfo); |
| 2735 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2736 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2737 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2738 | out: |
| 2739 | nfs_free_fattr(res.dir_attr); |
| 2740 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | return status; |
| 2742 | } |
| 2743 | |
| 2744 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2745 | { |
| 2746 | struct nfs4_exception exception = { }; |
| 2747 | int err; |
| 2748 | do { |
| 2749 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2750 | _nfs4_proc_link(inode, dir, name), |
| 2751 | &exception); |
| 2752 | } while (exception.retry); |
| 2753 | return err; |
| 2754 | } |
| 2755 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2756 | struct nfs4_createdata { |
| 2757 | struct rpc_message msg; |
| 2758 | struct nfs4_create_arg arg; |
| 2759 | struct nfs4_create_res res; |
| 2760 | struct nfs_fh fh; |
| 2761 | struct nfs_fattr fattr; |
| 2762 | struct nfs_fattr dir_fattr; |
| 2763 | }; |
| 2764 | |
| 2765 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 2766 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 2767 | { |
| 2768 | struct nfs4_createdata *data; |
| 2769 | |
| 2770 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2771 | if (data != NULL) { |
| 2772 | struct nfs_server *server = NFS_SERVER(dir); |
| 2773 | |
| 2774 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 2775 | data->msg.rpc_argp = &data->arg; |
| 2776 | data->msg.rpc_resp = &data->res; |
| 2777 | data->arg.dir_fh = NFS_FH(dir); |
| 2778 | data->arg.server = server; |
| 2779 | data->arg.name = name; |
| 2780 | data->arg.attrs = sattr; |
| 2781 | data->arg.ftype = ftype; |
| 2782 | data->arg.bitmask = server->attr_bitmask; |
| 2783 | data->res.server = server; |
| 2784 | data->res.fh = &data->fh; |
| 2785 | data->res.fattr = &data->fattr; |
| 2786 | data->res.dir_fattr = &data->dir_fattr; |
| 2787 | nfs_fattr_init(data->res.fattr); |
| 2788 | nfs_fattr_init(data->res.dir_fattr); |
| 2789 | } |
| 2790 | return data; |
| 2791 | } |
| 2792 | |
| 2793 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 2794 | { |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2795 | int status = nfs4_call_sync(NFS_SERVER(dir), &data->msg, |
| 2796 | &data->arg, &data->res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2797 | if (status == 0) { |
| 2798 | update_changeattr(dir, &data->res.dir_cinfo); |
| 2799 | nfs_post_op_update_inode(dir, data->res.dir_fattr); |
| 2800 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 2801 | } |
| 2802 | return status; |
| 2803 | } |
| 2804 | |
| 2805 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 2806 | { |
| 2807 | kfree(data); |
| 2808 | } |
| 2809 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2810 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2811 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2813 | struct nfs4_createdata *data; |
| 2814 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2816 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2817 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2818 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2819 | status = -ENOMEM; |
| 2820 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 2821 | if (data == NULL) |
| 2822 | goto out; |
| 2823 | |
| 2824 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 2825 | data->arg.u.symlink.pages = &page; |
| 2826 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2827 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2828 | status = nfs4_do_create(dir, dentry, data); |
| 2829 | |
| 2830 | nfs4_free_createdata(data); |
| 2831 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | return status; |
| 2833 | } |
| 2834 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2835 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2836 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2837 | { |
| 2838 | struct nfs4_exception exception = { }; |
| 2839 | int err; |
| 2840 | do { |
| 2841 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2842 | _nfs4_proc_symlink(dir, dentry, page, |
| 2843 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | &exception); |
| 2845 | } while (exception.retry); |
| 2846 | return err; |
| 2847 | } |
| 2848 | |
| 2849 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2850 | struct iattr *sattr) |
| 2851 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2852 | struct nfs4_createdata *data; |
| 2853 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2855 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 2856 | if (data == NULL) |
| 2857 | goto out; |
| 2858 | |
| 2859 | status = nfs4_do_create(dir, dentry, data); |
| 2860 | |
| 2861 | nfs4_free_createdata(data); |
| 2862 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2863 | return status; |
| 2864 | } |
| 2865 | |
| 2866 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2867 | struct iattr *sattr) |
| 2868 | { |
| 2869 | struct nfs4_exception exception = { }; |
| 2870 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2871 | |
| 2872 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2873 | do { |
| 2874 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2875 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 2876 | &exception); |
| 2877 | } while (exception.retry); |
| 2878 | return err; |
| 2879 | } |
| 2880 | |
| 2881 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2882 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2883 | { |
| 2884 | struct inode *dir = dentry->d_inode; |
| 2885 | struct nfs4_readdir_arg args = { |
| 2886 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2887 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2888 | .pgbase = 0, |
| 2889 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 2890 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 2891 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2892 | }; |
| 2893 | struct nfs4_readdir_res res; |
| 2894 | struct rpc_message msg = { |
| 2895 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 2896 | .rpc_argp = &args, |
| 2897 | .rpc_resp = &res, |
| 2898 | .rpc_cred = cred, |
| 2899 | }; |
| 2900 | int status; |
| 2901 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2902 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 2903 | dentry->d_parent->d_name.name, |
| 2904 | dentry->d_name.name, |
| 2905 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 2907 | res.pgbase = args.pgbase; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2908 | status = nfs4_call_sync(NFS_SERVER(dir), &msg, &args, &res, 0); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 2909 | if (status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2910 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 2911 | status += args.pgbase; |
| 2912 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 2913 | |
| 2914 | nfs_invalidate_atime(dir); |
| 2915 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2916 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2917 | return status; |
| 2918 | } |
| 2919 | |
| 2920 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2921 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | { |
| 2923 | struct nfs4_exception exception = { }; |
| 2924 | int err; |
| 2925 | do { |
| 2926 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 2927 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2928 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | &exception); |
| 2930 | } while (exception.retry); |
| 2931 | return err; |
| 2932 | } |
| 2933 | |
| 2934 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2935 | struct iattr *sattr, dev_t rdev) |
| 2936 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2937 | struct nfs4_createdata *data; |
| 2938 | int mode = sattr->ia_mode; |
| 2939 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2940 | |
| 2941 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 2942 | 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] | 2943 | |
| 2944 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 2945 | if (data == NULL) |
| 2946 | goto out; |
| 2947 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2948 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2949 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2951 | data->arg.ftype = NF4BLK; |
| 2952 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 2953 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2954 | } |
| 2955 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2956 | data->arg.ftype = NF4CHR; |
| 2957 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 2958 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2959 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2960 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2961 | status = nfs4_do_create(dir, dentry, data); |
| 2962 | |
| 2963 | nfs4_free_createdata(data); |
| 2964 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | return status; |
| 2966 | } |
| 2967 | |
| 2968 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2969 | struct iattr *sattr, dev_t rdev) |
| 2970 | { |
| 2971 | struct nfs4_exception exception = { }; |
| 2972 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2973 | |
| 2974 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | do { |
| 2976 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2977 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 2978 | &exception); |
| 2979 | } while (exception.retry); |
| 2980 | return err; |
| 2981 | } |
| 2982 | |
| 2983 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2984 | struct nfs_fsstat *fsstat) |
| 2985 | { |
| 2986 | struct nfs4_statfs_arg args = { |
| 2987 | .fh = fhandle, |
| 2988 | .bitmask = server->attr_bitmask, |
| 2989 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 2990 | struct nfs4_statfs_res res = { |
| 2991 | .fsstat = fsstat, |
| 2992 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2993 | struct rpc_message msg = { |
| 2994 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 2995 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 2996 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | }; |
| 2998 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2999 | nfs_fattr_init(fsstat->fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3000 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | } |
| 3002 | |
| 3003 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3004 | { |
| 3005 | struct nfs4_exception exception = { }; |
| 3006 | int err; |
| 3007 | do { |
| 3008 | err = nfs4_handle_exception(server, |
| 3009 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3010 | &exception); |
| 3011 | } while (exception.retry); |
| 3012 | return err; |
| 3013 | } |
| 3014 | |
| 3015 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3016 | struct nfs_fsinfo *fsinfo) |
| 3017 | { |
| 3018 | struct nfs4_fsinfo_arg args = { |
| 3019 | .fh = fhandle, |
| 3020 | .bitmask = server->attr_bitmask, |
| 3021 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3022 | struct nfs4_fsinfo_res res = { |
| 3023 | .fsinfo = fsinfo, |
| 3024 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3025 | struct rpc_message msg = { |
| 3026 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3027 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3028 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | }; |
| 3030 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3031 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | } |
| 3033 | |
| 3034 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3035 | { |
| 3036 | struct nfs4_exception exception = { }; |
| 3037 | int err; |
| 3038 | |
| 3039 | do { |
| 3040 | err = nfs4_handle_exception(server, |
| 3041 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3042 | &exception); |
| 3043 | } while (exception.retry); |
| 3044 | return err; |
| 3045 | } |
| 3046 | |
| 3047 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3048 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3049 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3051 | } |
| 3052 | |
| 3053 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3054 | struct nfs_pathconf *pathconf) |
| 3055 | { |
| 3056 | struct nfs4_pathconf_arg args = { |
| 3057 | .fh = fhandle, |
| 3058 | .bitmask = server->attr_bitmask, |
| 3059 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3060 | struct nfs4_pathconf_res res = { |
| 3061 | .pathconf = pathconf, |
| 3062 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3063 | struct rpc_message msg = { |
| 3064 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3065 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3066 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | }; |
| 3068 | |
| 3069 | /* None of the pathconf attributes are mandatory to implement */ |
| 3070 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3071 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3072 | return 0; |
| 3073 | } |
| 3074 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3075 | nfs_fattr_init(pathconf->fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3076 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | } |
| 3078 | |
| 3079 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3080 | struct nfs_pathconf *pathconf) |
| 3081 | { |
| 3082 | struct nfs4_exception exception = { }; |
| 3083 | int err; |
| 3084 | |
| 3085 | do { |
| 3086 | err = nfs4_handle_exception(server, |
| 3087 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3088 | &exception); |
| 3089 | } while (exception.retry); |
| 3090 | return err; |
| 3091 | } |
| 3092 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3093 | 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] | 3094 | { |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3095 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3096 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3097 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3098 | nfs_restart_rpc(task, server->nfs_client); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3099 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3100 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3101 | |
| 3102 | nfs_invalidate_atime(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3104 | renew_lease(server, data->timestamp); |
| 3105 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | } |
| 3107 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3108 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3109 | { |
| 3110 | |
| 3111 | dprintk("--> %s\n", __func__); |
| 3112 | |
| 3113 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3114 | return -EAGAIN; |
| 3115 | |
| 3116 | return data->read_done_cb(task, data); |
| 3117 | } |
| 3118 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3119 | 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] | 3120 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3122 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3123 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3124 | } |
| 3125 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3126 | /* Reset the the nfs_read_data to send the read to the MDS. */ |
| 3127 | void nfs4_reset_read(struct rpc_task *task, struct nfs_read_data *data) |
| 3128 | { |
| 3129 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3130 | put_lseg(data->lseg); |
| 3131 | data->lseg = NULL; |
| 3132 | /* offsets will differ in the dense stripe case */ |
| 3133 | data->args.offset = data->mds_offset; |
| 3134 | data->ds_clp = NULL; |
| 3135 | data->args.fh = NFS_FH(data->inode); |
| 3136 | data->read_done_cb = nfs4_read_done_cb; |
| 3137 | task->tk_ops = data->mds_ops; |
| 3138 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3139 | } |
| 3140 | EXPORT_SYMBOL_GPL(nfs4_reset_read); |
| 3141 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3142 | 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] | 3143 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3144 | struct inode *inode = data->inode; |
| 3145 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3146 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3147 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3148 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3150 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 3152 | nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3153 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3154 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | } |
| 3156 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3157 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3158 | { |
| 3159 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3160 | return -EAGAIN; |
| 3161 | return data->write_done_cb(task, data); |
| 3162 | } |
| 3163 | |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3164 | /* Reset the the nfs_write_data to send the write to the MDS. */ |
| 3165 | void nfs4_reset_write(struct rpc_task *task, struct nfs_write_data *data) |
| 3166 | { |
| 3167 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3168 | put_lseg(data->lseg); |
| 3169 | data->lseg = NULL; |
| 3170 | data->ds_clp = NULL; |
| 3171 | data->write_done_cb = nfs4_write_done_cb; |
| 3172 | data->args.fh = NFS_FH(data->inode); |
| 3173 | data->args.bitmask = data->res.server->cache_consistency_bitmask; |
| 3174 | data->args.offset = data->mds_offset; |
| 3175 | data->res.fattr = &data->fattr; |
| 3176 | task->tk_ops = data->mds_ops; |
| 3177 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3178 | } |
| 3179 | EXPORT_SYMBOL_GPL(nfs4_reset_write); |
| 3180 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3181 | 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] | 3182 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3183 | struct nfs_server *server = NFS_SERVER(data->inode); |
| 3184 | |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3185 | if (data->lseg) { |
| 3186 | data->args.bitmask = NULL; |
| 3187 | data->res.fattr = NULL; |
| 3188 | } else |
| 3189 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3190 | if (!data->write_done_cb) |
| 3191 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3192 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | data->timestamp = jiffies; |
| 3194 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3195 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | } |
| 3197 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3198 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | struct inode *inode = data->inode; |
| 3201 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3202 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3203 | return -EAGAIN; |
| 3204 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3205 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3206 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3207 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | } |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 3209 | nfs_refresh_inode(inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3210 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3211 | } |
| 3212 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3213 | 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] | 3214 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3215 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3217 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3218 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3219 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | } |
| 3221 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3222 | struct nfs4_renewdata { |
| 3223 | struct nfs_client *client; |
| 3224 | unsigned long timestamp; |
| 3225 | }; |
| 3226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | /* |
| 3228 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3229 | * standalone procedure for queueing an asynchronous RENEW. |
| 3230 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3231 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3232 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3233 | struct nfs4_renewdata *data = calldata; |
| 3234 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3235 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3236 | if (atomic_read(&clp->cl_count) > 1) |
| 3237 | nfs4_schedule_state_renewal(clp); |
| 3238 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3239 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3240 | } |
| 3241 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3242 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3244 | struct nfs4_renewdata *data = calldata; |
| 3245 | struct nfs_client *clp = data->client; |
| 3246 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | |
| 3248 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3249 | /* Unless we're shutting down, schedule state recovery! */ |
| 3250 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) != 0) |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3251 | nfs4_schedule_lease_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3252 | return; |
| 3253 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3254 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | } |
| 3256 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3257 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3258 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3259 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3260 | }; |
| 3261 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3262 | int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3263 | { |
| 3264 | struct rpc_message msg = { |
| 3265 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3266 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3267 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3268 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3269 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3271 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3272 | return -EIO; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3273 | data = kmalloc(sizeof(*data), GFP_KERNEL); |
| 3274 | if (data == NULL) |
| 3275 | return -ENOMEM; |
| 3276 | data->client = clp; |
| 3277 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3278 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3279 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3280 | } |
| 3281 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3282 | int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | { |
| 3284 | struct rpc_message msg = { |
| 3285 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3286 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3287 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | }; |
| 3289 | unsigned long now = jiffies; |
| 3290 | int status; |
| 3291 | |
| 3292 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3293 | if (status < 0) |
| 3294 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3295 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | return 0; |
| 3297 | } |
| 3298 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3299 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3300 | { |
| 3301 | return (server->caps & NFS_CAP_ACLS) |
| 3302 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3303 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3304 | } |
| 3305 | |
| 3306 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3307 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3308 | * the stack. |
| 3309 | */ |
| 3310 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3311 | |
| 3312 | static void buf_to_pages(const void *buf, size_t buflen, |
| 3313 | struct page **pages, unsigned int *pgbase) |
| 3314 | { |
| 3315 | const void *p = buf; |
| 3316 | |
| 3317 | *pgbase = offset_in_page(buf); |
| 3318 | p -= *pgbase; |
| 3319 | while (p < buf + buflen) { |
| 3320 | *(pages++) = virt_to_page(p); |
| 3321 | p += PAGE_CACHE_SIZE; |
| 3322 | } |
| 3323 | } |
| 3324 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3325 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3326 | struct page **pages, unsigned int *pgbase) |
| 3327 | { |
| 3328 | struct page *newpage, **spages; |
| 3329 | int rc = 0; |
| 3330 | size_t len; |
| 3331 | spages = pages; |
| 3332 | |
| 3333 | do { |
Jovi Zhang | 43b7c3f | 2011-03-02 23:19:37 +0000 | [diff] [blame] | 3334 | len = min_t(size_t, PAGE_CACHE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3335 | newpage = alloc_page(GFP_KERNEL); |
| 3336 | |
| 3337 | if (newpage == NULL) |
| 3338 | goto unwind; |
| 3339 | memcpy(page_address(newpage), buf, len); |
| 3340 | buf += len; |
| 3341 | buflen -= len; |
| 3342 | *pages++ = newpage; |
| 3343 | rc++; |
| 3344 | } while (buflen != 0); |
| 3345 | |
| 3346 | return rc; |
| 3347 | |
| 3348 | unwind: |
| 3349 | for(; rc > 0; rc--) |
| 3350 | __free_page(spages[rc-1]); |
| 3351 | return -ENOMEM; |
| 3352 | } |
| 3353 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3354 | struct nfs4_cached_acl { |
| 3355 | int cached; |
| 3356 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3357 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3358 | }; |
| 3359 | |
| 3360 | 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] | 3361 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3362 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3363 | |
| 3364 | spin_lock(&inode->i_lock); |
| 3365 | kfree(nfsi->nfs4_acl); |
| 3366 | nfsi->nfs4_acl = acl; |
| 3367 | spin_unlock(&inode->i_lock); |
| 3368 | } |
| 3369 | |
| 3370 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3371 | { |
| 3372 | nfs4_set_cached_acl(inode, NULL); |
| 3373 | } |
| 3374 | |
| 3375 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3376 | { |
| 3377 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3378 | struct nfs4_cached_acl *acl; |
| 3379 | int ret = -ENOENT; |
| 3380 | |
| 3381 | spin_lock(&inode->i_lock); |
| 3382 | acl = nfsi->nfs4_acl; |
| 3383 | if (acl == NULL) |
| 3384 | goto out; |
| 3385 | if (buf == NULL) /* user is just asking for length */ |
| 3386 | goto out_len; |
| 3387 | if (acl->cached == 0) |
| 3388 | goto out; |
| 3389 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3390 | if (acl->len > buflen) |
| 3391 | goto out; |
| 3392 | memcpy(buf, acl->data, acl->len); |
| 3393 | out_len: |
| 3394 | ret = acl->len; |
| 3395 | out: |
| 3396 | spin_unlock(&inode->i_lock); |
| 3397 | return ret; |
| 3398 | } |
| 3399 | |
| 3400 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) |
| 3401 | { |
| 3402 | struct nfs4_cached_acl *acl; |
| 3403 | |
| 3404 | if (buf && acl_len <= PAGE_SIZE) { |
| 3405 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3406 | if (acl == NULL) |
| 3407 | goto out; |
| 3408 | acl->cached = 1; |
| 3409 | memcpy(acl->data, buf, acl_len); |
| 3410 | } else { |
| 3411 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3412 | if (acl == NULL) |
| 3413 | goto out; |
| 3414 | acl->cached = 0; |
| 3415 | } |
| 3416 | acl->len = acl_len; |
| 3417 | out: |
| 3418 | nfs4_set_cached_acl(inode, acl); |
| 3419 | } |
| 3420 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3421 | 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] | 3422 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3423 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3424 | struct nfs_getaclargs args = { |
| 3425 | .fh = NFS_FH(inode), |
| 3426 | .acl_pages = pages, |
| 3427 | .acl_len = buflen, |
| 3428 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3429 | struct nfs_getaclres res = { |
| 3430 | .acl_len = buflen, |
| 3431 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3432 | void *resp_buf; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3433 | struct rpc_message msg = { |
| 3434 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3435 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3436 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3437 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3438 | struct page *localpage = NULL; |
| 3439 | int ret; |
| 3440 | |
| 3441 | if (buflen < PAGE_SIZE) { |
| 3442 | /* As long as we're doing a round trip to the server anyway, |
| 3443 | * let's be prepared for a page of acl data. */ |
| 3444 | localpage = alloc_page(GFP_KERNEL); |
| 3445 | resp_buf = page_address(localpage); |
| 3446 | if (localpage == NULL) |
| 3447 | return -ENOMEM; |
| 3448 | args.acl_pages[0] = localpage; |
| 3449 | args.acl_pgbase = 0; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3450 | args.acl_len = PAGE_SIZE; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3451 | } else { |
| 3452 | resp_buf = buf; |
| 3453 | buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase); |
| 3454 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3455 | ret = nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3456 | if (ret) |
| 3457 | goto out_free; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3458 | if (res.acl_len > args.acl_len) |
| 3459 | nfs4_write_cached_acl(inode, NULL, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3460 | else |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3461 | nfs4_write_cached_acl(inode, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3462 | if (buf) { |
| 3463 | ret = -ERANGE; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3464 | if (res.acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3465 | goto out_free; |
| 3466 | if (localpage) |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3467 | memcpy(buf, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3468 | } |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3469 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3470 | out_free: |
| 3471 | if (localpage) |
| 3472 | __free_page(localpage); |
| 3473 | return ret; |
| 3474 | } |
| 3475 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3476 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3477 | { |
| 3478 | struct nfs4_exception exception = { }; |
| 3479 | ssize_t ret; |
| 3480 | do { |
| 3481 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3482 | if (ret >= 0) |
| 3483 | break; |
| 3484 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3485 | } while (exception.retry); |
| 3486 | return ret; |
| 3487 | } |
| 3488 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3489 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3490 | { |
| 3491 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3492 | int ret; |
| 3493 | |
| 3494 | if (!nfs4_server_supports_acls(server)) |
| 3495 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3496 | ret = nfs_revalidate_inode(server, inode); |
| 3497 | if (ret < 0) |
| 3498 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3499 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3500 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3501 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3502 | if (ret != -ENOENT) |
| 3503 | return ret; |
| 3504 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3505 | } |
| 3506 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3507 | 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] | 3508 | { |
| 3509 | struct nfs_server *server = NFS_SERVER(inode); |
| 3510 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3511 | struct nfs_setaclargs arg = { |
| 3512 | .fh = NFS_FH(inode), |
| 3513 | .acl_pages = pages, |
| 3514 | .acl_len = buflen, |
| 3515 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3516 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3517 | struct rpc_message msg = { |
| 3518 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3519 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3520 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3521 | }; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3522 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3523 | |
| 3524 | if (!nfs4_server_supports_acls(server)) |
| 3525 | return -EOPNOTSUPP; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3526 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3527 | if (i < 0) |
| 3528 | return i; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3529 | nfs_inode_return_delegation(inode); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3530 | ret = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3531 | |
| 3532 | /* |
| 3533 | * Free each page after tx, so the only ref left is |
| 3534 | * held by the network stack |
| 3535 | */ |
| 3536 | for (; i > 0; i--) |
| 3537 | put_page(pages[i-1]); |
| 3538 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3539 | /* |
| 3540 | * Acl update can result in inode attribute update. |
| 3541 | * so mark the attribute cache invalid. |
| 3542 | */ |
| 3543 | spin_lock(&inode->i_lock); |
| 3544 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3545 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3546 | nfs_access_zap_cache(inode); |
| 3547 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3548 | return ret; |
| 3549 | } |
| 3550 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3551 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3552 | { |
| 3553 | struct nfs4_exception exception = { }; |
| 3554 | int err; |
| 3555 | do { |
| 3556 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3557 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3558 | &exception); |
| 3559 | } while (exception.retry); |
| 3560 | return err; |
| 3561 | } |
| 3562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3563 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3564 | 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] | 3565 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3566 | struct nfs_client *clp = server->nfs_client; |
| 3567 | |
| 3568 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3569 | return 0; |
| 3570 | switch(task->tk_status) { |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3571 | case -NFS4ERR_ADMIN_REVOKED: |
| 3572 | case -NFS4ERR_BAD_STATEID: |
| 3573 | case -NFS4ERR_OPENMODE: |
| 3574 | if (state == NULL) |
| 3575 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3576 | nfs4_schedule_stateid_recovery(server, state); |
| 3577 | goto wait_on_recovery; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3578 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3579 | case -NFS4ERR_STALE_CLIENTID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3580 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3581 | nfs4_schedule_lease_recovery(clp); |
| 3582 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3583 | #if defined(CONFIG_NFS_V4_1) |
| 3584 | case -NFS4ERR_BADSESSION: |
| 3585 | case -NFS4ERR_BADSLOT: |
| 3586 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3587 | case -NFS4ERR_DEADSESSION: |
| 3588 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3589 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3590 | case -NFS4ERR_SEQ_MISORDERED: |
| 3591 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3592 | task->tk_status); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3593 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3594 | task->tk_status = 0; |
| 3595 | return -EAGAIN; |
| 3596 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3597 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3598 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3599 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3600 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3601 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3602 | task->tk_status = 0; |
| 3603 | return -EAGAIN; |
| 3604 | case -NFS4ERR_OLD_STATEID: |
| 3605 | task->tk_status = 0; |
| 3606 | return -EAGAIN; |
| 3607 | } |
| 3608 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3609 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3610 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3611 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3612 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3613 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3614 | task->tk_status = 0; |
| 3615 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3616 | } |
| 3617 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3618 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 3619 | unsigned short port, struct rpc_cred *cred, |
| 3620 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3621 | { |
| 3622 | nfs4_verifier sc_verifier; |
| 3623 | struct nfs4_setclientid setclientid = { |
| 3624 | .sc_verifier = &sc_verifier, |
| 3625 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 3626 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3627 | }; |
| 3628 | struct rpc_message msg = { |
| 3629 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3630 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3631 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3632 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3633 | }; |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3634 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3635 | int loop = 0; |
| 3636 | int status; |
| 3637 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3638 | p = (__be32*)sc_verifier.data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3639 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 3640 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 3641 | |
| 3642 | for(;;) { |
| 3643 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3644 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3645 | clp->cl_ipaddr, |
| 3646 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3647 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3648 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3649 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3650 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3651 | clp->cl_id_uniquifier); |
| 3652 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3653 | sizeof(setclientid.sc_netid), |
| 3654 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3655 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3656 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3657 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3658 | clp->cl_ipaddr, port >> 8, port & 255); |
| 3659 | |
| 3660 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3661 | if (status != -NFS4ERR_CLID_INUSE) |
| 3662 | break; |
| 3663 | if (signalled()) |
| 3664 | break; |
| 3665 | if (loop++ & 1) |
J. Bruce Fields | 611c96c | 2010-12-13 19:05:46 -0500 | [diff] [blame] | 3666 | ssleep(clp->cl_lease_time / HZ + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3667 | else |
| 3668 | if (++clp->cl_id_uniquifier == 0) |
| 3669 | break; |
| 3670 | } |
| 3671 | return status; |
| 3672 | } |
| 3673 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3674 | static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
| 3675 | struct nfs4_setclientid_res *arg, |
| 3676 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3677 | { |
| 3678 | struct nfs_fsinfo fsinfo; |
| 3679 | struct rpc_message msg = { |
| 3680 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3681 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3682 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3683 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3684 | }; |
| 3685 | unsigned long now; |
| 3686 | int status; |
| 3687 | |
| 3688 | now = jiffies; |
| 3689 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3690 | if (status == 0) { |
| 3691 | spin_lock(&clp->cl_lock); |
| 3692 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 3693 | clp->cl_last_renewal = now; |
| 3694 | spin_unlock(&clp->cl_lock); |
| 3695 | } |
| 3696 | return status; |
| 3697 | } |
| 3698 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3699 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
| 3700 | struct nfs4_setclientid_res *arg, |
| 3701 | struct rpc_cred *cred) |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3702 | { |
Benny Halevy | 77e0367 | 2008-06-24 20:25:57 +0300 | [diff] [blame] | 3703 | long timeout = 0; |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3704 | int err; |
| 3705 | do { |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3706 | err = _nfs4_proc_setclientid_confirm(clp, arg, cred); |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3707 | switch (err) { |
| 3708 | case 0: |
| 3709 | return err; |
| 3710 | case -NFS4ERR_RESOURCE: |
| 3711 | /* The IBM lawyers misread another document! */ |
| 3712 | case -NFS4ERR_DELAY: |
| 3713 | err = nfs4_delay(clp->cl_rpcclient, &timeout); |
| 3714 | } |
| 3715 | } while (err == 0); |
| 3716 | return err; |
| 3717 | } |
| 3718 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3719 | struct nfs4_delegreturndata { |
| 3720 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3721 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3722 | struct nfs_fh fh; |
| 3723 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3724 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3725 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3726 | int rpc_status; |
| 3727 | }; |
| 3728 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3729 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 3730 | { |
| 3731 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3732 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3733 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3734 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3735 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3736 | switch (task->tk_status) { |
| 3737 | case -NFS4ERR_STALE_STATEID: |
| 3738 | case -NFS4ERR_EXPIRED: |
| 3739 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3740 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3741 | break; |
| 3742 | default: |
| 3743 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 3744 | -EAGAIN) { |
| 3745 | nfs_restart_rpc(task, data->res.server->nfs_client); |
| 3746 | return; |
| 3747 | } |
| 3748 | } |
| 3749 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3750 | } |
| 3751 | |
| 3752 | static void nfs4_delegreturn_release(void *calldata) |
| 3753 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3754 | kfree(calldata); |
| 3755 | } |
| 3756 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3757 | #if defined(CONFIG_NFS_V4_1) |
| 3758 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 3759 | { |
| 3760 | struct nfs4_delegreturndata *d_data; |
| 3761 | |
| 3762 | d_data = (struct nfs4_delegreturndata *)data; |
| 3763 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3764 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3765 | &d_data->args.seq_args, |
| 3766 | &d_data->res.seq_res, 1, task)) |
| 3767 | return; |
| 3768 | rpc_call_start(task); |
| 3769 | } |
| 3770 | #endif /* CONFIG_NFS_V4_1 */ |
| 3771 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 3772 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3773 | #if defined(CONFIG_NFS_V4_1) |
| 3774 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 3775 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3776 | .rpc_call_done = nfs4_delegreturn_done, |
| 3777 | .rpc_release = nfs4_delegreturn_release, |
| 3778 | }; |
| 3779 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3780 | 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] | 3781 | { |
| 3782 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3783 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3784 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3785 | struct rpc_message msg = { |
| 3786 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 3787 | .rpc_cred = cred, |
| 3788 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3789 | struct rpc_task_setup task_setup_data = { |
| 3790 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3791 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3792 | .callback_ops = &nfs4_delegreturn_ops, |
| 3793 | .flags = RPC_TASK_ASYNC, |
| 3794 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3795 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3796 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3797 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3798 | if (data == NULL) |
| 3799 | return -ENOMEM; |
| 3800 | data->args.fhandle = &data->fh; |
| 3801 | data->args.stateid = &data->stateid; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3802 | data->args.bitmask = server->attr_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3803 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
| 3804 | memcpy(&data->stateid, stateid, sizeof(data->stateid)); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3805 | data->res.fattr = &data->fattr; |
| 3806 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3807 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3808 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3809 | data->rpc_status = 0; |
| 3810 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3811 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3812 | msg.rpc_argp = &data->args; |
| 3813 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3814 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 3815 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3816 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3817 | if (!issync) |
| 3818 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3819 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3820 | if (status != 0) |
| 3821 | goto out; |
| 3822 | status = data->rpc_status; |
| 3823 | if (status != 0) |
| 3824 | goto out; |
| 3825 | nfs_refresh_inode(inode, &data->fattr); |
| 3826 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3827 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3828 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3829 | } |
| 3830 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3831 | 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] | 3832 | { |
| 3833 | struct nfs_server *server = NFS_SERVER(inode); |
| 3834 | struct nfs4_exception exception = { }; |
| 3835 | int err; |
| 3836 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3837 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3838 | switch (err) { |
| 3839 | case -NFS4ERR_STALE_STATEID: |
| 3840 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3841 | case 0: |
| 3842 | return 0; |
| 3843 | } |
| 3844 | err = nfs4_handle_exception(server, err, &exception); |
| 3845 | } while (exception.retry); |
| 3846 | return err; |
| 3847 | } |
| 3848 | |
| 3849 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 3850 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 3851 | |
| 3852 | /* |
| 3853 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 3854 | */ |
| 3855 | static unsigned long |
| 3856 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 3857 | { |
Matthew Wilcox | 150030b | 2007-12-06 16:24:39 -0500 | [diff] [blame] | 3858 | schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3859 | timeout <<= 1; |
| 3860 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 3861 | return NFS4_LOCK_MAXTIMEOUT; |
| 3862 | return timeout; |
| 3863 | } |
| 3864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3865 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3866 | { |
| 3867 | struct inode *inode = state->inode; |
| 3868 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3869 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3870 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3871 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3872 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3873 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3874 | struct nfs_lockt_res res = { |
| 3875 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3876 | }; |
| 3877 | struct rpc_message msg = { |
| 3878 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 3879 | .rpc_argp = &arg, |
| 3880 | .rpc_resp = &res, |
| 3881 | .rpc_cred = state->owner->so_cred, |
| 3882 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3883 | struct nfs4_lock_state *lsp; |
| 3884 | int status; |
| 3885 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3886 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3887 | status = nfs4_set_lock_state(state, request); |
| 3888 | if (status != 0) |
| 3889 | goto out; |
| 3890 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 3891 | arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 3892 | arg.lock_owner.s_dev = server->s_dev; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3893 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3894 | switch (status) { |
| 3895 | case 0: |
| 3896 | request->fl_type = F_UNLCK; |
| 3897 | break; |
| 3898 | case -NFS4ERR_DENIED: |
| 3899 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3900 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 3901 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3902 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3903 | return status; |
| 3904 | } |
| 3905 | |
| 3906 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3907 | { |
| 3908 | struct nfs4_exception exception = { }; |
| 3909 | int err; |
| 3910 | |
| 3911 | do { |
| 3912 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 3913 | _nfs4_proc_getlk(state, cmd, request), |
| 3914 | &exception); |
| 3915 | } while (exception.retry); |
| 3916 | return err; |
| 3917 | } |
| 3918 | |
| 3919 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 3920 | { |
| 3921 | int res = 0; |
| 3922 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 3923 | case FL_POSIX: |
| 3924 | res = posix_lock_file_wait(file, fl); |
| 3925 | break; |
| 3926 | case FL_FLOCK: |
| 3927 | res = flock_lock_file_wait(file, fl); |
| 3928 | break; |
| 3929 | default: |
| 3930 | BUG(); |
| 3931 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3932 | return res; |
| 3933 | } |
| 3934 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3935 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3936 | struct nfs_locku_args arg; |
| 3937 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3938 | struct nfs4_lock_state *lsp; |
| 3939 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3940 | struct file_lock fl; |
| 3941 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3942 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3943 | }; |
| 3944 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3945 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 3946 | struct nfs_open_context *ctx, |
| 3947 | struct nfs4_lock_state *lsp, |
| 3948 | struct nfs_seqid *seqid) |
| 3949 | { |
| 3950 | struct nfs4_unlockdata *p; |
| 3951 | struct inode *inode = lsp->ls_state->inode; |
| 3952 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3953 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3954 | if (p == NULL) |
| 3955 | return NULL; |
| 3956 | p->arg.fh = NFS_FH(inode); |
| 3957 | p->arg.fl = &p->fl; |
| 3958 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3959 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3960 | p->arg.stateid = &lsp->ls_stateid; |
| 3961 | p->lsp = lsp; |
| 3962 | atomic_inc(&lsp->ls_count); |
| 3963 | /* Ensure we don't close file until we're done freeing locks! */ |
| 3964 | p->ctx = get_nfs_open_context(ctx); |
| 3965 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 3966 | p->server = NFS_SERVER(inode); |
| 3967 | return p; |
| 3968 | } |
| 3969 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3970 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3971 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3972 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3973 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3974 | nfs4_put_lock_state(calldata->lsp); |
| 3975 | put_nfs_open_context(calldata->ctx); |
| 3976 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3977 | } |
| 3978 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3979 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3980 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3981 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3982 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3983 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3984 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3985 | switch (task->tk_status) { |
| 3986 | case 0: |
| 3987 | memcpy(calldata->lsp->ls_stateid.data, |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3988 | calldata->res.stateid.data, |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3989 | sizeof(calldata->lsp->ls_stateid.data)); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3990 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3991 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3992 | case -NFS4ERR_BAD_STATEID: |
| 3993 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3994 | case -NFS4ERR_STALE_STATEID: |
| 3995 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3996 | break; |
| 3997 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3998 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3999 | nfs_restart_rpc(task, |
Trond Myklebust | d61e612 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 4000 | calldata->server->nfs_client); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4001 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4002 | } |
| 4003 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4004 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4005 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4006 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4007 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4008 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4009 | return; |
| 4010 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4011 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4012 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4013 | return; |
| 4014 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4015 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4016 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4017 | &calldata->arg.seq_args, |
| 4018 | &calldata->res.seq_res, 1, task)) |
| 4019 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4020 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4021 | } |
| 4022 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4023 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4024 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4025 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4026 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4027 | }; |
| 4028 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4029 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4030 | struct nfs_open_context *ctx, |
| 4031 | struct nfs4_lock_state *lsp, |
| 4032 | struct nfs_seqid *seqid) |
| 4033 | { |
| 4034 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4035 | struct rpc_message msg = { |
| 4036 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4037 | .rpc_cred = ctx->cred, |
| 4038 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4039 | struct rpc_task_setup task_setup_data = { |
| 4040 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4041 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4042 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4043 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4044 | .flags = RPC_TASK_ASYNC, |
| 4045 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4046 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4047 | /* Ensure this is an unlock - when canceling a lock, the |
| 4048 | * canceled lock is passed in, and it won't be an unlock. |
| 4049 | */ |
| 4050 | fl->fl_type = F_UNLCK; |
| 4051 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4052 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4053 | if (data == NULL) { |
| 4054 | nfs_free_seqid(seqid); |
| 4055 | return ERR_PTR(-ENOMEM); |
| 4056 | } |
| 4057 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4058 | msg.rpc_argp = &data->arg; |
| 4059 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4060 | task_setup_data.callback_data = data; |
| 4061 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4062 | } |
| 4063 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4065 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4066 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4067 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4068 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4069 | struct rpc_task *task; |
| 4070 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4071 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4072 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4073 | status = nfs4_set_lock_state(state, request); |
| 4074 | /* Unlock _before_ we do the RPC call */ |
| 4075 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4076 | down_read(&nfsi->rwsem); |
| 4077 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4078 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4079 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4080 | } |
| 4081 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4082 | if (status != 0) |
| 4083 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4084 | /* Is this a delegated lock? */ |
| 4085 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4086 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4087 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4088 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4089 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4090 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4091 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4092 | 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] | 4093 | status = PTR_ERR(task); |
| 4094 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4095 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4096 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4097 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4098 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4099 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4100 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4101 | } |
| 4102 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4103 | struct nfs4_lockdata { |
| 4104 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4105 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4106 | struct nfs4_lock_state *lsp; |
| 4107 | struct nfs_open_context *ctx; |
| 4108 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4109 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4110 | int rpc_status; |
| 4111 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4112 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4113 | }; |
| 4114 | |
| 4115 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4116 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4117 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4118 | { |
| 4119 | struct nfs4_lockdata *p; |
| 4120 | struct inode *inode = lsp->ls_state->inode; |
| 4121 | struct nfs_server *server = NFS_SERVER(inode); |
| 4122 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4123 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4124 | if (p == NULL) |
| 4125 | return NULL; |
| 4126 | |
| 4127 | p->arg.fh = NFS_FH(inode); |
| 4128 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4129 | 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] | 4130 | if (p->arg.open_seqid == NULL) |
| 4131 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4132 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4133 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4134 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4135 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4136 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 4137 | p->arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4138 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4139 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4140 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4141 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4142 | atomic_inc(&lsp->ls_count); |
| 4143 | p->ctx = get_nfs_open_context(ctx); |
| 4144 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4145 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4146 | out_free_seqid: |
| 4147 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4148 | out_free: |
| 4149 | kfree(p); |
| 4150 | return NULL; |
| 4151 | } |
| 4152 | |
| 4153 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4154 | { |
| 4155 | struct nfs4_lockdata *data = calldata; |
| 4156 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4157 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4158 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4159 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4160 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4161 | /* Do we need to do an open_to_lock_owner? */ |
| 4162 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4163 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4164 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4165 | data->arg.open_stateid = &state->stateid; |
| 4166 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4167 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4168 | } else |
| 4169 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4170 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4171 | if (nfs4_setup_sequence(data->server, |
| 4172 | &data->arg.seq_args, |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4173 | &data->res.seq_res, 1, task)) |
| 4174 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4175 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4176 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4177 | } |
| 4178 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4179 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4180 | { |
| 4181 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4182 | nfs4_lock_prepare(task, calldata); |
| 4183 | } |
| 4184 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4185 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4186 | { |
| 4187 | struct nfs4_lockdata *data = calldata; |
| 4188 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4189 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4190 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4191 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4192 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4193 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4194 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4195 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4196 | if (data->rpc_status == 0) |
| 4197 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4198 | else |
| 4199 | goto out; |
| 4200 | } |
| 4201 | if (data->rpc_status == 0) { |
| 4202 | memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, |
| 4203 | sizeof(data->lsp->ls_stateid.data)); |
| 4204 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Trond Myklebust | 88be9f9 | 2007-06-05 10:42:27 -0400 | [diff] [blame] | 4205 | renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4206 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4207 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4208 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4209 | } |
| 4210 | |
| 4211 | static void nfs4_lock_release(void *calldata) |
| 4212 | { |
| 4213 | struct nfs4_lockdata *data = calldata; |
| 4214 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4215 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4216 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4217 | if (data->cancelled != 0) { |
| 4218 | struct rpc_task *task; |
| 4219 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4220 | data->arg.lock_seqid); |
| 4221 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4222 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4223 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4224 | } else |
| 4225 | nfs_free_seqid(data->arg.lock_seqid); |
| 4226 | nfs4_put_lock_state(data->lsp); |
| 4227 | put_nfs_open_context(data->ctx); |
| 4228 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4229 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4233 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4234 | .rpc_call_done = nfs4_lock_done, |
| 4235 | .rpc_release = nfs4_lock_release, |
| 4236 | }; |
| 4237 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4238 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4239 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4240 | .rpc_call_done = nfs4_lock_done, |
| 4241 | .rpc_release = nfs4_lock_release, |
| 4242 | }; |
| 4243 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4244 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4245 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4246 | switch (error) { |
| 4247 | case -NFS4ERR_ADMIN_REVOKED: |
| 4248 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4249 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4250 | if (new_lock_owner != 0 || |
| 4251 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4252 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4253 | break; |
| 4254 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4255 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4256 | case -NFS4ERR_EXPIRED: |
| 4257 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4258 | }; |
| 4259 | } |
| 4260 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4261 | 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] | 4262 | { |
| 4263 | struct nfs4_lockdata *data; |
| 4264 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4265 | struct rpc_message msg = { |
| 4266 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4267 | .rpc_cred = state->owner->so_cred, |
| 4268 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4269 | struct rpc_task_setup task_setup_data = { |
| 4270 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4271 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4272 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4273 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4274 | .flags = RPC_TASK_ASYNC, |
| 4275 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4276 | int ret; |
| 4277 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4278 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4279 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4280 | fl->fl_u.nfs4_fl.owner, |
| 4281 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4282 | if (data == NULL) |
| 4283 | return -ENOMEM; |
| 4284 | if (IS_SETLKW(cmd)) |
| 4285 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4286 | if (recovery_type > NFS_LOCK_NEW) { |
| 4287 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4288 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4289 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4290 | } |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4291 | msg.rpc_argp = &data->arg; |
| 4292 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4293 | task_setup_data.callback_data = data; |
| 4294 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4295 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4296 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4297 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4298 | if (ret == 0) { |
| 4299 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4300 | if (ret) |
| 4301 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4302 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4303 | } else |
| 4304 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4305 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4306 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4307 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4308 | } |
| 4309 | |
| 4310 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4311 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4312 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4313 | struct nfs4_exception exception = { }; |
| 4314 | int err; |
| 4315 | |
| 4316 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4317 | /* Cache the lock if possible... */ |
| 4318 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4319 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4320 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4321 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4322 | break; |
| 4323 | nfs4_handle_exception(server, err, &exception); |
| 4324 | } while (exception.retry); |
| 4325 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | } |
| 4327 | |
| 4328 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4329 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4330 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4331 | struct nfs4_exception exception = { }; |
| 4332 | int err; |
| 4333 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4334 | err = nfs4_set_lock_state(state, request); |
| 4335 | if (err != 0) |
| 4336 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4337 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4338 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4339 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4340 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4341 | switch (err) { |
| 4342 | default: |
| 4343 | goto out; |
| 4344 | case -NFS4ERR_GRACE: |
| 4345 | case -NFS4ERR_DELAY: |
| 4346 | nfs4_handle_exception(server, err, &exception); |
| 4347 | err = 0; |
| 4348 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4349 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4350 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4351 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4352 | } |
| 4353 | |
| 4354 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4355 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4356 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4357 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4358 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4359 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4360 | if ((fl_flags & FL_POSIX) && |
| 4361 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4362 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4363 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4364 | status = nfs4_set_lock_state(state, request); |
| 4365 | if (status != 0) |
| 4366 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4367 | request->fl_flags |= FL_ACCESS; |
| 4368 | status = do_vfs_lock(request->fl_file, request); |
| 4369 | if (status < 0) |
| 4370 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4371 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4372 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4373 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4374 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4375 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4376 | status = do_vfs_lock(request->fl_file, request); |
| 4377 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4378 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4379 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4380 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4381 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4382 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4383 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4384 | if (do_vfs_lock(request->fl_file, request) < 0) |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4385 | printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4386 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4387 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4388 | out: |
| 4389 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4390 | return status; |
| 4391 | } |
| 4392 | |
| 4393 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4394 | { |
| 4395 | struct nfs4_exception exception = { }; |
| 4396 | int err; |
| 4397 | |
| 4398 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4399 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4400 | if (err == -NFS4ERR_DENIED) |
| 4401 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4402 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4403 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4404 | } while (exception.retry); |
| 4405 | return err; |
| 4406 | } |
| 4407 | |
| 4408 | static int |
| 4409 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4410 | { |
| 4411 | struct nfs_open_context *ctx; |
| 4412 | struct nfs4_state *state; |
| 4413 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4414 | int status; |
| 4415 | |
| 4416 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4417 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4418 | state = ctx->state; |
| 4419 | |
| 4420 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4421 | return -EINVAL; |
| 4422 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4423 | if (IS_GETLK(cmd)) { |
| 4424 | if (state != NULL) |
| 4425 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4426 | return 0; |
| 4427 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | |
| 4429 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4430 | return -EINVAL; |
| 4431 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4432 | if (request->fl_type == F_UNLCK) { |
| 4433 | if (state != NULL) |
| 4434 | return nfs4_proc_unlck(state, cmd, request); |
| 4435 | return 0; |
| 4436 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4437 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4438 | if (state == NULL) |
| 4439 | return -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4440 | do { |
| 4441 | status = nfs4_proc_setlk(state, cmd, request); |
| 4442 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4443 | break; |
| 4444 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4445 | status = -ERESTARTSYS; |
| 4446 | if (signalled()) |
| 4447 | break; |
| 4448 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4449 | return status; |
| 4450 | } |
| 4451 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4452 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4453 | { |
| 4454 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4455 | struct nfs4_exception exception = { }; |
| 4456 | int err; |
| 4457 | |
| 4458 | err = nfs4_set_lock_state(state, fl); |
| 4459 | if (err != 0) |
| 4460 | goto out; |
| 4461 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4462 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4463 | switch (err) { |
| 4464 | default: |
| 4465 | printk(KERN_ERR "%s: unhandled error %d.\n", |
| 4466 | __func__, err); |
| 4467 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4468 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4469 | goto out; |
| 4470 | case -NFS4ERR_EXPIRED: |
| 4471 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4472 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4473 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4474 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4475 | case -NFS4ERR_BADSESSION: |
| 4476 | case -NFS4ERR_BADSLOT: |
| 4477 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4478 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4479 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4480 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4481 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4482 | case -ERESTARTSYS: |
| 4483 | /* |
| 4484 | * The show must go on: exit, but mark the |
| 4485 | * stateid as needing recovery. |
| 4486 | */ |
| 4487 | case -NFS4ERR_ADMIN_REVOKED: |
| 4488 | case -NFS4ERR_BAD_STATEID: |
| 4489 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4490 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4491 | err = 0; |
| 4492 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4493 | case -EKEYEXPIRED: |
| 4494 | /* |
| 4495 | * User RPCSEC_GSS context has expired. |
| 4496 | * We cannot recover this stateid now, so |
| 4497 | * skip it and allow recovery thread to |
| 4498 | * proceed. |
| 4499 | */ |
| 4500 | err = 0; |
| 4501 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4502 | case -ENOMEM: |
| 4503 | case -NFS4ERR_DENIED: |
| 4504 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4505 | err = 0; |
| 4506 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4507 | case -NFS4ERR_DELAY: |
| 4508 | break; |
| 4509 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4510 | err = nfs4_handle_exception(server, err, &exception); |
| 4511 | } while (exception.retry); |
| 4512 | out: |
| 4513 | return err; |
| 4514 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4515 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4516 | static void nfs4_release_lockowner_release(void *calldata) |
| 4517 | { |
| 4518 | kfree(calldata); |
| 4519 | } |
| 4520 | |
| 4521 | const struct rpc_call_ops nfs4_release_lockowner_ops = { |
| 4522 | .rpc_release = nfs4_release_lockowner_release, |
| 4523 | }; |
| 4524 | |
| 4525 | void nfs4_release_lockowner(const struct nfs4_lock_state *lsp) |
| 4526 | { |
| 4527 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
| 4528 | struct nfs_release_lockowner_args *args; |
| 4529 | struct rpc_message msg = { |
| 4530 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 4531 | }; |
| 4532 | |
| 4533 | if (server->nfs_client->cl_mvops->minor_version != 0) |
| 4534 | return; |
| 4535 | args = kmalloc(sizeof(*args), GFP_NOFS); |
| 4536 | if (!args) |
| 4537 | return; |
| 4538 | args->lock_owner.clientid = server->nfs_client->cl_clientid; |
| 4539 | args->lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4540 | args->lock_owner.s_dev = server->s_dev; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4541 | msg.rpc_argp = args; |
| 4542 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args); |
| 4543 | } |
| 4544 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4545 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4546 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4547 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 4548 | const void *buf, size_t buflen, |
| 4549 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4550 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4551 | if (strcmp(key, "") != 0) |
| 4552 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4553 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4554 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4555 | } |
| 4556 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4557 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 4558 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4559 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4560 | if (strcmp(key, "") != 0) |
| 4561 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4562 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4563 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4564 | } |
| 4565 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4566 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 4567 | size_t list_len, const char *name, |
| 4568 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4569 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4570 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4571 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4572 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4573 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4574 | |
| 4575 | if (list && len <= list_len) |
| 4576 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4577 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4578 | } |
| 4579 | |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4580 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4581 | { |
| 4582 | if (!((fattr->valid & NFS_ATTR_FATTR_FILEID) && |
| 4583 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
| 4584 | (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL))) |
| 4585 | return; |
| 4586 | |
| 4587 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 4588 | NFS_ATTR_FATTR_NLINK; |
| 4589 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4590 | fattr->nlink = 2; |
| 4591 | } |
| 4592 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 4593 | int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 4594 | struct nfs4_fs_locations *fs_locations, struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4595 | { |
| 4596 | struct nfs_server *server = NFS_SERVER(dir); |
| 4597 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4598 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 4599 | [1] = FATTR4_WORD1_MOUNTED_ON_FILEID, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4600 | }; |
| 4601 | struct nfs4_fs_locations_arg args = { |
| 4602 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4603 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4604 | .page = page, |
| 4605 | .bitmask = bitmask, |
| 4606 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4607 | struct nfs4_fs_locations_res res = { |
| 4608 | .fs_locations = fs_locations, |
| 4609 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4610 | struct rpc_message msg = { |
| 4611 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4612 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4613 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4614 | }; |
| 4615 | int status; |
| 4616 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4617 | dprintk("%s: start\n", __func__); |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4618 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4619 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 4620 | fs_locations->nlocations = 0; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 4621 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4622 | nfs_fixup_referral_attributes(&fs_locations->fattr); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4623 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4624 | return status; |
| 4625 | } |
| 4626 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4627 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4628 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4629 | * Check the exchange flags returned by the server for invalid flags, having |
| 4630 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 4631 | * DS flags set. |
| 4632 | */ |
| 4633 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 4634 | { |
| 4635 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 4636 | goto out_inval; |
| 4637 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 4638 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 4639 | goto out_inval; |
| 4640 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 4641 | goto out_inval; |
| 4642 | return NFS_OK; |
| 4643 | out_inval: |
| 4644 | return -NFS4ERR_INVAL; |
| 4645 | } |
| 4646 | |
| 4647 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4648 | * nfs4_proc_exchange_id() |
| 4649 | * |
| 4650 | * Since the clientid has expired, all compounds using sessions |
| 4651 | * associated with the stale clientid will be returning |
| 4652 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 4653 | * be in some phase of session reset. |
| 4654 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 4655 | 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] | 4656 | { |
| 4657 | nfs4_verifier verifier; |
| 4658 | struct nfs41_exchange_id_args args = { |
| 4659 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4660 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4661 | }; |
| 4662 | struct nfs41_exchange_id_res res = { |
| 4663 | .client = clp, |
| 4664 | }; |
| 4665 | int status; |
| 4666 | struct rpc_message msg = { |
| 4667 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 4668 | .rpc_argp = &args, |
| 4669 | .rpc_resp = &res, |
| 4670 | .rpc_cred = cred, |
| 4671 | }; |
| 4672 | __be32 *p; |
| 4673 | |
| 4674 | dprintk("--> %s\n", __func__); |
| 4675 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 4676 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4677 | p = (u32 *)verifier.data; |
| 4678 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 4679 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 4680 | args.verifier = &verifier; |
| 4681 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4682 | args.id_len = scnprintf(args.id, sizeof(args.id), |
| 4683 | "%s/%s.%s/%u", |
| 4684 | clp->cl_ipaddr, |
| 4685 | init_utsname()->nodename, |
| 4686 | init_utsname()->domainname, |
| 4687 | clp->cl_rpcclient->cl_auth->au_flavor); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4688 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4689 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 4690 | if (!status) |
| 4691 | status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4692 | dprintk("<-- %s status= %d\n", __func__, status); |
| 4693 | return status; |
| 4694 | } |
| 4695 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4696 | struct nfs4_get_lease_time_data { |
| 4697 | struct nfs4_get_lease_time_args *args; |
| 4698 | struct nfs4_get_lease_time_res *res; |
| 4699 | struct nfs_client *clp; |
| 4700 | }; |
| 4701 | |
| 4702 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 4703 | void *calldata) |
| 4704 | { |
| 4705 | int ret; |
| 4706 | struct nfs4_get_lease_time_data *data = |
| 4707 | (struct nfs4_get_lease_time_data *)calldata; |
| 4708 | |
| 4709 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4710 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4711 | /* just setup sequence, do not trigger session recovery |
| 4712 | since we're invoked within one */ |
| 4713 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4714 | &data->args->la_seq_args, |
| 4715 | &data->res->lr_seq_res, 0, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4716 | |
| 4717 | BUG_ON(ret == -EAGAIN); |
| 4718 | rpc_call_start(task); |
| 4719 | dprintk("<-- %s\n", __func__); |
| 4720 | } |
| 4721 | |
| 4722 | /* |
| 4723 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 4724 | * from sequence operation or clientid errors. |
| 4725 | */ |
| 4726 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 4727 | { |
| 4728 | struct nfs4_get_lease_time_data *data = |
| 4729 | (struct nfs4_get_lease_time_data *)calldata; |
| 4730 | |
| 4731 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4732 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 4733 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4734 | switch (task->tk_status) { |
| 4735 | case -NFS4ERR_DELAY: |
| 4736 | case -NFS4ERR_GRACE: |
| 4737 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 4738 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 4739 | task->tk_status = 0; |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 4740 | nfs_restart_rpc(task, data->clp); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4741 | return; |
| 4742 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4743 | dprintk("<-- %s\n", __func__); |
| 4744 | } |
| 4745 | |
| 4746 | struct rpc_call_ops nfs4_get_lease_time_ops = { |
| 4747 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 4748 | .rpc_call_done = nfs4_get_lease_time_done, |
| 4749 | }; |
| 4750 | |
| 4751 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 4752 | { |
| 4753 | struct rpc_task *task; |
| 4754 | struct nfs4_get_lease_time_args args; |
| 4755 | struct nfs4_get_lease_time_res res = { |
| 4756 | .lr_fsinfo = fsinfo, |
| 4757 | }; |
| 4758 | struct nfs4_get_lease_time_data data = { |
| 4759 | .args = &args, |
| 4760 | .res = &res, |
| 4761 | .clp = clp, |
| 4762 | }; |
| 4763 | struct rpc_message msg = { |
| 4764 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 4765 | .rpc_argp = &args, |
| 4766 | .rpc_resp = &res, |
| 4767 | }; |
| 4768 | struct rpc_task_setup task_setup = { |
| 4769 | .rpc_client = clp->cl_rpcclient, |
| 4770 | .rpc_message = &msg, |
| 4771 | .callback_ops = &nfs4_get_lease_time_ops, |
| 4772 | .callback_data = &data |
| 4773 | }; |
| 4774 | int status; |
| 4775 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4776 | dprintk("--> %s\n", __func__); |
| 4777 | task = rpc_run_task(&task_setup); |
| 4778 | |
| 4779 | if (IS_ERR(task)) |
| 4780 | status = PTR_ERR(task); |
| 4781 | else { |
| 4782 | status = task->tk_status; |
| 4783 | rpc_put_task(task); |
| 4784 | } |
| 4785 | dprintk("<-- %s return %d\n", __func__, status); |
| 4786 | |
| 4787 | return status; |
| 4788 | } |
| 4789 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4790 | /* |
| 4791 | * Reset a slot table |
| 4792 | */ |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4793 | static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 4794 | int ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4795 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4796 | struct nfs4_slot *new = NULL; |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4797 | int i; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4798 | int ret = 0; |
| 4799 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4800 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 4801 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4802 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4803 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 4804 | if (max_reqs != tbl->max_slots) { |
| 4805 | ret = -ENOMEM; |
| 4806 | new = kmalloc(max_reqs * sizeof(struct nfs4_slot), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4807 | GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4808 | if (!new) |
| 4809 | goto out; |
| 4810 | ret = 0; |
| 4811 | kfree(tbl->slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4812 | } |
| 4813 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4814 | if (new) { |
| 4815 | tbl->slots = new; |
| 4816 | tbl->max_slots = max_reqs; |
| 4817 | } |
| 4818 | for (i = 0; i < tbl->max_slots; ++i) |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4819 | tbl->slots[i].seq_nr = ivalue; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4820 | spin_unlock(&tbl->slot_tbl_lock); |
| 4821 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4822 | tbl, tbl->slots, tbl->max_slots); |
| 4823 | out: |
| 4824 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4825 | return ret; |
| 4826 | } |
| 4827 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4828 | /* |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4829 | * Reset the forechannel and backchannel slot tables |
| 4830 | */ |
| 4831 | static int nfs4_reset_slot_tables(struct nfs4_session *session) |
| 4832 | { |
| 4833 | int status; |
| 4834 | |
| 4835 | status = nfs4_reset_slot_table(&session->fc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4836 | session->fc_attrs.max_reqs, 1); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4837 | if (status) |
| 4838 | return status; |
| 4839 | |
| 4840 | status = nfs4_reset_slot_table(&session->bc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4841 | session->bc_attrs.max_reqs, 0); |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4842 | return status; |
| 4843 | } |
| 4844 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4845 | /* Destroy the slot table */ |
| 4846 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 4847 | { |
| 4848 | if (session->fc_slot_table.slots != NULL) { |
| 4849 | kfree(session->fc_slot_table.slots); |
| 4850 | session->fc_slot_table.slots = NULL; |
| 4851 | } |
| 4852 | if (session->bc_slot_table.slots != NULL) { |
| 4853 | kfree(session->bc_slot_table.slots); |
| 4854 | session->bc_slot_table.slots = NULL; |
| 4855 | } |
| 4856 | return; |
| 4857 | } |
| 4858 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4859 | /* |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4860 | * Initialize slot table |
| 4861 | */ |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4862 | static int nfs4_init_slot_table(struct nfs4_slot_table *tbl, |
| 4863 | int max_slots, int ivalue) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4864 | { |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4865 | struct nfs4_slot *slot; |
| 4866 | int ret = -ENOMEM; |
| 4867 | |
| 4868 | BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE); |
| 4869 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4870 | dprintk("--> %s: max_reqs=%u\n", __func__, max_slots); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4871 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4872 | slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4873 | if (!slot) |
| 4874 | goto out; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4875 | ret = 0; |
| 4876 | |
| 4877 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4878 | tbl->max_slots = max_slots; |
| 4879 | tbl->slots = slot; |
| 4880 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 4881 | spin_unlock(&tbl->slot_tbl_lock); |
| 4882 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4883 | tbl, tbl->slots, tbl->max_slots); |
| 4884 | out: |
| 4885 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4886 | return ret; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4887 | } |
| 4888 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4889 | /* |
| 4890 | * Initialize the forechannel and backchannel tables |
| 4891 | */ |
| 4892 | static int nfs4_init_slot_tables(struct nfs4_session *session) |
| 4893 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4894 | struct nfs4_slot_table *tbl; |
| 4895 | int status = 0; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4896 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4897 | tbl = &session->fc_slot_table; |
| 4898 | if (tbl->slots == NULL) { |
| 4899 | status = nfs4_init_slot_table(tbl, |
| 4900 | session->fc_attrs.max_reqs, 1); |
| 4901 | if (status) |
| 4902 | return status; |
| 4903 | } |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4904 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4905 | tbl = &session->bc_slot_table; |
| 4906 | if (tbl->slots == NULL) { |
| 4907 | status = nfs4_init_slot_table(tbl, |
| 4908 | session->bc_attrs.max_reqs, 0); |
| 4909 | if (status) |
| 4910 | nfs4_destroy_slot_tables(session); |
| 4911 | } |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4912 | |
| 4913 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4914 | } |
| 4915 | |
| 4916 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 4917 | { |
| 4918 | struct nfs4_session *session; |
| 4919 | struct nfs4_slot_table *tbl; |
| 4920 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4921 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4922 | if (!session) |
| 4923 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 4924 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4925 | tbl = &session->fc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 4926 | tbl->highest_used_slotid = -1; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4927 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4928 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 4929 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4930 | |
| 4931 | tbl = &session->bc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 4932 | tbl->highest_used_slotid = -1; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4933 | spin_lock_init(&tbl->slot_tbl_lock); |
| 4934 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 4935 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4936 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 4937 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 4938 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4939 | session->clp = clp; |
| 4940 | return session; |
| 4941 | } |
| 4942 | |
| 4943 | void nfs4_destroy_session(struct nfs4_session *session) |
| 4944 | { |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 4945 | nfs4_proc_destroy_session(session); |
| 4946 | dprintk("%s Destroy backchannel for xprt %p\n", |
| 4947 | __func__, session->clp->cl_rpcclient->cl_xprt); |
| 4948 | xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt, |
| 4949 | NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4950 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4951 | kfree(session); |
| 4952 | } |
| 4953 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4954 | /* |
| 4955 | * Initialize the values to be used by the client in CREATE_SESSION |
| 4956 | * If nfs4_init_session set the fore channel request and response sizes, |
| 4957 | * use them. |
| 4958 | * |
| 4959 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 4960 | * always set csa_cachethis to FALSE because the current implementation |
| 4961 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 4962 | */ |
| 4963 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 4964 | { |
| 4965 | struct nfs4_session *session = args->client->cl_session; |
| 4966 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 4967 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 4968 | |
| 4969 | if (mxrqst_sz == 0) |
| 4970 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 4971 | if (mxresp_sz == 0) |
| 4972 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 4973 | /* Fore channel attributes */ |
| 4974 | args->fc_attrs.headerpadsz = 0; |
| 4975 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 4976 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4977 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
| 4978 | args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs; |
| 4979 | |
| 4980 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 4981 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4982 | __func__, |
| 4983 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 4984 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4985 | |
| 4986 | /* Back channel attributes */ |
| 4987 | args->bc_attrs.headerpadsz = 0; |
| 4988 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 4989 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 4990 | args->bc_attrs.max_resp_sz_cached = 0; |
| 4991 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 4992 | args->bc_attrs.max_reqs = 1; |
| 4993 | |
| 4994 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 4995 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 4996 | __func__, |
| 4997 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 4998 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 4999 | args->bc_attrs.max_reqs); |
| 5000 | } |
| 5001 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5002 | 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] | 5003 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5004 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5005 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5006 | |
| 5007 | if (rcvd->headerpadsz > sent->headerpadsz) |
| 5008 | return -EINVAL; |
| 5009 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5010 | return -EINVAL; |
| 5011 | /* |
| 5012 | * Our requested max_ops is the minimum we need; we're not |
| 5013 | * prepared to break up compounds into smaller pieces than that. |
| 5014 | * So, no point even trying to continue if the server won't |
| 5015 | * cooperate: |
| 5016 | */ |
| 5017 | if (rcvd->max_ops < sent->max_ops) |
| 5018 | return -EINVAL; |
| 5019 | if (rcvd->max_reqs == 0) |
| 5020 | return -EINVAL; |
| 5021 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5022 | } |
| 5023 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5024 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5025 | { |
| 5026 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5027 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5028 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5029 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5030 | return -EINVAL; |
| 5031 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5032 | return -EINVAL; |
| 5033 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5034 | return -EINVAL; |
| 5035 | /* These would render the backchannel useless: */ |
| 5036 | if (rcvd->max_ops == 0) |
| 5037 | return -EINVAL; |
| 5038 | if (rcvd->max_reqs == 0) |
| 5039 | return -EINVAL; |
| 5040 | return 0; |
| 5041 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5042 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5043 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5044 | struct nfs4_session *session) |
| 5045 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5046 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5047 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5048 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5049 | if (ret) |
| 5050 | return ret; |
| 5051 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5052 | } |
| 5053 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5054 | static int _nfs4_proc_create_session(struct nfs_client *clp) |
| 5055 | { |
| 5056 | struct nfs4_session *session = clp->cl_session; |
| 5057 | struct nfs41_create_session_args args = { |
| 5058 | .client = clp, |
| 5059 | .cb_program = NFS4_CALLBACK, |
| 5060 | }; |
| 5061 | struct nfs41_create_session_res res = { |
| 5062 | .client = clp, |
| 5063 | }; |
| 5064 | struct rpc_message msg = { |
| 5065 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5066 | .rpc_argp = &args, |
| 5067 | .rpc_resp = &res, |
| 5068 | }; |
| 5069 | int status; |
| 5070 | |
| 5071 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5072 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5073 | |
| 5074 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); |
| 5075 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5076 | if (!status) |
| 5077 | /* Verify the session's negotiated channel_attrs values */ |
| 5078 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5079 | if (!status) { |
| 5080 | /* Increment the clientid slot sequence id */ |
| 5081 | clp->cl_seqid++; |
| 5082 | } |
| 5083 | |
| 5084 | return status; |
| 5085 | } |
| 5086 | |
| 5087 | /* |
| 5088 | * Issues a CREATE_SESSION operation to the server. |
| 5089 | * It is the responsibility of the caller to verify the session is |
| 5090 | * expired before calling this routine. |
| 5091 | */ |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5092 | int nfs4_proc_create_session(struct nfs_client *clp) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5093 | { |
| 5094 | int status; |
| 5095 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5096 | struct nfs4_session *session = clp->cl_session; |
Ricardo Labiaga | 7d6d63d | 2011-03-09 13:13:44 -0500 | [diff] [blame] | 5097 | long timeout = 0; |
| 5098 | int err; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5099 | |
| 5100 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5101 | |
Ricardo Labiaga | 7d6d63d | 2011-03-09 13:13:44 -0500 | [diff] [blame] | 5102 | do { |
| 5103 | status = _nfs4_proc_create_session(clp); |
| 5104 | if (status == -NFS4ERR_DELAY) { |
| 5105 | err = nfs4_delay(clp->cl_rpcclient, &timeout); |
| 5106 | if (err) |
| 5107 | status = err; |
| 5108 | } |
| 5109 | } while (status == -NFS4ERR_DELAY); |
| 5110 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5111 | if (status) |
| 5112 | goto out; |
| 5113 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5114 | /* Init and reset the fore channel */ |
| 5115 | status = nfs4_init_slot_tables(session); |
| 5116 | dprintk("slot table initialization returned %d\n", status); |
| 5117 | if (status) |
| 5118 | goto out; |
| 5119 | status = nfs4_reset_slot_tables(session); |
| 5120 | dprintk("slot table reset returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5121 | if (status) |
| 5122 | goto out; |
| 5123 | |
| 5124 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5125 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5126 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5127 | out: |
| 5128 | dprintk("<-- %s\n", __func__); |
| 5129 | return status; |
| 5130 | } |
| 5131 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5132 | /* |
| 5133 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5134 | * The caller must serialize access to this routine. |
| 5135 | */ |
| 5136 | int nfs4_proc_destroy_session(struct nfs4_session *session) |
| 5137 | { |
| 5138 | int status = 0; |
| 5139 | struct rpc_message msg; |
| 5140 | |
| 5141 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5142 | |
| 5143 | /* session is still being setup */ |
| 5144 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5145 | return status; |
| 5146 | |
| 5147 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; |
| 5148 | msg.rpc_argp = session; |
| 5149 | msg.rpc_resp = NULL; |
| 5150 | msg.rpc_cred = NULL; |
| 5151 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); |
| 5152 | |
| 5153 | if (status) |
| 5154 | printk(KERN_WARNING |
| 5155 | "Got error %d from the server on DESTROY_SESSION. " |
| 5156 | "Session has been destroyed regardless...\n", status); |
| 5157 | |
| 5158 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5159 | return status; |
| 5160 | } |
| 5161 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5162 | int nfs4_init_session(struct nfs_server *server) |
| 5163 | { |
| 5164 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5165 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5166 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5167 | int ret; |
| 5168 | |
| 5169 | if (!nfs4_has_session(clp)) |
| 5170 | return 0; |
| 5171 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5172 | session = clp->cl_session; |
| 5173 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5174 | return 0; |
| 5175 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5176 | rsize = server->rsize; |
| 5177 | if (rsize == 0) |
| 5178 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5179 | wsize = server->wsize; |
| 5180 | if (wsize == 0) |
| 5181 | wsize = NFS_MAX_FILE_IO_SIZE; |
| 5182 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5183 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5184 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5185 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5186 | ret = nfs4_recover_expired_lease(server); |
| 5187 | if (!ret) |
| 5188 | ret = nfs4_check_client_ready(clp); |
| 5189 | return ret; |
| 5190 | } |
| 5191 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5192 | int nfs4_init_ds_session(struct nfs_client *clp) |
| 5193 | { |
| 5194 | struct nfs4_session *session = clp->cl_session; |
| 5195 | int ret; |
| 5196 | |
| 5197 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5198 | return 0; |
| 5199 | |
| 5200 | ret = nfs4_client_recover_expired_lease(clp); |
| 5201 | if (!ret) |
| 5202 | /* Test for the DS role */ |
| 5203 | if (!is_ds_client(clp)) |
| 5204 | ret = -ENODEV; |
| 5205 | if (!ret) |
| 5206 | ret = nfs4_check_client_ready(clp); |
| 5207 | return ret; |
| 5208 | |
| 5209 | } |
| 5210 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 5211 | |
| 5212 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5213 | /* |
| 5214 | * Renew the cl_session lease. |
| 5215 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5216 | struct nfs4_sequence_data { |
| 5217 | struct nfs_client *clp; |
| 5218 | struct nfs4_sequence_args args; |
| 5219 | struct nfs4_sequence_res res; |
| 5220 | }; |
| 5221 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5222 | static void nfs41_sequence_release(void *data) |
| 5223 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5224 | struct nfs4_sequence_data *calldata = data; |
| 5225 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5226 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5227 | if (atomic_read(&clp->cl_count) > 1) |
| 5228 | nfs4_schedule_state_renewal(clp); |
| 5229 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5230 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5231 | } |
| 5232 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5233 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5234 | { |
| 5235 | switch(task->tk_status) { |
| 5236 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5237 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5238 | return -EAGAIN; |
| 5239 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5240 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5241 | } |
| 5242 | return 0; |
| 5243 | } |
| 5244 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5245 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5246 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5247 | struct nfs4_sequence_data *calldata = data; |
| 5248 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5249 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5250 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5251 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5252 | |
| 5253 | if (task->tk_status < 0) { |
| 5254 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5255 | if (atomic_read(&clp->cl_count) == 1) |
| 5256 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5257 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5258 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5259 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5260 | return; |
| 5261 | } |
| 5262 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5263 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5264 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5265 | dprintk("<-- %s\n", __func__); |
| 5266 | } |
| 5267 | |
| 5268 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5269 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5270 | struct nfs4_sequence_data *calldata = data; |
| 5271 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5272 | struct nfs4_sequence_args *args; |
| 5273 | struct nfs4_sequence_res *res; |
| 5274 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5275 | args = task->tk_msg.rpc_argp; |
| 5276 | res = task->tk_msg.rpc_resp; |
| 5277 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5278 | if (nfs41_setup_sequence(clp->cl_session, args, res, 0, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5279 | return; |
| 5280 | rpc_call_start(task); |
| 5281 | } |
| 5282 | |
| 5283 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5284 | .rpc_call_done = nfs41_sequence_call_done, |
| 5285 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5286 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5287 | }; |
| 5288 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5289 | 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] | 5290 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5291 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5292 | struct rpc_message msg = { |
| 5293 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5294 | .rpc_cred = cred, |
| 5295 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5296 | struct rpc_task_setup task_setup_data = { |
| 5297 | .rpc_client = clp->cl_rpcclient, |
| 5298 | .rpc_message = &msg, |
| 5299 | .callback_ops = &nfs41_sequence_ops, |
| 5300 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5301 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5302 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5303 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5304 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5305 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5306 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5307 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5308 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5309 | } |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5310 | msg.rpc_argp = &calldata->args; |
| 5311 | msg.rpc_resp = &calldata->res; |
| 5312 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5313 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5314 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5315 | return rpc_run_task(&task_setup_data); |
| 5316 | } |
| 5317 | |
| 5318 | static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5319 | { |
| 5320 | struct rpc_task *task; |
| 5321 | int ret = 0; |
| 5322 | |
| 5323 | task = _nfs41_proc_sequence(clp, cred); |
| 5324 | if (IS_ERR(task)) |
| 5325 | ret = PTR_ERR(task); |
| 5326 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5327 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5328 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5329 | return ret; |
| 5330 | } |
| 5331 | |
| 5332 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5333 | { |
| 5334 | struct rpc_task *task; |
| 5335 | int ret; |
| 5336 | |
| 5337 | task = _nfs41_proc_sequence(clp, cred); |
| 5338 | if (IS_ERR(task)) { |
| 5339 | ret = PTR_ERR(task); |
| 5340 | goto out; |
| 5341 | } |
| 5342 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5343 | if (!ret) { |
| 5344 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5345 | |
| 5346 | if (task->tk_status == 0) |
| 5347 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5348 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5349 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5350 | rpc_put_task(task); |
| 5351 | out: |
| 5352 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5353 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5354 | } |
| 5355 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5356 | struct nfs4_reclaim_complete_data { |
| 5357 | struct nfs_client *clp; |
| 5358 | struct nfs41_reclaim_complete_args arg; |
| 5359 | struct nfs41_reclaim_complete_res res; |
| 5360 | }; |
| 5361 | |
| 5362 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5363 | { |
| 5364 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5365 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5366 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5367 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5368 | &calldata->arg.seq_args, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5369 | &calldata->res.seq_res, 0, task)) |
| 5370 | return; |
| 5371 | |
| 5372 | rpc_call_start(task); |
| 5373 | } |
| 5374 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5375 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5376 | { |
| 5377 | switch(task->tk_status) { |
| 5378 | case 0: |
| 5379 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5380 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5381 | break; |
| 5382 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5383 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5384 | return -EAGAIN; |
| 5385 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5386 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5387 | } |
| 5388 | return 0; |
| 5389 | } |
| 5390 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5391 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5392 | { |
| 5393 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5394 | struct nfs_client *clp = calldata->clp; |
| 5395 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5396 | |
| 5397 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5398 | if (!nfs41_sequence_done(task, res)) |
| 5399 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5400 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5401 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5402 | rpc_restart_call_prepare(task); |
| 5403 | return; |
| 5404 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5405 | dprintk("<-- %s\n", __func__); |
| 5406 | } |
| 5407 | |
| 5408 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5409 | { |
| 5410 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5411 | |
| 5412 | kfree(calldata); |
| 5413 | } |
| 5414 | |
| 5415 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5416 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5417 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5418 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5419 | }; |
| 5420 | |
| 5421 | /* |
| 5422 | * Issue a global reclaim complete. |
| 5423 | */ |
| 5424 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5425 | { |
| 5426 | struct nfs4_reclaim_complete_data *calldata; |
| 5427 | struct rpc_task *task; |
| 5428 | struct rpc_message msg = { |
| 5429 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5430 | }; |
| 5431 | struct rpc_task_setup task_setup_data = { |
| 5432 | .rpc_client = clp->cl_rpcclient, |
| 5433 | .rpc_message = &msg, |
| 5434 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5435 | .flags = RPC_TASK_ASYNC, |
| 5436 | }; |
| 5437 | int status = -ENOMEM; |
| 5438 | |
| 5439 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5440 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5441 | if (calldata == NULL) |
| 5442 | goto out; |
| 5443 | calldata->clp = clp; |
| 5444 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5445 | |
| 5446 | msg.rpc_argp = &calldata->arg; |
| 5447 | msg.rpc_resp = &calldata->res; |
| 5448 | task_setup_data.callback_data = calldata; |
| 5449 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5450 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5451 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5452 | goto out; |
| 5453 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 5454 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5455 | if (status == 0) |
| 5456 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5457 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5458 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5459 | out: |
| 5460 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5461 | return status; |
| 5462 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5463 | |
| 5464 | static void |
| 5465 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 5466 | { |
| 5467 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5468 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5469 | |
| 5470 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5471 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 5472 | * right now covering the LAYOUTGET we are about to send. |
| 5473 | * However, that is not so catastrophic, and there seems |
| 5474 | * to be no way to prevent it completely. |
| 5475 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5476 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
| 5477 | &lgp->res.seq_res, 0, task)) |
| 5478 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5479 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 5480 | NFS_I(lgp->args.inode)->layout, |
| 5481 | lgp->args.ctx->state)) { |
| 5482 | rpc_exit(task, NFS4_OK); |
| 5483 | return; |
| 5484 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5485 | rpc_call_start(task); |
| 5486 | } |
| 5487 | |
| 5488 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 5489 | { |
| 5490 | struct nfs4_layoutget *lgp = calldata; |
| 5491 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5492 | |
| 5493 | dprintk("--> %s\n", __func__); |
| 5494 | |
| 5495 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 5496 | return; |
| 5497 | |
| 5498 | switch (task->tk_status) { |
| 5499 | case 0: |
| 5500 | break; |
| 5501 | case -NFS4ERR_LAYOUTTRYLATER: |
| 5502 | case -NFS4ERR_RECALLCONFLICT: |
| 5503 | task->tk_status = -NFS4ERR_DELAY; |
| 5504 | /* Fall through */ |
| 5505 | default: |
| 5506 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5507 | rpc_restart_call_prepare(task); |
| 5508 | return; |
| 5509 | } |
| 5510 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5511 | dprintk("<-- %s\n", __func__); |
| 5512 | } |
| 5513 | |
| 5514 | static void nfs4_layoutget_release(void *calldata) |
| 5515 | { |
| 5516 | struct nfs4_layoutget *lgp = calldata; |
| 5517 | |
| 5518 | dprintk("--> %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5519 | if (lgp->res.layout.buf != NULL) |
| 5520 | free_page((unsigned long) lgp->res.layout.buf); |
| 5521 | put_nfs_open_context(lgp->args.ctx); |
| 5522 | kfree(calldata); |
| 5523 | dprintk("<-- %s\n", __func__); |
| 5524 | } |
| 5525 | |
| 5526 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 5527 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 5528 | .rpc_call_done = nfs4_layoutget_done, |
| 5529 | .rpc_release = nfs4_layoutget_release, |
| 5530 | }; |
| 5531 | |
| 5532 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) |
| 5533 | { |
| 5534 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5535 | struct rpc_task *task; |
| 5536 | struct rpc_message msg = { |
| 5537 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 5538 | .rpc_argp = &lgp->args, |
| 5539 | .rpc_resp = &lgp->res, |
| 5540 | }; |
| 5541 | struct rpc_task_setup task_setup_data = { |
| 5542 | .rpc_client = server->client, |
| 5543 | .rpc_message = &msg, |
| 5544 | .callback_ops = &nfs4_layoutget_call_ops, |
| 5545 | .callback_data = lgp, |
| 5546 | .flags = RPC_TASK_ASYNC, |
| 5547 | }; |
| 5548 | int status = 0; |
| 5549 | |
| 5550 | dprintk("--> %s\n", __func__); |
| 5551 | |
| 5552 | lgp->res.layout.buf = (void *)__get_free_page(GFP_NOFS); |
| 5553 | if (lgp->res.layout.buf == NULL) { |
| 5554 | nfs4_layoutget_release(lgp); |
| 5555 | return -ENOMEM; |
| 5556 | } |
| 5557 | |
| 5558 | lgp->res.seq_res.sr_slot = NULL; |
| 5559 | task = rpc_run_task(&task_setup_data); |
| 5560 | if (IS_ERR(task)) |
| 5561 | return PTR_ERR(task); |
| 5562 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5563 | if (status == 0) |
| 5564 | status = task->tk_status; |
| 5565 | if (status == 0) |
| 5566 | status = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5567 | rpc_put_task(task); |
| 5568 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5569 | return status; |
| 5570 | } |
| 5571 | |
| 5572 | static int |
| 5573 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5574 | { |
| 5575 | struct nfs4_getdeviceinfo_args args = { |
| 5576 | .pdev = pdev, |
| 5577 | }; |
| 5578 | struct nfs4_getdeviceinfo_res res = { |
| 5579 | .pdev = pdev, |
| 5580 | }; |
| 5581 | struct rpc_message msg = { |
| 5582 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 5583 | .rpc_argp = &args, |
| 5584 | .rpc_resp = &res, |
| 5585 | }; |
| 5586 | int status; |
| 5587 | |
| 5588 | dprintk("--> %s\n", __func__); |
| 5589 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
| 5590 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5591 | |
| 5592 | return status; |
| 5593 | } |
| 5594 | |
| 5595 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5596 | { |
| 5597 | struct nfs4_exception exception = { }; |
| 5598 | int err; |
| 5599 | |
| 5600 | do { |
| 5601 | err = nfs4_handle_exception(server, |
| 5602 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 5603 | &exception); |
| 5604 | } while (exception.retry); |
| 5605 | return err; |
| 5606 | } |
| 5607 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 5608 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5609 | #endif /* CONFIG_NFS_V4_1 */ |
| 5610 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5611 | struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5612 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5613 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5614 | .recover_open = nfs4_open_reclaim, |
| 5615 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5616 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5617 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5618 | }; |
| 5619 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5620 | #if defined(CONFIG_NFS_V4_1) |
| 5621 | struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
| 5622 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 5623 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 5624 | .recover_open = nfs4_open_reclaim, |
| 5625 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5626 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5627 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5628 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5629 | }; |
| 5630 | #endif /* CONFIG_NFS_V4_1 */ |
| 5631 | |
| 5632 | struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5633 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5634 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5635 | .recover_open = nfs4_open_expired, |
| 5636 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5637 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5638 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5639 | }; |
| 5640 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5641 | #if defined(CONFIG_NFS_V4_1) |
| 5642 | struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
| 5643 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 5644 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
| 5645 | .recover_open = nfs4_open_expired, |
| 5646 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5647 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5648 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5649 | }; |
| 5650 | #endif /* CONFIG_NFS_V4_1 */ |
| 5651 | |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5652 | struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
| 5653 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5654 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5655 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5656 | }; |
| 5657 | |
| 5658 | #if defined(CONFIG_NFS_V4_1) |
| 5659 | struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
| 5660 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5661 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5662 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5663 | }; |
| 5664 | #endif |
| 5665 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5666 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 5667 | .minor_version = 0, |
| 5668 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5669 | .validate_stateid = nfs4_validate_delegation_stateid, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5670 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 5671 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 5672 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5673 | }; |
| 5674 | |
| 5675 | #if defined(CONFIG_NFS_V4_1) |
| 5676 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 5677 | .minor_version = 1, |
| 5678 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5679 | .validate_stateid = nfs41_validate_delegation_stateid, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5680 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 5681 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 5682 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5683 | }; |
| 5684 | #endif |
| 5685 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5686 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 5687 | [0] = &nfs_v4_0_minor_ops, |
| 5688 | #if defined(CONFIG_NFS_V4_1) |
| 5689 | [1] = &nfs_v4_1_minor_ops, |
| 5690 | #endif |
| 5691 | }; |
| 5692 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 5693 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5694 | .permission = nfs_permission, |
| 5695 | .getattr = nfs_getattr, |
| 5696 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5697 | .getxattr = generic_getxattr, |
| 5698 | .setxattr = generic_setxattr, |
| 5699 | .listxattr = generic_listxattr, |
| 5700 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5701 | }; |
| 5702 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 5703 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5704 | .version = 4, /* protocol version */ |
| 5705 | .dentry_ops = &nfs4_dentry_operations, |
| 5706 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5707 | .file_inode_ops = &nfs4_file_inode_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5708 | .getroot = nfs4_proc_get_root, |
| 5709 | .getattr = nfs4_proc_getattr, |
| 5710 | .setattr = nfs4_proc_setattr, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5711 | .lookupfh = nfs4_proc_lookupfh, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5712 | .lookup = nfs4_proc_lookup, |
| 5713 | .access = nfs4_proc_access, |
| 5714 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5715 | .create = nfs4_proc_create, |
| 5716 | .remove = nfs4_proc_remove, |
| 5717 | .unlink_setup = nfs4_proc_unlink_setup, |
| 5718 | .unlink_done = nfs4_proc_unlink_done, |
| 5719 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 5720 | .rename_setup = nfs4_proc_rename_setup, |
| 5721 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5722 | .link = nfs4_proc_link, |
| 5723 | .symlink = nfs4_proc_symlink, |
| 5724 | .mkdir = nfs4_proc_mkdir, |
| 5725 | .rmdir = nfs4_proc_remove, |
| 5726 | .readdir = nfs4_proc_readdir, |
| 5727 | .mknod = nfs4_proc_mknod, |
| 5728 | .statfs = nfs4_proc_statfs, |
| 5729 | .fsinfo = nfs4_proc_fsinfo, |
| 5730 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 5731 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5732 | .decode_dirent = nfs4_decode_dirent, |
| 5733 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5734 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5735 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5736 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5737 | .commit_setup = nfs4_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5738 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5739 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5740 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 5741 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 5742 | .open_context = nfs4_atomic_open, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 5743 | .init_client = nfs4_init_client, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5744 | }; |
| 5745 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5746 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 5747 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 5748 | .list = nfs4_xattr_list_nfs4_acl, |
| 5749 | .get = nfs4_xattr_get_nfs4_acl, |
| 5750 | .set = nfs4_xattr_set_nfs4_acl, |
| 5751 | }; |
| 5752 | |
| 5753 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 5754 | &nfs4_xattr_nfs4_acl_handler, |
| 5755 | NULL |
| 5756 | }; |
| 5757 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5758 | /* |
| 5759 | * Local variables: |
| 5760 | * c-basic-offset: 8 |
| 5761 | * End: |
| 5762 | */ |