Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 46 | #include <linux/sunrpc/gss_api.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <linux/nfs.h> |
| 48 | #include <linux/nfs4.h> |
| 49 | #include <linux/nfs_fs.h> |
| 50 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 51 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 53 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 54 | #include <linux/module.h> |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 55 | #include <linux/nfs_idmap.h> |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 56 | #include <linux/sunrpc/bc_xprt.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 57 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 58 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 59 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 61 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 63 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 64 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 65 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 66 | #include "pnfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 69 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 70 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 72 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 73 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 74 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 75 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 76 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 77 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | 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] | 79 | 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] | 80 | 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] | 81 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 82 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 83 | struct nfs4_state *state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 84 | #ifdef CONFIG_NFS_V4_1 |
| 85 | static int nfs41_test_stateid(struct nfs_server *, struct nfs4_state *); |
| 86 | static int nfs41_free_stateid(struct nfs_server *, struct nfs4_state *); |
| 87 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 89 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 91 | if (err >= -1000) |
| 92 | return err; |
| 93 | switch (err) { |
| 94 | case -NFS4ERR_RESOURCE: |
| 95 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 96 | case -NFS4ERR_WRONGSEC: |
| 97 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 98 | case -NFS4ERR_BADOWNER: |
| 99 | case -NFS4ERR_BADNAME: |
| 100 | return -EINVAL; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 101 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 103 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 104 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 106 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /* |
| 110 | * This is our standard bitmap for GETATTR requests. |
| 111 | */ |
| 112 | const u32 nfs4_fattr_bitmap[2] = { |
| 113 | FATTR4_WORD0_TYPE |
| 114 | | FATTR4_WORD0_CHANGE |
| 115 | | FATTR4_WORD0_SIZE |
| 116 | | FATTR4_WORD0_FSID |
| 117 | | FATTR4_WORD0_FILEID, |
| 118 | FATTR4_WORD1_MODE |
| 119 | | FATTR4_WORD1_NUMLINKS |
| 120 | | FATTR4_WORD1_OWNER |
| 121 | | FATTR4_WORD1_OWNER_GROUP |
| 122 | | FATTR4_WORD1_RAWDEV |
| 123 | | FATTR4_WORD1_SPACE_USED |
| 124 | | FATTR4_WORD1_TIME_ACCESS |
| 125 | | FATTR4_WORD1_TIME_METADATA |
| 126 | | FATTR4_WORD1_TIME_MODIFY |
| 127 | }; |
| 128 | |
| 129 | const u32 nfs4_statfs_bitmap[2] = { |
| 130 | FATTR4_WORD0_FILES_AVAIL |
| 131 | | FATTR4_WORD0_FILES_FREE |
| 132 | | FATTR4_WORD0_FILES_TOTAL, |
| 133 | FATTR4_WORD1_SPACE_AVAIL |
| 134 | | FATTR4_WORD1_SPACE_FREE |
| 135 | | FATTR4_WORD1_SPACE_TOTAL |
| 136 | }; |
| 137 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 138 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | FATTR4_WORD0_MAXLINK |
| 140 | | FATTR4_WORD0_MAXNAME, |
| 141 | 0 |
| 142 | }; |
| 143 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 144 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | | FATTR4_WORD0_MAXREAD |
| 146 | | FATTR4_WORD0_MAXWRITE |
| 147 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 148 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 149 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 150 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | }; |
| 152 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 153 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 154 | FATTR4_WORD0_TYPE |
| 155 | | FATTR4_WORD0_CHANGE |
| 156 | | FATTR4_WORD0_SIZE |
| 157 | | FATTR4_WORD0_FSID |
| 158 | | FATTR4_WORD0_FILEID |
| 159 | | FATTR4_WORD0_FS_LOCATIONS, |
| 160 | FATTR4_WORD1_MODE |
| 161 | | FATTR4_WORD1_NUMLINKS |
| 162 | | FATTR4_WORD1_OWNER |
| 163 | | FATTR4_WORD1_OWNER_GROUP |
| 164 | | FATTR4_WORD1_RAWDEV |
| 165 | | FATTR4_WORD1_SPACE_USED |
| 166 | | FATTR4_WORD1_TIME_ACCESS |
| 167 | | FATTR4_WORD1_TIME_METADATA |
| 168 | | FATTR4_WORD1_TIME_MODIFY |
| 169 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 170 | }; |
| 171 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 172 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | struct nfs4_readdir_arg *readdir) |
| 174 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 175 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
| 177 | BUG_ON(readdir->count < 80); |
| 178 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 179 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 181 | return; |
| 182 | } |
| 183 | |
| 184 | readdir->cookie = 0; |
| 185 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 186 | if (cookie == 2) |
| 187 | return; |
| 188 | |
| 189 | /* |
| 190 | * NFSv4 servers do not return entries for '.' and '..' |
| 191 | * Therefore, we fake these entries here. We let '.' |
| 192 | * have cookie 0 and '..' have cookie 1. Note that |
| 193 | * when talking to the server, we always send cookie 0 |
| 194 | * instead of 1 or 2. |
| 195 | */ |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 196 | start = p = kmap_atomic(*readdir->pages, KM_USER0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
| 198 | if (cookie == 0) { |
| 199 | *p++ = xdr_one; /* next */ |
| 200 | *p++ = xdr_zero; /* cookie, first word */ |
| 201 | *p++ = xdr_one; /* cookie, second word */ |
| 202 | *p++ = xdr_one; /* entry len */ |
| 203 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 204 | p++; |
| 205 | *p++ = xdr_one; /* bitmap length */ |
| 206 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 207 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 208 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | *p++ = xdr_one; /* next */ |
| 212 | *p++ = xdr_zero; /* cookie, first word */ |
| 213 | *p++ = xdr_two; /* cookie, second word */ |
| 214 | *p++ = xdr_two; /* entry len */ |
| 215 | memcpy(p, "..\0\0", 4); /* entry */ |
| 216 | p++; |
| 217 | *p++ = xdr_one; /* bitmap length */ |
| 218 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 219 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 220 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
| 222 | readdir->pgbase = (char *)p - (char *)start; |
| 223 | readdir->count -= readdir->pgbase; |
| 224 | kunmap_atomic(start, KM_USER0); |
| 225 | } |
| 226 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 227 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 228 | { |
| 229 | int res; |
| 230 | |
| 231 | might_sleep(); |
| 232 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 233 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 234 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 235 | return res; |
| 236 | } |
| 237 | |
| 238 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 239 | { |
| 240 | int res = 0; |
| 241 | |
| 242 | might_sleep(); |
| 243 | |
| 244 | if (*timeout <= 0) |
| 245 | *timeout = NFS4_POLL_RETRY_MIN; |
| 246 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 247 | *timeout = NFS4_POLL_RETRY_MAX; |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 248 | freezable_schedule_timeout_killable(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 249 | if (fatal_signal_pending(current)) |
| 250 | res = -ERESTARTSYS; |
| 251 | *timeout <<= 1; |
| 252 | return res; |
| 253 | } |
| 254 | |
| 255 | /* This is the error handling routine for processes that are allowed |
| 256 | * to sleep. |
| 257 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 258 | 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] | 259 | { |
| 260 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 261 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 262 | int ret = errorcode; |
| 263 | |
| 264 | exception->retry = 0; |
| 265 | switch(errorcode) { |
| 266 | case 0: |
| 267 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 268 | case -NFS4ERR_ADMIN_REVOKED: |
| 269 | case -NFS4ERR_BAD_STATEID: |
| 270 | case -NFS4ERR_OPENMODE: |
| 271 | if (state == NULL) |
| 272 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 273 | nfs4_schedule_stateid_recovery(server, state); |
| 274 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 275 | case -NFS4ERR_EXPIRED: |
| 276 | if (state != NULL) |
| 277 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 278 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 279 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 280 | nfs4_schedule_lease_recovery(clp); |
| 281 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 282 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 283 | case -NFS4ERR_BADSESSION: |
| 284 | case -NFS4ERR_BADSLOT: |
| 285 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 286 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 287 | case -NFS4ERR_DEADSESSION: |
| 288 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 289 | case -NFS4ERR_SEQ_MISORDERED: |
| 290 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 291 | errorcode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 292 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 293 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 294 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 295 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 296 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 297 | if (exception->timeout > HZ) { |
| 298 | /* We have retried a decent amount, time to |
| 299 | * fail |
| 300 | */ |
| 301 | ret = -EBUSY; |
| 302 | break; |
| 303 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 304 | case -NFS4ERR_GRACE: |
| 305 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 306 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 307 | ret = nfs4_delay(server->client, &exception->timeout); |
| 308 | if (ret != 0) |
| 309 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 310 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 311 | case -NFS4ERR_OLD_STATEID: |
| 312 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 313 | break; |
| 314 | case -NFS4ERR_BADOWNER: |
| 315 | /* The following works around a Linux server bug! */ |
| 316 | case -NFS4ERR_BADNAME: |
| 317 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 318 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 319 | exception->retry = 1; |
| 320 | printk(KERN_WARNING "NFS: v4 server %s " |
| 321 | "does not accept raw " |
| 322 | "uid/gids. " |
| 323 | "Reenabling the idmapper.\n", |
| 324 | server->nfs_client->cl_hostname); |
| 325 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 326 | } |
| 327 | /* We failed to handle the error */ |
| 328 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 329 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 330 | ret = nfs4_wait_clnt_recover(clp); |
| 331 | if (ret == 0) |
| 332 | exception->retry = 1; |
| 333 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 337 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | spin_lock(&clp->cl_lock); |
| 340 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 341 | clp->cl_last_renewal = timestamp; |
| 342 | spin_unlock(&clp->cl_lock); |
| 343 | } |
| 344 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 345 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 346 | { |
| 347 | do_renew_lease(server->nfs_client, timestamp); |
| 348 | } |
| 349 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 350 | #if defined(CONFIG_NFS_V4_1) |
| 351 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 352 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 353 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 354 | * |
| 355 | * freeing a slot is trivially done by clearing its respective bit |
| 356 | * in the bitmap. |
| 357 | * If the freed slotid equals highest_used_slotid we want to update it |
| 358 | * so that the server would be able to size down the slot table if needed, |
| 359 | * otherwise we know that the highest_used_slotid is still in use. |
| 360 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 361 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 362 | * highest slotid in use. |
| 363 | * If none found, highest_used_slotid is set to -1. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 364 | * |
| 365 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 366 | */ |
| 367 | static void |
Andy Adamson | aabd0b4 | 2011-11-09 13:58:22 -0500 | [diff] [blame] | 368 | nfs4_free_slot(struct nfs4_slot_table *tbl, u8 free_slotid) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 369 | { |
| 370 | int slotid = free_slotid; |
| 371 | |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 372 | BUG_ON(slotid < 0 || slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 373 | /* clear used bit in bitmap */ |
| 374 | __clear_bit(slotid, tbl->used_slots); |
| 375 | |
| 376 | /* update highest_used_slotid when it is freed */ |
| 377 | if (slotid == tbl->highest_used_slotid) { |
| 378 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 379 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 380 | tbl->highest_used_slotid = slotid; |
| 381 | else |
| 382 | tbl->highest_used_slotid = -1; |
| 383 | } |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 384 | dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__, |
| 385 | free_slotid, tbl->highest_used_slotid); |
| 386 | } |
| 387 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 388 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 389 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 390 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 391 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 392 | { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 393 | struct rpc_task *task; |
| 394 | |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 395 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 396 | task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq); |
| 397 | if (task) |
| 398 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 399 | return; |
| 400 | } |
| 401 | |
| 402 | if (ses->fc_slot_table.highest_used_slotid != -1) |
| 403 | return; |
| 404 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 405 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 406 | complete(&ses->fc_slot_table.complete); |
| 407 | } |
| 408 | |
| 409 | /* |
| 410 | * Signal state manager thread if session back channel is drained |
| 411 | */ |
| 412 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 413 | { |
| 414 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
| 415 | ses->bc_slot_table.highest_used_slotid != -1) |
| 416 | return; |
| 417 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 418 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 419 | } |
| 420 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 421 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 422 | { |
| 423 | struct nfs4_slot_table *tbl; |
| 424 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 425 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 426 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 427 | /* just wake up the next guy waiting since |
| 428 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 429 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 430 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 431 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 432 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 433 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | aabd0b4 | 2011-11-09 13:58:22 -0500 | [diff] [blame] | 434 | nfs4_free_slot(tbl, res->sr_slot - tbl->slots); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 435 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 436 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 437 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 438 | } |
| 439 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 440 | static int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 441 | { |
| 442 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 443 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 444 | |
| 445 | /* |
| 446 | * sr_status remains 1 if an RPC level error occurred. The server |
| 447 | * may or may not have processed the sequence operation.. |
| 448 | * Proceed as if the server received and processed the sequence |
| 449 | * operation. |
| 450 | */ |
| 451 | if (res->sr_status == 1) |
| 452 | res->sr_status = NFS_OK; |
| 453 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 454 | /* don't increment the sequence number if the task wasn't sent */ |
| 455 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 456 | goto out; |
| 457 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 458 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 459 | switch (res->sr_status) { |
| 460 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 461 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 462 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 463 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 464 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 465 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 466 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 467 | if (res->sr_status_flags != 0) |
| 468 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 469 | break; |
| 470 | case -NFS4ERR_DELAY: |
| 471 | /* The server detected a resend of the RPC call and |
| 472 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 473 | * of RFC5661. |
| 474 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 475 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 476 | __func__, |
| 477 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 478 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 479 | goto out_retry; |
| 480 | default: |
| 481 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 482 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 483 | } |
| 484 | out: |
| 485 | /* The session may be reset by one of the error handlers. */ |
| 486 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 487 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 488 | return 1; |
| 489 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 490 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 491 | goto out; |
| 492 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 493 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 494 | } |
| 495 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 496 | static int nfs4_sequence_done(struct rpc_task *task, |
| 497 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 498 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 499 | if (res->sr_session == NULL) |
| 500 | return 1; |
| 501 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 502 | } |
| 503 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 504 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 505 | * nfs4_find_slot - efficiently look for a free slot |
| 506 | * |
| 507 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 508 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 509 | * and respectively set up the sequence operation args. |
| 510 | * The slot number is returned if found, or NFS4_MAX_SLOT_TABLE otherwise. |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 511 | * |
| 512 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 513 | */ |
| 514 | static u8 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 515 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 516 | { |
| 517 | int slotid; |
| 518 | u8 ret_id = NFS4_MAX_SLOT_TABLE; |
| 519 | BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE); |
| 520 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 521 | dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n", |
| 522 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 523 | tbl->max_slots); |
| 524 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 525 | if (slotid >= tbl->max_slots) |
| 526 | goto out; |
| 527 | __set_bit(slotid, tbl->used_slots); |
| 528 | if (slotid > tbl->highest_used_slotid) |
| 529 | tbl->highest_used_slotid = slotid; |
| 530 | ret_id = slotid; |
| 531 | out: |
| 532 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 533 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 534 | return ret_id; |
| 535 | } |
| 536 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 537 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 538 | struct nfs4_sequence_args *args, |
| 539 | struct nfs4_sequence_res *res, |
| 540 | int cache_reply, |
| 541 | struct rpc_task *task) |
| 542 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 543 | struct nfs4_slot *slot; |
| 544 | struct nfs4_slot_table *tbl; |
| 545 | u8 slotid; |
| 546 | |
| 547 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 548 | /* slot already allocated? */ |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 549 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 550 | return 0; |
| 551 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 552 | tbl = &session->fc_slot_table; |
| 553 | |
| 554 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 555 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 556 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 557 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 558 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 559 | spin_unlock(&tbl->slot_tbl_lock); |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 560 | dprintk("%s session is draining\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 561 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 562 | } |
| 563 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 564 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 565 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 566 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 567 | spin_unlock(&tbl->slot_tbl_lock); |
| 568 | dprintk("%s enforce FIFO order\n", __func__); |
| 569 | return -EAGAIN; |
| 570 | } |
| 571 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 572 | slotid = nfs4_find_slot(tbl); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 573 | if (slotid == NFS4_MAX_SLOT_TABLE) { |
| 574 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 575 | spin_unlock(&tbl->slot_tbl_lock); |
| 576 | dprintk("<-- %s: no free slots\n", __func__); |
| 577 | return -EAGAIN; |
| 578 | } |
| 579 | spin_unlock(&tbl->slot_tbl_lock); |
| 580 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 581 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 582 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 583 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 584 | args->sa_slotid = slotid; |
| 585 | args->sa_cache_this = cache_reply; |
| 586 | |
| 587 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 588 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 589 | res->sr_session = session; |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 590 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 591 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 592 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 593 | /* |
| 594 | * sr_status is only set in decode_sequence, and so will remain |
| 595 | * set to 1 if an rpc level failure occurs. |
| 596 | */ |
| 597 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 598 | return 0; |
| 599 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 600 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 601 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 602 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 603 | struct nfs4_sequence_args *args, |
| 604 | struct nfs4_sequence_res *res, |
| 605 | int cache_reply, |
| 606 | struct rpc_task *task) |
| 607 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 608 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 609 | int ret = 0; |
| 610 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 611 | if (session == NULL) { |
| 612 | args->sa_session = NULL; |
| 613 | res->sr_session = NULL; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 614 | goto out; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 615 | } |
| 616 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 617 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 618 | __func__, session->clp, session, res->sr_slot ? |
| 619 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 620 | |
| 621 | ret = nfs41_setup_sequence(session, args, res, cache_reply, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 622 | task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 623 | out: |
| 624 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 625 | return ret; |
| 626 | } |
| 627 | |
| 628 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 629 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 630 | struct nfs4_sequence_args *seq_args; |
| 631 | struct nfs4_sequence_res *seq_res; |
| 632 | int cache_reply; |
| 633 | }; |
| 634 | |
| 635 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 636 | { |
| 637 | struct nfs41_call_sync_data *data = calldata; |
| 638 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 639 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 640 | |
| 641 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 642 | data->seq_res, data->cache_reply, task)) |
| 643 | return; |
| 644 | rpc_call_start(task); |
| 645 | } |
| 646 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 647 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 648 | { |
| 649 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 650 | nfs41_call_sync_prepare(task, calldata); |
| 651 | } |
| 652 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 653 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 654 | { |
| 655 | struct nfs41_call_sync_data *data = calldata; |
| 656 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 657 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 658 | } |
| 659 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 660 | struct rpc_call_ops nfs41_call_sync_ops = { |
| 661 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 662 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 663 | }; |
| 664 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 665 | struct rpc_call_ops nfs41_call_priv_sync_ops = { |
| 666 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 667 | .rpc_call_done = nfs41_call_sync_done, |
| 668 | }; |
| 669 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 670 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 671 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 672 | struct rpc_message *msg, |
| 673 | struct nfs4_sequence_args *args, |
| 674 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 675 | int cache_reply, |
| 676 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 677 | { |
| 678 | int ret; |
| 679 | struct rpc_task *task; |
| 680 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 681 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 682 | .seq_args = args, |
| 683 | .seq_res = res, |
| 684 | .cache_reply = cache_reply, |
| 685 | }; |
| 686 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 687 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 688 | .rpc_message = msg, |
| 689 | .callback_ops = &nfs41_call_sync_ops, |
| 690 | .callback_data = &data |
| 691 | }; |
| 692 | |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 693 | res->sr_slot = NULL; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 694 | if (privileged) |
| 695 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 696 | task = rpc_run_task(&task_setup); |
| 697 | if (IS_ERR(task)) |
| 698 | ret = PTR_ERR(task); |
| 699 | else { |
| 700 | ret = task->tk_status; |
| 701 | rpc_put_task(task); |
| 702 | } |
| 703 | return ret; |
| 704 | } |
| 705 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 706 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 707 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 708 | struct rpc_message *msg, |
| 709 | struct nfs4_sequence_args *args, |
| 710 | struct nfs4_sequence_res *res, |
| 711 | int cache_reply) |
| 712 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 713 | return nfs4_call_sync_sequence(clnt, server, msg, args, res, cache_reply, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 714 | } |
| 715 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 716 | #else |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 717 | static int nfs4_sequence_done(struct rpc_task *task, |
| 718 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 719 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 720 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 721 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 722 | #endif /* CONFIG_NFS_V4_1 */ |
| 723 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 724 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 725 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 726 | struct rpc_message *msg, |
| 727 | struct nfs4_sequence_args *args, |
| 728 | struct nfs4_sequence_res *res, |
| 729 | int cache_reply) |
| 730 | { |
Benny Halevy | f375297 | 2009-04-01 09:22:04 -0400 | [diff] [blame] | 731 | args->sa_session = res->sr_session = NULL; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 732 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 733 | } |
| 734 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 735 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 736 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 737 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 738 | struct rpc_message *msg, |
| 739 | struct nfs4_sequence_args *args, |
| 740 | struct nfs4_sequence_res *res, |
| 741 | int cache_reply) |
| 742 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 743 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 744 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 745 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 746 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 747 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 749 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 751 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 752 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 753 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 754 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 755 | dir->i_version = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 756 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | } |
| 758 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 759 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 760 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 761 | struct nfs_openargs o_arg; |
| 762 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 763 | struct nfs_open_confirmargs c_arg; |
| 764 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 765 | struct nfs4_string owner_name; |
| 766 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 767 | struct nfs_fattr f_attr; |
| 768 | struct nfs_fattr dir_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 769 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 770 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 771 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 772 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 773 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 774 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 775 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 776 | int rpc_status; |
| 777 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 778 | }; |
| 779 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 780 | |
| 781 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 782 | { |
| 783 | p->o_res.f_attr = &p->f_attr; |
| 784 | p->o_res.dir_attr = &p->dir_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 785 | p->o_res.seqid = p->o_arg.seqid; |
| 786 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 787 | p->o_res.server = p->o_arg.server; |
| 788 | nfs_fattr_init(&p->f_attr); |
| 789 | nfs_fattr_init(&p->dir_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 790 | nfs_fattr_init_names(&p->f_attr, &p->owner_name, &p->group_name); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 791 | } |
| 792 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 793 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 794 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 795 | const struct iattr *attrs, |
| 796 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 797 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 798 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 799 | struct inode *dir = parent->d_inode; |
| 800 | struct nfs_server *server = NFS_SERVER(dir); |
| 801 | struct nfs4_opendata *p; |
| 802 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 803 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 804 | if (p == NULL) |
| 805 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 806 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 807 | if (p->o_arg.seqid == NULL) |
| 808 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 809 | nfs_sb_active(dentry->d_sb); |
| 810 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 811 | p->dir = parent; |
| 812 | p->owner = sp; |
| 813 | atomic_inc(&sp->so_count); |
| 814 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 815 | p->o_arg.open_flags = flags; |
| 816 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 817 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 818 | p->o_arg.id = sp->so_owner_id.id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 819 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 820 | p->o_arg.server = server; |
| 821 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 822 | p->o_arg.dir_bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 823 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 824 | if (flags & O_CREAT) { |
| 825 | u32 *s; |
| 826 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 827 | p->o_arg.u.attrs = &p->attrs; |
| 828 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 829 | s = (u32 *) p->o_arg.u.verifier.data; |
| 830 | s[0] = jiffies; |
| 831 | s[1] = current->pid; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 832 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 833 | p->c_arg.fh = &p->o_res.fh; |
| 834 | p->c_arg.stateid = &p->o_res.stateid; |
| 835 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 836 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 837 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 838 | return p; |
| 839 | err_free: |
| 840 | kfree(p); |
| 841 | err: |
| 842 | dput(parent); |
| 843 | return NULL; |
| 844 | } |
| 845 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 846 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 847 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 848 | struct nfs4_opendata *p = container_of(kref, |
| 849 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 850 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 851 | |
| 852 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 853 | if (p->state != NULL) |
| 854 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 855 | nfs4_put_state_owner(p->owner); |
| 856 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 857 | dput(p->dentry); |
| 858 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 859 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 860 | kfree(p); |
| 861 | } |
| 862 | |
| 863 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 864 | { |
| 865 | if (p != NULL) |
| 866 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 867 | } |
| 868 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 869 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 870 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 871 | int ret; |
| 872 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 873 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 874 | return ret; |
| 875 | } |
| 876 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 877 | 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] | 878 | { |
| 879 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 880 | |
| 881 | if (open_mode & O_EXCL) |
| 882 | goto out; |
| 883 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 884 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 885 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 886 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 887 | break; |
| 888 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 889 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 890 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 891 | break; |
| 892 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 893 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 894 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 895 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 896 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 897 | return ret; |
| 898 | } |
| 899 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 900 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 901 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 902 | if (delegation == NULL) |
| 903 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 904 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 905 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 906 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 907 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 908 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 909 | return 1; |
| 910 | } |
| 911 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 912 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 913 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 914 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 915 | case FMODE_WRITE: |
| 916 | state->n_wronly++; |
| 917 | break; |
| 918 | case FMODE_READ: |
| 919 | state->n_rdonly++; |
| 920 | break; |
| 921 | case FMODE_READ|FMODE_WRITE: |
| 922 | state->n_rdwr++; |
| 923 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 924 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 925 | } |
| 926 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 927 | 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] | 928 | { |
| 929 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 930 | memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); |
| 931 | memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 932 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 933 | case FMODE_READ: |
| 934 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 935 | break; |
| 936 | case FMODE_WRITE: |
| 937 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 938 | break; |
| 939 | case FMODE_READ|FMODE_WRITE: |
| 940 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 941 | } |
| 942 | } |
| 943 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 944 | 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] | 945 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 946 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 947 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 948 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 949 | } |
| 950 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 951 | 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] | 952 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 953 | /* |
| 954 | * Protect the call to nfs4_state_set_mode_locked and |
| 955 | * serialise the stateid update |
| 956 | */ |
| 957 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 958 | if (deleg_stateid != NULL) { |
| 959 | memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); |
| 960 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 961 | } |
| 962 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 963 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 964 | write_sequnlock(&state->seqlock); |
| 965 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 966 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 967 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | } |
| 969 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 970 | 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] | 971 | { |
| 972 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 973 | struct nfs_delegation *deleg_cur; |
| 974 | int ret = 0; |
| 975 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 976 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 977 | |
| 978 | rcu_read_lock(); |
| 979 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 980 | if (deleg_cur == NULL) |
| 981 | goto no_delegation; |
| 982 | |
| 983 | spin_lock(&deleg_cur->lock); |
| 984 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 985 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 986 | goto no_delegation_unlock; |
| 987 | |
| 988 | if (delegation == NULL) |
| 989 | delegation = &deleg_cur->stateid; |
| 990 | else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) |
| 991 | goto no_delegation_unlock; |
| 992 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 993 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 994 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 995 | ret = 1; |
| 996 | no_delegation_unlock: |
| 997 | spin_unlock(&deleg_cur->lock); |
| 998 | no_delegation: |
| 999 | rcu_read_unlock(); |
| 1000 | |
| 1001 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1002 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1003 | ret = 1; |
| 1004 | } |
| 1005 | |
| 1006 | return ret; |
| 1007 | } |
| 1008 | |
| 1009 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1010 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1011 | { |
| 1012 | struct nfs_delegation *delegation; |
| 1013 | |
| 1014 | rcu_read_lock(); |
| 1015 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1016 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1017 | rcu_read_unlock(); |
| 1018 | return; |
| 1019 | } |
| 1020 | rcu_read_unlock(); |
| 1021 | nfs_inode_return_delegation(inode); |
| 1022 | } |
| 1023 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1024 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1025 | { |
| 1026 | struct nfs4_state *state = opendata->state; |
| 1027 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1028 | struct nfs_delegation *delegation; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1029 | int open_mode = opendata->o_arg.open_flags & O_EXCL; |
| 1030 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1031 | nfs4_stateid stateid; |
| 1032 | int ret = -EAGAIN; |
| 1033 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1034 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1035 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1036 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1037 | if (can_open_cached(state, fmode, open_mode)) { |
| 1038 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1039 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1040 | goto out_return_state; |
| 1041 | } |
| 1042 | spin_unlock(&state->owner->so_lock); |
| 1043 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1044 | rcu_read_lock(); |
| 1045 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1046 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1047 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1048 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1049 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1050 | /* Save the delegation */ |
| 1051 | memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); |
| 1052 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1053 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1054 | if (ret != 0) |
| 1055 | goto out; |
| 1056 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1057 | |
| 1058 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1059 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1060 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1061 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1062 | out: |
| 1063 | return ERR_PTR(ret); |
| 1064 | out_return_state: |
| 1065 | atomic_inc(&state->count); |
| 1066 | return state; |
| 1067 | } |
| 1068 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1069 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1070 | { |
| 1071 | struct inode *inode; |
| 1072 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1073 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1074 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1075 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1076 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1077 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1078 | goto out; |
| 1079 | } |
| 1080 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1081 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1082 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1083 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1084 | 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] | 1085 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1086 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1087 | goto err; |
| 1088 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1089 | state = nfs4_get_open_state(inode, data->owner); |
| 1090 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1091 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1092 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1093 | int delegation_flags = 0; |
| 1094 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1095 | rcu_read_lock(); |
| 1096 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1097 | if (delegation) |
| 1098 | delegation_flags = delegation->flags; |
| 1099 | rcu_read_unlock(); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1100 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1101 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1102 | "returning a delegation for " |
| 1103 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1104 | NFS_CLIENT(inode)->cl_server); |
| 1105 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1106 | nfs_inode_set_delegation(state->inode, |
| 1107 | data->owner->so_cred, |
| 1108 | &data->o_res); |
| 1109 | else |
| 1110 | nfs_inode_reclaim_delegation(state->inode, |
| 1111 | data->owner->so_cred, |
| 1112 | &data->o_res); |
| 1113 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1114 | |
| 1115 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1116 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1117 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1118 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1119 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1120 | err_put_inode: |
| 1121 | iput(inode); |
| 1122 | err: |
| 1123 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1124 | } |
| 1125 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1126 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1127 | { |
| 1128 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1129 | struct nfs_open_context *ctx; |
| 1130 | |
| 1131 | spin_lock(&state->inode->i_lock); |
| 1132 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1133 | if (ctx->state != state) |
| 1134 | continue; |
| 1135 | get_nfs_open_context(ctx); |
| 1136 | spin_unlock(&state->inode->i_lock); |
| 1137 | return ctx; |
| 1138 | } |
| 1139 | spin_unlock(&state->inode->i_lock); |
| 1140 | return ERR_PTR(-ENOENT); |
| 1141 | } |
| 1142 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1143 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1144 | { |
| 1145 | struct nfs4_opendata *opendata; |
| 1146 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1147 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, NULL, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1148 | if (opendata == NULL) |
| 1149 | return ERR_PTR(-ENOMEM); |
| 1150 | opendata->state = state; |
| 1151 | atomic_inc(&state->count); |
| 1152 | return opendata; |
| 1153 | } |
| 1154 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1155 | 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] | 1156 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1157 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1158 | int ret; |
| 1159 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1160 | opendata->o_arg.open_flags = 0; |
| 1161 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1162 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1163 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1164 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1165 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1166 | if (ret != 0) |
| 1167 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1168 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1169 | if (IS_ERR(newstate)) |
| 1170 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1171 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1172 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1173 | return 0; |
| 1174 | } |
| 1175 | |
| 1176 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1177 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1178 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1179 | int ret; |
| 1180 | |
| 1181 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1182 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1183 | smp_rmb(); |
| 1184 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1185 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1186 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1187 | if (ret != 0) |
| 1188 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1189 | if (newstate != state) |
| 1190 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1191 | } |
| 1192 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1193 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1194 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1195 | if (ret != 0) |
| 1196 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1197 | if (newstate != state) |
| 1198 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1199 | } |
| 1200 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1201 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1202 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1203 | if (ret != 0) |
| 1204 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1205 | if (newstate != state) |
| 1206 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1207 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1208 | /* |
| 1209 | * We may have performed cached opens for all three recoveries. |
| 1210 | * Check if we need to update the current stateid. |
| 1211 | */ |
| 1212 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
| 1213 | 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] | 1214 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1215 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1216 | memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1217 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1218 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1219 | return 0; |
| 1220 | } |
| 1221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | /* |
| 1223 | * OPEN_RECLAIM: |
| 1224 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1226 | 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] | 1227 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1228 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1229 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1230 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | int status; |
| 1232 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1233 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1234 | if (IS_ERR(opendata)) |
| 1235 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1236 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1237 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1238 | rcu_read_lock(); |
| 1239 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1240 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1241 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1242 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1243 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1244 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1245 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | return status; |
| 1247 | } |
| 1248 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1249 | 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] | 1250 | { |
| 1251 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1252 | struct nfs4_exception exception = { }; |
| 1253 | int err; |
| 1254 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1255 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1256 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1257 | break; |
| 1258 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | } while (exception.retry); |
| 1260 | return err; |
| 1261 | } |
| 1262 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1263 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1264 | { |
| 1265 | struct nfs_open_context *ctx; |
| 1266 | int ret; |
| 1267 | |
| 1268 | ctx = nfs4_state_find_open_context(state); |
| 1269 | if (IS_ERR(ctx)) |
| 1270 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1271 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1272 | put_nfs_open_context(ctx); |
| 1273 | return ret; |
| 1274 | } |
| 1275 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1276 | 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] | 1277 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1278 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1279 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1281 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1282 | if (IS_ERR(opendata)) |
| 1283 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1284 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1285 | memcpy(opendata->o_arg.u.delegation.data, stateid->data, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1286 | sizeof(opendata->o_arg.u.delegation.data)); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1287 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1288 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1289 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | } |
| 1291 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1292 | 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] | 1293 | { |
| 1294 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1295 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | int err; |
| 1297 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1298 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | switch (err) { |
| 1300 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1301 | case -ENOENT: |
| 1302 | case -ESTALE: |
| 1303 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1304 | case -NFS4ERR_BADSESSION: |
| 1305 | case -NFS4ERR_BADSLOT: |
| 1306 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1307 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1308 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1309 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1310 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | case -NFS4ERR_STALE_CLIENTID: |
| 1312 | case -NFS4ERR_STALE_STATEID: |
| 1313 | case -NFS4ERR_EXPIRED: |
| 1314 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1315 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1316 | goto out; |
| 1317 | case -ERESTARTSYS: |
| 1318 | /* |
| 1319 | * The show must go on: exit, but mark the |
| 1320 | * stateid as needing recovery. |
| 1321 | */ |
| 1322 | case -NFS4ERR_ADMIN_REVOKED: |
| 1323 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1324 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1325 | case -EKEYEXPIRED: |
| 1326 | /* |
| 1327 | * User RPCSEC_GSS context has expired. |
| 1328 | * We cannot recover this stateid now, so |
| 1329 | * skip it and allow recovery thread to |
| 1330 | * proceed. |
| 1331 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1332 | case -ENOMEM: |
| 1333 | err = 0; |
| 1334 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | } |
| 1336 | err = nfs4_handle_exception(server, err, &exception); |
| 1337 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1338 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | return err; |
| 1340 | } |
| 1341 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1342 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1343 | { |
| 1344 | struct nfs4_opendata *data = calldata; |
| 1345 | |
| 1346 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1347 | if (data->rpc_status == 0) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1348 | memcpy(data->o_res.stateid.data, data->c_res.stateid.data, |
| 1349 | sizeof(data->o_res.stateid.data)); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1350 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1351 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1352 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1353 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | static void nfs4_open_confirm_release(void *calldata) |
| 1357 | { |
| 1358 | struct nfs4_opendata *data = calldata; |
| 1359 | struct nfs4_state *state = NULL; |
| 1360 | |
| 1361 | /* If this request hasn't been cancelled, do nothing */ |
| 1362 | if (data->cancelled == 0) |
| 1363 | goto out_free; |
| 1364 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1365 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1366 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1367 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1368 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1369 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1370 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1371 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1375 | .rpc_call_done = nfs4_open_confirm_done, |
| 1376 | .rpc_release = nfs4_open_confirm_release, |
| 1377 | }; |
| 1378 | |
| 1379 | /* |
| 1380 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1381 | */ |
| 1382 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1383 | { |
| 1384 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1385 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1386 | struct rpc_message msg = { |
| 1387 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1388 | .rpc_argp = &data->c_arg, |
| 1389 | .rpc_resp = &data->c_res, |
| 1390 | .rpc_cred = data->owner->so_cred, |
| 1391 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1392 | struct rpc_task_setup task_setup_data = { |
| 1393 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1394 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1395 | .callback_ops = &nfs4_open_confirm_ops, |
| 1396 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1397 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1398 | .flags = RPC_TASK_ASYNC, |
| 1399 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | int status; |
| 1401 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1402 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1403 | data->rpc_done = 0; |
| 1404 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1405 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1406 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1407 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1408 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1409 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1410 | if (status != 0) { |
| 1411 | data->cancelled = 1; |
| 1412 | smp_wmb(); |
| 1413 | } else |
| 1414 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1415 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | return status; |
| 1417 | } |
| 1418 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1419 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1421 | struct nfs4_opendata *data = calldata; |
| 1422 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1423 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1424 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1425 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1426 | /* |
| 1427 | * Check if we still need to send an OPEN call, or if we can use |
| 1428 | * a delegation instead. |
| 1429 | */ |
| 1430 | if (data->state != NULL) { |
| 1431 | struct nfs_delegation *delegation; |
| 1432 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1433 | 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] | 1434 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1435 | rcu_read_lock(); |
| 1436 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1437 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1438 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1439 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1440 | rcu_read_unlock(); |
| 1441 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1442 | /* Update sequence id. */ |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1443 | data->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1444 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1445 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1446 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1447 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1448 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1449 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1450 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1451 | &data->o_arg.seq_args, |
| 1452 | &data->o_res.seq_res, 1, task)) |
| 1453 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1454 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1455 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1456 | unlock_no_action: |
| 1457 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1458 | out_no_action: |
| 1459 | task->tk_action = NULL; |
| 1460 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1461 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1463 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1464 | { |
| 1465 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1466 | nfs4_open_prepare(task, calldata); |
| 1467 | } |
| 1468 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1469 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1470 | { |
| 1471 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1473 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1474 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1475 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1476 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1477 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1478 | if (task->tk_status == 0) { |
| 1479 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1480 | case S_IFREG: |
| 1481 | break; |
| 1482 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1483 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1484 | break; |
| 1485 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1486 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1487 | break; |
| 1488 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1489 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1490 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1491 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1492 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1493 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1494 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1495 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1496 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1497 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1498 | static void nfs4_open_release(void *calldata) |
| 1499 | { |
| 1500 | struct nfs4_opendata *data = calldata; |
| 1501 | struct nfs4_state *state = NULL; |
| 1502 | |
| 1503 | /* If this request hasn't been cancelled, do nothing */ |
| 1504 | if (data->cancelled == 0) |
| 1505 | goto out_free; |
| 1506 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1507 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1508 | goto out_free; |
| 1509 | /* In case we need an open_confirm, no cleanup! */ |
| 1510 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1511 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1512 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1513 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1514 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1515 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1516 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1520 | .rpc_call_prepare = nfs4_open_prepare, |
| 1521 | .rpc_call_done = nfs4_open_done, |
| 1522 | .rpc_release = nfs4_open_release, |
| 1523 | }; |
| 1524 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1525 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1526 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1527 | .rpc_call_done = nfs4_open_done, |
| 1528 | .rpc_release = nfs4_open_release, |
| 1529 | }; |
| 1530 | |
| 1531 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1532 | { |
| 1533 | struct inode *dir = data->dir->d_inode; |
| 1534 | struct nfs_server *server = NFS_SERVER(dir); |
| 1535 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1536 | struct nfs_openres *o_res = &data->o_res; |
| 1537 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1538 | struct rpc_message msg = { |
| 1539 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1540 | .rpc_argp = o_arg, |
| 1541 | .rpc_resp = o_res, |
| 1542 | .rpc_cred = data->owner->so_cred, |
| 1543 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1544 | struct rpc_task_setup task_setup_data = { |
| 1545 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1546 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1547 | .callback_ops = &nfs4_open_ops, |
| 1548 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1549 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1550 | .flags = RPC_TASK_ASYNC, |
| 1551 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1552 | int status; |
| 1553 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1554 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1555 | data->rpc_done = 0; |
| 1556 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1557 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1558 | if (isrecover) |
| 1559 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1560 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1561 | if (IS_ERR(task)) |
| 1562 | return PTR_ERR(task); |
| 1563 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1564 | if (status != 0) { |
| 1565 | data->cancelled = 1; |
| 1566 | smp_wmb(); |
| 1567 | } else |
| 1568 | status = data->rpc_status; |
| 1569 | rpc_put_task(task); |
| 1570 | |
| 1571 | return status; |
| 1572 | } |
| 1573 | |
| 1574 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1575 | { |
| 1576 | struct inode *dir = data->dir->d_inode; |
| 1577 | struct nfs_openres *o_res = &data->o_res; |
| 1578 | int status; |
| 1579 | |
| 1580 | status = nfs4_run_open_task(data, 1); |
| 1581 | if (status != 0 || !data->rpc_done) |
| 1582 | return status; |
| 1583 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1584 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1585 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1586 | nfs_refresh_inode(dir, o_res->dir_attr); |
| 1587 | |
| 1588 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1589 | status = _nfs4_proc_open_confirm(data); |
| 1590 | if (status != 0) |
| 1591 | return status; |
| 1592 | } |
| 1593 | |
| 1594 | return status; |
| 1595 | } |
| 1596 | |
| 1597 | /* |
| 1598 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1599 | */ |
| 1600 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1601 | { |
| 1602 | struct inode *dir = data->dir->d_inode; |
| 1603 | struct nfs_server *server = NFS_SERVER(dir); |
| 1604 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1605 | struct nfs_openres *o_res = &data->o_res; |
| 1606 | int status; |
| 1607 | |
| 1608 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1609 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1610 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1611 | if (status != 0) { |
| 1612 | if (status == -NFS4ERR_BADNAME && |
| 1613 | !(o_arg->open_flags & O_CREAT)) |
| 1614 | return -ENOENT; |
| 1615 | return status; |
| 1616 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1617 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1618 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1619 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1620 | if (o_arg->open_flags & O_CREAT) { |
| 1621 | update_changeattr(dir, &o_res->cinfo); |
| 1622 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
| 1623 | } else |
| 1624 | nfs_refresh_inode(dir, o_res->dir_attr); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1625 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1626 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1628 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1630 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | } |
| 1632 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1633 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1634 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | } |
| 1636 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1637 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1638 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1639 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1640 | int ret; |
Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1641 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1642 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1643 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1644 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1645 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1646 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1647 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1648 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1649 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1650 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1651 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1652 | return ret; |
Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1653 | } |
| 1654 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1655 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1656 | { |
| 1657 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1658 | } |
| 1659 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | /* |
| 1661 | * OPEN_EXPIRED: |
| 1662 | * reclaim state on the server after a network partition. |
| 1663 | * Assumes caller holds the appropriate lock |
| 1664 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1665 | 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] | 1666 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1667 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1668 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1670 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1671 | if (IS_ERR(opendata)) |
| 1672 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1673 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1674 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1675 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1676 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1677 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | } |
| 1679 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1680 | 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] | 1681 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1682 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1683 | struct nfs4_exception exception = { }; |
| 1684 | int err; |
| 1685 | |
| 1686 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1687 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1688 | switch (err) { |
| 1689 | default: |
| 1690 | goto out; |
| 1691 | case -NFS4ERR_GRACE: |
| 1692 | case -NFS4ERR_DELAY: |
| 1693 | nfs4_handle_exception(server, err, &exception); |
| 1694 | err = 0; |
| 1695 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1696 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1697 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1698 | return err; |
| 1699 | } |
| 1700 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1702 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1704 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1706 | ctx = nfs4_state_find_open_context(state); |
| 1707 | if (IS_ERR(ctx)) |
| 1708 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1709 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1710 | put_nfs_open_context(ctx); |
| 1711 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1714 | #if defined(CONFIG_NFS_V4_1) |
| 1715 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1716 | { |
| 1717 | int status; |
| 1718 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1719 | |
| 1720 | status = nfs41_test_stateid(server, state); |
| 1721 | if (status == NFS_OK) |
| 1722 | return 0; |
| 1723 | nfs41_free_stateid(server, state); |
| 1724 | return nfs4_open_expired(sp, state); |
| 1725 | } |
| 1726 | #endif |
| 1727 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1729 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1730 | * fields corresponding to attributes that were used to store the verifier. |
| 1731 | * Make sure we clobber those fields in the later setattr call |
| 1732 | */ |
| 1733 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1734 | { |
| 1735 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1736 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1737 | sattr->ia_valid |= ATTR_ATIME; |
| 1738 | |
| 1739 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1740 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1741 | sattr->ia_valid |= ATTR_MTIME; |
| 1742 | } |
| 1743 | |
| 1744 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1745 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | */ |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1747 | static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred, struct nfs4_state **res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | { |
| 1749 | struct nfs4_state_owner *sp; |
| 1750 | struct nfs4_state *state = NULL; |
| 1751 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1752 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1753 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | |
| 1755 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | status = -ENOMEM; |
| 1757 | if (!(sp = nfs4_get_state_owner(server, cred))) { |
| 1758 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1759 | goto out_err; |
| 1760 | } |
Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1761 | status = nfs4_recover_expired_lease(server); |
| 1762 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1763 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1764 | if (dentry->d_inode != NULL) |
| 1765 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1766 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1767 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1768 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1769 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1771 | if (dentry->d_inode != NULL) |
| 1772 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1773 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1774 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1776 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1778 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1779 | status = PTR_ERR(state); |
| 1780 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1781 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1782 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1783 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1784 | |
| 1785 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1786 | nfs4_exclusive_attrset(opendata, sattr); |
| 1787 | |
| 1788 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1789 | status = nfs4_do_setattr(state->inode, cred, |
| 1790 | opendata->o_res.f_attr, sattr, |
| 1791 | state); |
| 1792 | if (status == 0) |
| 1793 | nfs_setattr_update_inode(state->inode, sattr); |
| 1794 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1795 | } |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1796 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | *res = state; |
| 1799 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1800 | err_opendata_put: |
| 1801 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1802 | err_put_state_owner: |
| 1803 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | *res = NULL; |
| 1806 | return status; |
| 1807 | } |
| 1808 | |
| 1809 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1810 | static struct nfs4_state *nfs4_do_open(struct inode *dir, struct dentry *dentry, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | { |
| 1812 | struct nfs4_exception exception = { }; |
| 1813 | struct nfs4_state *res; |
| 1814 | int status; |
| 1815 | |
| 1816 | do { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1817 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | if (status == 0) |
| 1819 | break; |
| 1820 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1821 | * book-keeping w.r.t. state-changing operations |
| 1822 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1823 | * It is actually a sign of a bug on the client or on the server. |
| 1824 | * |
| 1825 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1826 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | * have unhashed the old state_owner for us, and that we can |
| 1828 | * therefore safely retry using a new one. We should still warn |
| 1829 | * the user though... |
| 1830 | */ |
| 1831 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1832 | printk(KERN_WARNING "NFS: v4 server %s " |
| 1833 | " returned a bad sequence-id error!\n", |
| 1834 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | exception.retry = 1; |
| 1836 | continue; |
| 1837 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1838 | /* |
| 1839 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1840 | * state before it received the OPEN_CONFIRM. |
| 1841 | * Recover by retrying the request as per the discussion |
| 1842 | * on Page 181 of RFC3530. |
| 1843 | */ |
| 1844 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1845 | exception.retry = 1; |
| 1846 | continue; |
| 1847 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1848 | if (status == -EAGAIN) { |
| 1849 | /* We must have found a delegation */ |
| 1850 | exception.retry = 1; |
| 1851 | continue; |
| 1852 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1854 | status, &exception)); |
| 1855 | } while (exception.retry); |
| 1856 | return res; |
| 1857 | } |
| 1858 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1859 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1860 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1861 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1863 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1865 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | .iap = sattr, |
| 1867 | .server = server, |
| 1868 | .bitmask = server->attr_bitmask, |
| 1869 | }; |
| 1870 | struct nfs_setattrres res = { |
| 1871 | .fattr = fattr, |
| 1872 | .server = server, |
| 1873 | }; |
| 1874 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1875 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1876 | .rpc_argp = &arg, |
| 1877 | .rpc_resp = &res, |
| 1878 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1880 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1881 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1883 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1885 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { |
| 1886 | /* Use that stateid */ |
| 1887 | } else if (state != NULL) { |
Trond Myklebust | 77041ed | 2010-07-01 12:49:11 -0400 | [diff] [blame] | 1888 | nfs4_copy_stateid(&arg.stateid, state, current->files, current->tgid); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1889 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); |
| 1891 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1892 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1893 | if (status == 0 && state != NULL) |
| 1894 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1895 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | } |
| 1897 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1898 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1899 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1900 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1902 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | struct nfs4_exception exception = { }; |
| 1904 | int err; |
| 1905 | do { |
| 1906 | err = nfs4_handle_exception(server, |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1907 | _nfs4_do_setattr(inode, cred, fattr, sattr, state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | &exception); |
| 1909 | } while (exception.retry); |
| 1910 | return err; |
| 1911 | } |
| 1912 | |
| 1913 | struct nfs4_closedata { |
| 1914 | struct inode *inode; |
| 1915 | struct nfs4_state *state; |
| 1916 | struct nfs_closeargs arg; |
| 1917 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1918 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1919 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1920 | bool roc; |
| 1921 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | }; |
| 1923 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1924 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1925 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1926 | struct nfs4_closedata *calldata = data; |
| 1927 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1928 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1929 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1930 | if (calldata->roc) |
| 1931 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1932 | nfs4_put_open_state(calldata->state); |
| 1933 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1934 | nfs4_put_state_owner(sp); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1935 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1936 | kfree(calldata); |
| 1937 | } |
| 1938 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1939 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 1940 | fmode_t fmode) |
| 1941 | { |
| 1942 | spin_lock(&state->owner->so_lock); |
| 1943 | if (!(fmode & FMODE_READ)) |
| 1944 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1945 | if (!(fmode & FMODE_WRITE)) |
| 1946 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1947 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1948 | spin_unlock(&state->owner->so_lock); |
| 1949 | } |
| 1950 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1951 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1953 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1954 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 1956 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1957 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 1958 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1959 | /* hmm. we are done with the inode, and in the process of freeing |
| 1960 | * the state_owner. we keep this around to process errors |
| 1961 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | switch (task->tk_status) { |
| 1963 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1964 | if (calldata->roc) |
| 1965 | pnfs_roc_set_barrier(state->inode, |
| 1966 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1967 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1968 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1969 | nfs4_close_clear_stateid_flags(state, |
| 1970 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | break; |
| 1972 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1973 | case -NFS4ERR_OLD_STATEID: |
| 1974 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1976 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1977 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1979 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 1980 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1982 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1983 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | } |
| 1985 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1986 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1988 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1989 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1990 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1991 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1992 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1993 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1994 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1995 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 1996 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1997 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1998 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1999 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2000 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2001 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2002 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2003 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2004 | } |
| 2005 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2006 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2007 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2008 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2009 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2010 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2011 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2012 | |
| 2013 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2014 | /* Note: exit _without_ calling nfs4_close_done */ |
| 2015 | task->tk_action = NULL; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2016 | return; |
| 2017 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2018 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2019 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2020 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2021 | if (calldata->roc && |
| 2022 | pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { |
| 2023 | rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, |
| 2024 | task, NULL); |
| 2025 | return; |
| 2026 | } |
| 2027 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2028 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2029 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2030 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2031 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 2032 | &calldata->arg.seq_args, &calldata->res.seq_res, |
| 2033 | 1, task)) |
| 2034 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2035 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | } |
| 2037 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2038 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2039 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2040 | .rpc_call_done = nfs4_close_done, |
| 2041 | .rpc_release = nfs4_free_closedata, |
| 2042 | }; |
| 2043 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | /* |
| 2045 | * It is possible for data to be read/written from a mem-mapped file |
| 2046 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2047 | * This means that we can't safely call nfsv4 close on a file until |
| 2048 | * the inode is cleared. This in turn means that we are not good |
| 2049 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2050 | * share state even when we are done with one of the three share |
| 2051 | * stateid's in the inode. |
| 2052 | * |
| 2053 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2054 | */ |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2055 | int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait, bool roc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2057 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2058 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2059 | struct nfs4_state_owner *sp = state->owner; |
| 2060 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2061 | struct rpc_message msg = { |
| 2062 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2063 | .rpc_cred = state->owner->so_cred, |
| 2064 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2065 | struct rpc_task_setup task_setup_data = { |
| 2066 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2067 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2068 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2069 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2070 | .flags = RPC_TASK_ASYNC, |
| 2071 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2072 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2074 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2076 | goto out; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2077 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2079 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2080 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2082 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2083 | if (calldata->arg.seqid == NULL) |
| 2084 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2085 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2086 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2087 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2088 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2089 | calldata->res.server = server; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2090 | calldata->roc = roc; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2091 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2092 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2093 | msg.rpc_argp = &calldata->arg; |
| 2094 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2095 | task_setup_data.callback_data = calldata; |
| 2096 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2097 | if (IS_ERR(task)) |
| 2098 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2099 | status = 0; |
| 2100 | if (wait) |
| 2101 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2102 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2103 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2104 | out_free_calldata: |
| 2105 | kfree(calldata); |
| 2106 | out: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2107 | if (roc) |
| 2108 | pnfs_roc_release(state->inode); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2109 | nfs4_put_open_state(state); |
| 2110 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2111 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | } |
| 2113 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2114 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2115 | 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] | 2116 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | struct nfs4_state *state; |
| 2118 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2119 | /* Protect against concurrent sillydeletes */ |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2120 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, ctx->cred); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2121 | if (IS_ERR(state)) |
| 2122 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2123 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2124 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | } |
| 2126 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2127 | 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] | 2128 | { |
| 2129 | if (ctx->state == NULL) |
| 2130 | return; |
| 2131 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2132 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2133 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2134 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2135 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | |
| 2137 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2138 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2139 | struct nfs4_server_caps_arg args = { |
| 2140 | .fhandle = fhandle, |
| 2141 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | struct nfs4_server_caps_res res = {}; |
| 2143 | struct rpc_message msg = { |
| 2144 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2145 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | .rpc_resp = &res, |
| 2147 | }; |
| 2148 | int status; |
| 2149 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2150 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | if (status == 0) { |
| 2152 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2153 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2154 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2155 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2156 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2157 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2159 | server->caps |= NFS_CAP_ACLS; |
| 2160 | if (res.has_links != 0) |
| 2161 | server->caps |= NFS_CAP_HARDLINKS; |
| 2162 | if (res.has_symlinks != 0) |
| 2163 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2164 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2165 | server->caps |= NFS_CAP_FILEID; |
| 2166 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2167 | server->caps |= NFS_CAP_MODE; |
| 2168 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2169 | server->caps |= NFS_CAP_NLINK; |
| 2170 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2171 | server->caps |= NFS_CAP_OWNER; |
| 2172 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2173 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2174 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2175 | server->caps |= NFS_CAP_ATIME; |
| 2176 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2177 | server->caps |= NFS_CAP_CTIME; |
| 2178 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2179 | server->caps |= NFS_CAP_MTIME; |
| 2180 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2181 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2182 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2183 | 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] | 2184 | server->acl_bitmask = res.acl_bitmask; |
| 2185 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | return status; |
| 2188 | } |
| 2189 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2190 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | { |
| 2192 | struct nfs4_exception exception = { }; |
| 2193 | int err; |
| 2194 | do { |
| 2195 | err = nfs4_handle_exception(server, |
| 2196 | _nfs4_server_capabilities(server, fhandle), |
| 2197 | &exception); |
| 2198 | } while (exception.retry); |
| 2199 | return err; |
| 2200 | } |
| 2201 | |
| 2202 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2203 | struct nfs_fsinfo *info) |
| 2204 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | struct nfs4_lookup_root_arg args = { |
| 2206 | .bitmask = nfs4_fattr_bitmap, |
| 2207 | }; |
| 2208 | struct nfs4_lookup_res res = { |
| 2209 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2210 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | .fh = fhandle, |
| 2212 | }; |
| 2213 | struct rpc_message msg = { |
| 2214 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2215 | .rpc_argp = &args, |
| 2216 | .rpc_resp = &res, |
| 2217 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2218 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2219 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2220 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2224 | struct nfs_fsinfo *info) |
| 2225 | { |
| 2226 | struct nfs4_exception exception = { }; |
| 2227 | int err; |
| 2228 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2229 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2230 | switch (err) { |
| 2231 | case 0: |
| 2232 | case -NFS4ERR_WRONGSEC: |
| 2233 | break; |
| 2234 | default: |
| 2235 | err = nfs4_handle_exception(server, err, &exception); |
| 2236 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | } while (exception.retry); |
| 2238 | return err; |
| 2239 | } |
| 2240 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2241 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2242 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2243 | { |
| 2244 | struct rpc_auth *auth; |
| 2245 | int ret; |
| 2246 | |
| 2247 | auth = rpcauth_create(flavor, server->client); |
| 2248 | if (!auth) { |
| 2249 | ret = -EIO; |
| 2250 | goto out; |
| 2251 | } |
| 2252 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2253 | out: |
| 2254 | return ret; |
| 2255 | } |
| 2256 | |
Bryan Schumaker | 801a16d | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2257 | static int nfs4_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2258 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2260 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2261 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2262 | |
Bryan Schumaker | 801a16d | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2263 | len = gss_mech_list_pseudoflavors(&flav_array[0]); |
| 2264 | flav_array[len] = RPC_AUTH_NULL; |
| 2265 | len += 1; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2266 | |
| 2267 | for (i = 0; i < len; i++) { |
| 2268 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2269 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2270 | continue; |
| 2271 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2272 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2273 | /* |
| 2274 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2275 | * to access the mount. It could also mean that we tried to mount |
| 2276 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2277 | * existing mount programs don't handle -EACCES very well so it should |
| 2278 | * be mapped to -EPERM instead. |
| 2279 | */ |
| 2280 | if (status == -EACCES) |
| 2281 | status = -EPERM; |
Bryan Schumaker | 801a16d | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2282 | return status; |
| 2283 | } |
| 2284 | |
| 2285 | /* |
| 2286 | * get the file handle for the "/" directory on the server |
| 2287 | */ |
| 2288 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2289 | struct nfs_fsinfo *info) |
| 2290 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2291 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16d | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2292 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2293 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2294 | /* |
| 2295 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2296 | * by nfs4_map_errors() as this function exits. |
| 2297 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2298 | status = nfs_v4_minor_ops[minor_version]->find_root_sec(server, fhandle, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | if (status == 0) |
| 2300 | status = nfs4_server_capabilities(server, fhandle); |
| 2301 | if (status == 0) |
| 2302 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2303 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | } |
| 2305 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2306 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2307 | /* |
| 2308 | * Get locations and (maybe) other attributes of a referral. |
| 2309 | * Note that we'll actually follow the referral later when |
| 2310 | * we detect fsid mismatch in inode revalidation |
| 2311 | */ |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2312 | static int nfs4_get_referral(struct inode *dir, const struct qstr *name, |
| 2313 | struct nfs_fattr *fattr, struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2314 | { |
| 2315 | int status = -ENOMEM; |
| 2316 | struct page *page = NULL; |
| 2317 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2318 | |
| 2319 | page = alloc_page(GFP_KERNEL); |
| 2320 | if (page == NULL) |
| 2321 | goto out; |
| 2322 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2323 | if (locations == NULL) |
| 2324 | goto out; |
| 2325 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 2326 | status = nfs4_proc_fs_locations(dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2327 | if (status != 0) |
| 2328 | goto out; |
| 2329 | /* Make sure server returned a different fsid for the referral */ |
| 2330 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2331 | dprintk("%s: server did not return a different fsid for" |
| 2332 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2333 | status = -EIO; |
| 2334 | goto out; |
| 2335 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2336 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2337 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2338 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2339 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2340 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2341 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2342 | out: |
| 2343 | if (page) |
| 2344 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2345 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2346 | return status; |
| 2347 | } |
| 2348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2350 | { |
| 2351 | struct nfs4_getattr_arg args = { |
| 2352 | .fh = fhandle, |
| 2353 | .bitmask = server->attr_bitmask, |
| 2354 | }; |
| 2355 | struct nfs4_getattr_res res = { |
| 2356 | .fattr = fattr, |
| 2357 | .server = server, |
| 2358 | }; |
| 2359 | struct rpc_message msg = { |
| 2360 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2361 | .rpc_argp = &args, |
| 2362 | .rpc_resp = &res, |
| 2363 | }; |
| 2364 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2365 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2366 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | } |
| 2368 | |
| 2369 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2370 | { |
| 2371 | struct nfs4_exception exception = { }; |
| 2372 | int err; |
| 2373 | do { |
| 2374 | err = nfs4_handle_exception(server, |
| 2375 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2376 | &exception); |
| 2377 | } while (exception.retry); |
| 2378 | return err; |
| 2379 | } |
| 2380 | |
| 2381 | /* |
| 2382 | * The file is not closed if it is opened due to the a request to change |
| 2383 | * the size of the file. The open call will not be needed once the |
| 2384 | * VFS layer lookup-intents are implemented. |
| 2385 | * |
| 2386 | * Close is called when the inode is destroyed. |
| 2387 | * If we haven't opened the file for O_WRONLY, we |
| 2388 | * need to in the size_change case to obtain a stateid. |
| 2389 | * |
| 2390 | * Got race? |
| 2391 | * Because OPEN is always done by name in nfsv4, it is |
| 2392 | * possible that we opened a different file by the same |
| 2393 | * name. We can recognize this race condition, but we |
| 2394 | * can't do anything about it besides returning an error. |
| 2395 | * |
| 2396 | * This will be fixed with VFS changes (lookup-intent). |
| 2397 | */ |
| 2398 | static int |
| 2399 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2400 | struct iattr *sattr) |
| 2401 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2402 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2403 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2404 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2405 | int status; |
| 2406 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2407 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2408 | pnfs_return_layout(inode); |
| 2409 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2410 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2411 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2412 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2413 | if (sattr->ia_valid & ATTR_FILE) { |
| 2414 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2415 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2416 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2417 | if (ctx) { |
| 2418 | cred = ctx->cred; |
| 2419 | state = ctx->state; |
| 2420 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2421 | } |
| 2422 | |
| 2423 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2424 | if (status == 0) |
| 2425 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | return status; |
| 2427 | } |
| 2428 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2429 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2430 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2431 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2432 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2433 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2434 | int status; |
| 2435 | struct nfs4_lookup_arg args = { |
| 2436 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2437 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2438 | .name = name, |
| 2439 | }; |
| 2440 | struct nfs4_lookup_res res = { |
| 2441 | .server = server, |
| 2442 | .fattr = fattr, |
| 2443 | .fh = fhandle, |
| 2444 | }; |
| 2445 | struct rpc_message msg = { |
| 2446 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2447 | .rpc_argp = &args, |
| 2448 | .rpc_resp = &res, |
| 2449 | }; |
| 2450 | |
| 2451 | nfs_fattr_init(fattr); |
| 2452 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2453 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2454 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2455 | dprintk("NFS reply lookup: %d\n", status); |
| 2456 | return status; |
| 2457 | } |
| 2458 | |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2459 | void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr, struct nfs_fh *fh) |
| 2460 | { |
| 2461 | memset(fh, 0, sizeof(struct nfs_fh)); |
| 2462 | fattr->fsid.major = 1; |
| 2463 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 2464 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_FSID | NFS_ATTR_FATTR_MOUNTPOINT; |
| 2465 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2466 | fattr->nlink = 2; |
| 2467 | } |
| 2468 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2469 | static int nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, struct qstr *name, |
| 2470 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2471 | { |
| 2472 | struct nfs4_exception exception = { }; |
| 2473 | int err; |
| 2474 | do { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2475 | int status; |
| 2476 | |
| 2477 | status = _nfs4_proc_lookup(clnt, dir, name, fhandle, fattr); |
| 2478 | switch (status) { |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2479 | case -NFS4ERR_BADNAME: |
| 2480 | return -ENOENT; |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2481 | case -NFS4ERR_MOVED: |
Trond Myklebust | a6f498a | 2011-11-07 15:50:32 -0500 | [diff] [blame] | 2482 | return nfs4_get_referral(dir, name, fattr, fhandle); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2483 | case -NFS4ERR_WRONGSEC: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2484 | nfs_fixup_secinfo_attributes(fattr, fhandle); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2485 | } |
| 2486 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2487 | status, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | } while (exception.retry); |
| 2489 | return err; |
| 2490 | } |
| 2491 | |
| 2492 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2493 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2494 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2495 | struct nfs4_accessargs args = { |
| 2496 | .fh = NFS_FH(inode), |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2497 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2499 | struct nfs4_accessres res = { |
| 2500 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2501 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2502 | struct rpc_message msg = { |
| 2503 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2504 | .rpc_argp = &args, |
| 2505 | .rpc_resp = &res, |
| 2506 | .rpc_cred = entry->cred, |
| 2507 | }; |
| 2508 | int mode = entry->mask; |
| 2509 | int status; |
| 2510 | |
| 2511 | /* |
| 2512 | * Determine which access bits we want to ask for... |
| 2513 | */ |
| 2514 | if (mode & MAY_READ) |
| 2515 | args.access |= NFS4_ACCESS_READ; |
| 2516 | if (S_ISDIR(inode->i_mode)) { |
| 2517 | if (mode & MAY_WRITE) |
| 2518 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2519 | if (mode & MAY_EXEC) |
| 2520 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2521 | } else { |
| 2522 | if (mode & MAY_WRITE) |
| 2523 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2524 | if (mode & MAY_EXEC) |
| 2525 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2526 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2527 | |
| 2528 | res.fattr = nfs_alloc_fattr(); |
| 2529 | if (res.fattr == NULL) |
| 2530 | return -ENOMEM; |
| 2531 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2532 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2533 | if (!status) { |
| 2534 | entry->mask = 0; |
| 2535 | if (res.access & NFS4_ACCESS_READ) |
| 2536 | entry->mask |= MAY_READ; |
| 2537 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2538 | entry->mask |= MAY_WRITE; |
| 2539 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2540 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2541 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2543 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2544 | return status; |
| 2545 | } |
| 2546 | |
| 2547 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2548 | { |
| 2549 | struct nfs4_exception exception = { }; |
| 2550 | int err; |
| 2551 | do { |
| 2552 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2553 | _nfs4_proc_access(inode, entry), |
| 2554 | &exception); |
| 2555 | } while (exception.retry); |
| 2556 | return err; |
| 2557 | } |
| 2558 | |
| 2559 | /* |
| 2560 | * TODO: For the time being, we don't try to get any attributes |
| 2561 | * along with any of the zero-copy operations READ, READDIR, |
| 2562 | * READLINK, WRITE. |
| 2563 | * |
| 2564 | * In the case of the first three, we want to put the GETATTR |
| 2565 | * after the read-type operation -- this is because it is hard |
| 2566 | * to predict the length of a GETATTR response in v4, and thus |
| 2567 | * align the READ data correctly. This means that the GETATTR |
| 2568 | * may end up partially falling into the page cache, and we should |
| 2569 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2570 | * To do this efficiently, we need to know the total length |
| 2571 | * of data received, which doesn't seem to be available outside |
| 2572 | * of the RPC layer. |
| 2573 | * |
| 2574 | * In the case of WRITE, we also want to put the GETATTR after |
| 2575 | * the operation -- in this case because we want to make sure |
| 2576 | * we get the post-operation mtime and size. This means that |
| 2577 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2578 | * of it which would leave room in the 'tail' iovec. |
| 2579 | * |
| 2580 | * Both of these changes to the XDR layer would in fact be quite |
| 2581 | * minor, but I decided to leave them for a subsequent patch. |
| 2582 | */ |
| 2583 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2584 | unsigned int pgbase, unsigned int pglen) |
| 2585 | { |
| 2586 | struct nfs4_readlink args = { |
| 2587 | .fh = NFS_FH(inode), |
| 2588 | .pgbase = pgbase, |
| 2589 | .pglen = pglen, |
| 2590 | .pages = &page, |
| 2591 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2592 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | struct rpc_message msg = { |
| 2594 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2595 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2596 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2597 | }; |
| 2598 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2599 | return nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | } |
| 2601 | |
| 2602 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2603 | unsigned int pgbase, unsigned int pglen) |
| 2604 | { |
| 2605 | struct nfs4_exception exception = { }; |
| 2606 | int err; |
| 2607 | do { |
| 2608 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2609 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2610 | &exception); |
| 2611 | } while (exception.retry); |
| 2612 | return err; |
| 2613 | } |
| 2614 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2615 | /* |
| 2616 | * Got race? |
| 2617 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2618 | * Until then, this create/open method is prone to inefficiency and race |
| 2619 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2620 | * placed on the wire. |
| 2621 | * |
| 2622 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2623 | * The file will be opened again in the subsequent VFS open call |
| 2624 | * (nfs4_proc_file_open). |
| 2625 | * |
| 2626 | * The open for read will just hang around to be used by any process that |
| 2627 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2628 | */ |
| 2629 | |
| 2630 | static int |
| 2631 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2632 | int flags, struct nfs_open_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2634 | struct dentry *de = dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2635 | struct nfs4_state *state; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2636 | struct rpc_cred *cred = NULL; |
| 2637 | fmode_t fmode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2638 | int status = 0; |
| 2639 | |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2640 | if (ctx != NULL) { |
| 2641 | cred = ctx->cred; |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2642 | de = ctx->dentry; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2643 | fmode = ctx->mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | } |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2645 | sattr->ia_mode &= ~current_umask(); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2646 | state = nfs4_do_open(dir, de, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2647 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | if (IS_ERR(state)) { |
| 2649 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2650 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2651 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2652 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2653 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2654 | if (ctx != NULL) |
| 2655 | ctx->state = state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2656 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2657 | nfs4_close_sync(state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2658 | out: |
| 2659 | return status; |
| 2660 | } |
| 2661 | |
| 2662 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2663 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2664 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2665 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2666 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2667 | .name.len = name->len, |
| 2668 | .name.name = name->name, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2669 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2671 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2672 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2673 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2674 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2675 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2676 | .rpc_argp = &args, |
| 2677 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | }; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2679 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2681 | res.dir_attr = nfs_alloc_fattr(); |
| 2682 | if (res.dir_attr == NULL) |
| 2683 | goto out; |
| 2684 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2685 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2686 | if (status == 0) { |
| 2687 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2688 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2689 | } |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2690 | nfs_free_fattr(res.dir_attr); |
| 2691 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2692 | return status; |
| 2693 | } |
| 2694 | |
| 2695 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2696 | { |
| 2697 | struct nfs4_exception exception = { }; |
| 2698 | int err; |
| 2699 | do { |
| 2700 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2701 | _nfs4_proc_remove(dir, name), |
| 2702 | &exception); |
| 2703 | } while (exception.retry); |
| 2704 | return err; |
| 2705 | } |
| 2706 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2707 | 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] | 2708 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2709 | struct nfs_server *server = NFS_SERVER(dir); |
| 2710 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2711 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2712 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2713 | args->bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2714 | res->server = server; |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 2715 | res->seq_res.sr_slot = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | } |
| 2718 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2719 | 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] | 2720 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2721 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2722 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2723 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2724 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2725 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2726 | return 0; |
| 2727 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2728 | nfs_post_op_update_inode(dir, res->dir_attr); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2729 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2730 | } |
| 2731 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2732 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2733 | { |
| 2734 | struct nfs_server *server = NFS_SERVER(dir); |
| 2735 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2736 | struct nfs_renameres *res = msg->rpc_resp; |
| 2737 | |
| 2738 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
| 2739 | arg->bitmask = server->attr_bitmask; |
| 2740 | res->server = server; |
| 2741 | } |
| 2742 | |
| 2743 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2744 | struct inode *new_dir) |
| 2745 | { |
| 2746 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2747 | |
| 2748 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2749 | return 0; |
| 2750 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2751 | return 0; |
| 2752 | |
| 2753 | update_changeattr(old_dir, &res->old_cinfo); |
| 2754 | nfs_post_op_update_inode(old_dir, res->old_fattr); |
| 2755 | update_changeattr(new_dir, &res->new_cinfo); |
| 2756 | nfs_post_op_update_inode(new_dir, res->new_fattr); |
| 2757 | return 1; |
| 2758 | } |
| 2759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2761 | struct inode *new_dir, struct qstr *new_name) |
| 2762 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2763 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2764 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | .old_dir = NFS_FH(old_dir), |
| 2766 | .new_dir = NFS_FH(new_dir), |
| 2767 | .old_name = old_name, |
| 2768 | .new_name = new_name, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2769 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2771 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2772 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2773 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2774 | struct rpc_message msg = { |
| 2775 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2776 | .rpc_argp = &arg, |
| 2777 | .rpc_resp = &res, |
| 2778 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2779 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2781 | res.old_fattr = nfs_alloc_fattr(); |
| 2782 | res.new_fattr = nfs_alloc_fattr(); |
| 2783 | if (res.old_fattr == NULL || res.new_fattr == NULL) |
| 2784 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2785 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2786 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | if (!status) { |
| 2788 | update_changeattr(old_dir, &res.old_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2789 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 | update_changeattr(new_dir, &res.new_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2791 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | } |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2793 | out: |
| 2794 | nfs_free_fattr(res.new_fattr); |
| 2795 | nfs_free_fattr(res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | return status; |
| 2797 | } |
| 2798 | |
| 2799 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2800 | struct inode *new_dir, struct qstr *new_name) |
| 2801 | { |
| 2802 | struct nfs4_exception exception = { }; |
| 2803 | int err; |
| 2804 | do { |
| 2805 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2806 | _nfs4_proc_rename(old_dir, old_name, |
| 2807 | new_dir, new_name), |
| 2808 | &exception); |
| 2809 | } while (exception.retry); |
| 2810 | return err; |
| 2811 | } |
| 2812 | |
| 2813 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2814 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2815 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | struct nfs4_link_arg arg = { |
| 2817 | .fh = NFS_FH(inode), |
| 2818 | .dir_fh = NFS_FH(dir), |
| 2819 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2820 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2822 | struct nfs4_link_res res = { |
| 2823 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2824 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2825 | struct rpc_message msg = { |
| 2826 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2827 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2828 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2830 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2832 | res.fattr = nfs_alloc_fattr(); |
| 2833 | res.dir_attr = nfs_alloc_fattr(); |
| 2834 | if (res.fattr == NULL || res.dir_attr == NULL) |
| 2835 | goto out; |
| 2836 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2837 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2838 | if (!status) { |
| 2839 | update_changeattr(dir, &res.cinfo); |
| 2840 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2841 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2842 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2843 | out: |
| 2844 | nfs_free_fattr(res.dir_attr); |
| 2845 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | return status; |
| 2847 | } |
| 2848 | |
| 2849 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2850 | { |
| 2851 | struct nfs4_exception exception = { }; |
| 2852 | int err; |
| 2853 | do { |
| 2854 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2855 | _nfs4_proc_link(inode, dir, name), |
| 2856 | &exception); |
| 2857 | } while (exception.retry); |
| 2858 | return err; |
| 2859 | } |
| 2860 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2861 | struct nfs4_createdata { |
| 2862 | struct rpc_message msg; |
| 2863 | struct nfs4_create_arg arg; |
| 2864 | struct nfs4_create_res res; |
| 2865 | struct nfs_fh fh; |
| 2866 | struct nfs_fattr fattr; |
| 2867 | struct nfs_fattr dir_fattr; |
| 2868 | }; |
| 2869 | |
| 2870 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 2871 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 2872 | { |
| 2873 | struct nfs4_createdata *data; |
| 2874 | |
| 2875 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2876 | if (data != NULL) { |
| 2877 | struct nfs_server *server = NFS_SERVER(dir); |
| 2878 | |
| 2879 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 2880 | data->msg.rpc_argp = &data->arg; |
| 2881 | data->msg.rpc_resp = &data->res; |
| 2882 | data->arg.dir_fh = NFS_FH(dir); |
| 2883 | data->arg.server = server; |
| 2884 | data->arg.name = name; |
| 2885 | data->arg.attrs = sattr; |
| 2886 | data->arg.ftype = ftype; |
| 2887 | data->arg.bitmask = server->attr_bitmask; |
| 2888 | data->res.server = server; |
| 2889 | data->res.fh = &data->fh; |
| 2890 | data->res.fattr = &data->fattr; |
| 2891 | data->res.dir_fattr = &data->dir_fattr; |
| 2892 | nfs_fattr_init(data->res.fattr); |
| 2893 | nfs_fattr_init(data->res.dir_fattr); |
| 2894 | } |
| 2895 | return data; |
| 2896 | } |
| 2897 | |
| 2898 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 2899 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2900 | int status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &data->msg, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 2901 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2902 | if (status == 0) { |
| 2903 | update_changeattr(dir, &data->res.dir_cinfo); |
| 2904 | nfs_post_op_update_inode(dir, data->res.dir_fattr); |
| 2905 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 2906 | } |
| 2907 | return status; |
| 2908 | } |
| 2909 | |
| 2910 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 2911 | { |
| 2912 | kfree(data); |
| 2913 | } |
| 2914 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2915 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2916 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2917 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2918 | struct nfs4_createdata *data; |
| 2919 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2921 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2922 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2923 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2924 | status = -ENOMEM; |
| 2925 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 2926 | if (data == NULL) |
| 2927 | goto out; |
| 2928 | |
| 2929 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 2930 | data->arg.u.symlink.pages = &page; |
| 2931 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2933 | status = nfs4_do_create(dir, dentry, data); |
| 2934 | |
| 2935 | nfs4_free_createdata(data); |
| 2936 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2937 | return status; |
| 2938 | } |
| 2939 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2940 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2941 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | { |
| 2943 | struct nfs4_exception exception = { }; |
| 2944 | int err; |
| 2945 | do { |
| 2946 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2947 | _nfs4_proc_symlink(dir, dentry, page, |
| 2948 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2949 | &exception); |
| 2950 | } while (exception.retry); |
| 2951 | return err; |
| 2952 | } |
| 2953 | |
| 2954 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2955 | struct iattr *sattr) |
| 2956 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2957 | struct nfs4_createdata *data; |
| 2958 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2959 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2960 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 2961 | if (data == NULL) |
| 2962 | goto out; |
| 2963 | |
| 2964 | status = nfs4_do_create(dir, dentry, data); |
| 2965 | |
| 2966 | nfs4_free_createdata(data); |
| 2967 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | return status; |
| 2969 | } |
| 2970 | |
| 2971 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2972 | struct iattr *sattr) |
| 2973 | { |
| 2974 | struct nfs4_exception exception = { }; |
| 2975 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2976 | |
| 2977 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | do { |
| 2979 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2980 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 2981 | &exception); |
| 2982 | } while (exception.retry); |
| 2983 | return err; |
| 2984 | } |
| 2985 | |
| 2986 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2987 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | { |
| 2989 | struct inode *dir = dentry->d_inode; |
| 2990 | struct nfs4_readdir_arg args = { |
| 2991 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2992 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2993 | .pgbase = 0, |
| 2994 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 2995 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 2996 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | }; |
| 2998 | struct nfs4_readdir_res res; |
| 2999 | struct rpc_message msg = { |
| 3000 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3001 | .rpc_argp = &args, |
| 3002 | .rpc_resp = &res, |
| 3003 | .rpc_cred = cred, |
| 3004 | }; |
| 3005 | int status; |
| 3006 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3007 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3008 | dentry->d_parent->d_name.name, |
| 3009 | dentry->d_name.name, |
| 3010 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 3012 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3013 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3014 | if (status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3016 | status += args.pgbase; |
| 3017 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3018 | |
| 3019 | nfs_invalidate_atime(dir); |
| 3020 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3021 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | return status; |
| 3023 | } |
| 3024 | |
| 3025 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3026 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3027 | { |
| 3028 | struct nfs4_exception exception = { }; |
| 3029 | int err; |
| 3030 | do { |
| 3031 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3032 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3033 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | &exception); |
| 3035 | } while (exception.retry); |
| 3036 | return err; |
| 3037 | } |
| 3038 | |
| 3039 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3040 | struct iattr *sattr, dev_t rdev) |
| 3041 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3042 | struct nfs4_createdata *data; |
| 3043 | int mode = sattr->ia_mode; |
| 3044 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | |
| 3046 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 3047 | 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] | 3048 | |
| 3049 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3050 | if (data == NULL) |
| 3051 | goto out; |
| 3052 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3053 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3054 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3056 | data->arg.ftype = NF4BLK; |
| 3057 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3058 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3059 | } |
| 3060 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3061 | data->arg.ftype = NF4CHR; |
| 3062 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3063 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3066 | status = nfs4_do_create(dir, dentry, data); |
| 3067 | |
| 3068 | nfs4_free_createdata(data); |
| 3069 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | return status; |
| 3071 | } |
| 3072 | |
| 3073 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3074 | struct iattr *sattr, dev_t rdev) |
| 3075 | { |
| 3076 | struct nfs4_exception exception = { }; |
| 3077 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3078 | |
| 3079 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3080 | do { |
| 3081 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3082 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3083 | &exception); |
| 3084 | } while (exception.retry); |
| 3085 | return err; |
| 3086 | } |
| 3087 | |
| 3088 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3089 | struct nfs_fsstat *fsstat) |
| 3090 | { |
| 3091 | struct nfs4_statfs_arg args = { |
| 3092 | .fh = fhandle, |
| 3093 | .bitmask = server->attr_bitmask, |
| 3094 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3095 | struct nfs4_statfs_res res = { |
| 3096 | .fsstat = fsstat, |
| 3097 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3098 | struct rpc_message msg = { |
| 3099 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3100 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3101 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | }; |
| 3103 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3104 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3105 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | } |
| 3107 | |
| 3108 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3109 | { |
| 3110 | struct nfs4_exception exception = { }; |
| 3111 | int err; |
| 3112 | do { |
| 3113 | err = nfs4_handle_exception(server, |
| 3114 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3115 | &exception); |
| 3116 | } while (exception.retry); |
| 3117 | return err; |
| 3118 | } |
| 3119 | |
| 3120 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3121 | struct nfs_fsinfo *fsinfo) |
| 3122 | { |
| 3123 | struct nfs4_fsinfo_arg args = { |
| 3124 | .fh = fhandle, |
| 3125 | .bitmask = server->attr_bitmask, |
| 3126 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3127 | struct nfs4_fsinfo_res res = { |
| 3128 | .fsinfo = fsinfo, |
| 3129 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3130 | struct rpc_message msg = { |
| 3131 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3132 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3133 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | }; |
| 3135 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3136 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3137 | } |
| 3138 | |
| 3139 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3140 | { |
| 3141 | struct nfs4_exception exception = { }; |
| 3142 | int err; |
| 3143 | |
| 3144 | do { |
| 3145 | err = nfs4_handle_exception(server, |
| 3146 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3147 | &exception); |
| 3148 | } while (exception.retry); |
| 3149 | return err; |
| 3150 | } |
| 3151 | |
| 3152 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3153 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3154 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3156 | } |
| 3157 | |
| 3158 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3159 | struct nfs_pathconf *pathconf) |
| 3160 | { |
| 3161 | struct nfs4_pathconf_arg args = { |
| 3162 | .fh = fhandle, |
| 3163 | .bitmask = server->attr_bitmask, |
| 3164 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3165 | struct nfs4_pathconf_res res = { |
| 3166 | .pathconf = pathconf, |
| 3167 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | struct rpc_message msg = { |
| 3169 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3170 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3171 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | }; |
| 3173 | |
| 3174 | /* None of the pathconf attributes are mandatory to implement */ |
| 3175 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3176 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3177 | return 0; |
| 3178 | } |
| 3179 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3180 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3181 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3185 | struct nfs_pathconf *pathconf) |
| 3186 | { |
| 3187 | struct nfs4_exception exception = { }; |
| 3188 | int err; |
| 3189 | |
| 3190 | do { |
| 3191 | err = nfs4_handle_exception(server, |
| 3192 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3193 | &exception); |
| 3194 | } while (exception.retry); |
| 3195 | return err; |
| 3196 | } |
| 3197 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3198 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3199 | { |
| 3200 | nfs_invalidate_atime(data->inode); |
| 3201 | } |
| 3202 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3203 | 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] | 3204 | { |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3205 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3207 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3208 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3209 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3211 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3212 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3214 | renew_lease(server, data->timestamp); |
| 3215 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | } |
| 3217 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3218 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3219 | { |
| 3220 | |
| 3221 | dprintk("--> %s\n", __func__); |
| 3222 | |
| 3223 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3224 | return -EAGAIN; |
| 3225 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3226 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3227 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3228 | } |
| 3229 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3230 | 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] | 3231 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3233 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3234 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 | } |
| 3236 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3237 | /* Reset the the nfs_read_data to send the read to the MDS. */ |
| 3238 | void nfs4_reset_read(struct rpc_task *task, struct nfs_read_data *data) |
| 3239 | { |
| 3240 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3241 | put_lseg(data->lseg); |
| 3242 | data->lseg = NULL; |
| 3243 | /* offsets will differ in the dense stripe case */ |
| 3244 | data->args.offset = data->mds_offset; |
| 3245 | data->ds_clp = NULL; |
| 3246 | data->args.fh = NFS_FH(data->inode); |
| 3247 | data->read_done_cb = nfs4_read_done_cb; |
| 3248 | task->tk_ops = data->mds_ops; |
| 3249 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3250 | } |
| 3251 | EXPORT_SYMBOL_GPL(nfs4_reset_read); |
| 3252 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3253 | 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] | 3254 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | struct inode *inode = data->inode; |
| 3256 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3257 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3258 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3259 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3261 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 3263 | nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3264 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3265 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | } |
| 3267 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3268 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3269 | { |
| 3270 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3271 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3272 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3273 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3274 | } |
| 3275 | |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3276 | /* Reset the the nfs_write_data to send the write to the MDS. */ |
| 3277 | void nfs4_reset_write(struct rpc_task *task, struct nfs_write_data *data) |
| 3278 | { |
| 3279 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3280 | put_lseg(data->lseg); |
| 3281 | data->lseg = NULL; |
| 3282 | data->ds_clp = NULL; |
| 3283 | data->write_done_cb = nfs4_write_done_cb; |
| 3284 | data->args.fh = NFS_FH(data->inode); |
| 3285 | data->args.bitmask = data->res.server->cache_consistency_bitmask; |
| 3286 | data->args.offset = data->mds_offset; |
| 3287 | data->res.fattr = &data->fattr; |
| 3288 | task->tk_ops = data->mds_ops; |
| 3289 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3290 | } |
| 3291 | EXPORT_SYMBOL_GPL(nfs4_reset_write); |
| 3292 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3293 | 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] | 3294 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3295 | struct nfs_server *server = NFS_SERVER(data->inode); |
| 3296 | |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3297 | if (data->lseg) { |
| 3298 | data->args.bitmask = NULL; |
| 3299 | data->res.fattr = NULL; |
| 3300 | } else |
| 3301 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3302 | if (!data->write_done_cb) |
| 3303 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3304 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3305 | data->timestamp = jiffies; |
| 3306 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3307 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | } |
| 3309 | |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3310 | static int nfs4_commit_done_cb(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3312 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3313 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3314 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3315 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3316 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3317 | } |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 3318 | nfs_refresh_inode(inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3319 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3320 | } |
| 3321 | |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3322 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3323 | { |
| 3324 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3325 | return -EAGAIN; |
| 3326 | return data->write_done_cb(task, data); |
| 3327 | } |
| 3328 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3329 | 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] | 3330 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3331 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3332 | |
| 3333 | if (data->lseg) { |
| 3334 | data->args.bitmask = NULL; |
| 3335 | data->res.fattr = NULL; |
| 3336 | } else |
| 3337 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3338 | if (!data->write_done_cb) |
| 3339 | data->write_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3340 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3341 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3342 | } |
| 3343 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3344 | struct nfs4_renewdata { |
| 3345 | struct nfs_client *client; |
| 3346 | unsigned long timestamp; |
| 3347 | }; |
| 3348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3349 | /* |
| 3350 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3351 | * standalone procedure for queueing an asynchronous RENEW. |
| 3352 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3353 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3354 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3355 | struct nfs4_renewdata *data = calldata; |
| 3356 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3357 | |
Alexandros Batsakis | 0851de0 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3358 | if (atomic_read(&clp->cl_count) > 1) |
| 3359 | nfs4_schedule_state_renewal(clp); |
| 3360 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3361 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3362 | } |
| 3363 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3364 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3365 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3366 | struct nfs4_renewdata *data = calldata; |
| 3367 | struct nfs_client *clp = data->client; |
| 3368 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 | |
| 3370 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3371 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3372 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3373 | return; |
| 3374 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3375 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3376 | return; |
| 3377 | } |
| 3378 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3380 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | } |
| 3382 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3383 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3384 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3385 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3386 | }; |
| 3387 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3388 | static int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | { |
| 3390 | struct rpc_message msg = { |
| 3391 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3392 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3393 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3395 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3397 | if (renew_flags == 0) |
| 3398 | return 0; |
Alexandros Batsakis | 0851de0 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3399 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3400 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3401 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3402 | if (data == NULL) |
| 3403 | return -ENOMEM; |
| 3404 | data->client = clp; |
| 3405 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3406 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3407 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3408 | } |
| 3409 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3410 | static int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3411 | { |
| 3412 | struct rpc_message msg = { |
| 3413 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3414 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3415 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3416 | }; |
| 3417 | unsigned long now = jiffies; |
| 3418 | int status; |
| 3419 | |
| 3420 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3421 | if (status < 0) |
| 3422 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3423 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3424 | return 0; |
| 3425 | } |
| 3426 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3427 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3428 | { |
| 3429 | return (server->caps & NFS_CAP_ACLS) |
| 3430 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3431 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3432 | } |
| 3433 | |
| 3434 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3435 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3436 | * the stack. |
| 3437 | */ |
| 3438 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3439 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3440 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3441 | struct page **pages, unsigned int *pgbase) |
| 3442 | { |
| 3443 | struct page *newpage, **spages; |
| 3444 | int rc = 0; |
| 3445 | size_t len; |
| 3446 | spages = pages; |
| 3447 | |
| 3448 | do { |
Jovi Zhang | 43b7c3f | 2011-03-02 23:19:37 +0000 | [diff] [blame] | 3449 | len = min_t(size_t, PAGE_CACHE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3450 | newpage = alloc_page(GFP_KERNEL); |
| 3451 | |
| 3452 | if (newpage == NULL) |
| 3453 | goto unwind; |
| 3454 | memcpy(page_address(newpage), buf, len); |
| 3455 | buf += len; |
| 3456 | buflen -= len; |
| 3457 | *pages++ = newpage; |
| 3458 | rc++; |
| 3459 | } while (buflen != 0); |
| 3460 | |
| 3461 | return rc; |
| 3462 | |
| 3463 | unwind: |
| 3464 | for(; rc > 0; rc--) |
| 3465 | __free_page(spages[rc-1]); |
| 3466 | return -ENOMEM; |
| 3467 | } |
| 3468 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3469 | struct nfs4_cached_acl { |
| 3470 | int cached; |
| 3471 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3472 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3473 | }; |
| 3474 | |
| 3475 | 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] | 3476 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3477 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3478 | |
| 3479 | spin_lock(&inode->i_lock); |
| 3480 | kfree(nfsi->nfs4_acl); |
| 3481 | nfsi->nfs4_acl = acl; |
| 3482 | spin_unlock(&inode->i_lock); |
| 3483 | } |
| 3484 | |
| 3485 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3486 | { |
| 3487 | nfs4_set_cached_acl(inode, NULL); |
| 3488 | } |
| 3489 | |
| 3490 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3491 | { |
| 3492 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3493 | struct nfs4_cached_acl *acl; |
| 3494 | int ret = -ENOENT; |
| 3495 | |
| 3496 | spin_lock(&inode->i_lock); |
| 3497 | acl = nfsi->nfs4_acl; |
| 3498 | if (acl == NULL) |
| 3499 | goto out; |
| 3500 | if (buf == NULL) /* user is just asking for length */ |
| 3501 | goto out_len; |
| 3502 | if (acl->cached == 0) |
| 3503 | goto out; |
| 3504 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3505 | if (acl->len > buflen) |
| 3506 | goto out; |
| 3507 | memcpy(buf, acl->data, acl->len); |
| 3508 | out_len: |
| 3509 | ret = acl->len; |
| 3510 | out: |
| 3511 | spin_unlock(&inode->i_lock); |
| 3512 | return ret; |
| 3513 | } |
| 3514 | |
| 3515 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) |
| 3516 | { |
| 3517 | struct nfs4_cached_acl *acl; |
| 3518 | |
| 3519 | if (buf && acl_len <= PAGE_SIZE) { |
| 3520 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3521 | if (acl == NULL) |
| 3522 | goto out; |
| 3523 | acl->cached = 1; |
| 3524 | memcpy(acl->data, buf, acl_len); |
| 3525 | } else { |
| 3526 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3527 | if (acl == NULL) |
| 3528 | goto out; |
| 3529 | acl->cached = 0; |
| 3530 | } |
| 3531 | acl->len = acl_len; |
| 3532 | out: |
| 3533 | nfs4_set_cached_acl(inode, acl); |
| 3534 | } |
| 3535 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3536 | /* |
| 3537 | * The getxattr API returns the required buffer length when called with a |
| 3538 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3539 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3540 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3541 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3542 | * the cache. If not so, we throw away the page, and cache the required |
| 3543 | * length. The next getxattr call will then produce another round trip to |
| 3544 | * the server, this time with the input buf of the required size. |
| 3545 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3546 | 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] | 3547 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3548 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3549 | struct nfs_getaclargs args = { |
| 3550 | .fh = NFS_FH(inode), |
| 3551 | .acl_pages = pages, |
| 3552 | .acl_len = buflen, |
| 3553 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3554 | struct nfs_getaclres res = { |
| 3555 | .acl_len = buflen, |
| 3556 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3557 | void *resp_buf; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3558 | struct rpc_message msg = { |
| 3559 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3560 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3561 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3562 | }; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3563 | int ret = -ENOMEM, npages, i, acl_len = 0; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3564 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3565 | npages = (buflen + PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 3566 | /* As long as we're doing a round trip to the server anyway, |
| 3567 | * let's be prepared for a page of acl data. */ |
| 3568 | if (npages == 0) |
| 3569 | npages = 1; |
| 3570 | |
| 3571 | for (i = 0; i < npages; i++) { |
| 3572 | pages[i] = alloc_page(GFP_KERNEL); |
| 3573 | if (!pages[i]) |
| 3574 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3575 | } |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3576 | if (npages > 1) { |
| 3577 | /* for decoding across pages */ |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame^] | 3578 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 3579 | if (!res.acl_scratch) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3580 | goto out_free; |
| 3581 | } |
| 3582 | args.acl_len = npages * PAGE_SIZE; |
| 3583 | args.acl_pgbase = 0; |
| 3584 | /* Let decode_getfacl know not to fail if the ACL data is larger than |
| 3585 | * the page we send as a guess */ |
| 3586 | if (buf == NULL) |
| 3587 | res.acl_flags |= NFS4_ACL_LEN_REQUEST; |
| 3588 | resp_buf = page_address(pages[0]); |
| 3589 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3590 | dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n", |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3591 | __func__, buf, buflen, npages, args.acl_len); |
| 3592 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 3593 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3594 | if (ret) |
| 3595 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3596 | |
| 3597 | acl_len = res.acl_len - res.acl_data_offset; |
| 3598 | if (acl_len > args.acl_len) |
| 3599 | nfs4_write_cached_acl(inode, NULL, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3600 | else |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3601 | nfs4_write_cached_acl(inode, resp_buf + res.acl_data_offset, |
| 3602 | acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3603 | if (buf) { |
| 3604 | ret = -ERANGE; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3605 | if (acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3606 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3607 | _copy_from_pages(buf, pages, res.acl_data_offset, |
| 3608 | res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3609 | } |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3610 | ret = acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3611 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3612 | for (i = 0; i < npages; i++) |
| 3613 | if (pages[i]) |
| 3614 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame^] | 3615 | if (res.acl_scratch) |
| 3616 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3617 | return ret; |
| 3618 | } |
| 3619 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3620 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3621 | { |
| 3622 | struct nfs4_exception exception = { }; |
| 3623 | ssize_t ret; |
| 3624 | do { |
| 3625 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3626 | if (ret >= 0) |
| 3627 | break; |
| 3628 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3629 | } while (exception.retry); |
| 3630 | return ret; |
| 3631 | } |
| 3632 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3633 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3634 | { |
| 3635 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3636 | int ret; |
| 3637 | |
| 3638 | if (!nfs4_server_supports_acls(server)) |
| 3639 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3640 | ret = nfs_revalidate_inode(server, inode); |
| 3641 | if (ret < 0) |
| 3642 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3643 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3644 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3645 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3646 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3647 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 3648 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3649 | return ret; |
| 3650 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3651 | } |
| 3652 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3653 | 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] | 3654 | { |
| 3655 | struct nfs_server *server = NFS_SERVER(inode); |
| 3656 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3657 | struct nfs_setaclargs arg = { |
| 3658 | .fh = NFS_FH(inode), |
| 3659 | .acl_pages = pages, |
| 3660 | .acl_len = buflen, |
| 3661 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3662 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3663 | struct rpc_message msg = { |
| 3664 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3665 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3666 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3667 | }; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3668 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3669 | |
| 3670 | if (!nfs4_server_supports_acls(server)) |
| 3671 | return -EOPNOTSUPP; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3672 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3673 | if (i < 0) |
| 3674 | return i; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3675 | nfs_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3676 | ret = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3677 | |
| 3678 | /* |
| 3679 | * Free each page after tx, so the only ref left is |
| 3680 | * held by the network stack |
| 3681 | */ |
| 3682 | for (; i > 0; i--) |
| 3683 | put_page(pages[i-1]); |
| 3684 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3685 | /* |
| 3686 | * Acl update can result in inode attribute update. |
| 3687 | * so mark the attribute cache invalid. |
| 3688 | */ |
| 3689 | spin_lock(&inode->i_lock); |
| 3690 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3691 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3692 | nfs_access_zap_cache(inode); |
| 3693 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3694 | return ret; |
| 3695 | } |
| 3696 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3697 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3698 | { |
| 3699 | struct nfs4_exception exception = { }; |
| 3700 | int err; |
| 3701 | do { |
| 3702 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3703 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3704 | &exception); |
| 3705 | } while (exception.retry); |
| 3706 | return err; |
| 3707 | } |
| 3708 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3709 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3710 | 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] | 3711 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3712 | struct nfs_client *clp = server->nfs_client; |
| 3713 | |
| 3714 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3715 | return 0; |
| 3716 | switch(task->tk_status) { |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3717 | case -NFS4ERR_ADMIN_REVOKED: |
| 3718 | case -NFS4ERR_BAD_STATEID: |
| 3719 | case -NFS4ERR_OPENMODE: |
| 3720 | if (state == NULL) |
| 3721 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3722 | nfs4_schedule_stateid_recovery(server, state); |
| 3723 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 3724 | case -NFS4ERR_EXPIRED: |
| 3725 | if (state != NULL) |
| 3726 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3727 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3728 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3729 | nfs4_schedule_lease_recovery(clp); |
| 3730 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3731 | #if defined(CONFIG_NFS_V4_1) |
| 3732 | case -NFS4ERR_BADSESSION: |
| 3733 | case -NFS4ERR_BADSLOT: |
| 3734 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3735 | case -NFS4ERR_DEADSESSION: |
| 3736 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3737 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3738 | case -NFS4ERR_SEQ_MISORDERED: |
| 3739 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3740 | task->tk_status); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3741 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3742 | task->tk_status = 0; |
| 3743 | return -EAGAIN; |
| 3744 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3746 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3747 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3748 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3749 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3750 | task->tk_status = 0; |
| 3751 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 3752 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3753 | case -NFS4ERR_OLD_STATEID: |
| 3754 | task->tk_status = 0; |
| 3755 | return -EAGAIN; |
| 3756 | } |
| 3757 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3758 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3759 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3760 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3761 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3762 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3763 | task->tk_status = 0; |
| 3764 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3765 | } |
| 3766 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3767 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 3768 | unsigned short port, struct rpc_cred *cred, |
| 3769 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3770 | { |
| 3771 | nfs4_verifier sc_verifier; |
| 3772 | struct nfs4_setclientid setclientid = { |
| 3773 | .sc_verifier = &sc_verifier, |
| 3774 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 3775 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3776 | }; |
| 3777 | struct rpc_message msg = { |
| 3778 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3779 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3780 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3781 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3782 | }; |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3783 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3784 | int loop = 0; |
| 3785 | int status; |
| 3786 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3787 | p = (__be32*)sc_verifier.data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3788 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 3789 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 3790 | |
| 3791 | for(;;) { |
| 3792 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3793 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3794 | clp->cl_ipaddr, |
| 3795 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3796 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3797 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3798 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3799 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3800 | clp->cl_id_uniquifier); |
| 3801 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3802 | sizeof(setclientid.sc_netid), |
| 3803 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3804 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3805 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3806 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3807 | clp->cl_ipaddr, port >> 8, port & 255); |
| 3808 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 3809 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3810 | if (status != -NFS4ERR_CLID_INUSE) |
| 3811 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3812 | if (loop != 0) { |
| 3813 | ++clp->cl_id_uniquifier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3815 | } |
| 3816 | ++loop; |
| 3817 | ssleep(clp->cl_lease_time / HZ + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3818 | } |
| 3819 | return status; |
| 3820 | } |
| 3821 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3822 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3823 | struct nfs4_setclientid_res *arg, |
| 3824 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3825 | { |
| 3826 | struct nfs_fsinfo fsinfo; |
| 3827 | struct rpc_message msg = { |
| 3828 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3829 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3830 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3831 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3832 | }; |
| 3833 | unsigned long now; |
| 3834 | int status; |
| 3835 | |
| 3836 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 3837 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3838 | if (status == 0) { |
| 3839 | spin_lock(&clp->cl_lock); |
| 3840 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 3841 | clp->cl_last_renewal = now; |
| 3842 | spin_unlock(&clp->cl_lock); |
| 3843 | } |
| 3844 | return status; |
| 3845 | } |
| 3846 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3847 | struct nfs4_delegreturndata { |
| 3848 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3849 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3850 | struct nfs_fh fh; |
| 3851 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3852 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3853 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3854 | int rpc_status; |
| 3855 | }; |
| 3856 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3857 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 3858 | { |
| 3859 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3860 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3861 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3862 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3863 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3864 | switch (task->tk_status) { |
| 3865 | case -NFS4ERR_STALE_STATEID: |
| 3866 | case -NFS4ERR_EXPIRED: |
| 3867 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3868 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3869 | break; |
| 3870 | default: |
| 3871 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 3872 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3873 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3874 | return; |
| 3875 | } |
| 3876 | } |
| 3877 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3878 | } |
| 3879 | |
| 3880 | static void nfs4_delegreturn_release(void *calldata) |
| 3881 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3882 | kfree(calldata); |
| 3883 | } |
| 3884 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3885 | #if defined(CONFIG_NFS_V4_1) |
| 3886 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 3887 | { |
| 3888 | struct nfs4_delegreturndata *d_data; |
| 3889 | |
| 3890 | d_data = (struct nfs4_delegreturndata *)data; |
| 3891 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3892 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3893 | &d_data->args.seq_args, |
| 3894 | &d_data->res.seq_res, 1, task)) |
| 3895 | return; |
| 3896 | rpc_call_start(task); |
| 3897 | } |
| 3898 | #endif /* CONFIG_NFS_V4_1 */ |
| 3899 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 3900 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3901 | #if defined(CONFIG_NFS_V4_1) |
| 3902 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 3903 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3904 | .rpc_call_done = nfs4_delegreturn_done, |
| 3905 | .rpc_release = nfs4_delegreturn_release, |
| 3906 | }; |
| 3907 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3908 | 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] | 3909 | { |
| 3910 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3911 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3912 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3913 | struct rpc_message msg = { |
| 3914 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 3915 | .rpc_cred = cred, |
| 3916 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3917 | struct rpc_task_setup task_setup_data = { |
| 3918 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3919 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3920 | .callback_ops = &nfs4_delegreturn_ops, |
| 3921 | .flags = RPC_TASK_ASYNC, |
| 3922 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3923 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3924 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3925 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3926 | if (data == NULL) |
| 3927 | return -ENOMEM; |
| 3928 | data->args.fhandle = &data->fh; |
| 3929 | data->args.stateid = &data->stateid; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3930 | data->args.bitmask = server->attr_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3931 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
| 3932 | memcpy(&data->stateid, stateid, sizeof(data->stateid)); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3933 | data->res.fattr = &data->fattr; |
| 3934 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3935 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3936 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3937 | data->rpc_status = 0; |
| 3938 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3939 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3940 | msg.rpc_argp = &data->args; |
| 3941 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3942 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 3943 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3944 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3945 | if (!issync) |
| 3946 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3947 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3948 | if (status != 0) |
| 3949 | goto out; |
| 3950 | status = data->rpc_status; |
| 3951 | if (status != 0) |
| 3952 | goto out; |
| 3953 | nfs_refresh_inode(inode, &data->fattr); |
| 3954 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3955 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3956 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3957 | } |
| 3958 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3959 | 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] | 3960 | { |
| 3961 | struct nfs_server *server = NFS_SERVER(inode); |
| 3962 | struct nfs4_exception exception = { }; |
| 3963 | int err; |
| 3964 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3965 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3966 | switch (err) { |
| 3967 | case -NFS4ERR_STALE_STATEID: |
| 3968 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3969 | case 0: |
| 3970 | return 0; |
| 3971 | } |
| 3972 | err = nfs4_handle_exception(server, err, &exception); |
| 3973 | } while (exception.retry); |
| 3974 | return err; |
| 3975 | } |
| 3976 | |
| 3977 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 3978 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 3979 | |
| 3980 | /* |
| 3981 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 3982 | */ |
| 3983 | static unsigned long |
| 3984 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 3985 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 3986 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | timeout <<= 1; |
| 3988 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 3989 | return NFS4_LOCK_MAXTIMEOUT; |
| 3990 | return timeout; |
| 3991 | } |
| 3992 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3993 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3994 | { |
| 3995 | struct inode *inode = state->inode; |
| 3996 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3997 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3998 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3999 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4000 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4001 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4002 | struct nfs_lockt_res res = { |
| 4003 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4004 | }; |
| 4005 | struct rpc_message msg = { |
| 4006 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4007 | .rpc_argp = &arg, |
| 4008 | .rpc_resp = &res, |
| 4009 | .rpc_cred = state->owner->so_cred, |
| 4010 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4011 | struct nfs4_lock_state *lsp; |
| 4012 | int status; |
| 4013 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4014 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4015 | status = nfs4_set_lock_state(state, request); |
| 4016 | if (status != 0) |
| 4017 | goto out; |
| 4018 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 4019 | arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4020 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4021 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4022 | switch (status) { |
| 4023 | case 0: |
| 4024 | request->fl_type = F_UNLCK; |
| 4025 | break; |
| 4026 | case -NFS4ERR_DENIED: |
| 4027 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4028 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4029 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4030 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4031 | return status; |
| 4032 | } |
| 4033 | |
| 4034 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4035 | { |
| 4036 | struct nfs4_exception exception = { }; |
| 4037 | int err; |
| 4038 | |
| 4039 | do { |
| 4040 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4041 | _nfs4_proc_getlk(state, cmd, request), |
| 4042 | &exception); |
| 4043 | } while (exception.retry); |
| 4044 | return err; |
| 4045 | } |
| 4046 | |
| 4047 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4048 | { |
| 4049 | int res = 0; |
| 4050 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4051 | case FL_POSIX: |
| 4052 | res = posix_lock_file_wait(file, fl); |
| 4053 | break; |
| 4054 | case FL_FLOCK: |
| 4055 | res = flock_lock_file_wait(file, fl); |
| 4056 | break; |
| 4057 | default: |
| 4058 | BUG(); |
| 4059 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4060 | return res; |
| 4061 | } |
| 4062 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4063 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4064 | struct nfs_locku_args arg; |
| 4065 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4066 | struct nfs4_lock_state *lsp; |
| 4067 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4068 | struct file_lock fl; |
| 4069 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4070 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4071 | }; |
| 4072 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4073 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4074 | struct nfs_open_context *ctx, |
| 4075 | struct nfs4_lock_state *lsp, |
| 4076 | struct nfs_seqid *seqid) |
| 4077 | { |
| 4078 | struct nfs4_unlockdata *p; |
| 4079 | struct inode *inode = lsp->ls_state->inode; |
| 4080 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4081 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4082 | if (p == NULL) |
| 4083 | return NULL; |
| 4084 | p->arg.fh = NFS_FH(inode); |
| 4085 | p->arg.fl = &p->fl; |
| 4086 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4087 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4088 | p->arg.stateid = &lsp->ls_stateid; |
| 4089 | p->lsp = lsp; |
| 4090 | atomic_inc(&lsp->ls_count); |
| 4091 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4092 | p->ctx = get_nfs_open_context(ctx); |
| 4093 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4094 | p->server = NFS_SERVER(inode); |
| 4095 | return p; |
| 4096 | } |
| 4097 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4098 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4099 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4100 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4101 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4102 | nfs4_put_lock_state(calldata->lsp); |
| 4103 | put_nfs_open_context(calldata->ctx); |
| 4104 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4105 | } |
| 4106 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4107 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4108 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4109 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4110 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4111 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4112 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4113 | switch (task->tk_status) { |
| 4114 | case 0: |
| 4115 | memcpy(calldata->lsp->ls_stateid.data, |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4116 | calldata->res.stateid.data, |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4117 | sizeof(calldata->lsp->ls_stateid.data)); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4118 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4119 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4120 | case -NFS4ERR_BAD_STATEID: |
| 4121 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4122 | case -NFS4ERR_STALE_STATEID: |
| 4123 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4124 | break; |
| 4125 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4126 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4127 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4128 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4129 | } |
| 4130 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4131 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4132 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4133 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4134 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4135 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4136 | return; |
| 4137 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4138 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4139 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4140 | return; |
| 4141 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4142 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4143 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4144 | &calldata->arg.seq_args, |
| 4145 | &calldata->res.seq_res, 1, task)) |
| 4146 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4147 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4148 | } |
| 4149 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4150 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4151 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4152 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4153 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4154 | }; |
| 4155 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4156 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4157 | struct nfs_open_context *ctx, |
| 4158 | struct nfs4_lock_state *lsp, |
| 4159 | struct nfs_seqid *seqid) |
| 4160 | { |
| 4161 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4162 | struct rpc_message msg = { |
| 4163 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4164 | .rpc_cred = ctx->cred, |
| 4165 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4166 | struct rpc_task_setup task_setup_data = { |
| 4167 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4168 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4169 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4170 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4171 | .flags = RPC_TASK_ASYNC, |
| 4172 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4173 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4174 | /* Ensure this is an unlock - when canceling a lock, the |
| 4175 | * canceled lock is passed in, and it won't be an unlock. |
| 4176 | */ |
| 4177 | fl->fl_type = F_UNLCK; |
| 4178 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4179 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4180 | if (data == NULL) { |
| 4181 | nfs_free_seqid(seqid); |
| 4182 | return ERR_PTR(-ENOMEM); |
| 4183 | } |
| 4184 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4185 | msg.rpc_argp = &data->arg; |
| 4186 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4187 | task_setup_data.callback_data = data; |
| 4188 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4189 | } |
| 4190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4191 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4192 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4193 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4194 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4195 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4196 | struct rpc_task *task; |
| 4197 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4198 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4199 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4200 | status = nfs4_set_lock_state(state, request); |
| 4201 | /* Unlock _before_ we do the RPC call */ |
| 4202 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4203 | down_read(&nfsi->rwsem); |
| 4204 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4205 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4206 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4207 | } |
| 4208 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4209 | if (status != 0) |
| 4210 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4211 | /* Is this a delegated lock? */ |
| 4212 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4213 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4214 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4215 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4216 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4217 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4218 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4219 | 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] | 4220 | status = PTR_ERR(task); |
| 4221 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4222 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4223 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4224 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4225 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4226 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4227 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4228 | } |
| 4229 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4230 | struct nfs4_lockdata { |
| 4231 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4232 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4233 | struct nfs4_lock_state *lsp; |
| 4234 | struct nfs_open_context *ctx; |
| 4235 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4236 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4237 | int rpc_status; |
| 4238 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4239 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4240 | }; |
| 4241 | |
| 4242 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4243 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4244 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4245 | { |
| 4246 | struct nfs4_lockdata *p; |
| 4247 | struct inode *inode = lsp->ls_state->inode; |
| 4248 | struct nfs_server *server = NFS_SERVER(inode); |
| 4249 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4250 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4251 | if (p == NULL) |
| 4252 | return NULL; |
| 4253 | |
| 4254 | p->arg.fh = NFS_FH(inode); |
| 4255 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4256 | 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] | 4257 | if (p->arg.open_seqid == NULL) |
| 4258 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4259 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4260 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4261 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4262 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4263 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 4264 | p->arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4265 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4266 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4267 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4268 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4269 | atomic_inc(&lsp->ls_count); |
| 4270 | p->ctx = get_nfs_open_context(ctx); |
| 4271 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4272 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4273 | out_free_seqid: |
| 4274 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4275 | out_free: |
| 4276 | kfree(p); |
| 4277 | return NULL; |
| 4278 | } |
| 4279 | |
| 4280 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4281 | { |
| 4282 | struct nfs4_lockdata *data = calldata; |
| 4283 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4284 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4285 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4286 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4287 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4288 | /* Do we need to do an open_to_lock_owner? */ |
| 4289 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4290 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4291 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4292 | data->arg.open_stateid = &state->stateid; |
| 4293 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4294 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4295 | } else |
| 4296 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4297 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4298 | if (nfs4_setup_sequence(data->server, |
| 4299 | &data->arg.seq_args, |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4300 | &data->res.seq_res, 1, task)) |
| 4301 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4302 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4303 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4304 | } |
| 4305 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4306 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4307 | { |
| 4308 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4309 | nfs4_lock_prepare(task, calldata); |
| 4310 | } |
| 4311 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4312 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4313 | { |
| 4314 | struct nfs4_lockdata *data = calldata; |
| 4315 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4316 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4317 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4318 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4319 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4320 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4321 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4322 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4323 | if (data->rpc_status == 0) |
| 4324 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4325 | else |
| 4326 | goto out; |
| 4327 | } |
| 4328 | if (data->rpc_status == 0) { |
| 4329 | memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, |
| 4330 | sizeof(data->lsp->ls_stateid.data)); |
| 4331 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4332 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4333 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4334 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4335 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4336 | } |
| 4337 | |
| 4338 | static void nfs4_lock_release(void *calldata) |
| 4339 | { |
| 4340 | struct nfs4_lockdata *data = calldata; |
| 4341 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4342 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4343 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4344 | if (data->cancelled != 0) { |
| 4345 | struct rpc_task *task; |
| 4346 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4347 | data->arg.lock_seqid); |
| 4348 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4349 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4350 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4351 | } else |
| 4352 | nfs_free_seqid(data->arg.lock_seqid); |
| 4353 | nfs4_put_lock_state(data->lsp); |
| 4354 | put_nfs_open_context(data->ctx); |
| 4355 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4356 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4357 | } |
| 4358 | |
| 4359 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4360 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4361 | .rpc_call_done = nfs4_lock_done, |
| 4362 | .rpc_release = nfs4_lock_release, |
| 4363 | }; |
| 4364 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4365 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4366 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4367 | .rpc_call_done = nfs4_lock_done, |
| 4368 | .rpc_release = nfs4_lock_release, |
| 4369 | }; |
| 4370 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4371 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4372 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4373 | switch (error) { |
| 4374 | case -NFS4ERR_ADMIN_REVOKED: |
| 4375 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4376 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4377 | if (new_lock_owner != 0 || |
| 4378 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4379 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4380 | break; |
| 4381 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4382 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4383 | case -NFS4ERR_EXPIRED: |
| 4384 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4385 | }; |
| 4386 | } |
| 4387 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4388 | 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] | 4389 | { |
| 4390 | struct nfs4_lockdata *data; |
| 4391 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4392 | struct rpc_message msg = { |
| 4393 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4394 | .rpc_cred = state->owner->so_cred, |
| 4395 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4396 | struct rpc_task_setup task_setup_data = { |
| 4397 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4398 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4399 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4400 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4401 | .flags = RPC_TASK_ASYNC, |
| 4402 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4403 | int ret; |
| 4404 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4405 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4406 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4407 | fl->fl_u.nfs4_fl.owner, |
| 4408 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4409 | if (data == NULL) |
| 4410 | return -ENOMEM; |
| 4411 | if (IS_SETLKW(cmd)) |
| 4412 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4413 | if (recovery_type > NFS_LOCK_NEW) { |
| 4414 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4415 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4416 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4417 | } |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4418 | msg.rpc_argp = &data->arg; |
| 4419 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4420 | task_setup_data.callback_data = data; |
| 4421 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4422 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4423 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4424 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4425 | if (ret == 0) { |
| 4426 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4427 | if (ret) |
| 4428 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4429 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4430 | } else |
| 4431 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4432 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4433 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4434 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4435 | } |
| 4436 | |
| 4437 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4438 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4439 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4440 | struct nfs4_exception exception = { }; |
| 4441 | int err; |
| 4442 | |
| 4443 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4444 | /* Cache the lock if possible... */ |
| 4445 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4446 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4447 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4448 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4449 | break; |
| 4450 | nfs4_handle_exception(server, err, &exception); |
| 4451 | } while (exception.retry); |
| 4452 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4453 | } |
| 4454 | |
| 4455 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4456 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4457 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4458 | struct nfs4_exception exception = { }; |
| 4459 | int err; |
| 4460 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4461 | err = nfs4_set_lock_state(state, request); |
| 4462 | if (err != 0) |
| 4463 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4464 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4465 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4466 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4467 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4468 | switch (err) { |
| 4469 | default: |
| 4470 | goto out; |
| 4471 | case -NFS4ERR_GRACE: |
| 4472 | case -NFS4ERR_DELAY: |
| 4473 | nfs4_handle_exception(server, err, &exception); |
| 4474 | err = 0; |
| 4475 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4476 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4477 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4478 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | } |
| 4480 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4481 | #if defined(CONFIG_NFS_V4_1) |
| 4482 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4483 | { |
| 4484 | int status; |
| 4485 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4486 | |
| 4487 | status = nfs41_test_stateid(server, state); |
| 4488 | if (status == NFS_OK) |
| 4489 | return 0; |
| 4490 | nfs41_free_stateid(server, state); |
| 4491 | return nfs4_lock_expired(state, request); |
| 4492 | } |
| 4493 | #endif |
| 4494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4496 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4497 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4498 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4499 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4500 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4501 | if ((fl_flags & FL_POSIX) && |
| 4502 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4503 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4504 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4505 | status = nfs4_set_lock_state(state, request); |
| 4506 | if (status != 0) |
| 4507 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4508 | request->fl_flags |= FL_ACCESS; |
| 4509 | status = do_vfs_lock(request->fl_file, request); |
| 4510 | if (status < 0) |
| 4511 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4512 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4513 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4514 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4515 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4516 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4517 | status = do_vfs_lock(request->fl_file, request); |
| 4518 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4519 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4520 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4521 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4522 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4523 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4524 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4525 | if (do_vfs_lock(request->fl_file, request) < 0) |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4526 | 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] | 4527 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4528 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4529 | out: |
| 4530 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4531 | return status; |
| 4532 | } |
| 4533 | |
| 4534 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4535 | { |
| 4536 | struct nfs4_exception exception = { }; |
| 4537 | int err; |
| 4538 | |
| 4539 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4540 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4541 | if (err == -NFS4ERR_DENIED) |
| 4542 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4543 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4544 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4545 | } while (exception.retry); |
| 4546 | return err; |
| 4547 | } |
| 4548 | |
| 4549 | static int |
| 4550 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4551 | { |
| 4552 | struct nfs_open_context *ctx; |
| 4553 | struct nfs4_state *state; |
| 4554 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4555 | int status; |
| 4556 | |
| 4557 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4558 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | state = ctx->state; |
| 4560 | |
| 4561 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4562 | return -EINVAL; |
| 4563 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4564 | if (IS_GETLK(cmd)) { |
| 4565 | if (state != NULL) |
| 4566 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4567 | return 0; |
| 4568 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4569 | |
| 4570 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4571 | return -EINVAL; |
| 4572 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4573 | if (request->fl_type == F_UNLCK) { |
| 4574 | if (state != NULL) |
| 4575 | return nfs4_proc_unlck(state, cmd, request); |
| 4576 | return 0; |
| 4577 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4578 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4579 | if (state == NULL) |
| 4580 | return -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4581 | do { |
| 4582 | status = nfs4_proc_setlk(state, cmd, request); |
| 4583 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4584 | break; |
| 4585 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4586 | status = -ERESTARTSYS; |
| 4587 | if (signalled()) |
| 4588 | break; |
| 4589 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4590 | return status; |
| 4591 | } |
| 4592 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4593 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4594 | { |
| 4595 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4596 | struct nfs4_exception exception = { }; |
| 4597 | int err; |
| 4598 | |
| 4599 | err = nfs4_set_lock_state(state, fl); |
| 4600 | if (err != 0) |
| 4601 | goto out; |
| 4602 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4603 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4604 | switch (err) { |
| 4605 | default: |
| 4606 | printk(KERN_ERR "%s: unhandled error %d.\n", |
| 4607 | __func__, err); |
| 4608 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4609 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4610 | goto out; |
| 4611 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4612 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4613 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4614 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4615 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4616 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4617 | case -NFS4ERR_BADSESSION: |
| 4618 | case -NFS4ERR_BADSLOT: |
| 4619 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4620 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4621 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4622 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4623 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4624 | case -ERESTARTSYS: |
| 4625 | /* |
| 4626 | * The show must go on: exit, but mark the |
| 4627 | * stateid as needing recovery. |
| 4628 | */ |
| 4629 | case -NFS4ERR_ADMIN_REVOKED: |
| 4630 | case -NFS4ERR_BAD_STATEID: |
| 4631 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4632 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4633 | err = 0; |
| 4634 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4635 | case -EKEYEXPIRED: |
| 4636 | /* |
| 4637 | * User RPCSEC_GSS context has expired. |
| 4638 | * We cannot recover this stateid now, so |
| 4639 | * skip it and allow recovery thread to |
| 4640 | * proceed. |
| 4641 | */ |
| 4642 | err = 0; |
| 4643 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4644 | case -ENOMEM: |
| 4645 | case -NFS4ERR_DENIED: |
| 4646 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4647 | err = 0; |
| 4648 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4649 | case -NFS4ERR_DELAY: |
| 4650 | break; |
| 4651 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4652 | err = nfs4_handle_exception(server, err, &exception); |
| 4653 | } while (exception.retry); |
| 4654 | out: |
| 4655 | return err; |
| 4656 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4657 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4658 | static void nfs4_release_lockowner_release(void *calldata) |
| 4659 | { |
| 4660 | kfree(calldata); |
| 4661 | } |
| 4662 | |
| 4663 | const struct rpc_call_ops nfs4_release_lockowner_ops = { |
| 4664 | .rpc_release = nfs4_release_lockowner_release, |
| 4665 | }; |
| 4666 | |
| 4667 | void nfs4_release_lockowner(const struct nfs4_lock_state *lsp) |
| 4668 | { |
| 4669 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
| 4670 | struct nfs_release_lockowner_args *args; |
| 4671 | struct rpc_message msg = { |
| 4672 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 4673 | }; |
| 4674 | |
| 4675 | if (server->nfs_client->cl_mvops->minor_version != 0) |
| 4676 | return; |
| 4677 | args = kmalloc(sizeof(*args), GFP_NOFS); |
| 4678 | if (!args) |
| 4679 | return; |
| 4680 | args->lock_owner.clientid = server->nfs_client->cl_clientid; |
| 4681 | args->lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4682 | args->lock_owner.s_dev = server->s_dev; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4683 | msg.rpc_argp = args; |
| 4684 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args); |
| 4685 | } |
| 4686 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4687 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4688 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4689 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 4690 | const void *buf, size_t buflen, |
| 4691 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4692 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4693 | if (strcmp(key, "") != 0) |
| 4694 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4695 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4696 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4697 | } |
| 4698 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4699 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 4700 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4701 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4702 | if (strcmp(key, "") != 0) |
| 4703 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4704 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4705 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4706 | } |
| 4707 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4708 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 4709 | size_t list_len, const char *name, |
| 4710 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4711 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4712 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4713 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4714 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4715 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4716 | |
| 4717 | if (list && len <= list_len) |
| 4718 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4719 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4720 | } |
| 4721 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4722 | /* |
| 4723 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 4724 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4725 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4726 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4727 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 4728 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 4729 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
| 4730 | (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4731 | return; |
| 4732 | |
| 4733 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 4734 | NFS_ATTR_FATTR_NLINK; |
| 4735 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4736 | fattr->nlink = 2; |
| 4737 | } |
| 4738 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 4739 | int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 4740 | struct nfs4_fs_locations *fs_locations, struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4741 | { |
| 4742 | struct nfs_server *server = NFS_SERVER(dir); |
| 4743 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4744 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4745 | }; |
| 4746 | struct nfs4_fs_locations_arg args = { |
| 4747 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4748 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4749 | .page = page, |
| 4750 | .bitmask = bitmask, |
| 4751 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4752 | struct nfs4_fs_locations_res res = { |
| 4753 | .fs_locations = fs_locations, |
| 4754 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4755 | struct rpc_message msg = { |
| 4756 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4757 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4758 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4759 | }; |
| 4760 | int status; |
| 4761 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4762 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4763 | |
| 4764 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 4765 | * is not supported */ |
| 4766 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 4767 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 4768 | else |
| 4769 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 4770 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4771 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4772 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 4773 | fs_locations->nlocations = 0; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4774 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4775 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4776 | return status; |
| 4777 | } |
| 4778 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 4779 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4780 | { |
| 4781 | int status; |
| 4782 | struct nfs4_secinfo_arg args = { |
| 4783 | .dir_fh = NFS_FH(dir), |
| 4784 | .name = name, |
| 4785 | }; |
| 4786 | struct nfs4_secinfo_res res = { |
| 4787 | .flavors = flavors, |
| 4788 | }; |
| 4789 | struct rpc_message msg = { |
| 4790 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 4791 | .rpc_argp = &args, |
| 4792 | .rpc_resp = &res, |
| 4793 | }; |
| 4794 | |
| 4795 | dprintk("NFS call secinfo %s\n", name->name); |
| 4796 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 4797 | dprintk("NFS reply secinfo: %d\n", status); |
| 4798 | return status; |
| 4799 | } |
| 4800 | |
| 4801 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4802 | { |
| 4803 | struct nfs4_exception exception = { }; |
| 4804 | int err; |
| 4805 | do { |
| 4806 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 4807 | _nfs4_proc_secinfo(dir, name, flavors), |
| 4808 | &exception); |
| 4809 | } while (exception.retry); |
| 4810 | return err; |
| 4811 | } |
| 4812 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4813 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4814 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4815 | * Check the exchange flags returned by the server for invalid flags, having |
| 4816 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 4817 | * DS flags set. |
| 4818 | */ |
| 4819 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 4820 | { |
| 4821 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 4822 | goto out_inval; |
| 4823 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 4824 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 4825 | goto out_inval; |
| 4826 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 4827 | goto out_inval; |
| 4828 | return NFS_OK; |
| 4829 | out_inval: |
| 4830 | return -NFS4ERR_INVAL; |
| 4831 | } |
| 4832 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4833 | static bool |
| 4834 | nfs41_same_server_scope(struct server_scope *a, struct server_scope *b) |
| 4835 | { |
| 4836 | if (a->server_scope_sz == b->server_scope_sz && |
| 4837 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 4838 | return true; |
| 4839 | |
| 4840 | return false; |
| 4841 | } |
| 4842 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4843 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4844 | * nfs4_proc_exchange_id() |
| 4845 | * |
| 4846 | * Since the clientid has expired, all compounds using sessions |
| 4847 | * associated with the stale clientid will be returning |
| 4848 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 4849 | * be in some phase of session reset. |
| 4850 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 4851 | 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] | 4852 | { |
| 4853 | nfs4_verifier verifier; |
| 4854 | struct nfs41_exchange_id_args args = { |
| 4855 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4856 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4857 | }; |
| 4858 | struct nfs41_exchange_id_res res = { |
| 4859 | .client = clp, |
| 4860 | }; |
| 4861 | int status; |
| 4862 | struct rpc_message msg = { |
| 4863 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 4864 | .rpc_argp = &args, |
| 4865 | .rpc_resp = &res, |
| 4866 | .rpc_cred = cred, |
| 4867 | }; |
| 4868 | __be32 *p; |
| 4869 | |
| 4870 | dprintk("--> %s\n", __func__); |
| 4871 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 4872 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4873 | p = (u32 *)verifier.data; |
| 4874 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 4875 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 4876 | args.verifier = &verifier; |
| 4877 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4878 | args.id_len = scnprintf(args.id, sizeof(args.id), |
| 4879 | "%s/%s.%s/%u", |
| 4880 | clp->cl_ipaddr, |
| 4881 | init_utsname()->nodename, |
| 4882 | init_utsname()->domainname, |
| 4883 | clp->cl_rpcclient->cl_auth->au_flavor); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4884 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4885 | res.server_scope = kzalloc(sizeof(struct server_scope), GFP_KERNEL); |
| 4886 | if (unlikely(!res.server_scope)) |
| 4887 | return -ENOMEM; |
| 4888 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4889 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4890 | if (!status) |
| 4891 | status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4892 | |
| 4893 | if (!status) { |
| 4894 | if (clp->server_scope && |
| 4895 | !nfs41_same_server_scope(clp->server_scope, |
| 4896 | res.server_scope)) { |
| 4897 | dprintk("%s: server_scope mismatch detected\n", |
| 4898 | __func__); |
| 4899 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 4900 | kfree(clp->server_scope); |
| 4901 | clp->server_scope = NULL; |
| 4902 | } |
| 4903 | |
| 4904 | if (!clp->server_scope) |
| 4905 | clp->server_scope = res.server_scope; |
| 4906 | else |
| 4907 | kfree(res.server_scope); |
| 4908 | } |
| 4909 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4910 | dprintk("<-- %s status= %d\n", __func__, status); |
| 4911 | return status; |
| 4912 | } |
| 4913 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4914 | struct nfs4_get_lease_time_data { |
| 4915 | struct nfs4_get_lease_time_args *args; |
| 4916 | struct nfs4_get_lease_time_res *res; |
| 4917 | struct nfs_client *clp; |
| 4918 | }; |
| 4919 | |
| 4920 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 4921 | void *calldata) |
| 4922 | { |
| 4923 | int ret; |
| 4924 | struct nfs4_get_lease_time_data *data = |
| 4925 | (struct nfs4_get_lease_time_data *)calldata; |
| 4926 | |
| 4927 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4928 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4929 | /* just setup sequence, do not trigger session recovery |
| 4930 | since we're invoked within one */ |
| 4931 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4932 | &data->args->la_seq_args, |
| 4933 | &data->res->lr_seq_res, 0, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4934 | |
| 4935 | BUG_ON(ret == -EAGAIN); |
| 4936 | rpc_call_start(task); |
| 4937 | dprintk("<-- %s\n", __func__); |
| 4938 | } |
| 4939 | |
| 4940 | /* |
| 4941 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 4942 | * from sequence operation or clientid errors. |
| 4943 | */ |
| 4944 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 4945 | { |
| 4946 | struct nfs4_get_lease_time_data *data = |
| 4947 | (struct nfs4_get_lease_time_data *)calldata; |
| 4948 | |
| 4949 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4950 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 4951 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4952 | switch (task->tk_status) { |
| 4953 | case -NFS4ERR_DELAY: |
| 4954 | case -NFS4ERR_GRACE: |
| 4955 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 4956 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 4957 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4958 | /* fall through */ |
| 4959 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4960 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4961 | return; |
| 4962 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4963 | dprintk("<-- %s\n", __func__); |
| 4964 | } |
| 4965 | |
| 4966 | struct rpc_call_ops nfs4_get_lease_time_ops = { |
| 4967 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 4968 | .rpc_call_done = nfs4_get_lease_time_done, |
| 4969 | }; |
| 4970 | |
| 4971 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 4972 | { |
| 4973 | struct rpc_task *task; |
| 4974 | struct nfs4_get_lease_time_args args; |
| 4975 | struct nfs4_get_lease_time_res res = { |
| 4976 | .lr_fsinfo = fsinfo, |
| 4977 | }; |
| 4978 | struct nfs4_get_lease_time_data data = { |
| 4979 | .args = &args, |
| 4980 | .res = &res, |
| 4981 | .clp = clp, |
| 4982 | }; |
| 4983 | struct rpc_message msg = { |
| 4984 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 4985 | .rpc_argp = &args, |
| 4986 | .rpc_resp = &res, |
| 4987 | }; |
| 4988 | struct rpc_task_setup task_setup = { |
| 4989 | .rpc_client = clp->cl_rpcclient, |
| 4990 | .rpc_message = &msg, |
| 4991 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4992 | .callback_data = &data, |
| 4993 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4994 | }; |
| 4995 | int status; |
| 4996 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4997 | dprintk("--> %s\n", __func__); |
| 4998 | task = rpc_run_task(&task_setup); |
| 4999 | |
| 5000 | if (IS_ERR(task)) |
| 5001 | status = PTR_ERR(task); |
| 5002 | else { |
| 5003 | status = task->tk_status; |
| 5004 | rpc_put_task(task); |
| 5005 | } |
| 5006 | dprintk("<-- %s return %d\n", __func__, status); |
| 5007 | |
| 5008 | return status; |
| 5009 | } |
| 5010 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5011 | /* |
| 5012 | * Reset a slot table |
| 5013 | */ |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5014 | static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 5015 | int ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5016 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5017 | struct nfs4_slot *new = NULL; |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5018 | int i; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5019 | int ret = 0; |
| 5020 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5021 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 5022 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5023 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5024 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 5025 | if (max_reqs != tbl->max_slots) { |
| 5026 | ret = -ENOMEM; |
| 5027 | new = kmalloc(max_reqs * sizeof(struct nfs4_slot), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5028 | GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5029 | if (!new) |
| 5030 | goto out; |
| 5031 | ret = 0; |
| 5032 | kfree(tbl->slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5033 | } |
| 5034 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5035 | if (new) { |
| 5036 | tbl->slots = new; |
| 5037 | tbl->max_slots = max_reqs; |
| 5038 | } |
| 5039 | for (i = 0; i < tbl->max_slots; ++i) |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5040 | tbl->slots[i].seq_nr = ivalue; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5041 | spin_unlock(&tbl->slot_tbl_lock); |
| 5042 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5043 | tbl, tbl->slots, tbl->max_slots); |
| 5044 | out: |
| 5045 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5046 | return ret; |
| 5047 | } |
| 5048 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5049 | /* Destroy the slot table */ |
| 5050 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 5051 | { |
| 5052 | if (session->fc_slot_table.slots != NULL) { |
| 5053 | kfree(session->fc_slot_table.slots); |
| 5054 | session->fc_slot_table.slots = NULL; |
| 5055 | } |
| 5056 | if (session->bc_slot_table.slots != NULL) { |
| 5057 | kfree(session->bc_slot_table.slots); |
| 5058 | session->bc_slot_table.slots = NULL; |
| 5059 | } |
| 5060 | return; |
| 5061 | } |
| 5062 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5063 | /* |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5064 | * Initialize slot table |
| 5065 | */ |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5066 | static int nfs4_init_slot_table(struct nfs4_slot_table *tbl, |
| 5067 | int max_slots, int ivalue) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5068 | { |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5069 | struct nfs4_slot *slot; |
| 5070 | int ret = -ENOMEM; |
| 5071 | |
| 5072 | BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE); |
| 5073 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5074 | dprintk("--> %s: max_reqs=%u\n", __func__, max_slots); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5075 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5076 | slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5077 | if (!slot) |
| 5078 | goto out; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5079 | ret = 0; |
| 5080 | |
| 5081 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5082 | tbl->max_slots = max_slots; |
| 5083 | tbl->slots = slot; |
| 5084 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 5085 | spin_unlock(&tbl->slot_tbl_lock); |
| 5086 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5087 | tbl, tbl->slots, tbl->max_slots); |
| 5088 | out: |
| 5089 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5090 | return ret; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5091 | } |
| 5092 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5093 | /* |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5094 | * Initialize or reset the forechannel and backchannel tables |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5095 | */ |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5096 | static int nfs4_setup_session_slot_tables(struct nfs4_session *ses) |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5097 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5098 | struct nfs4_slot_table *tbl; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5099 | int status; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5100 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5101 | dprintk("--> %s\n", __func__); |
| 5102 | /* Fore channel */ |
| 5103 | tbl = &ses->fc_slot_table; |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5104 | if (tbl->slots == NULL) { |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5105 | status = nfs4_init_slot_table(tbl, ses->fc_attrs.max_reqs, 1); |
| 5106 | if (status) /* -ENOMEM */ |
| 5107 | return status; |
| 5108 | } else { |
| 5109 | status = nfs4_reset_slot_table(tbl, ses->fc_attrs.max_reqs, 1); |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5110 | if (status) |
| 5111 | return status; |
| 5112 | } |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5113 | /* Back channel */ |
| 5114 | tbl = &ses->bc_slot_table; |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5115 | if (tbl->slots == NULL) { |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5116 | status = nfs4_init_slot_table(tbl, ses->bc_attrs.max_reqs, 0); |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5117 | if (status) |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5118 | /* Fore and back channel share a connection so get |
| 5119 | * both slot tables or neither */ |
| 5120 | nfs4_destroy_slot_tables(ses); |
| 5121 | } else |
| 5122 | status = nfs4_reset_slot_table(tbl, ses->bc_attrs.max_reqs, 0); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5123 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5124 | } |
| 5125 | |
| 5126 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 5127 | { |
| 5128 | struct nfs4_session *session; |
| 5129 | struct nfs4_slot_table *tbl; |
| 5130 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5131 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5132 | if (!session) |
| 5133 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 5134 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5135 | tbl = &session->fc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 5136 | tbl->highest_used_slotid = -1; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5137 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5138 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5139 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5140 | |
| 5141 | tbl = &session->bc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 5142 | tbl->highest_used_slotid = -1; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5143 | spin_lock_init(&tbl->slot_tbl_lock); |
| 5144 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5145 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5146 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5147 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 5148 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5149 | session->clp = clp; |
| 5150 | return session; |
| 5151 | } |
| 5152 | |
| 5153 | void nfs4_destroy_session(struct nfs4_session *session) |
| 5154 | { |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5155 | nfs4_proc_destroy_session(session); |
| 5156 | dprintk("%s Destroy backchannel for xprt %p\n", |
| 5157 | __func__, session->clp->cl_rpcclient->cl_xprt); |
| 5158 | xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt, |
| 5159 | NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5160 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5161 | kfree(session); |
| 5162 | } |
| 5163 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5164 | /* |
| 5165 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5166 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5167 | * use them. |
| 5168 | * |
| 5169 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5170 | * always set csa_cachethis to FALSE because the current implementation |
| 5171 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5172 | */ |
| 5173 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5174 | { |
| 5175 | struct nfs4_session *session = args->client->cl_session; |
| 5176 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 5177 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 5178 | |
| 5179 | if (mxrqst_sz == 0) |
| 5180 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5181 | if (mxresp_sz == 0) |
| 5182 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5183 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5184 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5185 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5186 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
| 5187 | args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs; |
| 5188 | |
| 5189 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5190 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5191 | __func__, |
| 5192 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5193 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5194 | |
| 5195 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5196 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5197 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5198 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5199 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5200 | args->bc_attrs.max_reqs = 1; |
| 5201 | |
| 5202 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5203 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5204 | __func__, |
| 5205 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5206 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5207 | args->bc_attrs.max_reqs); |
| 5208 | } |
| 5209 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5210 | 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] | 5211 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5212 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5213 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5214 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5215 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5216 | return -EINVAL; |
| 5217 | /* |
| 5218 | * Our requested max_ops is the minimum we need; we're not |
| 5219 | * prepared to break up compounds into smaller pieces than that. |
| 5220 | * So, no point even trying to continue if the server won't |
| 5221 | * cooperate: |
| 5222 | */ |
| 5223 | if (rcvd->max_ops < sent->max_ops) |
| 5224 | return -EINVAL; |
| 5225 | if (rcvd->max_reqs == 0) |
| 5226 | return -EINVAL; |
| 5227 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5228 | } |
| 5229 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5230 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5231 | { |
| 5232 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5233 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5234 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5235 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5236 | return -EINVAL; |
| 5237 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5238 | return -EINVAL; |
| 5239 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5240 | return -EINVAL; |
| 5241 | /* These would render the backchannel useless: */ |
| 5242 | if (rcvd->max_ops == 0) |
| 5243 | return -EINVAL; |
| 5244 | if (rcvd->max_reqs == 0) |
| 5245 | return -EINVAL; |
| 5246 | return 0; |
| 5247 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5248 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5249 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5250 | struct nfs4_session *session) |
| 5251 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5252 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5253 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5254 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5255 | if (ret) |
| 5256 | return ret; |
| 5257 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5258 | } |
| 5259 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5260 | static int _nfs4_proc_create_session(struct nfs_client *clp) |
| 5261 | { |
| 5262 | struct nfs4_session *session = clp->cl_session; |
| 5263 | struct nfs41_create_session_args args = { |
| 5264 | .client = clp, |
| 5265 | .cb_program = NFS4_CALLBACK, |
| 5266 | }; |
| 5267 | struct nfs41_create_session_res res = { |
| 5268 | .client = clp, |
| 5269 | }; |
| 5270 | struct rpc_message msg = { |
| 5271 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5272 | .rpc_argp = &args, |
| 5273 | .rpc_resp = &res, |
| 5274 | }; |
| 5275 | int status; |
| 5276 | |
| 5277 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5278 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5279 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5280 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5281 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5282 | if (!status) |
| 5283 | /* Verify the session's negotiated channel_attrs values */ |
| 5284 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5285 | if (!status) { |
| 5286 | /* Increment the clientid slot sequence id */ |
| 5287 | clp->cl_seqid++; |
| 5288 | } |
| 5289 | |
| 5290 | return status; |
| 5291 | } |
| 5292 | |
| 5293 | /* |
| 5294 | * Issues a CREATE_SESSION operation to the server. |
| 5295 | * It is the responsibility of the caller to verify the session is |
| 5296 | * expired before calling this routine. |
| 5297 | */ |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5298 | int nfs4_proc_create_session(struct nfs_client *clp) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5299 | { |
| 5300 | int status; |
| 5301 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5302 | struct nfs4_session *session = clp->cl_session; |
| 5303 | |
| 5304 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5305 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5306 | status = _nfs4_proc_create_session(clp); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5307 | if (status) |
| 5308 | goto out; |
| 5309 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5310 | /* Init or reset the session slot tables */ |
| 5311 | status = nfs4_setup_session_slot_tables(session); |
| 5312 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5313 | if (status) |
| 5314 | goto out; |
| 5315 | |
| 5316 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5317 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5318 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5319 | out: |
| 5320 | dprintk("<-- %s\n", __func__); |
| 5321 | return status; |
| 5322 | } |
| 5323 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5324 | /* |
| 5325 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5326 | * The caller must serialize access to this routine. |
| 5327 | */ |
| 5328 | int nfs4_proc_destroy_session(struct nfs4_session *session) |
| 5329 | { |
| 5330 | int status = 0; |
| 5331 | struct rpc_message msg; |
| 5332 | |
| 5333 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5334 | |
| 5335 | /* session is still being setup */ |
| 5336 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5337 | return status; |
| 5338 | |
| 5339 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; |
| 5340 | msg.rpc_argp = session; |
| 5341 | msg.rpc_resp = NULL; |
| 5342 | msg.rpc_cred = NULL; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5343 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5344 | |
| 5345 | if (status) |
| 5346 | printk(KERN_WARNING |
| 5347 | "Got error %d from the server on DESTROY_SESSION. " |
| 5348 | "Session has been destroyed regardless...\n", status); |
| 5349 | |
| 5350 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5351 | return status; |
| 5352 | } |
| 5353 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5354 | int nfs4_init_session(struct nfs_server *server) |
| 5355 | { |
| 5356 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5357 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5358 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5359 | int ret; |
| 5360 | |
| 5361 | if (!nfs4_has_session(clp)) |
| 5362 | return 0; |
| 5363 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5364 | session = clp->cl_session; |
| 5365 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5366 | return 0; |
| 5367 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5368 | rsize = server->rsize; |
| 5369 | if (rsize == 0) |
| 5370 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5371 | wsize = server->wsize; |
| 5372 | if (wsize == 0) |
| 5373 | wsize = NFS_MAX_FILE_IO_SIZE; |
| 5374 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5375 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5376 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5377 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5378 | ret = nfs4_recover_expired_lease(server); |
| 5379 | if (!ret) |
| 5380 | ret = nfs4_check_client_ready(clp); |
| 5381 | return ret; |
| 5382 | } |
| 5383 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5384 | int nfs4_init_ds_session(struct nfs_client *clp) |
| 5385 | { |
| 5386 | struct nfs4_session *session = clp->cl_session; |
| 5387 | int ret; |
| 5388 | |
| 5389 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5390 | return 0; |
| 5391 | |
| 5392 | ret = nfs4_client_recover_expired_lease(clp); |
| 5393 | if (!ret) |
| 5394 | /* Test for the DS role */ |
| 5395 | if (!is_ds_client(clp)) |
| 5396 | ret = -ENODEV; |
| 5397 | if (!ret) |
| 5398 | ret = nfs4_check_client_ready(clp); |
| 5399 | return ret; |
| 5400 | |
| 5401 | } |
| 5402 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 5403 | |
| 5404 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5405 | /* |
| 5406 | * Renew the cl_session lease. |
| 5407 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5408 | struct nfs4_sequence_data { |
| 5409 | struct nfs_client *clp; |
| 5410 | struct nfs4_sequence_args args; |
| 5411 | struct nfs4_sequence_res res; |
| 5412 | }; |
| 5413 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5414 | static void nfs41_sequence_release(void *data) |
| 5415 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5416 | struct nfs4_sequence_data *calldata = data; |
| 5417 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5418 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5419 | if (atomic_read(&clp->cl_count) > 1) |
| 5420 | nfs4_schedule_state_renewal(clp); |
| 5421 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5422 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5423 | } |
| 5424 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5425 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5426 | { |
| 5427 | switch(task->tk_status) { |
| 5428 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5429 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5430 | return -EAGAIN; |
| 5431 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5432 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5433 | } |
| 5434 | return 0; |
| 5435 | } |
| 5436 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5437 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5438 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5439 | struct nfs4_sequence_data *calldata = data; |
| 5440 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5441 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5442 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5443 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5444 | |
| 5445 | if (task->tk_status < 0) { |
| 5446 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5447 | if (atomic_read(&clp->cl_count) == 1) |
| 5448 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5449 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5450 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5451 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5452 | return; |
| 5453 | } |
| 5454 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5455 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5456 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5457 | dprintk("<-- %s\n", __func__); |
| 5458 | } |
| 5459 | |
| 5460 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5461 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5462 | struct nfs4_sequence_data *calldata = data; |
| 5463 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5464 | struct nfs4_sequence_args *args; |
| 5465 | struct nfs4_sequence_res *res; |
| 5466 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5467 | args = task->tk_msg.rpc_argp; |
| 5468 | res = task->tk_msg.rpc_resp; |
| 5469 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5470 | if (nfs41_setup_sequence(clp->cl_session, args, res, 0, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5471 | return; |
| 5472 | rpc_call_start(task); |
| 5473 | } |
| 5474 | |
| 5475 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5476 | .rpc_call_done = nfs41_sequence_call_done, |
| 5477 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5478 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5479 | }; |
| 5480 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5481 | 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] | 5482 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5483 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5484 | struct rpc_message msg = { |
| 5485 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5486 | .rpc_cred = cred, |
| 5487 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5488 | struct rpc_task_setup task_setup_data = { |
| 5489 | .rpc_client = clp->cl_rpcclient, |
| 5490 | .rpc_message = &msg, |
| 5491 | .callback_ops = &nfs41_sequence_ops, |
| 5492 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5493 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5494 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5495 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5496 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5497 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5498 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5499 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5500 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5501 | } |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5502 | msg.rpc_argp = &calldata->args; |
| 5503 | msg.rpc_resp = &calldata->res; |
| 5504 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5505 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5506 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5507 | return rpc_run_task(&task_setup_data); |
| 5508 | } |
| 5509 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5510 | static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5511 | { |
| 5512 | struct rpc_task *task; |
| 5513 | int ret = 0; |
| 5514 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5515 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 5516 | return 0; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5517 | task = _nfs41_proc_sequence(clp, cred); |
| 5518 | if (IS_ERR(task)) |
| 5519 | ret = PTR_ERR(task); |
| 5520 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5521 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5522 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5523 | return ret; |
| 5524 | } |
| 5525 | |
| 5526 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5527 | { |
| 5528 | struct rpc_task *task; |
| 5529 | int ret; |
| 5530 | |
| 5531 | task = _nfs41_proc_sequence(clp, cred); |
| 5532 | if (IS_ERR(task)) { |
| 5533 | ret = PTR_ERR(task); |
| 5534 | goto out; |
| 5535 | } |
| 5536 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5537 | if (!ret) { |
| 5538 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5539 | |
| 5540 | if (task->tk_status == 0) |
| 5541 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5542 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5543 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5544 | rpc_put_task(task); |
| 5545 | out: |
| 5546 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5547 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5548 | } |
| 5549 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5550 | struct nfs4_reclaim_complete_data { |
| 5551 | struct nfs_client *clp; |
| 5552 | struct nfs41_reclaim_complete_args arg; |
| 5553 | struct nfs41_reclaim_complete_res res; |
| 5554 | }; |
| 5555 | |
| 5556 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5557 | { |
| 5558 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5559 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5560 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5561 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5562 | &calldata->arg.seq_args, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5563 | &calldata->res.seq_res, 0, task)) |
| 5564 | return; |
| 5565 | |
| 5566 | rpc_call_start(task); |
| 5567 | } |
| 5568 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5569 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5570 | { |
| 5571 | switch(task->tk_status) { |
| 5572 | case 0: |
| 5573 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5574 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5575 | break; |
| 5576 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5577 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5578 | /* fall through */ |
| 5579 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5580 | return -EAGAIN; |
| 5581 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5582 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5583 | } |
| 5584 | return 0; |
| 5585 | } |
| 5586 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5587 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5588 | { |
| 5589 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5590 | struct nfs_client *clp = calldata->clp; |
| 5591 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5592 | |
| 5593 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5594 | if (!nfs41_sequence_done(task, res)) |
| 5595 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5596 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5597 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5598 | rpc_restart_call_prepare(task); |
| 5599 | return; |
| 5600 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5601 | dprintk("<-- %s\n", __func__); |
| 5602 | } |
| 5603 | |
| 5604 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5605 | { |
| 5606 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5607 | |
| 5608 | kfree(calldata); |
| 5609 | } |
| 5610 | |
| 5611 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5612 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5613 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5614 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5615 | }; |
| 5616 | |
| 5617 | /* |
| 5618 | * Issue a global reclaim complete. |
| 5619 | */ |
| 5620 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5621 | { |
| 5622 | struct nfs4_reclaim_complete_data *calldata; |
| 5623 | struct rpc_task *task; |
| 5624 | struct rpc_message msg = { |
| 5625 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5626 | }; |
| 5627 | struct rpc_task_setup task_setup_data = { |
| 5628 | .rpc_client = clp->cl_rpcclient, |
| 5629 | .rpc_message = &msg, |
| 5630 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5631 | .flags = RPC_TASK_ASYNC, |
| 5632 | }; |
| 5633 | int status = -ENOMEM; |
| 5634 | |
| 5635 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5636 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5637 | if (calldata == NULL) |
| 5638 | goto out; |
| 5639 | calldata->clp = clp; |
| 5640 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5641 | |
| 5642 | msg.rpc_argp = &calldata->arg; |
| 5643 | msg.rpc_resp = &calldata->res; |
| 5644 | task_setup_data.callback_data = calldata; |
| 5645 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5646 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5647 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5648 | goto out; |
| 5649 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 5650 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5651 | if (status == 0) |
| 5652 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5653 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5654 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5655 | out: |
| 5656 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5657 | return status; |
| 5658 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5659 | |
| 5660 | static void |
| 5661 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 5662 | { |
| 5663 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5664 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5665 | |
| 5666 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5667 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 5668 | * right now covering the LAYOUTGET we are about to send. |
| 5669 | * However, that is not so catastrophic, and there seems |
| 5670 | * to be no way to prevent it completely. |
| 5671 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5672 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
| 5673 | &lgp->res.seq_res, 0, task)) |
| 5674 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5675 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 5676 | NFS_I(lgp->args.inode)->layout, |
| 5677 | lgp->args.ctx->state)) { |
| 5678 | rpc_exit(task, NFS4_OK); |
| 5679 | return; |
| 5680 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5681 | rpc_call_start(task); |
| 5682 | } |
| 5683 | |
| 5684 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 5685 | { |
| 5686 | struct nfs4_layoutget *lgp = calldata; |
| 5687 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5688 | |
| 5689 | dprintk("--> %s\n", __func__); |
| 5690 | |
| 5691 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 5692 | return; |
| 5693 | |
| 5694 | switch (task->tk_status) { |
| 5695 | case 0: |
| 5696 | break; |
| 5697 | case -NFS4ERR_LAYOUTTRYLATER: |
| 5698 | case -NFS4ERR_RECALLCONFLICT: |
| 5699 | task->tk_status = -NFS4ERR_DELAY; |
| 5700 | /* Fall through */ |
| 5701 | default: |
| 5702 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5703 | rpc_restart_call_prepare(task); |
| 5704 | return; |
| 5705 | } |
| 5706 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5707 | dprintk("<-- %s\n", __func__); |
| 5708 | } |
| 5709 | |
| 5710 | static void nfs4_layoutget_release(void *calldata) |
| 5711 | { |
| 5712 | struct nfs4_layoutget *lgp = calldata; |
| 5713 | |
| 5714 | dprintk("--> %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5715 | put_nfs_open_context(lgp->args.ctx); |
| 5716 | kfree(calldata); |
| 5717 | dprintk("<-- %s\n", __func__); |
| 5718 | } |
| 5719 | |
| 5720 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 5721 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 5722 | .rpc_call_done = nfs4_layoutget_done, |
| 5723 | .rpc_release = nfs4_layoutget_release, |
| 5724 | }; |
| 5725 | |
| 5726 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) |
| 5727 | { |
| 5728 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5729 | struct rpc_task *task; |
| 5730 | struct rpc_message msg = { |
| 5731 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 5732 | .rpc_argp = &lgp->args, |
| 5733 | .rpc_resp = &lgp->res, |
| 5734 | }; |
| 5735 | struct rpc_task_setup task_setup_data = { |
| 5736 | .rpc_client = server->client, |
| 5737 | .rpc_message = &msg, |
| 5738 | .callback_ops = &nfs4_layoutget_call_ops, |
| 5739 | .callback_data = lgp, |
| 5740 | .flags = RPC_TASK_ASYNC, |
| 5741 | }; |
| 5742 | int status = 0; |
| 5743 | |
| 5744 | dprintk("--> %s\n", __func__); |
| 5745 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 5746 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5747 | lgp->res.seq_res.sr_slot = NULL; |
| 5748 | task = rpc_run_task(&task_setup_data); |
| 5749 | if (IS_ERR(task)) |
| 5750 | return PTR_ERR(task); |
| 5751 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5752 | if (status == 0) |
| 5753 | status = task->tk_status; |
| 5754 | if (status == 0) |
| 5755 | status = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5756 | rpc_put_task(task); |
| 5757 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5758 | return status; |
| 5759 | } |
| 5760 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5761 | static void |
| 5762 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 5763 | { |
| 5764 | struct nfs4_layoutreturn *lrp = calldata; |
| 5765 | |
| 5766 | dprintk("--> %s\n", __func__); |
| 5767 | if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, |
| 5768 | &lrp->res.seq_res, 0, task)) |
| 5769 | return; |
| 5770 | rpc_call_start(task); |
| 5771 | } |
| 5772 | |
| 5773 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 5774 | { |
| 5775 | struct nfs4_layoutreturn *lrp = calldata; |
| 5776 | struct nfs_server *server; |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 5777 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5778 | |
| 5779 | dprintk("--> %s\n", __func__); |
| 5780 | |
| 5781 | if (!nfs4_sequence_done(task, &lrp->res.seq_res)) |
| 5782 | return; |
| 5783 | |
| 5784 | server = NFS_SERVER(lrp->args.inode); |
| 5785 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5786 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5787 | return; |
| 5788 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 5789 | spin_lock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5790 | if (task->tk_status == 0) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5791 | if (lrp->res.lrs_present) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5792 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5793 | } else |
| 5794 | BUG_ON(!list_empty(&lo->plh_segs)); |
| 5795 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 5796 | lo->plh_block_lgets--; |
| 5797 | spin_unlock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5798 | dprintk("<-- %s\n", __func__); |
| 5799 | } |
| 5800 | |
| 5801 | static void nfs4_layoutreturn_release(void *calldata) |
| 5802 | { |
| 5803 | struct nfs4_layoutreturn *lrp = calldata; |
| 5804 | |
| 5805 | dprintk("--> %s\n", __func__); |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 5806 | put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5807 | kfree(calldata); |
| 5808 | dprintk("<-- %s\n", __func__); |
| 5809 | } |
| 5810 | |
| 5811 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 5812 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 5813 | .rpc_call_done = nfs4_layoutreturn_done, |
| 5814 | .rpc_release = nfs4_layoutreturn_release, |
| 5815 | }; |
| 5816 | |
| 5817 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 5818 | { |
| 5819 | struct rpc_task *task; |
| 5820 | struct rpc_message msg = { |
| 5821 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 5822 | .rpc_argp = &lrp->args, |
| 5823 | .rpc_resp = &lrp->res, |
| 5824 | }; |
| 5825 | struct rpc_task_setup task_setup_data = { |
| 5826 | .rpc_client = lrp->clp->cl_rpcclient, |
| 5827 | .rpc_message = &msg, |
| 5828 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 5829 | .callback_data = lrp, |
| 5830 | }; |
| 5831 | int status; |
| 5832 | |
| 5833 | dprintk("--> %s\n", __func__); |
| 5834 | task = rpc_run_task(&task_setup_data); |
| 5835 | if (IS_ERR(task)) |
| 5836 | return PTR_ERR(task); |
| 5837 | status = task->tk_status; |
| 5838 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5839 | rpc_put_task(task); |
| 5840 | return status; |
| 5841 | } |
| 5842 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 5843 | /* |
| 5844 | * Retrieve the list of Data Server devices from the MDS. |
| 5845 | */ |
| 5846 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 5847 | const struct nfs_fh *fh, |
| 5848 | struct pnfs_devicelist *devlist) |
| 5849 | { |
| 5850 | struct nfs4_getdevicelist_args args = { |
| 5851 | .fh = fh, |
| 5852 | .layoutclass = server->pnfs_curr_ld->id, |
| 5853 | }; |
| 5854 | struct nfs4_getdevicelist_res res = { |
| 5855 | .devlist = devlist, |
| 5856 | }; |
| 5857 | struct rpc_message msg = { |
| 5858 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 5859 | .rpc_argp = &args, |
| 5860 | .rpc_resp = &res, |
| 5861 | }; |
| 5862 | int status; |
| 5863 | |
| 5864 | dprintk("--> %s\n", __func__); |
| 5865 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 5866 | &res.seq_res, 0); |
| 5867 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5868 | return status; |
| 5869 | } |
| 5870 | |
| 5871 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 5872 | const struct nfs_fh *fh, |
| 5873 | struct pnfs_devicelist *devlist) |
| 5874 | { |
| 5875 | struct nfs4_exception exception = { }; |
| 5876 | int err; |
| 5877 | |
| 5878 | do { |
| 5879 | err = nfs4_handle_exception(server, |
| 5880 | _nfs4_getdevicelist(server, fh, devlist), |
| 5881 | &exception); |
| 5882 | } while (exception.retry); |
| 5883 | |
| 5884 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 5885 | err, devlist->num_devs); |
| 5886 | |
| 5887 | return err; |
| 5888 | } |
| 5889 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 5890 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5891 | static int |
| 5892 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5893 | { |
| 5894 | struct nfs4_getdeviceinfo_args args = { |
| 5895 | .pdev = pdev, |
| 5896 | }; |
| 5897 | struct nfs4_getdeviceinfo_res res = { |
| 5898 | .pdev = pdev, |
| 5899 | }; |
| 5900 | struct rpc_message msg = { |
| 5901 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 5902 | .rpc_argp = &args, |
| 5903 | .rpc_resp = &res, |
| 5904 | }; |
| 5905 | int status; |
| 5906 | |
| 5907 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5908 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5909 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5910 | |
| 5911 | return status; |
| 5912 | } |
| 5913 | |
| 5914 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5915 | { |
| 5916 | struct nfs4_exception exception = { }; |
| 5917 | int err; |
| 5918 | |
| 5919 | do { |
| 5920 | err = nfs4_handle_exception(server, |
| 5921 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 5922 | &exception); |
| 5923 | } while (exception.retry); |
| 5924 | return err; |
| 5925 | } |
| 5926 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 5927 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5928 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 5929 | { |
| 5930 | struct nfs4_layoutcommit_data *data = calldata; |
| 5931 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 5932 | |
| 5933 | if (nfs4_setup_sequence(server, &data->args.seq_args, |
| 5934 | &data->res.seq_res, 1, task)) |
| 5935 | return; |
| 5936 | rpc_call_start(task); |
| 5937 | } |
| 5938 | |
| 5939 | static void |
| 5940 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 5941 | { |
| 5942 | struct nfs4_layoutcommit_data *data = calldata; |
| 5943 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 5944 | |
| 5945 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5946 | return; |
| 5947 | |
| 5948 | switch (task->tk_status) { /* Just ignore these failures */ |
| 5949 | case NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 5950 | case NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 5951 | case NFS4ERR_BADLAYOUT: /* no layout */ |
| 5952 | case NFS4ERR_GRACE: /* loca_recalim always false */ |
| 5953 | task->tk_status = 0; |
| 5954 | } |
| 5955 | |
| 5956 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5957 | rpc_restart_call_prepare(task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5958 | return; |
| 5959 | } |
| 5960 | |
| 5961 | if (task->tk_status == 0) |
| 5962 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 5963 | data->res.fattr); |
| 5964 | } |
| 5965 | |
| 5966 | static void nfs4_layoutcommit_release(void *calldata) |
| 5967 | { |
| 5968 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 5969 | struct pnfs_layout_segment *lseg, *tmp; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 5970 | unsigned long *bitlock = &NFS_I(data->args.inode)->flags; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5971 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 5972 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5973 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 5974 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 5975 | list_del_init(&lseg->pls_lc_list); |
| 5976 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 5977 | &lseg->pls_flags)) |
| 5978 | put_lseg(lseg); |
| 5979 | } |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 5980 | |
| 5981 | clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); |
| 5982 | smp_mb__after_clear_bit(); |
| 5983 | wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING); |
| 5984 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5985 | put_rpccred(data->cred); |
| 5986 | kfree(data); |
| 5987 | } |
| 5988 | |
| 5989 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 5990 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 5991 | .rpc_call_done = nfs4_layoutcommit_done, |
| 5992 | .rpc_release = nfs4_layoutcommit_release, |
| 5993 | }; |
| 5994 | |
| 5995 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 5996 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5997 | { |
| 5998 | struct rpc_message msg = { |
| 5999 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6000 | .rpc_argp = &data->args, |
| 6001 | .rpc_resp = &data->res, |
| 6002 | .rpc_cred = data->cred, |
| 6003 | }; |
| 6004 | struct rpc_task_setup task_setup_data = { |
| 6005 | .task = &data->task, |
| 6006 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6007 | .rpc_message = &msg, |
| 6008 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6009 | .callback_data = data, |
| 6010 | .flags = RPC_TASK_ASYNC, |
| 6011 | }; |
| 6012 | struct rpc_task *task; |
| 6013 | int status = 0; |
| 6014 | |
| 6015 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6016 | "lbw: %llu inode %lu\n", |
| 6017 | data->task.tk_pid, sync, |
| 6018 | data->args.lastbytewritten, |
| 6019 | data->args.inode->i_ino); |
| 6020 | |
| 6021 | task = rpc_run_task(&task_setup_data); |
| 6022 | if (IS_ERR(task)) |
| 6023 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6024 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6025 | goto out; |
| 6026 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6027 | if (status != 0) |
| 6028 | goto out; |
| 6029 | status = task->tk_status; |
| 6030 | out: |
| 6031 | dprintk("%s: status %d\n", __func__, status); |
| 6032 | rpc_put_task(task); |
| 6033 | return status; |
| 6034 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6035 | |
| 6036 | static int |
| 6037 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6038 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6039 | { |
| 6040 | struct nfs41_secinfo_no_name_args args = { |
| 6041 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6042 | }; |
| 6043 | struct nfs4_secinfo_res res = { |
| 6044 | .flavors = flavors, |
| 6045 | }; |
| 6046 | struct rpc_message msg = { |
| 6047 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6048 | .rpc_argp = &args, |
| 6049 | .rpc_resp = &res, |
| 6050 | }; |
| 6051 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6052 | } |
| 6053 | |
| 6054 | static int |
| 6055 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6056 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6057 | { |
| 6058 | struct nfs4_exception exception = { }; |
| 6059 | int err; |
| 6060 | do { |
| 6061 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6062 | switch (err) { |
| 6063 | case 0: |
| 6064 | case -NFS4ERR_WRONGSEC: |
| 6065 | case -NFS4ERR_NOTSUPP: |
| 6066 | break; |
| 6067 | default: |
| 6068 | err = nfs4_handle_exception(server, err, &exception); |
| 6069 | } |
| 6070 | } while (exception.retry); |
| 6071 | return err; |
| 6072 | } |
| 6073 | |
| 6074 | static int |
| 6075 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6076 | struct nfs_fsinfo *info) |
| 6077 | { |
| 6078 | int err; |
| 6079 | struct page *page; |
| 6080 | rpc_authflavor_t flavor; |
| 6081 | struct nfs4_secinfo_flavors *flavors; |
| 6082 | |
| 6083 | page = alloc_page(GFP_KERNEL); |
| 6084 | if (!page) { |
| 6085 | err = -ENOMEM; |
| 6086 | goto out; |
| 6087 | } |
| 6088 | |
| 6089 | flavors = page_address(page); |
| 6090 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6091 | |
| 6092 | /* |
| 6093 | * Fall back on "guess and check" method if |
| 6094 | * the server doesn't support SECINFO_NO_NAME |
| 6095 | */ |
| 6096 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6097 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6098 | goto out_freepage; |
| 6099 | } |
| 6100 | if (err) |
| 6101 | goto out_freepage; |
| 6102 | |
| 6103 | flavor = nfs_find_best_sec(flavors); |
| 6104 | if (err == 0) |
| 6105 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6106 | |
| 6107 | out_freepage: |
| 6108 | put_page(page); |
| 6109 | if (err == -EACCES) |
| 6110 | return -EPERM; |
| 6111 | out: |
| 6112 | return err; |
| 6113 | } |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6114 | static int _nfs41_test_stateid(struct nfs_server *server, struct nfs4_state *state) |
| 6115 | { |
| 6116 | int status; |
| 6117 | struct nfs41_test_stateid_args args = { |
| 6118 | .stateid = &state->stateid, |
| 6119 | }; |
| 6120 | struct nfs41_test_stateid_res res; |
| 6121 | struct rpc_message msg = { |
| 6122 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6123 | .rpc_argp = &args, |
| 6124 | .rpc_resp = &res, |
| 6125 | }; |
| 6126 | args.seq_args.sa_session = res.seq_res.sr_session = NULL; |
| 6127 | status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 0, 1); |
| 6128 | return status; |
| 6129 | } |
| 6130 | |
| 6131 | static int nfs41_test_stateid(struct nfs_server *server, struct nfs4_state *state) |
| 6132 | { |
| 6133 | struct nfs4_exception exception = { }; |
| 6134 | int err; |
| 6135 | do { |
| 6136 | err = nfs4_handle_exception(server, |
| 6137 | _nfs41_test_stateid(server, state), |
| 6138 | &exception); |
| 6139 | } while (exception.retry); |
| 6140 | return err; |
| 6141 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6142 | |
| 6143 | static int _nfs4_free_stateid(struct nfs_server *server, struct nfs4_state *state) |
| 6144 | { |
| 6145 | int status; |
| 6146 | struct nfs41_free_stateid_args args = { |
| 6147 | .stateid = &state->stateid, |
| 6148 | }; |
| 6149 | struct nfs41_free_stateid_res res; |
| 6150 | struct rpc_message msg = { |
| 6151 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6152 | .rpc_argp = &args, |
| 6153 | .rpc_resp = &res, |
| 6154 | }; |
| 6155 | |
| 6156 | args.seq_args.sa_session = res.seq_res.sr_session = NULL; |
| 6157 | status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 0, 1); |
| 6158 | return status; |
| 6159 | } |
| 6160 | |
| 6161 | static int nfs41_free_stateid(struct nfs_server *server, struct nfs4_state *state) |
| 6162 | { |
| 6163 | struct nfs4_exception exception = { }; |
| 6164 | int err; |
| 6165 | do { |
| 6166 | err = nfs4_handle_exception(server, |
| 6167 | _nfs4_free_stateid(server, state), |
| 6168 | &exception); |
| 6169 | } while (exception.retry); |
| 6170 | return err; |
| 6171 | } |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6172 | #endif /* CONFIG_NFS_V4_1 */ |
| 6173 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6174 | struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6175 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6176 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6177 | .recover_open = nfs4_open_reclaim, |
| 6178 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6179 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6180 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6181 | }; |
| 6182 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6183 | #if defined(CONFIG_NFS_V4_1) |
| 6184 | struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
| 6185 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6186 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6187 | .recover_open = nfs4_open_reclaim, |
| 6188 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6189 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6190 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6191 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6192 | }; |
| 6193 | #endif /* CONFIG_NFS_V4_1 */ |
| 6194 | |
| 6195 | struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6196 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6197 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6198 | .recover_open = nfs4_open_expired, |
| 6199 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6200 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6201 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6202 | }; |
| 6203 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6204 | #if defined(CONFIG_NFS_V4_1) |
| 6205 | struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
| 6206 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6207 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6208 | .recover_open = nfs41_open_expired, |
| 6209 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6210 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6211 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6212 | }; |
| 6213 | #endif /* CONFIG_NFS_V4_1 */ |
| 6214 | |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6215 | struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
| 6216 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6217 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6218 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6219 | }; |
| 6220 | |
| 6221 | #if defined(CONFIG_NFS_V4_1) |
| 6222 | struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
| 6223 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6224 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6225 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6226 | }; |
| 6227 | #endif |
| 6228 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6229 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6230 | .minor_version = 0, |
| 6231 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6232 | .validate_stateid = nfs4_validate_delegation_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6233 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6234 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6235 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6236 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6237 | }; |
| 6238 | |
| 6239 | #if defined(CONFIG_NFS_V4_1) |
| 6240 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6241 | .minor_version = 1, |
| 6242 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6243 | .validate_stateid = nfs41_validate_delegation_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6244 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6245 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6246 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6247 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6248 | }; |
| 6249 | #endif |
| 6250 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6251 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6252 | [0] = &nfs_v4_0_minor_ops, |
| 6253 | #if defined(CONFIG_NFS_V4_1) |
| 6254 | [1] = &nfs_v4_1_minor_ops, |
| 6255 | #endif |
| 6256 | }; |
| 6257 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6258 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6259 | .permission = nfs_permission, |
| 6260 | .getattr = nfs_getattr, |
| 6261 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6262 | .getxattr = generic_getxattr, |
| 6263 | .setxattr = generic_setxattr, |
| 6264 | .listxattr = generic_listxattr, |
| 6265 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6266 | }; |
| 6267 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6268 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6269 | .version = 4, /* protocol version */ |
| 6270 | .dentry_ops = &nfs4_dentry_operations, |
| 6271 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6272 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 6273 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6274 | .getroot = nfs4_proc_get_root, |
| 6275 | .getattr = nfs4_proc_getattr, |
| 6276 | .setattr = nfs4_proc_setattr, |
| 6277 | .lookup = nfs4_proc_lookup, |
| 6278 | .access = nfs4_proc_access, |
| 6279 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6280 | .create = nfs4_proc_create, |
| 6281 | .remove = nfs4_proc_remove, |
| 6282 | .unlink_setup = nfs4_proc_unlink_setup, |
| 6283 | .unlink_done = nfs4_proc_unlink_done, |
| 6284 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6285 | .rename_setup = nfs4_proc_rename_setup, |
| 6286 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6287 | .link = nfs4_proc_link, |
| 6288 | .symlink = nfs4_proc_symlink, |
| 6289 | .mkdir = nfs4_proc_mkdir, |
| 6290 | .rmdir = nfs4_proc_remove, |
| 6291 | .readdir = nfs4_proc_readdir, |
| 6292 | .mknod = nfs4_proc_mknod, |
| 6293 | .statfs = nfs4_proc_statfs, |
| 6294 | .fsinfo = nfs4_proc_fsinfo, |
| 6295 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6296 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6297 | .decode_dirent = nfs4_decode_dirent, |
| 6298 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6299 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6300 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6301 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6302 | .commit_setup = nfs4_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6303 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6304 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6305 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6306 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6307 | .open_context = nfs4_atomic_open, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6308 | .init_client = nfs4_init_client, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6309 | .secinfo = nfs4_proc_secinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6310 | }; |
| 6311 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6312 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6313 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6314 | .list = nfs4_xattr_list_nfs4_acl, |
| 6315 | .get = nfs4_xattr_get_nfs4_acl, |
| 6316 | .set = nfs4_xattr_set_nfs4_acl, |
| 6317 | }; |
| 6318 | |
| 6319 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6320 | &nfs4_xattr_nfs4_acl_handler, |
| 6321 | NULL |
| 6322 | }; |
| 6323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6324 | /* |
| 6325 | * Local variables: |
| 6326 | * c-basic-offset: 8 |
| 6327 | * End: |
| 6328 | */ |