Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 46 | #include <linux/sunrpc/gss_api.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <linux/nfs.h> |
| 48 | #include <linux/nfs4.h> |
| 49 | #include <linux/nfs_fs.h> |
| 50 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 51 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 53 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 54 | #include <linux/module.h> |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 55 | #include <linux/nfs_idmap.h> |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 56 | #include <linux/sunrpc/bc_xprt.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 57 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 58 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 59 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 61 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 63 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 64 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 65 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 66 | #include "pnfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 69 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 70 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 72 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 73 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 74 | |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 75 | static unsigned short max_session_slots = NFS4_DEF_SLOT_TABLE_SIZE; |
| 76 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 77 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 78 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 79 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 81 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 82 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 83 | 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] | 84 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 85 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 86 | struct nfs4_state *state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 87 | #ifdef CONFIG_NFS_V4_1 |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 88 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *); |
| 89 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 90 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 92 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 94 | if (err >= -1000) |
| 95 | return err; |
| 96 | switch (err) { |
| 97 | case -NFS4ERR_RESOURCE: |
| 98 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 99 | case -NFS4ERR_WRONGSEC: |
| 100 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 101 | case -NFS4ERR_BADOWNER: |
| 102 | case -NFS4ERR_BADNAME: |
| 103 | return -EINVAL; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 104 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 106 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 107 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 109 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /* |
| 113 | * This is our standard bitmap for GETATTR requests. |
| 114 | */ |
| 115 | const u32 nfs4_fattr_bitmap[2] = { |
| 116 | FATTR4_WORD0_TYPE |
| 117 | | FATTR4_WORD0_CHANGE |
| 118 | | FATTR4_WORD0_SIZE |
| 119 | | FATTR4_WORD0_FSID |
| 120 | | FATTR4_WORD0_FILEID, |
| 121 | FATTR4_WORD1_MODE |
| 122 | | FATTR4_WORD1_NUMLINKS |
| 123 | | FATTR4_WORD1_OWNER |
| 124 | | FATTR4_WORD1_OWNER_GROUP |
| 125 | | FATTR4_WORD1_RAWDEV |
| 126 | | FATTR4_WORD1_SPACE_USED |
| 127 | | FATTR4_WORD1_TIME_ACCESS |
| 128 | | FATTR4_WORD1_TIME_METADATA |
| 129 | | FATTR4_WORD1_TIME_MODIFY |
| 130 | }; |
| 131 | |
| 132 | const u32 nfs4_statfs_bitmap[2] = { |
| 133 | FATTR4_WORD0_FILES_AVAIL |
| 134 | | FATTR4_WORD0_FILES_FREE |
| 135 | | FATTR4_WORD0_FILES_TOTAL, |
| 136 | FATTR4_WORD1_SPACE_AVAIL |
| 137 | | FATTR4_WORD1_SPACE_FREE |
| 138 | | FATTR4_WORD1_SPACE_TOTAL |
| 139 | }; |
| 140 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 141 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | FATTR4_WORD0_MAXLINK |
| 143 | | FATTR4_WORD0_MAXNAME, |
| 144 | 0 |
| 145 | }; |
| 146 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 147 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | | FATTR4_WORD0_MAXREAD |
| 149 | | FATTR4_WORD0_MAXWRITE |
| 150 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 151 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 152 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 153 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | }; |
| 155 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 156 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 157 | FATTR4_WORD0_TYPE |
| 158 | | FATTR4_WORD0_CHANGE |
| 159 | | FATTR4_WORD0_SIZE |
| 160 | | FATTR4_WORD0_FSID |
| 161 | | FATTR4_WORD0_FILEID |
| 162 | | FATTR4_WORD0_FS_LOCATIONS, |
| 163 | FATTR4_WORD1_MODE |
| 164 | | FATTR4_WORD1_NUMLINKS |
| 165 | | FATTR4_WORD1_OWNER |
| 166 | | FATTR4_WORD1_OWNER_GROUP |
| 167 | | FATTR4_WORD1_RAWDEV |
| 168 | | FATTR4_WORD1_SPACE_USED |
| 169 | | FATTR4_WORD1_TIME_ACCESS |
| 170 | | FATTR4_WORD1_TIME_METADATA |
| 171 | | FATTR4_WORD1_TIME_MODIFY |
| 172 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 173 | }; |
| 174 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 175 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | struct nfs4_readdir_arg *readdir) |
| 177 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 178 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
| 180 | BUG_ON(readdir->count < 80); |
| 181 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 182 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 184 | return; |
| 185 | } |
| 186 | |
| 187 | readdir->cookie = 0; |
| 188 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 189 | if (cookie == 2) |
| 190 | return; |
| 191 | |
| 192 | /* |
| 193 | * NFSv4 servers do not return entries for '.' and '..' |
| 194 | * Therefore, we fake these entries here. We let '.' |
| 195 | * have cookie 0 and '..' have cookie 1. Note that |
| 196 | * when talking to the server, we always send cookie 0 |
| 197 | * instead of 1 or 2. |
| 198 | */ |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 199 | start = p = kmap_atomic(*readdir->pages, KM_USER0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
| 201 | if (cookie == 0) { |
| 202 | *p++ = xdr_one; /* next */ |
| 203 | *p++ = xdr_zero; /* cookie, first word */ |
| 204 | *p++ = xdr_one; /* cookie, second word */ |
| 205 | *p++ = xdr_one; /* entry len */ |
| 206 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 207 | p++; |
| 208 | *p++ = xdr_one; /* bitmap length */ |
| 209 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 210 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 211 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | *p++ = xdr_one; /* next */ |
| 215 | *p++ = xdr_zero; /* cookie, first word */ |
| 216 | *p++ = xdr_two; /* cookie, second word */ |
| 217 | *p++ = xdr_two; /* entry len */ |
| 218 | memcpy(p, "..\0\0", 4); /* entry */ |
| 219 | p++; |
| 220 | *p++ = xdr_one; /* bitmap length */ |
| 221 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 222 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 223 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
| 225 | readdir->pgbase = (char *)p - (char *)start; |
| 226 | readdir->count -= readdir->pgbase; |
| 227 | kunmap_atomic(start, KM_USER0); |
| 228 | } |
| 229 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 230 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 231 | { |
| 232 | int res; |
| 233 | |
| 234 | might_sleep(); |
| 235 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 236 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 237 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 238 | return res; |
| 239 | } |
| 240 | |
| 241 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 242 | { |
| 243 | int res = 0; |
| 244 | |
| 245 | might_sleep(); |
| 246 | |
| 247 | if (*timeout <= 0) |
| 248 | *timeout = NFS4_POLL_RETRY_MIN; |
| 249 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 250 | *timeout = NFS4_POLL_RETRY_MAX; |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 251 | freezable_schedule_timeout_killable(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 252 | if (fatal_signal_pending(current)) |
| 253 | res = -ERESTARTSYS; |
| 254 | *timeout <<= 1; |
| 255 | return res; |
| 256 | } |
| 257 | |
| 258 | /* This is the error handling routine for processes that are allowed |
| 259 | * to sleep. |
| 260 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 261 | 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] | 262 | { |
| 263 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 264 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 265 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 266 | int ret = errorcode; |
| 267 | |
| 268 | exception->retry = 0; |
| 269 | switch(errorcode) { |
| 270 | case 0: |
| 271 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 272 | case -NFS4ERR_OPENMODE: |
| 273 | if (nfs_have_delegation(inode, FMODE_READ)) { |
| 274 | nfs_inode_return_delegation(inode); |
| 275 | exception->retry = 1; |
| 276 | return 0; |
| 277 | } |
| 278 | if (state == NULL) |
| 279 | break; |
| 280 | nfs4_schedule_stateid_recovery(server, state); |
| 281 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 282 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 283 | case -NFS4ERR_ADMIN_REVOKED: |
| 284 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 285 | if (state != NULL) |
| 286 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 287 | if (state == NULL) |
| 288 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 289 | nfs4_schedule_stateid_recovery(server, state); |
| 290 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 291 | case -NFS4ERR_EXPIRED: |
| 292 | if (state != NULL) |
| 293 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 294 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 295 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 296 | nfs4_schedule_lease_recovery(clp); |
| 297 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 298 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 299 | case -NFS4ERR_BADSESSION: |
| 300 | case -NFS4ERR_BADSLOT: |
| 301 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 302 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 303 | case -NFS4ERR_DEADSESSION: |
| 304 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 305 | case -NFS4ERR_SEQ_MISORDERED: |
| 306 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 307 | errorcode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 308 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 309 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 310 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 311 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 312 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 313 | if (exception->timeout > HZ) { |
| 314 | /* We have retried a decent amount, time to |
| 315 | * fail |
| 316 | */ |
| 317 | ret = -EBUSY; |
| 318 | break; |
| 319 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 320 | case -NFS4ERR_GRACE: |
| 321 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 322 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 323 | ret = nfs4_delay(server->client, &exception->timeout); |
| 324 | if (ret != 0) |
| 325 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 326 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 327 | case -NFS4ERR_OLD_STATEID: |
| 328 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 329 | break; |
| 330 | case -NFS4ERR_BADOWNER: |
| 331 | /* The following works around a Linux server bug! */ |
| 332 | case -NFS4ERR_BADNAME: |
| 333 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 334 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 335 | exception->retry = 1; |
| 336 | printk(KERN_WARNING "NFS: v4 server %s " |
| 337 | "does not accept raw " |
| 338 | "uid/gids. " |
| 339 | "Reenabling the idmapper.\n", |
| 340 | server->nfs_client->cl_hostname); |
| 341 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 342 | } |
| 343 | /* We failed to handle the error */ |
| 344 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 345 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 346 | ret = nfs4_wait_clnt_recover(clp); |
| 347 | if (ret == 0) |
| 348 | exception->retry = 1; |
| 349 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 353 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | spin_lock(&clp->cl_lock); |
| 356 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 357 | clp->cl_last_renewal = timestamp; |
| 358 | spin_unlock(&clp->cl_lock); |
| 359 | } |
| 360 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 361 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 362 | { |
| 363 | do_renew_lease(server->nfs_client, timestamp); |
| 364 | } |
| 365 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 366 | #if defined(CONFIG_NFS_V4_1) |
| 367 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 368 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 369 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 370 | * |
| 371 | * freeing a slot is trivially done by clearing its respective bit |
| 372 | * in the bitmap. |
| 373 | * If the freed slotid equals highest_used_slotid we want to update it |
| 374 | * so that the server would be able to size down the slot table if needed, |
| 375 | * otherwise we know that the highest_used_slotid is still in use. |
| 376 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 377 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 378 | * highest slotid in use. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 379 | * If none found, highest_used_slotid is set to NFS4_NO_SLOT. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 380 | * |
| 381 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 382 | */ |
| 383 | static void |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 384 | nfs4_free_slot(struct nfs4_slot_table *tbl, u32 slotid) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 385 | { |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 386 | BUG_ON(slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 387 | /* clear used bit in bitmap */ |
| 388 | __clear_bit(slotid, tbl->used_slots); |
| 389 | |
| 390 | /* update highest_used_slotid when it is freed */ |
| 391 | if (slotid == tbl->highest_used_slotid) { |
| 392 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 393 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 394 | tbl->highest_used_slotid = slotid; |
| 395 | else |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 396 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 397 | } |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 398 | dprintk("%s: slotid %u highest_used_slotid %d\n", __func__, |
| 399 | slotid, tbl->highest_used_slotid); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 400 | } |
| 401 | |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 402 | bool nfs4_set_task_privileged(struct rpc_task *task, void *dummy) |
| 403 | { |
| 404 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 405 | return true; |
| 406 | } |
| 407 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 408 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 409 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 410 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 411 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 412 | { |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 413 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 414 | rpc_wake_up_first(&ses->fc_slot_table.slot_tbl_waitq, |
| 415 | nfs4_set_task_privileged, NULL); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 416 | return; |
| 417 | } |
| 418 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 419 | if (ses->fc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 420 | return; |
| 421 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 422 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 423 | complete(&ses->fc_slot_table.complete); |
| 424 | } |
| 425 | |
| 426 | /* |
| 427 | * Signal state manager thread if session back channel is drained |
| 428 | */ |
| 429 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 430 | { |
| 431 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 432 | ses->bc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 433 | return; |
| 434 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 435 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 436 | } |
| 437 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 438 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 439 | { |
| 440 | struct nfs4_slot_table *tbl; |
| 441 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 442 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 443 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 444 | /* just wake up the next guy waiting since |
| 445 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 446 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 447 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 448 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 449 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 450 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | aabd0b4 | 2011-11-09 13:58:22 -0500 | [diff] [blame] | 451 | nfs4_free_slot(tbl, res->sr_slot - tbl->slots); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 452 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 453 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 454 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 455 | } |
| 456 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 457 | 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] | 458 | { |
| 459 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 460 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 461 | |
| 462 | /* |
| 463 | * sr_status remains 1 if an RPC level error occurred. The server |
| 464 | * may or may not have processed the sequence operation.. |
| 465 | * Proceed as if the server received and processed the sequence |
| 466 | * operation. |
| 467 | */ |
| 468 | if (res->sr_status == 1) |
| 469 | res->sr_status = NFS_OK; |
| 470 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 471 | /* don't increment the sequence number if the task wasn't sent */ |
| 472 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 473 | goto out; |
| 474 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 475 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 476 | switch (res->sr_status) { |
| 477 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 478 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 479 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 480 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 481 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 482 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 483 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 484 | if (res->sr_status_flags != 0) |
| 485 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 486 | break; |
| 487 | case -NFS4ERR_DELAY: |
| 488 | /* The server detected a resend of the RPC call and |
| 489 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 490 | * of RFC5661. |
| 491 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 492 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 493 | __func__, |
| 494 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 495 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 496 | goto out_retry; |
| 497 | default: |
| 498 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 499 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 500 | } |
| 501 | out: |
| 502 | /* The session may be reset by one of the error handlers. */ |
| 503 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 504 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 505 | return 1; |
| 506 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 507 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 508 | goto out; |
| 509 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 510 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 511 | } |
| 512 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 513 | static int nfs4_sequence_done(struct rpc_task *task, |
| 514 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 515 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 516 | if (res->sr_session == NULL) |
| 517 | return 1; |
| 518 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 519 | } |
| 520 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 521 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 522 | * nfs4_find_slot - efficiently look for a free slot |
| 523 | * |
| 524 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 525 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 526 | * and respectively set up the sequence operation args. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 527 | * The slot number is returned if found, or NFS4_NO_SLOT otherwise. |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 528 | * |
| 529 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 530 | */ |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 531 | static u32 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 532 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 533 | { |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 534 | u32 slotid; |
| 535 | u32 ret_id = NFS4_NO_SLOT; |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 536 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 537 | dprintk("--> %s used_slots=%04lx highest_used=%u max_slots=%u\n", |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 538 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 539 | tbl->max_slots); |
| 540 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 541 | if (slotid >= tbl->max_slots) |
| 542 | goto out; |
| 543 | __set_bit(slotid, tbl->used_slots); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 544 | if (slotid > tbl->highest_used_slotid || |
| 545 | tbl->highest_used_slotid == NFS4_NO_SLOT) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 546 | tbl->highest_used_slotid = slotid; |
| 547 | ret_id = slotid; |
| 548 | out: |
| 549 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 550 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 551 | return ret_id; |
| 552 | } |
| 553 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 554 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 555 | struct nfs4_sequence_res *res, int cache_reply) |
| 556 | { |
| 557 | args->sa_session = NULL; |
| 558 | args->sa_cache_this = 0; |
| 559 | if (cache_reply) |
| 560 | args->sa_cache_this = 1; |
| 561 | res->sr_session = NULL; |
| 562 | res->sr_slot = NULL; |
| 563 | } |
| 564 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 565 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 566 | struct nfs4_sequence_args *args, |
| 567 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 568 | struct rpc_task *task) |
| 569 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 570 | struct nfs4_slot *slot; |
| 571 | struct nfs4_slot_table *tbl; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 572 | u32 slotid; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 573 | |
| 574 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 575 | /* slot already allocated? */ |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 576 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 577 | return 0; |
| 578 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 579 | tbl = &session->fc_slot_table; |
| 580 | |
| 581 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 582 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 583 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 584 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 585 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 586 | spin_unlock(&tbl->slot_tbl_lock); |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 587 | dprintk("%s session is draining\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 588 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 589 | } |
| 590 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 591 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 592 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 593 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 594 | spin_unlock(&tbl->slot_tbl_lock); |
| 595 | dprintk("%s enforce FIFO order\n", __func__); |
| 596 | return -EAGAIN; |
| 597 | } |
| 598 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 599 | slotid = nfs4_find_slot(tbl); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 600 | if (slotid == NFS4_NO_SLOT) { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 601 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 602 | spin_unlock(&tbl->slot_tbl_lock); |
| 603 | dprintk("<-- %s: no free slots\n", __func__); |
| 604 | return -EAGAIN; |
| 605 | } |
| 606 | spin_unlock(&tbl->slot_tbl_lock); |
| 607 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 608 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 609 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 610 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 611 | args->sa_slotid = slotid; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 612 | |
| 613 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 614 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 615 | res->sr_session = session; |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 616 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 617 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 618 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 619 | /* |
| 620 | * sr_status is only set in decode_sequence, and so will remain |
| 621 | * set to 1 if an rpc level failure occurs. |
| 622 | */ |
| 623 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 624 | return 0; |
| 625 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 626 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 627 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 628 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 629 | struct nfs4_sequence_args *args, |
| 630 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 631 | struct rpc_task *task) |
| 632 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 633 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 634 | int ret = 0; |
| 635 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 636 | if (session == NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 637 | goto out; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 638 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 639 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 640 | __func__, session->clp, session, res->sr_slot ? |
| 641 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 642 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 643 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 644 | out: |
| 645 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 646 | return ret; |
| 647 | } |
| 648 | |
| 649 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 650 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 651 | struct nfs4_sequence_args *seq_args; |
| 652 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 653 | }; |
| 654 | |
| 655 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 656 | { |
| 657 | struct nfs41_call_sync_data *data = calldata; |
| 658 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 659 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 660 | |
| 661 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 662 | data->seq_res, task)) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 663 | return; |
| 664 | rpc_call_start(task); |
| 665 | } |
| 666 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 667 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 668 | { |
| 669 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 670 | nfs41_call_sync_prepare(task, calldata); |
| 671 | } |
| 672 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 673 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 674 | { |
| 675 | struct nfs41_call_sync_data *data = calldata; |
| 676 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 677 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 678 | } |
| 679 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 680 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 681 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 682 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 683 | }; |
| 684 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 685 | static const struct rpc_call_ops nfs41_call_priv_sync_ops = { |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 686 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 687 | .rpc_call_done = nfs41_call_sync_done, |
| 688 | }; |
| 689 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 690 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 691 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 692 | struct rpc_message *msg, |
| 693 | struct nfs4_sequence_args *args, |
| 694 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 695 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 696 | { |
| 697 | int ret; |
| 698 | struct rpc_task *task; |
| 699 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 700 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 701 | .seq_args = args, |
| 702 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 703 | }; |
| 704 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 705 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 706 | .rpc_message = msg, |
| 707 | .callback_ops = &nfs41_call_sync_ops, |
| 708 | .callback_data = &data |
| 709 | }; |
| 710 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 711 | if (privileged) |
| 712 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 713 | task = rpc_run_task(&task_setup); |
| 714 | if (IS_ERR(task)) |
| 715 | ret = PTR_ERR(task); |
| 716 | else { |
| 717 | ret = task->tk_status; |
| 718 | rpc_put_task(task); |
| 719 | } |
| 720 | return ret; |
| 721 | } |
| 722 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 723 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 724 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 725 | struct rpc_message *msg, |
| 726 | struct nfs4_sequence_args *args, |
| 727 | struct nfs4_sequence_res *res, |
| 728 | int cache_reply) |
| 729 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 730 | nfs41_init_sequence(args, res, cache_reply); |
| 731 | return nfs4_call_sync_sequence(clnt, server, msg, args, res, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 732 | } |
| 733 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 734 | #else |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 735 | static inline |
| 736 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 737 | struct nfs4_sequence_res *res, int cache_reply) |
| 738 | { |
| 739 | } |
| 740 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 741 | static int nfs4_sequence_done(struct rpc_task *task, |
| 742 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 743 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 744 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 745 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 746 | #endif /* CONFIG_NFS_V4_1 */ |
| 747 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 748 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 749 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 750 | struct rpc_message *msg, |
| 751 | struct nfs4_sequence_args *args, |
| 752 | struct nfs4_sequence_res *res, |
| 753 | int cache_reply) |
| 754 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 755 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 756 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 757 | } |
| 758 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 759 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 760 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 761 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 762 | struct rpc_message *msg, |
| 763 | struct nfs4_sequence_args *args, |
| 764 | struct nfs4_sequence_res *res, |
| 765 | int cache_reply) |
| 766 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 767 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 768 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 769 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 770 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 771 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 773 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 775 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 776 | 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] | 777 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 778 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 779 | dir->i_version = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 780 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | } |
| 782 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 783 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 784 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 785 | struct nfs_openargs o_arg; |
| 786 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 787 | struct nfs_open_confirmargs c_arg; |
| 788 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 789 | struct nfs4_string owner_name; |
| 790 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 791 | struct nfs_fattr f_attr; |
| 792 | struct nfs_fattr dir_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 793 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 794 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 795 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 796 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 797 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 798 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 799 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 800 | int rpc_status; |
| 801 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 802 | }; |
| 803 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 804 | |
| 805 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 806 | { |
| 807 | p->o_res.f_attr = &p->f_attr; |
| 808 | p->o_res.dir_attr = &p->dir_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 809 | p->o_res.seqid = p->o_arg.seqid; |
| 810 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 811 | p->o_res.server = p->o_arg.server; |
| 812 | nfs_fattr_init(&p->f_attr); |
| 813 | nfs_fattr_init(&p->dir_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 814 | 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] | 815 | } |
| 816 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 817 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 818 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 819 | const struct iattr *attrs, |
| 820 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 821 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 822 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 823 | struct inode *dir = parent->d_inode; |
| 824 | struct nfs_server *server = NFS_SERVER(dir); |
| 825 | struct nfs4_opendata *p; |
| 826 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 827 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 828 | if (p == NULL) |
| 829 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 830 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 831 | if (p->o_arg.seqid == NULL) |
| 832 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 833 | nfs_sb_active(dentry->d_sb); |
| 834 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 835 | p->dir = parent; |
| 836 | p->owner = sp; |
| 837 | atomic_inc(&sp->so_count); |
| 838 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 839 | p->o_arg.open_flags = flags; |
| 840 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 841 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 842 | p->o_arg.id = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 843 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 844 | p->o_arg.server = server; |
| 845 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 846 | p->o_arg.dir_bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 847 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 848 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 849 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 850 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 851 | p->o_arg.u.attrs = &p->attrs; |
| 852 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 853 | |
| 854 | verf[0] = jiffies; |
| 855 | verf[1] = current->pid; |
| 856 | memcpy(p->o_arg.u.verifier.data, verf, |
| 857 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 858 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 859 | p->c_arg.fh = &p->o_res.fh; |
| 860 | p->c_arg.stateid = &p->o_res.stateid; |
| 861 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 862 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 863 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 864 | return p; |
| 865 | err_free: |
| 866 | kfree(p); |
| 867 | err: |
| 868 | dput(parent); |
| 869 | return NULL; |
| 870 | } |
| 871 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 872 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 873 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 874 | struct nfs4_opendata *p = container_of(kref, |
| 875 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 876 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 877 | |
| 878 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 879 | if (p->state != NULL) |
| 880 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 881 | nfs4_put_state_owner(p->owner); |
| 882 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 883 | dput(p->dentry); |
| 884 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 885 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 886 | kfree(p); |
| 887 | } |
| 888 | |
| 889 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 890 | { |
| 891 | if (p != NULL) |
| 892 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 893 | } |
| 894 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 895 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 896 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 897 | int ret; |
| 898 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 899 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 900 | return ret; |
| 901 | } |
| 902 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 903 | 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] | 904 | { |
| 905 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 906 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 907 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 908 | goto out; |
| 909 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 910 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 911 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 912 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 913 | break; |
| 914 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 915 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 916 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 917 | break; |
| 918 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 919 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 920 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 921 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 922 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 923 | return ret; |
| 924 | } |
| 925 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 926 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 927 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 928 | if (delegation == NULL) |
| 929 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 930 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 931 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 932 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 933 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 934 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 935 | return 1; |
| 936 | } |
| 937 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 938 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 939 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 940 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 941 | case FMODE_WRITE: |
| 942 | state->n_wronly++; |
| 943 | break; |
| 944 | case FMODE_READ: |
| 945 | state->n_rdonly++; |
| 946 | break; |
| 947 | case FMODE_READ|FMODE_WRITE: |
| 948 | state->n_rdwr++; |
| 949 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 950 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 951 | } |
| 952 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 953 | 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] | 954 | { |
| 955 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 956 | nfs4_stateid_copy(&state->stateid, stateid); |
| 957 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 958 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 959 | case FMODE_READ: |
| 960 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 961 | break; |
| 962 | case FMODE_WRITE: |
| 963 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 964 | break; |
| 965 | case FMODE_READ|FMODE_WRITE: |
| 966 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 967 | } |
| 968 | } |
| 969 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 970 | 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] | 971 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 972 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 973 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 974 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 975 | } |
| 976 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 977 | 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] | 978 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 979 | /* |
| 980 | * Protect the call to nfs4_state_set_mode_locked and |
| 981 | * serialise the stateid update |
| 982 | */ |
| 983 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 984 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 985 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 986 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 987 | } |
| 988 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 989 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 990 | write_sequnlock(&state->seqlock); |
| 991 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 992 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 993 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | } |
| 995 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 996 | 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] | 997 | { |
| 998 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 999 | struct nfs_delegation *deleg_cur; |
| 1000 | int ret = 0; |
| 1001 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1002 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1003 | |
| 1004 | rcu_read_lock(); |
| 1005 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1006 | if (deleg_cur == NULL) |
| 1007 | goto no_delegation; |
| 1008 | |
| 1009 | spin_lock(&deleg_cur->lock); |
| 1010 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1011 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1012 | goto no_delegation_unlock; |
| 1013 | |
| 1014 | if (delegation == NULL) |
| 1015 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1016 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1017 | goto no_delegation_unlock; |
| 1018 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1019 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1020 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1021 | ret = 1; |
| 1022 | no_delegation_unlock: |
| 1023 | spin_unlock(&deleg_cur->lock); |
| 1024 | no_delegation: |
| 1025 | rcu_read_unlock(); |
| 1026 | |
| 1027 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1028 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1029 | ret = 1; |
| 1030 | } |
| 1031 | |
| 1032 | return ret; |
| 1033 | } |
| 1034 | |
| 1035 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1036 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1037 | { |
| 1038 | struct nfs_delegation *delegation; |
| 1039 | |
| 1040 | rcu_read_lock(); |
| 1041 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1042 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1043 | rcu_read_unlock(); |
| 1044 | return; |
| 1045 | } |
| 1046 | rcu_read_unlock(); |
| 1047 | nfs_inode_return_delegation(inode); |
| 1048 | } |
| 1049 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1050 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1051 | { |
| 1052 | struct nfs4_state *state = opendata->state; |
| 1053 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1054 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1055 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1056 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1057 | nfs4_stateid stateid; |
| 1058 | int ret = -EAGAIN; |
| 1059 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1060 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1061 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1062 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1063 | if (can_open_cached(state, fmode, open_mode)) { |
| 1064 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1065 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1066 | goto out_return_state; |
| 1067 | } |
| 1068 | spin_unlock(&state->owner->so_lock); |
| 1069 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1070 | rcu_read_lock(); |
| 1071 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1072 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1073 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1074 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1075 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1076 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1077 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1078 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1079 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1080 | if (ret != 0) |
| 1081 | goto out; |
| 1082 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1083 | |
| 1084 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1085 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1086 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1087 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1088 | out: |
| 1089 | return ERR_PTR(ret); |
| 1090 | out_return_state: |
| 1091 | atomic_inc(&state->count); |
| 1092 | return state; |
| 1093 | } |
| 1094 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1095 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1096 | { |
| 1097 | struct inode *inode; |
| 1098 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1099 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1100 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1101 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1102 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1103 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1104 | goto out; |
| 1105 | } |
| 1106 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1107 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1108 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1109 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1110 | 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] | 1111 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1112 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1113 | goto err; |
| 1114 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1115 | state = nfs4_get_open_state(inode, data->owner); |
| 1116 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1117 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1118 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 1119 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1120 | int delegation_flags = 0; |
| 1121 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1122 | rcu_read_lock(); |
| 1123 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1124 | if (delegation) |
| 1125 | delegation_flags = delegation->flags; |
| 1126 | rcu_read_unlock(); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1127 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1128 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1129 | "returning a delegation for " |
| 1130 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 1131 | clp->cl_hostname); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1132 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1133 | nfs_inode_set_delegation(state->inode, |
| 1134 | data->owner->so_cred, |
| 1135 | &data->o_res); |
| 1136 | else |
| 1137 | nfs_inode_reclaim_delegation(state->inode, |
| 1138 | data->owner->so_cred, |
| 1139 | &data->o_res); |
| 1140 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1141 | |
| 1142 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1143 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1144 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1145 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1146 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1147 | err_put_inode: |
| 1148 | iput(inode); |
| 1149 | err: |
| 1150 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1151 | } |
| 1152 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1153 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1154 | { |
| 1155 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1156 | struct nfs_open_context *ctx; |
| 1157 | |
| 1158 | spin_lock(&state->inode->i_lock); |
| 1159 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1160 | if (ctx->state != state) |
| 1161 | continue; |
| 1162 | get_nfs_open_context(ctx); |
| 1163 | spin_unlock(&state->inode->i_lock); |
| 1164 | return ctx; |
| 1165 | } |
| 1166 | spin_unlock(&state->inode->i_lock); |
| 1167 | return ERR_PTR(-ENOENT); |
| 1168 | } |
| 1169 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1170 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1171 | { |
| 1172 | struct nfs4_opendata *opendata; |
| 1173 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1174 | 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] | 1175 | if (opendata == NULL) |
| 1176 | return ERR_PTR(-ENOMEM); |
| 1177 | opendata->state = state; |
| 1178 | atomic_inc(&state->count); |
| 1179 | return opendata; |
| 1180 | } |
| 1181 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1182 | 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] | 1183 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1184 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1185 | int ret; |
| 1186 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1187 | opendata->o_arg.open_flags = 0; |
| 1188 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1189 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1190 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1191 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1192 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1193 | if (ret != 0) |
| 1194 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1195 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1196 | if (IS_ERR(newstate)) |
| 1197 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1198 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1199 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1200 | return 0; |
| 1201 | } |
| 1202 | |
| 1203 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1204 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1205 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1206 | int ret; |
| 1207 | |
| 1208 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1209 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1210 | smp_rmb(); |
| 1211 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1212 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1213 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1214 | if (ret != 0) |
| 1215 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1216 | if (newstate != state) |
| 1217 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1218 | } |
| 1219 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1220 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1221 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1222 | if (ret != 0) |
| 1223 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1224 | if (newstate != state) |
| 1225 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1226 | } |
| 1227 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1228 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1229 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1230 | if (ret != 0) |
| 1231 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1232 | if (newstate != state) |
| 1233 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1234 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1235 | /* |
| 1236 | * We may have performed cached opens for all three recoveries. |
| 1237 | * Check if we need to update the current stateid. |
| 1238 | */ |
| 1239 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1240 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1241 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1242 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1243 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1244 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1245 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1246 | return 0; |
| 1247 | } |
| 1248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | /* |
| 1250 | * OPEN_RECLAIM: |
| 1251 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1253 | 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] | 1254 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1255 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1256 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1257 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | int status; |
| 1259 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1260 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1261 | if (IS_ERR(opendata)) |
| 1262 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1263 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1264 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1265 | rcu_read_lock(); |
| 1266 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1267 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1268 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1269 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1270 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1271 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1272 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | return status; |
| 1274 | } |
| 1275 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1276 | 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] | 1277 | { |
| 1278 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1279 | struct nfs4_exception exception = { }; |
| 1280 | int err; |
| 1281 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1282 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1283 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1284 | break; |
| 1285 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | } while (exception.retry); |
| 1287 | return err; |
| 1288 | } |
| 1289 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1290 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1291 | { |
| 1292 | struct nfs_open_context *ctx; |
| 1293 | int ret; |
| 1294 | |
| 1295 | ctx = nfs4_state_find_open_context(state); |
| 1296 | if (IS_ERR(ctx)) |
| 1297 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1298 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1299 | put_nfs_open_context(ctx); |
| 1300 | return ret; |
| 1301 | } |
| 1302 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1303 | 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] | 1304 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1305 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1306 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1308 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1309 | if (IS_ERR(opendata)) |
| 1310 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1311 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1312 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1313 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1314 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1315 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1318 | 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] | 1319 | { |
| 1320 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1321 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | int err; |
| 1323 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1324 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | switch (err) { |
| 1326 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1327 | case -ENOENT: |
| 1328 | case -ESTALE: |
| 1329 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1330 | case -NFS4ERR_BADSESSION: |
| 1331 | case -NFS4ERR_BADSLOT: |
| 1332 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1333 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1334 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1335 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1336 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | case -NFS4ERR_STALE_CLIENTID: |
| 1338 | case -NFS4ERR_STALE_STATEID: |
| 1339 | case -NFS4ERR_EXPIRED: |
| 1340 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1341 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1342 | goto out; |
| 1343 | case -ERESTARTSYS: |
| 1344 | /* |
| 1345 | * The show must go on: exit, but mark the |
| 1346 | * stateid as needing recovery. |
| 1347 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1348 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1349 | case -NFS4ERR_ADMIN_REVOKED: |
| 1350 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1351 | nfs_inode_find_state_and_recover(state->inode, |
| 1352 | stateid); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1353 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1354 | case -EKEYEXPIRED: |
| 1355 | /* |
| 1356 | * User RPCSEC_GSS context has expired. |
| 1357 | * We cannot recover this stateid now, so |
| 1358 | * skip it and allow recovery thread to |
| 1359 | * proceed. |
| 1360 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1361 | case -ENOMEM: |
| 1362 | err = 0; |
| 1363 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | } |
| 1365 | err = nfs4_handle_exception(server, err, &exception); |
| 1366 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1367 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | return err; |
| 1369 | } |
| 1370 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1371 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1372 | { |
| 1373 | struct nfs4_opendata *data = calldata; |
| 1374 | |
| 1375 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1376 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1377 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1378 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1379 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1380 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1381 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | static void nfs4_open_confirm_release(void *calldata) |
| 1385 | { |
| 1386 | struct nfs4_opendata *data = calldata; |
| 1387 | struct nfs4_state *state = NULL; |
| 1388 | |
| 1389 | /* If this request hasn't been cancelled, do nothing */ |
| 1390 | if (data->cancelled == 0) |
| 1391 | goto out_free; |
| 1392 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1393 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1394 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1395 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1396 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1397 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1398 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1399 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1403 | .rpc_call_done = nfs4_open_confirm_done, |
| 1404 | .rpc_release = nfs4_open_confirm_release, |
| 1405 | }; |
| 1406 | |
| 1407 | /* |
| 1408 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1409 | */ |
| 1410 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1411 | { |
| 1412 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1413 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1414 | struct rpc_message msg = { |
| 1415 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1416 | .rpc_argp = &data->c_arg, |
| 1417 | .rpc_resp = &data->c_res, |
| 1418 | .rpc_cred = data->owner->so_cred, |
| 1419 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1420 | struct rpc_task_setup task_setup_data = { |
| 1421 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1422 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1423 | .callback_ops = &nfs4_open_confirm_ops, |
| 1424 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1425 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1426 | .flags = RPC_TASK_ASYNC, |
| 1427 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | int status; |
| 1429 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1430 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1431 | data->rpc_done = 0; |
| 1432 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1433 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1434 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1435 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1436 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1437 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1438 | if (status != 0) { |
| 1439 | data->cancelled = 1; |
| 1440 | smp_wmb(); |
| 1441 | } else |
| 1442 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1443 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | return status; |
| 1445 | } |
| 1446 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1447 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1449 | struct nfs4_opendata *data = calldata; |
| 1450 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1451 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1452 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1453 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1454 | /* |
| 1455 | * Check if we still need to send an OPEN call, or if we can use |
| 1456 | * a delegation instead. |
| 1457 | */ |
| 1458 | if (data->state != NULL) { |
| 1459 | struct nfs_delegation *delegation; |
| 1460 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1461 | 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] | 1462 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1463 | rcu_read_lock(); |
| 1464 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1465 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1466 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1467 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1468 | rcu_read_unlock(); |
| 1469 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1470 | /* Update sequence id. */ |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1471 | data->o_arg.id = sp->so_seqid.owner_id; |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1472 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1473 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1474 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1475 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1476 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1477 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1478 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1479 | &data->o_arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1480 | &data->o_res.seq_res, task)) |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1481 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1482 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1483 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1484 | unlock_no_action: |
| 1485 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1486 | out_no_action: |
| 1487 | task->tk_action = NULL; |
| 1488 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1489 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1491 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1492 | { |
| 1493 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1494 | nfs4_open_prepare(task, calldata); |
| 1495 | } |
| 1496 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1497 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1498 | { |
| 1499 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1501 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1502 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1503 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1504 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1505 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1506 | if (task->tk_status == 0) { |
| 1507 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1508 | case S_IFREG: |
| 1509 | break; |
| 1510 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1511 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1512 | break; |
| 1513 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1514 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1515 | break; |
| 1516 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1517 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1518 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1519 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1520 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1521 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1522 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1523 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1524 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1525 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1526 | static void nfs4_open_release(void *calldata) |
| 1527 | { |
| 1528 | struct nfs4_opendata *data = calldata; |
| 1529 | struct nfs4_state *state = NULL; |
| 1530 | |
| 1531 | /* If this request hasn't been cancelled, do nothing */ |
| 1532 | if (data->cancelled == 0) |
| 1533 | goto out_free; |
| 1534 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1535 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1536 | goto out_free; |
| 1537 | /* In case we need an open_confirm, no cleanup! */ |
| 1538 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1539 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1540 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1541 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1542 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1543 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1544 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1548 | .rpc_call_prepare = nfs4_open_prepare, |
| 1549 | .rpc_call_done = nfs4_open_done, |
| 1550 | .rpc_release = nfs4_open_release, |
| 1551 | }; |
| 1552 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1553 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1554 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1555 | .rpc_call_done = nfs4_open_done, |
| 1556 | .rpc_release = nfs4_open_release, |
| 1557 | }; |
| 1558 | |
| 1559 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1560 | { |
| 1561 | struct inode *dir = data->dir->d_inode; |
| 1562 | struct nfs_server *server = NFS_SERVER(dir); |
| 1563 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1564 | struct nfs_openres *o_res = &data->o_res; |
| 1565 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1566 | struct rpc_message msg = { |
| 1567 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1568 | .rpc_argp = o_arg, |
| 1569 | .rpc_resp = o_res, |
| 1570 | .rpc_cred = data->owner->so_cred, |
| 1571 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1572 | struct rpc_task_setup task_setup_data = { |
| 1573 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1574 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1575 | .callback_ops = &nfs4_open_ops, |
| 1576 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1577 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1578 | .flags = RPC_TASK_ASYNC, |
| 1579 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1580 | int status; |
| 1581 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1582 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1583 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1584 | data->rpc_done = 0; |
| 1585 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1586 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1587 | if (isrecover) |
| 1588 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1589 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1590 | if (IS_ERR(task)) |
| 1591 | return PTR_ERR(task); |
| 1592 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1593 | if (status != 0) { |
| 1594 | data->cancelled = 1; |
| 1595 | smp_wmb(); |
| 1596 | } else |
| 1597 | status = data->rpc_status; |
| 1598 | rpc_put_task(task); |
| 1599 | |
| 1600 | return status; |
| 1601 | } |
| 1602 | |
| 1603 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1604 | { |
| 1605 | struct inode *dir = data->dir->d_inode; |
| 1606 | struct nfs_openres *o_res = &data->o_res; |
| 1607 | int status; |
| 1608 | |
| 1609 | status = nfs4_run_open_task(data, 1); |
| 1610 | if (status != 0 || !data->rpc_done) |
| 1611 | return status; |
| 1612 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1613 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1614 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1615 | nfs_refresh_inode(dir, o_res->dir_attr); |
| 1616 | |
| 1617 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1618 | status = _nfs4_proc_open_confirm(data); |
| 1619 | if (status != 0) |
| 1620 | return status; |
| 1621 | } |
| 1622 | |
| 1623 | return status; |
| 1624 | } |
| 1625 | |
| 1626 | /* |
| 1627 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1628 | */ |
| 1629 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1630 | { |
| 1631 | struct inode *dir = data->dir->d_inode; |
| 1632 | struct nfs_server *server = NFS_SERVER(dir); |
| 1633 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1634 | struct nfs_openres *o_res = &data->o_res; |
| 1635 | int status; |
| 1636 | |
| 1637 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1638 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1639 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1640 | if (status != 0) { |
| 1641 | if (status == -NFS4ERR_BADNAME && |
| 1642 | !(o_arg->open_flags & O_CREAT)) |
| 1643 | return -ENOENT; |
| 1644 | return status; |
| 1645 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1646 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1647 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1648 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1649 | if (o_arg->open_flags & O_CREAT) { |
| 1650 | update_changeattr(dir, &o_res->cinfo); |
| 1651 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
| 1652 | } else |
| 1653 | nfs_refresh_inode(dir, o_res->dir_attr); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1654 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1655 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1657 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1659 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | } |
| 1661 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1662 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1663 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | } |
| 1665 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1666 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1667 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1668 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1669 | int ret; |
Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1670 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1671 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1672 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1673 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1674 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1675 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1676 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1677 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1678 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1679 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1680 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1681 | return ret; |
Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1682 | } |
| 1683 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1684 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1685 | { |
| 1686 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1687 | } |
| 1688 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | /* |
| 1690 | * OPEN_EXPIRED: |
| 1691 | * reclaim state on the server after a network partition. |
| 1692 | * Assumes caller holds the appropriate lock |
| 1693 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1694 | 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] | 1695 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1696 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1697 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1699 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1700 | if (IS_ERR(opendata)) |
| 1701 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1702 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1703 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1704 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1705 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1706 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | } |
| 1708 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1709 | 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] | 1710 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1711 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1712 | struct nfs4_exception exception = { }; |
| 1713 | int err; |
| 1714 | |
| 1715 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1716 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1717 | switch (err) { |
| 1718 | default: |
| 1719 | goto out; |
| 1720 | case -NFS4ERR_GRACE: |
| 1721 | case -NFS4ERR_DELAY: |
| 1722 | nfs4_handle_exception(server, err, &exception); |
| 1723 | err = 0; |
| 1724 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1725 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1726 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1727 | return err; |
| 1728 | } |
| 1729 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1731 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1733 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1735 | ctx = nfs4_state_find_open_context(state); |
| 1736 | if (IS_ERR(ctx)) |
| 1737 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1738 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1739 | put_nfs_open_context(ctx); |
| 1740 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | } |
| 1742 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1743 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1744 | static int nfs41_check_expired_stateid(struct nfs4_state *state, nfs4_stateid *stateid, unsigned int flags) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1745 | { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1746 | int status = NFS_OK; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1747 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1748 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1749 | if (state->flags & flags) { |
| 1750 | status = nfs41_test_stateid(server, stateid); |
| 1751 | if (status != NFS_OK) { |
| 1752 | nfs41_free_stateid(server, stateid); |
| 1753 | state->flags &= ~flags; |
| 1754 | } |
| 1755 | } |
| 1756 | return status; |
| 1757 | } |
| 1758 | |
| 1759 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1760 | { |
| 1761 | int deleg_status, open_status; |
| 1762 | int deleg_flags = 1 << NFS_DELEGATED_STATE; |
| 1763 | int open_flags = (1 << NFS_O_RDONLY_STATE) | (1 << NFS_O_WRONLY_STATE) | (1 << NFS_O_RDWR_STATE); |
| 1764 | |
| 1765 | deleg_status = nfs41_check_expired_stateid(state, &state->stateid, deleg_flags); |
| 1766 | open_status = nfs41_check_expired_stateid(state, &state->open_stateid, open_flags); |
| 1767 | |
| 1768 | if ((deleg_status == NFS_OK) && (open_status == NFS_OK)) |
| 1769 | return NFS_OK; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1770 | return nfs4_open_expired(sp, state); |
| 1771 | } |
| 1772 | #endif |
| 1773 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1775 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1776 | * fields corresponding to attributes that were used to store the verifier. |
| 1777 | * Make sure we clobber those fields in the later setattr call |
| 1778 | */ |
| 1779 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1780 | { |
| 1781 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1782 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1783 | sattr->ia_valid |= ATTR_ATIME; |
| 1784 | |
| 1785 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1786 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1787 | sattr->ia_valid |= ATTR_MTIME; |
| 1788 | } |
| 1789 | |
| 1790 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1791 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | */ |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1793 | 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] | 1794 | { |
| 1795 | struct nfs4_state_owner *sp; |
| 1796 | struct nfs4_state *state = NULL; |
| 1797 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1798 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1799 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | |
| 1801 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1803 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1804 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1806 | goto out_err; |
| 1807 | } |
Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1808 | status = nfs4_recover_expired_lease(server); |
| 1809 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1810 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1811 | if (dentry->d_inode != NULL) |
| 1812 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1813 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1814 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1815 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1816 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1818 | if (dentry->d_inode != NULL) |
| 1819 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1820 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1821 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1823 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1825 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1826 | status = PTR_ERR(state); |
| 1827 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1828 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1829 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1830 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1831 | |
| 1832 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1833 | nfs4_exclusive_attrset(opendata, sattr); |
| 1834 | |
| 1835 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1836 | status = nfs4_do_setattr(state->inode, cred, |
| 1837 | opendata->o_res.f_attr, sattr, |
| 1838 | state); |
| 1839 | if (status == 0) |
| 1840 | nfs_setattr_update_inode(state->inode, sattr); |
| 1841 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1842 | } |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1843 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | *res = state; |
| 1846 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1847 | err_opendata_put: |
| 1848 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1849 | err_put_state_owner: |
| 1850 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | *res = NULL; |
| 1853 | return status; |
| 1854 | } |
| 1855 | |
| 1856 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1857 | 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] | 1858 | { |
| 1859 | struct nfs4_exception exception = { }; |
| 1860 | struct nfs4_state *res; |
| 1861 | int status; |
| 1862 | |
| 1863 | do { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1864 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | if (status == 0) |
| 1866 | break; |
| 1867 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1868 | * book-keeping w.r.t. state-changing operations |
| 1869 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1870 | * It is actually a sign of a bug on the client or on the server. |
| 1871 | * |
| 1872 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1873 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | * have unhashed the old state_owner for us, and that we can |
| 1875 | * therefore safely retry using a new one. We should still warn |
| 1876 | * the user though... |
| 1877 | */ |
| 1878 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 1879 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1880 | " returned a bad sequence-id error!\n", |
| 1881 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | exception.retry = 1; |
| 1883 | continue; |
| 1884 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1885 | /* |
| 1886 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1887 | * state before it received the OPEN_CONFIRM. |
| 1888 | * Recover by retrying the request as per the discussion |
| 1889 | * on Page 181 of RFC3530. |
| 1890 | */ |
| 1891 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1892 | exception.retry = 1; |
| 1893 | continue; |
| 1894 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1895 | if (status == -EAGAIN) { |
| 1896 | /* We must have found a delegation */ |
| 1897 | exception.retry = 1; |
| 1898 | continue; |
| 1899 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1901 | status, &exception)); |
| 1902 | } while (exception.retry); |
| 1903 | return res; |
| 1904 | } |
| 1905 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1906 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1907 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1908 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1910 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1912 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | .iap = sattr, |
| 1914 | .server = server, |
| 1915 | .bitmask = server->attr_bitmask, |
| 1916 | }; |
| 1917 | struct nfs_setattrres res = { |
| 1918 | .fattr = fattr, |
| 1919 | .server = server, |
| 1920 | }; |
| 1921 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1922 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1923 | .rpc_argp = &arg, |
| 1924 | .rpc_resp = &res, |
| 1925 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1927 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1928 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1930 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 1932 | if (state != NULL) { |
| 1933 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
| 1934 | current->files, current->tgid); |
| 1935 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 1936 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1937 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1938 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1939 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1941 | 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] | 1942 | if (status == 0 && state != NULL) |
| 1943 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1944 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | } |
| 1946 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1947 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1948 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1949 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1951 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1952 | struct nfs4_exception exception = { |
| 1953 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 1954 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1955 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | int err; |
| 1957 | do { |
| 1958 | err = nfs4_handle_exception(server, |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1959 | _nfs4_do_setattr(inode, cred, fattr, sattr, state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | &exception); |
| 1961 | } while (exception.retry); |
| 1962 | return err; |
| 1963 | } |
| 1964 | |
| 1965 | struct nfs4_closedata { |
| 1966 | struct inode *inode; |
| 1967 | struct nfs4_state *state; |
| 1968 | struct nfs_closeargs arg; |
| 1969 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1970 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1971 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1972 | bool roc; |
| 1973 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | }; |
| 1975 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1976 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1977 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1978 | struct nfs4_closedata *calldata = data; |
| 1979 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1980 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1981 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1982 | if (calldata->roc) |
| 1983 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1984 | nfs4_put_open_state(calldata->state); |
| 1985 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1986 | nfs4_put_state_owner(sp); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1987 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1988 | kfree(calldata); |
| 1989 | } |
| 1990 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1991 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 1992 | fmode_t fmode) |
| 1993 | { |
| 1994 | spin_lock(&state->owner->so_lock); |
| 1995 | if (!(fmode & FMODE_READ)) |
| 1996 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1997 | if (!(fmode & FMODE_WRITE)) |
| 1998 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1999 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2000 | spin_unlock(&state->owner->so_lock); |
| 2001 | } |
| 2002 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2003 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2005 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2008 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2009 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2010 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2011 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | /* hmm. we are done with the inode, and in the process of freeing |
| 2013 | * the state_owner. we keep this around to process errors |
| 2014 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | switch (task->tk_status) { |
| 2016 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2017 | if (calldata->roc) |
| 2018 | pnfs_roc_set_barrier(state->inode, |
| 2019 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2020 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2021 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2022 | nfs4_close_clear_stateid_flags(state, |
| 2023 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | break; |
| 2025 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2026 | case -NFS4ERR_OLD_STATEID: |
| 2027 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2029 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2030 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2032 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2033 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2035 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2036 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2037 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | } |
| 2039 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2040 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2042 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2043 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2044 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2045 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2046 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2047 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2048 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2049 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2050 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2051 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2052 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2053 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2054 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2055 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2056 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2057 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2058 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2059 | } |
| 2060 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2061 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2062 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2063 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2064 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2065 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2066 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2067 | |
| 2068 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2069 | /* Note: exit _without_ calling nfs4_close_done */ |
| 2070 | task->tk_action = NULL; |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2071 | goto out; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2072 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2073 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2074 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2075 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2076 | if (calldata->roc && |
| 2077 | pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { |
| 2078 | rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, |
| 2079 | task, NULL); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2080 | goto out; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2081 | } |
| 2082 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2083 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2084 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2085 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2086 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2087 | &calldata->arg.seq_args, |
| 2088 | &calldata->res.seq_res, |
| 2089 | task)) |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2090 | goto out; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2091 | rpc_call_start(task); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2092 | out: |
| 2093 | dprintk("%s: done!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | } |
| 2095 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2096 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2097 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2098 | .rpc_call_done = nfs4_close_done, |
| 2099 | .rpc_release = nfs4_free_closedata, |
| 2100 | }; |
| 2101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | /* |
| 2103 | * It is possible for data to be read/written from a mem-mapped file |
| 2104 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2105 | * This means that we can't safely call nfsv4 close on a file until |
| 2106 | * the inode is cleared. This in turn means that we are not good |
| 2107 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2108 | * share state even when we are done with one of the three share |
| 2109 | * stateid's in the inode. |
| 2110 | * |
| 2111 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2112 | */ |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2113 | 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] | 2114 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2115 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2117 | struct nfs4_state_owner *sp = state->owner; |
| 2118 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2119 | struct rpc_message msg = { |
| 2120 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2121 | .rpc_cred = state->owner->so_cred, |
| 2122 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2123 | struct rpc_task_setup task_setup_data = { |
| 2124 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2125 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2126 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2127 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2128 | .flags = RPC_TASK_ASYNC, |
| 2129 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2130 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2132 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2134 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2135 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2136 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2138 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2139 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2141 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2142 | if (calldata->arg.seqid == NULL) |
| 2143 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2144 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2145 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2146 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2147 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2148 | calldata->res.server = server; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2149 | calldata->roc = roc; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2150 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2151 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2152 | msg.rpc_argp = &calldata->arg; |
| 2153 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2154 | task_setup_data.callback_data = calldata; |
| 2155 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2156 | if (IS_ERR(task)) |
| 2157 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2158 | status = 0; |
| 2159 | if (wait) |
| 2160 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2161 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2162 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2163 | out_free_calldata: |
| 2164 | kfree(calldata); |
| 2165 | out: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2166 | if (roc) |
| 2167 | pnfs_roc_release(state->inode); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2168 | nfs4_put_open_state(state); |
| 2169 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2170 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | } |
| 2172 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2173 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2174 | 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] | 2175 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | struct nfs4_state *state; |
| 2177 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2178 | /* Protect against concurrent sillydeletes */ |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2179 | 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] | 2180 | if (IS_ERR(state)) |
| 2181 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2182 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2183 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | } |
| 2185 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2186 | 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] | 2187 | { |
| 2188 | if (ctx->state == NULL) |
| 2189 | return; |
| 2190 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2191 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2192 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2193 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2194 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | |
| 2196 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2197 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2198 | struct nfs4_server_caps_arg args = { |
| 2199 | .fhandle = fhandle, |
| 2200 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | struct nfs4_server_caps_res res = {}; |
| 2202 | struct rpc_message msg = { |
| 2203 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2204 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | .rpc_resp = &res, |
| 2206 | }; |
| 2207 | int status; |
| 2208 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2209 | 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] | 2210 | if (status == 0) { |
| 2211 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2212 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2213 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2214 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2215 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2216 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2217 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2218 | server->caps |= NFS_CAP_ACLS; |
| 2219 | if (res.has_links != 0) |
| 2220 | server->caps |= NFS_CAP_HARDLINKS; |
| 2221 | if (res.has_symlinks != 0) |
| 2222 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2223 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2224 | server->caps |= NFS_CAP_FILEID; |
| 2225 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2226 | server->caps |= NFS_CAP_MODE; |
| 2227 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2228 | server->caps |= NFS_CAP_NLINK; |
| 2229 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2230 | server->caps |= NFS_CAP_OWNER; |
| 2231 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2232 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2233 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2234 | server->caps |= NFS_CAP_ATIME; |
| 2235 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2236 | server->caps |= NFS_CAP_CTIME; |
| 2237 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2238 | server->caps |= NFS_CAP_MTIME; |
| 2239 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2240 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2241 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2242 | 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] | 2243 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2244 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2247 | return status; |
| 2248 | } |
| 2249 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2250 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | { |
| 2252 | struct nfs4_exception exception = { }; |
| 2253 | int err; |
| 2254 | do { |
| 2255 | err = nfs4_handle_exception(server, |
| 2256 | _nfs4_server_capabilities(server, fhandle), |
| 2257 | &exception); |
| 2258 | } while (exception.retry); |
| 2259 | return err; |
| 2260 | } |
| 2261 | |
| 2262 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2263 | struct nfs_fsinfo *info) |
| 2264 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | struct nfs4_lookup_root_arg args = { |
| 2266 | .bitmask = nfs4_fattr_bitmap, |
| 2267 | }; |
| 2268 | struct nfs4_lookup_res res = { |
| 2269 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2270 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | .fh = fhandle, |
| 2272 | }; |
| 2273 | struct rpc_message msg = { |
| 2274 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2275 | .rpc_argp = &args, |
| 2276 | .rpc_resp = &res, |
| 2277 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2278 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2279 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2280 | 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] | 2281 | } |
| 2282 | |
| 2283 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2284 | struct nfs_fsinfo *info) |
| 2285 | { |
| 2286 | struct nfs4_exception exception = { }; |
| 2287 | int err; |
| 2288 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2289 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2290 | switch (err) { |
| 2291 | case 0: |
| 2292 | case -NFS4ERR_WRONGSEC: |
| 2293 | break; |
| 2294 | default: |
| 2295 | err = nfs4_handle_exception(server, err, &exception); |
| 2296 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | } while (exception.retry); |
| 2298 | return err; |
| 2299 | } |
| 2300 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2301 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2302 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2303 | { |
| 2304 | struct rpc_auth *auth; |
| 2305 | int ret; |
| 2306 | |
| 2307 | auth = rpcauth_create(flavor, server->client); |
| 2308 | if (!auth) { |
| 2309 | ret = -EIO; |
| 2310 | goto out; |
| 2311 | } |
| 2312 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2313 | out: |
| 2314 | return ret; |
| 2315 | } |
| 2316 | |
Bryan Schumaker | 801a16d | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2317 | 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] | 2318 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2319 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2320 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2321 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | |
Bryan Schumaker | 801a16d | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2323 | len = gss_mech_list_pseudoflavors(&flav_array[0]); |
| 2324 | flav_array[len] = RPC_AUTH_NULL; |
| 2325 | len += 1; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2326 | |
| 2327 | for (i = 0; i < len; i++) { |
| 2328 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2329 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2330 | continue; |
| 2331 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2332 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2333 | /* |
| 2334 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2335 | * to access the mount. It could also mean that we tried to mount |
| 2336 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2337 | * existing mount programs don't handle -EACCES very well so it should |
| 2338 | * be mapped to -EPERM instead. |
| 2339 | */ |
| 2340 | if (status == -EACCES) |
| 2341 | status = -EPERM; |
Bryan Schumaker | 801a16d | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2342 | return status; |
| 2343 | } |
| 2344 | |
| 2345 | /* |
| 2346 | * get the file handle for the "/" directory on the server |
| 2347 | */ |
| 2348 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2349 | struct nfs_fsinfo *info) |
| 2350 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2351 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16d | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2352 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2353 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2354 | /* |
| 2355 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2356 | * by nfs4_map_errors() as this function exits. |
| 2357 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2358 | 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] | 2359 | if (status == 0) |
| 2360 | status = nfs4_server_capabilities(server, fhandle); |
| 2361 | if (status == 0) |
| 2362 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2363 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | } |
| 2365 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2366 | /* |
| 2367 | * Get locations and (maybe) other attributes of a referral. |
| 2368 | * Note that we'll actually follow the referral later when |
| 2369 | * we detect fsid mismatch in inode revalidation |
| 2370 | */ |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2371 | static int nfs4_get_referral(struct inode *dir, const struct qstr *name, |
| 2372 | struct nfs_fattr *fattr, struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2373 | { |
| 2374 | int status = -ENOMEM; |
| 2375 | struct page *page = NULL; |
| 2376 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2377 | |
| 2378 | page = alloc_page(GFP_KERNEL); |
| 2379 | if (page == NULL) |
| 2380 | goto out; |
| 2381 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2382 | if (locations == NULL) |
| 2383 | goto out; |
| 2384 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 2385 | status = nfs4_proc_fs_locations(dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2386 | if (status != 0) |
| 2387 | goto out; |
| 2388 | /* Make sure server returned a different fsid for the referral */ |
| 2389 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2390 | dprintk("%s: server did not return a different fsid for" |
| 2391 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2392 | status = -EIO; |
| 2393 | goto out; |
| 2394 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2395 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2396 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2397 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2398 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2399 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2400 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2401 | out: |
| 2402 | if (page) |
| 2403 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2404 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2405 | return status; |
| 2406 | } |
| 2407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2409 | { |
| 2410 | struct nfs4_getattr_arg args = { |
| 2411 | .fh = fhandle, |
| 2412 | .bitmask = server->attr_bitmask, |
| 2413 | }; |
| 2414 | struct nfs4_getattr_res res = { |
| 2415 | .fattr = fattr, |
| 2416 | .server = server, |
| 2417 | }; |
| 2418 | struct rpc_message msg = { |
| 2419 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2420 | .rpc_argp = &args, |
| 2421 | .rpc_resp = &res, |
| 2422 | }; |
| 2423 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2424 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2425 | 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] | 2426 | } |
| 2427 | |
| 2428 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2429 | { |
| 2430 | struct nfs4_exception exception = { }; |
| 2431 | int err; |
| 2432 | do { |
| 2433 | err = nfs4_handle_exception(server, |
| 2434 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2435 | &exception); |
| 2436 | } while (exception.retry); |
| 2437 | return err; |
| 2438 | } |
| 2439 | |
| 2440 | /* |
| 2441 | * The file is not closed if it is opened due to the a request to change |
| 2442 | * the size of the file. The open call will not be needed once the |
| 2443 | * VFS layer lookup-intents are implemented. |
| 2444 | * |
| 2445 | * Close is called when the inode is destroyed. |
| 2446 | * If we haven't opened the file for O_WRONLY, we |
| 2447 | * need to in the size_change case to obtain a stateid. |
| 2448 | * |
| 2449 | * Got race? |
| 2450 | * Because OPEN is always done by name in nfsv4, it is |
| 2451 | * possible that we opened a different file by the same |
| 2452 | * name. We can recognize this race condition, but we |
| 2453 | * can't do anything about it besides returning an error. |
| 2454 | * |
| 2455 | * This will be fixed with VFS changes (lookup-intent). |
| 2456 | */ |
| 2457 | static int |
| 2458 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2459 | struct iattr *sattr) |
| 2460 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2461 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2462 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2463 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | int status; |
| 2465 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2466 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2467 | pnfs_return_layout(inode); |
| 2468 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2469 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2471 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2472 | if (sattr->ia_valid & ATTR_FILE) { |
| 2473 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2474 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2475 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2476 | if (ctx) { |
| 2477 | cred = ctx->cred; |
| 2478 | state = ctx->state; |
| 2479 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2480 | } |
| 2481 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 2482 | /* Deal with open(O_TRUNC) */ |
| 2483 | if (sattr->ia_valid & ATTR_OPEN) |
| 2484 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2485 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2486 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2487 | if (status == 0) |
| 2488 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | return status; |
| 2490 | } |
| 2491 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2492 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2493 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2494 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2495 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2496 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2497 | int status; |
| 2498 | struct nfs4_lookup_arg args = { |
| 2499 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2500 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2501 | .name = name, |
| 2502 | }; |
| 2503 | struct nfs4_lookup_res res = { |
| 2504 | .server = server, |
| 2505 | .fattr = fattr, |
| 2506 | .fh = fhandle, |
| 2507 | }; |
| 2508 | struct rpc_message msg = { |
| 2509 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2510 | .rpc_argp = &args, |
| 2511 | .rpc_resp = &res, |
| 2512 | }; |
| 2513 | |
| 2514 | nfs_fattr_init(fattr); |
| 2515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2516 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2517 | 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] | 2518 | dprintk("NFS reply lookup: %d\n", status); |
| 2519 | return status; |
| 2520 | } |
| 2521 | |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2522 | void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr, struct nfs_fh *fh) |
| 2523 | { |
| 2524 | memset(fh, 0, sizeof(struct nfs_fh)); |
| 2525 | fattr->fsid.major = 1; |
| 2526 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 2527 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_FSID | NFS_ATTR_FATTR_MOUNTPOINT; |
| 2528 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2529 | fattr->nlink = 2; |
| 2530 | } |
| 2531 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2532 | static int nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, struct qstr *name, |
| 2533 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | { |
| 2535 | struct nfs4_exception exception = { }; |
| 2536 | int err; |
| 2537 | do { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2538 | int status; |
| 2539 | |
| 2540 | status = _nfs4_proc_lookup(clnt, dir, name, fhandle, fattr); |
| 2541 | switch (status) { |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2542 | case -NFS4ERR_BADNAME: |
| 2543 | return -ENOENT; |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2544 | case -NFS4ERR_MOVED: |
Trond Myklebust | a6f498a | 2011-11-07 15:50:32 -0500 | [diff] [blame] | 2545 | return nfs4_get_referral(dir, name, fattr, fhandle); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2546 | case -NFS4ERR_WRONGSEC: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2547 | nfs_fixup_secinfo_attributes(fattr, fhandle); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2548 | } |
| 2549 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2550 | status, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2551 | } while (exception.retry); |
| 2552 | return err; |
| 2553 | } |
| 2554 | |
| 2555 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2556 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2557 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | struct nfs4_accessargs args = { |
| 2559 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2560 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2562 | struct nfs4_accessres res = { |
| 2563 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2564 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2565 | struct rpc_message msg = { |
| 2566 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2567 | .rpc_argp = &args, |
| 2568 | .rpc_resp = &res, |
| 2569 | .rpc_cred = entry->cred, |
| 2570 | }; |
| 2571 | int mode = entry->mask; |
| 2572 | int status; |
| 2573 | |
| 2574 | /* |
| 2575 | * Determine which access bits we want to ask for... |
| 2576 | */ |
| 2577 | if (mode & MAY_READ) |
| 2578 | args.access |= NFS4_ACCESS_READ; |
| 2579 | if (S_ISDIR(inode->i_mode)) { |
| 2580 | if (mode & MAY_WRITE) |
| 2581 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2582 | if (mode & MAY_EXEC) |
| 2583 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2584 | } else { |
| 2585 | if (mode & MAY_WRITE) |
| 2586 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2587 | if (mode & MAY_EXEC) |
| 2588 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2589 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2590 | |
| 2591 | res.fattr = nfs_alloc_fattr(); |
| 2592 | if (res.fattr == NULL) |
| 2593 | return -ENOMEM; |
| 2594 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2595 | 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] | 2596 | if (!status) { |
| 2597 | entry->mask = 0; |
| 2598 | if (res.access & NFS4_ACCESS_READ) |
| 2599 | entry->mask |= MAY_READ; |
| 2600 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2601 | entry->mask |= MAY_WRITE; |
| 2602 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2603 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2604 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2605 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2606 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | return status; |
| 2608 | } |
| 2609 | |
| 2610 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2611 | { |
| 2612 | struct nfs4_exception exception = { }; |
| 2613 | int err; |
| 2614 | do { |
| 2615 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2616 | _nfs4_proc_access(inode, entry), |
| 2617 | &exception); |
| 2618 | } while (exception.retry); |
| 2619 | return err; |
| 2620 | } |
| 2621 | |
| 2622 | /* |
| 2623 | * TODO: For the time being, we don't try to get any attributes |
| 2624 | * along with any of the zero-copy operations READ, READDIR, |
| 2625 | * READLINK, WRITE. |
| 2626 | * |
| 2627 | * In the case of the first three, we want to put the GETATTR |
| 2628 | * after the read-type operation -- this is because it is hard |
| 2629 | * to predict the length of a GETATTR response in v4, and thus |
| 2630 | * align the READ data correctly. This means that the GETATTR |
| 2631 | * may end up partially falling into the page cache, and we should |
| 2632 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2633 | * To do this efficiently, we need to know the total length |
| 2634 | * of data received, which doesn't seem to be available outside |
| 2635 | * of the RPC layer. |
| 2636 | * |
| 2637 | * In the case of WRITE, we also want to put the GETATTR after |
| 2638 | * the operation -- in this case because we want to make sure |
| 2639 | * we get the post-operation mtime and size. This means that |
| 2640 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2641 | * of it which would leave room in the 'tail' iovec. |
| 2642 | * |
| 2643 | * Both of these changes to the XDR layer would in fact be quite |
| 2644 | * minor, but I decided to leave them for a subsequent patch. |
| 2645 | */ |
| 2646 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2647 | unsigned int pgbase, unsigned int pglen) |
| 2648 | { |
| 2649 | struct nfs4_readlink args = { |
| 2650 | .fh = NFS_FH(inode), |
| 2651 | .pgbase = pgbase, |
| 2652 | .pglen = pglen, |
| 2653 | .pages = &page, |
| 2654 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2655 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | struct rpc_message msg = { |
| 2657 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2658 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2659 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | }; |
| 2661 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2662 | 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] | 2663 | } |
| 2664 | |
| 2665 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2666 | unsigned int pgbase, unsigned int pglen) |
| 2667 | { |
| 2668 | struct nfs4_exception exception = { }; |
| 2669 | int err; |
| 2670 | do { |
| 2671 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2672 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2673 | &exception); |
| 2674 | } while (exception.retry); |
| 2675 | return err; |
| 2676 | } |
| 2677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | /* |
| 2679 | * Got race? |
| 2680 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2681 | * Until then, this create/open method is prone to inefficiency and race |
| 2682 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2683 | * placed on the wire. |
| 2684 | * |
| 2685 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2686 | * The file will be opened again in the subsequent VFS open call |
| 2687 | * (nfs4_proc_file_open). |
| 2688 | * |
| 2689 | * The open for read will just hang around to be used by any process that |
| 2690 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2691 | */ |
| 2692 | |
| 2693 | static int |
| 2694 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2695 | int flags, struct nfs_open_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2696 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2697 | struct dentry *de = dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2698 | struct nfs4_state *state; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2699 | struct rpc_cred *cred = NULL; |
| 2700 | fmode_t fmode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | int status = 0; |
| 2702 | |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2703 | if (ctx != NULL) { |
| 2704 | cred = ctx->cred; |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2705 | de = ctx->dentry; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2706 | fmode = ctx->mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | } |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2708 | sattr->ia_mode &= ~current_umask(); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2709 | state = nfs4_do_open(dir, de, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2710 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2711 | if (IS_ERR(state)) { |
| 2712 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2713 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2715 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2716 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2717 | if (ctx != NULL) |
| 2718 | ctx->state = state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2719 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2720 | nfs4_close_sync(state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2721 | out: |
| 2722 | return status; |
| 2723 | } |
| 2724 | |
| 2725 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2726 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2727 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2728 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2729 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2730 | .name.len = name->len, |
| 2731 | .name.name = name->name, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2732 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2733 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2734 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2735 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2736 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2738 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2739 | .rpc_argp = &args, |
| 2740 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | }; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2742 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2743 | |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2744 | res.dir_attr = nfs_alloc_fattr(); |
| 2745 | if (res.dir_attr == NULL) |
| 2746 | goto out; |
| 2747 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2748 | 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] | 2749 | if (status == 0) { |
| 2750 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2751 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2752 | } |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2753 | nfs_free_fattr(res.dir_attr); |
| 2754 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2755 | return status; |
| 2756 | } |
| 2757 | |
| 2758 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2759 | { |
| 2760 | struct nfs4_exception exception = { }; |
| 2761 | int err; |
| 2762 | do { |
| 2763 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2764 | _nfs4_proc_remove(dir, name), |
| 2765 | &exception); |
| 2766 | } while (exception.retry); |
| 2767 | return err; |
| 2768 | } |
| 2769 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2770 | 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] | 2771 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2772 | struct nfs_server *server = NFS_SERVER(dir); |
| 2773 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2774 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2776 | args->bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2777 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2778 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2779 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | } |
| 2781 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2782 | 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] | 2783 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2784 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2785 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2786 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2787 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2788 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2789 | return 0; |
| 2790 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2791 | nfs_post_op_update_inode(dir, res->dir_attr); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2792 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2793 | } |
| 2794 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2795 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2796 | { |
| 2797 | struct nfs_server *server = NFS_SERVER(dir); |
| 2798 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2799 | struct nfs_renameres *res = msg->rpc_resp; |
| 2800 | |
| 2801 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
| 2802 | arg->bitmask = server->attr_bitmask; |
| 2803 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2804 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2805 | } |
| 2806 | |
| 2807 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2808 | struct inode *new_dir) |
| 2809 | { |
| 2810 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2811 | |
| 2812 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2813 | return 0; |
| 2814 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2815 | return 0; |
| 2816 | |
| 2817 | update_changeattr(old_dir, &res->old_cinfo); |
| 2818 | nfs_post_op_update_inode(old_dir, res->old_fattr); |
| 2819 | update_changeattr(new_dir, &res->new_cinfo); |
| 2820 | nfs_post_op_update_inode(new_dir, res->new_fattr); |
| 2821 | return 1; |
| 2822 | } |
| 2823 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2825 | struct inode *new_dir, struct qstr *new_name) |
| 2826 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2827 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2828 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | .old_dir = NFS_FH(old_dir), |
| 2830 | .new_dir = NFS_FH(new_dir), |
| 2831 | .old_name = old_name, |
| 2832 | .new_name = new_name, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2833 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2835 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2836 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2837 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2838 | struct rpc_message msg = { |
| 2839 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2840 | .rpc_argp = &arg, |
| 2841 | .rpc_resp = &res, |
| 2842 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2843 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2845 | res.old_fattr = nfs_alloc_fattr(); |
| 2846 | res.new_fattr = nfs_alloc_fattr(); |
| 2847 | if (res.old_fattr == NULL || res.new_fattr == NULL) |
| 2848 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2849 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2850 | 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] | 2851 | if (!status) { |
| 2852 | update_changeattr(old_dir, &res.old_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2853 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | update_changeattr(new_dir, &res.new_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2855 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2856 | } |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2857 | out: |
| 2858 | nfs_free_fattr(res.new_fattr); |
| 2859 | nfs_free_fattr(res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2860 | return status; |
| 2861 | } |
| 2862 | |
| 2863 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2864 | struct inode *new_dir, struct qstr *new_name) |
| 2865 | { |
| 2866 | struct nfs4_exception exception = { }; |
| 2867 | int err; |
| 2868 | do { |
| 2869 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2870 | _nfs4_proc_rename(old_dir, old_name, |
| 2871 | new_dir, new_name), |
| 2872 | &exception); |
| 2873 | } while (exception.retry); |
| 2874 | return err; |
| 2875 | } |
| 2876 | |
| 2877 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2878 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2879 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2880 | struct nfs4_link_arg arg = { |
| 2881 | .fh = NFS_FH(inode), |
| 2882 | .dir_fh = NFS_FH(dir), |
| 2883 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2884 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2885 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2886 | struct nfs4_link_res res = { |
| 2887 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2888 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | struct rpc_message msg = { |
| 2890 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2891 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2892 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2894 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2896 | res.fattr = nfs_alloc_fattr(); |
| 2897 | res.dir_attr = nfs_alloc_fattr(); |
| 2898 | if (res.fattr == NULL || res.dir_attr == NULL) |
| 2899 | goto out; |
| 2900 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2901 | 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] | 2902 | if (!status) { |
| 2903 | update_changeattr(dir, &res.cinfo); |
| 2904 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2905 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2906 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2907 | out: |
| 2908 | nfs_free_fattr(res.dir_attr); |
| 2909 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2910 | return status; |
| 2911 | } |
| 2912 | |
| 2913 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2914 | { |
| 2915 | struct nfs4_exception exception = { }; |
| 2916 | int err; |
| 2917 | do { |
| 2918 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2919 | _nfs4_proc_link(inode, dir, name), |
| 2920 | &exception); |
| 2921 | } while (exception.retry); |
| 2922 | return err; |
| 2923 | } |
| 2924 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2925 | struct nfs4_createdata { |
| 2926 | struct rpc_message msg; |
| 2927 | struct nfs4_create_arg arg; |
| 2928 | struct nfs4_create_res res; |
| 2929 | struct nfs_fh fh; |
| 2930 | struct nfs_fattr fattr; |
| 2931 | struct nfs_fattr dir_fattr; |
| 2932 | }; |
| 2933 | |
| 2934 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 2935 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 2936 | { |
| 2937 | struct nfs4_createdata *data; |
| 2938 | |
| 2939 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2940 | if (data != NULL) { |
| 2941 | struct nfs_server *server = NFS_SERVER(dir); |
| 2942 | |
| 2943 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 2944 | data->msg.rpc_argp = &data->arg; |
| 2945 | data->msg.rpc_resp = &data->res; |
| 2946 | data->arg.dir_fh = NFS_FH(dir); |
| 2947 | data->arg.server = server; |
| 2948 | data->arg.name = name; |
| 2949 | data->arg.attrs = sattr; |
| 2950 | data->arg.ftype = ftype; |
| 2951 | data->arg.bitmask = server->attr_bitmask; |
| 2952 | data->res.server = server; |
| 2953 | data->res.fh = &data->fh; |
| 2954 | data->res.fattr = &data->fattr; |
| 2955 | data->res.dir_fattr = &data->dir_fattr; |
| 2956 | nfs_fattr_init(data->res.fattr); |
| 2957 | nfs_fattr_init(data->res.dir_fattr); |
| 2958 | } |
| 2959 | return data; |
| 2960 | } |
| 2961 | |
| 2962 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 2963 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2964 | 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] | 2965 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2966 | if (status == 0) { |
| 2967 | update_changeattr(dir, &data->res.dir_cinfo); |
| 2968 | nfs_post_op_update_inode(dir, data->res.dir_fattr); |
| 2969 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 2970 | } |
| 2971 | return status; |
| 2972 | } |
| 2973 | |
| 2974 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 2975 | { |
| 2976 | kfree(data); |
| 2977 | } |
| 2978 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2979 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2980 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2981 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2982 | struct nfs4_createdata *data; |
| 2983 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2985 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2986 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2987 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2988 | status = -ENOMEM; |
| 2989 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 2990 | if (data == NULL) |
| 2991 | goto out; |
| 2992 | |
| 2993 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 2994 | data->arg.u.symlink.pages = &page; |
| 2995 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2996 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2997 | status = nfs4_do_create(dir, dentry, data); |
| 2998 | |
| 2999 | nfs4_free_createdata(data); |
| 3000 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | return status; |
| 3002 | } |
| 3003 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3004 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3005 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | { |
| 3007 | struct nfs4_exception exception = { }; |
| 3008 | int err; |
| 3009 | do { |
| 3010 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3011 | _nfs4_proc_symlink(dir, dentry, page, |
| 3012 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | &exception); |
| 3014 | } while (exception.retry); |
| 3015 | return err; |
| 3016 | } |
| 3017 | |
| 3018 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3019 | struct iattr *sattr) |
| 3020 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3021 | struct nfs4_createdata *data; |
| 3022 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3023 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3024 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3025 | if (data == NULL) |
| 3026 | goto out; |
| 3027 | |
| 3028 | status = nfs4_do_create(dir, dentry, data); |
| 3029 | |
| 3030 | nfs4_free_createdata(data); |
| 3031 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | return status; |
| 3033 | } |
| 3034 | |
| 3035 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3036 | struct iattr *sattr) |
| 3037 | { |
| 3038 | struct nfs4_exception exception = { }; |
| 3039 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3040 | |
| 3041 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | do { |
| 3043 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3044 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3045 | &exception); |
| 3046 | } while (exception.retry); |
| 3047 | return err; |
| 3048 | } |
| 3049 | |
| 3050 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3051 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | { |
| 3053 | struct inode *dir = dentry->d_inode; |
| 3054 | struct nfs4_readdir_arg args = { |
| 3055 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3056 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3057 | .pgbase = 0, |
| 3058 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3059 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3060 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | }; |
| 3062 | struct nfs4_readdir_res res; |
| 3063 | struct rpc_message msg = { |
| 3064 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3065 | .rpc_argp = &args, |
| 3066 | .rpc_resp = &res, |
| 3067 | .rpc_cred = cred, |
| 3068 | }; |
| 3069 | int status; |
| 3070 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3071 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3072 | dentry->d_parent->d_name.name, |
| 3073 | dentry->d_name.name, |
| 3074 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3075 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 3076 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3077 | 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] | 3078 | if (status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3080 | status += args.pgbase; |
| 3081 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3082 | |
| 3083 | nfs_invalidate_atime(dir); |
| 3084 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3085 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3086 | return status; |
| 3087 | } |
| 3088 | |
| 3089 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3090 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | { |
| 3092 | struct nfs4_exception exception = { }; |
| 3093 | int err; |
| 3094 | do { |
| 3095 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3096 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3097 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3098 | &exception); |
| 3099 | } while (exception.retry); |
| 3100 | return err; |
| 3101 | } |
| 3102 | |
| 3103 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3104 | struct iattr *sattr, dev_t rdev) |
| 3105 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3106 | struct nfs4_createdata *data; |
| 3107 | int mode = sattr->ia_mode; |
| 3108 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3109 | |
| 3110 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 3111 | 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] | 3112 | |
| 3113 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3114 | if (data == NULL) |
| 3115 | goto out; |
| 3116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3117 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3118 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3120 | data->arg.ftype = NF4BLK; |
| 3121 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3122 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3123 | } |
| 3124 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3125 | data->arg.ftype = NF4CHR; |
| 3126 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3127 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3128 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3130 | status = nfs4_do_create(dir, dentry, data); |
| 3131 | |
| 3132 | nfs4_free_createdata(data); |
| 3133 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | return status; |
| 3135 | } |
| 3136 | |
| 3137 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3138 | struct iattr *sattr, dev_t rdev) |
| 3139 | { |
| 3140 | struct nfs4_exception exception = { }; |
| 3141 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3142 | |
| 3143 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3144 | do { |
| 3145 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3146 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3147 | &exception); |
| 3148 | } while (exception.retry); |
| 3149 | return err; |
| 3150 | } |
| 3151 | |
| 3152 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3153 | struct nfs_fsstat *fsstat) |
| 3154 | { |
| 3155 | struct nfs4_statfs_arg args = { |
| 3156 | .fh = fhandle, |
| 3157 | .bitmask = server->attr_bitmask, |
| 3158 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3159 | struct nfs4_statfs_res res = { |
| 3160 | .fsstat = fsstat, |
| 3161 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3162 | struct rpc_message msg = { |
| 3163 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3164 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3165 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | }; |
| 3167 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3168 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3169 | 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] | 3170 | } |
| 3171 | |
| 3172 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3173 | { |
| 3174 | struct nfs4_exception exception = { }; |
| 3175 | int err; |
| 3176 | do { |
| 3177 | err = nfs4_handle_exception(server, |
| 3178 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3179 | &exception); |
| 3180 | } while (exception.retry); |
| 3181 | return err; |
| 3182 | } |
| 3183 | |
| 3184 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3185 | struct nfs_fsinfo *fsinfo) |
| 3186 | { |
| 3187 | struct nfs4_fsinfo_arg args = { |
| 3188 | .fh = fhandle, |
| 3189 | .bitmask = server->attr_bitmask, |
| 3190 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3191 | struct nfs4_fsinfo_res res = { |
| 3192 | .fsinfo = fsinfo, |
| 3193 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3194 | struct rpc_message msg = { |
| 3195 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3196 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3197 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | }; |
| 3199 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3200 | 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] | 3201 | } |
| 3202 | |
| 3203 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3204 | { |
| 3205 | struct nfs4_exception exception = { }; |
| 3206 | int err; |
| 3207 | |
| 3208 | do { |
| 3209 | err = nfs4_handle_exception(server, |
| 3210 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3211 | &exception); |
| 3212 | } while (exception.retry); |
| 3213 | return err; |
| 3214 | } |
| 3215 | |
| 3216 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3217 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3218 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3220 | } |
| 3221 | |
| 3222 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3223 | struct nfs_pathconf *pathconf) |
| 3224 | { |
| 3225 | struct nfs4_pathconf_arg args = { |
| 3226 | .fh = fhandle, |
| 3227 | .bitmask = server->attr_bitmask, |
| 3228 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3229 | struct nfs4_pathconf_res res = { |
| 3230 | .pathconf = pathconf, |
| 3231 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | struct rpc_message msg = { |
| 3233 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3234 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3235 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | }; |
| 3237 | |
| 3238 | /* None of the pathconf attributes are mandatory to implement */ |
| 3239 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3240 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3241 | return 0; |
| 3242 | } |
| 3243 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3244 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3245 | 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] | 3246 | } |
| 3247 | |
| 3248 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3249 | struct nfs_pathconf *pathconf) |
| 3250 | { |
| 3251 | struct nfs4_exception exception = { }; |
| 3252 | int err; |
| 3253 | |
| 3254 | do { |
| 3255 | err = nfs4_handle_exception(server, |
| 3256 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3257 | &exception); |
| 3258 | } while (exception.retry); |
| 3259 | return err; |
| 3260 | } |
| 3261 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3262 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3263 | { |
| 3264 | nfs_invalidate_atime(data->inode); |
| 3265 | } |
| 3266 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3267 | 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] | 3268 | { |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3269 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3271 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3272 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3273 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3275 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3276 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3277 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3278 | renew_lease(server, data->timestamp); |
| 3279 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3280 | } |
| 3281 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3282 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3283 | { |
| 3284 | |
| 3285 | dprintk("--> %s\n", __func__); |
| 3286 | |
| 3287 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3288 | return -EAGAIN; |
| 3289 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3290 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3291 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3292 | } |
| 3293 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3294 | 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] | 3295 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3297 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3298 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3299 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3300 | } |
| 3301 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame^] | 3302 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3303 | { |
| 3304 | if (nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3305 | &data->args.seq_args, |
| 3306 | &data->res.seq_res, |
| 3307 | task)) |
| 3308 | return; |
| 3309 | rpc_call_start(task); |
| 3310 | } |
| 3311 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3312 | /* Reset the the nfs_read_data to send the read to the MDS. */ |
| 3313 | void nfs4_reset_read(struct rpc_task *task, struct nfs_read_data *data) |
| 3314 | { |
| 3315 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3316 | put_lseg(data->lseg); |
| 3317 | data->lseg = NULL; |
| 3318 | /* offsets will differ in the dense stripe case */ |
| 3319 | data->args.offset = data->mds_offset; |
| 3320 | data->ds_clp = NULL; |
| 3321 | data->args.fh = NFS_FH(data->inode); |
| 3322 | data->read_done_cb = nfs4_read_done_cb; |
| 3323 | task->tk_ops = data->mds_ops; |
| 3324 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3325 | } |
| 3326 | EXPORT_SYMBOL_GPL(nfs4_reset_read); |
| 3327 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3328 | 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] | 3329 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | struct inode *inode = data->inode; |
| 3331 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3332 | 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] | 3333 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3334 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3335 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3336 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3337 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 3338 | nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3339 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3340 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3341 | } |
| 3342 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3343 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3344 | { |
| 3345 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3346 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3347 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3348 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3349 | } |
| 3350 | |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3351 | /* Reset the the nfs_write_data to send the write to the MDS. */ |
| 3352 | void nfs4_reset_write(struct rpc_task *task, struct nfs_write_data *data) |
| 3353 | { |
| 3354 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3355 | put_lseg(data->lseg); |
| 3356 | data->lseg = NULL; |
| 3357 | data->ds_clp = NULL; |
| 3358 | data->write_done_cb = nfs4_write_done_cb; |
| 3359 | data->args.fh = NFS_FH(data->inode); |
| 3360 | data->args.bitmask = data->res.server->cache_consistency_bitmask; |
| 3361 | data->args.offset = data->mds_offset; |
| 3362 | data->res.fattr = &data->fattr; |
| 3363 | task->tk_ops = data->mds_ops; |
| 3364 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3365 | } |
| 3366 | EXPORT_SYMBOL_GPL(nfs4_reset_write); |
| 3367 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3368 | 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] | 3369 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3370 | struct nfs_server *server = NFS_SERVER(data->inode); |
| 3371 | |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3372 | if (data->lseg) { |
| 3373 | data->args.bitmask = NULL; |
| 3374 | data->res.fattr = NULL; |
| 3375 | } else |
| 3376 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3377 | if (!data->write_done_cb) |
| 3378 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3379 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3380 | data->timestamp = jiffies; |
| 3381 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3382 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3383 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3384 | } |
| 3385 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3386 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3387 | { |
| 3388 | if (nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3389 | &data->args.seq_args, |
| 3390 | &data->res.seq_res, |
| 3391 | task)) |
| 3392 | return; |
| 3393 | rpc_call_start(task); |
| 3394 | } |
| 3395 | |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3396 | 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] | 3397 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3398 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3399 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3400 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3401 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3402 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3403 | } |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 3404 | nfs_refresh_inode(inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3405 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3406 | } |
| 3407 | |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3408 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3409 | { |
| 3410 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3411 | return -EAGAIN; |
| 3412 | return data->write_done_cb(task, data); |
| 3413 | } |
| 3414 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3415 | 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] | 3416 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3417 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3418 | |
| 3419 | if (data->lseg) { |
| 3420 | data->args.bitmask = NULL; |
| 3421 | data->res.fattr = NULL; |
| 3422 | } else |
| 3423 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3424 | if (!data->write_done_cb) |
| 3425 | data->write_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3426 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3427 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3428 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3429 | } |
| 3430 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3431 | struct nfs4_renewdata { |
| 3432 | struct nfs_client *client; |
| 3433 | unsigned long timestamp; |
| 3434 | }; |
| 3435 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3436 | /* |
| 3437 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3438 | * standalone procedure for queueing an asynchronous RENEW. |
| 3439 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3440 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3441 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3442 | struct nfs4_renewdata *data = calldata; |
| 3443 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3444 | |
Alexandros Batsakis | 0851de0 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3445 | if (atomic_read(&clp->cl_count) > 1) |
| 3446 | nfs4_schedule_state_renewal(clp); |
| 3447 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3448 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3449 | } |
| 3450 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3451 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3452 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3453 | struct nfs4_renewdata *data = calldata; |
| 3454 | struct nfs_client *clp = data->client; |
| 3455 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3456 | |
| 3457 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3458 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3459 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3460 | return; |
| 3461 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3462 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3463 | return; |
| 3464 | } |
| 3465 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3467 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3468 | } |
| 3469 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3470 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3471 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3472 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3473 | }; |
| 3474 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3475 | 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] | 3476 | { |
| 3477 | struct rpc_message msg = { |
| 3478 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3479 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3480 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3481 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3482 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3483 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3484 | if (renew_flags == 0) |
| 3485 | return 0; |
Alexandros Batsakis | 0851de0 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3486 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3487 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3488 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3489 | if (data == NULL) |
| 3490 | return -ENOMEM; |
| 3491 | data->client = clp; |
| 3492 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3493 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3494 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3495 | } |
| 3496 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3497 | 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] | 3498 | { |
| 3499 | struct rpc_message msg = { |
| 3500 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3501 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3502 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3503 | }; |
| 3504 | unsigned long now = jiffies; |
| 3505 | int status; |
| 3506 | |
| 3507 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3508 | if (status < 0) |
| 3509 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3510 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3511 | return 0; |
| 3512 | } |
| 3513 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3514 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3515 | { |
| 3516 | return (server->caps & NFS_CAP_ACLS) |
| 3517 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3518 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3519 | } |
| 3520 | |
| 3521 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3522 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3523 | * the stack. |
| 3524 | */ |
| 3525 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3526 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3527 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3528 | struct page **pages, unsigned int *pgbase) |
| 3529 | { |
| 3530 | struct page *newpage, **spages; |
| 3531 | int rc = 0; |
| 3532 | size_t len; |
| 3533 | spages = pages; |
| 3534 | |
| 3535 | do { |
Jovi Zhang | 43b7c3f | 2011-03-02 23:19:37 +0000 | [diff] [blame] | 3536 | len = min_t(size_t, PAGE_CACHE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3537 | newpage = alloc_page(GFP_KERNEL); |
| 3538 | |
| 3539 | if (newpage == NULL) |
| 3540 | goto unwind; |
| 3541 | memcpy(page_address(newpage), buf, len); |
| 3542 | buf += len; |
| 3543 | buflen -= len; |
| 3544 | *pages++ = newpage; |
| 3545 | rc++; |
| 3546 | } while (buflen != 0); |
| 3547 | |
| 3548 | return rc; |
| 3549 | |
| 3550 | unwind: |
| 3551 | for(; rc > 0; rc--) |
| 3552 | __free_page(spages[rc-1]); |
| 3553 | return -ENOMEM; |
| 3554 | } |
| 3555 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3556 | struct nfs4_cached_acl { |
| 3557 | int cached; |
| 3558 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3559 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3560 | }; |
| 3561 | |
| 3562 | 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] | 3563 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3564 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3565 | |
| 3566 | spin_lock(&inode->i_lock); |
| 3567 | kfree(nfsi->nfs4_acl); |
| 3568 | nfsi->nfs4_acl = acl; |
| 3569 | spin_unlock(&inode->i_lock); |
| 3570 | } |
| 3571 | |
| 3572 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3573 | { |
| 3574 | nfs4_set_cached_acl(inode, NULL); |
| 3575 | } |
| 3576 | |
| 3577 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3578 | { |
| 3579 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3580 | struct nfs4_cached_acl *acl; |
| 3581 | int ret = -ENOENT; |
| 3582 | |
| 3583 | spin_lock(&inode->i_lock); |
| 3584 | acl = nfsi->nfs4_acl; |
| 3585 | if (acl == NULL) |
| 3586 | goto out; |
| 3587 | if (buf == NULL) /* user is just asking for length */ |
| 3588 | goto out_len; |
| 3589 | if (acl->cached == 0) |
| 3590 | goto out; |
| 3591 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3592 | if (acl->len > buflen) |
| 3593 | goto out; |
| 3594 | memcpy(buf, acl->data, acl->len); |
| 3595 | out_len: |
| 3596 | ret = acl->len; |
| 3597 | out: |
| 3598 | spin_unlock(&inode->i_lock); |
| 3599 | return ret; |
| 3600 | } |
| 3601 | |
| 3602 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) |
| 3603 | { |
| 3604 | struct nfs4_cached_acl *acl; |
| 3605 | |
| 3606 | if (buf && acl_len <= PAGE_SIZE) { |
| 3607 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3608 | if (acl == NULL) |
| 3609 | goto out; |
| 3610 | acl->cached = 1; |
| 3611 | memcpy(acl->data, buf, acl_len); |
| 3612 | } else { |
| 3613 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3614 | if (acl == NULL) |
| 3615 | goto out; |
| 3616 | acl->cached = 0; |
| 3617 | } |
| 3618 | acl->len = acl_len; |
| 3619 | out: |
| 3620 | nfs4_set_cached_acl(inode, acl); |
| 3621 | } |
| 3622 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3623 | /* |
| 3624 | * The getxattr API returns the required buffer length when called with a |
| 3625 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3626 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3627 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3628 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3629 | * the cache. If not so, we throw away the page, and cache the required |
| 3630 | * length. The next getxattr call will then produce another round trip to |
| 3631 | * the server, this time with the input buf of the required size. |
| 3632 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3633 | 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] | 3634 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3635 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3636 | struct nfs_getaclargs args = { |
| 3637 | .fh = NFS_FH(inode), |
| 3638 | .acl_pages = pages, |
| 3639 | .acl_len = buflen, |
| 3640 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3641 | struct nfs_getaclres res = { |
| 3642 | .acl_len = buflen, |
| 3643 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3644 | void *resp_buf; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3645 | struct rpc_message msg = { |
| 3646 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3647 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3648 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3649 | }; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3650 | int ret = -ENOMEM, npages, i, acl_len = 0; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3651 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3652 | npages = (buflen + PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 3653 | /* As long as we're doing a round trip to the server anyway, |
| 3654 | * let's be prepared for a page of acl data. */ |
| 3655 | if (npages == 0) |
| 3656 | npages = 1; |
| 3657 | |
| 3658 | for (i = 0; i < npages; i++) { |
| 3659 | pages[i] = alloc_page(GFP_KERNEL); |
| 3660 | if (!pages[i]) |
| 3661 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3662 | } |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3663 | if (npages > 1) { |
| 3664 | /* for decoding across pages */ |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 3665 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 3666 | if (!res.acl_scratch) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3667 | goto out_free; |
| 3668 | } |
| 3669 | args.acl_len = npages * PAGE_SIZE; |
| 3670 | args.acl_pgbase = 0; |
| 3671 | /* Let decode_getfacl know not to fail if the ACL data is larger than |
| 3672 | * the page we send as a guess */ |
| 3673 | if (buf == NULL) |
| 3674 | res.acl_flags |= NFS4_ACL_LEN_REQUEST; |
| 3675 | resp_buf = page_address(pages[0]); |
| 3676 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3677 | 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] | 3678 | __func__, buf, buflen, npages, args.acl_len); |
| 3679 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 3680 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3681 | if (ret) |
| 3682 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3683 | |
| 3684 | acl_len = res.acl_len - res.acl_data_offset; |
| 3685 | if (acl_len > args.acl_len) |
| 3686 | nfs4_write_cached_acl(inode, NULL, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3687 | else |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3688 | nfs4_write_cached_acl(inode, resp_buf + res.acl_data_offset, |
| 3689 | acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3690 | if (buf) { |
| 3691 | ret = -ERANGE; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3692 | if (acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3693 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3694 | _copy_from_pages(buf, pages, res.acl_data_offset, |
| 3695 | res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3696 | } |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3697 | ret = acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3698 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3699 | for (i = 0; i < npages; i++) |
| 3700 | if (pages[i]) |
| 3701 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 3702 | if (res.acl_scratch) |
| 3703 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3704 | return ret; |
| 3705 | } |
| 3706 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3707 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3708 | { |
| 3709 | struct nfs4_exception exception = { }; |
| 3710 | ssize_t ret; |
| 3711 | do { |
| 3712 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3713 | if (ret >= 0) |
| 3714 | break; |
| 3715 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3716 | } while (exception.retry); |
| 3717 | return ret; |
| 3718 | } |
| 3719 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3720 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3721 | { |
| 3722 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3723 | int ret; |
| 3724 | |
| 3725 | if (!nfs4_server_supports_acls(server)) |
| 3726 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3727 | ret = nfs_revalidate_inode(server, inode); |
| 3728 | if (ret < 0) |
| 3729 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3730 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3731 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3732 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3733 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3734 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 3735 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3736 | return ret; |
| 3737 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3738 | } |
| 3739 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3740 | 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] | 3741 | { |
| 3742 | struct nfs_server *server = NFS_SERVER(inode); |
| 3743 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3744 | struct nfs_setaclargs arg = { |
| 3745 | .fh = NFS_FH(inode), |
| 3746 | .acl_pages = pages, |
| 3747 | .acl_len = buflen, |
| 3748 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3749 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3750 | struct rpc_message msg = { |
| 3751 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3752 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3753 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3754 | }; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3755 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3756 | |
| 3757 | if (!nfs4_server_supports_acls(server)) |
| 3758 | return -EOPNOTSUPP; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3759 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3760 | if (i < 0) |
| 3761 | return i; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3762 | nfs_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3763 | 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] | 3764 | |
| 3765 | /* |
| 3766 | * Free each page after tx, so the only ref left is |
| 3767 | * held by the network stack |
| 3768 | */ |
| 3769 | for (; i > 0; i--) |
| 3770 | put_page(pages[i-1]); |
| 3771 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3772 | /* |
| 3773 | * Acl update can result in inode attribute update. |
| 3774 | * so mark the attribute cache invalid. |
| 3775 | */ |
| 3776 | spin_lock(&inode->i_lock); |
| 3777 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3778 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3779 | nfs_access_zap_cache(inode); |
| 3780 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3781 | return ret; |
| 3782 | } |
| 3783 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3784 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3785 | { |
| 3786 | struct nfs4_exception exception = { }; |
| 3787 | int err; |
| 3788 | do { |
| 3789 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3790 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3791 | &exception); |
| 3792 | } while (exception.retry); |
| 3793 | return err; |
| 3794 | } |
| 3795 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3796 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3797 | 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] | 3798 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3799 | struct nfs_client *clp = server->nfs_client; |
| 3800 | |
| 3801 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3802 | return 0; |
| 3803 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 3804 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3805 | case -NFS4ERR_ADMIN_REVOKED: |
| 3806 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 3807 | if (state != NULL) |
| 3808 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3809 | case -NFS4ERR_OPENMODE: |
| 3810 | if (state == NULL) |
| 3811 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3812 | nfs4_schedule_stateid_recovery(server, state); |
| 3813 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 3814 | case -NFS4ERR_EXPIRED: |
| 3815 | if (state != NULL) |
| 3816 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3817 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3818 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3819 | nfs4_schedule_lease_recovery(clp); |
| 3820 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3821 | #if defined(CONFIG_NFS_V4_1) |
| 3822 | case -NFS4ERR_BADSESSION: |
| 3823 | case -NFS4ERR_BADSLOT: |
| 3824 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3825 | case -NFS4ERR_DEADSESSION: |
| 3826 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3827 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3828 | case -NFS4ERR_SEQ_MISORDERED: |
| 3829 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3830 | task->tk_status); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3831 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3832 | task->tk_status = 0; |
| 3833 | return -EAGAIN; |
| 3834 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3835 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3836 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3837 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3838 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3840 | task->tk_status = 0; |
| 3841 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 3842 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | case -NFS4ERR_OLD_STATEID: |
| 3844 | task->tk_status = 0; |
| 3845 | return -EAGAIN; |
| 3846 | } |
| 3847 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3848 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3849 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3850 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3851 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3852 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3853 | task->tk_status = 0; |
| 3854 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3855 | } |
| 3856 | |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 3857 | static void nfs4_construct_boot_verifier(struct nfs_client *clp, |
| 3858 | nfs4_verifier *bootverf) |
| 3859 | { |
| 3860 | __be32 verf[2]; |
| 3861 | |
| 3862 | verf[0] = htonl((u32)clp->cl_boot_time.tv_sec); |
| 3863 | verf[1] = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 3864 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 3865 | } |
| 3866 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3867 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 3868 | unsigned short port, struct rpc_cred *cred, |
| 3869 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3870 | { |
| 3871 | nfs4_verifier sc_verifier; |
| 3872 | struct nfs4_setclientid setclientid = { |
| 3873 | .sc_verifier = &sc_verifier, |
| 3874 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 3875 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3876 | }; |
| 3877 | struct rpc_message msg = { |
| 3878 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3879 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3880 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3881 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3882 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3883 | int loop = 0; |
| 3884 | int status; |
| 3885 | |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 3886 | nfs4_construct_boot_verifier(clp, &sc_verifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3887 | |
| 3888 | for(;;) { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 3889 | rcu_read_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3890 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3891 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3892 | clp->cl_ipaddr, |
| 3893 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3894 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3895 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3896 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3897 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3898 | clp->cl_id_uniquifier); |
| 3899 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3900 | sizeof(setclientid.sc_netid), |
| 3901 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3902 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3903 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3904 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3905 | clp->cl_ipaddr, port >> 8, port & 255); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 3906 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3907 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 3908 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3909 | if (status != -NFS4ERR_CLID_INUSE) |
| 3910 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3911 | if (loop != 0) { |
| 3912 | ++clp->cl_id_uniquifier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3913 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3914 | } |
| 3915 | ++loop; |
| 3916 | ssleep(clp->cl_lease_time / HZ + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3917 | } |
| 3918 | return status; |
| 3919 | } |
| 3920 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3921 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3922 | struct nfs4_setclientid_res *arg, |
| 3923 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3924 | { |
| 3925 | struct nfs_fsinfo fsinfo; |
| 3926 | struct rpc_message msg = { |
| 3927 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3928 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3929 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3930 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3931 | }; |
| 3932 | unsigned long now; |
| 3933 | int status; |
| 3934 | |
| 3935 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 3936 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | if (status == 0) { |
| 3938 | spin_lock(&clp->cl_lock); |
| 3939 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 3940 | clp->cl_last_renewal = now; |
| 3941 | spin_unlock(&clp->cl_lock); |
| 3942 | } |
| 3943 | return status; |
| 3944 | } |
| 3945 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3946 | struct nfs4_delegreturndata { |
| 3947 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3948 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3949 | struct nfs_fh fh; |
| 3950 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3951 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3952 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3953 | int rpc_status; |
| 3954 | }; |
| 3955 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3956 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 3957 | { |
| 3958 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3959 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3960 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3961 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3962 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3963 | switch (task->tk_status) { |
| 3964 | case -NFS4ERR_STALE_STATEID: |
| 3965 | case -NFS4ERR_EXPIRED: |
| 3966 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3967 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3968 | break; |
| 3969 | default: |
| 3970 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 3971 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3972 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3973 | return; |
| 3974 | } |
| 3975 | } |
| 3976 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3977 | } |
| 3978 | |
| 3979 | static void nfs4_delegreturn_release(void *calldata) |
| 3980 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3981 | kfree(calldata); |
| 3982 | } |
| 3983 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3984 | #if defined(CONFIG_NFS_V4_1) |
| 3985 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 3986 | { |
| 3987 | struct nfs4_delegreturndata *d_data; |
| 3988 | |
| 3989 | d_data = (struct nfs4_delegreturndata *)data; |
| 3990 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3991 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3992 | &d_data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3993 | &d_data->res.seq_res, task)) |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3994 | return; |
| 3995 | rpc_call_start(task); |
| 3996 | } |
| 3997 | #endif /* CONFIG_NFS_V4_1 */ |
| 3998 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 3999 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4000 | #if defined(CONFIG_NFS_V4_1) |
| 4001 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4002 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4003 | .rpc_call_done = nfs4_delegreturn_done, |
| 4004 | .rpc_release = nfs4_delegreturn_release, |
| 4005 | }; |
| 4006 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4007 | 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] | 4008 | { |
| 4009 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4010 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4011 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4012 | struct rpc_message msg = { |
| 4013 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4014 | .rpc_cred = cred, |
| 4015 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4016 | struct rpc_task_setup task_setup_data = { |
| 4017 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4018 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4019 | .callback_ops = &nfs4_delegreturn_ops, |
| 4020 | .flags = RPC_TASK_ASYNC, |
| 4021 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4022 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4023 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4024 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4025 | if (data == NULL) |
| 4026 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4027 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4028 | data->args.fhandle = &data->fh; |
| 4029 | data->args.stateid = &data->stateid; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4030 | data->args.bitmask = server->attr_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4031 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4032 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4033 | data->res.fattr = &data->fattr; |
| 4034 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4035 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4036 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4037 | data->rpc_status = 0; |
| 4038 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4039 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4040 | msg.rpc_argp = &data->args; |
| 4041 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4042 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4043 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4044 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4045 | if (!issync) |
| 4046 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4047 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4048 | if (status != 0) |
| 4049 | goto out; |
| 4050 | status = data->rpc_status; |
| 4051 | if (status != 0) |
| 4052 | goto out; |
| 4053 | nfs_refresh_inode(inode, &data->fattr); |
| 4054 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4055 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4056 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4057 | } |
| 4058 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4059 | 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] | 4060 | { |
| 4061 | struct nfs_server *server = NFS_SERVER(inode); |
| 4062 | struct nfs4_exception exception = { }; |
| 4063 | int err; |
| 4064 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4065 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4066 | switch (err) { |
| 4067 | case -NFS4ERR_STALE_STATEID: |
| 4068 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | case 0: |
| 4070 | return 0; |
| 4071 | } |
| 4072 | err = nfs4_handle_exception(server, err, &exception); |
| 4073 | } while (exception.retry); |
| 4074 | return err; |
| 4075 | } |
| 4076 | |
| 4077 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4078 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4079 | |
| 4080 | /* |
| 4081 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4082 | */ |
| 4083 | static unsigned long |
| 4084 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4085 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4086 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4087 | timeout <<= 1; |
| 4088 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4089 | return NFS4_LOCK_MAXTIMEOUT; |
| 4090 | return timeout; |
| 4091 | } |
| 4092 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4093 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4094 | { |
| 4095 | struct inode *inode = state->inode; |
| 4096 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4097 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4098 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4099 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4100 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4101 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4102 | struct nfs_lockt_res res = { |
| 4103 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4104 | }; |
| 4105 | struct rpc_message msg = { |
| 4106 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4107 | .rpc_argp = &arg, |
| 4108 | .rpc_resp = &res, |
| 4109 | .rpc_cred = state->owner->so_cred, |
| 4110 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4111 | struct nfs4_lock_state *lsp; |
| 4112 | int status; |
| 4113 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4114 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4115 | status = nfs4_set_lock_state(state, request); |
| 4116 | if (status != 0) |
| 4117 | goto out; |
| 4118 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4119 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4120 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4121 | 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] | 4122 | switch (status) { |
| 4123 | case 0: |
| 4124 | request->fl_type = F_UNLCK; |
| 4125 | break; |
| 4126 | case -NFS4ERR_DENIED: |
| 4127 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4128 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4129 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4130 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4131 | return status; |
| 4132 | } |
| 4133 | |
| 4134 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4135 | { |
| 4136 | struct nfs4_exception exception = { }; |
| 4137 | int err; |
| 4138 | |
| 4139 | do { |
| 4140 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4141 | _nfs4_proc_getlk(state, cmd, request), |
| 4142 | &exception); |
| 4143 | } while (exception.retry); |
| 4144 | return err; |
| 4145 | } |
| 4146 | |
| 4147 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4148 | { |
| 4149 | int res = 0; |
| 4150 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4151 | case FL_POSIX: |
| 4152 | res = posix_lock_file_wait(file, fl); |
| 4153 | break; |
| 4154 | case FL_FLOCK: |
| 4155 | res = flock_lock_file_wait(file, fl); |
| 4156 | break; |
| 4157 | default: |
| 4158 | BUG(); |
| 4159 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4160 | return res; |
| 4161 | } |
| 4162 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4163 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4164 | struct nfs_locku_args arg; |
| 4165 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4166 | struct nfs4_lock_state *lsp; |
| 4167 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4168 | struct file_lock fl; |
| 4169 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4170 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4171 | }; |
| 4172 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4173 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4174 | struct nfs_open_context *ctx, |
| 4175 | struct nfs4_lock_state *lsp, |
| 4176 | struct nfs_seqid *seqid) |
| 4177 | { |
| 4178 | struct nfs4_unlockdata *p; |
| 4179 | struct inode *inode = lsp->ls_state->inode; |
| 4180 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4181 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4182 | if (p == NULL) |
| 4183 | return NULL; |
| 4184 | p->arg.fh = NFS_FH(inode); |
| 4185 | p->arg.fl = &p->fl; |
| 4186 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4187 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4188 | p->arg.stateid = &lsp->ls_stateid; |
| 4189 | p->lsp = lsp; |
| 4190 | atomic_inc(&lsp->ls_count); |
| 4191 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4192 | p->ctx = get_nfs_open_context(ctx); |
| 4193 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4194 | p->server = NFS_SERVER(inode); |
| 4195 | return p; |
| 4196 | } |
| 4197 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4198 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4199 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4200 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4201 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4202 | nfs4_put_lock_state(calldata->lsp); |
| 4203 | put_nfs_open_context(calldata->ctx); |
| 4204 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4205 | } |
| 4206 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4207 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4208 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4209 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4210 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4211 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4212 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4213 | switch (task->tk_status) { |
| 4214 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4215 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4216 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4217 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4218 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4219 | case -NFS4ERR_BAD_STATEID: |
| 4220 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4221 | case -NFS4ERR_STALE_STATEID: |
| 4222 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4223 | break; |
| 4224 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4225 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4226 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4227 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4228 | } |
| 4229 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4230 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4231 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4232 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4234 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4235 | return; |
| 4236 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4237 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4238 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4239 | return; |
| 4240 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4241 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4242 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4243 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4244 | &calldata->res.seq_res, task)) |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4245 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4246 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4247 | } |
| 4248 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4249 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4250 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4251 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4252 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4253 | }; |
| 4254 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4255 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4256 | struct nfs_open_context *ctx, |
| 4257 | struct nfs4_lock_state *lsp, |
| 4258 | struct nfs_seqid *seqid) |
| 4259 | { |
| 4260 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4261 | struct rpc_message msg = { |
| 4262 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4263 | .rpc_cred = ctx->cred, |
| 4264 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4265 | struct rpc_task_setup task_setup_data = { |
| 4266 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4267 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4268 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4269 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4270 | .flags = RPC_TASK_ASYNC, |
| 4271 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4272 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4273 | /* Ensure this is an unlock - when canceling a lock, the |
| 4274 | * canceled lock is passed in, and it won't be an unlock. |
| 4275 | */ |
| 4276 | fl->fl_type = F_UNLCK; |
| 4277 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4278 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4279 | if (data == NULL) { |
| 4280 | nfs_free_seqid(seqid); |
| 4281 | return ERR_PTR(-ENOMEM); |
| 4282 | } |
| 4283 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4284 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4285 | msg.rpc_argp = &data->arg; |
| 4286 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4287 | task_setup_data.callback_data = data; |
| 4288 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4289 | } |
| 4290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4291 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4292 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4293 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4294 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4295 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4296 | struct rpc_task *task; |
| 4297 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4298 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4299 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4300 | status = nfs4_set_lock_state(state, request); |
| 4301 | /* Unlock _before_ we do the RPC call */ |
| 4302 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4303 | down_read(&nfsi->rwsem); |
| 4304 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4305 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4306 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4307 | } |
| 4308 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4309 | if (status != 0) |
| 4310 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4311 | /* Is this a delegated lock? */ |
| 4312 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4313 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4314 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4315 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4316 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4317 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4318 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4319 | 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] | 4320 | status = PTR_ERR(task); |
| 4321 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4322 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4323 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4324 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4325 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4326 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4327 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4328 | } |
| 4329 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4330 | struct nfs4_lockdata { |
| 4331 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4332 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4333 | struct nfs4_lock_state *lsp; |
| 4334 | struct nfs_open_context *ctx; |
| 4335 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4336 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4337 | int rpc_status; |
| 4338 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4339 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4340 | }; |
| 4341 | |
| 4342 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4343 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4344 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4345 | { |
| 4346 | struct nfs4_lockdata *p; |
| 4347 | struct inode *inode = lsp->ls_state->inode; |
| 4348 | struct nfs_server *server = NFS_SERVER(inode); |
| 4349 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4350 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4351 | if (p == NULL) |
| 4352 | return NULL; |
| 4353 | |
| 4354 | p->arg.fh = NFS_FH(inode); |
| 4355 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4356 | 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] | 4357 | if (p->arg.open_seqid == NULL) |
| 4358 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4359 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4360 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4361 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4362 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4363 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4364 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4365 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4366 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4367 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4368 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4369 | atomic_inc(&lsp->ls_count); |
| 4370 | p->ctx = get_nfs_open_context(ctx); |
| 4371 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4372 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4373 | out_free_seqid: |
| 4374 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4375 | out_free: |
| 4376 | kfree(p); |
| 4377 | return NULL; |
| 4378 | } |
| 4379 | |
| 4380 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4381 | { |
| 4382 | struct nfs4_lockdata *data = calldata; |
| 4383 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4384 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4385 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4386 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4387 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4388 | /* Do we need to do an open_to_lock_owner? */ |
| 4389 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4390 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4391 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4392 | data->arg.open_stateid = &state->stateid; |
| 4393 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4394 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4395 | } else |
| 4396 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4397 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4398 | if (nfs4_setup_sequence(data->server, |
| 4399 | &data->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4400 | &data->res.seq_res, task)) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4401 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4402 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4403 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4404 | } |
| 4405 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4406 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4407 | { |
| 4408 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4409 | nfs4_lock_prepare(task, calldata); |
| 4410 | } |
| 4411 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4412 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4413 | { |
| 4414 | struct nfs4_lockdata *data = calldata; |
| 4415 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4416 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4417 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4418 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4419 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4420 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4421 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4422 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4423 | if (data->rpc_status == 0) |
| 4424 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4425 | else |
| 4426 | goto out; |
| 4427 | } |
| 4428 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4429 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4430 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4431 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4432 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4433 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4434 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4435 | } |
| 4436 | |
| 4437 | static void nfs4_lock_release(void *calldata) |
| 4438 | { |
| 4439 | struct nfs4_lockdata *data = calldata; |
| 4440 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4441 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4442 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4443 | if (data->cancelled != 0) { |
| 4444 | struct rpc_task *task; |
| 4445 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4446 | data->arg.lock_seqid); |
| 4447 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4448 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4449 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4450 | } else |
| 4451 | nfs_free_seqid(data->arg.lock_seqid); |
| 4452 | nfs4_put_lock_state(data->lsp); |
| 4453 | put_nfs_open_context(data->ctx); |
| 4454 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4455 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4456 | } |
| 4457 | |
| 4458 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4459 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4460 | .rpc_call_done = nfs4_lock_done, |
| 4461 | .rpc_release = nfs4_lock_release, |
| 4462 | }; |
| 4463 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4464 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4465 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4466 | .rpc_call_done = nfs4_lock_done, |
| 4467 | .rpc_release = nfs4_lock_release, |
| 4468 | }; |
| 4469 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4470 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4471 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4472 | switch (error) { |
| 4473 | case -NFS4ERR_ADMIN_REVOKED: |
| 4474 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4475 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4476 | if (new_lock_owner != 0 || |
| 4477 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4478 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4479 | break; |
| 4480 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4481 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4482 | case -NFS4ERR_EXPIRED: |
| 4483 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4484 | }; |
| 4485 | } |
| 4486 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4487 | 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] | 4488 | { |
| 4489 | struct nfs4_lockdata *data; |
| 4490 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4491 | struct rpc_message msg = { |
| 4492 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4493 | .rpc_cred = state->owner->so_cred, |
| 4494 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4495 | struct rpc_task_setup task_setup_data = { |
| 4496 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4497 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4498 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4499 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4500 | .flags = RPC_TASK_ASYNC, |
| 4501 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4502 | int ret; |
| 4503 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4504 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4505 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4506 | fl->fl_u.nfs4_fl.owner, |
| 4507 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4508 | if (data == NULL) |
| 4509 | return -ENOMEM; |
| 4510 | if (IS_SETLKW(cmd)) |
| 4511 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4512 | if (recovery_type > NFS_LOCK_NEW) { |
| 4513 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4514 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4515 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4516 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4517 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4518 | msg.rpc_argp = &data->arg; |
| 4519 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4520 | task_setup_data.callback_data = data; |
| 4521 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4522 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4523 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4524 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4525 | if (ret == 0) { |
| 4526 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4527 | if (ret) |
| 4528 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4529 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4530 | } else |
| 4531 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4532 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4533 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4534 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4535 | } |
| 4536 | |
| 4537 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4538 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4539 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4540 | struct nfs4_exception exception = { }; |
| 4541 | int err; |
| 4542 | |
| 4543 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4544 | /* Cache the lock if possible... */ |
| 4545 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4546 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4547 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4548 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4549 | break; |
| 4550 | nfs4_handle_exception(server, err, &exception); |
| 4551 | } while (exception.retry); |
| 4552 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4553 | } |
| 4554 | |
| 4555 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4556 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4557 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4558 | struct nfs4_exception exception = { }; |
| 4559 | int err; |
| 4560 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4561 | err = nfs4_set_lock_state(state, request); |
| 4562 | if (err != 0) |
| 4563 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4564 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4565 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4566 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4567 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4568 | switch (err) { |
| 4569 | default: |
| 4570 | goto out; |
| 4571 | case -NFS4ERR_GRACE: |
| 4572 | case -NFS4ERR_DELAY: |
| 4573 | nfs4_handle_exception(server, err, &exception); |
| 4574 | err = 0; |
| 4575 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4576 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4577 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4578 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4579 | } |
| 4580 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4581 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4582 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4583 | { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4584 | int status, ret = NFS_OK; |
| 4585 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4586 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4587 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4588 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 4589 | if (lsp->ls_flags & NFS_LOCK_INITIALIZED) { |
| 4590 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 4591 | if (status != NFS_OK) { |
| 4592 | nfs41_free_stateid(server, &lsp->ls_stateid); |
| 4593 | lsp->ls_flags &= ~NFS_LOCK_INITIALIZED; |
| 4594 | ret = status; |
| 4595 | } |
| 4596 | } |
| 4597 | }; |
| 4598 | |
| 4599 | return ret; |
| 4600 | } |
| 4601 | |
| 4602 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4603 | { |
| 4604 | int status = NFS_OK; |
| 4605 | |
| 4606 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 4607 | status = nfs41_check_expired_locks(state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4608 | if (status == NFS_OK) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4609 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4610 | return nfs4_lock_expired(state, request); |
| 4611 | } |
| 4612 | #endif |
| 4613 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4614 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4615 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4616 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4617 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4618 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4619 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4620 | if ((fl_flags & FL_POSIX) && |
| 4621 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4622 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4623 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4624 | status = nfs4_set_lock_state(state, request); |
| 4625 | if (status != 0) |
| 4626 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4627 | request->fl_flags |= FL_ACCESS; |
| 4628 | status = do_vfs_lock(request->fl_file, request); |
| 4629 | if (status < 0) |
| 4630 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4631 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4632 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4633 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4634 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4635 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4636 | status = do_vfs_lock(request->fl_file, request); |
| 4637 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4638 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4639 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4640 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4641 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4642 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4643 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4644 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4645 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 4646 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4647 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4648 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4649 | out: |
| 4650 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4651 | return status; |
| 4652 | } |
| 4653 | |
| 4654 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4655 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4656 | struct nfs4_exception exception = { |
| 4657 | .state = state, |
| 4658 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4659 | int err; |
| 4660 | |
| 4661 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4662 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4663 | if (err == -NFS4ERR_DENIED) |
| 4664 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4665 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4666 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4667 | } while (exception.retry); |
| 4668 | return err; |
| 4669 | } |
| 4670 | |
| 4671 | static int |
| 4672 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4673 | { |
| 4674 | struct nfs_open_context *ctx; |
| 4675 | struct nfs4_state *state; |
| 4676 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4677 | int status; |
| 4678 | |
| 4679 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4680 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4681 | state = ctx->state; |
| 4682 | |
| 4683 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4684 | return -EINVAL; |
| 4685 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4686 | if (IS_GETLK(cmd)) { |
| 4687 | if (state != NULL) |
| 4688 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4689 | return 0; |
| 4690 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4691 | |
| 4692 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4693 | return -EINVAL; |
| 4694 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4695 | if (request->fl_type == F_UNLCK) { |
| 4696 | if (state != NULL) |
| 4697 | return nfs4_proc_unlck(state, cmd, request); |
| 4698 | return 0; |
| 4699 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4700 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4701 | if (state == NULL) |
| 4702 | return -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4703 | do { |
| 4704 | status = nfs4_proc_setlk(state, cmd, request); |
| 4705 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4706 | break; |
| 4707 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4708 | status = -ERESTARTSYS; |
| 4709 | if (signalled()) |
| 4710 | break; |
| 4711 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4712 | return status; |
| 4713 | } |
| 4714 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4715 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4716 | { |
| 4717 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4718 | struct nfs4_exception exception = { }; |
| 4719 | int err; |
| 4720 | |
| 4721 | err = nfs4_set_lock_state(state, fl); |
| 4722 | if (err != 0) |
| 4723 | goto out; |
| 4724 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4725 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4726 | switch (err) { |
| 4727 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4728 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 4729 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4730 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4731 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4732 | goto out; |
| 4733 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4734 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4735 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4736 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4737 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4738 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4739 | case -NFS4ERR_BADSESSION: |
| 4740 | case -NFS4ERR_BADSLOT: |
| 4741 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4742 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4743 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4744 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4745 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4746 | case -ERESTARTSYS: |
| 4747 | /* |
| 4748 | * The show must go on: exit, but mark the |
| 4749 | * stateid as needing recovery. |
| 4750 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4751 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4752 | case -NFS4ERR_ADMIN_REVOKED: |
| 4753 | case -NFS4ERR_BAD_STATEID: |
| 4754 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4755 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4756 | err = 0; |
| 4757 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4758 | case -EKEYEXPIRED: |
| 4759 | /* |
| 4760 | * User RPCSEC_GSS context has expired. |
| 4761 | * We cannot recover this stateid now, so |
| 4762 | * skip it and allow recovery thread to |
| 4763 | * proceed. |
| 4764 | */ |
| 4765 | err = 0; |
| 4766 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4767 | case -ENOMEM: |
| 4768 | case -NFS4ERR_DENIED: |
| 4769 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4770 | err = 0; |
| 4771 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4772 | case -NFS4ERR_DELAY: |
| 4773 | break; |
| 4774 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4775 | err = nfs4_handle_exception(server, err, &exception); |
| 4776 | } while (exception.retry); |
| 4777 | out: |
| 4778 | return err; |
| 4779 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4780 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4781 | struct nfs_release_lockowner_data { |
| 4782 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 4783 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4784 | struct nfs_release_lockowner_args args; |
| 4785 | }; |
| 4786 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4787 | static void nfs4_release_lockowner_release(void *calldata) |
| 4788 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4789 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 4790 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4791 | kfree(calldata); |
| 4792 | } |
| 4793 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 4794 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4795 | .rpc_release = nfs4_release_lockowner_release, |
| 4796 | }; |
| 4797 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4798 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4799 | { |
| 4800 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4801 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4802 | struct rpc_message msg = { |
| 4803 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 4804 | }; |
| 4805 | |
| 4806 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4807 | return -EINVAL; |
| 4808 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 4809 | if (!data) |
| 4810 | return -ENOMEM; |
| 4811 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 4812 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4813 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 4814 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 4815 | data->args.lock_owner.s_dev = server->s_dev; |
| 4816 | msg.rpc_argp = &data->args; |
| 4817 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 4818 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4819 | } |
| 4820 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4821 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4822 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4823 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 4824 | const void *buf, size_t buflen, |
| 4825 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4826 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4827 | if (strcmp(key, "") != 0) |
| 4828 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4829 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4830 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4831 | } |
| 4832 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4833 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 4834 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4835 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4836 | if (strcmp(key, "") != 0) |
| 4837 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4838 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4839 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4840 | } |
| 4841 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4842 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 4843 | size_t list_len, const char *name, |
| 4844 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4845 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4846 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4847 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4848 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4849 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4850 | |
| 4851 | if (list && len <= list_len) |
| 4852 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4853 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4854 | } |
| 4855 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4856 | /* |
| 4857 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 4858 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4859 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4860 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4861 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 4862 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 4863 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 4864 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4865 | return; |
| 4866 | |
| 4867 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 4868 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4869 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4870 | fattr->nlink = 2; |
| 4871 | } |
| 4872 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 4873 | int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 4874 | struct nfs4_fs_locations *fs_locations, struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4875 | { |
| 4876 | struct nfs_server *server = NFS_SERVER(dir); |
| 4877 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4878 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4879 | }; |
| 4880 | struct nfs4_fs_locations_arg args = { |
| 4881 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4882 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4883 | .page = page, |
| 4884 | .bitmask = bitmask, |
| 4885 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4886 | struct nfs4_fs_locations_res res = { |
| 4887 | .fs_locations = fs_locations, |
| 4888 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4889 | struct rpc_message msg = { |
| 4890 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4891 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4892 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4893 | }; |
| 4894 | int status; |
| 4895 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4896 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4897 | |
| 4898 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 4899 | * is not supported */ |
| 4900 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 4901 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 4902 | else |
| 4903 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 4904 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4905 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4906 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 4907 | fs_locations->nlocations = 0; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4908 | 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] | 4909 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4910 | return status; |
| 4911 | } |
| 4912 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 4913 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4914 | { |
| 4915 | int status; |
| 4916 | struct nfs4_secinfo_arg args = { |
| 4917 | .dir_fh = NFS_FH(dir), |
| 4918 | .name = name, |
| 4919 | }; |
| 4920 | struct nfs4_secinfo_res res = { |
| 4921 | .flavors = flavors, |
| 4922 | }; |
| 4923 | struct rpc_message msg = { |
| 4924 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 4925 | .rpc_argp = &args, |
| 4926 | .rpc_resp = &res, |
| 4927 | }; |
| 4928 | |
| 4929 | dprintk("NFS call secinfo %s\n", name->name); |
| 4930 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 4931 | dprintk("NFS reply secinfo: %d\n", status); |
| 4932 | return status; |
| 4933 | } |
| 4934 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 4935 | static int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 4936 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 4937 | { |
| 4938 | struct nfs4_exception exception = { }; |
| 4939 | int err; |
| 4940 | do { |
| 4941 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 4942 | _nfs4_proc_secinfo(dir, name, flavors), |
| 4943 | &exception); |
| 4944 | } while (exception.retry); |
| 4945 | return err; |
| 4946 | } |
| 4947 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4948 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4949 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4950 | * Check the exchange flags returned by the server for invalid flags, having |
| 4951 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 4952 | * DS flags set. |
| 4953 | */ |
| 4954 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 4955 | { |
| 4956 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 4957 | goto out_inval; |
| 4958 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 4959 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 4960 | goto out_inval; |
| 4961 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 4962 | goto out_inval; |
| 4963 | return NFS_OK; |
| 4964 | out_inval: |
| 4965 | return -NFS4ERR_INVAL; |
| 4966 | } |
| 4967 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4968 | static bool |
| 4969 | nfs41_same_server_scope(struct server_scope *a, struct server_scope *b) |
| 4970 | { |
| 4971 | if (a->server_scope_sz == b->server_scope_sz && |
| 4972 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 4973 | return true; |
| 4974 | |
| 4975 | return false; |
| 4976 | } |
| 4977 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4978 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4979 | * nfs4_proc_exchange_id() |
| 4980 | * |
| 4981 | * Since the clientid has expired, all compounds using sessions |
| 4982 | * associated with the stale clientid will be returning |
| 4983 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 4984 | * be in some phase of session reset. |
| 4985 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 4986 | 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] | 4987 | { |
| 4988 | nfs4_verifier verifier; |
| 4989 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4990 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4991 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4992 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4993 | }; |
| 4994 | struct nfs41_exchange_id_res res = { |
| 4995 | .client = clp, |
| 4996 | }; |
| 4997 | int status; |
| 4998 | struct rpc_message msg = { |
| 4999 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5000 | .rpc_argp = &args, |
| 5001 | .rpc_resp = &res, |
| 5002 | .rpc_cred = cred, |
| 5003 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5004 | |
| 5005 | dprintk("--> %s\n", __func__); |
| 5006 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5007 | |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5008 | nfs4_construct_boot_verifier(clp, &verifier); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5009 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 5010 | args.id_len = scnprintf(args.id, sizeof(args.id), |
| 5011 | "%s/%s.%s/%u", |
| 5012 | clp->cl_ipaddr, |
| 5013 | init_utsname()->nodename, |
| 5014 | init_utsname()->domainname, |
| 5015 | clp->cl_rpcclient->cl_auth->au_flavor); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5016 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5017 | res.server_scope = kzalloc(sizeof(struct server_scope), GFP_KERNEL); |
Weston Andros Adamson | 9edbd95 | 2012-02-17 15:20:25 -0500 | [diff] [blame] | 5018 | if (unlikely(!res.server_scope)) { |
| 5019 | status = -ENOMEM; |
| 5020 | goto out; |
| 5021 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5022 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5023 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_KERNEL); |
| 5024 | if (unlikely(!res.impl_id)) { |
| 5025 | status = -ENOMEM; |
| 5026 | goto out_server_scope; |
| 5027 | } |
| 5028 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5029 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 5030 | if (!status) |
| 5031 | status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5032 | |
| 5033 | if (!status) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5034 | /* use the most recent implementation id */ |
| 5035 | kfree(clp->impl_id); |
| 5036 | clp->impl_id = res.impl_id; |
| 5037 | } else |
| 5038 | kfree(res.impl_id); |
| 5039 | |
| 5040 | if (!status) { |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5041 | if (clp->server_scope && |
| 5042 | !nfs41_same_server_scope(clp->server_scope, |
| 5043 | res.server_scope)) { |
| 5044 | dprintk("%s: server_scope mismatch detected\n", |
| 5045 | __func__); |
| 5046 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 5047 | kfree(clp->server_scope); |
| 5048 | clp->server_scope = NULL; |
| 5049 | } |
| 5050 | |
Weston Andros Adamson | 9edbd95 | 2012-02-17 15:20:25 -0500 | [diff] [blame] | 5051 | if (!clp->server_scope) { |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5052 | clp->server_scope = res.server_scope; |
Weston Andros Adamson | 9edbd95 | 2012-02-17 15:20:25 -0500 | [diff] [blame] | 5053 | goto out; |
| 5054 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5055 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5056 | |
| 5057 | out_server_scope: |
Weston Andros Adamson | 9edbd95 | 2012-02-17 15:20:25 -0500 | [diff] [blame] | 5058 | kfree(res.server_scope); |
| 5059 | out: |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5060 | if (clp->impl_id) |
| 5061 | dprintk("%s: Server Implementation ID: " |
| 5062 | "domain: %s, name: %s, date: %llu,%u\n", |
| 5063 | __func__, clp->impl_id->domain, clp->impl_id->name, |
| 5064 | clp->impl_id->date.seconds, |
| 5065 | clp->impl_id->date.nseconds); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5066 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5067 | return status; |
| 5068 | } |
| 5069 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5070 | struct nfs4_get_lease_time_data { |
| 5071 | struct nfs4_get_lease_time_args *args; |
| 5072 | struct nfs4_get_lease_time_res *res; |
| 5073 | struct nfs_client *clp; |
| 5074 | }; |
| 5075 | |
| 5076 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5077 | void *calldata) |
| 5078 | { |
| 5079 | int ret; |
| 5080 | struct nfs4_get_lease_time_data *data = |
| 5081 | (struct nfs4_get_lease_time_data *)calldata; |
| 5082 | |
| 5083 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5084 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5085 | /* just setup sequence, do not trigger session recovery |
| 5086 | since we're invoked within one */ |
| 5087 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5088 | &data->args->la_seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5089 | &data->res->lr_seq_res, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5090 | |
| 5091 | BUG_ON(ret == -EAGAIN); |
| 5092 | rpc_call_start(task); |
| 5093 | dprintk("<-- %s\n", __func__); |
| 5094 | } |
| 5095 | |
| 5096 | /* |
| 5097 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5098 | * from sequence operation or clientid errors. |
| 5099 | */ |
| 5100 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5101 | { |
| 5102 | struct nfs4_get_lease_time_data *data = |
| 5103 | (struct nfs4_get_lease_time_data *)calldata; |
| 5104 | |
| 5105 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5106 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5107 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5108 | switch (task->tk_status) { |
| 5109 | case -NFS4ERR_DELAY: |
| 5110 | case -NFS4ERR_GRACE: |
| 5111 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5112 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5113 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5114 | /* fall through */ |
| 5115 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5116 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5117 | return; |
| 5118 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5119 | dprintk("<-- %s\n", __func__); |
| 5120 | } |
| 5121 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5122 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5123 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5124 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5125 | }; |
| 5126 | |
| 5127 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5128 | { |
| 5129 | struct rpc_task *task; |
| 5130 | struct nfs4_get_lease_time_args args; |
| 5131 | struct nfs4_get_lease_time_res res = { |
| 5132 | .lr_fsinfo = fsinfo, |
| 5133 | }; |
| 5134 | struct nfs4_get_lease_time_data data = { |
| 5135 | .args = &args, |
| 5136 | .res = &res, |
| 5137 | .clp = clp, |
| 5138 | }; |
| 5139 | struct rpc_message msg = { |
| 5140 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5141 | .rpc_argp = &args, |
| 5142 | .rpc_resp = &res, |
| 5143 | }; |
| 5144 | struct rpc_task_setup task_setup = { |
| 5145 | .rpc_client = clp->cl_rpcclient, |
| 5146 | .rpc_message = &msg, |
| 5147 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5148 | .callback_data = &data, |
| 5149 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5150 | }; |
| 5151 | int status; |
| 5152 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5153 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5154 | dprintk("--> %s\n", __func__); |
| 5155 | task = rpc_run_task(&task_setup); |
| 5156 | |
| 5157 | if (IS_ERR(task)) |
| 5158 | status = PTR_ERR(task); |
| 5159 | else { |
| 5160 | status = task->tk_status; |
| 5161 | rpc_put_task(task); |
| 5162 | } |
| 5163 | dprintk("<-- %s return %d\n", __func__, status); |
| 5164 | |
| 5165 | return status; |
| 5166 | } |
| 5167 | |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5168 | static struct nfs4_slot *nfs4_alloc_slots(u32 max_slots, gfp_t gfp_flags) |
| 5169 | { |
| 5170 | return kcalloc(max_slots, sizeof(struct nfs4_slot), gfp_flags); |
| 5171 | } |
| 5172 | |
| 5173 | static void nfs4_add_and_init_slots(struct nfs4_slot_table *tbl, |
| 5174 | struct nfs4_slot *new, |
| 5175 | u32 max_slots, |
| 5176 | u32 ivalue) |
| 5177 | { |
| 5178 | struct nfs4_slot *old = NULL; |
| 5179 | u32 i; |
| 5180 | |
| 5181 | spin_lock(&tbl->slot_tbl_lock); |
| 5182 | if (new) { |
| 5183 | old = tbl->slots; |
| 5184 | tbl->slots = new; |
| 5185 | tbl->max_slots = max_slots; |
| 5186 | } |
| 5187 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 5188 | for (i = 0; i < tbl->max_slots; i++) |
| 5189 | tbl->slots[i].seq_nr = ivalue; |
| 5190 | spin_unlock(&tbl->slot_tbl_lock); |
| 5191 | kfree(old); |
| 5192 | } |
| 5193 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5194 | /* |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5195 | * (re)Initialise a slot table |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5196 | */ |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5197 | static int nfs4_realloc_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 5198 | u32 ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5199 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5200 | struct nfs4_slot *new = NULL; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5201 | int ret = -ENOMEM; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5202 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5203 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 5204 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5205 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5206 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 5207 | if (max_reqs != tbl->max_slots) { |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5208 | new = nfs4_alloc_slots(max_reqs, GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5209 | if (!new) |
| 5210 | goto out; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5211 | } |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5212 | ret = 0; |
| 5213 | |
| 5214 | nfs4_add_and_init_slots(tbl, new, max_reqs, ivalue); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5215 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5216 | tbl, tbl->slots, tbl->max_slots); |
| 5217 | out: |
| 5218 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5219 | return ret; |
| 5220 | } |
| 5221 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5222 | /* Destroy the slot table */ |
| 5223 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 5224 | { |
| 5225 | if (session->fc_slot_table.slots != NULL) { |
| 5226 | kfree(session->fc_slot_table.slots); |
| 5227 | session->fc_slot_table.slots = NULL; |
| 5228 | } |
| 5229 | if (session->bc_slot_table.slots != NULL) { |
| 5230 | kfree(session->bc_slot_table.slots); |
| 5231 | session->bc_slot_table.slots = NULL; |
| 5232 | } |
| 5233 | return; |
| 5234 | } |
| 5235 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5236 | /* |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5237 | * Initialize or reset the forechannel and backchannel tables |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5238 | */ |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5239 | static int nfs4_setup_session_slot_tables(struct nfs4_session *ses) |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5240 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5241 | struct nfs4_slot_table *tbl; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5242 | int status; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5243 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5244 | dprintk("--> %s\n", __func__); |
| 5245 | /* Fore channel */ |
| 5246 | tbl = &ses->fc_slot_table; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5247 | status = nfs4_realloc_slot_table(tbl, ses->fc_attrs.max_reqs, 1); |
| 5248 | if (status) /* -ENOMEM */ |
| 5249 | return status; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5250 | /* Back channel */ |
| 5251 | tbl = &ses->bc_slot_table; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5252 | status = nfs4_realloc_slot_table(tbl, ses->bc_attrs.max_reqs, 0); |
| 5253 | if (status && tbl->slots == NULL) |
| 5254 | /* Fore and back channel share a connection so get |
| 5255 | * both slot tables or neither */ |
| 5256 | nfs4_destroy_slot_tables(ses); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5257 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5258 | } |
| 5259 | |
| 5260 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 5261 | { |
| 5262 | struct nfs4_session *session; |
| 5263 | struct nfs4_slot_table *tbl; |
| 5264 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5265 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5266 | if (!session) |
| 5267 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 5268 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5269 | tbl = &session->fc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5270 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5271 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5272 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5273 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5274 | |
| 5275 | tbl = &session->bc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5276 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5277 | spin_lock_init(&tbl->slot_tbl_lock); |
| 5278 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5279 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5280 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5281 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 5282 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5283 | session->clp = clp; |
| 5284 | return session; |
| 5285 | } |
| 5286 | |
| 5287 | void nfs4_destroy_session(struct nfs4_session *session) |
| 5288 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5289 | struct rpc_xprt *xprt; |
| 5290 | |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5291 | nfs4_proc_destroy_session(session); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5292 | |
| 5293 | rcu_read_lock(); |
| 5294 | xprt = rcu_dereference(session->clp->cl_rpcclient->cl_xprt); |
| 5295 | rcu_read_unlock(); |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5296 | dprintk("%s Destroy backchannel for xprt %p\n", |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5297 | __func__, xprt); |
| 5298 | xprt_destroy_backchannel(xprt, NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5299 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5300 | kfree(session); |
| 5301 | } |
| 5302 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5303 | /* |
| 5304 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5305 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5306 | * use them. |
| 5307 | * |
| 5308 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5309 | * always set csa_cachethis to FALSE because the current implementation |
| 5310 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5311 | */ |
| 5312 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5313 | { |
| 5314 | struct nfs4_session *session = args->client->cl_session; |
| 5315 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 5316 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 5317 | |
| 5318 | if (mxrqst_sz == 0) |
| 5319 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5320 | if (mxresp_sz == 0) |
| 5321 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5322 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5323 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5324 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5325 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5326 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5327 | |
| 5328 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5329 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5330 | __func__, |
| 5331 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5332 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5333 | |
| 5334 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5335 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5336 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5337 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5338 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5339 | args->bc_attrs.max_reqs = 1; |
| 5340 | |
| 5341 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5342 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5343 | __func__, |
| 5344 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5345 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5346 | args->bc_attrs.max_reqs); |
| 5347 | } |
| 5348 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5349 | 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] | 5350 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5351 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5352 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5353 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5354 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5355 | return -EINVAL; |
| 5356 | /* |
| 5357 | * Our requested max_ops is the minimum we need; we're not |
| 5358 | * prepared to break up compounds into smaller pieces than that. |
| 5359 | * So, no point even trying to continue if the server won't |
| 5360 | * cooperate: |
| 5361 | */ |
| 5362 | if (rcvd->max_ops < sent->max_ops) |
| 5363 | return -EINVAL; |
| 5364 | if (rcvd->max_reqs == 0) |
| 5365 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5366 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5367 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5368 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5369 | } |
| 5370 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5371 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5372 | { |
| 5373 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5374 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5375 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5376 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5377 | return -EINVAL; |
| 5378 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5379 | return -EINVAL; |
| 5380 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5381 | return -EINVAL; |
| 5382 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5383 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5384 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5385 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5386 | return -EINVAL; |
| 5387 | return 0; |
| 5388 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5389 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5390 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5391 | struct nfs4_session *session) |
| 5392 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5393 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5394 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5395 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5396 | if (ret) |
| 5397 | return ret; |
| 5398 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5399 | } |
| 5400 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5401 | static int _nfs4_proc_create_session(struct nfs_client *clp) |
| 5402 | { |
| 5403 | struct nfs4_session *session = clp->cl_session; |
| 5404 | struct nfs41_create_session_args args = { |
| 5405 | .client = clp, |
| 5406 | .cb_program = NFS4_CALLBACK, |
| 5407 | }; |
| 5408 | struct nfs41_create_session_res res = { |
| 5409 | .client = clp, |
| 5410 | }; |
| 5411 | struct rpc_message msg = { |
| 5412 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5413 | .rpc_argp = &args, |
| 5414 | .rpc_resp = &res, |
| 5415 | }; |
| 5416 | int status; |
| 5417 | |
| 5418 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5419 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5420 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5421 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5422 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5423 | if (!status) |
| 5424 | /* Verify the session's negotiated channel_attrs values */ |
| 5425 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5426 | if (!status) { |
| 5427 | /* Increment the clientid slot sequence id */ |
| 5428 | clp->cl_seqid++; |
| 5429 | } |
| 5430 | |
| 5431 | return status; |
| 5432 | } |
| 5433 | |
| 5434 | /* |
| 5435 | * Issues a CREATE_SESSION operation to the server. |
| 5436 | * It is the responsibility of the caller to verify the session is |
| 5437 | * expired before calling this routine. |
| 5438 | */ |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5439 | int nfs4_proc_create_session(struct nfs_client *clp) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5440 | { |
| 5441 | int status; |
| 5442 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5443 | struct nfs4_session *session = clp->cl_session; |
| 5444 | |
| 5445 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5446 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5447 | status = _nfs4_proc_create_session(clp); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5448 | if (status) |
| 5449 | goto out; |
| 5450 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5451 | /* Init or reset the session slot tables */ |
| 5452 | status = nfs4_setup_session_slot_tables(session); |
| 5453 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5454 | if (status) |
| 5455 | goto out; |
| 5456 | |
| 5457 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5458 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5459 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5460 | out: |
| 5461 | dprintk("<-- %s\n", __func__); |
| 5462 | return status; |
| 5463 | } |
| 5464 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5465 | /* |
| 5466 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5467 | * The caller must serialize access to this routine. |
| 5468 | */ |
| 5469 | int nfs4_proc_destroy_session(struct nfs4_session *session) |
| 5470 | { |
| 5471 | int status = 0; |
| 5472 | struct rpc_message msg; |
| 5473 | |
| 5474 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5475 | |
| 5476 | /* session is still being setup */ |
| 5477 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5478 | return status; |
| 5479 | |
| 5480 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; |
| 5481 | msg.rpc_argp = session; |
| 5482 | msg.rpc_resp = NULL; |
| 5483 | msg.rpc_cred = NULL; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5484 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5485 | |
| 5486 | if (status) |
| 5487 | printk(KERN_WARNING |
Weston Andros Adamson | f9fd2d9 | 2012-01-26 13:32:22 -0500 | [diff] [blame] | 5488 | "NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5489 | "Session has been destroyed regardless...\n", status); |
| 5490 | |
| 5491 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5492 | return status; |
| 5493 | } |
| 5494 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5495 | int nfs4_init_session(struct nfs_server *server) |
| 5496 | { |
| 5497 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5498 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5499 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5500 | int ret; |
| 5501 | |
| 5502 | if (!nfs4_has_session(clp)) |
| 5503 | return 0; |
| 5504 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5505 | session = clp->cl_session; |
| 5506 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5507 | return 0; |
| 5508 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5509 | rsize = server->rsize; |
| 5510 | if (rsize == 0) |
| 5511 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5512 | wsize = server->wsize; |
| 5513 | if (wsize == 0) |
| 5514 | wsize = NFS_MAX_FILE_IO_SIZE; |
| 5515 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5516 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5517 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5518 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5519 | ret = nfs4_recover_expired_lease(server); |
| 5520 | if (!ret) |
| 5521 | ret = nfs4_check_client_ready(clp); |
| 5522 | return ret; |
| 5523 | } |
| 5524 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5525 | int nfs4_init_ds_session(struct nfs_client *clp) |
| 5526 | { |
| 5527 | struct nfs4_session *session = clp->cl_session; |
| 5528 | int ret; |
| 5529 | |
| 5530 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5531 | return 0; |
| 5532 | |
| 5533 | ret = nfs4_client_recover_expired_lease(clp); |
| 5534 | if (!ret) |
| 5535 | /* Test for the DS role */ |
| 5536 | if (!is_ds_client(clp)) |
| 5537 | ret = -ENODEV; |
| 5538 | if (!ret) |
| 5539 | ret = nfs4_check_client_ready(clp); |
| 5540 | return ret; |
| 5541 | |
| 5542 | } |
| 5543 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 5544 | |
| 5545 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5546 | /* |
| 5547 | * Renew the cl_session lease. |
| 5548 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5549 | struct nfs4_sequence_data { |
| 5550 | struct nfs_client *clp; |
| 5551 | struct nfs4_sequence_args args; |
| 5552 | struct nfs4_sequence_res res; |
| 5553 | }; |
| 5554 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5555 | static void nfs41_sequence_release(void *data) |
| 5556 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5557 | struct nfs4_sequence_data *calldata = data; |
| 5558 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5559 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5560 | if (atomic_read(&clp->cl_count) > 1) |
| 5561 | nfs4_schedule_state_renewal(clp); |
| 5562 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5563 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5564 | } |
| 5565 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5566 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5567 | { |
| 5568 | switch(task->tk_status) { |
| 5569 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5570 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5571 | return -EAGAIN; |
| 5572 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5573 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5574 | } |
| 5575 | return 0; |
| 5576 | } |
| 5577 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5578 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5579 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5580 | struct nfs4_sequence_data *calldata = data; |
| 5581 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5582 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5583 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5584 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5585 | |
| 5586 | if (task->tk_status < 0) { |
| 5587 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5588 | if (atomic_read(&clp->cl_count) == 1) |
| 5589 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5590 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5591 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5592 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5593 | return; |
| 5594 | } |
| 5595 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5596 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5597 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5598 | dprintk("<-- %s\n", __func__); |
| 5599 | } |
| 5600 | |
| 5601 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5602 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5603 | struct nfs4_sequence_data *calldata = data; |
| 5604 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5605 | struct nfs4_sequence_args *args; |
| 5606 | struct nfs4_sequence_res *res; |
| 5607 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5608 | args = task->tk_msg.rpc_argp; |
| 5609 | res = task->tk_msg.rpc_resp; |
| 5610 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5611 | if (nfs41_setup_sequence(clp->cl_session, args, res, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5612 | return; |
| 5613 | rpc_call_start(task); |
| 5614 | } |
| 5615 | |
| 5616 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5617 | .rpc_call_done = nfs41_sequence_call_done, |
| 5618 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5619 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5620 | }; |
| 5621 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5622 | 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] | 5623 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5624 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5625 | struct rpc_message msg = { |
| 5626 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5627 | .rpc_cred = cred, |
| 5628 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5629 | struct rpc_task_setup task_setup_data = { |
| 5630 | .rpc_client = clp->cl_rpcclient, |
| 5631 | .rpc_message = &msg, |
| 5632 | .callback_ops = &nfs41_sequence_ops, |
| 5633 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5634 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5635 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5636 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5637 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5638 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5639 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5640 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5641 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5642 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5643 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5644 | msg.rpc_argp = &calldata->args; |
| 5645 | msg.rpc_resp = &calldata->res; |
| 5646 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5647 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5648 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5649 | return rpc_run_task(&task_setup_data); |
| 5650 | } |
| 5651 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5652 | 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] | 5653 | { |
| 5654 | struct rpc_task *task; |
| 5655 | int ret = 0; |
| 5656 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5657 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 5658 | return 0; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5659 | task = _nfs41_proc_sequence(clp, cred); |
| 5660 | if (IS_ERR(task)) |
| 5661 | ret = PTR_ERR(task); |
| 5662 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5663 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5664 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5665 | return ret; |
| 5666 | } |
| 5667 | |
| 5668 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5669 | { |
| 5670 | struct rpc_task *task; |
| 5671 | int ret; |
| 5672 | |
| 5673 | task = _nfs41_proc_sequence(clp, cred); |
| 5674 | if (IS_ERR(task)) { |
| 5675 | ret = PTR_ERR(task); |
| 5676 | goto out; |
| 5677 | } |
| 5678 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5679 | if (!ret) { |
| 5680 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5681 | |
| 5682 | if (task->tk_status == 0) |
| 5683 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5684 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5685 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5686 | rpc_put_task(task); |
| 5687 | out: |
| 5688 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5689 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5690 | } |
| 5691 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5692 | struct nfs4_reclaim_complete_data { |
| 5693 | struct nfs_client *clp; |
| 5694 | struct nfs41_reclaim_complete_args arg; |
| 5695 | struct nfs41_reclaim_complete_res res; |
| 5696 | }; |
| 5697 | |
| 5698 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5699 | { |
| 5700 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5701 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5702 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5703 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5704 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5705 | &calldata->res.seq_res, task)) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5706 | return; |
| 5707 | |
| 5708 | rpc_call_start(task); |
| 5709 | } |
| 5710 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5711 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5712 | { |
| 5713 | switch(task->tk_status) { |
| 5714 | case 0: |
| 5715 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5716 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5717 | break; |
| 5718 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5719 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5720 | /* fall through */ |
| 5721 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5722 | return -EAGAIN; |
| 5723 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5724 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5725 | } |
| 5726 | return 0; |
| 5727 | } |
| 5728 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5729 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5730 | { |
| 5731 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5732 | struct nfs_client *clp = calldata->clp; |
| 5733 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5734 | |
| 5735 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5736 | if (!nfs41_sequence_done(task, res)) |
| 5737 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5738 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5739 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5740 | rpc_restart_call_prepare(task); |
| 5741 | return; |
| 5742 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5743 | dprintk("<-- %s\n", __func__); |
| 5744 | } |
| 5745 | |
| 5746 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5747 | { |
| 5748 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5749 | |
| 5750 | kfree(calldata); |
| 5751 | } |
| 5752 | |
| 5753 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5754 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5755 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5756 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5757 | }; |
| 5758 | |
| 5759 | /* |
| 5760 | * Issue a global reclaim complete. |
| 5761 | */ |
| 5762 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5763 | { |
| 5764 | struct nfs4_reclaim_complete_data *calldata; |
| 5765 | struct rpc_task *task; |
| 5766 | struct rpc_message msg = { |
| 5767 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5768 | }; |
| 5769 | struct rpc_task_setup task_setup_data = { |
| 5770 | .rpc_client = clp->cl_rpcclient, |
| 5771 | .rpc_message = &msg, |
| 5772 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5773 | .flags = RPC_TASK_ASYNC, |
| 5774 | }; |
| 5775 | int status = -ENOMEM; |
| 5776 | |
| 5777 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5778 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5779 | if (calldata == NULL) |
| 5780 | goto out; |
| 5781 | calldata->clp = clp; |
| 5782 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5783 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5784 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5785 | msg.rpc_argp = &calldata->arg; |
| 5786 | msg.rpc_resp = &calldata->res; |
| 5787 | task_setup_data.callback_data = calldata; |
| 5788 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5789 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5790 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5791 | goto out; |
| 5792 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 5793 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5794 | if (status == 0) |
| 5795 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5796 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5797 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5798 | out: |
| 5799 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5800 | return status; |
| 5801 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5802 | |
| 5803 | static void |
| 5804 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 5805 | { |
| 5806 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5807 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5808 | |
| 5809 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5810 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 5811 | * right now covering the LAYOUTGET we are about to send. |
| 5812 | * However, that is not so catastrophic, and there seems |
| 5813 | * to be no way to prevent it completely. |
| 5814 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5815 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5816 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5817 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5818 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 5819 | NFS_I(lgp->args.inode)->layout, |
| 5820 | lgp->args.ctx->state)) { |
| 5821 | rpc_exit(task, NFS4_OK); |
| 5822 | return; |
| 5823 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5824 | rpc_call_start(task); |
| 5825 | } |
| 5826 | |
| 5827 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 5828 | { |
| 5829 | struct nfs4_layoutget *lgp = calldata; |
| 5830 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5831 | |
| 5832 | dprintk("--> %s\n", __func__); |
| 5833 | |
| 5834 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 5835 | return; |
| 5836 | |
| 5837 | switch (task->tk_status) { |
| 5838 | case 0: |
| 5839 | break; |
| 5840 | case -NFS4ERR_LAYOUTTRYLATER: |
| 5841 | case -NFS4ERR_RECALLCONFLICT: |
| 5842 | task->tk_status = -NFS4ERR_DELAY; |
| 5843 | /* Fall through */ |
| 5844 | default: |
| 5845 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5846 | rpc_restart_call_prepare(task); |
| 5847 | return; |
| 5848 | } |
| 5849 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5850 | dprintk("<-- %s\n", __func__); |
| 5851 | } |
| 5852 | |
| 5853 | static void nfs4_layoutget_release(void *calldata) |
| 5854 | { |
| 5855 | struct nfs4_layoutget *lgp = calldata; |
| 5856 | |
| 5857 | dprintk("--> %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5858 | put_nfs_open_context(lgp->args.ctx); |
| 5859 | kfree(calldata); |
| 5860 | dprintk("<-- %s\n", __func__); |
| 5861 | } |
| 5862 | |
| 5863 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 5864 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 5865 | .rpc_call_done = nfs4_layoutget_done, |
| 5866 | .rpc_release = nfs4_layoutget_release, |
| 5867 | }; |
| 5868 | |
| 5869 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) |
| 5870 | { |
| 5871 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5872 | struct rpc_task *task; |
| 5873 | struct rpc_message msg = { |
| 5874 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 5875 | .rpc_argp = &lgp->args, |
| 5876 | .rpc_resp = &lgp->res, |
| 5877 | }; |
| 5878 | struct rpc_task_setup task_setup_data = { |
| 5879 | .rpc_client = server->client, |
| 5880 | .rpc_message = &msg, |
| 5881 | .callback_ops = &nfs4_layoutget_call_ops, |
| 5882 | .callback_data = lgp, |
| 5883 | .flags = RPC_TASK_ASYNC, |
| 5884 | }; |
| 5885 | int status = 0; |
| 5886 | |
| 5887 | dprintk("--> %s\n", __func__); |
| 5888 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 5889 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5890 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5891 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5892 | task = rpc_run_task(&task_setup_data); |
| 5893 | if (IS_ERR(task)) |
| 5894 | return PTR_ERR(task); |
| 5895 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5896 | if (status == 0) |
| 5897 | status = task->tk_status; |
| 5898 | if (status == 0) |
| 5899 | status = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5900 | rpc_put_task(task); |
| 5901 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5902 | return status; |
| 5903 | } |
| 5904 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5905 | static void |
| 5906 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 5907 | { |
| 5908 | struct nfs4_layoutreturn *lrp = calldata; |
| 5909 | |
| 5910 | dprintk("--> %s\n", __func__); |
| 5911 | if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5912 | &lrp->res.seq_res, task)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5913 | return; |
| 5914 | rpc_call_start(task); |
| 5915 | } |
| 5916 | |
| 5917 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 5918 | { |
| 5919 | struct nfs4_layoutreturn *lrp = calldata; |
| 5920 | struct nfs_server *server; |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 5921 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5922 | |
| 5923 | dprintk("--> %s\n", __func__); |
| 5924 | |
| 5925 | if (!nfs4_sequence_done(task, &lrp->res.seq_res)) |
| 5926 | return; |
| 5927 | |
| 5928 | server = NFS_SERVER(lrp->args.inode); |
| 5929 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5930 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5931 | return; |
| 5932 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 5933 | spin_lock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5934 | if (task->tk_status == 0) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5935 | if (lrp->res.lrs_present) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5936 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5937 | } else |
| 5938 | BUG_ON(!list_empty(&lo->plh_segs)); |
| 5939 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 5940 | lo->plh_block_lgets--; |
| 5941 | spin_unlock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5942 | dprintk("<-- %s\n", __func__); |
| 5943 | } |
| 5944 | |
| 5945 | static void nfs4_layoutreturn_release(void *calldata) |
| 5946 | { |
| 5947 | struct nfs4_layoutreturn *lrp = calldata; |
| 5948 | |
| 5949 | dprintk("--> %s\n", __func__); |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 5950 | put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5951 | kfree(calldata); |
| 5952 | dprintk("<-- %s\n", __func__); |
| 5953 | } |
| 5954 | |
| 5955 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 5956 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 5957 | .rpc_call_done = nfs4_layoutreturn_done, |
| 5958 | .rpc_release = nfs4_layoutreturn_release, |
| 5959 | }; |
| 5960 | |
| 5961 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 5962 | { |
| 5963 | struct rpc_task *task; |
| 5964 | struct rpc_message msg = { |
| 5965 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 5966 | .rpc_argp = &lrp->args, |
| 5967 | .rpc_resp = &lrp->res, |
| 5968 | }; |
| 5969 | struct rpc_task_setup task_setup_data = { |
| 5970 | .rpc_client = lrp->clp->cl_rpcclient, |
| 5971 | .rpc_message = &msg, |
| 5972 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 5973 | .callback_data = lrp, |
| 5974 | }; |
| 5975 | int status; |
| 5976 | |
| 5977 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5978 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5979 | task = rpc_run_task(&task_setup_data); |
| 5980 | if (IS_ERR(task)) |
| 5981 | return PTR_ERR(task); |
| 5982 | status = task->tk_status; |
| 5983 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5984 | rpc_put_task(task); |
| 5985 | return status; |
| 5986 | } |
| 5987 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 5988 | /* |
| 5989 | * Retrieve the list of Data Server devices from the MDS. |
| 5990 | */ |
| 5991 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 5992 | const struct nfs_fh *fh, |
| 5993 | struct pnfs_devicelist *devlist) |
| 5994 | { |
| 5995 | struct nfs4_getdevicelist_args args = { |
| 5996 | .fh = fh, |
| 5997 | .layoutclass = server->pnfs_curr_ld->id, |
| 5998 | }; |
| 5999 | struct nfs4_getdevicelist_res res = { |
| 6000 | .devlist = devlist, |
| 6001 | }; |
| 6002 | struct rpc_message msg = { |
| 6003 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6004 | .rpc_argp = &args, |
| 6005 | .rpc_resp = &res, |
| 6006 | }; |
| 6007 | int status; |
| 6008 | |
| 6009 | dprintk("--> %s\n", __func__); |
| 6010 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6011 | &res.seq_res, 0); |
| 6012 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6013 | return status; |
| 6014 | } |
| 6015 | |
| 6016 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6017 | const struct nfs_fh *fh, |
| 6018 | struct pnfs_devicelist *devlist) |
| 6019 | { |
| 6020 | struct nfs4_exception exception = { }; |
| 6021 | int err; |
| 6022 | |
| 6023 | do { |
| 6024 | err = nfs4_handle_exception(server, |
| 6025 | _nfs4_getdevicelist(server, fh, devlist), |
| 6026 | &exception); |
| 6027 | } while (exception.retry); |
| 6028 | |
| 6029 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6030 | err, devlist->num_devs); |
| 6031 | |
| 6032 | return err; |
| 6033 | } |
| 6034 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6035 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6036 | static int |
| 6037 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6038 | { |
| 6039 | struct nfs4_getdeviceinfo_args args = { |
| 6040 | .pdev = pdev, |
| 6041 | }; |
| 6042 | struct nfs4_getdeviceinfo_res res = { |
| 6043 | .pdev = pdev, |
| 6044 | }; |
| 6045 | struct rpc_message msg = { |
| 6046 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6047 | .rpc_argp = &args, |
| 6048 | .rpc_resp = &res, |
| 6049 | }; |
| 6050 | int status; |
| 6051 | |
| 6052 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6053 | 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] | 6054 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6055 | |
| 6056 | return status; |
| 6057 | } |
| 6058 | |
| 6059 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6060 | { |
| 6061 | struct nfs4_exception exception = { }; |
| 6062 | int err; |
| 6063 | |
| 6064 | do { |
| 6065 | err = nfs4_handle_exception(server, |
| 6066 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6067 | &exception); |
| 6068 | } while (exception.retry); |
| 6069 | return err; |
| 6070 | } |
| 6071 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6072 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6073 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6074 | { |
| 6075 | struct nfs4_layoutcommit_data *data = calldata; |
| 6076 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6077 | |
| 6078 | if (nfs4_setup_sequence(server, &data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6079 | &data->res.seq_res, task)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6080 | return; |
| 6081 | rpc_call_start(task); |
| 6082 | } |
| 6083 | |
| 6084 | static void |
| 6085 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6086 | { |
| 6087 | struct nfs4_layoutcommit_data *data = calldata; |
| 6088 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6089 | |
| 6090 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6091 | return; |
| 6092 | |
| 6093 | switch (task->tk_status) { /* Just ignore these failures */ |
| 6094 | case NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6095 | case NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6096 | case NFS4ERR_BADLAYOUT: /* no layout */ |
| 6097 | case NFS4ERR_GRACE: /* loca_recalim always false */ |
| 6098 | task->tk_status = 0; |
| 6099 | } |
| 6100 | |
| 6101 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6102 | rpc_restart_call_prepare(task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6103 | return; |
| 6104 | } |
| 6105 | |
| 6106 | if (task->tk_status == 0) |
| 6107 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6108 | data->res.fattr); |
| 6109 | } |
| 6110 | |
| 6111 | static void nfs4_layoutcommit_release(void *calldata) |
| 6112 | { |
| 6113 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6114 | struct pnfs_layout_segment *lseg, *tmp; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6115 | unsigned long *bitlock = &NFS_I(data->args.inode)->flags; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6116 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6117 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6118 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6119 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 6120 | list_del_init(&lseg->pls_lc_list); |
| 6121 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 6122 | &lseg->pls_flags)) |
| 6123 | put_lseg(lseg); |
| 6124 | } |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6125 | |
| 6126 | clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); |
| 6127 | smp_mb__after_clear_bit(); |
| 6128 | wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING); |
| 6129 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6130 | put_rpccred(data->cred); |
| 6131 | kfree(data); |
| 6132 | } |
| 6133 | |
| 6134 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6135 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6136 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6137 | .rpc_release = nfs4_layoutcommit_release, |
| 6138 | }; |
| 6139 | |
| 6140 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6141 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6142 | { |
| 6143 | struct rpc_message msg = { |
| 6144 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6145 | .rpc_argp = &data->args, |
| 6146 | .rpc_resp = &data->res, |
| 6147 | .rpc_cred = data->cred, |
| 6148 | }; |
| 6149 | struct rpc_task_setup task_setup_data = { |
| 6150 | .task = &data->task, |
| 6151 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6152 | .rpc_message = &msg, |
| 6153 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6154 | .callback_data = data, |
| 6155 | .flags = RPC_TASK_ASYNC, |
| 6156 | }; |
| 6157 | struct rpc_task *task; |
| 6158 | int status = 0; |
| 6159 | |
| 6160 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6161 | "lbw: %llu inode %lu\n", |
| 6162 | data->task.tk_pid, sync, |
| 6163 | data->args.lastbytewritten, |
| 6164 | data->args.inode->i_ino); |
| 6165 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6166 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6167 | task = rpc_run_task(&task_setup_data); |
| 6168 | if (IS_ERR(task)) |
| 6169 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6170 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6171 | goto out; |
| 6172 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6173 | if (status != 0) |
| 6174 | goto out; |
| 6175 | status = task->tk_status; |
| 6176 | out: |
| 6177 | dprintk("%s: status %d\n", __func__, status); |
| 6178 | rpc_put_task(task); |
| 6179 | return status; |
| 6180 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6181 | |
| 6182 | static int |
| 6183 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6184 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6185 | { |
| 6186 | struct nfs41_secinfo_no_name_args args = { |
| 6187 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6188 | }; |
| 6189 | struct nfs4_secinfo_res res = { |
| 6190 | .flavors = flavors, |
| 6191 | }; |
| 6192 | struct rpc_message msg = { |
| 6193 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6194 | .rpc_argp = &args, |
| 6195 | .rpc_resp = &res, |
| 6196 | }; |
| 6197 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6198 | } |
| 6199 | |
| 6200 | static int |
| 6201 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6202 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6203 | { |
| 6204 | struct nfs4_exception exception = { }; |
| 6205 | int err; |
| 6206 | do { |
| 6207 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6208 | switch (err) { |
| 6209 | case 0: |
| 6210 | case -NFS4ERR_WRONGSEC: |
| 6211 | case -NFS4ERR_NOTSUPP: |
| 6212 | break; |
| 6213 | default: |
| 6214 | err = nfs4_handle_exception(server, err, &exception); |
| 6215 | } |
| 6216 | } while (exception.retry); |
| 6217 | return err; |
| 6218 | } |
| 6219 | |
| 6220 | static int |
| 6221 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6222 | struct nfs_fsinfo *info) |
| 6223 | { |
| 6224 | int err; |
| 6225 | struct page *page; |
| 6226 | rpc_authflavor_t flavor; |
| 6227 | struct nfs4_secinfo_flavors *flavors; |
| 6228 | |
| 6229 | page = alloc_page(GFP_KERNEL); |
| 6230 | if (!page) { |
| 6231 | err = -ENOMEM; |
| 6232 | goto out; |
| 6233 | } |
| 6234 | |
| 6235 | flavors = page_address(page); |
| 6236 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6237 | |
| 6238 | /* |
| 6239 | * Fall back on "guess and check" method if |
| 6240 | * the server doesn't support SECINFO_NO_NAME |
| 6241 | */ |
| 6242 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6243 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6244 | goto out_freepage; |
| 6245 | } |
| 6246 | if (err) |
| 6247 | goto out_freepage; |
| 6248 | |
| 6249 | flavor = nfs_find_best_sec(flavors); |
| 6250 | if (err == 0) |
| 6251 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6252 | |
| 6253 | out_freepage: |
| 6254 | put_page(page); |
| 6255 | if (err == -EACCES) |
| 6256 | return -EPERM; |
| 6257 | out: |
| 6258 | return err; |
| 6259 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6260 | |
| 6261 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6262 | { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6263 | int status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6264 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6265 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6266 | }; |
| 6267 | struct nfs41_test_stateid_res res; |
| 6268 | struct rpc_message msg = { |
| 6269 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6270 | .rpc_argp = &args, |
| 6271 | .rpc_resp = &res, |
| 6272 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6273 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6274 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6275 | status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
| 6276 | |
| 6277 | if (status == NFS_OK) |
| 6278 | return res.status; |
| 6279 | return status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6280 | } |
| 6281 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6282 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6283 | { |
| 6284 | struct nfs4_exception exception = { }; |
| 6285 | int err; |
| 6286 | do { |
| 6287 | err = nfs4_handle_exception(server, |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6288 | _nfs41_test_stateid(server, stateid), |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6289 | &exception); |
| 6290 | } while (exception.retry); |
| 6291 | return err; |
| 6292 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6293 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6294 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6295 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6296 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6297 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6298 | }; |
| 6299 | struct nfs41_free_stateid_res res; |
| 6300 | struct rpc_message msg = { |
| 6301 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6302 | .rpc_argp = &args, |
| 6303 | .rpc_resp = &res, |
| 6304 | }; |
| 6305 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6306 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6307 | return nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6308 | } |
| 6309 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6310 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6311 | { |
| 6312 | struct nfs4_exception exception = { }; |
| 6313 | int err; |
| 6314 | do { |
| 6315 | err = nfs4_handle_exception(server, |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6316 | _nfs4_free_stateid(server, stateid), |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6317 | &exception); |
| 6318 | } while (exception.retry); |
| 6319 | return err; |
| 6320 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6321 | |
| 6322 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6323 | const nfs4_stateid *s2) |
| 6324 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6325 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6326 | return false; |
| 6327 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6328 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6329 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6330 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6331 | return true; |
| 6332 | |
| 6333 | return false; |
| 6334 | } |
| 6335 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6336 | #endif /* CONFIG_NFS_V4_1 */ |
| 6337 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6338 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 6339 | const nfs4_stateid *s2) |
| 6340 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6341 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6342 | } |
| 6343 | |
| 6344 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6345 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6346 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6347 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6348 | .recover_open = nfs4_open_reclaim, |
| 6349 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6350 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6351 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6352 | }; |
| 6353 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6354 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6355 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6356 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6357 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6358 | .recover_open = nfs4_open_reclaim, |
| 6359 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6360 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6361 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6362 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6363 | }; |
| 6364 | #endif /* CONFIG_NFS_V4_1 */ |
| 6365 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6366 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6367 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6368 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6369 | .recover_open = nfs4_open_expired, |
| 6370 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6371 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6372 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6373 | }; |
| 6374 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6375 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6376 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6377 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6378 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6379 | .recover_open = nfs41_open_expired, |
| 6380 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6381 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6382 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6383 | }; |
| 6384 | #endif /* CONFIG_NFS_V4_1 */ |
| 6385 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6386 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6387 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6388 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6389 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6390 | }; |
| 6391 | |
| 6392 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6393 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6394 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6395 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6396 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6397 | }; |
| 6398 | #endif |
| 6399 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6400 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6401 | .minor_version = 0, |
| 6402 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6403 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6404 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6405 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6406 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6407 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6408 | }; |
| 6409 | |
| 6410 | #if defined(CONFIG_NFS_V4_1) |
| 6411 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6412 | .minor_version = 1, |
| 6413 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6414 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6415 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6416 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6417 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6418 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6419 | }; |
| 6420 | #endif |
| 6421 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6422 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6423 | [0] = &nfs_v4_0_minor_ops, |
| 6424 | #if defined(CONFIG_NFS_V4_1) |
| 6425 | [1] = &nfs_v4_1_minor_ops, |
| 6426 | #endif |
| 6427 | }; |
| 6428 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6429 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6430 | .permission = nfs_permission, |
| 6431 | .getattr = nfs_getattr, |
| 6432 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6433 | .getxattr = generic_getxattr, |
| 6434 | .setxattr = generic_setxattr, |
| 6435 | .listxattr = generic_listxattr, |
| 6436 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6437 | }; |
| 6438 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6439 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6440 | .version = 4, /* protocol version */ |
| 6441 | .dentry_ops = &nfs4_dentry_operations, |
| 6442 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6443 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 6444 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6445 | .getroot = nfs4_proc_get_root, |
| 6446 | .getattr = nfs4_proc_getattr, |
| 6447 | .setattr = nfs4_proc_setattr, |
| 6448 | .lookup = nfs4_proc_lookup, |
| 6449 | .access = nfs4_proc_access, |
| 6450 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6451 | .create = nfs4_proc_create, |
| 6452 | .remove = nfs4_proc_remove, |
| 6453 | .unlink_setup = nfs4_proc_unlink_setup, |
| 6454 | .unlink_done = nfs4_proc_unlink_done, |
| 6455 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6456 | .rename_setup = nfs4_proc_rename_setup, |
| 6457 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6458 | .link = nfs4_proc_link, |
| 6459 | .symlink = nfs4_proc_symlink, |
| 6460 | .mkdir = nfs4_proc_mkdir, |
| 6461 | .rmdir = nfs4_proc_remove, |
| 6462 | .readdir = nfs4_proc_readdir, |
| 6463 | .mknod = nfs4_proc_mknod, |
| 6464 | .statfs = nfs4_proc_statfs, |
| 6465 | .fsinfo = nfs4_proc_fsinfo, |
| 6466 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6467 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6468 | .decode_dirent = nfs4_decode_dirent, |
| 6469 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame^] | 6470 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6471 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6472 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 6473 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6474 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6475 | .commit_setup = nfs4_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6476 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6477 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6478 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6479 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6480 | .open_context = nfs4_atomic_open, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6481 | .init_client = nfs4_init_client, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6482 | .secinfo = nfs4_proc_secinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6483 | }; |
| 6484 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6485 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6486 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6487 | .list = nfs4_xattr_list_nfs4_acl, |
| 6488 | .get = nfs4_xattr_get_nfs4_acl, |
| 6489 | .set = nfs4_xattr_set_nfs4_acl, |
| 6490 | }; |
| 6491 | |
| 6492 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6493 | &nfs4_xattr_nfs4_acl_handler, |
| 6494 | NULL |
| 6495 | }; |
| 6496 | |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 6497 | module_param(max_session_slots, ushort, 0644); |
| 6498 | MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 " |
| 6499 | "requests the client will negotiate"); |
| 6500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6501 | /* |
| 6502 | * Local variables: |
| 6503 | * c-basic-offset: 8 |
| 6504 | * End: |
| 6505 | */ |