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> |
| 42 | #include <linux/sunrpc/clnt.h> |
| 43 | #include <linux/nfs.h> |
| 44 | #include <linux/nfs4.h> |
| 45 | #include <linux/nfs_fs.h> |
| 46 | #include <linux/nfs_page.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 48 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 49 | #include <linux/module.h> |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 50 | #include <linux/sunrpc/bc_xprt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 52 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 54 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 55 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 56 | #include "callback.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 59 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 60 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 62 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 63 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 64 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 65 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 66 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | 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] | 68 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 69 | static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
| 70 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 73 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { |
| 75 | if (err < -1000) { |
| 76 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 77 | __func__, -err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | return -EIO; |
| 79 | } |
| 80 | return err; |
| 81 | } |
| 82 | |
| 83 | /* |
| 84 | * This is our standard bitmap for GETATTR requests. |
| 85 | */ |
| 86 | const u32 nfs4_fattr_bitmap[2] = { |
| 87 | FATTR4_WORD0_TYPE |
| 88 | | FATTR4_WORD0_CHANGE |
| 89 | | FATTR4_WORD0_SIZE |
| 90 | | FATTR4_WORD0_FSID |
| 91 | | FATTR4_WORD0_FILEID, |
| 92 | FATTR4_WORD1_MODE |
| 93 | | FATTR4_WORD1_NUMLINKS |
| 94 | | FATTR4_WORD1_OWNER |
| 95 | | FATTR4_WORD1_OWNER_GROUP |
| 96 | | FATTR4_WORD1_RAWDEV |
| 97 | | FATTR4_WORD1_SPACE_USED |
| 98 | | FATTR4_WORD1_TIME_ACCESS |
| 99 | | FATTR4_WORD1_TIME_METADATA |
| 100 | | FATTR4_WORD1_TIME_MODIFY |
| 101 | }; |
| 102 | |
| 103 | const u32 nfs4_statfs_bitmap[2] = { |
| 104 | FATTR4_WORD0_FILES_AVAIL |
| 105 | | FATTR4_WORD0_FILES_FREE |
| 106 | | FATTR4_WORD0_FILES_TOTAL, |
| 107 | FATTR4_WORD1_SPACE_AVAIL |
| 108 | | FATTR4_WORD1_SPACE_FREE |
| 109 | | FATTR4_WORD1_SPACE_TOTAL |
| 110 | }; |
| 111 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 112 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | FATTR4_WORD0_MAXLINK |
| 114 | | FATTR4_WORD0_MAXNAME, |
| 115 | 0 |
| 116 | }; |
| 117 | |
| 118 | const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE |
| 119 | | FATTR4_WORD0_MAXREAD |
| 120 | | FATTR4_WORD0_MAXWRITE |
| 121 | | FATTR4_WORD0_LEASE_TIME, |
| 122 | 0 |
| 123 | }; |
| 124 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 125 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 126 | FATTR4_WORD0_TYPE |
| 127 | | FATTR4_WORD0_CHANGE |
| 128 | | FATTR4_WORD0_SIZE |
| 129 | | FATTR4_WORD0_FSID |
| 130 | | FATTR4_WORD0_FILEID |
| 131 | | FATTR4_WORD0_FS_LOCATIONS, |
| 132 | FATTR4_WORD1_MODE |
| 133 | | FATTR4_WORD1_NUMLINKS |
| 134 | | FATTR4_WORD1_OWNER |
| 135 | | FATTR4_WORD1_OWNER_GROUP |
| 136 | | FATTR4_WORD1_RAWDEV |
| 137 | | FATTR4_WORD1_SPACE_USED |
| 138 | | FATTR4_WORD1_TIME_ACCESS |
| 139 | | FATTR4_WORD1_TIME_METADATA |
| 140 | | FATTR4_WORD1_TIME_MODIFY |
| 141 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 142 | }; |
| 143 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 144 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | struct nfs4_readdir_arg *readdir) |
| 146 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 147 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
| 149 | BUG_ON(readdir->count < 80); |
| 150 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 151 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 153 | return; |
| 154 | } |
| 155 | |
| 156 | readdir->cookie = 0; |
| 157 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 158 | if (cookie == 2) |
| 159 | return; |
| 160 | |
| 161 | /* |
| 162 | * NFSv4 servers do not return entries for '.' and '..' |
| 163 | * Therefore, we fake these entries here. We let '.' |
| 164 | * have cookie 0 and '..' have cookie 1. Note that |
| 165 | * when talking to the server, we always send cookie 0 |
| 166 | * instead of 1 or 2. |
| 167 | */ |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 168 | start = p = kmap_atomic(*readdir->pages, KM_USER0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
| 170 | if (cookie == 0) { |
| 171 | *p++ = xdr_one; /* next */ |
| 172 | *p++ = xdr_zero; /* cookie, first word */ |
| 173 | *p++ = xdr_one; /* cookie, second word */ |
| 174 | *p++ = xdr_one; /* entry len */ |
| 175 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 176 | p++; |
| 177 | *p++ = xdr_one; /* bitmap length */ |
| 178 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 179 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 180 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | *p++ = xdr_one; /* next */ |
| 184 | *p++ = xdr_zero; /* cookie, first word */ |
| 185 | *p++ = xdr_two; /* cookie, second word */ |
| 186 | *p++ = xdr_two; /* entry len */ |
| 187 | memcpy(p, "..\0\0", 4); /* entry */ |
| 188 | p++; |
| 189 | *p++ = xdr_one; /* bitmap length */ |
| 190 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 191 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 192 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
| 194 | readdir->pgbase = (char *)p - (char *)start; |
| 195 | readdir->count -= readdir->pgbase; |
| 196 | kunmap_atomic(start, KM_USER0); |
| 197 | } |
| 198 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 199 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 200 | { |
| 201 | int res; |
| 202 | |
| 203 | might_sleep(); |
| 204 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 205 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 206 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 207 | return res; |
| 208 | } |
| 209 | |
| 210 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 211 | { |
| 212 | int res = 0; |
| 213 | |
| 214 | might_sleep(); |
| 215 | |
| 216 | if (*timeout <= 0) |
| 217 | *timeout = NFS4_POLL_RETRY_MIN; |
| 218 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 219 | *timeout = NFS4_POLL_RETRY_MAX; |
| 220 | schedule_timeout_killable(*timeout); |
| 221 | if (fatal_signal_pending(current)) |
| 222 | res = -ERESTARTSYS; |
| 223 | *timeout <<= 1; |
| 224 | return res; |
| 225 | } |
| 226 | |
| 227 | /* This is the error handling routine for processes that are allowed |
| 228 | * to sleep. |
| 229 | */ |
| 230 | static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 231 | { |
| 232 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 233 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 234 | int ret = errorcode; |
| 235 | |
| 236 | exception->retry = 0; |
| 237 | switch(errorcode) { |
| 238 | case 0: |
| 239 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 240 | case -NFS4ERR_ADMIN_REVOKED: |
| 241 | case -NFS4ERR_BAD_STATEID: |
| 242 | case -NFS4ERR_OPENMODE: |
| 243 | if (state == NULL) |
| 244 | break; |
| 245 | nfs4_state_mark_reclaim_nograce(clp, state); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 246 | case -NFS4ERR_STALE_CLIENTID: |
| 247 | case -NFS4ERR_STALE_STATEID: |
| 248 | case -NFS4ERR_EXPIRED: |
| 249 | nfs4_schedule_state_recovery(clp); |
| 250 | ret = nfs4_wait_clnt_recover(clp); |
| 251 | if (ret == 0) |
| 252 | exception->retry = 1; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 253 | #if !defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 254 | break; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 255 | #else /* !defined(CONFIG_NFS_V4_1) */ |
| 256 | if (!nfs4_has_session(server->nfs_client)) |
| 257 | break; |
| 258 | /* FALLTHROUGH */ |
| 259 | case -NFS4ERR_BADSESSION: |
| 260 | case -NFS4ERR_BADSLOT: |
| 261 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 262 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 263 | case -NFS4ERR_DEADSESSION: |
| 264 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 265 | case -NFS4ERR_SEQ_MISORDERED: |
| 266 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 267 | errorcode); |
| 268 | set_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state); |
| 269 | exception->retry = 1; |
| 270 | /* FALLTHROUGH */ |
| 271 | #endif /* !defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 272 | case -NFS4ERR_FILE_OPEN: |
| 273 | case -NFS4ERR_GRACE: |
| 274 | case -NFS4ERR_DELAY: |
| 275 | ret = nfs4_delay(server->client, &exception->timeout); |
| 276 | if (ret != 0) |
| 277 | break; |
| 278 | case -NFS4ERR_OLD_STATEID: |
| 279 | exception->retry = 1; |
| 280 | } |
| 281 | /* We failed to handle the error */ |
| 282 | return nfs4_map_errors(ret); |
| 283 | } |
| 284 | |
| 285 | |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 286 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | { |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 288 | struct nfs_client *clp = server->nfs_client; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | spin_lock(&clp->cl_lock); |
| 290 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 291 | clp->cl_last_renewal = timestamp; |
| 292 | spin_unlock(&clp->cl_lock); |
| 293 | } |
| 294 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 295 | #if defined(CONFIG_NFS_V4_1) |
| 296 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 297 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 298 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 299 | * |
| 300 | * freeing a slot is trivially done by clearing its respective bit |
| 301 | * in the bitmap. |
| 302 | * If the freed slotid equals highest_used_slotid we want to update it |
| 303 | * so that the server would be able to size down the slot table if needed, |
| 304 | * otherwise we know that the highest_used_slotid is still in use. |
| 305 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 306 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 307 | * highest slotid in use. |
| 308 | * If none found, highest_used_slotid is set to -1. |
| 309 | */ |
| 310 | static void |
| 311 | nfs4_free_slot(struct nfs4_slot_table *tbl, u8 free_slotid) |
| 312 | { |
| 313 | int slotid = free_slotid; |
| 314 | |
| 315 | spin_lock(&tbl->slot_tbl_lock); |
| 316 | /* clear used bit in bitmap */ |
| 317 | __clear_bit(slotid, tbl->used_slots); |
| 318 | |
| 319 | /* update highest_used_slotid when it is freed */ |
| 320 | if (slotid == tbl->highest_used_slotid) { |
| 321 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
| 322 | if (slotid >= 0 && slotid < tbl->max_slots) |
| 323 | tbl->highest_used_slotid = slotid; |
| 324 | else |
| 325 | tbl->highest_used_slotid = -1; |
| 326 | } |
| 327 | rpc_wake_up_next(&tbl->slot_tbl_waitq); |
| 328 | spin_unlock(&tbl->slot_tbl_lock); |
| 329 | dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__, |
| 330 | free_slotid, tbl->highest_used_slotid); |
| 331 | } |
| 332 | |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 333 | void nfs41_sequence_free_slot(const struct nfs_client *clp, |
| 334 | struct nfs4_sequence_res *res) |
| 335 | { |
| 336 | struct nfs4_slot_table *tbl; |
| 337 | |
| 338 | if (!nfs4_has_session(clp)) { |
| 339 | dprintk("%s: No session\n", __func__); |
| 340 | return; |
| 341 | } |
| 342 | tbl = &clp->cl_session->fc_slot_table; |
| 343 | if (res->sr_slotid == NFS4_MAX_SLOT_TABLE) { |
| 344 | dprintk("%s: No slot\n", __func__); |
| 345 | /* just wake up the next guy waiting since |
| 346 | * we may have not consumed a slot after all */ |
| 347 | rpc_wake_up_next(&tbl->slot_tbl_waitq); |
| 348 | return; |
| 349 | } |
| 350 | nfs4_free_slot(tbl, res->sr_slotid); |
| 351 | res->sr_slotid = NFS4_MAX_SLOT_TABLE; |
| 352 | } |
| 353 | |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 354 | static void nfs41_sequence_done(struct nfs_client *clp, |
| 355 | struct nfs4_sequence_res *res, |
| 356 | int rpc_status) |
| 357 | { |
| 358 | unsigned long timestamp; |
| 359 | struct nfs4_slot_table *tbl; |
| 360 | struct nfs4_slot *slot; |
| 361 | |
| 362 | /* |
| 363 | * sr_status remains 1 if an RPC level error occurred. The server |
| 364 | * may or may not have processed the sequence operation.. |
| 365 | * Proceed as if the server received and processed the sequence |
| 366 | * operation. |
| 367 | */ |
| 368 | if (res->sr_status == 1) |
| 369 | res->sr_status = NFS_OK; |
| 370 | |
| 371 | /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */ |
| 372 | if (res->sr_slotid == NFS4_MAX_SLOT_TABLE) |
| 373 | goto out; |
| 374 | |
| 375 | tbl = &clp->cl_session->fc_slot_table; |
| 376 | slot = tbl->slots + res->sr_slotid; |
| 377 | |
| 378 | if (res->sr_status == 0) { |
| 379 | /* Update the slot's sequence and clientid lease timer */ |
| 380 | ++slot->seq_nr; |
| 381 | timestamp = res->sr_renewal_time; |
| 382 | spin_lock(&clp->cl_lock); |
| 383 | if (time_before(clp->cl_last_renewal, timestamp)) |
| 384 | clp->cl_last_renewal = timestamp; |
| 385 | spin_unlock(&clp->cl_lock); |
| 386 | return; |
| 387 | } |
| 388 | out: |
| 389 | /* The session may be reset by one of the error handlers. */ |
| 390 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
| 391 | nfs41_sequence_free_slot(clp, res); |
| 392 | } |
| 393 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 394 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 395 | * nfs4_find_slot - efficiently look for a free slot |
| 396 | * |
| 397 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 398 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 399 | * and respectively set up the sequence operation args. |
| 400 | * The slot number is returned if found, or NFS4_MAX_SLOT_TABLE otherwise. |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 401 | * |
| 402 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 403 | */ |
| 404 | static u8 |
| 405 | nfs4_find_slot(struct nfs4_slot_table *tbl, struct rpc_task *task) |
| 406 | { |
| 407 | int slotid; |
| 408 | u8 ret_id = NFS4_MAX_SLOT_TABLE; |
| 409 | BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE); |
| 410 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 411 | dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n", |
| 412 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 413 | tbl->max_slots); |
| 414 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 415 | if (slotid >= tbl->max_slots) |
| 416 | goto out; |
| 417 | __set_bit(slotid, tbl->used_slots); |
| 418 | if (slotid > tbl->highest_used_slotid) |
| 419 | tbl->highest_used_slotid = slotid; |
| 420 | ret_id = slotid; |
| 421 | out: |
| 422 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 423 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 424 | return ret_id; |
| 425 | } |
| 426 | |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 427 | static int nfs4_recover_session(struct nfs4_session *session) |
| 428 | { |
| 429 | struct nfs_client *clp = session->clp; |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 430 | unsigned int loop; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 431 | int ret; |
| 432 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 433 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 434 | ret = nfs4_wait_clnt_recover(clp); |
| 435 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 436 | break; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 437 | if (!test_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state)) |
| 438 | break; |
| 439 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 440 | ret = -EIO; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 441 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 442 | return ret; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 443 | } |
| 444 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 445 | static int nfs41_setup_sequence(struct nfs4_session *session, |
| 446 | struct nfs4_sequence_args *args, |
| 447 | struct nfs4_sequence_res *res, |
| 448 | int cache_reply, |
| 449 | struct rpc_task *task) |
| 450 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 451 | struct nfs4_slot *slot; |
| 452 | struct nfs4_slot_table *tbl; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 453 | int status = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 454 | u8 slotid; |
| 455 | |
| 456 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 457 | /* slot already allocated? */ |
| 458 | if (res->sr_slotid != NFS4_MAX_SLOT_TABLE) |
| 459 | return 0; |
| 460 | |
| 461 | memset(res, 0, sizeof(*res)); |
| 462 | res->sr_slotid = NFS4_MAX_SLOT_TABLE; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 463 | tbl = &session->fc_slot_table; |
| 464 | |
| 465 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 466 | if (test_bit(NFS4CLNT_SESSION_SETUP, &session->clp->cl_state)) { |
| 467 | if (tbl->highest_used_slotid != -1) { |
| 468 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 469 | spin_unlock(&tbl->slot_tbl_lock); |
| 470 | dprintk("<-- %s: Session reset: draining\n", __func__); |
| 471 | return -EAGAIN; |
| 472 | } |
| 473 | |
| 474 | /* The slot table is empty; start the reset thread */ |
| 475 | dprintk("%s Session Reset\n", __func__); |
| 476 | spin_unlock(&tbl->slot_tbl_lock); |
| 477 | status = nfs4_recover_session(session); |
| 478 | if (status) |
| 479 | return status; |
| 480 | spin_lock(&tbl->slot_tbl_lock); |
| 481 | } |
| 482 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 483 | slotid = nfs4_find_slot(tbl, task); |
| 484 | if (slotid == NFS4_MAX_SLOT_TABLE) { |
| 485 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 486 | spin_unlock(&tbl->slot_tbl_lock); |
| 487 | dprintk("<-- %s: no free slots\n", __func__); |
| 488 | return -EAGAIN; |
| 489 | } |
| 490 | spin_unlock(&tbl->slot_tbl_lock); |
| 491 | |
| 492 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 493 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 494 | args->sa_slotid = slotid; |
| 495 | args->sa_cache_this = cache_reply; |
| 496 | |
| 497 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 498 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 499 | res->sr_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 500 | res->sr_slotid = slotid; |
| 501 | res->sr_renewal_time = jiffies; |
| 502 | /* |
| 503 | * sr_status is only set in decode_sequence, and so will remain |
| 504 | * set to 1 if an rpc level failure occurs. |
| 505 | */ |
| 506 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 507 | return 0; |
| 508 | } |
| 509 | |
| 510 | int nfs4_setup_sequence(struct nfs_client *clp, |
| 511 | struct nfs4_sequence_args *args, |
| 512 | struct nfs4_sequence_res *res, |
| 513 | int cache_reply, |
| 514 | struct rpc_task *task) |
| 515 | { |
| 516 | int ret = 0; |
| 517 | |
| 518 | dprintk("--> %s clp %p session %p sr_slotid %d\n", |
| 519 | __func__, clp, clp->cl_session, res->sr_slotid); |
| 520 | |
| 521 | if (!nfs4_has_session(clp)) |
| 522 | goto out; |
| 523 | ret = nfs41_setup_sequence(clp->cl_session, args, res, cache_reply, |
| 524 | task); |
| 525 | if (ret != -EAGAIN) { |
| 526 | /* terminate rpc task */ |
| 527 | task->tk_status = ret; |
| 528 | task->tk_action = NULL; |
| 529 | } |
| 530 | out: |
| 531 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 532 | return ret; |
| 533 | } |
| 534 | |
| 535 | struct nfs41_call_sync_data { |
| 536 | struct nfs_client *clp; |
| 537 | struct nfs4_sequence_args *seq_args; |
| 538 | struct nfs4_sequence_res *seq_res; |
| 539 | int cache_reply; |
| 540 | }; |
| 541 | |
| 542 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 543 | { |
| 544 | struct nfs41_call_sync_data *data = calldata; |
| 545 | |
| 546 | dprintk("--> %s data->clp->cl_session %p\n", __func__, |
| 547 | data->clp->cl_session); |
| 548 | if (nfs4_setup_sequence(data->clp, data->seq_args, |
| 549 | data->seq_res, data->cache_reply, task)) |
| 550 | return; |
| 551 | rpc_call_start(task); |
| 552 | } |
| 553 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 554 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 555 | { |
| 556 | struct nfs41_call_sync_data *data = calldata; |
| 557 | |
| 558 | nfs41_sequence_done(data->clp, data->seq_res, task->tk_status); |
| 559 | nfs41_sequence_free_slot(data->clp, data->seq_res); |
| 560 | } |
| 561 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 562 | struct rpc_call_ops nfs41_call_sync_ops = { |
| 563 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 564 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 565 | }; |
| 566 | |
| 567 | static int nfs4_call_sync_sequence(struct nfs_client *clp, |
| 568 | struct rpc_clnt *clnt, |
| 569 | struct rpc_message *msg, |
| 570 | struct nfs4_sequence_args *args, |
| 571 | struct nfs4_sequence_res *res, |
| 572 | int cache_reply) |
| 573 | { |
| 574 | int ret; |
| 575 | struct rpc_task *task; |
| 576 | struct nfs41_call_sync_data data = { |
| 577 | .clp = clp, |
| 578 | .seq_args = args, |
| 579 | .seq_res = res, |
| 580 | .cache_reply = cache_reply, |
| 581 | }; |
| 582 | struct rpc_task_setup task_setup = { |
| 583 | .rpc_client = clnt, |
| 584 | .rpc_message = msg, |
| 585 | .callback_ops = &nfs41_call_sync_ops, |
| 586 | .callback_data = &data |
| 587 | }; |
| 588 | |
| 589 | res->sr_slotid = NFS4_MAX_SLOT_TABLE; |
| 590 | task = rpc_run_task(&task_setup); |
| 591 | if (IS_ERR(task)) |
| 592 | ret = PTR_ERR(task); |
| 593 | else { |
| 594 | ret = task->tk_status; |
| 595 | rpc_put_task(task); |
| 596 | } |
| 597 | return ret; |
| 598 | } |
| 599 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 600 | int _nfs4_call_sync_session(struct nfs_server *server, |
| 601 | struct rpc_message *msg, |
| 602 | struct nfs4_sequence_args *args, |
| 603 | struct nfs4_sequence_res *res, |
| 604 | int cache_reply) |
| 605 | { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 606 | return nfs4_call_sync_sequence(server->nfs_client, server->client, |
| 607 | msg, args, res, cache_reply); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | #endif /* CONFIG_NFS_V4_1 */ |
| 611 | |
| 612 | int _nfs4_call_sync(struct nfs_server *server, |
| 613 | struct rpc_message *msg, |
| 614 | struct nfs4_sequence_args *args, |
| 615 | struct nfs4_sequence_res *res, |
| 616 | int cache_reply) |
| 617 | { |
Benny Halevy | f375297 | 2009-04-01 09:22:04 -0400 | [diff] [blame] | 618 | args->sa_session = res->sr_session = NULL; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 619 | return rpc_call_sync(server->client, msg, 0); |
| 620 | } |
| 621 | |
| 622 | #define nfs4_call_sync(server, msg, args, res, cache_reply) \ |
| 623 | (server)->nfs_client->cl_call_sync((server), (msg), &(args)->seq_args, \ |
| 624 | &(res)->seq_res, (cache_reply)) |
| 625 | |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 626 | static void nfs4_sequence_done(const struct nfs_server *server, |
| 627 | struct nfs4_sequence_res *res, int rpc_status) |
| 628 | { |
| 629 | #ifdef CONFIG_NFS_V4_1 |
| 630 | if (nfs4_has_session(server->nfs_client)) |
| 631 | nfs41_sequence_done(server->nfs_client, res, rpc_status); |
| 632 | #endif /* CONFIG_NFS_V4_1 */ |
| 633 | } |
| 634 | |
| 635 | /* no restart, therefore free slot here */ |
| 636 | static void nfs4_sequence_done_free_slot(const struct nfs_server *server, |
| 637 | struct nfs4_sequence_res *res, |
| 638 | int rpc_status) |
| 639 | { |
| 640 | nfs4_sequence_done(server, res, rpc_status); |
| 641 | nfs4_sequence_free_slot(server->nfs_client, res); |
| 642 | } |
| 643 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 644 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 646 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 648 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 649 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA; |
| 650 | if (!cinfo->atomic || cinfo->before != nfsi->change_attr) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 651 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 652 | nfsi->change_attr = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 653 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 656 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 657 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 658 | struct nfs_openargs o_arg; |
| 659 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 660 | struct nfs_open_confirmargs c_arg; |
| 661 | struct nfs_open_confirmres c_res; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 662 | struct nfs_fattr f_attr; |
| 663 | struct nfs_fattr dir_attr; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 664 | struct path path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 665 | struct dentry *dir; |
| 666 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 667 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 668 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 669 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 670 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 671 | int rpc_status; |
| 672 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 673 | }; |
| 674 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 675 | |
| 676 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 677 | { |
| 678 | p->o_res.f_attr = &p->f_attr; |
| 679 | p->o_res.dir_attr = &p->dir_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 680 | p->o_res.seqid = p->o_arg.seqid; |
| 681 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 682 | p->o_res.server = p->o_arg.server; |
| 683 | nfs_fattr_init(&p->f_attr); |
| 684 | nfs_fattr_init(&p->dir_attr); |
Benny Halevy | 578e458 | 2009-06-18 22:01:23 -0400 | [diff] [blame] | 685 | p->o_res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 686 | } |
| 687 | |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 688 | static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 689 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 690 | const struct iattr *attrs) |
| 691 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 692 | struct dentry *parent = dget_parent(path->dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 693 | struct inode *dir = parent->d_inode; |
| 694 | struct nfs_server *server = NFS_SERVER(dir); |
| 695 | struct nfs4_opendata *p; |
| 696 | |
| 697 | p = kzalloc(sizeof(*p), GFP_KERNEL); |
| 698 | if (p == NULL) |
| 699 | goto err; |
| 700 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid); |
| 701 | if (p->o_arg.seqid == NULL) |
| 702 | goto err_free; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 703 | p->path.mnt = mntget(path->mnt); |
| 704 | p->path.dentry = dget(path->dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 705 | p->dir = parent; |
| 706 | p->owner = sp; |
| 707 | atomic_inc(&sp->so_count); |
| 708 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 709 | p->o_arg.open_flags = flags; |
| 710 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 711 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 712 | p->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 713 | p->o_arg.name = &p->path.dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 714 | p->o_arg.server = server; |
| 715 | p->o_arg.bitmask = server->attr_bitmask; |
| 716 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 717 | if (flags & O_EXCL) { |
| 718 | u32 *s = (u32 *) p->o_arg.u.verifier.data; |
| 719 | s[0] = jiffies; |
| 720 | s[1] = current->pid; |
| 721 | } else if (flags & O_CREAT) { |
| 722 | p->o_arg.u.attrs = &p->attrs; |
| 723 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
| 724 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 725 | p->c_arg.fh = &p->o_res.fh; |
| 726 | p->c_arg.stateid = &p->o_res.stateid; |
| 727 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 728 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 729 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 730 | return p; |
| 731 | err_free: |
| 732 | kfree(p); |
| 733 | err: |
| 734 | dput(parent); |
| 735 | return NULL; |
| 736 | } |
| 737 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 738 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 739 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 740 | struct nfs4_opendata *p = container_of(kref, |
| 741 | struct nfs4_opendata, kref); |
| 742 | |
| 743 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 744 | if (p->state != NULL) |
| 745 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 746 | nfs4_put_state_owner(p->owner); |
| 747 | dput(p->dir); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 748 | path_put(&p->path); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 749 | kfree(p); |
| 750 | } |
| 751 | |
| 752 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 753 | { |
| 754 | if (p != NULL) |
| 755 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 756 | } |
| 757 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 758 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 759 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 760 | int ret; |
| 761 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 762 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 763 | return ret; |
| 764 | } |
| 765 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 766 | 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] | 767 | { |
| 768 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 769 | |
| 770 | if (open_mode & O_EXCL) |
| 771 | goto out; |
| 772 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 773 | case FMODE_READ: |
| 774 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 775 | break; |
| 776 | case FMODE_WRITE: |
| 777 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 778 | break; |
| 779 | case FMODE_READ|FMODE_WRITE: |
| 780 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0; |
| 781 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 782 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 783 | return ret; |
| 784 | } |
| 785 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 786 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 787 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 788 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 789 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 790 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 791 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 792 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 793 | return 1; |
| 794 | } |
| 795 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 796 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 797 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 798 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 799 | case FMODE_WRITE: |
| 800 | state->n_wronly++; |
| 801 | break; |
| 802 | case FMODE_READ: |
| 803 | state->n_rdonly++; |
| 804 | break; |
| 805 | case FMODE_READ|FMODE_WRITE: |
| 806 | state->n_rdwr++; |
| 807 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 808 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 809 | } |
| 810 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 811 | 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] | 812 | { |
| 813 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 814 | memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); |
| 815 | memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 816 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 817 | case FMODE_READ: |
| 818 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 819 | break; |
| 820 | case FMODE_WRITE: |
| 821 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 822 | break; |
| 823 | case FMODE_READ|FMODE_WRITE: |
| 824 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 825 | } |
| 826 | } |
| 827 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 828 | 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] | 829 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 830 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 831 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 832 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 833 | } |
| 834 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 835 | 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] | 836 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 837 | /* |
| 838 | * Protect the call to nfs4_state_set_mode_locked and |
| 839 | * serialise the stateid update |
| 840 | */ |
| 841 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 842 | if (deleg_stateid != NULL) { |
| 843 | memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); |
| 844 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 845 | } |
| 846 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 847 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 848 | write_sequnlock(&state->seqlock); |
| 849 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 850 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 851 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | } |
| 853 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 854 | 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] | 855 | { |
| 856 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 857 | struct nfs_delegation *deleg_cur; |
| 858 | int ret = 0; |
| 859 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 860 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 861 | |
| 862 | rcu_read_lock(); |
| 863 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 864 | if (deleg_cur == NULL) |
| 865 | goto no_delegation; |
| 866 | |
| 867 | spin_lock(&deleg_cur->lock); |
| 868 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 869 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 870 | goto no_delegation_unlock; |
| 871 | |
| 872 | if (delegation == NULL) |
| 873 | delegation = &deleg_cur->stateid; |
| 874 | else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) |
| 875 | goto no_delegation_unlock; |
| 876 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 877 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 878 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 879 | ret = 1; |
| 880 | no_delegation_unlock: |
| 881 | spin_unlock(&deleg_cur->lock); |
| 882 | no_delegation: |
| 883 | rcu_read_unlock(); |
| 884 | |
| 885 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 886 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 887 | ret = 1; |
| 888 | } |
| 889 | |
| 890 | return ret; |
| 891 | } |
| 892 | |
| 893 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 894 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 895 | { |
| 896 | struct nfs_delegation *delegation; |
| 897 | |
| 898 | rcu_read_lock(); |
| 899 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 900 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 901 | rcu_read_unlock(); |
| 902 | return; |
| 903 | } |
| 904 | rcu_read_unlock(); |
| 905 | nfs_inode_return_delegation(inode); |
| 906 | } |
| 907 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 908 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 909 | { |
| 910 | struct nfs4_state *state = opendata->state; |
| 911 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 912 | struct nfs_delegation *delegation; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 913 | int open_mode = opendata->o_arg.open_flags & O_EXCL; |
| 914 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 915 | nfs4_stateid stateid; |
| 916 | int ret = -EAGAIN; |
| 917 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 918 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 919 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 920 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 921 | if (can_open_cached(state, fmode, open_mode)) { |
| 922 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 923 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 924 | goto out_return_state; |
| 925 | } |
| 926 | spin_unlock(&state->owner->so_lock); |
| 927 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 928 | rcu_read_lock(); |
| 929 | delegation = rcu_dereference(nfsi->delegation); |
| 930 | if (delegation == NULL || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 931 | !can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 932 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 933 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 934 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 935 | /* Save the delegation */ |
| 936 | memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); |
| 937 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 938 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 939 | if (ret != 0) |
| 940 | goto out; |
| 941 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 942 | |
| 943 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 944 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 945 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 946 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 947 | out: |
| 948 | return ERR_PTR(ret); |
| 949 | out_return_state: |
| 950 | atomic_inc(&state->count); |
| 951 | return state; |
| 952 | } |
| 953 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 954 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 955 | { |
| 956 | struct inode *inode; |
| 957 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 958 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 959 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 960 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 961 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 962 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 963 | goto out; |
| 964 | } |
| 965 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 966 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 967 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 968 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 969 | 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] | 970 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 971 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 972 | goto err; |
| 973 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 974 | state = nfs4_get_open_state(inode, data->owner); |
| 975 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 976 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 977 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 978 | int delegation_flags = 0; |
| 979 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 980 | rcu_read_lock(); |
| 981 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 982 | if (delegation) |
| 983 | delegation_flags = delegation->flags; |
| 984 | rcu_read_unlock(); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 985 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 986 | nfs_inode_set_delegation(state->inode, |
| 987 | data->owner->so_cred, |
| 988 | &data->o_res); |
| 989 | else |
| 990 | nfs_inode_reclaim_delegation(state->inode, |
| 991 | data->owner->so_cred, |
| 992 | &data->o_res); |
| 993 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 994 | |
| 995 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 996 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 997 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 998 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 999 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1000 | err_put_inode: |
| 1001 | iput(inode); |
| 1002 | err: |
| 1003 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1004 | } |
| 1005 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1006 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1007 | { |
| 1008 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1009 | struct nfs_open_context *ctx; |
| 1010 | |
| 1011 | spin_lock(&state->inode->i_lock); |
| 1012 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1013 | if (ctx->state != state) |
| 1014 | continue; |
| 1015 | get_nfs_open_context(ctx); |
| 1016 | spin_unlock(&state->inode->i_lock); |
| 1017 | return ctx; |
| 1018 | } |
| 1019 | spin_unlock(&state->inode->i_lock); |
| 1020 | return ERR_PTR(-ENOENT); |
| 1021 | } |
| 1022 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1023 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1024 | { |
| 1025 | struct nfs4_opendata *opendata; |
| 1026 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1027 | opendata = nfs4_opendata_alloc(&ctx->path, state->owner, 0, 0, NULL); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1028 | if (opendata == NULL) |
| 1029 | return ERR_PTR(-ENOMEM); |
| 1030 | opendata->state = state; |
| 1031 | atomic_inc(&state->count); |
| 1032 | return opendata; |
| 1033 | } |
| 1034 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1035 | 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] | 1036 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1037 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1038 | int ret; |
| 1039 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1040 | opendata->o_arg.open_flags = 0; |
| 1041 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1042 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1043 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1044 | nfs4_init_opendata_res(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1045 | ret = _nfs4_proc_open(opendata); |
| 1046 | if (ret != 0) |
| 1047 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1048 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1049 | if (IS_ERR(newstate)) |
| 1050 | return PTR_ERR(newstate); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1051 | nfs4_close_state(&opendata->path, newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1052 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1053 | return 0; |
| 1054 | } |
| 1055 | |
| 1056 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1057 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1058 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1059 | int ret; |
| 1060 | |
| 1061 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1062 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1063 | smp_rmb(); |
| 1064 | if (state->n_rdwr != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1065 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1066 | if (ret != 0) |
| 1067 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1068 | if (newstate != state) |
| 1069 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1070 | } |
| 1071 | if (state->n_wronly != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1072 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1073 | if (ret != 0) |
| 1074 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1075 | if (newstate != state) |
| 1076 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1077 | } |
| 1078 | if (state->n_rdonly != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1079 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1080 | if (ret != 0) |
| 1081 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1082 | if (newstate != state) |
| 1083 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1084 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1085 | /* |
| 1086 | * We may have performed cached opens for all three recoveries. |
| 1087 | * Check if we need to update the current stateid. |
| 1088 | */ |
| 1089 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
| 1090 | memcmp(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)) != 0) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1091 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1092 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1093 | memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1094 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1095 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1096 | return 0; |
| 1097 | } |
| 1098 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | /* |
| 1100 | * OPEN_RECLAIM: |
| 1101 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1103 | 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] | 1104 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1105 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1106 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1107 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | int status; |
| 1109 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1110 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1111 | if (IS_ERR(opendata)) |
| 1112 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1113 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1114 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1115 | rcu_read_lock(); |
| 1116 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1117 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1118 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1119 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1120 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1121 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1122 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | return status; |
| 1124 | } |
| 1125 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1126 | 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] | 1127 | { |
| 1128 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1129 | struct nfs4_exception exception = { }; |
| 1130 | int err; |
| 1131 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1132 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1133 | if (err != -NFS4ERR_DELAY) |
| 1134 | break; |
| 1135 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | } while (exception.retry); |
| 1137 | return err; |
| 1138 | } |
| 1139 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1140 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1141 | { |
| 1142 | struct nfs_open_context *ctx; |
| 1143 | int ret; |
| 1144 | |
| 1145 | ctx = nfs4_state_find_open_context(state); |
| 1146 | if (IS_ERR(ctx)) |
| 1147 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1148 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1149 | put_nfs_open_context(ctx); |
| 1150 | return ret; |
| 1151 | } |
| 1152 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1153 | 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] | 1154 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1155 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1156 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1158 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1159 | if (IS_ERR(opendata)) |
| 1160 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1161 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1162 | memcpy(opendata->o_arg.u.delegation.data, stateid->data, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1163 | sizeof(opendata->o_arg.u.delegation.data)); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1164 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1165 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1166 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | } |
| 1168 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1169 | 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] | 1170 | { |
| 1171 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1172 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | int err; |
| 1174 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1175 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | switch (err) { |
| 1177 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1178 | case -ENOENT: |
| 1179 | case -ESTALE: |
| 1180 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | case -NFS4ERR_STALE_CLIENTID: |
| 1182 | case -NFS4ERR_STALE_STATEID: |
| 1183 | case -NFS4ERR_EXPIRED: |
| 1184 | /* Don't recall a delegation if it was lost */ |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1185 | nfs4_schedule_state_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1186 | goto out; |
| 1187 | case -ERESTARTSYS: |
| 1188 | /* |
| 1189 | * The show must go on: exit, but mark the |
| 1190 | * stateid as needing recovery. |
| 1191 | */ |
| 1192 | case -NFS4ERR_ADMIN_REVOKED: |
| 1193 | case -NFS4ERR_BAD_STATEID: |
| 1194 | nfs4_state_mark_reclaim_nograce(server->nfs_client, state); |
| 1195 | case -ENOMEM: |
| 1196 | err = 0; |
| 1197 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | } |
| 1199 | err = nfs4_handle_exception(server, err, &exception); |
| 1200 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1201 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | return err; |
| 1203 | } |
| 1204 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1205 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1206 | { |
| 1207 | struct nfs4_opendata *data = calldata; |
| 1208 | |
| 1209 | data->rpc_status = task->tk_status; |
| 1210 | if (RPC_ASSASSINATED(task)) |
| 1211 | return; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1212 | if (data->rpc_status == 0) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1213 | memcpy(data->o_res.stateid.data, data->c_res.stateid.data, |
| 1214 | sizeof(data->o_res.stateid.data)); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1215 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1216 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1217 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1218 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | static void nfs4_open_confirm_release(void *calldata) |
| 1222 | { |
| 1223 | struct nfs4_opendata *data = calldata; |
| 1224 | struct nfs4_state *state = NULL; |
| 1225 | |
| 1226 | /* If this request hasn't been cancelled, do nothing */ |
| 1227 | if (data->cancelled == 0) |
| 1228 | goto out_free; |
| 1229 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1230 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1231 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1232 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1233 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1234 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1235 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1236 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1240 | .rpc_call_done = nfs4_open_confirm_done, |
| 1241 | .rpc_release = nfs4_open_confirm_release, |
| 1242 | }; |
| 1243 | |
| 1244 | /* |
| 1245 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1246 | */ |
| 1247 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1248 | { |
| 1249 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1250 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1251 | struct rpc_message msg = { |
| 1252 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1253 | .rpc_argp = &data->c_arg, |
| 1254 | .rpc_resp = &data->c_res, |
| 1255 | .rpc_cred = data->owner->so_cred, |
| 1256 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1257 | struct rpc_task_setup task_setup_data = { |
| 1258 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1259 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1260 | .callback_ops = &nfs4_open_confirm_ops, |
| 1261 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1262 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1263 | .flags = RPC_TASK_ASYNC, |
| 1264 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | int status; |
| 1266 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1267 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1268 | data->rpc_done = 0; |
| 1269 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1270 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1271 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1272 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1273 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1274 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1275 | if (status != 0) { |
| 1276 | data->cancelled = 1; |
| 1277 | smp_wmb(); |
| 1278 | } else |
| 1279 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1280 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | return status; |
| 1282 | } |
| 1283 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1284 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1286 | struct nfs4_opendata *data = calldata; |
| 1287 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1288 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1289 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1290 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1291 | /* |
| 1292 | * Check if we still need to send an OPEN call, or if we can use |
| 1293 | * a delegation instead. |
| 1294 | */ |
| 1295 | if (data->state != NULL) { |
| 1296 | struct nfs_delegation *delegation; |
| 1297 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1298 | 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] | 1299 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1300 | rcu_read_lock(); |
| 1301 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
| 1302 | if (delegation != NULL && |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1303 | test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1304 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1305 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1306 | } |
| 1307 | rcu_read_unlock(); |
| 1308 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1309 | /* Update sequence id. */ |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1310 | data->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1311 | data->o_arg.clientid = sp->so_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1312 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1313 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1314 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1315 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1316 | data->timestamp = jiffies; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1317 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 1318 | &data->o_arg.seq_args, |
| 1319 | &data->o_res.seq_res, 1, task)) |
| 1320 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1321 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1322 | return; |
| 1323 | out_no_action: |
| 1324 | task->tk_action = NULL; |
| 1325 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1326 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1328 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1329 | { |
| 1330 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1332 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1333 | |
| 1334 | nfs4_sequence_done_free_slot(data->o_arg.server, &data->o_res.seq_res, |
| 1335 | task->tk_status); |
| 1336 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1337 | if (RPC_ASSASSINATED(task)) |
| 1338 | return; |
| 1339 | if (task->tk_status == 0) { |
| 1340 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1341 | case S_IFREG: |
| 1342 | break; |
| 1343 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1344 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1345 | break; |
| 1346 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1347 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1348 | break; |
| 1349 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1350 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1351 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1352 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1353 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1354 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1355 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1356 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1357 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1358 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1359 | static void nfs4_open_release(void *calldata) |
| 1360 | { |
| 1361 | struct nfs4_opendata *data = calldata; |
| 1362 | struct nfs4_state *state = NULL; |
| 1363 | |
| 1364 | /* If this request hasn't been cancelled, do nothing */ |
| 1365 | if (data->cancelled == 0) |
| 1366 | goto out_free; |
| 1367 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1368 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1369 | goto out_free; |
| 1370 | /* In case we need an open_confirm, no cleanup! */ |
| 1371 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1372 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1373 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1374 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1375 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1376 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1377 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1381 | .rpc_call_prepare = nfs4_open_prepare, |
| 1382 | .rpc_call_done = nfs4_open_done, |
| 1383 | .rpc_release = nfs4_open_release, |
| 1384 | }; |
| 1385 | |
| 1386 | /* |
| 1387 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1388 | */ |
| 1389 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1390 | { |
| 1391 | struct inode *dir = data->dir->d_inode; |
| 1392 | struct nfs_server *server = NFS_SERVER(dir); |
| 1393 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1394 | struct nfs_openres *o_res = &data->o_res; |
| 1395 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1396 | struct rpc_message msg = { |
| 1397 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1398 | .rpc_argp = o_arg, |
| 1399 | .rpc_resp = o_res, |
| 1400 | .rpc_cred = data->owner->so_cred, |
| 1401 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1402 | struct rpc_task_setup task_setup_data = { |
| 1403 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1404 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1405 | .callback_ops = &nfs4_open_ops, |
| 1406 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1407 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1408 | .flags = RPC_TASK_ASYNC, |
| 1409 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1410 | int status; |
| 1411 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1412 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1413 | data->rpc_done = 0; |
| 1414 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1415 | data->cancelled = 0; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1416 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1417 | if (IS_ERR(task)) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1418 | return PTR_ERR(task); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1419 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1420 | if (status != 0) { |
| 1421 | data->cancelled = 1; |
| 1422 | smp_wmb(); |
| 1423 | } else |
| 1424 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1425 | rpc_put_task(task); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1426 | if (status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1427 | return status; |
| 1428 | |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1429 | if (o_res->fh.size == 0) |
| 1430 | _nfs4_proc_lookup(dir, o_arg->name, &o_res->fh, o_res->f_attr); |
| 1431 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1432 | if (o_arg->open_flags & O_CREAT) { |
| 1433 | update_changeattr(dir, &o_res->cinfo); |
| 1434 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
| 1435 | } else |
| 1436 | nfs_refresh_inode(dir, o_res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1438 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1440 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | } |
| 1442 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1443 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1444 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | } |
| 1446 | |
Trond Myklebust | 10afec9 | 2007-05-14 17:16:04 -0400 | [diff] [blame] | 1447 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1448 | { |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1449 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1450 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1451 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1452 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1453 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1454 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1455 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1456 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1457 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1458 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1459 | break; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1460 | nfs4_schedule_state_recovery(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1461 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1462 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1463 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1464 | } |
| 1465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | /* |
| 1467 | * OPEN_EXPIRED: |
| 1468 | * reclaim state on the server after a network partition. |
| 1469 | * Assumes caller holds the appropriate lock |
| 1470 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1471 | 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] | 1472 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1473 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1474 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1476 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1477 | if (IS_ERR(opendata)) |
| 1478 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1479 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1480 | if (ret == -ESTALE) |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1481 | d_drop(ctx->path.dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1482 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1483 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | } |
| 1485 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1486 | static inline 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] | 1487 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1488 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1489 | struct nfs4_exception exception = { }; |
| 1490 | int err; |
| 1491 | |
| 1492 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1493 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 027b6ca | 2008-12-23 16:04:13 -0500 | [diff] [blame] | 1494 | if (err != -NFS4ERR_DELAY) |
| 1495 | break; |
| 1496 | nfs4_handle_exception(server, err, &exception); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1497 | } while (exception.retry); |
| 1498 | return err; |
| 1499 | } |
| 1500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1502 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1504 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1506 | ctx = nfs4_state_find_open_context(state); |
| 1507 | if (IS_ERR(ctx)) |
| 1508 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1509 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1510 | put_nfs_open_context(ctx); |
| 1511 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1515 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1516 | * fields corresponding to attributes that were used to store the verifier. |
| 1517 | * Make sure we clobber those fields in the later setattr call |
| 1518 | */ |
| 1519 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1520 | { |
| 1521 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1522 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1523 | sattr->ia_valid |= ATTR_ATIME; |
| 1524 | |
| 1525 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1526 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1527 | sattr->ia_valid |= ATTR_MTIME; |
| 1528 | } |
| 1529 | |
| 1530 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1531 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1533 | static int _nfs4_do_open(struct inode *dir, struct path *path, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred, struct nfs4_state **res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | { |
| 1535 | struct nfs4_state_owner *sp; |
| 1536 | struct nfs4_state *state = NULL; |
| 1537 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1538 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1539 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | |
| 1541 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | status = -ENOMEM; |
| 1543 | if (!(sp = nfs4_get_state_owner(server, cred))) { |
| 1544 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1545 | goto out_err; |
| 1546 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1547 | status = nfs4_recover_expired_lease(server); |
| 1548 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1549 | goto err_put_state_owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1550 | if (path->dentry->d_inode != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1551 | nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1552 | status = -ENOMEM; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1553 | opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1554 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1555 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1557 | if (path->dentry->d_inode != NULL) |
| 1558 | opendata->state = nfs4_get_open_state(path->dentry->d_inode, sp); |
| 1559 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1560 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1562 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1564 | if (opendata->o_arg.open_flags & O_EXCL) |
| 1565 | nfs4_exclusive_attrset(opendata, sattr); |
| 1566 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1567 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1568 | status = PTR_ERR(state); |
| 1569 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1570 | goto err_opendata_put; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1571 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | *res = state; |
| 1574 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1575 | err_opendata_put: |
| 1576 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1577 | err_put_state_owner: |
| 1578 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | *res = NULL; |
| 1581 | return status; |
| 1582 | } |
| 1583 | |
| 1584 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1585 | static struct nfs4_state *nfs4_do_open(struct inode *dir, struct path *path, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | { |
| 1587 | struct nfs4_exception exception = { }; |
| 1588 | struct nfs4_state *res; |
| 1589 | int status; |
| 1590 | |
| 1591 | do { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1592 | status = _nfs4_do_open(dir, path, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | if (status == 0) |
| 1594 | break; |
| 1595 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1596 | * book-keeping w.r.t. state-changing operations |
| 1597 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1598 | * It is actually a sign of a bug on the client or on the server. |
| 1599 | * |
| 1600 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1601 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | * have unhashed the old state_owner for us, and that we can |
| 1603 | * therefore safely retry using a new one. We should still warn |
| 1604 | * the user though... |
| 1605 | */ |
| 1606 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1607 | printk(KERN_WARNING "NFS: v4 server %s " |
| 1608 | " returned a bad sequence-id error!\n", |
| 1609 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | exception.retry = 1; |
| 1611 | continue; |
| 1612 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1613 | /* |
| 1614 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1615 | * state before it received the OPEN_CONFIRM. |
| 1616 | * Recover by retrying the request as per the discussion |
| 1617 | * on Page 181 of RFC3530. |
| 1618 | */ |
| 1619 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1620 | exception.retry = 1; |
| 1621 | continue; |
| 1622 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1623 | if (status == -EAGAIN) { |
| 1624 | /* We must have found a delegation */ |
| 1625 | exception.retry = 1; |
| 1626 | continue; |
| 1627 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1629 | status, &exception)); |
| 1630 | } while (exception.retry); |
| 1631 | return res; |
| 1632 | } |
| 1633 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1634 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1635 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1636 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1637 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1638 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1640 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | .iap = sattr, |
| 1642 | .server = server, |
| 1643 | .bitmask = server->attr_bitmask, |
| 1644 | }; |
| 1645 | struct nfs_setattrres res = { |
| 1646 | .fattr = fattr, |
| 1647 | .server = server, |
| 1648 | }; |
| 1649 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1650 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1651 | .rpc_argp = &arg, |
| 1652 | .rpc_resp = &res, |
| 1653 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1655 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1656 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1658 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1660 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { |
| 1661 | /* Use that stateid */ |
| 1662 | } else if (state != NULL) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1663 | nfs4_copy_stateid(&arg.stateid, state, current->files); |
| 1664 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); |
| 1666 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1667 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1668 | if (status == 0 && state != NULL) |
| 1669 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1670 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | } |
| 1672 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1673 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1674 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1675 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1677 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | struct nfs4_exception exception = { }; |
| 1679 | int err; |
| 1680 | do { |
| 1681 | err = nfs4_handle_exception(server, |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1682 | _nfs4_do_setattr(inode, cred, fattr, sattr, state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | &exception); |
| 1684 | } while (exception.retry); |
| 1685 | return err; |
| 1686 | } |
| 1687 | |
| 1688 | struct nfs4_closedata { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1689 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | struct inode *inode; |
| 1691 | struct nfs4_state *state; |
| 1692 | struct nfs_closeargs arg; |
| 1693 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1694 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1695 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | }; |
| 1697 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1698 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1699 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1700 | struct nfs4_closedata *calldata = data; |
| 1701 | struct nfs4_state_owner *sp = calldata->state->owner; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1702 | |
| 1703 | nfs4_put_open_state(calldata->state); |
| 1704 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1705 | nfs4_put_state_owner(sp); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 1706 | path_put(&calldata->path); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1707 | kfree(calldata); |
| 1708 | } |
| 1709 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1710 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1712 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 1715 | |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 1716 | nfs4_sequence_done(server, &calldata->res.seq_res, task->tk_status); |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1717 | if (RPC_ASSASSINATED(task)) |
| 1718 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | /* hmm. we are done with the inode, and in the process of freeing |
| 1720 | * the state_owner. we keep this around to process errors |
| 1721 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | switch (task->tk_status) { |
| 1723 | case 0: |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1724 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1725 | renew_lease(server, calldata->timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | break; |
| 1727 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1728 | case -NFS4ERR_OLD_STATEID: |
| 1729 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1731 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1732 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1734 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) { |
Andy Adamson | eedc020 | 2009-04-01 09:22:41 -0400 | [diff] [blame] | 1735 | nfs4_restart_rpc(task, server->nfs_client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | return; |
| 1737 | } |
| 1738 | } |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 1739 | nfs4_sequence_free_slot(server->nfs_client, &calldata->res.seq_res); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1740 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | } |
| 1742 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1743 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1745 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1746 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1747 | int clear_rd, clear_wr, clear_rdwr; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1748 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1749 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1750 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1751 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1752 | clear_rd = clear_wr = clear_rdwr = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1753 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1754 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1755 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1756 | if (state->n_rdonly == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1757 | clear_rd |= test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1758 | clear_rdwr |= test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1759 | } |
| 1760 | if (state->n_wronly == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1761 | clear_wr |= test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1762 | clear_rdwr |= test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1763 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1764 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1765 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1766 | if (!clear_rd && !clear_wr && !clear_rdwr) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1767 | /* Note: exit _without_ calling nfs4_close_done */ |
| 1768 | task->tk_action = NULL; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1769 | return; |
| 1770 | } |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1771 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1772 | if (test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1773 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1774 | calldata->arg.fmode = FMODE_READ; |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1775 | } else if (test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1776 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1777 | calldata->arg.fmode = FMODE_WRITE; |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1778 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1779 | calldata->timestamp = jiffies; |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 1780 | if (nfs4_setup_sequence((NFS_SERVER(calldata->inode))->nfs_client, |
| 1781 | &calldata->arg.seq_args, &calldata->res.seq_res, |
| 1782 | 1, task)) |
| 1783 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1784 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1787 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1788 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1789 | .rpc_call_done = nfs4_close_done, |
| 1790 | .rpc_release = nfs4_free_closedata, |
| 1791 | }; |
| 1792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | /* |
| 1794 | * It is possible for data to be read/written from a mem-mapped file |
| 1795 | * after the sys_close call (which hits the vfs layer as a flush). |
| 1796 | * This means that we can't safely call nfsv4 close on a file until |
| 1797 | * the inode is cleared. This in turn means that we are not good |
| 1798 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 1799 | * share state even when we are done with one of the three share |
| 1800 | * stateid's in the inode. |
| 1801 | * |
| 1802 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 1803 | */ |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 1804 | int nfs4_do_close(struct path *path, struct nfs4_state *state, int wait) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1806 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1808 | struct nfs4_state_owner *sp = state->owner; |
| 1809 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1810 | struct rpc_message msg = { |
| 1811 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 1812 | .rpc_cred = state->owner->so_cred, |
| 1813 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1814 | struct rpc_task_setup task_setup_data = { |
| 1815 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1816 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1817 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1818 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1819 | .flags = RPC_TASK_ASYNC, |
| 1820 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1821 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 1823 | calldata = kzalloc(sizeof(*calldata), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1825 | goto out; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1826 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1828 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1829 | calldata->arg.stateid = &state->open_stateid; |
Benny Halevy | 34dc1ad | 2009-04-01 09:22:52 -0400 | [diff] [blame] | 1830 | if (nfs4_has_session(server->nfs_client)) |
| 1831 | memset(calldata->arg.stateid->data, 0, 4); /* clear seqid */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | /* Serialization for the sequence id */ |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1833 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1834 | if (calldata->arg.seqid == NULL) |
| 1835 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1836 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 1837 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1838 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 1839 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1840 | calldata->res.server = server; |
Andy Adamson | 5f7dbd5 | 2009-04-01 09:22:05 -0400 | [diff] [blame] | 1841 | calldata->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1842 | calldata->path.mnt = mntget(path->mnt); |
| 1843 | calldata->path.dentry = dget(path->dentry); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1844 | |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1845 | msg.rpc_argp = &calldata->arg, |
| 1846 | msg.rpc_resp = &calldata->res, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1847 | task_setup_data.callback_data = calldata; |
| 1848 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1849 | if (IS_ERR(task)) |
| 1850 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 1851 | status = 0; |
| 1852 | if (wait) |
| 1853 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1854 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 1855 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1856 | out_free_calldata: |
| 1857 | kfree(calldata); |
| 1858 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1859 | nfs4_put_open_state(state); |
| 1860 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1861 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | } |
| 1863 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1864 | static int nfs4_intent_set_file(struct nameidata *nd, struct path *path, struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1865 | { |
| 1866 | struct file *filp; |
Trond Myklebust | 1b45c46 | 2007-07-03 13:04:56 -0400 | [diff] [blame] | 1867 | int ret; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1868 | |
Trond Myklebust | 1b45c46 | 2007-07-03 13:04:56 -0400 | [diff] [blame] | 1869 | /* If the open_intent is for execute, we have an extra check to make */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1870 | if (fmode & FMODE_EXEC) { |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1871 | ret = nfs_may_open(state->inode, |
Trond Myklebust | 1b45c46 | 2007-07-03 13:04:56 -0400 | [diff] [blame] | 1872 | state->owner->so_cred, |
| 1873 | nd->intent.open.flags); |
| 1874 | if (ret < 0) |
| 1875 | goto out_close; |
| 1876 | } |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1877 | filp = lookup_instantiate_filp(nd, path->dentry, NULL); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1878 | if (!IS_ERR(filp)) { |
| 1879 | struct nfs_open_context *ctx; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 1880 | ctx = nfs_file_open_context(filp); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1881 | ctx->state = state; |
Trond Myklebust | 95cf959 | 2006-04-18 13:14:06 -0400 | [diff] [blame] | 1882 | return 0; |
| 1883 | } |
Trond Myklebust | 1b45c46 | 2007-07-03 13:04:56 -0400 | [diff] [blame] | 1884 | ret = PTR_ERR(filp); |
| 1885 | out_close: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1886 | nfs4_close_sync(path, state, fmode & (FMODE_READ|FMODE_WRITE)); |
Trond Myklebust | 1b45c46 | 2007-07-03 13:04:56 -0400 | [diff] [blame] | 1887 | return ret; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | struct dentry * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd) |
| 1892 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1893 | struct path path = { |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 1894 | .mnt = nd->path.mnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1895 | .dentry = dentry, |
| 1896 | }; |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 1897 | struct dentry *parent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | struct iattr attr; |
| 1899 | struct rpc_cred *cred; |
| 1900 | struct nfs4_state *state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1901 | struct dentry *res; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1902 | fmode_t fmode = nd->intent.open.flags & (FMODE_READ | FMODE_WRITE | FMODE_EXEC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | |
| 1904 | if (nd->flags & LOOKUP_CREATE) { |
| 1905 | attr.ia_mode = nd->intent.open.create_mode; |
| 1906 | attr.ia_valid = ATTR_MODE; |
| 1907 | if (!IS_POSIXACL(dir)) |
Al Viro | ce3b0f8 | 2009-03-29 19:08:22 -0400 | [diff] [blame] | 1908 | attr.ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | } else { |
| 1910 | attr.ia_valid = 0; |
| 1911 | BUG_ON(nd->intent.open.flags & O_CREAT); |
| 1912 | } |
| 1913 | |
Trond Myklebust | 98a8e32 | 2008-03-12 12:25:28 -0400 | [diff] [blame] | 1914 | cred = rpc_lookup_cred(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | if (IS_ERR(cred)) |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1916 | return (struct dentry *)cred; |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 1917 | parent = dentry->d_parent; |
| 1918 | /* Protect against concurrent sillydeletes */ |
| 1919 | nfs_block_sillyrename(parent); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1920 | state = nfs4_do_open(dir, &path, fmode, nd->intent.open.flags, &attr, cred); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | put_rpccred(cred); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1922 | if (IS_ERR(state)) { |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 1923 | if (PTR_ERR(state) == -ENOENT) { |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1924 | d_add(dentry, NULL); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 1925 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
| 1926 | } |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 1927 | nfs_unblock_sillyrename(parent); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1928 | return (struct dentry *)state; |
| 1929 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1930 | res = d_add_unique(dentry, igrab(state->inode)); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1931 | if (res != NULL) |
Trond Myklebust | deee936 | 2007-08-27 11:33:00 -0400 | [diff] [blame] | 1932 | path.dentry = res; |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 1933 | nfs_set_verifier(path.dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 1934 | nfs_unblock_sillyrename(parent); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1935 | nfs4_intent_set_file(nd, &path, state, fmode); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1936 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | int |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1940 | nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags, struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1942 | struct path path = { |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 1943 | .mnt = nd->path.mnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1944 | .dentry = dentry, |
| 1945 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | struct rpc_cred *cred; |
| 1947 | struct nfs4_state *state; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1948 | fmode_t fmode = openflags & (FMODE_READ | FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | |
Trond Myklebust | 98a8e32 | 2008-03-12 12:25:28 -0400 | [diff] [blame] | 1950 | cred = rpc_lookup_cred(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | if (IS_ERR(cred)) |
| 1952 | return PTR_ERR(cred); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1953 | state = nfs4_do_open(dir, &path, fmode, openflags, NULL, cred); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1954 | put_rpccred(cred); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1955 | if (IS_ERR(state)) { |
| 1956 | switch (PTR_ERR(state)) { |
| 1957 | case -EPERM: |
| 1958 | case -EACCES: |
| 1959 | case -EDQUOT: |
| 1960 | case -ENOSPC: |
| 1961 | case -EROFS: |
| 1962 | lookup_instantiate_filp(nd, (struct dentry *)state, NULL); |
| 1963 | return 1; |
Chuck Lever | b87c0ad | 2006-10-19 23:28:42 -0700 | [diff] [blame] | 1964 | default: |
| 1965 | goto out_drop; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1966 | } |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1967 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1968 | if (state->inode == dentry->d_inode) { |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 1969 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1970 | nfs4_intent_set_file(nd, &path, state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | return 1; |
| 1972 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1973 | nfs4_close_sync(&path, state, fmode); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1974 | out_drop: |
| 1975 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | return 0; |
| 1977 | } |
| 1978 | |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 1979 | void nfs4_close_context(struct nfs_open_context *ctx, int is_sync) |
| 1980 | { |
| 1981 | if (ctx->state == NULL) |
| 1982 | return; |
| 1983 | if (is_sync) |
| 1984 | nfs4_close_sync(&ctx->path, ctx->state, ctx->mode); |
| 1985 | else |
| 1986 | nfs4_close_state(&ctx->path, ctx->state, ctx->mode); |
| 1987 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | |
| 1989 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 1990 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 1991 | struct nfs4_server_caps_arg args = { |
| 1992 | .fhandle = fhandle, |
| 1993 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | struct nfs4_server_caps_res res = {}; |
| 1995 | struct rpc_message msg = { |
| 1996 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 1997 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | .rpc_resp = &res, |
| 1999 | }; |
| 2000 | int status; |
| 2001 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2002 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | if (status == 0) { |
| 2004 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2005 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2006 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2007 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2008 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2009 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2011 | server->caps |= NFS_CAP_ACLS; |
| 2012 | if (res.has_links != 0) |
| 2013 | server->caps |= NFS_CAP_HARDLINKS; |
| 2014 | if (res.has_symlinks != 0) |
| 2015 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2016 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2017 | server->caps |= NFS_CAP_FILEID; |
| 2018 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2019 | server->caps |= NFS_CAP_MODE; |
| 2020 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2021 | server->caps |= NFS_CAP_NLINK; |
| 2022 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2023 | server->caps |= NFS_CAP_OWNER; |
| 2024 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2025 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2026 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2027 | server->caps |= NFS_CAP_ATIME; |
| 2028 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2029 | server->caps |= NFS_CAP_CTIME; |
| 2030 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2031 | server->caps |= NFS_CAP_MTIME; |
| 2032 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2033 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2034 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2035 | 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] | 2036 | server->acl_bitmask = res.acl_bitmask; |
| 2037 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2038 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | return status; |
| 2040 | } |
| 2041 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2042 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | { |
| 2044 | struct nfs4_exception exception = { }; |
| 2045 | int err; |
| 2046 | do { |
| 2047 | err = nfs4_handle_exception(server, |
| 2048 | _nfs4_server_capabilities(server, fhandle), |
| 2049 | &exception); |
| 2050 | } while (exception.retry); |
| 2051 | return err; |
| 2052 | } |
| 2053 | |
| 2054 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2055 | struct nfs_fsinfo *info) |
| 2056 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | struct nfs4_lookup_root_arg args = { |
| 2058 | .bitmask = nfs4_fattr_bitmap, |
| 2059 | }; |
| 2060 | struct nfs4_lookup_res res = { |
| 2061 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2062 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | .fh = fhandle, |
| 2064 | }; |
| 2065 | struct rpc_message msg = { |
| 2066 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2067 | .rpc_argp = &args, |
| 2068 | .rpc_resp = &res, |
| 2069 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2070 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2071 | nfs_fattr_init(info->fattr); |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 2072 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | } |
| 2074 | |
| 2075 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2076 | struct nfs_fsinfo *info) |
| 2077 | { |
| 2078 | struct nfs4_exception exception = { }; |
| 2079 | int err; |
| 2080 | do { |
| 2081 | err = nfs4_handle_exception(server, |
| 2082 | _nfs4_lookup_root(server, fhandle, info), |
| 2083 | &exception); |
| 2084 | } while (exception.retry); |
| 2085 | return err; |
| 2086 | } |
| 2087 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2088 | /* |
| 2089 | * get the file handle for the "/" directory on the server |
| 2090 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2092 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | int status; |
| 2095 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | status = nfs4_lookup_root(server, fhandle, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | if (status == 0) |
| 2098 | status = nfs4_server_capabilities(server, fhandle); |
| 2099 | if (status == 0) |
| 2100 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2101 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | } |
| 2103 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2104 | /* |
| 2105 | * Get locations and (maybe) other attributes of a referral. |
| 2106 | * Note that we'll actually follow the referral later when |
| 2107 | * we detect fsid mismatch in inode revalidation |
| 2108 | */ |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2109 | static int nfs4_get_referral(struct inode *dir, const struct qstr *name, struct nfs_fattr *fattr, struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2110 | { |
| 2111 | int status = -ENOMEM; |
| 2112 | struct page *page = NULL; |
| 2113 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2114 | |
| 2115 | page = alloc_page(GFP_KERNEL); |
| 2116 | if (page == NULL) |
| 2117 | goto out; |
| 2118 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2119 | if (locations == NULL) |
| 2120 | goto out; |
| 2121 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 2122 | status = nfs4_proc_fs_locations(dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2123 | if (status != 0) |
| 2124 | goto out; |
| 2125 | /* Make sure server returned a different fsid for the referral */ |
| 2126 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2127 | dprintk("%s: server did not return a different fsid for a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2128 | status = -EIO; |
| 2129 | goto out; |
| 2130 | } |
| 2131 | |
| 2132 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
| 2133 | fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL; |
| 2134 | if (!fattr->mode) |
| 2135 | fattr->mode = S_IFDIR; |
| 2136 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2137 | out: |
| 2138 | if (page) |
| 2139 | __free_page(page); |
| 2140 | if (locations) |
| 2141 | kfree(locations); |
| 2142 | return status; |
| 2143 | } |
| 2144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2145 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2146 | { |
| 2147 | struct nfs4_getattr_arg args = { |
| 2148 | .fh = fhandle, |
| 2149 | .bitmask = server->attr_bitmask, |
| 2150 | }; |
| 2151 | struct nfs4_getattr_res res = { |
| 2152 | .fattr = fattr, |
| 2153 | .server = server, |
| 2154 | }; |
| 2155 | struct rpc_message msg = { |
| 2156 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2157 | .rpc_argp = &args, |
| 2158 | .rpc_resp = &res, |
| 2159 | }; |
| 2160 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2161 | nfs_fattr_init(fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2162 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2166 | { |
| 2167 | struct nfs4_exception exception = { }; |
| 2168 | int err; |
| 2169 | do { |
| 2170 | err = nfs4_handle_exception(server, |
| 2171 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2172 | &exception); |
| 2173 | } while (exception.retry); |
| 2174 | return err; |
| 2175 | } |
| 2176 | |
| 2177 | /* |
| 2178 | * The file is not closed if it is opened due to the a request to change |
| 2179 | * the size of the file. The open call will not be needed once the |
| 2180 | * VFS layer lookup-intents are implemented. |
| 2181 | * |
| 2182 | * Close is called when the inode is destroyed. |
| 2183 | * If we haven't opened the file for O_WRONLY, we |
| 2184 | * need to in the size_change case to obtain a stateid. |
| 2185 | * |
| 2186 | * Got race? |
| 2187 | * Because OPEN is always done by name in nfsv4, it is |
| 2188 | * possible that we opened a different file by the same |
| 2189 | * name. We can recognize this race condition, but we |
| 2190 | * can't do anything about it besides returning an error. |
| 2191 | * |
| 2192 | * This will be fixed with VFS changes (lookup-intent). |
| 2193 | */ |
| 2194 | static int |
| 2195 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2196 | struct iattr *sattr) |
| 2197 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2198 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2199 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2200 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | int status; |
| 2202 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2203 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2205 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2206 | if (sattr->ia_valid & ATTR_FILE) { |
| 2207 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2208 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2209 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2210 | if (ctx) { |
| 2211 | cred = ctx->cred; |
| 2212 | state = ctx->state; |
| 2213 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2214 | } |
| 2215 | |
| 2216 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2217 | if (status == 0) |
| 2218 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | return status; |
| 2220 | } |
| 2221 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2222 | static int _nfs4_proc_lookupfh(struct nfs_server *server, const struct nfs_fh *dirfh, |
| 2223 | const struct qstr *name, struct nfs_fh *fhandle, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2224 | struct nfs_fattr *fattr) |
| 2225 | { |
| 2226 | int status; |
| 2227 | struct nfs4_lookup_arg args = { |
| 2228 | .bitmask = server->attr_bitmask, |
| 2229 | .dir_fh = dirfh, |
| 2230 | .name = name, |
| 2231 | }; |
| 2232 | struct nfs4_lookup_res res = { |
| 2233 | .server = server, |
| 2234 | .fattr = fattr, |
| 2235 | .fh = fhandle, |
| 2236 | }; |
| 2237 | struct rpc_message msg = { |
| 2238 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2239 | .rpc_argp = &args, |
| 2240 | .rpc_resp = &res, |
| 2241 | }; |
| 2242 | |
| 2243 | nfs_fattr_init(fattr); |
| 2244 | |
| 2245 | dprintk("NFS call lookupfh %s\n", name->name); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2246 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2247 | dprintk("NFS reply lookupfh: %d\n", status); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2248 | return status; |
| 2249 | } |
| 2250 | |
| 2251 | static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh, |
| 2252 | struct qstr *name, struct nfs_fh *fhandle, |
| 2253 | struct nfs_fattr *fattr) |
| 2254 | { |
| 2255 | struct nfs4_exception exception = { }; |
| 2256 | int err; |
| 2257 | do { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2258 | err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr); |
| 2259 | /* FIXME: !!!! */ |
| 2260 | if (err == -NFS4ERR_MOVED) { |
| 2261 | err = -EREMOTE; |
| 2262 | break; |
| 2263 | } |
| 2264 | err = nfs4_handle_exception(server, err, &exception); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2265 | } while (exception.retry); |
| 2266 | return err; |
| 2267 | } |
| 2268 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2269 | static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2270 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2271 | { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2272 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | |
| 2274 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2275 | status = _nfs4_proc_lookupfh(NFS_SERVER(dir), NFS_FH(dir), name, fhandle, fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2276 | if (status == -NFS4ERR_MOVED) |
| 2277 | status = nfs4_get_referral(dir, name, fattr, fhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | dprintk("NFS reply lookup: %d\n", status); |
| 2279 | return status; |
| 2280 | } |
| 2281 | |
| 2282 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2283 | { |
| 2284 | struct nfs4_exception exception = { }; |
| 2285 | int err; |
| 2286 | do { |
| 2287 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2288 | _nfs4_proc_lookup(dir, name, fhandle, fattr), |
| 2289 | &exception); |
| 2290 | } while (exception.retry); |
| 2291 | return err; |
| 2292 | } |
| 2293 | |
| 2294 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2295 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2296 | struct nfs_server *server = NFS_SERVER(inode); |
| 2297 | struct nfs_fattr fattr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | struct nfs4_accessargs args = { |
| 2299 | .fh = NFS_FH(inode), |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2300 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2302 | struct nfs4_accessres res = { |
| 2303 | .server = server, |
| 2304 | .fattr = &fattr, |
| 2305 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | struct rpc_message msg = { |
| 2307 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2308 | .rpc_argp = &args, |
| 2309 | .rpc_resp = &res, |
| 2310 | .rpc_cred = entry->cred, |
| 2311 | }; |
| 2312 | int mode = entry->mask; |
| 2313 | int status; |
| 2314 | |
| 2315 | /* |
| 2316 | * Determine which access bits we want to ask for... |
| 2317 | */ |
| 2318 | if (mode & MAY_READ) |
| 2319 | args.access |= NFS4_ACCESS_READ; |
| 2320 | if (S_ISDIR(inode->i_mode)) { |
| 2321 | if (mode & MAY_WRITE) |
| 2322 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2323 | if (mode & MAY_EXEC) |
| 2324 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2325 | } else { |
| 2326 | if (mode & MAY_WRITE) |
| 2327 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2328 | if (mode & MAY_EXEC) |
| 2329 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2330 | } |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2331 | nfs_fattr_init(&fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2332 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | if (!status) { |
| 2334 | entry->mask = 0; |
| 2335 | if (res.access & NFS4_ACCESS_READ) |
| 2336 | entry->mask |= MAY_READ; |
| 2337 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2338 | entry->mask |= MAY_WRITE; |
| 2339 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2340 | entry->mask |= MAY_EXEC; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2341 | nfs_refresh_inode(inode, &fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | } |
| 2343 | return status; |
| 2344 | } |
| 2345 | |
| 2346 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2347 | { |
| 2348 | struct nfs4_exception exception = { }; |
| 2349 | int err; |
| 2350 | do { |
| 2351 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2352 | _nfs4_proc_access(inode, entry), |
| 2353 | &exception); |
| 2354 | } while (exception.retry); |
| 2355 | return err; |
| 2356 | } |
| 2357 | |
| 2358 | /* |
| 2359 | * TODO: For the time being, we don't try to get any attributes |
| 2360 | * along with any of the zero-copy operations READ, READDIR, |
| 2361 | * READLINK, WRITE. |
| 2362 | * |
| 2363 | * In the case of the first three, we want to put the GETATTR |
| 2364 | * after the read-type operation -- this is because it is hard |
| 2365 | * to predict the length of a GETATTR response in v4, and thus |
| 2366 | * align the READ data correctly. This means that the GETATTR |
| 2367 | * may end up partially falling into the page cache, and we should |
| 2368 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2369 | * To do this efficiently, we need to know the total length |
| 2370 | * of data received, which doesn't seem to be available outside |
| 2371 | * of the RPC layer. |
| 2372 | * |
| 2373 | * In the case of WRITE, we also want to put the GETATTR after |
| 2374 | * the operation -- in this case because we want to make sure |
| 2375 | * we get the post-operation mtime and size. This means that |
| 2376 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2377 | * of it which would leave room in the 'tail' iovec. |
| 2378 | * |
| 2379 | * Both of these changes to the XDR layer would in fact be quite |
| 2380 | * minor, but I decided to leave them for a subsequent patch. |
| 2381 | */ |
| 2382 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2383 | unsigned int pgbase, unsigned int pglen) |
| 2384 | { |
| 2385 | struct nfs4_readlink args = { |
| 2386 | .fh = NFS_FH(inode), |
| 2387 | .pgbase = pgbase, |
| 2388 | .pglen = pglen, |
| 2389 | .pages = &page, |
| 2390 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2391 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | struct rpc_message msg = { |
| 2393 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2394 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2395 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 | }; |
| 2397 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2398 | return nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2402 | unsigned int pgbase, unsigned int pglen) |
| 2403 | { |
| 2404 | struct nfs4_exception exception = { }; |
| 2405 | int err; |
| 2406 | do { |
| 2407 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2408 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2409 | &exception); |
| 2410 | } while (exception.retry); |
| 2411 | return err; |
| 2412 | } |
| 2413 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | /* |
| 2415 | * Got race? |
| 2416 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2417 | * Until then, this create/open method is prone to inefficiency and race |
| 2418 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2419 | * placed on the wire. |
| 2420 | * |
| 2421 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2422 | * The file will be opened again in the subsequent VFS open call |
| 2423 | * (nfs4_proc_file_open). |
| 2424 | * |
| 2425 | * The open for read will just hang around to be used by any process that |
| 2426 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2427 | */ |
| 2428 | |
| 2429 | static int |
| 2430 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2431 | int flags, struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2432 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2433 | struct path path = { |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 2434 | .mnt = nd->path.mnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2435 | .dentry = dentry, |
| 2436 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2437 | struct nfs4_state *state; |
| 2438 | struct rpc_cred *cred; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2439 | fmode_t fmode = flags & (FMODE_READ | FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | int status = 0; |
| 2441 | |
Trond Myklebust | 98a8e32 | 2008-03-12 12:25:28 -0400 | [diff] [blame] | 2442 | cred = rpc_lookup_cred(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2443 | if (IS_ERR(cred)) { |
| 2444 | status = PTR_ERR(cred); |
| 2445 | goto out; |
| 2446 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2447 | state = nfs4_do_open(dir, &path, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2448 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2449 | if (IS_ERR(state)) { |
| 2450 | status = PTR_ERR(state); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2451 | goto out_putcred; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2452 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2453 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2454 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2455 | if (flags & O_EXCL) { |
| 2456 | struct nfs_fattr fattr; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2457 | status = nfs4_do_setattr(state->inode, cred, &fattr, sattr, state); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2458 | if (status == 0) |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2459 | nfs_setattr_update_inode(state->inode, sattr); |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2460 | nfs_post_op_update_inode(state->inode, &fattr); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2461 | } |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2462 | if (status == 0 && (nd->flags & LOOKUP_OPEN) != 0) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2463 | status = nfs4_intent_set_file(nd, &path, state, fmode); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2464 | else |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2465 | nfs4_close_sync(&path, state, fmode); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2466 | out_putcred: |
| 2467 | put_rpccred(cred); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | out: |
| 2469 | return status; |
| 2470 | } |
| 2471 | |
| 2472 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2473 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2474 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2475 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2476 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2477 | .name.len = name->len, |
| 2478 | .name.name = name->name, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2479 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2481 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2482 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2483 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2485 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2486 | .rpc_argp = &args, |
| 2487 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | }; |
| 2489 | int status; |
| 2490 | |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2491 | nfs_fattr_init(&res.dir_attr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2492 | status = nfs4_call_sync(server, &msg, &args, &res, 1); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2493 | if (status == 0) { |
| 2494 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2495 | nfs_post_op_update_inode(dir, &res.dir_attr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2496 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2497 | return status; |
| 2498 | } |
| 2499 | |
| 2500 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2501 | { |
| 2502 | struct nfs4_exception exception = { }; |
| 2503 | int err; |
| 2504 | do { |
| 2505 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2506 | _nfs4_proc_remove(dir, name), |
| 2507 | &exception); |
| 2508 | } while (exception.retry); |
| 2509 | return err; |
| 2510 | } |
| 2511 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2512 | 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] | 2513 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2514 | struct nfs_server *server = NFS_SERVER(dir); |
| 2515 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2516 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2518 | args->bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2519 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | } |
| 2522 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2523 | 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] | 2524 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2525 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2526 | |
Andy Adamson | 472cfbd | 2009-04-01 09:22:24 -0400 | [diff] [blame] | 2527 | nfs4_sequence_done(res->server, &res->seq_res, task->tk_status); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2528 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2529 | return 0; |
Andy Adamson | 472cfbd | 2009-04-01 09:22:24 -0400 | [diff] [blame] | 2530 | nfs4_sequence_free_slot(res->server->nfs_client, &res->seq_res); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2531 | update_changeattr(dir, &res->cinfo); |
| 2532 | nfs_post_op_update_inode(dir, &res->dir_attr); |
| 2533 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2537 | struct inode *new_dir, struct qstr *new_name) |
| 2538 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2539 | struct nfs_server *server = NFS_SERVER(old_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | struct nfs4_rename_arg arg = { |
| 2541 | .old_dir = NFS_FH(old_dir), |
| 2542 | .new_dir = NFS_FH(new_dir), |
| 2543 | .old_name = old_name, |
| 2544 | .new_name = new_name, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2545 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2546 | }; |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2547 | struct nfs_fattr old_fattr, new_fattr; |
| 2548 | struct nfs4_rename_res res = { |
| 2549 | .server = server, |
| 2550 | .old_fattr = &old_fattr, |
| 2551 | .new_fattr = &new_fattr, |
| 2552 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 | struct rpc_message msg = { |
| 2554 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2555 | .rpc_argp = &arg, |
| 2556 | .rpc_resp = &res, |
| 2557 | }; |
| 2558 | int status; |
| 2559 | |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2560 | nfs_fattr_init(res.old_fattr); |
| 2561 | nfs_fattr_init(res.new_fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2562 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2563 | |
| 2564 | if (!status) { |
| 2565 | update_changeattr(old_dir, &res.old_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2566 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2567 | update_changeattr(new_dir, &res.new_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2568 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2569 | } |
| 2570 | return status; |
| 2571 | } |
| 2572 | |
| 2573 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2574 | struct inode *new_dir, struct qstr *new_name) |
| 2575 | { |
| 2576 | struct nfs4_exception exception = { }; |
| 2577 | int err; |
| 2578 | do { |
| 2579 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2580 | _nfs4_proc_rename(old_dir, old_name, |
| 2581 | new_dir, new_name), |
| 2582 | &exception); |
| 2583 | } while (exception.retry); |
| 2584 | return err; |
| 2585 | } |
| 2586 | |
| 2587 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2588 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2589 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | struct nfs4_link_arg arg = { |
| 2591 | .fh = NFS_FH(inode), |
| 2592 | .dir_fh = NFS_FH(dir), |
| 2593 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2594 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2595 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2596 | struct nfs_fattr fattr, dir_attr; |
| 2597 | struct nfs4_link_res res = { |
| 2598 | .server = server, |
| 2599 | .fattr = &fattr, |
| 2600 | .dir_attr = &dir_attr, |
| 2601 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | struct rpc_message msg = { |
| 2603 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2604 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2605 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | }; |
| 2607 | int status; |
| 2608 | |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2609 | nfs_fattr_init(res.fattr); |
| 2610 | nfs_fattr_init(res.dir_attr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2611 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2612 | if (!status) { |
| 2613 | update_changeattr(dir, &res.cinfo); |
| 2614 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2615 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2616 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | |
| 2618 | return status; |
| 2619 | } |
| 2620 | |
| 2621 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2622 | { |
| 2623 | struct nfs4_exception exception = { }; |
| 2624 | int err; |
| 2625 | do { |
| 2626 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2627 | _nfs4_proc_link(inode, dir, name), |
| 2628 | &exception); |
| 2629 | } while (exception.retry); |
| 2630 | return err; |
| 2631 | } |
| 2632 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2633 | struct nfs4_createdata { |
| 2634 | struct rpc_message msg; |
| 2635 | struct nfs4_create_arg arg; |
| 2636 | struct nfs4_create_res res; |
| 2637 | struct nfs_fh fh; |
| 2638 | struct nfs_fattr fattr; |
| 2639 | struct nfs_fattr dir_fattr; |
| 2640 | }; |
| 2641 | |
| 2642 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 2643 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 2644 | { |
| 2645 | struct nfs4_createdata *data; |
| 2646 | |
| 2647 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2648 | if (data != NULL) { |
| 2649 | struct nfs_server *server = NFS_SERVER(dir); |
| 2650 | |
| 2651 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 2652 | data->msg.rpc_argp = &data->arg; |
| 2653 | data->msg.rpc_resp = &data->res; |
| 2654 | data->arg.dir_fh = NFS_FH(dir); |
| 2655 | data->arg.server = server; |
| 2656 | data->arg.name = name; |
| 2657 | data->arg.attrs = sattr; |
| 2658 | data->arg.ftype = ftype; |
| 2659 | data->arg.bitmask = server->attr_bitmask; |
| 2660 | data->res.server = server; |
| 2661 | data->res.fh = &data->fh; |
| 2662 | data->res.fattr = &data->fattr; |
| 2663 | data->res.dir_fattr = &data->dir_fattr; |
| 2664 | nfs_fattr_init(data->res.fattr); |
| 2665 | nfs_fattr_init(data->res.dir_fattr); |
| 2666 | } |
| 2667 | return data; |
| 2668 | } |
| 2669 | |
| 2670 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 2671 | { |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2672 | int status = nfs4_call_sync(NFS_SERVER(dir), &data->msg, |
| 2673 | &data->arg, &data->res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2674 | if (status == 0) { |
| 2675 | update_changeattr(dir, &data->res.dir_cinfo); |
| 2676 | nfs_post_op_update_inode(dir, data->res.dir_fattr); |
| 2677 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 2678 | } |
| 2679 | return status; |
| 2680 | } |
| 2681 | |
| 2682 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 2683 | { |
| 2684 | kfree(data); |
| 2685 | } |
| 2686 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2687 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2688 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2690 | struct nfs4_createdata *data; |
| 2691 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2692 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2693 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2694 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2695 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2696 | status = -ENOMEM; |
| 2697 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 2698 | if (data == NULL) |
| 2699 | goto out; |
| 2700 | |
| 2701 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 2702 | data->arg.u.symlink.pages = &page; |
| 2703 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2705 | status = nfs4_do_create(dir, dentry, data); |
| 2706 | |
| 2707 | nfs4_free_createdata(data); |
| 2708 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2709 | return status; |
| 2710 | } |
| 2711 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2712 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2713 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | { |
| 2715 | struct nfs4_exception exception = { }; |
| 2716 | int err; |
| 2717 | do { |
| 2718 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2719 | _nfs4_proc_symlink(dir, dentry, page, |
| 2720 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2721 | &exception); |
| 2722 | } while (exception.retry); |
| 2723 | return err; |
| 2724 | } |
| 2725 | |
| 2726 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2727 | struct iattr *sattr) |
| 2728 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2729 | struct nfs4_createdata *data; |
| 2730 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2731 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2732 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 2733 | if (data == NULL) |
| 2734 | goto out; |
| 2735 | |
| 2736 | status = nfs4_do_create(dir, dentry, data); |
| 2737 | |
| 2738 | nfs4_free_createdata(data); |
| 2739 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2740 | return status; |
| 2741 | } |
| 2742 | |
| 2743 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2744 | struct iattr *sattr) |
| 2745 | { |
| 2746 | struct nfs4_exception exception = { }; |
| 2747 | int err; |
| 2748 | do { |
| 2749 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2750 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 2751 | &exception); |
| 2752 | } while (exception.retry); |
| 2753 | return err; |
| 2754 | } |
| 2755 | |
| 2756 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
| 2757 | u64 cookie, struct page *page, unsigned int count, int plus) |
| 2758 | { |
| 2759 | struct inode *dir = dentry->d_inode; |
| 2760 | struct nfs4_readdir_arg args = { |
| 2761 | .fh = NFS_FH(dir), |
| 2762 | .pages = &page, |
| 2763 | .pgbase = 0, |
| 2764 | .count = count, |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2765 | .bitmask = NFS_SERVER(dentry->d_inode)->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | }; |
| 2767 | struct nfs4_readdir_res res; |
| 2768 | struct rpc_message msg = { |
| 2769 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 2770 | .rpc_argp = &args, |
| 2771 | .rpc_resp = &res, |
| 2772 | .rpc_cred = cred, |
| 2773 | }; |
| 2774 | int status; |
| 2775 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2776 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 2777 | dentry->d_parent->d_name.name, |
| 2778 | dentry->d_name.name, |
| 2779 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 2781 | res.pgbase = args.pgbase; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2782 | status = nfs4_call_sync(NFS_SERVER(dir), &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | if (status == 0) |
| 2784 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 2785 | |
| 2786 | nfs_invalidate_atime(dir); |
| 2787 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2788 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | return status; |
| 2790 | } |
| 2791 | |
| 2792 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
| 2793 | u64 cookie, struct page *page, unsigned int count, int plus) |
| 2794 | { |
| 2795 | struct nfs4_exception exception = { }; |
| 2796 | int err; |
| 2797 | do { |
| 2798 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 2799 | _nfs4_proc_readdir(dentry, cred, cookie, |
| 2800 | page, count, plus), |
| 2801 | &exception); |
| 2802 | } while (exception.retry); |
| 2803 | return err; |
| 2804 | } |
| 2805 | |
| 2806 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2807 | struct iattr *sattr, dev_t rdev) |
| 2808 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2809 | struct nfs4_createdata *data; |
| 2810 | int mode = sattr->ia_mode; |
| 2811 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | |
| 2813 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 2814 | 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] | 2815 | |
| 2816 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 2817 | if (data == NULL) |
| 2818 | goto out; |
| 2819 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2820 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2821 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2823 | data->arg.ftype = NF4BLK; |
| 2824 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 2825 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2826 | } |
| 2827 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2828 | data->arg.ftype = NF4CHR; |
| 2829 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 2830 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2833 | status = nfs4_do_create(dir, dentry, data); |
| 2834 | |
| 2835 | nfs4_free_createdata(data); |
| 2836 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2837 | return status; |
| 2838 | } |
| 2839 | |
| 2840 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2841 | struct iattr *sattr, dev_t rdev) |
| 2842 | { |
| 2843 | struct nfs4_exception exception = { }; |
| 2844 | int err; |
| 2845 | do { |
| 2846 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2847 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 2848 | &exception); |
| 2849 | } while (exception.retry); |
| 2850 | return err; |
| 2851 | } |
| 2852 | |
| 2853 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2854 | struct nfs_fsstat *fsstat) |
| 2855 | { |
| 2856 | struct nfs4_statfs_arg args = { |
| 2857 | .fh = fhandle, |
| 2858 | .bitmask = server->attr_bitmask, |
| 2859 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 2860 | struct nfs4_statfs_res res = { |
| 2861 | .fsstat = fsstat, |
| 2862 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2863 | struct rpc_message msg = { |
| 2864 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 2865 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 2866 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2867 | }; |
| 2868 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2869 | nfs_fattr_init(fsstat->fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2870 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | } |
| 2872 | |
| 2873 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 2874 | { |
| 2875 | struct nfs4_exception exception = { }; |
| 2876 | int err; |
| 2877 | do { |
| 2878 | err = nfs4_handle_exception(server, |
| 2879 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 2880 | &exception); |
| 2881 | } while (exception.retry); |
| 2882 | return err; |
| 2883 | } |
| 2884 | |
| 2885 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2886 | struct nfs_fsinfo *fsinfo) |
| 2887 | { |
| 2888 | struct nfs4_fsinfo_arg args = { |
| 2889 | .fh = fhandle, |
| 2890 | .bitmask = server->attr_bitmask, |
| 2891 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 2892 | struct nfs4_fsinfo_res res = { |
| 2893 | .fsinfo = fsinfo, |
| 2894 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | struct rpc_message msg = { |
| 2896 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 2897 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 2898 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | }; |
| 2900 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2901 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2902 | } |
| 2903 | |
| 2904 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 2905 | { |
| 2906 | struct nfs4_exception exception = { }; |
| 2907 | int err; |
| 2908 | |
| 2909 | do { |
| 2910 | err = nfs4_handle_exception(server, |
| 2911 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 2912 | &exception); |
| 2913 | } while (exception.retry); |
| 2914 | return err; |
| 2915 | } |
| 2916 | |
| 2917 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 2918 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2919 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 2921 | } |
| 2922 | |
| 2923 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2924 | struct nfs_pathconf *pathconf) |
| 2925 | { |
| 2926 | struct nfs4_pathconf_arg args = { |
| 2927 | .fh = fhandle, |
| 2928 | .bitmask = server->attr_bitmask, |
| 2929 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 2930 | struct nfs4_pathconf_res res = { |
| 2931 | .pathconf = pathconf, |
| 2932 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | struct rpc_message msg = { |
| 2934 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 2935 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 2936 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2937 | }; |
| 2938 | |
| 2939 | /* None of the pathconf attributes are mandatory to implement */ |
| 2940 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 2941 | memset(pathconf, 0, sizeof(*pathconf)); |
| 2942 | return 0; |
| 2943 | } |
| 2944 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2945 | nfs_fattr_init(pathconf->fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2946 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2950 | struct nfs_pathconf *pathconf) |
| 2951 | { |
| 2952 | struct nfs4_exception exception = { }; |
| 2953 | int err; |
| 2954 | |
| 2955 | do { |
| 2956 | err = nfs4_handle_exception(server, |
| 2957 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 2958 | &exception); |
| 2959 | } while (exception.retry); |
| 2960 | return err; |
| 2961 | } |
| 2962 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 2963 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2964 | { |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 2965 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | |
Andy Adamson | f11c88a | 2009-04-01 09:22:25 -0400 | [diff] [blame] | 2967 | dprintk("--> %s\n", __func__); |
| 2968 | |
| 2969 | /* nfs4_sequence_free_slot called in the read rpc_call_done */ |
| 2970 | nfs4_sequence_done(server, &data->res.seq_res, task->tk_status); |
| 2971 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2972 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Andy Adamson | eedc020 | 2009-04-01 09:22:41 -0400 | [diff] [blame] | 2973 | nfs4_restart_rpc(task, server->nfs_client); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 2974 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 2976 | |
| 2977 | nfs_invalidate_atime(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 2979 | renew_lease(server, data->timestamp); |
| 2980 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2981 | } |
| 2982 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 2983 | 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] | 2984 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2985 | data->timestamp = jiffies; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 2986 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2987 | } |
| 2988 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 2989 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | struct inode *inode = data->inode; |
| 2992 | |
Andy Adamson | def6ed7 | 2009-04-01 09:22:26 -0400 | [diff] [blame] | 2993 | /* slot is freed in nfs_writeback_done */ |
| 2994 | nfs4_sequence_done(NFS_SERVER(inode), &data->res.seq_res, |
| 2995 | task->tk_status); |
| 2996 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2997 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) { |
Andy Adamson | eedc020 | 2009-04-01 09:22:41 -0400 | [diff] [blame] | 2998 | nfs4_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 2999 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3000 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3001 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 3003 | nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3004 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3005 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | } |
| 3007 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3008 | 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] | 3009 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3010 | struct nfs_server *server = NFS_SERVER(data->inode); |
| 3011 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3012 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3013 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3014 | data->timestamp = jiffies; |
| 3015 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3016 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | } |
| 3018 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3019 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3020 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | struct inode *inode = data->inode; |
| 3022 | |
Andy Adamson | 21d9a85 | 2009-04-01 09:22:27 -0400 | [diff] [blame] | 3023 | nfs4_sequence_done(NFS_SERVER(inode), &data->res.seq_res, |
| 3024 | task->tk_status); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3025 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Andy Adamson | eedc020 | 2009-04-01 09:22:41 -0400 | [diff] [blame] | 3026 | nfs4_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3027 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3028 | } |
Andy Adamson | 21d9a85 | 2009-04-01 09:22:27 -0400 | [diff] [blame] | 3029 | nfs4_sequence_free_slot(NFS_SERVER(inode)->nfs_client, |
| 3030 | &data->res.seq_res); |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 3031 | nfs_refresh_inode(inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3032 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | } |
| 3034 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3035 | 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] | 3036 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3037 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3038 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3039 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3040 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3041 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | } |
| 3043 | |
| 3044 | /* |
| 3045 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3046 | * standalone procedure for queueing an asynchronous RENEW. |
| 3047 | */ |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3048 | static void nfs4_renew_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3049 | { |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3050 | struct nfs_client *clp = (struct nfs_client *)task->tk_msg.rpc_argp; |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3051 | unsigned long timestamp = (unsigned long)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | |
| 3053 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3054 | /* Unless we're shutting down, schedule state recovery! */ |
| 3055 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) != 0) |
| 3056 | nfs4_schedule_state_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3057 | return; |
| 3058 | } |
| 3059 | spin_lock(&clp->cl_lock); |
| 3060 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 3061 | clp->cl_last_renewal = timestamp; |
| 3062 | spin_unlock(&clp->cl_lock); |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 3063 | dprintk("%s calling put_rpccred on rpc_cred %p\n", __func__, |
| 3064 | task->tk_msg.rpc_cred); |
| 3065 | put_rpccred(task->tk_msg.rpc_cred); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3066 | } |
| 3067 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3068 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3069 | .rpc_call_done = nfs4_renew_done, |
| 3070 | }; |
| 3071 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3072 | int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | { |
| 3074 | struct rpc_message msg = { |
| 3075 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3076 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3077 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3078 | }; |
| 3079 | |
| 3080 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3081 | &nfs4_renew_ops, (void *)jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3082 | } |
| 3083 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3084 | int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | { |
| 3086 | struct rpc_message msg = { |
| 3087 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3088 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3089 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3090 | }; |
| 3091 | unsigned long now = jiffies; |
| 3092 | int status; |
| 3093 | |
| 3094 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3095 | if (status < 0) |
| 3096 | return status; |
| 3097 | spin_lock(&clp->cl_lock); |
| 3098 | if (time_before(clp->cl_last_renewal,now)) |
| 3099 | clp->cl_last_renewal = now; |
| 3100 | spin_unlock(&clp->cl_lock); |
| 3101 | return 0; |
| 3102 | } |
| 3103 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3104 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3105 | { |
| 3106 | return (server->caps & NFS_CAP_ACLS) |
| 3107 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3108 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3109 | } |
| 3110 | |
| 3111 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3112 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3113 | * the stack. |
| 3114 | */ |
| 3115 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3116 | |
| 3117 | static void buf_to_pages(const void *buf, size_t buflen, |
| 3118 | struct page **pages, unsigned int *pgbase) |
| 3119 | { |
| 3120 | const void *p = buf; |
| 3121 | |
| 3122 | *pgbase = offset_in_page(buf); |
| 3123 | p -= *pgbase; |
| 3124 | while (p < buf + buflen) { |
| 3125 | *(pages++) = virt_to_page(p); |
| 3126 | p += PAGE_CACHE_SIZE; |
| 3127 | } |
| 3128 | } |
| 3129 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3130 | struct nfs4_cached_acl { |
| 3131 | int cached; |
| 3132 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3133 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3134 | }; |
| 3135 | |
| 3136 | 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] | 3137 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3138 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3139 | |
| 3140 | spin_lock(&inode->i_lock); |
| 3141 | kfree(nfsi->nfs4_acl); |
| 3142 | nfsi->nfs4_acl = acl; |
| 3143 | spin_unlock(&inode->i_lock); |
| 3144 | } |
| 3145 | |
| 3146 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3147 | { |
| 3148 | nfs4_set_cached_acl(inode, NULL); |
| 3149 | } |
| 3150 | |
| 3151 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3152 | { |
| 3153 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3154 | struct nfs4_cached_acl *acl; |
| 3155 | int ret = -ENOENT; |
| 3156 | |
| 3157 | spin_lock(&inode->i_lock); |
| 3158 | acl = nfsi->nfs4_acl; |
| 3159 | if (acl == NULL) |
| 3160 | goto out; |
| 3161 | if (buf == NULL) /* user is just asking for length */ |
| 3162 | goto out_len; |
| 3163 | if (acl->cached == 0) |
| 3164 | goto out; |
| 3165 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3166 | if (acl->len > buflen) |
| 3167 | goto out; |
| 3168 | memcpy(buf, acl->data, acl->len); |
| 3169 | out_len: |
| 3170 | ret = acl->len; |
| 3171 | out: |
| 3172 | spin_unlock(&inode->i_lock); |
| 3173 | return ret; |
| 3174 | } |
| 3175 | |
| 3176 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) |
| 3177 | { |
| 3178 | struct nfs4_cached_acl *acl; |
| 3179 | |
| 3180 | if (buf && acl_len <= PAGE_SIZE) { |
| 3181 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3182 | if (acl == NULL) |
| 3183 | goto out; |
| 3184 | acl->cached = 1; |
| 3185 | memcpy(acl->data, buf, acl_len); |
| 3186 | } else { |
| 3187 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3188 | if (acl == NULL) |
| 3189 | goto out; |
| 3190 | acl->cached = 0; |
| 3191 | } |
| 3192 | acl->len = acl_len; |
| 3193 | out: |
| 3194 | nfs4_set_cached_acl(inode, acl); |
| 3195 | } |
| 3196 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3197 | 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] | 3198 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3199 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3200 | struct nfs_getaclargs args = { |
| 3201 | .fh = NFS_FH(inode), |
| 3202 | .acl_pages = pages, |
| 3203 | .acl_len = buflen, |
| 3204 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3205 | struct nfs_getaclres res = { |
| 3206 | .acl_len = buflen, |
| 3207 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3208 | void *resp_buf; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3209 | struct rpc_message msg = { |
| 3210 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3211 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3212 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3213 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3214 | struct page *localpage = NULL; |
| 3215 | int ret; |
| 3216 | |
| 3217 | if (buflen < PAGE_SIZE) { |
| 3218 | /* As long as we're doing a round trip to the server anyway, |
| 3219 | * let's be prepared for a page of acl data. */ |
| 3220 | localpage = alloc_page(GFP_KERNEL); |
| 3221 | resp_buf = page_address(localpage); |
| 3222 | if (localpage == NULL) |
| 3223 | return -ENOMEM; |
| 3224 | args.acl_pages[0] = localpage; |
| 3225 | args.acl_pgbase = 0; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3226 | args.acl_len = PAGE_SIZE; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3227 | } else { |
| 3228 | resp_buf = buf; |
| 3229 | buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase); |
| 3230 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3231 | ret = nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3232 | if (ret) |
| 3233 | goto out_free; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3234 | if (res.acl_len > args.acl_len) |
| 3235 | nfs4_write_cached_acl(inode, NULL, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3236 | else |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3237 | nfs4_write_cached_acl(inode, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3238 | if (buf) { |
| 3239 | ret = -ERANGE; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3240 | if (res.acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3241 | goto out_free; |
| 3242 | if (localpage) |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3243 | memcpy(buf, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3244 | } |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3245 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3246 | out_free: |
| 3247 | if (localpage) |
| 3248 | __free_page(localpage); |
| 3249 | return ret; |
| 3250 | } |
| 3251 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3252 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3253 | { |
| 3254 | struct nfs4_exception exception = { }; |
| 3255 | ssize_t ret; |
| 3256 | do { |
| 3257 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3258 | if (ret >= 0) |
| 3259 | break; |
| 3260 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3261 | } while (exception.retry); |
| 3262 | return ret; |
| 3263 | } |
| 3264 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3265 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3266 | { |
| 3267 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3268 | int ret; |
| 3269 | |
| 3270 | if (!nfs4_server_supports_acls(server)) |
| 3271 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3272 | ret = nfs_revalidate_inode(server, inode); |
| 3273 | if (ret < 0) |
| 3274 | return ret; |
| 3275 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3276 | if (ret != -ENOENT) |
| 3277 | return ret; |
| 3278 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3279 | } |
| 3280 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3281 | 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] | 3282 | { |
| 3283 | struct nfs_server *server = NFS_SERVER(inode); |
| 3284 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3285 | struct nfs_setaclargs arg = { |
| 3286 | .fh = NFS_FH(inode), |
| 3287 | .acl_pages = pages, |
| 3288 | .acl_len = buflen, |
| 3289 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3290 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3291 | struct rpc_message msg = { |
| 3292 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3293 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3294 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3295 | }; |
| 3296 | int ret; |
| 3297 | |
| 3298 | if (!nfs4_server_supports_acls(server)) |
| 3299 | return -EOPNOTSUPP; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3300 | nfs_inode_return_delegation(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3301 | buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3302 | ret = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3303 | nfs_access_zap_cache(inode); |
| 3304 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3305 | return ret; |
| 3306 | } |
| 3307 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3308 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3309 | { |
| 3310 | struct nfs4_exception exception = { }; |
| 3311 | int err; |
| 3312 | do { |
| 3313 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3314 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3315 | &exception); |
| 3316 | } while (exception.retry); |
| 3317 | return err; |
| 3318 | } |
| 3319 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3320 | static int |
Andy Adamson | 8328d59 | 2009-04-01 09:22:35 -0400 | [diff] [blame] | 3321 | _nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs_client *clp, struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3322 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | if (!clp || task->tk_status >= 0) |
| 3324 | return 0; |
| 3325 | switch(task->tk_status) { |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3326 | case -NFS4ERR_ADMIN_REVOKED: |
| 3327 | case -NFS4ERR_BAD_STATEID: |
| 3328 | case -NFS4ERR_OPENMODE: |
| 3329 | if (state == NULL) |
| 3330 | break; |
| 3331 | nfs4_state_mark_reclaim_nograce(clp, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3332 | case -NFS4ERR_STALE_CLIENTID: |
| 3333 | case -NFS4ERR_STALE_STATEID: |
| 3334 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d00837 | 2008-02-22 16:34:17 -0500 | [diff] [blame] | 3335 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3336 | nfs4_schedule_state_recovery(clp); |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 3337 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
Trond Myklebust | fda1393 | 2008-02-22 16:34:12 -0500 | [diff] [blame] | 3338 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | task->tk_status = 0; |
| 3340 | return -EAGAIN; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3341 | #if defined(CONFIG_NFS_V4_1) |
| 3342 | case -NFS4ERR_BADSESSION: |
| 3343 | case -NFS4ERR_BADSLOT: |
| 3344 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3345 | case -NFS4ERR_DEADSESSION: |
| 3346 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3347 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3348 | case -NFS4ERR_SEQ_MISORDERED: |
| 3349 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3350 | task->tk_status); |
| 3351 | set_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state); |
| 3352 | task->tk_status = 0; |
| 3353 | return -EAGAIN; |
| 3354 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | case -NFS4ERR_DELAY: |
Andy Adamson | 8328d59 | 2009-04-01 09:22:35 -0400 | [diff] [blame] | 3356 | if (server) |
| 3357 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3358 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3359 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3360 | task->tk_status = 0; |
| 3361 | return -EAGAIN; |
| 3362 | case -NFS4ERR_OLD_STATEID: |
| 3363 | task->tk_status = 0; |
| 3364 | return -EAGAIN; |
| 3365 | } |
| 3366 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3367 | return 0; |
| 3368 | } |
| 3369 | |
Andy Adamson | 8328d59 | 2009-04-01 09:22:35 -0400 | [diff] [blame] | 3370 | static int |
| 3371 | nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs4_state *state) |
| 3372 | { |
| 3373 | return _nfs4_async_handle_error(task, server, server->nfs_client, state); |
| 3374 | } |
| 3375 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3376 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, unsigned short port, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3377 | { |
| 3378 | nfs4_verifier sc_verifier; |
| 3379 | struct nfs4_setclientid setclientid = { |
| 3380 | .sc_verifier = &sc_verifier, |
| 3381 | .sc_prog = program, |
| 3382 | }; |
| 3383 | struct rpc_message msg = { |
| 3384 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3385 | .rpc_argp = &setclientid, |
| 3386 | .rpc_resp = clp, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3387 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | }; |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3389 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | int loop = 0; |
| 3391 | int status; |
| 3392 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3393 | p = (__be32*)sc_verifier.data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 3395 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 3396 | |
| 3397 | for(;;) { |
| 3398 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3399 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3400 | clp->cl_ipaddr, |
| 3401 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3402 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3403 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3404 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3405 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3406 | clp->cl_id_uniquifier); |
| 3407 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3408 | sizeof(setclientid.sc_netid), |
| 3409 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3410 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3411 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3412 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | clp->cl_ipaddr, port >> 8, port & 255); |
| 3414 | |
| 3415 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3416 | if (status != -NFS4ERR_CLID_INUSE) |
| 3417 | break; |
| 3418 | if (signalled()) |
| 3419 | break; |
| 3420 | if (loop++ & 1) |
| 3421 | ssleep(clp->cl_lease_time + 1); |
| 3422 | else |
| 3423 | if (++clp->cl_id_uniquifier == 0) |
| 3424 | break; |
| 3425 | } |
| 3426 | return status; |
| 3427 | } |
| 3428 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3429 | static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3430 | { |
| 3431 | struct nfs_fsinfo fsinfo; |
| 3432 | struct rpc_message msg = { |
| 3433 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
| 3434 | .rpc_argp = clp, |
| 3435 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3436 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3437 | }; |
| 3438 | unsigned long now; |
| 3439 | int status; |
| 3440 | |
| 3441 | now = jiffies; |
| 3442 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3443 | if (status == 0) { |
| 3444 | spin_lock(&clp->cl_lock); |
| 3445 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 3446 | clp->cl_last_renewal = now; |
| 3447 | spin_unlock(&clp->cl_lock); |
| 3448 | } |
| 3449 | return status; |
| 3450 | } |
| 3451 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3452 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, struct rpc_cred *cred) |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3453 | { |
Benny Halevy | 77e0367 | 2008-06-24 20:25:57 +0300 | [diff] [blame] | 3454 | long timeout = 0; |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3455 | int err; |
| 3456 | do { |
| 3457 | err = _nfs4_proc_setclientid_confirm(clp, cred); |
| 3458 | switch (err) { |
| 3459 | case 0: |
| 3460 | return err; |
| 3461 | case -NFS4ERR_RESOURCE: |
| 3462 | /* The IBM lawyers misread another document! */ |
| 3463 | case -NFS4ERR_DELAY: |
| 3464 | err = nfs4_delay(clp->cl_rpcclient, &timeout); |
| 3465 | } |
| 3466 | } while (err == 0); |
| 3467 | return err; |
| 3468 | } |
| 3469 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3470 | struct nfs4_delegreturndata { |
| 3471 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3472 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3473 | struct nfs_fh fh; |
| 3474 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3475 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3476 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3477 | int rpc_status; |
| 3478 | }; |
| 3479 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3480 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 3481 | { |
| 3482 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3483 | |
| 3484 | nfs4_sequence_done_free_slot(data->res.server, &data->res.seq_res, |
| 3485 | task->tk_status); |
| 3486 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3487 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3488 | if (data->rpc_status == 0) |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3489 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3490 | } |
| 3491 | |
| 3492 | static void nfs4_delegreturn_release(void *calldata) |
| 3493 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3494 | kfree(calldata); |
| 3495 | } |
| 3496 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3497 | #if defined(CONFIG_NFS_V4_1) |
| 3498 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 3499 | { |
| 3500 | struct nfs4_delegreturndata *d_data; |
| 3501 | |
| 3502 | d_data = (struct nfs4_delegreturndata *)data; |
| 3503 | |
| 3504 | if (nfs4_setup_sequence(d_data->res.server->nfs_client, |
| 3505 | &d_data->args.seq_args, |
| 3506 | &d_data->res.seq_res, 1, task)) |
| 3507 | return; |
| 3508 | rpc_call_start(task); |
| 3509 | } |
| 3510 | #endif /* CONFIG_NFS_V4_1 */ |
| 3511 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 3512 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3513 | #if defined(CONFIG_NFS_V4_1) |
| 3514 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 3515 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3516 | .rpc_call_done = nfs4_delegreturn_done, |
| 3517 | .rpc_release = nfs4_delegreturn_release, |
| 3518 | }; |
| 3519 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3520 | 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] | 3521 | { |
| 3522 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3523 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3524 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3525 | struct rpc_message msg = { |
| 3526 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 3527 | .rpc_cred = cred, |
| 3528 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3529 | struct rpc_task_setup task_setup_data = { |
| 3530 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3531 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3532 | .callback_ops = &nfs4_delegreturn_ops, |
| 3533 | .flags = RPC_TASK_ASYNC, |
| 3534 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3535 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3536 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3537 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3538 | if (data == NULL) |
| 3539 | return -ENOMEM; |
| 3540 | data->args.fhandle = &data->fh; |
| 3541 | data->args.stateid = &data->stateid; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3542 | data->args.bitmask = server->attr_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3543 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
| 3544 | memcpy(&data->stateid, stateid, sizeof(data->stateid)); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3545 | data->res.fattr = &data->fattr; |
| 3546 | data->res.server = server; |
Andy Adamson | 5f7dbd5 | 2009-04-01 09:22:05 -0400 | [diff] [blame] | 3547 | data->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3548 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3549 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3550 | data->rpc_status = 0; |
| 3551 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3552 | task_setup_data.callback_data = data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3553 | msg.rpc_argp = &data->args, |
| 3554 | msg.rpc_resp = &data->res, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3555 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 3556 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3557 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3558 | if (!issync) |
| 3559 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3560 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3561 | if (status != 0) |
| 3562 | goto out; |
| 3563 | status = data->rpc_status; |
| 3564 | if (status != 0) |
| 3565 | goto out; |
| 3566 | nfs_refresh_inode(inode, &data->fattr); |
| 3567 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3568 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3569 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | } |
| 3571 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3572 | 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] | 3573 | { |
| 3574 | struct nfs_server *server = NFS_SERVER(inode); |
| 3575 | struct nfs4_exception exception = { }; |
| 3576 | int err; |
| 3577 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3578 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | switch (err) { |
| 3580 | case -NFS4ERR_STALE_STATEID: |
| 3581 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3582 | case 0: |
| 3583 | return 0; |
| 3584 | } |
| 3585 | err = nfs4_handle_exception(server, err, &exception); |
| 3586 | } while (exception.retry); |
| 3587 | return err; |
| 3588 | } |
| 3589 | |
| 3590 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 3591 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 3592 | |
| 3593 | /* |
| 3594 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 3595 | */ |
| 3596 | static unsigned long |
| 3597 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 3598 | { |
Matthew Wilcox | 150030b | 2007-12-06 16:24:39 -0500 | [diff] [blame] | 3599 | schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3600 | timeout <<= 1; |
| 3601 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 3602 | return NFS4_LOCK_MAXTIMEOUT; |
| 3603 | return timeout; |
| 3604 | } |
| 3605 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3606 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3607 | { |
| 3608 | struct inode *inode = state->inode; |
| 3609 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3610 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3611 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3612 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3613 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3614 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3615 | struct nfs_lockt_res res = { |
| 3616 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3617 | }; |
| 3618 | struct rpc_message msg = { |
| 3619 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 3620 | .rpc_argp = &arg, |
| 3621 | .rpc_resp = &res, |
| 3622 | .rpc_cred = state->owner->so_cred, |
| 3623 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3624 | struct nfs4_lock_state *lsp; |
| 3625 | int status; |
| 3626 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3627 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3628 | status = nfs4_set_lock_state(state, request); |
| 3629 | if (status != 0) |
| 3630 | goto out; |
| 3631 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 3632 | arg.lock_owner.id = lsp->ls_id.id; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3633 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3634 | switch (status) { |
| 3635 | case 0: |
| 3636 | request->fl_type = F_UNLCK; |
| 3637 | break; |
| 3638 | case -NFS4ERR_DENIED: |
| 3639 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3640 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 3641 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3642 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3643 | return status; |
| 3644 | } |
| 3645 | |
| 3646 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3647 | { |
| 3648 | struct nfs4_exception exception = { }; |
| 3649 | int err; |
| 3650 | |
| 3651 | do { |
| 3652 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 3653 | _nfs4_proc_getlk(state, cmd, request), |
| 3654 | &exception); |
| 3655 | } while (exception.retry); |
| 3656 | return err; |
| 3657 | } |
| 3658 | |
| 3659 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 3660 | { |
| 3661 | int res = 0; |
| 3662 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 3663 | case FL_POSIX: |
| 3664 | res = posix_lock_file_wait(file, fl); |
| 3665 | break; |
| 3666 | case FL_FLOCK: |
| 3667 | res = flock_lock_file_wait(file, fl); |
| 3668 | break; |
| 3669 | default: |
| 3670 | BUG(); |
| 3671 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3672 | return res; |
| 3673 | } |
| 3674 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3675 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3676 | struct nfs_locku_args arg; |
| 3677 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3678 | struct nfs4_lock_state *lsp; |
| 3679 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3680 | struct file_lock fl; |
| 3681 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3682 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3683 | }; |
| 3684 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3685 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 3686 | struct nfs_open_context *ctx, |
| 3687 | struct nfs4_lock_state *lsp, |
| 3688 | struct nfs_seqid *seqid) |
| 3689 | { |
| 3690 | struct nfs4_unlockdata *p; |
| 3691 | struct inode *inode = lsp->ls_state->inode; |
| 3692 | |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 3693 | p = kzalloc(sizeof(*p), GFP_KERNEL); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3694 | if (p == NULL) |
| 3695 | return NULL; |
| 3696 | p->arg.fh = NFS_FH(inode); |
| 3697 | p->arg.fl = &p->fl; |
| 3698 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3699 | p->res.seqid = seqid; |
Andy Adamson | 5f7dbd5 | 2009-04-01 09:22:05 -0400 | [diff] [blame] | 3700 | p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3701 | p->arg.stateid = &lsp->ls_stateid; |
| 3702 | p->lsp = lsp; |
| 3703 | atomic_inc(&lsp->ls_count); |
| 3704 | /* Ensure we don't close file until we're done freeing locks! */ |
| 3705 | p->ctx = get_nfs_open_context(ctx); |
| 3706 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 3707 | p->server = NFS_SERVER(inode); |
| 3708 | return p; |
| 3709 | } |
| 3710 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3711 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3712 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3713 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3714 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3715 | nfs4_put_lock_state(calldata->lsp); |
| 3716 | put_nfs_open_context(calldata->ctx); |
| 3717 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3718 | } |
| 3719 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3720 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3721 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3722 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3723 | |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 3724 | nfs4_sequence_done(calldata->server, &calldata->res.seq_res, |
| 3725 | task->tk_status); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3726 | if (RPC_ASSASSINATED(task)) |
| 3727 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3728 | switch (task->tk_status) { |
| 3729 | case 0: |
| 3730 | memcpy(calldata->lsp->ls_stateid.data, |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3731 | calldata->res.stateid.data, |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3732 | sizeof(calldata->lsp->ls_stateid.data)); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3733 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3734 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3735 | case -NFS4ERR_BAD_STATEID: |
| 3736 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3737 | case -NFS4ERR_STALE_STATEID: |
| 3738 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3739 | break; |
| 3740 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3741 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Andy Adamson | eedc020 | 2009-04-01 09:22:41 -0400 | [diff] [blame] | 3742 | nfs4_restart_rpc(task, |
| 3743 | calldata->server->nfs_client); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3744 | } |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 3745 | nfs4_sequence_free_slot(calldata->server->nfs_client, |
| 3746 | &calldata->res.seq_res); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3747 | } |
| 3748 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3749 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3750 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3751 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3752 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3753 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3754 | return; |
| 3755 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3756 | /* Note: exit _without_ running nfs4_locku_done */ |
| 3757 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3758 | return; |
| 3759 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3760 | calldata->timestamp = jiffies; |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 3761 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
| 3762 | &calldata->arg.seq_args, |
| 3763 | &calldata->res.seq_res, 1, task)) |
| 3764 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3765 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3766 | } |
| 3767 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3768 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3769 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3770 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3771 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3772 | }; |
| 3773 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3774 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 3775 | struct nfs_open_context *ctx, |
| 3776 | struct nfs4_lock_state *lsp, |
| 3777 | struct nfs_seqid *seqid) |
| 3778 | { |
| 3779 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3780 | struct rpc_message msg = { |
| 3781 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 3782 | .rpc_cred = ctx->cred, |
| 3783 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3784 | struct rpc_task_setup task_setup_data = { |
| 3785 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3786 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3787 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3788 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3789 | .flags = RPC_TASK_ASYNC, |
| 3790 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3791 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 3792 | /* Ensure this is an unlock - when canceling a lock, the |
| 3793 | * canceled lock is passed in, and it won't be an unlock. |
| 3794 | */ |
| 3795 | fl->fl_type = F_UNLCK; |
| 3796 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3797 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 3798 | if (data == NULL) { |
| 3799 | nfs_free_seqid(seqid); |
| 3800 | return ERR_PTR(-ENOMEM); |
| 3801 | } |
| 3802 | |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3803 | msg.rpc_argp = &data->arg, |
| 3804 | msg.rpc_resp = &data->res, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3805 | task_setup_data.callback_data = data; |
| 3806 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3807 | } |
| 3808 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3809 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3810 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3811 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3812 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3813 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3814 | struct rpc_task *task; |
| 3815 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 3816 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3817 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3818 | status = nfs4_set_lock_state(state, request); |
| 3819 | /* Unlock _before_ we do the RPC call */ |
| 3820 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3821 | down_read(&nfsi->rwsem); |
| 3822 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 3823 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3824 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3825 | } |
| 3826 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3827 | if (status != 0) |
| 3828 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 3829 | /* Is this a delegated lock? */ |
| 3830 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3831 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3832 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3833 | seqid = nfs_alloc_seqid(&lsp->ls_seqid); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3834 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3835 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3836 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 3837 | 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] | 3838 | status = PTR_ERR(task); |
| 3839 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3840 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3841 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3842 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3843 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 3844 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3845 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3846 | } |
| 3847 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3848 | struct nfs4_lockdata { |
| 3849 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3850 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3851 | struct nfs4_lock_state *lsp; |
| 3852 | struct nfs_open_context *ctx; |
| 3853 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3854 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3855 | int rpc_status; |
| 3856 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 3857 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3858 | }; |
| 3859 | |
| 3860 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
| 3861 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp) |
| 3862 | { |
| 3863 | struct nfs4_lockdata *p; |
| 3864 | struct inode *inode = lsp->ls_state->inode; |
| 3865 | struct nfs_server *server = NFS_SERVER(inode); |
| 3866 | |
| 3867 | p = kzalloc(sizeof(*p), GFP_KERNEL); |
| 3868 | if (p == NULL) |
| 3869 | return NULL; |
| 3870 | |
| 3871 | p->arg.fh = NFS_FH(inode); |
| 3872 | p->arg.fl = &p->fl; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 3873 | p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid); |
| 3874 | if (p->arg.open_seqid == NULL) |
| 3875 | goto out_free; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3876 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid); |
| 3877 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 3878 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3879 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3880 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 3881 | p->arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3882 | p->res.lock_seqid = p->arg.lock_seqid; |
Andy Adamson | 5f7dbd5 | 2009-04-01 09:22:05 -0400 | [diff] [blame] | 3883 | p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3884 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 3885 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3886 | atomic_inc(&lsp->ls_count); |
| 3887 | p->ctx = get_nfs_open_context(ctx); |
| 3888 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 3889 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 3890 | out_free_seqid: |
| 3891 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3892 | out_free: |
| 3893 | kfree(p); |
| 3894 | return NULL; |
| 3895 | } |
| 3896 | |
| 3897 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 3898 | { |
| 3899 | struct nfs4_lockdata *data = calldata; |
| 3900 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3901 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3902 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 3903 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 3904 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3905 | /* Do we need to do an open_to_lock_owner? */ |
| 3906 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 3907 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 3908 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3909 | data->arg.open_stateid = &state->stateid; |
| 3910 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3911 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 3912 | } else |
| 3913 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3914 | data->timestamp = jiffies; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 3915 | if (nfs4_setup_sequence(data->server->nfs_client, &data->arg.seq_args, |
| 3916 | &data->res.seq_res, 1, task)) |
| 3917 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3918 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3919 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3920 | } |
| 3921 | |
| 3922 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 3923 | { |
| 3924 | struct nfs4_lockdata *data = calldata; |
| 3925 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3926 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3927 | |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 3928 | nfs4_sequence_done_free_slot(data->server, &data->res.seq_res, |
| 3929 | task->tk_status); |
| 3930 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3931 | data->rpc_status = task->tk_status; |
| 3932 | if (RPC_ASSASSINATED(task)) |
| 3933 | goto out; |
| 3934 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3935 | if (data->rpc_status == 0) |
| 3936 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 3937 | else |
| 3938 | goto out; |
| 3939 | } |
| 3940 | if (data->rpc_status == 0) { |
| 3941 | memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, |
| 3942 | sizeof(data->lsp->ls_stateid.data)); |
| 3943 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Trond Myklebust | 88be9f9 | 2007-06-05 10:42:27 -0400 | [diff] [blame] | 3944 | renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3945 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3946 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3947 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3948 | } |
| 3949 | |
| 3950 | static void nfs4_lock_release(void *calldata) |
| 3951 | { |
| 3952 | struct nfs4_lockdata *data = calldata; |
| 3953 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3954 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 3955 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3956 | if (data->cancelled != 0) { |
| 3957 | struct rpc_task *task; |
| 3958 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 3959 | data->arg.lock_seqid); |
| 3960 | if (!IS_ERR(task)) |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3961 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3962 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3963 | } else |
| 3964 | nfs_free_seqid(data->arg.lock_seqid); |
| 3965 | nfs4_put_lock_state(data->lsp); |
| 3966 | put_nfs_open_context(data->ctx); |
| 3967 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3968 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3969 | } |
| 3970 | |
| 3971 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 3972 | .rpc_call_prepare = nfs4_lock_prepare, |
| 3973 | .rpc_call_done = nfs4_lock_done, |
| 3974 | .rpc_release = nfs4_lock_release, |
| 3975 | }; |
| 3976 | |
| 3977 | static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int reclaim) |
| 3978 | { |
| 3979 | struct nfs4_lockdata *data; |
| 3980 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3981 | struct rpc_message msg = { |
| 3982 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 3983 | .rpc_cred = state->owner->so_cred, |
| 3984 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3985 | struct rpc_task_setup task_setup_data = { |
| 3986 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3987 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3988 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3989 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3990 | .flags = RPC_TASK_ASYNC, |
| 3991 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3992 | int ret; |
| 3993 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3994 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 3995 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3996 | fl->fl_u.nfs4_fl.owner); |
| 3997 | if (data == NULL) |
| 3998 | return -ENOMEM; |
| 3999 | if (IS_SETLKW(cmd)) |
| 4000 | data->arg.block = 1; |
| 4001 | if (reclaim != 0) |
| 4002 | data->arg.reclaim = 1; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4003 | msg.rpc_argp = &data->arg, |
| 4004 | msg.rpc_resp = &data->res, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4005 | task_setup_data.callback_data = data; |
| 4006 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4007 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4008 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4009 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4010 | if (ret == 0) { |
| 4011 | ret = data->rpc_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4012 | } else |
| 4013 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4014 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4015 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4016 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 | } |
| 4018 | |
| 4019 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4020 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4021 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4022 | struct nfs4_exception exception = { }; |
| 4023 | int err; |
| 4024 | |
| 4025 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4026 | /* Cache the lock if possible... */ |
| 4027 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4028 | return 0; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4029 | err = _nfs4_do_setlk(state, F_SETLK, request, 1); |
| 4030 | if (err != -NFS4ERR_DELAY) |
| 4031 | break; |
| 4032 | nfs4_handle_exception(server, err, &exception); |
| 4033 | } while (exception.retry); |
| 4034 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4035 | } |
| 4036 | |
| 4037 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4038 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4039 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4040 | struct nfs4_exception exception = { }; |
| 4041 | int err; |
| 4042 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4043 | err = nfs4_set_lock_state(state, request); |
| 4044 | if (err != 0) |
| 4045 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4046 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4047 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4048 | return 0; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4049 | err = _nfs4_do_setlk(state, F_SETLK, request, 0); |
| 4050 | if (err != -NFS4ERR_DELAY) |
| 4051 | break; |
| 4052 | nfs4_handle_exception(server, err, &exception); |
| 4053 | } while (exception.retry); |
| 4054 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4055 | } |
| 4056 | |
| 4057 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4058 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4059 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4060 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4061 | int status; |
| 4062 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4063 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4064 | status = nfs4_set_lock_state(state, request); |
| 4065 | if (status != 0) |
| 4066 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4067 | request->fl_flags |= FL_ACCESS; |
| 4068 | status = do_vfs_lock(request->fl_file, request); |
| 4069 | if (status < 0) |
| 4070 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4071 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4072 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4073 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4074 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4075 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4076 | status = do_vfs_lock(request->fl_file, request); |
| 4077 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4078 | } |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4079 | status = _nfs4_do_setlk(state, cmd, request, 0); |
| 4080 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4081 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4082 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4083 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4084 | if (do_vfs_lock(request->fl_file, request) < 0) |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4085 | printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4086 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4087 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4088 | out: |
| 4089 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4090 | return status; |
| 4091 | } |
| 4092 | |
| 4093 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4094 | { |
| 4095 | struct nfs4_exception exception = { }; |
| 4096 | int err; |
| 4097 | |
| 4098 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4099 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4100 | if (err == -NFS4ERR_DENIED) |
| 4101 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4102 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4103 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4104 | } while (exception.retry); |
| 4105 | return err; |
| 4106 | } |
| 4107 | |
| 4108 | static int |
| 4109 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4110 | { |
| 4111 | struct nfs_open_context *ctx; |
| 4112 | struct nfs4_state *state; |
| 4113 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4114 | int status; |
| 4115 | |
| 4116 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4117 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4118 | state = ctx->state; |
| 4119 | |
| 4120 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4121 | return -EINVAL; |
| 4122 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4123 | if (IS_GETLK(cmd)) { |
| 4124 | if (state != NULL) |
| 4125 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4126 | return 0; |
| 4127 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4128 | |
| 4129 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4130 | return -EINVAL; |
| 4131 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4132 | if (request->fl_type == F_UNLCK) { |
| 4133 | if (state != NULL) |
| 4134 | return nfs4_proc_unlck(state, cmd, request); |
| 4135 | return 0; |
| 4136 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4137 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4138 | if (state == NULL) |
| 4139 | return -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4140 | do { |
| 4141 | status = nfs4_proc_setlk(state, cmd, request); |
| 4142 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4143 | break; |
| 4144 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4145 | status = -ERESTARTSYS; |
| 4146 | if (signalled()) |
| 4147 | break; |
| 4148 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4149 | return status; |
| 4150 | } |
| 4151 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4152 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4153 | { |
| 4154 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4155 | struct nfs4_exception exception = { }; |
| 4156 | int err; |
| 4157 | |
| 4158 | err = nfs4_set_lock_state(state, fl); |
| 4159 | if (err != 0) |
| 4160 | goto out; |
| 4161 | do { |
| 4162 | err = _nfs4_do_setlk(state, F_SETLK, fl, 0); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4163 | switch (err) { |
| 4164 | default: |
| 4165 | printk(KERN_ERR "%s: unhandled error %d.\n", |
| 4166 | __func__, err); |
| 4167 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4168 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4169 | goto out; |
| 4170 | case -NFS4ERR_EXPIRED: |
| 4171 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4172 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4173 | nfs4_schedule_state_recovery(server->nfs_client); |
| 4174 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4175 | case -ERESTARTSYS: |
| 4176 | /* |
| 4177 | * The show must go on: exit, but mark the |
| 4178 | * stateid as needing recovery. |
| 4179 | */ |
| 4180 | case -NFS4ERR_ADMIN_REVOKED: |
| 4181 | case -NFS4ERR_BAD_STATEID: |
| 4182 | case -NFS4ERR_OPENMODE: |
| 4183 | nfs4_state_mark_reclaim_nograce(server->nfs_client, state); |
| 4184 | err = 0; |
| 4185 | goto out; |
| 4186 | case -ENOMEM: |
| 4187 | case -NFS4ERR_DENIED: |
| 4188 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4189 | err = 0; |
| 4190 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4191 | case -NFS4ERR_DELAY: |
| 4192 | break; |
| 4193 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4194 | err = nfs4_handle_exception(server, err, &exception); |
| 4195 | } while (exception.retry); |
| 4196 | out: |
| 4197 | return err; |
| 4198 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4199 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4200 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4201 | |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4202 | int nfs4_setxattr(struct dentry *dentry, const char *key, const void *buf, |
| 4203 | size_t buflen, int flags) |
| 4204 | { |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4205 | struct inode *inode = dentry->d_inode; |
| 4206 | |
| 4207 | if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0) |
| 4208 | return -EOPNOTSUPP; |
| 4209 | |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4210 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4211 | } |
| 4212 | |
| 4213 | /* The getxattr man page suggests returning -ENODATA for unknown attributes, |
| 4214 | * and that's what we'll do for e.g. user attributes that haven't been set. |
| 4215 | * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported |
| 4216 | * attributes in kernel-managed attribute namespaces. */ |
| 4217 | ssize_t nfs4_getxattr(struct dentry *dentry, const char *key, void *buf, |
| 4218 | size_t buflen) |
| 4219 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4220 | struct inode *inode = dentry->d_inode; |
| 4221 | |
| 4222 | if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0) |
| 4223 | return -EOPNOTSUPP; |
| 4224 | |
| 4225 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4226 | } |
| 4227 | |
| 4228 | ssize_t nfs4_listxattr(struct dentry *dentry, char *buf, size_t buflen) |
| 4229 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4230 | size_t len = strlen(XATTR_NAME_NFSV4_ACL) + 1; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4231 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4232 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4233 | return 0; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4234 | if (buf && buflen < len) |
| 4235 | return -ERANGE; |
| 4236 | if (buf) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4237 | memcpy(buf, XATTR_NAME_NFSV4_ACL, len); |
| 4238 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4239 | } |
| 4240 | |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4241 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4242 | { |
| 4243 | if (!((fattr->valid & NFS_ATTR_FATTR_FILEID) && |
| 4244 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
| 4245 | (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL))) |
| 4246 | return; |
| 4247 | |
| 4248 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 4249 | NFS_ATTR_FATTR_NLINK; |
| 4250 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4251 | fattr->nlink = 2; |
| 4252 | } |
| 4253 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 4254 | int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 4255 | struct nfs4_fs_locations *fs_locations, struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4256 | { |
| 4257 | struct nfs_server *server = NFS_SERVER(dir); |
| 4258 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4259 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 4260 | [1] = FATTR4_WORD1_MOUNTED_ON_FILEID, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4261 | }; |
| 4262 | struct nfs4_fs_locations_arg args = { |
| 4263 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4264 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4265 | .page = page, |
| 4266 | .bitmask = bitmask, |
| 4267 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4268 | struct nfs4_fs_locations_res res = { |
| 4269 | .fs_locations = fs_locations, |
| 4270 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4271 | struct rpc_message msg = { |
| 4272 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4273 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4274 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4275 | }; |
| 4276 | int status; |
| 4277 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4278 | dprintk("%s: start\n", __func__); |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4279 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4280 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 4281 | fs_locations->nlocations = 0; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 4282 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4283 | nfs_fixup_referral_attributes(&fs_locations->fattr); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4284 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4285 | return status; |
| 4286 | } |
| 4287 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4288 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4289 | /* |
| 4290 | * nfs4_proc_exchange_id() |
| 4291 | * |
| 4292 | * Since the clientid has expired, all compounds using sessions |
| 4293 | * associated with the stale clientid will be returning |
| 4294 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 4295 | * be in some phase of session reset. |
| 4296 | */ |
| 4297 | static int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 4298 | { |
| 4299 | nfs4_verifier verifier; |
| 4300 | struct nfs41_exchange_id_args args = { |
| 4301 | .client = clp, |
| 4302 | .flags = clp->cl_exchange_flags, |
| 4303 | }; |
| 4304 | struct nfs41_exchange_id_res res = { |
| 4305 | .client = clp, |
| 4306 | }; |
| 4307 | int status; |
| 4308 | struct rpc_message msg = { |
| 4309 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 4310 | .rpc_argp = &args, |
| 4311 | .rpc_resp = &res, |
| 4312 | .rpc_cred = cred, |
| 4313 | }; |
| 4314 | __be32 *p; |
| 4315 | |
| 4316 | dprintk("--> %s\n", __func__); |
| 4317 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 4318 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4319 | p = (u32 *)verifier.data; |
| 4320 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 4321 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 4322 | args.verifier = &verifier; |
| 4323 | |
| 4324 | while (1) { |
| 4325 | args.id_len = scnprintf(args.id, sizeof(args.id), |
| 4326 | "%s/%s %u", |
| 4327 | clp->cl_ipaddr, |
| 4328 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4329 | RPC_DISPLAY_ADDR), |
| 4330 | clp->cl_id_uniquifier); |
| 4331 | |
| 4332 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 4333 | |
| 4334 | if (status != NFS4ERR_CLID_INUSE) |
| 4335 | break; |
| 4336 | |
| 4337 | if (signalled()) |
| 4338 | break; |
| 4339 | |
| 4340 | if (++clp->cl_id_uniquifier == 0) |
| 4341 | break; |
| 4342 | } |
| 4343 | |
| 4344 | dprintk("<-- %s status= %d\n", __func__, status); |
| 4345 | return status; |
| 4346 | } |
| 4347 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4348 | struct nfs4_get_lease_time_data { |
| 4349 | struct nfs4_get_lease_time_args *args; |
| 4350 | struct nfs4_get_lease_time_res *res; |
| 4351 | struct nfs_client *clp; |
| 4352 | }; |
| 4353 | |
| 4354 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 4355 | void *calldata) |
| 4356 | { |
| 4357 | int ret; |
| 4358 | struct nfs4_get_lease_time_data *data = |
| 4359 | (struct nfs4_get_lease_time_data *)calldata; |
| 4360 | |
| 4361 | dprintk("--> %s\n", __func__); |
| 4362 | /* just setup sequence, do not trigger session recovery |
| 4363 | since we're invoked within one */ |
| 4364 | ret = nfs41_setup_sequence(data->clp->cl_session, |
| 4365 | &data->args->la_seq_args, |
| 4366 | &data->res->lr_seq_res, 0, task); |
| 4367 | |
| 4368 | BUG_ON(ret == -EAGAIN); |
| 4369 | rpc_call_start(task); |
| 4370 | dprintk("<-- %s\n", __func__); |
| 4371 | } |
| 4372 | |
| 4373 | /* |
| 4374 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 4375 | * from sequence operation or clientid errors. |
| 4376 | */ |
| 4377 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 4378 | { |
| 4379 | struct nfs4_get_lease_time_data *data = |
| 4380 | (struct nfs4_get_lease_time_data *)calldata; |
| 4381 | |
| 4382 | dprintk("--> %s\n", __func__); |
| 4383 | nfs41_sequence_done(data->clp, &data->res->lr_seq_res, task->tk_status); |
| 4384 | switch (task->tk_status) { |
| 4385 | case -NFS4ERR_DELAY: |
| 4386 | case -NFS4ERR_GRACE: |
| 4387 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 4388 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 4389 | task->tk_status = 0; |
Andy Adamson | eedc020 | 2009-04-01 09:22:41 -0400 | [diff] [blame] | 4390 | nfs4_restart_rpc(task, data->clp); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4391 | return; |
| 4392 | } |
| 4393 | nfs41_sequence_free_slot(data->clp, &data->res->lr_seq_res); |
| 4394 | dprintk("<-- %s\n", __func__); |
| 4395 | } |
| 4396 | |
| 4397 | struct rpc_call_ops nfs4_get_lease_time_ops = { |
| 4398 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 4399 | .rpc_call_done = nfs4_get_lease_time_done, |
| 4400 | }; |
| 4401 | |
| 4402 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 4403 | { |
| 4404 | struct rpc_task *task; |
| 4405 | struct nfs4_get_lease_time_args args; |
| 4406 | struct nfs4_get_lease_time_res res = { |
| 4407 | .lr_fsinfo = fsinfo, |
| 4408 | }; |
| 4409 | struct nfs4_get_lease_time_data data = { |
| 4410 | .args = &args, |
| 4411 | .res = &res, |
| 4412 | .clp = clp, |
| 4413 | }; |
| 4414 | struct rpc_message msg = { |
| 4415 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 4416 | .rpc_argp = &args, |
| 4417 | .rpc_resp = &res, |
| 4418 | }; |
| 4419 | struct rpc_task_setup task_setup = { |
| 4420 | .rpc_client = clp->cl_rpcclient, |
| 4421 | .rpc_message = &msg, |
| 4422 | .callback_ops = &nfs4_get_lease_time_ops, |
| 4423 | .callback_data = &data |
| 4424 | }; |
| 4425 | int status; |
| 4426 | |
| 4427 | res.lr_seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
| 4428 | dprintk("--> %s\n", __func__); |
| 4429 | task = rpc_run_task(&task_setup); |
| 4430 | |
| 4431 | if (IS_ERR(task)) |
| 4432 | status = PTR_ERR(task); |
| 4433 | else { |
| 4434 | status = task->tk_status; |
| 4435 | rpc_put_task(task); |
| 4436 | } |
| 4437 | dprintk("<-- %s return %d\n", __func__, status); |
| 4438 | |
| 4439 | return status; |
| 4440 | } |
| 4441 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4442 | /* |
| 4443 | * Reset a slot table |
| 4444 | */ |
| 4445 | static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, int max_slots, |
| 4446 | int old_max_slots, int ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4447 | { |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4448 | int i; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4449 | int ret = 0; |
| 4450 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4451 | dprintk("--> %s: max_reqs=%u, tbl %p\n", __func__, max_slots, tbl); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4452 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4453 | /* |
| 4454 | * Until we have dynamic slot table adjustment, insist |
| 4455 | * upon the same slot table size |
| 4456 | */ |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4457 | if (max_slots != old_max_slots) { |
| 4458 | dprintk("%s reset slot table does't match old\n", |
| 4459 | __func__); |
| 4460 | ret = -EINVAL; /*XXX NFS4ERR_REQ_TOO_BIG ? */ |
| 4461 | goto out; |
| 4462 | } |
| 4463 | spin_lock(&tbl->slot_tbl_lock); |
| 4464 | for (i = 0; i < max_slots; ++i) |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4465 | tbl->slots[i].seq_nr = ivalue; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4466 | tbl->highest_used_slotid = -1; |
| 4467 | spin_unlock(&tbl->slot_tbl_lock); |
| 4468 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4469 | tbl, tbl->slots, tbl->max_slots); |
| 4470 | out: |
| 4471 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4472 | return ret; |
| 4473 | } |
| 4474 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4475 | /* |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4476 | * Reset the forechannel and backchannel slot tables |
| 4477 | */ |
| 4478 | static int nfs4_reset_slot_tables(struct nfs4_session *session) |
| 4479 | { |
| 4480 | int status; |
| 4481 | |
| 4482 | status = nfs4_reset_slot_table(&session->fc_slot_table, |
| 4483 | session->fc_attrs.max_reqs, |
| 4484 | session->fc_slot_table.max_slots, |
| 4485 | 1); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4486 | if (status) |
| 4487 | return status; |
| 4488 | |
| 4489 | status = nfs4_reset_slot_table(&session->bc_slot_table, |
| 4490 | session->bc_attrs.max_reqs, |
| 4491 | session->bc_slot_table.max_slots, |
| 4492 | 0); |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4493 | return status; |
| 4494 | } |
| 4495 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4496 | /* Destroy the slot table */ |
| 4497 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 4498 | { |
| 4499 | if (session->fc_slot_table.slots != NULL) { |
| 4500 | kfree(session->fc_slot_table.slots); |
| 4501 | session->fc_slot_table.slots = NULL; |
| 4502 | } |
| 4503 | if (session->bc_slot_table.slots != NULL) { |
| 4504 | kfree(session->bc_slot_table.slots); |
| 4505 | session->bc_slot_table.slots = NULL; |
| 4506 | } |
| 4507 | return; |
| 4508 | } |
| 4509 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4510 | /* |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4511 | * Initialize slot table |
| 4512 | */ |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4513 | static int nfs4_init_slot_table(struct nfs4_slot_table *tbl, |
| 4514 | int max_slots, int ivalue) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4515 | { |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4516 | int i; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4517 | struct nfs4_slot *slot; |
| 4518 | int ret = -ENOMEM; |
| 4519 | |
| 4520 | BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE); |
| 4521 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4522 | dprintk("--> %s: max_reqs=%u\n", __func__, max_slots); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4523 | |
| 4524 | slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_KERNEL); |
| 4525 | if (!slot) |
| 4526 | goto out; |
| 4527 | for (i = 0; i < max_slots; ++i) |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4528 | slot[i].seq_nr = ivalue; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4529 | ret = 0; |
| 4530 | |
| 4531 | spin_lock(&tbl->slot_tbl_lock); |
| 4532 | if (tbl->slots != NULL) { |
| 4533 | spin_unlock(&tbl->slot_tbl_lock); |
| 4534 | dprintk("%s: slot table already initialized. tbl=%p slots=%p\n", |
| 4535 | __func__, tbl, tbl->slots); |
| 4536 | WARN_ON(1); |
| 4537 | goto out_free; |
| 4538 | } |
| 4539 | tbl->max_slots = max_slots; |
| 4540 | tbl->slots = slot; |
| 4541 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 4542 | spin_unlock(&tbl->slot_tbl_lock); |
| 4543 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4544 | tbl, tbl->slots, tbl->max_slots); |
| 4545 | out: |
| 4546 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4547 | return ret; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4548 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4549 | out_free: |
| 4550 | kfree(slot); |
| 4551 | goto out; |
| 4552 | } |
| 4553 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4554 | /* |
| 4555 | * Initialize the forechannel and backchannel tables |
| 4556 | */ |
| 4557 | static int nfs4_init_slot_tables(struct nfs4_session *session) |
| 4558 | { |
| 4559 | int status; |
| 4560 | |
| 4561 | status = nfs4_init_slot_table(&session->fc_slot_table, |
| 4562 | session->fc_attrs.max_reqs, 1); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4563 | if (status) |
| 4564 | return status; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4565 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4566 | status = nfs4_init_slot_table(&session->bc_slot_table, |
| 4567 | session->bc_attrs.max_reqs, 0); |
| 4568 | if (status) |
| 4569 | nfs4_destroy_slot_tables(session); |
| 4570 | |
| 4571 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4572 | } |
| 4573 | |
| 4574 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 4575 | { |
| 4576 | struct nfs4_session *session; |
| 4577 | struct nfs4_slot_table *tbl; |
| 4578 | |
| 4579 | session = kzalloc(sizeof(struct nfs4_session), GFP_KERNEL); |
| 4580 | if (!session) |
| 4581 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 4582 | |
| 4583 | set_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state); |
| 4584 | /* |
| 4585 | * The create session reply races with the server back |
| 4586 | * channel probe. Mark the client NFS_CS_SESSION_INITING |
| 4587 | * so that the client back channel can find the |
| 4588 | * nfs_client struct |
| 4589 | */ |
| 4590 | clp->cl_cons_state = NFS_CS_SESSION_INITING; |
| 4591 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4592 | tbl = &session->fc_slot_table; |
| 4593 | spin_lock_init(&tbl->slot_tbl_lock); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4594 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
| 4595 | |
| 4596 | tbl = &session->bc_slot_table; |
| 4597 | spin_lock_init(&tbl->slot_tbl_lock); |
| 4598 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
| 4599 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4600 | session->clp = clp; |
| 4601 | return session; |
| 4602 | } |
| 4603 | |
| 4604 | void nfs4_destroy_session(struct nfs4_session *session) |
| 4605 | { |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 4606 | nfs4_proc_destroy_session(session); |
| 4607 | dprintk("%s Destroy backchannel for xprt %p\n", |
| 4608 | __func__, session->clp->cl_rpcclient->cl_xprt); |
| 4609 | xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt, |
| 4610 | NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4611 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4612 | kfree(session); |
| 4613 | } |
| 4614 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4615 | /* |
| 4616 | * Initialize the values to be used by the client in CREATE_SESSION |
| 4617 | * If nfs4_init_session set the fore channel request and response sizes, |
| 4618 | * use them. |
| 4619 | * |
| 4620 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 4621 | * always set csa_cachethis to FALSE because the current implementation |
| 4622 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 4623 | */ |
| 4624 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 4625 | { |
| 4626 | struct nfs4_session *session = args->client->cl_session; |
| 4627 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 4628 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 4629 | |
| 4630 | if (mxrqst_sz == 0) |
| 4631 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 4632 | if (mxresp_sz == 0) |
| 4633 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 4634 | /* Fore channel attributes */ |
| 4635 | args->fc_attrs.headerpadsz = 0; |
| 4636 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 4637 | args->fc_attrs.max_resp_sz = mxresp_sz; |
| 4638 | args->fc_attrs.max_resp_sz_cached = mxresp_sz; |
| 4639 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
| 4640 | args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs; |
| 4641 | |
| 4642 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 4643 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 4644 | __func__, |
| 4645 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
| 4646 | args->fc_attrs.max_resp_sz_cached, args->fc_attrs.max_ops, |
| 4647 | args->fc_attrs.max_reqs); |
| 4648 | |
| 4649 | /* Back channel attributes */ |
| 4650 | args->bc_attrs.headerpadsz = 0; |
| 4651 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 4652 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 4653 | args->bc_attrs.max_resp_sz_cached = 0; |
| 4654 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 4655 | args->bc_attrs.max_reqs = 1; |
| 4656 | |
| 4657 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 4658 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 4659 | __func__, |
| 4660 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 4661 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 4662 | args->bc_attrs.max_reqs); |
| 4663 | } |
| 4664 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4665 | static int _verify_channel_attr(char *chan, char *attr_name, u32 sent, u32 rcvd) |
| 4666 | { |
| 4667 | if (rcvd <= sent) |
| 4668 | return 0; |
| 4669 | printk(KERN_WARNING "%s: Session INVALID: %s channel %s increased. " |
| 4670 | "sent=%u rcvd=%u\n", __func__, chan, attr_name, sent, rcvd); |
| 4671 | return -EINVAL; |
| 4672 | } |
| 4673 | |
| 4674 | #define _verify_fore_channel_attr(_name_) \ |
| 4675 | _verify_channel_attr("fore", #_name_, \ |
| 4676 | args->fc_attrs._name_, \ |
| 4677 | session->fc_attrs._name_) |
| 4678 | |
| 4679 | #define _verify_back_channel_attr(_name_) \ |
| 4680 | _verify_channel_attr("back", #_name_, \ |
| 4681 | args->bc_attrs._name_, \ |
| 4682 | session->bc_attrs._name_) |
| 4683 | |
| 4684 | /* |
| 4685 | * The server is not allowed to increase the fore channel header pad size, |
| 4686 | * maximum response size, or maximum number of operations. |
| 4687 | * |
| 4688 | * The back channel attributes are only negotiatied down: We send what the |
| 4689 | * (back channel) server insists upon. |
| 4690 | */ |
| 4691 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 4692 | struct nfs4_session *session) |
| 4693 | { |
| 4694 | int ret = 0; |
| 4695 | |
| 4696 | ret |= _verify_fore_channel_attr(headerpadsz); |
| 4697 | ret |= _verify_fore_channel_attr(max_resp_sz); |
| 4698 | ret |= _verify_fore_channel_attr(max_ops); |
| 4699 | |
| 4700 | ret |= _verify_back_channel_attr(headerpadsz); |
| 4701 | ret |= _verify_back_channel_attr(max_rqst_sz); |
| 4702 | ret |= _verify_back_channel_attr(max_resp_sz); |
| 4703 | ret |= _verify_back_channel_attr(max_resp_sz_cached); |
| 4704 | ret |= _verify_back_channel_attr(max_ops); |
| 4705 | ret |= _verify_back_channel_attr(max_reqs); |
| 4706 | |
| 4707 | return ret; |
| 4708 | } |
| 4709 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4710 | static int _nfs4_proc_create_session(struct nfs_client *clp) |
| 4711 | { |
| 4712 | struct nfs4_session *session = clp->cl_session; |
| 4713 | struct nfs41_create_session_args args = { |
| 4714 | .client = clp, |
| 4715 | .cb_program = NFS4_CALLBACK, |
| 4716 | }; |
| 4717 | struct nfs41_create_session_res res = { |
| 4718 | .client = clp, |
| 4719 | }; |
| 4720 | struct rpc_message msg = { |
| 4721 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 4722 | .rpc_argp = &args, |
| 4723 | .rpc_resp = &res, |
| 4724 | }; |
| 4725 | int status; |
| 4726 | |
| 4727 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 4728 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4729 | |
| 4730 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); |
| 4731 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4732 | if (!status) |
| 4733 | /* Verify the session's negotiated channel_attrs values */ |
| 4734 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4735 | if (!status) { |
| 4736 | /* Increment the clientid slot sequence id */ |
| 4737 | clp->cl_seqid++; |
| 4738 | } |
| 4739 | |
| 4740 | return status; |
| 4741 | } |
| 4742 | |
| 4743 | /* |
| 4744 | * Issues a CREATE_SESSION operation to the server. |
| 4745 | * It is the responsibility of the caller to verify the session is |
| 4746 | * expired before calling this routine. |
| 4747 | */ |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4748 | int nfs4_proc_create_session(struct nfs_client *clp, int reset) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4749 | { |
| 4750 | int status; |
| 4751 | unsigned *ptr; |
| 4752 | struct nfs_fsinfo fsinfo; |
| 4753 | struct nfs4_session *session = clp->cl_session; |
| 4754 | |
| 4755 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 4756 | |
| 4757 | status = _nfs4_proc_create_session(clp); |
| 4758 | if (status) |
| 4759 | goto out; |
| 4760 | |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4761 | /* Init or reset the fore channel */ |
| 4762 | if (reset) |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4763 | status = nfs4_reset_slot_tables(session); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4764 | else |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4765 | status = nfs4_init_slot_tables(session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4766 | dprintk("fore channel slot table initialization returned %d\n", status); |
| 4767 | if (status) |
| 4768 | goto out; |
| 4769 | |
| 4770 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 4771 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 4772 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
| 4773 | |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4774 | if (reset) |
| 4775 | /* Lease time is aleady set */ |
| 4776 | goto out; |
| 4777 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4778 | /* Get the lease time */ |
| 4779 | status = nfs4_proc_get_lease_time(clp, &fsinfo); |
| 4780 | if (status == 0) { |
| 4781 | /* Update lease time and schedule renewal */ |
| 4782 | spin_lock(&clp->cl_lock); |
| 4783 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 4784 | clp->cl_last_renewal = jiffies; |
| 4785 | clear_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state); |
| 4786 | spin_unlock(&clp->cl_lock); |
| 4787 | |
| 4788 | nfs4_schedule_state_renewal(clp); |
| 4789 | } |
| 4790 | out: |
| 4791 | dprintk("<-- %s\n", __func__); |
| 4792 | return status; |
| 4793 | } |
| 4794 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 4795 | /* |
| 4796 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 4797 | * The caller must serialize access to this routine. |
| 4798 | */ |
| 4799 | int nfs4_proc_destroy_session(struct nfs4_session *session) |
| 4800 | { |
| 4801 | int status = 0; |
| 4802 | struct rpc_message msg; |
| 4803 | |
| 4804 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 4805 | |
| 4806 | /* session is still being setup */ |
| 4807 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 4808 | return status; |
| 4809 | |
| 4810 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; |
| 4811 | msg.rpc_argp = session; |
| 4812 | msg.rpc_resp = NULL; |
| 4813 | msg.rpc_cred = NULL; |
| 4814 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); |
| 4815 | |
| 4816 | if (status) |
| 4817 | printk(KERN_WARNING |
| 4818 | "Got error %d from the server on DESTROY_SESSION. " |
| 4819 | "Session has been destroyed regardless...\n", status); |
| 4820 | |
| 4821 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 4822 | return status; |
| 4823 | } |
| 4824 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 4825 | int nfs4_init_session(struct nfs_server *server) |
| 4826 | { |
| 4827 | struct nfs_client *clp = server->nfs_client; |
| 4828 | int ret; |
| 4829 | |
| 4830 | if (!nfs4_has_session(clp)) |
| 4831 | return 0; |
| 4832 | |
| 4833 | clp->cl_session->fc_attrs.max_rqst_sz = server->wsize; |
| 4834 | clp->cl_session->fc_attrs.max_resp_sz = server->rsize; |
| 4835 | ret = nfs4_recover_expired_lease(server); |
| 4836 | if (!ret) |
| 4837 | ret = nfs4_check_client_ready(clp); |
| 4838 | return ret; |
| 4839 | } |
| 4840 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 4841 | /* |
| 4842 | * Renew the cl_session lease. |
| 4843 | */ |
| 4844 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 4845 | { |
| 4846 | struct nfs4_sequence_args args; |
| 4847 | struct nfs4_sequence_res res; |
| 4848 | |
| 4849 | struct rpc_message msg = { |
| 4850 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 4851 | .rpc_argp = &args, |
| 4852 | .rpc_resp = &res, |
| 4853 | .rpc_cred = cred, |
| 4854 | }; |
| 4855 | |
| 4856 | args.sa_cache_this = 0; |
| 4857 | |
| 4858 | return nfs4_call_sync_sequence(clp, clp->cl_rpcclient, &msg, &args, |
| 4859 | &res, 0); |
| 4860 | } |
| 4861 | |
| 4862 | void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
| 4863 | { |
| 4864 | struct nfs_client *clp = (struct nfs_client *)data; |
| 4865 | |
| 4866 | nfs41_sequence_done(clp, task->tk_msg.rpc_resp, task->tk_status); |
| 4867 | |
| 4868 | if (task->tk_status < 0) { |
| 4869 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
| 4870 | |
| 4871 | if (_nfs4_async_handle_error(task, NULL, clp, NULL) |
| 4872 | == -EAGAIN) { |
Andy Adamson | eedc020 | 2009-04-01 09:22:41 -0400 | [diff] [blame] | 4873 | nfs4_restart_rpc(task, clp); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 4874 | return; |
| 4875 | } |
| 4876 | } |
| 4877 | nfs41_sequence_free_slot(clp, task->tk_msg.rpc_resp); |
| 4878 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
| 4879 | |
| 4880 | put_rpccred(task->tk_msg.rpc_cred); |
| 4881 | kfree(task->tk_msg.rpc_argp); |
| 4882 | kfree(task->tk_msg.rpc_resp); |
| 4883 | |
| 4884 | dprintk("<-- %s\n", __func__); |
| 4885 | } |
| 4886 | |
| 4887 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 4888 | { |
| 4889 | struct nfs_client *clp; |
| 4890 | struct nfs4_sequence_args *args; |
| 4891 | struct nfs4_sequence_res *res; |
| 4892 | |
| 4893 | clp = (struct nfs_client *)data; |
| 4894 | args = task->tk_msg.rpc_argp; |
| 4895 | res = task->tk_msg.rpc_resp; |
| 4896 | |
| 4897 | if (nfs4_setup_sequence(clp, args, res, 0, task)) |
| 4898 | return; |
| 4899 | rpc_call_start(task); |
| 4900 | } |
| 4901 | |
| 4902 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 4903 | .rpc_call_done = nfs41_sequence_call_done, |
| 4904 | .rpc_call_prepare = nfs41_sequence_prepare, |
| 4905 | }; |
| 4906 | |
| 4907 | static int nfs41_proc_async_sequence(struct nfs_client *clp, |
| 4908 | struct rpc_cred *cred) |
| 4909 | { |
| 4910 | struct nfs4_sequence_args *args; |
| 4911 | struct nfs4_sequence_res *res; |
| 4912 | struct rpc_message msg = { |
| 4913 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 4914 | .rpc_cred = cred, |
| 4915 | }; |
| 4916 | |
| 4917 | args = kzalloc(sizeof(*args), GFP_KERNEL); |
| 4918 | if (!args) |
| 4919 | return -ENOMEM; |
| 4920 | res = kzalloc(sizeof(*res), GFP_KERNEL); |
| 4921 | if (!res) { |
| 4922 | kfree(args); |
| 4923 | return -ENOMEM; |
| 4924 | } |
| 4925 | res->sr_slotid = NFS4_MAX_SLOT_TABLE; |
| 4926 | msg.rpc_argp = args; |
| 4927 | msg.rpc_resp = res; |
| 4928 | |
| 4929 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
| 4930 | &nfs41_sequence_ops, (void *)clp); |
| 4931 | } |
| 4932 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4933 | #endif /* CONFIG_NFS_V4_1 */ |
| 4934 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 4935 | struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 4936 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 4937 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4938 | .recover_open = nfs4_open_reclaim, |
| 4939 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 4940 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 4941 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4942 | }; |
| 4943 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 4944 | #if defined(CONFIG_NFS_V4_1) |
| 4945 | struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
| 4946 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 4947 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 4948 | .recover_open = nfs4_open_reclaim, |
| 4949 | .recover_lock = nfs4_lock_reclaim, |
| 4950 | .establish_clid = nfs4_proc_exchange_id, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 4951 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 4952 | }; |
| 4953 | #endif /* CONFIG_NFS_V4_1 */ |
| 4954 | |
| 4955 | struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 4956 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 4957 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4958 | .recover_open = nfs4_open_expired, |
| 4959 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 4960 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 4961 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4962 | }; |
| 4963 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 4964 | #if defined(CONFIG_NFS_V4_1) |
| 4965 | struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
| 4966 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 4967 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
| 4968 | .recover_open = nfs4_open_expired, |
| 4969 | .recover_lock = nfs4_lock_expired, |
| 4970 | .establish_clid = nfs4_proc_exchange_id, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 4971 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 4972 | }; |
| 4973 | #endif /* CONFIG_NFS_V4_1 */ |
| 4974 | |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 4975 | struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
| 4976 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 4977 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 4978 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 4979 | }; |
| 4980 | |
| 4981 | #if defined(CONFIG_NFS_V4_1) |
| 4982 | struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
| 4983 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 4984 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 4985 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 4986 | }; |
| 4987 | #endif |
| 4988 | |
| 4989 | /* |
| 4990 | * Per minor version reboot and network partition recovery ops |
| 4991 | */ |
| 4992 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 4993 | struct nfs4_state_recovery_ops *nfs4_reboot_recovery_ops[] = { |
| 4994 | &nfs40_reboot_recovery_ops, |
| 4995 | #if defined(CONFIG_NFS_V4_1) |
| 4996 | &nfs41_reboot_recovery_ops, |
| 4997 | #endif |
| 4998 | }; |
| 4999 | |
| 5000 | struct nfs4_state_recovery_ops *nfs4_nograce_recovery_ops[] = { |
| 5001 | &nfs40_nograce_recovery_ops, |
| 5002 | #if defined(CONFIG_NFS_V4_1) |
| 5003 | &nfs41_nograce_recovery_ops, |
| 5004 | #endif |
| 5005 | }; |
| 5006 | |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5007 | struct nfs4_state_maintenance_ops *nfs4_state_renewal_ops[] = { |
| 5008 | &nfs40_state_renewal_ops, |
| 5009 | #if defined(CONFIG_NFS_V4_1) |
| 5010 | &nfs41_state_renewal_ops, |
| 5011 | #endif |
| 5012 | }; |
| 5013 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 5014 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5015 | .permission = nfs_permission, |
| 5016 | .getattr = nfs_getattr, |
| 5017 | .setattr = nfs_setattr, |
| 5018 | .getxattr = nfs4_getxattr, |
| 5019 | .setxattr = nfs4_setxattr, |
| 5020 | .listxattr = nfs4_listxattr, |
| 5021 | }; |
| 5022 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 5023 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5024 | .version = 4, /* protocol version */ |
| 5025 | .dentry_ops = &nfs4_dentry_operations, |
| 5026 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5027 | .file_inode_ops = &nfs4_file_inode_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5028 | .getroot = nfs4_proc_get_root, |
| 5029 | .getattr = nfs4_proc_getattr, |
| 5030 | .setattr = nfs4_proc_setattr, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5031 | .lookupfh = nfs4_proc_lookupfh, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5032 | .lookup = nfs4_proc_lookup, |
| 5033 | .access = nfs4_proc_access, |
| 5034 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5035 | .create = nfs4_proc_create, |
| 5036 | .remove = nfs4_proc_remove, |
| 5037 | .unlink_setup = nfs4_proc_unlink_setup, |
| 5038 | .unlink_done = nfs4_proc_unlink_done, |
| 5039 | .rename = nfs4_proc_rename, |
| 5040 | .link = nfs4_proc_link, |
| 5041 | .symlink = nfs4_proc_symlink, |
| 5042 | .mkdir = nfs4_proc_mkdir, |
| 5043 | .rmdir = nfs4_proc_remove, |
| 5044 | .readdir = nfs4_proc_readdir, |
| 5045 | .mknod = nfs4_proc_mknod, |
| 5046 | .statfs = nfs4_proc_statfs, |
| 5047 | .fsinfo = nfs4_proc_fsinfo, |
| 5048 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 5049 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5050 | .decode_dirent = nfs4_decode_dirent, |
| 5051 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5052 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5053 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5054 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5055 | .commit_setup = nfs4_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5056 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5057 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5058 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 5059 | .close_context = nfs4_close_context, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5060 | }; |
| 5061 | |
| 5062 | /* |
| 5063 | * Local variables: |
| 5064 | * c-basic-offset: 8 |
| 5065 | * End: |
| 5066 | */ |