Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (c) 2001 The Regents of the University of Michigan. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Kendrick Smith <kmsmith@umich.edu> |
| 6 | * Andy Adamson <kandros@umich.edu> |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * |
| 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer in the |
| 16 | * documentation and/or other materials provided with the distribution. |
| 17 | * 3. Neither the name of the University nor the names of its |
| 18 | * contributors may be used to endorse or promote products derived |
| 19 | * from this software without specific prior written permission. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 23 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 24 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 28 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 29 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | * |
| 33 | */ |
| 34 | |
Dave Hansen | aceaf78 | 2008-02-15 14:37:31 -0800 | [diff] [blame] | 35 | #include <linux/file.h> |
Arnd Bergmann | b89f432 | 2010-09-18 15:09:31 +0200 | [diff] [blame] | 36 | #include <linux/fs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 37 | #include <linux/slab.h> |
NeilBrown | 0964a3d | 2005-06-23 22:04:32 -0700 | [diff] [blame] | 38 | #include <linux/namei.h> |
Meelap Shah | c2f1a55 | 2007-07-17 04:04:39 -0700 | [diff] [blame] | 39 | #include <linux/swap.h> |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 40 | #include <linux/pagemap.h> |
Olga Kornievskaia | 68e76ad | 2008-12-23 16:17:15 -0500 | [diff] [blame] | 41 | #include <linux/sunrpc/svcauth_gss.h> |
Jeff Layton | 363168b | 2009-08-14 12:57:56 -0400 | [diff] [blame] | 42 | #include <linux/sunrpc/clnt.h> |
Boaz Harrosh | 9a74af2 | 2009-12-03 20:30:56 +0200 | [diff] [blame] | 43 | #include "xdr4.h" |
J. Bruce Fields | 0a3adad | 2009-11-04 18:12:35 -0500 | [diff] [blame] | 44 | #include "vfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | #define NFSDDBG_FACILITY NFSDDBG_PROC |
| 47 | |
| 48 | /* Globals */ |
J. Bruce Fields | cf07d2e | 2010-02-28 23:20:19 -0500 | [diff] [blame] | 49 | time_t nfsd4_lease = 90; /* default lease time */ |
J. Bruce Fields | efc4bb4f | 2010-03-02 11:04:06 -0500 | [diff] [blame] | 50 | time_t nfsd4_grace = 90; |
NeilBrown | fd39ca9 | 2005-06-23 22:04:03 -0700 | [diff] [blame] | 51 | static time_t boot_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | static u32 current_ownerid = 1; |
| 53 | static u32 current_fileid = 1; |
| 54 | static u32 current_delegid = 1; |
NeilBrown | fd39ca9 | 2005-06-23 22:04:03 -0700 | [diff] [blame] | 55 | static stateid_t zerostateid; /* bits all 0 */ |
| 56 | static stateid_t onestateid; /* bits all 1 */ |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 57 | static u64 current_sessionid = 1; |
NeilBrown | fd39ca9 | 2005-06-23 22:04:03 -0700 | [diff] [blame] | 58 | |
| 59 | #define ZERO_STATEID(stateid) (!memcmp((stateid), &zerostateid, sizeof(stateid_t))) |
| 60 | #define ONE_STATEID(stateid) (!memcmp((stateid), &onestateid, sizeof(stateid_t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | /* forward declarations */ |
NeilBrown | fd39ca9 | 2005-06-23 22:04:03 -0700 | [diff] [blame] | 63 | static struct nfs4_stateid * find_stateid(stateid_t *stid, int flags); |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 64 | static struct nfs4_stateid * search_for_stateid(stateid_t *stid); |
| 65 | static struct nfs4_delegation * search_for_delegation(stateid_t *stid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | static struct nfs4_delegation * find_delegation_stateid(struct inode *ino, stateid_t *stid); |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 67 | static int check_for_locks(struct nfs4_file *filp, struct nfs4_stateowner *lowner); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
J. Bruce Fields | 8b671b8 | 2009-02-22 14:51:34 -0800 | [diff] [blame] | 69 | /* Locking: */ |
| 70 | |
| 71 | /* Currently used for almost all code touching nfsv4 state: */ |
Ingo Molnar | 353ab6e | 2006-03-26 01:37:12 -0800 | [diff] [blame] | 72 | static DEFINE_MUTEX(client_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
J. Bruce Fields | 8b671b8 | 2009-02-22 14:51:34 -0800 | [diff] [blame] | 74 | /* |
| 75 | * Currently used for the del_recall_lru and file hash table. In an |
| 76 | * effort to decrease the scope of the client_mutex, this spinlock may |
| 77 | * eventually cover more: |
| 78 | */ |
| 79 | static DEFINE_SPINLOCK(recall_lock); |
| 80 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 81 | static struct kmem_cache *stateowner_slab = NULL; |
| 82 | static struct kmem_cache *file_slab = NULL; |
| 83 | static struct kmem_cache *stateid_slab = NULL; |
| 84 | static struct kmem_cache *deleg_slab = NULL; |
NeilBrown | e60d439 | 2005-06-23 22:03:01 -0700 | [diff] [blame] | 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | void |
| 87 | nfs4_lock_state(void) |
| 88 | { |
Ingo Molnar | 353ab6e | 2006-03-26 01:37:12 -0800 | [diff] [blame] | 89 | mutex_lock(&client_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | void |
| 93 | nfs4_unlock_state(void) |
| 94 | { |
Ingo Molnar | 353ab6e | 2006-03-26 01:37:12 -0800 | [diff] [blame] | 95 | mutex_unlock(&client_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | static inline u32 |
| 99 | opaque_hashval(const void *ptr, int nbytes) |
| 100 | { |
| 101 | unsigned char *cptr = (unsigned char *) ptr; |
| 102 | |
| 103 | u32 x = 0; |
| 104 | while (nbytes--) { |
| 105 | x *= 37; |
| 106 | x += *cptr++; |
| 107 | } |
| 108 | return x; |
| 109 | } |
| 110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | static struct list_head del_recall_lru; |
| 112 | |
NeilBrown | 13cd218 | 2005-06-23 22:03:10 -0700 | [diff] [blame] | 113 | static inline void |
| 114 | put_nfs4_file(struct nfs4_file *fi) |
| 115 | { |
J. Bruce Fields | 8b671b8 | 2009-02-22 14:51:34 -0800 | [diff] [blame] | 116 | if (atomic_dec_and_lock(&fi->fi_ref, &recall_lock)) { |
| 117 | list_del(&fi->fi_hash); |
| 118 | spin_unlock(&recall_lock); |
| 119 | iput(fi->fi_inode); |
| 120 | kmem_cache_free(file_slab, fi); |
| 121 | } |
NeilBrown | 13cd218 | 2005-06-23 22:03:10 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | static inline void |
| 125 | get_nfs4_file(struct nfs4_file *fi) |
| 126 | { |
J. Bruce Fields | 8b671b8 | 2009-02-22 14:51:34 -0800 | [diff] [blame] | 127 | atomic_inc(&fi->fi_ref); |
NeilBrown | 13cd218 | 2005-06-23 22:03:10 -0700 | [diff] [blame] | 128 | } |
| 129 | |
NeilBrown | ef0f339 | 2006-04-10 22:55:41 -0700 | [diff] [blame] | 130 | static int num_delegations; |
Meelap Shah | c2f1a55 | 2007-07-17 04:04:39 -0700 | [diff] [blame] | 131 | unsigned int max_delegations; |
NeilBrown | ef0f339 | 2006-04-10 22:55:41 -0700 | [diff] [blame] | 132 | |
| 133 | /* |
| 134 | * Open owner state (share locks) |
| 135 | */ |
| 136 | |
| 137 | /* hash tables for nfs4_stateowner */ |
| 138 | #define OWNER_HASH_BITS 8 |
| 139 | #define OWNER_HASH_SIZE (1 << OWNER_HASH_BITS) |
| 140 | #define OWNER_HASH_MASK (OWNER_HASH_SIZE - 1) |
| 141 | |
| 142 | #define ownerid_hashval(id) \ |
| 143 | ((id) & OWNER_HASH_MASK) |
| 144 | #define ownerstr_hashval(clientid, ownername) \ |
| 145 | (((clientid) + opaque_hashval((ownername.data), (ownername.len))) & OWNER_HASH_MASK) |
| 146 | |
| 147 | static struct list_head ownerid_hashtbl[OWNER_HASH_SIZE]; |
| 148 | static struct list_head ownerstr_hashtbl[OWNER_HASH_SIZE]; |
| 149 | |
| 150 | /* hash table for nfs4_file */ |
| 151 | #define FILE_HASH_BITS 8 |
| 152 | #define FILE_HASH_SIZE (1 << FILE_HASH_BITS) |
Shan Wei | 3507958 | 2011-01-14 17:35:59 +0800 | [diff] [blame] | 153 | |
NeilBrown | ef0f339 | 2006-04-10 22:55:41 -0700 | [diff] [blame] | 154 | /* hash table for (open)nfs4_stateid */ |
| 155 | #define STATEID_HASH_BITS 10 |
| 156 | #define STATEID_HASH_SIZE (1 << STATEID_HASH_BITS) |
| 157 | #define STATEID_HASH_MASK (STATEID_HASH_SIZE - 1) |
| 158 | |
| 159 | #define file_hashval(x) \ |
| 160 | hash_ptr(x, FILE_HASH_BITS) |
| 161 | #define stateid_hashval(owner_id, file_id) \ |
| 162 | (((owner_id) + (file_id)) & STATEID_HASH_MASK) |
| 163 | |
| 164 | static struct list_head file_hashtbl[FILE_HASH_SIZE]; |
| 165 | static struct list_head stateid_hashtbl[STATEID_HASH_SIZE]; |
| 166 | |
J. Bruce Fields | 998db52 | 2010-08-07 09:21:41 -0400 | [diff] [blame] | 167 | static void __nfs4_file_get_access(struct nfs4_file *fp, int oflag) |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 168 | { |
| 169 | BUG_ON(!(fp->fi_fds[oflag] || fp->fi_fds[O_RDWR])); |
| 170 | atomic_inc(&fp->fi_access[oflag]); |
| 171 | } |
| 172 | |
J. Bruce Fields | 998db52 | 2010-08-07 09:21:41 -0400 | [diff] [blame] | 173 | static void nfs4_file_get_access(struct nfs4_file *fp, int oflag) |
| 174 | { |
| 175 | if (oflag == O_RDWR) { |
| 176 | __nfs4_file_get_access(fp, O_RDONLY); |
| 177 | __nfs4_file_get_access(fp, O_WRONLY); |
| 178 | } else |
| 179 | __nfs4_file_get_access(fp, oflag); |
| 180 | } |
| 181 | |
| 182 | static void nfs4_file_put_fd(struct nfs4_file *fp, int oflag) |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 183 | { |
| 184 | if (fp->fi_fds[oflag]) { |
| 185 | fput(fp->fi_fds[oflag]); |
| 186 | fp->fi_fds[oflag] = NULL; |
| 187 | } |
| 188 | } |
| 189 | |
J. Bruce Fields | 998db52 | 2010-08-07 09:21:41 -0400 | [diff] [blame] | 190 | static void __nfs4_file_put_access(struct nfs4_file *fp, int oflag) |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 191 | { |
| 192 | if (atomic_dec_and_test(&fp->fi_access[oflag])) { |
| 193 | nfs4_file_put_fd(fp, O_RDWR); |
| 194 | nfs4_file_put_fd(fp, oflag); |
| 195 | } |
| 196 | } |
| 197 | |
J. Bruce Fields | 998db52 | 2010-08-07 09:21:41 -0400 | [diff] [blame] | 198 | static void nfs4_file_put_access(struct nfs4_file *fp, int oflag) |
| 199 | { |
| 200 | if (oflag == O_RDWR) { |
| 201 | __nfs4_file_put_access(fp, O_RDONLY); |
| 202 | __nfs4_file_put_access(fp, O_WRONLY); |
| 203 | } else |
| 204 | __nfs4_file_put_access(fp, oflag); |
| 205 | } |
| 206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | static struct nfs4_delegation * |
| 208 | alloc_init_deleg(struct nfs4_client *clp, struct nfs4_stateid *stp, struct svc_fh *current_fh, u32 type) |
| 209 | { |
| 210 | struct nfs4_delegation *dp; |
| 211 | struct nfs4_file *fp = stp->st_file; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
| 213 | dprintk("NFSD alloc_init_deleg\n"); |
J. Bruce Fields | c3e4808 | 2010-07-28 10:08:57 -0400 | [diff] [blame] | 214 | /* |
| 215 | * Major work on the lease subsystem (for example, to support |
| 216 | * calbacks on stat) will be required before we can support |
| 217 | * write delegations properly. |
| 218 | */ |
| 219 | if (type != NFS4_OPEN_DELEGATE_READ) |
| 220 | return NULL; |
Meelap Shah | 47f9940 | 2007-07-17 04:04:40 -0700 | [diff] [blame] | 221 | if (fp->fi_had_conflict) |
| 222 | return NULL; |
Meelap Shah | c2f1a55 | 2007-07-17 04:04:39 -0700 | [diff] [blame] | 223 | if (num_delegations > max_delegations) |
NeilBrown | ef0f339 | 2006-04-10 22:55:41 -0700 | [diff] [blame] | 224 | return NULL; |
NeilBrown | 5b2d21c | 2005-06-23 22:03:04 -0700 | [diff] [blame] | 225 | dp = kmem_cache_alloc(deleg_slab, GFP_KERNEL); |
| 226 | if (dp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | return dp; |
NeilBrown | ef0f339 | 2006-04-10 22:55:41 -0700 | [diff] [blame] | 228 | num_delegations++; |
NeilBrown | ea1da63 | 2005-06-23 22:04:17 -0700 | [diff] [blame] | 229 | INIT_LIST_HEAD(&dp->dl_perfile); |
| 230 | INIT_LIST_HEAD(&dp->dl_perclnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | INIT_LIST_HEAD(&dp->dl_recall_lru); |
| 232 | dp->dl_client = clp; |
NeilBrown | 13cd218 | 2005-06-23 22:03:10 -0700 | [diff] [blame] | 233 | get_nfs4_file(fp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | dp->dl_file = fp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | dp->dl_type = type; |
J. Bruce Fields | e4e83ea | 2010-04-22 16:21:39 -0400 | [diff] [blame] | 236 | dp->dl_stateid.si_boot = boot_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | dp->dl_stateid.si_stateownerid = current_delegid++; |
| 238 | dp->dl_stateid.si_fileid = 0; |
| 239 | dp->dl_stateid.si_generation = 0; |
J. Bruce Fields | 6c02eaa | 2009-02-02 17:30:51 -0500 | [diff] [blame] | 240 | fh_copy_shallow(&dp->dl_fh, ¤t_fh->fh_handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | dp->dl_time = 0; |
| 242 | atomic_set(&dp->dl_count, 1); |
J. Bruce Fields | b5a1a81 | 2010-03-03 14:52:55 -0500 | [diff] [blame] | 243 | INIT_WORK(&dp->dl_recall.cb_work, nfsd4_do_callback_rpc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | return dp; |
| 245 | } |
| 246 | |
| 247 | void |
| 248 | nfs4_put_delegation(struct nfs4_delegation *dp) |
| 249 | { |
| 250 | if (atomic_dec_and_test(&dp->dl_count)) { |
| 251 | dprintk("NFSD: freeing dp %p\n",dp); |
NeilBrown | 13cd218 | 2005-06-23 22:03:10 -0700 | [diff] [blame] | 252 | put_nfs4_file(dp->dl_file); |
NeilBrown | 5b2d21c | 2005-06-23 22:03:04 -0700 | [diff] [blame] | 253 | kmem_cache_free(deleg_slab, dp); |
NeilBrown | ef0f339 | 2006-04-10 22:55:41 -0700 | [diff] [blame] | 254 | num_delegations--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | |
J. Bruce Fields | acfdf5c | 2011-01-31 19:20:39 -0500 | [diff] [blame] | 258 | static void nfs4_put_deleg_lease(struct nfs4_file *fp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | { |
J. Bruce Fields | acfdf5c | 2011-01-31 19:20:39 -0500 | [diff] [blame] | 260 | if (atomic_dec_and_test(&fp->fi_delegees)) { |
| 261 | vfs_setlease(fp->fi_deleg_file, F_UNLCK, &fp->fi_lease); |
| 262 | fp->fi_lease = NULL; |
J. Bruce Fields | 4ee6362 | 2011-04-15 18:08:26 -0400 | [diff] [blame] | 263 | fput(fp->fi_deleg_file); |
J. Bruce Fields | acfdf5c | 2011-01-31 19:20:39 -0500 | [diff] [blame] | 264 | fp->fi_deleg_file = NULL; |
| 265 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | /* Called under the state lock. */ |
| 269 | static void |
| 270 | unhash_delegation(struct nfs4_delegation *dp) |
| 271 | { |
NeilBrown | ea1da63 | 2005-06-23 22:04:17 -0700 | [diff] [blame] | 272 | list_del_init(&dp->dl_perclnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | spin_lock(&recall_lock); |
J. Bruce Fields | 5d926e8 | 2011-02-07 16:53:46 -0500 | [diff] [blame] | 274 | list_del_init(&dp->dl_perfile); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | list_del_init(&dp->dl_recall_lru); |
| 276 | spin_unlock(&recall_lock); |
J. Bruce Fields | acfdf5c | 2011-01-31 19:20:39 -0500 | [diff] [blame] | 277 | nfs4_put_deleg_lease(dp->dl_file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | nfs4_put_delegation(dp); |
| 279 | } |
| 280 | |
| 281 | /* |
| 282 | * SETCLIENTID state |
| 283 | */ |
| 284 | |
Benny Halevy | 36acb66 | 2010-05-12 00:13:04 +0300 | [diff] [blame] | 285 | /* client_lock protects the client lru list and session hash table */ |
Benny Halevy | 9089f1b | 2010-05-12 00:12:26 +0300 | [diff] [blame] | 286 | static DEFINE_SPINLOCK(client_lock); |
| 287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | /* Hash tables for nfs4_clientid state */ |
| 289 | #define CLIENT_HASH_BITS 4 |
| 290 | #define CLIENT_HASH_SIZE (1 << CLIENT_HASH_BITS) |
| 291 | #define CLIENT_HASH_MASK (CLIENT_HASH_SIZE - 1) |
| 292 | |
| 293 | #define clientid_hashval(id) \ |
| 294 | ((id) & CLIENT_HASH_MASK) |
NeilBrown | a55370a | 2005-06-23 22:03:52 -0700 | [diff] [blame] | 295 | #define clientstr_hashval(name) \ |
| 296 | (opaque_hashval((name), 8) & CLIENT_HASH_MASK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | /* |
| 298 | * reclaim_str_hashtbl[] holds known client info from previous reset/reboot |
| 299 | * used in reboot/reset lease grace period processing |
| 300 | * |
| 301 | * conf_id_hashtbl[], and conf_str_hashtbl[] hold confirmed |
| 302 | * setclientid_confirmed info. |
| 303 | * |
| 304 | * unconf_str_hastbl[] and unconf_id_hashtbl[] hold unconfirmed |
| 305 | * setclientid info. |
| 306 | * |
| 307 | * client_lru holds client queue ordered by nfs4_client.cl_time |
| 308 | * for lease renewal. |
| 309 | * |
| 310 | * close_lru holds (open) stateowner queue ordered by nfs4_stateowner.so_time |
| 311 | * for last close replay. |
| 312 | */ |
| 313 | static struct list_head reclaim_str_hashtbl[CLIENT_HASH_SIZE]; |
| 314 | static int reclaim_str_hashtbl_size = 0; |
| 315 | static struct list_head conf_id_hashtbl[CLIENT_HASH_SIZE]; |
| 316 | static struct list_head conf_str_hashtbl[CLIENT_HASH_SIZE]; |
| 317 | static struct list_head unconf_str_hashtbl[CLIENT_HASH_SIZE]; |
| 318 | static struct list_head unconf_id_hashtbl[CLIENT_HASH_SIZE]; |
| 319 | static struct list_head client_lru; |
| 320 | static struct list_head close_lru; |
| 321 | |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 322 | /* |
| 323 | * We store the NONE, READ, WRITE, and BOTH bits separately in the |
| 324 | * st_{access,deny}_bmap field of the stateid, in order to track not |
| 325 | * only what share bits are currently in force, but also what |
| 326 | * combinations of share bits previous opens have used. This allows us |
| 327 | * to enforce the recommendation of rfc 3530 14.2.19 that the server |
| 328 | * return an error if the client attempt to downgrade to a combination |
| 329 | * of share bits not explicable by closing some of its previous opens. |
| 330 | * |
| 331 | * XXX: This enforcement is actually incomplete, since we don't keep |
| 332 | * track of access/deny bit combinations; so, e.g., we allow: |
| 333 | * |
| 334 | * OPEN allow read, deny write |
| 335 | * OPEN allow both, deny none |
| 336 | * DOWNGRADE allow read, deny none |
| 337 | * |
| 338 | * which we should reject. |
| 339 | */ |
| 340 | static void |
| 341 | set_access(unsigned int *access, unsigned long bmap) { |
| 342 | int i; |
| 343 | |
| 344 | *access = 0; |
| 345 | for (i = 1; i < 4; i++) { |
| 346 | if (test_bit(i, &bmap)) |
| 347 | *access |= i; |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | static void |
| 352 | set_deny(unsigned int *deny, unsigned long bmap) { |
| 353 | int i; |
| 354 | |
| 355 | *deny = 0; |
| 356 | for (i = 0; i < 4; i++) { |
| 357 | if (test_bit(i, &bmap)) |
| 358 | *deny |= i ; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | static int |
| 363 | test_share(struct nfs4_stateid *stp, struct nfsd4_open *open) { |
| 364 | unsigned int access, deny; |
| 365 | |
| 366 | set_access(&access, stp->st_access_bmap); |
| 367 | set_deny(&deny, stp->st_deny_bmap); |
| 368 | if ((access & open->op_share_deny) || (deny & open->op_share_access)) |
| 369 | return 0; |
| 370 | return 1; |
| 371 | } |
| 372 | |
| 373 | static int nfs4_access_to_omode(u32 access) |
| 374 | { |
J. Bruce Fields | 8f34a43 | 2010-09-02 15:23:16 -0400 | [diff] [blame] | 375 | switch (access & NFS4_SHARE_ACCESS_BOTH) { |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 376 | case NFS4_SHARE_ACCESS_READ: |
| 377 | return O_RDONLY; |
| 378 | case NFS4_SHARE_ACCESS_WRITE: |
| 379 | return O_WRONLY; |
| 380 | case NFS4_SHARE_ACCESS_BOTH: |
| 381 | return O_RDWR; |
| 382 | } |
| 383 | BUG(); |
| 384 | } |
| 385 | |
J. Bruce Fields | 529d7b2 | 2011-03-02 23:48:33 -0500 | [diff] [blame] | 386 | static void unhash_generic_stateid(struct nfs4_stateid *stp) |
| 387 | { |
| 388 | list_del(&stp->st_hash); |
| 389 | list_del(&stp->st_perfile); |
| 390 | list_del(&stp->st_perstateowner); |
| 391 | } |
| 392 | |
| 393 | static void free_generic_stateid(struct nfs4_stateid *stp) |
| 394 | { |
J. Bruce Fields | 499f3ed | 2011-06-27 16:57:12 -0400 | [diff] [blame] | 395 | int i; |
J. Bruce Fields | 0997b17 | 2011-03-02 18:01:35 -0500 | [diff] [blame] | 396 | |
J. Bruce Fields | 23fcf2e | 2011-03-28 15:15:09 +0800 | [diff] [blame] | 397 | if (stp->st_access_bmap) { |
J. Bruce Fields | 499f3ed | 2011-06-27 16:57:12 -0400 | [diff] [blame] | 398 | for (i = 1; i < 4; i++) { |
| 399 | if (test_bit(i, &stp->st_access_bmap)) |
| 400 | nfs4_file_put_access(stp->st_file, |
| 401 | nfs4_access_to_omode(i)); |
| 402 | } |
J. Bruce Fields | 23fcf2e | 2011-03-28 15:15:09 +0800 | [diff] [blame] | 403 | } |
OGAWA Hirofumi | a96e5b9 | 2011-04-18 11:48:55 -0400 | [diff] [blame] | 404 | put_nfs4_file(stp->st_file); |
J. Bruce Fields | 529d7b2 | 2011-03-02 23:48:33 -0500 | [diff] [blame] | 405 | kmem_cache_free(stateid_slab, stp); |
| 406 | } |
| 407 | |
| 408 | static void release_lock_stateid(struct nfs4_stateid *stp) |
| 409 | { |
| 410 | struct file *file; |
| 411 | |
| 412 | unhash_generic_stateid(stp); |
| 413 | file = find_any_file(stp->st_file); |
| 414 | if (file) |
| 415 | locks_remove_posix(file, (fl_owner_t)stp->st_stateowner); |
| 416 | free_generic_stateid(stp); |
| 417 | } |
| 418 | |
| 419 | static void unhash_lockowner(struct nfs4_stateowner *sop) |
| 420 | { |
| 421 | struct nfs4_stateid *stp; |
| 422 | |
| 423 | list_del(&sop->so_idhash); |
| 424 | list_del(&sop->so_strhash); |
| 425 | list_del(&sop->so_perstateid); |
| 426 | while (!list_empty(&sop->so_stateids)) { |
| 427 | stp = list_first_entry(&sop->so_stateids, |
| 428 | struct nfs4_stateid, st_perstateowner); |
| 429 | release_lock_stateid(stp); |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | static void release_lockowner(struct nfs4_stateowner *sop) |
| 434 | { |
| 435 | unhash_lockowner(sop); |
| 436 | nfs4_put_stateowner(sop); |
| 437 | } |
| 438 | |
| 439 | static void |
| 440 | release_stateid_lockowners(struct nfs4_stateid *open_stp) |
| 441 | { |
| 442 | struct nfs4_stateowner *lock_sop; |
| 443 | |
| 444 | while (!list_empty(&open_stp->st_lockowners)) { |
| 445 | lock_sop = list_entry(open_stp->st_lockowners.next, |
| 446 | struct nfs4_stateowner, so_perstateid); |
| 447 | /* list_del(&open_stp->st_lockowners); */ |
| 448 | BUG_ON(lock_sop->so_is_open_owner); |
| 449 | release_lockowner(lock_sop); |
| 450 | } |
| 451 | } |
| 452 | |
J. Bruce Fields | 2283963 | 2009-01-11 14:27:17 -0500 | [diff] [blame] | 453 | static void release_open_stateid(struct nfs4_stateid *stp) |
| 454 | { |
| 455 | unhash_generic_stateid(stp); |
| 456 | release_stateid_lockowners(stp); |
J. Bruce Fields | 2283963 | 2009-01-11 14:27:17 -0500 | [diff] [blame] | 457 | free_generic_stateid(stp); |
| 458 | } |
| 459 | |
J. Bruce Fields | f044ff8 | 2009-01-11 15:24:04 -0500 | [diff] [blame] | 460 | static void unhash_openowner(struct nfs4_stateowner *sop) |
J. Bruce Fields | f1d110c | 2009-01-11 14:37:31 -0500 | [diff] [blame] | 461 | { |
| 462 | struct nfs4_stateid *stp; |
| 463 | |
| 464 | list_del(&sop->so_idhash); |
| 465 | list_del(&sop->so_strhash); |
J. Bruce Fields | f044ff8 | 2009-01-11 15:24:04 -0500 | [diff] [blame] | 466 | list_del(&sop->so_perclient); |
| 467 | list_del(&sop->so_perstateid); /* XXX: necessary? */ |
J. Bruce Fields | f1d110c | 2009-01-11 14:37:31 -0500 | [diff] [blame] | 468 | while (!list_empty(&sop->so_stateids)) { |
J. Bruce Fields | f044ff8 | 2009-01-11 15:24:04 -0500 | [diff] [blame] | 469 | stp = list_first_entry(&sop->so_stateids, |
| 470 | struct nfs4_stateid, st_perstateowner); |
| 471 | release_open_stateid(stp); |
J. Bruce Fields | f1d110c | 2009-01-11 14:37:31 -0500 | [diff] [blame] | 472 | } |
| 473 | } |
| 474 | |
J. Bruce Fields | f044ff8 | 2009-01-11 15:24:04 -0500 | [diff] [blame] | 475 | static void release_openowner(struct nfs4_stateowner *sop) |
J. Bruce Fields | f1d110c | 2009-01-11 14:37:31 -0500 | [diff] [blame] | 476 | { |
J. Bruce Fields | f044ff8 | 2009-01-11 15:24:04 -0500 | [diff] [blame] | 477 | unhash_openowner(sop); |
J. Bruce Fields | f1d110c | 2009-01-11 14:37:31 -0500 | [diff] [blame] | 478 | list_del(&sop->so_close_lru); |
| 479 | nfs4_put_stateowner(sop); |
| 480 | } |
| 481 | |
Marc Eshel | 5282fd7 | 2009-04-03 08:27:52 +0300 | [diff] [blame] | 482 | #define SESSION_HASH_SIZE 512 |
| 483 | static struct list_head sessionid_hashtbl[SESSION_HASH_SIZE]; |
| 484 | |
| 485 | static inline int |
| 486 | hash_sessionid(struct nfs4_sessionid *sessionid) |
| 487 | { |
| 488 | struct nfsd4_sessionid *sid = (struct nfsd4_sessionid *)sessionid; |
| 489 | |
| 490 | return sid->sequence % SESSION_HASH_SIZE; |
| 491 | } |
| 492 | |
| 493 | static inline void |
| 494 | dump_sessionid(const char *fn, struct nfs4_sessionid *sessionid) |
| 495 | { |
| 496 | u32 *ptr = (u32 *)(&sessionid->data[0]); |
| 497 | dprintk("%s: %u:%u:%u:%u\n", fn, ptr[0], ptr[1], ptr[2], ptr[3]); |
| 498 | } |
| 499 | |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 500 | static void |
| 501 | gen_sessionid(struct nfsd4_session *ses) |
| 502 | { |
| 503 | struct nfs4_client *clp = ses->se_client; |
| 504 | struct nfsd4_sessionid *sid; |
| 505 | |
| 506 | sid = (struct nfsd4_sessionid *)ses->se_sessionid.data; |
| 507 | sid->clientid = clp->cl_clientid; |
| 508 | sid->sequence = current_sessionid++; |
| 509 | sid->reserved = 0; |
| 510 | } |
| 511 | |
| 512 | /* |
Andy Adamson | a649637c7 | 2009-08-28 08:45:01 -0400 | [diff] [blame] | 513 | * The protocol defines ca_maxresponssize_cached to include the size of |
| 514 | * the rpc header, but all we need to cache is the data starting after |
| 515 | * the end of the initial SEQUENCE operation--the rest we regenerate |
| 516 | * each time. Therefore we can advertise a ca_maxresponssize_cached |
| 517 | * value that is the number of bytes in our cache plus a few additional |
| 518 | * bytes. In order to stay on the safe side, and not promise more than |
| 519 | * we can cache, those additional bytes must be the minimum possible: 24 |
| 520 | * bytes of rpc header (xid through accept state, with AUTH_NULL |
| 521 | * verifier), 12 for the compound header (with zero-length tag), and 44 |
| 522 | * for the SEQUENCE op response: |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 523 | */ |
Andy Adamson | a649637c7 | 2009-08-28 08:45:01 -0400 | [diff] [blame] | 524 | #define NFSD_MIN_HDR_SEQ_SZ (24 + 12 + 44) |
| 525 | |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 526 | static void |
| 527 | free_session_slots(struct nfsd4_session *ses) |
| 528 | { |
| 529 | int i; |
| 530 | |
| 531 | for (i = 0; i < ses->se_fchannel.maxreqs; i++) |
| 532 | kfree(ses->se_slots[i]); |
| 533 | } |
| 534 | |
J. Bruce Fields | efe0cb6 | 2009-10-24 20:52:16 -0400 | [diff] [blame] | 535 | /* |
| 536 | * We don't actually need to cache the rpc and session headers, so we |
| 537 | * can allocate a little less for each slot: |
| 538 | */ |
| 539 | static inline int slot_bytes(struct nfsd4_channel_attrs *ca) |
| 540 | { |
| 541 | return ca->maxresp_cached - NFSD_MIN_HDR_SEQ_SZ; |
| 542 | } |
| 543 | |
J. Bruce Fields | 5b6feee | 2010-09-27 17:12:05 -0400 | [diff] [blame] | 544 | static int nfsd4_sanitize_slot_size(u32 size) |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 545 | { |
J. Bruce Fields | 5b6feee | 2010-09-27 17:12:05 -0400 | [diff] [blame] | 546 | size -= NFSD_MIN_HDR_SEQ_SZ; /* We don't cache the rpc header */ |
| 547 | size = min_t(u32, size, NFSD_SLOT_CACHE_SIZE); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 548 | |
J. Bruce Fields | 5b6feee | 2010-09-27 17:12:05 -0400 | [diff] [blame] | 549 | return size; |
| 550 | } |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 551 | |
J. Bruce Fields | 5b6feee | 2010-09-27 17:12:05 -0400 | [diff] [blame] | 552 | /* |
| 553 | * XXX: If we run out of reserved DRC memory we could (up to a point) |
| 554 | * re-negotiate active sessions and reduce their slot usage to make |
| 555 | * rooom for new connections. For now we just fail the create session. |
| 556 | */ |
| 557 | static int nfsd4_get_drc_mem(int slotsize, u32 num) |
| 558 | { |
| 559 | int avail; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 560 | |
J. Bruce Fields | 5b6feee | 2010-09-27 17:12:05 -0400 | [diff] [blame] | 561 | num = min_t(u32, num, NFSD_MAX_SLOTS_PER_SESSION); |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 562 | |
J. Bruce Fields | 5b6feee | 2010-09-27 17:12:05 -0400 | [diff] [blame] | 563 | spin_lock(&nfsd_drc_lock); |
| 564 | avail = min_t(int, NFSD_MAX_MEM_PER_SESSION, |
| 565 | nfsd_drc_max_mem - nfsd_drc_mem_used); |
| 566 | num = min_t(int, num, avail / slotsize); |
| 567 | nfsd_drc_mem_used += num * slotsize; |
| 568 | spin_unlock(&nfsd_drc_lock); |
| 569 | |
| 570 | return num; |
| 571 | } |
| 572 | |
| 573 | static void nfsd4_put_drc_mem(int slotsize, int num) |
| 574 | { |
| 575 | spin_lock(&nfsd_drc_lock); |
| 576 | nfsd_drc_mem_used -= slotsize * num; |
| 577 | spin_unlock(&nfsd_drc_lock); |
| 578 | } |
| 579 | |
| 580 | static struct nfsd4_session *alloc_session(int slotsize, int numslots) |
| 581 | { |
| 582 | struct nfsd4_session *new; |
| 583 | int mem, i; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 584 | |
J. Bruce Fields | c23753d | 2010-09-27 16:22:30 -0400 | [diff] [blame] | 585 | BUILD_BUG_ON(NFSD_MAX_SLOTS_PER_SESSION * sizeof(struct nfsd4_slot *) |
J. Bruce Fields | 5b6feee | 2010-09-27 17:12:05 -0400 | [diff] [blame] | 586 | + sizeof(struct nfsd4_session) > PAGE_SIZE); |
| 587 | mem = numslots * sizeof(struct nfsd4_slot *); |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 588 | |
J. Bruce Fields | 5b6feee | 2010-09-27 17:12:05 -0400 | [diff] [blame] | 589 | new = kzalloc(sizeof(*new) + mem, GFP_KERNEL); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 590 | if (!new) |
J. Bruce Fields | 5b6feee | 2010-09-27 17:12:05 -0400 | [diff] [blame] | 591 | return NULL; |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 592 | /* allocate each struct nfsd4_slot and data cache in one piece */ |
J. Bruce Fields | 5b6feee | 2010-09-27 17:12:05 -0400 | [diff] [blame] | 593 | for (i = 0; i < numslots; i++) { |
| 594 | mem = sizeof(struct nfsd4_slot) + slotsize; |
| 595 | new->se_slots[i] = kzalloc(mem, GFP_KERNEL); |
| 596 | if (!new->se_slots[i]) |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 597 | goto out_free; |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 598 | } |
J. Bruce Fields | 5b6feee | 2010-09-27 17:12:05 -0400 | [diff] [blame] | 599 | return new; |
| 600 | out_free: |
| 601 | while (i--) |
| 602 | kfree(new->se_slots[i]); |
| 603 | kfree(new); |
| 604 | return NULL; |
| 605 | } |
| 606 | |
| 607 | static void init_forechannel_attrs(struct nfsd4_channel_attrs *new, struct nfsd4_channel_attrs *req, int numslots, int slotsize) |
| 608 | { |
| 609 | u32 maxrpc = nfsd_serv->sv_max_mesg; |
| 610 | |
| 611 | new->maxreqs = numslots; |
Mi Jinlong | d2b2174 | 2011-03-10 17:43:37 +0800 | [diff] [blame] | 612 | new->maxresp_cached = min_t(u32, req->maxresp_cached, |
| 613 | slotsize + NFSD_MIN_HDR_SEQ_SZ); |
J. Bruce Fields | 5b6feee | 2010-09-27 17:12:05 -0400 | [diff] [blame] | 614 | new->maxreq_sz = min_t(u32, req->maxreq_sz, maxrpc); |
| 615 | new->maxresp_sz = min_t(u32, req->maxresp_sz, maxrpc); |
| 616 | new->maxops = min_t(u32, req->maxops, NFSD_MAX_OPS_PER_COMPOUND); |
| 617 | } |
| 618 | |
J. Bruce Fields | 19cf5c0 | 2010-06-06 18:37:16 -0400 | [diff] [blame] | 619 | static void free_conn(struct nfsd4_conn *c) |
| 620 | { |
| 621 | svc_xprt_put(c->cn_xprt); |
| 622 | kfree(c); |
| 623 | } |
| 624 | |
| 625 | static void nfsd4_conn_lost(struct svc_xpt_user *u) |
| 626 | { |
| 627 | struct nfsd4_conn *c = container_of(u, struct nfsd4_conn, cn_xpt_user); |
| 628 | struct nfs4_client *clp = c->cn_session->se_client; |
| 629 | |
| 630 | spin_lock(&clp->cl_lock); |
| 631 | if (!list_empty(&c->cn_persession)) { |
| 632 | list_del(&c->cn_persession); |
| 633 | free_conn(c); |
| 634 | } |
| 635 | spin_unlock(&clp->cl_lock); |
J. Bruce Fields | eea4980 | 2010-11-18 08:34:12 -0500 | [diff] [blame] | 636 | nfsd4_probe_callback(clp); |
J. Bruce Fields | 19cf5c0 | 2010-06-06 18:37:16 -0400 | [diff] [blame] | 637 | } |
| 638 | |
J. Bruce Fields | d29c374 | 2010-06-15 17:34:11 -0400 | [diff] [blame] | 639 | static struct nfsd4_conn *alloc_conn(struct svc_rqst *rqstp, u32 flags) |
J. Bruce Fields | c766251 | 2010-06-06 18:12:14 -0400 | [diff] [blame] | 640 | { |
J. Bruce Fields | c766251 | 2010-06-06 18:12:14 -0400 | [diff] [blame] | 641 | struct nfsd4_conn *conn; |
| 642 | |
| 643 | conn = kmalloc(sizeof(struct nfsd4_conn), GFP_KERNEL); |
| 644 | if (!conn) |
J. Bruce Fields | db90681 | 2010-09-29 15:29:32 -0400 | [diff] [blame] | 645 | return NULL; |
J. Bruce Fields | c766251 | 2010-06-06 18:12:14 -0400 | [diff] [blame] | 646 | svc_xprt_get(rqstp->rq_xprt); |
| 647 | conn->cn_xprt = rqstp->rq_xprt; |
J. Bruce Fields | d29c374 | 2010-06-15 17:34:11 -0400 | [diff] [blame] | 648 | conn->cn_flags = flags; |
J. Bruce Fields | db90681 | 2010-09-29 15:29:32 -0400 | [diff] [blame] | 649 | INIT_LIST_HEAD(&conn->cn_xpt_user.list); |
| 650 | return conn; |
| 651 | } |
| 652 | |
J. Bruce Fields | 328ead2 | 2010-09-29 16:11:06 -0400 | [diff] [blame] | 653 | static void __nfsd4_hash_conn(struct nfsd4_conn *conn, struct nfsd4_session *ses) |
| 654 | { |
| 655 | conn->cn_session = ses; |
| 656 | list_add(&conn->cn_persession, &ses->se_conns); |
| 657 | } |
| 658 | |
J. Bruce Fields | db90681 | 2010-09-29 15:29:32 -0400 | [diff] [blame] | 659 | static void nfsd4_hash_conn(struct nfsd4_conn *conn, struct nfsd4_session *ses) |
| 660 | { |
| 661 | struct nfs4_client *clp = ses->se_client; |
J. Bruce Fields | c766251 | 2010-06-06 18:12:14 -0400 | [diff] [blame] | 662 | |
| 663 | spin_lock(&clp->cl_lock); |
J. Bruce Fields | 328ead2 | 2010-09-29 16:11:06 -0400 | [diff] [blame] | 664 | __nfsd4_hash_conn(conn, ses); |
J. Bruce Fields | c766251 | 2010-06-06 18:12:14 -0400 | [diff] [blame] | 665 | spin_unlock(&clp->cl_lock); |
J. Bruce Fields | db90681 | 2010-09-29 15:29:32 -0400 | [diff] [blame] | 666 | } |
J. Bruce Fields | c766251 | 2010-06-06 18:12:14 -0400 | [diff] [blame] | 667 | |
J. Bruce Fields | 21b75b0 | 2010-10-26 10:07:17 -0400 | [diff] [blame] | 668 | static int nfsd4_register_conn(struct nfsd4_conn *conn) |
J. Bruce Fields | db90681 | 2010-09-29 15:29:32 -0400 | [diff] [blame] | 669 | { |
J. Bruce Fields | 19cf5c0 | 2010-06-06 18:37:16 -0400 | [diff] [blame] | 670 | conn->cn_xpt_user.callback = nfsd4_conn_lost; |
J. Bruce Fields | 21b75b0 | 2010-10-26 10:07:17 -0400 | [diff] [blame] | 671 | return register_xpt_user(conn->cn_xprt, &conn->cn_xpt_user); |
J. Bruce Fields | db90681 | 2010-09-29 15:29:32 -0400 | [diff] [blame] | 672 | } |
| 673 | |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 674 | static __be32 nfsd4_new_conn(struct svc_rqst *rqstp, struct nfsd4_session *ses, u32 dir) |
J. Bruce Fields | db90681 | 2010-09-29 15:29:32 -0400 | [diff] [blame] | 675 | { |
| 676 | struct nfsd4_conn *conn; |
J. Bruce Fields | 21b75b0 | 2010-10-26 10:07:17 -0400 | [diff] [blame] | 677 | int ret; |
J. Bruce Fields | db90681 | 2010-09-29 15:29:32 -0400 | [diff] [blame] | 678 | |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 679 | conn = alloc_conn(rqstp, dir); |
J. Bruce Fields | db90681 | 2010-09-29 15:29:32 -0400 | [diff] [blame] | 680 | if (!conn) |
| 681 | return nfserr_jukebox; |
| 682 | nfsd4_hash_conn(conn, ses); |
J. Bruce Fields | 21b75b0 | 2010-10-26 10:07:17 -0400 | [diff] [blame] | 683 | ret = nfsd4_register_conn(conn); |
| 684 | if (ret) |
| 685 | /* oops; xprt is already down: */ |
| 686 | nfsd4_conn_lost(&conn->cn_xpt_user); |
J. Bruce Fields | c766251 | 2010-06-06 18:12:14 -0400 | [diff] [blame] | 687 | return nfs_ok; |
| 688 | } |
| 689 | |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 690 | static __be32 nfsd4_new_conn_from_crses(struct svc_rqst *rqstp, struct nfsd4_session *ses) |
| 691 | { |
| 692 | u32 dir = NFS4_CDFC4_FORE; |
| 693 | |
| 694 | if (ses->se_flags & SESSION4_BACK_CHAN) |
| 695 | dir |= NFS4_CDFC4_BACK; |
| 696 | |
| 697 | return nfsd4_new_conn(rqstp, ses, dir); |
| 698 | } |
| 699 | |
| 700 | /* must be called under client_lock */ |
J. Bruce Fields | 19cf5c0 | 2010-06-06 18:37:16 -0400 | [diff] [blame] | 701 | static void nfsd4_del_conns(struct nfsd4_session *s) |
J. Bruce Fields | c766251 | 2010-06-06 18:12:14 -0400 | [diff] [blame] | 702 | { |
J. Bruce Fields | 19cf5c0 | 2010-06-06 18:37:16 -0400 | [diff] [blame] | 703 | struct nfs4_client *clp = s->se_client; |
| 704 | struct nfsd4_conn *c; |
| 705 | |
| 706 | spin_lock(&clp->cl_lock); |
| 707 | while (!list_empty(&s->se_conns)) { |
| 708 | c = list_first_entry(&s->se_conns, struct nfsd4_conn, cn_persession); |
| 709 | list_del_init(&c->cn_persession); |
| 710 | spin_unlock(&clp->cl_lock); |
| 711 | |
| 712 | unregister_xpt_user(c->cn_xprt, &c->cn_xpt_user); |
| 713 | free_conn(c); |
| 714 | |
| 715 | spin_lock(&clp->cl_lock); |
| 716 | } |
| 717 | spin_unlock(&clp->cl_lock); |
J. Bruce Fields | c766251 | 2010-06-06 18:12:14 -0400 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | void free_session(struct kref *kref) |
| 721 | { |
| 722 | struct nfsd4_session *ses; |
| 723 | int mem; |
| 724 | |
| 725 | ses = container_of(kref, struct nfsd4_session, se_ref); |
J. Bruce Fields | 19cf5c0 | 2010-06-06 18:37:16 -0400 | [diff] [blame] | 726 | nfsd4_del_conns(ses); |
J. Bruce Fields | c766251 | 2010-06-06 18:12:14 -0400 | [diff] [blame] | 727 | spin_lock(&nfsd_drc_lock); |
| 728 | mem = ses->se_fchannel.maxreqs * slot_bytes(&ses->se_fchannel); |
| 729 | nfsd_drc_mem_used -= mem; |
| 730 | spin_unlock(&nfsd_drc_lock); |
| 731 | free_session_slots(ses); |
| 732 | kfree(ses); |
| 733 | } |
| 734 | |
J. Bruce Fields | ac7c46f | 2010-06-14 19:01:57 -0400 | [diff] [blame] | 735 | static struct nfsd4_session *alloc_init_session(struct svc_rqst *rqstp, struct nfs4_client *clp, struct nfsd4_create_session *cses) |
J. Bruce Fields | 5b6feee | 2010-09-27 17:12:05 -0400 | [diff] [blame] | 736 | { |
| 737 | struct nfsd4_session *new; |
| 738 | struct nfsd4_channel_attrs *fchan = &cses->fore_channel; |
| 739 | int numslots, slotsize; |
J. Bruce Fields | c766251 | 2010-06-06 18:12:14 -0400 | [diff] [blame] | 740 | int status; |
J. Bruce Fields | 5b6feee | 2010-09-27 17:12:05 -0400 | [diff] [blame] | 741 | int idx; |
| 742 | |
| 743 | /* |
| 744 | * Note decreasing slot size below client's request may |
| 745 | * make it difficult for client to function correctly, whereas |
| 746 | * decreasing the number of slots will (just?) affect |
| 747 | * performance. When short on memory we therefore prefer to |
| 748 | * decrease number of slots instead of their size. |
| 749 | */ |
| 750 | slotsize = nfsd4_sanitize_slot_size(fchan->maxresp_cached); |
| 751 | numslots = nfsd4_get_drc_mem(slotsize, fchan->maxreqs); |
Mi Jinlong | ced6dfe | 2010-11-11 18:03:50 +0800 | [diff] [blame] | 752 | if (numslots < 1) |
| 753 | return NULL; |
J. Bruce Fields | 5b6feee | 2010-09-27 17:12:05 -0400 | [diff] [blame] | 754 | |
| 755 | new = alloc_session(slotsize, numslots); |
| 756 | if (!new) { |
| 757 | nfsd4_put_drc_mem(slotsize, fchan->maxreqs); |
J. Bruce Fields | ac7c46f | 2010-06-14 19:01:57 -0400 | [diff] [blame] | 758 | return NULL; |
J. Bruce Fields | 5b6feee | 2010-09-27 17:12:05 -0400 | [diff] [blame] | 759 | } |
| 760 | init_forechannel_attrs(&new->se_fchannel, fchan, numslots, slotsize); |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 761 | |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 762 | new->se_client = clp; |
| 763 | gen_sessionid(new); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 764 | |
J. Bruce Fields | c766251 | 2010-06-06 18:12:14 -0400 | [diff] [blame] | 765 | INIT_LIST_HEAD(&new->se_conns); |
| 766 | |
J. Bruce Fields | ac7c46f | 2010-06-14 19:01:57 -0400 | [diff] [blame] | 767 | new->se_cb_seq_nr = 1; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 768 | new->se_flags = cses->flags; |
J. Bruce Fields | 8b5ce5c | 2010-10-19 17:31:50 -0400 | [diff] [blame] | 769 | new->se_cb_prog = cses->callback_prog; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 770 | kref_init(&new->se_ref); |
J. Bruce Fields | 5b6feee | 2010-09-27 17:12:05 -0400 | [diff] [blame] | 771 | idx = hash_sessionid(&new->se_sessionid); |
Benny Halevy | 9089f1b | 2010-05-12 00:12:26 +0300 | [diff] [blame] | 772 | spin_lock(&client_lock); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 773 | list_add(&new->se_hash, &sessionid_hashtbl[idx]); |
J. Bruce Fields | 4c64937 | 2010-06-15 14:22:37 -0400 | [diff] [blame] | 774 | spin_lock(&clp->cl_lock); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 775 | list_add(&new->se_perclnt, &clp->cl_sessions); |
J. Bruce Fields | 4c64937 | 2010-06-15 14:22:37 -0400 | [diff] [blame] | 776 | spin_unlock(&clp->cl_lock); |
Benny Halevy | 9089f1b | 2010-05-12 00:12:26 +0300 | [diff] [blame] | 777 | spin_unlock(&client_lock); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 778 | |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 779 | status = nfsd4_new_conn_from_crses(rqstp, new); |
J. Bruce Fields | ac7c46f | 2010-06-14 19:01:57 -0400 | [diff] [blame] | 780 | /* whoops: benny points out, status is ignored! (err, or bogus) */ |
J. Bruce Fields | c766251 | 2010-06-06 18:12:14 -0400 | [diff] [blame] | 781 | if (status) { |
| 782 | free_session(&new->se_ref); |
J. Bruce Fields | ac7c46f | 2010-06-14 19:01:57 -0400 | [diff] [blame] | 783 | return NULL; |
J. Bruce Fields | c766251 | 2010-06-06 18:12:14 -0400 | [diff] [blame] | 784 | } |
J. Bruce Fields | dcbeaa6 | 2010-06-15 17:25:45 -0400 | [diff] [blame] | 785 | if (cses->flags & SESSION4_BACK_CHAN) { |
J. Bruce Fields | edd7678 | 2010-06-14 22:26:31 -0400 | [diff] [blame] | 786 | struct sockaddr *sa = svc_addr(rqstp); |
J. Bruce Fields | dcbeaa6 | 2010-06-15 17:25:45 -0400 | [diff] [blame] | 787 | /* |
| 788 | * This is a little silly; with sessions there's no real |
| 789 | * use for the callback address. Use the peer address |
| 790 | * as a reasonable default for now, but consider fixing |
| 791 | * the rpc client not to require an address in the |
| 792 | * future: |
| 793 | */ |
J. Bruce Fields | edd7678 | 2010-06-14 22:26:31 -0400 | [diff] [blame] | 794 | rpc_copy_addr((struct sockaddr *)&clp->cl_cb_conn.cb_addr, sa); |
| 795 | clp->cl_cb_conn.cb_addrlen = svc_addr_len(sa); |
J. Bruce Fields | edd7678 | 2010-06-14 22:26:31 -0400 | [diff] [blame] | 796 | } |
J. Bruce Fields | dcbeaa6 | 2010-06-15 17:25:45 -0400 | [diff] [blame] | 797 | nfsd4_probe_callback(clp); |
J. Bruce Fields | ac7c46f | 2010-06-14 19:01:57 -0400 | [diff] [blame] | 798 | return new; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 799 | } |
| 800 | |
Benny Halevy | 9089f1b | 2010-05-12 00:12:26 +0300 | [diff] [blame] | 801 | /* caller must hold client_lock */ |
Marc Eshel | 5282fd7 | 2009-04-03 08:27:52 +0300 | [diff] [blame] | 802 | static struct nfsd4_session * |
| 803 | find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid) |
| 804 | { |
| 805 | struct nfsd4_session *elem; |
| 806 | int idx; |
| 807 | |
| 808 | dump_sessionid(__func__, sessionid); |
| 809 | idx = hash_sessionid(sessionid); |
Marc Eshel | 5282fd7 | 2009-04-03 08:27:52 +0300 | [diff] [blame] | 810 | /* Search in the appropriate list */ |
| 811 | list_for_each_entry(elem, &sessionid_hashtbl[idx], se_hash) { |
Marc Eshel | 5282fd7 | 2009-04-03 08:27:52 +0300 | [diff] [blame] | 812 | if (!memcmp(elem->se_sessionid.data, sessionid->data, |
| 813 | NFS4_MAX_SESSIONID_LEN)) { |
| 814 | return elem; |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | dprintk("%s: session not found\n", __func__); |
| 819 | return NULL; |
| 820 | } |
| 821 | |
Benny Halevy | 9089f1b | 2010-05-12 00:12:26 +0300 | [diff] [blame] | 822 | /* caller must hold client_lock */ |
Andy Adamson | 7116ed6 | 2009-04-03 08:27:43 +0300 | [diff] [blame] | 823 | static void |
Marc Eshel | 5282fd7 | 2009-04-03 08:27:52 +0300 | [diff] [blame] | 824 | unhash_session(struct nfsd4_session *ses) |
Andy Adamson | 7116ed6 | 2009-04-03 08:27:43 +0300 | [diff] [blame] | 825 | { |
| 826 | list_del(&ses->se_hash); |
J. Bruce Fields | 4c64937 | 2010-06-15 14:22:37 -0400 | [diff] [blame] | 827 | spin_lock(&ses->se_client->cl_lock); |
Andy Adamson | 7116ed6 | 2009-04-03 08:27:43 +0300 | [diff] [blame] | 828 | list_del(&ses->se_perclnt); |
J. Bruce Fields | 4c64937 | 2010-06-15 14:22:37 -0400 | [diff] [blame] | 829 | spin_unlock(&ses->se_client->cl_lock); |
Marc Eshel | 5282fd7 | 2009-04-03 08:27:52 +0300 | [diff] [blame] | 830 | } |
| 831 | |
Benny Halevy | 36acb66 | 2010-05-12 00:13:04 +0300 | [diff] [blame] | 832 | /* must be called under the client_lock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | static inline void |
Benny Halevy | 36acb66 | 2010-05-12 00:13:04 +0300 | [diff] [blame] | 834 | renew_client_locked(struct nfs4_client *clp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | { |
Benny Halevy | 07cd490 | 2010-05-12 00:13:41 +0300 | [diff] [blame] | 836 | if (is_client_expired(clp)) { |
| 837 | dprintk("%s: client (clientid %08x/%08x) already expired\n", |
| 838 | __func__, |
| 839 | clp->cl_clientid.cl_boot, |
| 840 | clp->cl_clientid.cl_id); |
| 841 | return; |
| 842 | } |
| 843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | /* |
| 845 | * Move client to the end to the LRU list. |
| 846 | */ |
| 847 | dprintk("renewing client (clientid %08x/%08x)\n", |
| 848 | clp->cl_clientid.cl_boot, |
| 849 | clp->cl_clientid.cl_id); |
| 850 | list_move_tail(&clp->cl_lru, &client_lru); |
| 851 | clp->cl_time = get_seconds(); |
| 852 | } |
| 853 | |
Benny Halevy | 36acb66 | 2010-05-12 00:13:04 +0300 | [diff] [blame] | 854 | static inline void |
| 855 | renew_client(struct nfs4_client *clp) |
| 856 | { |
| 857 | spin_lock(&client_lock); |
| 858 | renew_client_locked(clp); |
| 859 | spin_unlock(&client_lock); |
| 860 | } |
| 861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | /* SETCLIENTID and SETCLIENTID_CONFIRM Helper functions */ |
| 863 | static int |
| 864 | STALE_CLIENTID(clientid_t *clid) |
| 865 | { |
| 866 | if (clid->cl_boot == boot_time) |
| 867 | return 0; |
Andy Adamson | 60adfc5 | 2009-04-03 08:28:50 +0300 | [diff] [blame] | 868 | dprintk("NFSD stale clientid (%08x/%08x) boot_time %08lx\n", |
| 869 | clid->cl_boot, clid->cl_id, boot_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | return 1; |
| 871 | } |
| 872 | |
| 873 | /* |
| 874 | * XXX Should we use a slab cache ? |
| 875 | * This type of memory management is somewhat inefficient, but we use it |
| 876 | * anyway since SETCLIENTID is not a common operation. |
| 877 | */ |
J. Bruce Fields | 35bba9a | 2007-11-21 22:07:08 -0500 | [diff] [blame] | 878 | static struct nfs4_client *alloc_client(struct xdr_netobj name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | { |
| 880 | struct nfs4_client *clp; |
| 881 | |
J. Bruce Fields | 35bba9a | 2007-11-21 22:07:08 -0500 | [diff] [blame] | 882 | clp = kzalloc(sizeof(struct nfs4_client), GFP_KERNEL); |
| 883 | if (clp == NULL) |
| 884 | return NULL; |
| 885 | clp->cl_name.data = kmalloc(name.len, GFP_KERNEL); |
| 886 | if (clp->cl_name.data == NULL) { |
| 887 | kfree(clp); |
| 888 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | } |
J. Bruce Fields | 35bba9a | 2007-11-21 22:07:08 -0500 | [diff] [blame] | 890 | memcpy(clp->cl_name.data, name.data, name.len); |
| 891 | clp->cl_name.len = name.len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | return clp; |
| 893 | } |
| 894 | |
| 895 | static inline void |
| 896 | free_client(struct nfs4_client *clp) |
| 897 | { |
J. Bruce Fields | 792c95d | 2010-10-12 19:55:25 -0400 | [diff] [blame] | 898 | while (!list_empty(&clp->cl_sessions)) { |
| 899 | struct nfsd4_session *ses; |
| 900 | ses = list_entry(clp->cl_sessions.next, struct nfsd4_session, |
| 901 | se_perclnt); |
| 902 | list_del(&ses->se_perclnt); |
| 903 | nfsd4_put_session(ses); |
| 904 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | if (clp->cl_cred.cr_group_info) |
| 906 | put_group_info(clp->cl_cred.cr_group_info); |
Olga Kornievskaia | 68e76ad | 2008-12-23 16:17:15 -0500 | [diff] [blame] | 907 | kfree(clp->cl_principal); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | kfree(clp->cl_name.data); |
| 909 | kfree(clp); |
| 910 | } |
| 911 | |
Benny Halevy | d768298 | 2010-05-12 00:13:54 +0300 | [diff] [blame] | 912 | void |
| 913 | release_session_client(struct nfsd4_session *session) |
| 914 | { |
| 915 | struct nfs4_client *clp = session->se_client; |
| 916 | |
| 917 | if (!atomic_dec_and_lock(&clp->cl_refcount, &client_lock)) |
| 918 | return; |
| 919 | if (is_client_expired(clp)) { |
| 920 | free_client(clp); |
| 921 | session->se_client = NULL; |
| 922 | } else |
| 923 | renew_client_locked(clp); |
| 924 | spin_unlock(&client_lock); |
Benny Halevy | d768298 | 2010-05-12 00:13:54 +0300 | [diff] [blame] | 925 | } |
| 926 | |
Benny Halevy | 84d38ac | 2010-05-12 00:13:16 +0300 | [diff] [blame] | 927 | /* must be called under the client_lock */ |
| 928 | static inline void |
| 929 | unhash_client_locked(struct nfs4_client *clp) |
| 930 | { |
J. Bruce Fields | 792c95d | 2010-10-12 19:55:25 -0400 | [diff] [blame] | 931 | struct nfsd4_session *ses; |
| 932 | |
Benny Halevy | 07cd490 | 2010-05-12 00:13:41 +0300 | [diff] [blame] | 933 | mark_client_expired(clp); |
Benny Halevy | 84d38ac | 2010-05-12 00:13:16 +0300 | [diff] [blame] | 934 | list_del(&clp->cl_lru); |
J. Bruce Fields | 4c64937 | 2010-06-15 14:22:37 -0400 | [diff] [blame] | 935 | spin_lock(&clp->cl_lock); |
J. Bruce Fields | 792c95d | 2010-10-12 19:55:25 -0400 | [diff] [blame] | 936 | list_for_each_entry(ses, &clp->cl_sessions, se_perclnt) |
| 937 | list_del_init(&ses->se_hash); |
J. Bruce Fields | 4c64937 | 2010-06-15 14:22:37 -0400 | [diff] [blame] | 938 | spin_unlock(&clp->cl_lock); |
Benny Halevy | 84d38ac | 2010-05-12 00:13:16 +0300 | [diff] [blame] | 939 | } |
| 940 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | static void |
| 942 | expire_client(struct nfs4_client *clp) |
| 943 | { |
| 944 | struct nfs4_stateowner *sop; |
| 945 | struct nfs4_delegation *dp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | struct list_head reaplist; |
| 947 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | INIT_LIST_HEAD(&reaplist); |
| 949 | spin_lock(&recall_lock); |
NeilBrown | ea1da63 | 2005-06-23 22:04:17 -0700 | [diff] [blame] | 950 | while (!list_empty(&clp->cl_delegations)) { |
| 951 | dp = list_entry(clp->cl_delegations.next, struct nfs4_delegation, dl_perclnt); |
NeilBrown | ea1da63 | 2005-06-23 22:04:17 -0700 | [diff] [blame] | 952 | list_del_init(&dp->dl_perclnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | list_move(&dp->dl_recall_lru, &reaplist); |
| 954 | } |
| 955 | spin_unlock(&recall_lock); |
| 956 | while (!list_empty(&reaplist)) { |
| 957 | dp = list_entry(reaplist.next, struct nfs4_delegation, dl_recall_lru); |
| 958 | list_del_init(&dp->dl_recall_lru); |
| 959 | unhash_delegation(dp); |
| 960 | } |
NeilBrown | ea1da63 | 2005-06-23 22:04:17 -0700 | [diff] [blame] | 961 | while (!list_empty(&clp->cl_openowners)) { |
| 962 | sop = list_entry(clp->cl_openowners.next, struct nfs4_stateowner, so_perclient); |
J. Bruce Fields | f044ff8 | 2009-01-11 15:24:04 -0500 | [diff] [blame] | 963 | release_openowner(sop); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | } |
J. Bruce Fields | 6ff8da0 | 2010-06-04 20:04:45 -0400 | [diff] [blame] | 965 | nfsd4_shutdown_callback(clp); |
J. Bruce Fields | 2bf2387 | 2010-03-08 12:37:27 -0500 | [diff] [blame] | 966 | if (clp->cl_cb_conn.cb_xprt) |
| 967 | svc_xprt_put(clp->cl_cb_conn.cb_xprt); |
Benny Halevy | 84d38ac | 2010-05-12 00:13:16 +0300 | [diff] [blame] | 968 | list_del(&clp->cl_idhash); |
| 969 | list_del(&clp->cl_strhash); |
| 970 | spin_lock(&client_lock); |
| 971 | unhash_client_locked(clp); |
Benny Halevy | 46583e2 | 2010-05-12 00:13:29 +0300 | [diff] [blame] | 972 | if (atomic_read(&clp->cl_refcount) == 0) |
| 973 | free_client(clp); |
Benny Halevy | 84d38ac | 2010-05-12 00:13:16 +0300 | [diff] [blame] | 974 | spin_unlock(&client_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | } |
| 976 | |
J. Bruce Fields | 35bba9a | 2007-11-21 22:07:08 -0500 | [diff] [blame] | 977 | static void copy_verf(struct nfs4_client *target, nfs4_verifier *source) |
| 978 | { |
| 979 | memcpy(target->cl_verifier.data, source->data, |
| 980 | sizeof(target->cl_verifier.data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | } |
| 982 | |
J. Bruce Fields | 35bba9a | 2007-11-21 22:07:08 -0500 | [diff] [blame] | 983 | static void copy_clid(struct nfs4_client *target, struct nfs4_client *source) |
| 984 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | target->cl_clientid.cl_boot = source->cl_clientid.cl_boot; |
| 986 | target->cl_clientid.cl_id = source->cl_clientid.cl_id; |
| 987 | } |
| 988 | |
J. Bruce Fields | 35bba9a | 2007-11-21 22:07:08 -0500 | [diff] [blame] | 989 | static void copy_cred(struct svc_cred *target, struct svc_cred *source) |
| 990 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | target->cr_uid = source->cr_uid; |
| 992 | target->cr_gid = source->cr_gid; |
| 993 | target->cr_group_info = source->cr_group_info; |
| 994 | get_group_info(target->cr_group_info); |
| 995 | } |
| 996 | |
J. Bruce Fields | 35bba9a | 2007-11-21 22:07:08 -0500 | [diff] [blame] | 997 | static int same_name(const char *n1, const char *n2) |
J. Bruce Fields | 599e0a2 | 2007-07-26 17:04:54 -0400 | [diff] [blame] | 998 | { |
NeilBrown | a55370a | 2005-06-23 22:03:52 -0700 | [diff] [blame] | 999 | return 0 == memcmp(n1, n2, HEXDIR_LEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | static int |
J. Bruce Fields | 599e0a2 | 2007-07-26 17:04:54 -0400 | [diff] [blame] | 1003 | same_verf(nfs4_verifier *v1, nfs4_verifier *v2) |
| 1004 | { |
| 1005 | return 0 == memcmp(v1->data, v2->data, sizeof(v1->data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | static int |
J. Bruce Fields | 599e0a2 | 2007-07-26 17:04:54 -0400 | [diff] [blame] | 1009 | same_clid(clientid_t *cl1, clientid_t *cl2) |
| 1010 | { |
| 1011 | return (cl1->cl_boot == cl2->cl_boot) && (cl1->cl_id == cl2->cl_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | /* XXX what about NGROUP */ |
| 1015 | static int |
J. Bruce Fields | 599e0a2 | 2007-07-26 17:04:54 -0400 | [diff] [blame] | 1016 | same_creds(struct svc_cred *cr1, struct svc_cred *cr2) |
| 1017 | { |
| 1018 | return cr1->cr_uid == cr2->cr_uid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | } |
| 1020 | |
J. Bruce Fields | 5ec7b46 | 2007-11-21 21:58:56 -0500 | [diff] [blame] | 1021 | static void gen_clid(struct nfs4_client *clp) |
| 1022 | { |
| 1023 | static u32 current_clientid = 1; |
| 1024 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | clp->cl_clientid.cl_boot = boot_time; |
| 1026 | clp->cl_clientid.cl_id = current_clientid++; |
| 1027 | } |
| 1028 | |
J. Bruce Fields | deda2fa | 2007-11-19 20:31:04 -0500 | [diff] [blame] | 1029 | static void gen_confirm(struct nfs4_client *clp) |
| 1030 | { |
| 1031 | static u32 i; |
| 1032 | u32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | p = (u32 *)clp->cl_confirm.data; |
J. Bruce Fields | deda2fa | 2007-11-19 20:31:04 -0500 | [diff] [blame] | 1035 | *p++ = get_seconds(); |
| 1036 | *p++ = i++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
Ricardo Labiaga | b09333c | 2009-09-10 12:27:34 +0300 | [diff] [blame] | 1039 | static struct nfs4_client *create_client(struct xdr_netobj name, char *recdir, |
| 1040 | struct svc_rqst *rqstp, nfs4_verifier *verf) |
| 1041 | { |
| 1042 | struct nfs4_client *clp; |
| 1043 | struct sockaddr *sa = svc_addr(rqstp); |
| 1044 | char *princ; |
| 1045 | |
| 1046 | clp = alloc_client(name); |
| 1047 | if (clp == NULL) |
| 1048 | return NULL; |
| 1049 | |
J. Bruce Fields | 792c95d | 2010-10-12 19:55:25 -0400 | [diff] [blame] | 1050 | INIT_LIST_HEAD(&clp->cl_sessions); |
| 1051 | |
Ricardo Labiaga | b09333c | 2009-09-10 12:27:34 +0300 | [diff] [blame] | 1052 | princ = svc_gss_principal(rqstp); |
| 1053 | if (princ) { |
| 1054 | clp->cl_principal = kstrdup(princ, GFP_KERNEL); |
| 1055 | if (clp->cl_principal == NULL) { |
| 1056 | free_client(clp); |
| 1057 | return NULL; |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | memcpy(clp->cl_recdir, recdir, HEXDIR_LEN); |
Benny Halevy | 46583e2 | 2010-05-12 00:13:29 +0300 | [diff] [blame] | 1062 | atomic_set(&clp->cl_refcount, 0); |
J. Bruce Fields | 77a3569 | 2010-04-30 18:51:44 -0400 | [diff] [blame] | 1063 | clp->cl_cb_state = NFSD4_CB_UNKNOWN; |
Ricardo Labiaga | b09333c | 2009-09-10 12:27:34 +0300 | [diff] [blame] | 1064 | INIT_LIST_HEAD(&clp->cl_idhash); |
| 1065 | INIT_LIST_HEAD(&clp->cl_strhash); |
| 1066 | INIT_LIST_HEAD(&clp->cl_openowners); |
| 1067 | INIT_LIST_HEAD(&clp->cl_delegations); |
Ricardo Labiaga | b09333c | 2009-09-10 12:27:34 +0300 | [diff] [blame] | 1068 | INIT_LIST_HEAD(&clp->cl_lru); |
J. Bruce Fields | 5ce8ba2 | 2011-01-10 16:44:41 -0500 | [diff] [blame] | 1069 | INIT_LIST_HEAD(&clp->cl_callbacks); |
J. Bruce Fields | 6ff8da0 | 2010-06-04 20:04:45 -0400 | [diff] [blame] | 1070 | spin_lock_init(&clp->cl_lock); |
J. Bruce Fields | cee277d | 2010-05-26 17:52:14 -0400 | [diff] [blame] | 1071 | INIT_WORK(&clp->cl_cb_null.cb_work, nfsd4_do_callback_rpc); |
Benny Halevy | 07cd490 | 2010-05-12 00:13:41 +0300 | [diff] [blame] | 1072 | clp->cl_time = get_seconds(); |
Ricardo Labiaga | b09333c | 2009-09-10 12:27:34 +0300 | [diff] [blame] | 1073 | clear_bit(0, &clp->cl_cb_slot_busy); |
| 1074 | rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table"); |
| 1075 | copy_verf(clp, verf); |
| 1076 | rpc_copy_addr((struct sockaddr *) &clp->cl_addr, sa); |
| 1077 | clp->cl_flavor = rqstp->rq_flavor; |
| 1078 | copy_cred(&clp->cl_cred, &rqstp->rq_cred); |
| 1079 | gen_confirm(clp); |
J. Bruce Fields | edd7678 | 2010-06-14 22:26:31 -0400 | [diff] [blame] | 1080 | clp->cl_cb_session = NULL; |
Ricardo Labiaga | b09333c | 2009-09-10 12:27:34 +0300 | [diff] [blame] | 1081 | return clp; |
| 1082 | } |
| 1083 | |
J. Bruce Fields | 35bba9a | 2007-11-21 22:07:08 -0500 | [diff] [blame] | 1084 | static int check_name(struct xdr_netobj name) |
| 1085 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | if (name.len == 0) |
| 1087 | return 0; |
| 1088 | if (name.len > NFS4_OPAQUE_LIMIT) { |
J. Bruce Fields | 2fdada0 | 2007-07-27 16:10:37 -0400 | [diff] [blame] | 1089 | dprintk("NFSD: check_name: name too long(%d)!\n", name.len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | return 0; |
| 1091 | } |
| 1092 | return 1; |
| 1093 | } |
| 1094 | |
NeilBrown | fd39ca9 | 2005-06-23 22:04:03 -0700 | [diff] [blame] | 1095 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | add_to_unconfirmed(struct nfs4_client *clp, unsigned int strhashval) |
| 1097 | { |
| 1098 | unsigned int idhashval; |
| 1099 | |
| 1100 | list_add(&clp->cl_strhash, &unconf_str_hashtbl[strhashval]); |
| 1101 | idhashval = clientid_hashval(clp->cl_clientid.cl_id); |
| 1102 | list_add(&clp->cl_idhash, &unconf_id_hashtbl[idhashval]); |
Benny Halevy | 36acb66 | 2010-05-12 00:13:04 +0300 | [diff] [blame] | 1103 | renew_client(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
NeilBrown | fd39ca9 | 2005-06-23 22:04:03 -0700 | [diff] [blame] | 1106 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | move_to_confirmed(struct nfs4_client *clp) |
| 1108 | { |
| 1109 | unsigned int idhashval = clientid_hashval(clp->cl_clientid.cl_id); |
| 1110 | unsigned int strhashval; |
| 1111 | |
| 1112 | dprintk("NFSD: move_to_confirm nfs4_client %p\n", clp); |
Akinobu Mita | f116629 | 2006-06-26 00:24:46 -0700 | [diff] [blame] | 1113 | list_move(&clp->cl_idhash, &conf_id_hashtbl[idhashval]); |
NeilBrown | a55370a | 2005-06-23 22:03:52 -0700 | [diff] [blame] | 1114 | strhashval = clientstr_hashval(clp->cl_recdir); |
Benny Halevy | 328efba | 2010-05-12 00:12:51 +0300 | [diff] [blame] | 1115 | list_move(&clp->cl_strhash, &conf_str_hashtbl[strhashval]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | renew_client(clp); |
| 1117 | } |
| 1118 | |
| 1119 | static struct nfs4_client * |
| 1120 | find_confirmed_client(clientid_t *clid) |
| 1121 | { |
| 1122 | struct nfs4_client *clp; |
| 1123 | unsigned int idhashval = clientid_hashval(clid->cl_id); |
| 1124 | |
| 1125 | list_for_each_entry(clp, &conf_id_hashtbl[idhashval], cl_idhash) { |
J. Bruce Fields | 599e0a2 | 2007-07-26 17:04:54 -0400 | [diff] [blame] | 1126 | if (same_clid(&clp->cl_clientid, clid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | return clp; |
| 1128 | } |
| 1129 | return NULL; |
| 1130 | } |
| 1131 | |
| 1132 | static struct nfs4_client * |
| 1133 | find_unconfirmed_client(clientid_t *clid) |
| 1134 | { |
| 1135 | struct nfs4_client *clp; |
| 1136 | unsigned int idhashval = clientid_hashval(clid->cl_id); |
| 1137 | |
| 1138 | list_for_each_entry(clp, &unconf_id_hashtbl[idhashval], cl_idhash) { |
J. Bruce Fields | 599e0a2 | 2007-07-26 17:04:54 -0400 | [diff] [blame] | 1139 | if (same_clid(&clp->cl_clientid, clid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | return clp; |
| 1141 | } |
| 1142 | return NULL; |
| 1143 | } |
| 1144 | |
J. Bruce Fields | 6e5f15c | 2010-11-24 17:17:34 -0500 | [diff] [blame] | 1145 | static bool clp_used_exchangeid(struct nfs4_client *clp) |
Andy Adamson | a1bcecd | 2009-04-03 08:28:05 +0300 | [diff] [blame] | 1146 | { |
J. Bruce Fields | 6e5f15c | 2010-11-24 17:17:34 -0500 | [diff] [blame] | 1147 | return clp->cl_exchange_flags != 0; |
J. Bruce Fields | e203d50 | 2010-11-24 17:30:54 -0500 | [diff] [blame] | 1148 | } |
Andy Adamson | a1bcecd | 2009-04-03 08:28:05 +0300 | [diff] [blame] | 1149 | |
NeilBrown | 28ce605 | 2005-06-23 22:03:56 -0700 | [diff] [blame] | 1150 | static struct nfs4_client * |
J. Bruce Fields | e203d50 | 2010-11-24 17:30:54 -0500 | [diff] [blame] | 1151 | find_confirmed_client_by_str(const char *dname, unsigned int hashval) |
NeilBrown | 28ce605 | 2005-06-23 22:03:56 -0700 | [diff] [blame] | 1152 | { |
| 1153 | struct nfs4_client *clp; |
| 1154 | |
| 1155 | list_for_each_entry(clp, &conf_str_hashtbl[hashval], cl_strhash) { |
J. Bruce Fields | e203d50 | 2010-11-24 17:30:54 -0500 | [diff] [blame] | 1156 | if (same_name(clp->cl_recdir, dname)) |
NeilBrown | 28ce605 | 2005-06-23 22:03:56 -0700 | [diff] [blame] | 1157 | return clp; |
| 1158 | } |
| 1159 | return NULL; |
| 1160 | } |
| 1161 | |
| 1162 | static struct nfs4_client * |
J. Bruce Fields | e203d50 | 2010-11-24 17:30:54 -0500 | [diff] [blame] | 1163 | find_unconfirmed_client_by_str(const char *dname, unsigned int hashval) |
NeilBrown | 28ce605 | 2005-06-23 22:03:56 -0700 | [diff] [blame] | 1164 | { |
| 1165 | struct nfs4_client *clp; |
| 1166 | |
| 1167 | list_for_each_entry(clp, &unconf_str_hashtbl[hashval], cl_strhash) { |
J. Bruce Fields | e203d50 | 2010-11-24 17:30:54 -0500 | [diff] [blame] | 1168 | if (same_name(clp->cl_recdir, dname)) |
NeilBrown | 28ce605 | 2005-06-23 22:03:56 -0700 | [diff] [blame] | 1169 | return clp; |
| 1170 | } |
| 1171 | return NULL; |
| 1172 | } |
| 1173 | |
Takuma Umeya | 6f3d772 | 2010-12-15 14:09:01 +0900 | [diff] [blame] | 1174 | static void rpc_svcaddr2sockaddr(struct sockaddr *sa, unsigned short family, union svc_addr_u *svcaddr) |
| 1175 | { |
| 1176 | switch (family) { |
| 1177 | case AF_INET: |
| 1178 | ((struct sockaddr_in *)sa)->sin_family = AF_INET; |
| 1179 | ((struct sockaddr_in *)sa)->sin_addr = svcaddr->addr; |
| 1180 | return; |
| 1181 | case AF_INET6: |
| 1182 | ((struct sockaddr_in6 *)sa)->sin6_family = AF_INET6; |
| 1183 | ((struct sockaddr_in6 *)sa)->sin6_addr = svcaddr->addr6; |
| 1184 | return; |
| 1185 | } |
| 1186 | } |
| 1187 | |
NeilBrown | fd39ca9 | 2005-06-23 22:04:03 -0700 | [diff] [blame] | 1188 | static void |
Takuma Umeya | 6f3d772 | 2010-12-15 14:09:01 +0900 | [diff] [blame] | 1189 | gen_callback(struct nfs4_client *clp, struct nfsd4_setclientid *se, struct svc_rqst *rqstp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | { |
J. Bruce Fields | 07263f1 | 2010-05-31 19:09:40 -0400 | [diff] [blame] | 1191 | struct nfs4_cb_conn *conn = &clp->cl_cb_conn; |
Takuma Umeya | 6f3d772 | 2010-12-15 14:09:01 +0900 | [diff] [blame] | 1192 | struct sockaddr *sa = svc_addr(rqstp); |
| 1193 | u32 scopeid = rpc_get_scope_id(sa); |
Jeff Layton | 7077ecb | 2009-08-14 12:57:58 -0400 | [diff] [blame] | 1194 | unsigned short expected_family; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | |
Jeff Layton | 7077ecb | 2009-08-14 12:57:58 -0400 | [diff] [blame] | 1196 | /* Currently, we only support tcp and tcp6 for the callback channel */ |
| 1197 | if (se->se_callback_netid_len == 3 && |
| 1198 | !memcmp(se->se_callback_netid_val, "tcp", 3)) |
| 1199 | expected_family = AF_INET; |
| 1200 | else if (se->se_callback_netid_len == 4 && |
| 1201 | !memcmp(se->se_callback_netid_val, "tcp6", 4)) |
| 1202 | expected_family = AF_INET6; |
| 1203 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | goto out_err; |
| 1205 | |
J. Bruce Fields | 07263f1 | 2010-05-31 19:09:40 -0400 | [diff] [blame] | 1206 | conn->cb_addrlen = rpc_uaddr2sockaddr(se->se_callback_addr_val, |
Jeff Layton | aa9a4ec | 2009-08-14 12:57:57 -0400 | [diff] [blame] | 1207 | se->se_callback_addr_len, |
J. Bruce Fields | 07263f1 | 2010-05-31 19:09:40 -0400 | [diff] [blame] | 1208 | (struct sockaddr *)&conn->cb_addr, |
| 1209 | sizeof(conn->cb_addr)); |
Jeff Layton | aa9a4ec | 2009-08-14 12:57:57 -0400 | [diff] [blame] | 1210 | |
J. Bruce Fields | 07263f1 | 2010-05-31 19:09:40 -0400 | [diff] [blame] | 1211 | if (!conn->cb_addrlen || conn->cb_addr.ss_family != expected_family) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | goto out_err; |
Jeff Layton | aa9a4ec | 2009-08-14 12:57:57 -0400 | [diff] [blame] | 1213 | |
J. Bruce Fields | 07263f1 | 2010-05-31 19:09:40 -0400 | [diff] [blame] | 1214 | if (conn->cb_addr.ss_family == AF_INET6) |
| 1215 | ((struct sockaddr_in6 *)&conn->cb_addr)->sin6_scope_id = scopeid; |
Jeff Layton | fbf4665 | 2009-08-14 12:57:59 -0400 | [diff] [blame] | 1216 | |
J. Bruce Fields | 07263f1 | 2010-05-31 19:09:40 -0400 | [diff] [blame] | 1217 | conn->cb_prog = se->se_callback_prog; |
| 1218 | conn->cb_ident = se->se_callback_ident; |
Takuma Umeya | 6f3d772 | 2010-12-15 14:09:01 +0900 | [diff] [blame] | 1219 | rpc_svcaddr2sockaddr((struct sockaddr *)&conn->cb_saddr, expected_family, &rqstp->rq_daddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | return; |
| 1221 | out_err: |
J. Bruce Fields | 07263f1 | 2010-05-31 19:09:40 -0400 | [diff] [blame] | 1222 | conn->cb_addr.ss_family = AF_UNSPEC; |
| 1223 | conn->cb_addrlen = 0; |
Neil Brown | 849823c | 2005-09-13 01:25:36 -0700 | [diff] [blame] | 1224 | dprintk(KERN_INFO "NFSD: this client (clientid %08x/%08x) " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | "will not receive delegations\n", |
| 1226 | clp->cl_clientid.cl_boot, clp->cl_clientid.cl_id); |
| 1227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | return; |
| 1229 | } |
| 1230 | |
Andy Adamson | 074fe89 | 2009-04-03 08:28:15 +0300 | [diff] [blame] | 1231 | /* |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 1232 | * Cache a reply. nfsd4_check_drc_limit() has bounded the cache size. |
Andy Adamson | 074fe89 | 2009-04-03 08:28:15 +0300 | [diff] [blame] | 1233 | */ |
| 1234 | void |
| 1235 | nfsd4_store_cache_entry(struct nfsd4_compoundres *resp) |
| 1236 | { |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 1237 | struct nfsd4_slot *slot = resp->cstate.slot; |
| 1238 | unsigned int base; |
Andy Adamson | 074fe89 | 2009-04-03 08:28:15 +0300 | [diff] [blame] | 1239 | |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 1240 | dprintk("--> %s slot %p\n", __func__, slot); |
Andy Adamson | 074fe89 | 2009-04-03 08:28:15 +0300 | [diff] [blame] | 1241 | |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 1242 | slot->sl_opcnt = resp->opcnt; |
| 1243 | slot->sl_status = resp->cstate.status; |
Andy Adamson | bf864a3 | 2009-04-03 08:28:35 +0300 | [diff] [blame] | 1244 | |
| 1245 | if (nfsd4_not_cached(resp)) { |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 1246 | slot->sl_datalen = 0; |
Andy Adamson | bf864a3 | 2009-04-03 08:28:35 +0300 | [diff] [blame] | 1247 | return; |
| 1248 | } |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 1249 | slot->sl_datalen = (char *)resp->p - (char *)resp->cstate.datap; |
| 1250 | base = (char *)resp->cstate.datap - |
| 1251 | (char *)resp->xbuf->head[0].iov_base; |
| 1252 | if (read_bytes_from_xdr_buf(resp->xbuf, base, slot->sl_data, |
| 1253 | slot->sl_datalen)) |
| 1254 | WARN("%s: sessions DRC could not cache compound\n", __func__); |
| 1255 | return; |
Andy Adamson | 074fe89 | 2009-04-03 08:28:15 +0300 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | /* |
Andy Adamson | abfabf8 | 2009-07-23 19:02:18 -0400 | [diff] [blame] | 1259 | * Encode the replay sequence operation from the slot values. |
| 1260 | * If cachethis is FALSE encode the uncached rep error on the next |
| 1261 | * operation which sets resp->p and increments resp->opcnt for |
| 1262 | * nfs4svc_encode_compoundres. |
| 1263 | * |
Andy Adamson | 074fe89 | 2009-04-03 08:28:15 +0300 | [diff] [blame] | 1264 | */ |
Andy Adamson | abfabf8 | 2009-07-23 19:02:18 -0400 | [diff] [blame] | 1265 | static __be32 |
| 1266 | nfsd4_enc_sequence_replay(struct nfsd4_compoundargs *args, |
| 1267 | struct nfsd4_compoundres *resp) |
Andy Adamson | 074fe89 | 2009-04-03 08:28:15 +0300 | [diff] [blame] | 1268 | { |
Andy Adamson | abfabf8 | 2009-07-23 19:02:18 -0400 | [diff] [blame] | 1269 | struct nfsd4_op *op; |
| 1270 | struct nfsd4_slot *slot = resp->cstate.slot; |
Andy Adamson | 074fe89 | 2009-04-03 08:28:15 +0300 | [diff] [blame] | 1271 | |
Andy Adamson | abfabf8 | 2009-07-23 19:02:18 -0400 | [diff] [blame] | 1272 | dprintk("--> %s resp->opcnt %d cachethis %u \n", __func__, |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 1273 | resp->opcnt, resp->cstate.slot->sl_cachethis); |
Andy Adamson | abfabf8 | 2009-07-23 19:02:18 -0400 | [diff] [blame] | 1274 | |
| 1275 | /* Encode the replayed sequence operation */ |
| 1276 | op = &args->ops[resp->opcnt - 1]; |
| 1277 | nfsd4_encode_operation(resp, op); |
| 1278 | |
| 1279 | /* Return nfserr_retry_uncached_rep in next operation. */ |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 1280 | if (args->opcnt > 1 && slot->sl_cachethis == 0) { |
Andy Adamson | abfabf8 | 2009-07-23 19:02:18 -0400 | [diff] [blame] | 1281 | op = &args->ops[resp->opcnt++]; |
| 1282 | op->status = nfserr_retry_uncached_rep; |
| 1283 | nfsd4_encode_operation(resp, op); |
Andy Adamson | 074fe89 | 2009-04-03 08:28:15 +0300 | [diff] [blame] | 1284 | } |
Andy Adamson | abfabf8 | 2009-07-23 19:02:18 -0400 | [diff] [blame] | 1285 | return op->status; |
Andy Adamson | 074fe89 | 2009-04-03 08:28:15 +0300 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | /* |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 1289 | * The sequence operation is not cached because we can use the slot and |
| 1290 | * session values. |
Andy Adamson | 074fe89 | 2009-04-03 08:28:15 +0300 | [diff] [blame] | 1291 | */ |
| 1292 | __be32 |
Andy Adamson | bf864a3 | 2009-04-03 08:28:35 +0300 | [diff] [blame] | 1293 | nfsd4_replay_cache_entry(struct nfsd4_compoundres *resp, |
| 1294 | struct nfsd4_sequence *seq) |
Andy Adamson | 074fe89 | 2009-04-03 08:28:15 +0300 | [diff] [blame] | 1295 | { |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 1296 | struct nfsd4_slot *slot = resp->cstate.slot; |
Andy Adamson | 074fe89 | 2009-04-03 08:28:15 +0300 | [diff] [blame] | 1297 | __be32 status; |
| 1298 | |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 1299 | dprintk("--> %s slot %p\n", __func__, slot); |
Andy Adamson | 074fe89 | 2009-04-03 08:28:15 +0300 | [diff] [blame] | 1300 | |
Andy Adamson | abfabf8 | 2009-07-23 19:02:18 -0400 | [diff] [blame] | 1301 | /* Either returns 0 or nfserr_retry_uncached */ |
| 1302 | status = nfsd4_enc_sequence_replay(resp->rqstp->rq_argp, resp); |
| 1303 | if (status == nfserr_retry_uncached_rep) |
| 1304 | return status; |
Andy Adamson | 074fe89 | 2009-04-03 08:28:15 +0300 | [diff] [blame] | 1305 | |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 1306 | /* The sequence operation has been encoded, cstate->datap set. */ |
| 1307 | memcpy(resp->cstate.datap, slot->sl_data, slot->sl_datalen); |
Andy Adamson | 074fe89 | 2009-04-03 08:28:15 +0300 | [diff] [blame] | 1308 | |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 1309 | resp->opcnt = slot->sl_opcnt; |
| 1310 | resp->p = resp->cstate.datap + XDR_QUADLEN(slot->sl_datalen); |
| 1311 | status = slot->sl_status; |
Andy Adamson | 074fe89 | 2009-04-03 08:28:15 +0300 | [diff] [blame] | 1312 | |
| 1313 | return status; |
| 1314 | } |
| 1315 | |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1316 | /* |
| 1317 | * Set the exchange_id flags returned by the server. |
| 1318 | */ |
| 1319 | static void |
| 1320 | nfsd4_set_ex_flags(struct nfs4_client *new, struct nfsd4_exchange_id *clid) |
| 1321 | { |
| 1322 | /* pNFS is not supported */ |
| 1323 | new->cl_exchange_flags |= EXCHGID4_FLAG_USE_NON_PNFS; |
| 1324 | |
| 1325 | /* Referrals are supported, Migration is not. */ |
| 1326 | new->cl_exchange_flags |= EXCHGID4_FLAG_SUPP_MOVED_REFER; |
| 1327 | |
| 1328 | /* set the wire flags to return to client. */ |
| 1329 | clid->flags = new->cl_exchange_flags; |
| 1330 | } |
| 1331 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1332 | __be32 |
Andy Adamson | 069b6ad | 2009-04-03 08:27:58 +0300 | [diff] [blame] | 1333 | nfsd4_exchange_id(struct svc_rqst *rqstp, |
| 1334 | struct nfsd4_compound_state *cstate, |
| 1335 | struct nfsd4_exchange_id *exid) |
| 1336 | { |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1337 | struct nfs4_client *unconf, *conf, *new; |
| 1338 | int status; |
| 1339 | unsigned int strhashval; |
| 1340 | char dname[HEXDIR_LEN]; |
Jeff Layton | 363168b | 2009-08-14 12:57:56 -0400 | [diff] [blame] | 1341 | char addr_str[INET6_ADDRSTRLEN]; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1342 | nfs4_verifier verf = exid->verifier; |
Jeff Layton | 363168b | 2009-08-14 12:57:56 -0400 | [diff] [blame] | 1343 | struct sockaddr *sa = svc_addr(rqstp); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1344 | |
Jeff Layton | 363168b | 2009-08-14 12:57:56 -0400 | [diff] [blame] | 1345 | rpc_ntop(sa, addr_str, sizeof(addr_str)); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1346 | dprintk("%s rqstp=%p exid=%p clname.len=%u clname.data=%p " |
Jeff Layton | 363168b | 2009-08-14 12:57:56 -0400 | [diff] [blame] | 1347 | "ip_addr=%s flags %x, spa_how %d\n", |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1348 | __func__, rqstp, exid, exid->clname.len, exid->clname.data, |
Jeff Layton | 363168b | 2009-08-14 12:57:56 -0400 | [diff] [blame] | 1349 | addr_str, exid->flags, exid->spa_how); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1350 | |
| 1351 | if (!check_name(exid->clname) || (exid->flags & ~EXCHGID4_FLAG_MASK_A)) |
| 1352 | return nfserr_inval; |
| 1353 | |
| 1354 | /* Currently only support SP4_NONE */ |
| 1355 | switch (exid->spa_how) { |
| 1356 | case SP4_NONE: |
| 1357 | break; |
| 1358 | case SP4_SSV: |
J. Bruce Fields | 044bc1d | 2010-11-12 14:36:06 -0500 | [diff] [blame] | 1359 | return nfserr_serverfault; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1360 | default: |
| 1361 | BUG(); /* checked by xdr code */ |
| 1362 | case SP4_MACH_CRED: |
| 1363 | return nfserr_serverfault; /* no excuse :-/ */ |
| 1364 | } |
| 1365 | |
| 1366 | status = nfs4_make_rec_clidname(dname, &exid->clname); |
| 1367 | |
| 1368 | if (status) |
| 1369 | goto error; |
| 1370 | |
| 1371 | strhashval = clientstr_hashval(dname); |
| 1372 | |
| 1373 | nfs4_lock_state(); |
| 1374 | status = nfs_ok; |
| 1375 | |
J. Bruce Fields | e203d50 | 2010-11-24 17:30:54 -0500 | [diff] [blame] | 1376 | conf = find_confirmed_client_by_str(dname, strhashval); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1377 | if (conf) { |
J. Bruce Fields | e203d50 | 2010-11-24 17:30:54 -0500 | [diff] [blame] | 1378 | if (!clp_used_exchangeid(conf)) { |
| 1379 | status = nfserr_clid_inuse; /* XXX: ? */ |
| 1380 | goto out; |
| 1381 | } |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1382 | if (!same_verf(&verf, &conf->cl_verifier)) { |
| 1383 | /* 18.35.4 case 8 */ |
| 1384 | if (exid->flags & EXCHGID4_FLAG_UPD_CONFIRMED_REC_A) { |
| 1385 | status = nfserr_not_same; |
| 1386 | goto out; |
| 1387 | } |
| 1388 | /* Client reboot: destroy old state */ |
| 1389 | expire_client(conf); |
| 1390 | goto out_new; |
| 1391 | } |
| 1392 | if (!same_creds(&conf->cl_cred, &rqstp->rq_cred)) { |
| 1393 | /* 18.35.4 case 9 */ |
| 1394 | if (exid->flags & EXCHGID4_FLAG_UPD_CONFIRMED_REC_A) { |
| 1395 | status = nfserr_perm; |
| 1396 | goto out; |
| 1397 | } |
| 1398 | expire_client(conf); |
| 1399 | goto out_new; |
| 1400 | } |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1401 | /* |
| 1402 | * Set bit when the owner id and verifier map to an already |
| 1403 | * confirmed client id (18.35.3). |
| 1404 | */ |
| 1405 | exid->flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 1406 | |
| 1407 | /* |
| 1408 | * Falling into 18.35.4 case 2, possible router replay. |
| 1409 | * Leave confirmed record intact and return same result. |
| 1410 | */ |
| 1411 | copy_verf(conf, &verf); |
| 1412 | new = conf; |
| 1413 | goto out_copy; |
Mike Sager | 6ddbbbf | 2009-06-16 04:20:47 +0300 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | /* 18.35.4 case 7 */ |
| 1417 | if (exid->flags & EXCHGID4_FLAG_UPD_CONFIRMED_REC_A) { |
| 1418 | status = nfserr_noent; |
| 1419 | goto out; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1420 | } |
| 1421 | |
J. Bruce Fields | e203d50 | 2010-11-24 17:30:54 -0500 | [diff] [blame] | 1422 | unconf = find_unconfirmed_client_by_str(dname, strhashval); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1423 | if (unconf) { |
| 1424 | /* |
| 1425 | * Possible retry or client restart. Per 18.35.4 case 4, |
| 1426 | * a new unconfirmed record should be generated regardless |
| 1427 | * of whether any properties have changed. |
| 1428 | */ |
| 1429 | expire_client(unconf); |
| 1430 | } |
| 1431 | |
| 1432 | out_new: |
| 1433 | /* Normal case */ |
Ricardo Labiaga | b09333c | 2009-09-10 12:27:34 +0300 | [diff] [blame] | 1434 | new = create_client(exid->clname, dname, rqstp, &verf); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1435 | if (new == NULL) { |
J. Bruce Fields | 4731030 | 2010-06-22 16:17:12 -0400 | [diff] [blame] | 1436 | status = nfserr_jukebox; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1437 | goto out; |
| 1438 | } |
| 1439 | |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1440 | gen_clid(new); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1441 | add_to_unconfirmed(new, strhashval); |
| 1442 | out_copy: |
| 1443 | exid->clientid.cl_boot = new->cl_clientid.cl_boot; |
| 1444 | exid->clientid.cl_id = new->cl_clientid.cl_id; |
| 1445 | |
Andy Adamson | 38eb76a | 2009-04-03 08:28:32 +0300 | [diff] [blame] | 1446 | exid->seqid = 1; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1447 | nfsd4_set_ex_flags(new, exid); |
| 1448 | |
| 1449 | dprintk("nfsd4_exchange_id seqid %d flags %x\n", |
Andy Adamson | 49557cc | 2009-07-23 19:02:16 -0400 | [diff] [blame] | 1450 | new->cl_cs_slot.sl_seqid, new->cl_exchange_flags); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1451 | status = nfs_ok; |
| 1452 | |
| 1453 | out: |
| 1454 | nfs4_unlock_state(); |
| 1455 | error: |
| 1456 | dprintk("nfsd4_exchange_id returns %d\n", ntohl(status)); |
| 1457 | return status; |
Andy Adamson | 069b6ad | 2009-04-03 08:27:58 +0300 | [diff] [blame] | 1458 | } |
| 1459 | |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1460 | static int |
Andy Adamson | 88e588d | 2009-07-23 19:02:15 -0400 | [diff] [blame] | 1461 | check_slot_seqid(u32 seqid, u32 slot_seqid, int slot_inuse) |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1462 | { |
Andy Adamson | 88e588d | 2009-07-23 19:02:15 -0400 | [diff] [blame] | 1463 | dprintk("%s enter. seqid %d slot_seqid %d\n", __func__, seqid, |
| 1464 | slot_seqid); |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1465 | |
| 1466 | /* The slot is in use, and no response has been sent. */ |
Andy Adamson | 88e588d | 2009-07-23 19:02:15 -0400 | [diff] [blame] | 1467 | if (slot_inuse) { |
| 1468 | if (seqid == slot_seqid) |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1469 | return nfserr_jukebox; |
| 1470 | else |
| 1471 | return nfserr_seq_misordered; |
| 1472 | } |
| 1473 | /* Normal */ |
Andy Adamson | 88e588d | 2009-07-23 19:02:15 -0400 | [diff] [blame] | 1474 | if (likely(seqid == slot_seqid + 1)) |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1475 | return nfs_ok; |
| 1476 | /* Replay */ |
Andy Adamson | 88e588d | 2009-07-23 19:02:15 -0400 | [diff] [blame] | 1477 | if (seqid == slot_seqid) |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1478 | return nfserr_replay_cache; |
| 1479 | /* Wraparound */ |
Andy Adamson | 88e588d | 2009-07-23 19:02:15 -0400 | [diff] [blame] | 1480 | if (seqid == 1 && (slot_seqid + 1) == 0) |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1481 | return nfs_ok; |
| 1482 | /* Misordered replay or misordered new request */ |
| 1483 | return nfserr_seq_misordered; |
| 1484 | } |
| 1485 | |
Andy Adamson | 49557cc | 2009-07-23 19:02:16 -0400 | [diff] [blame] | 1486 | /* |
| 1487 | * Cache the create session result into the create session single DRC |
| 1488 | * slot cache by saving the xdr structure. sl_seqid has been set. |
| 1489 | * Do this for solo or embedded create session operations. |
| 1490 | */ |
| 1491 | static void |
| 1492 | nfsd4_cache_create_session(struct nfsd4_create_session *cr_ses, |
| 1493 | struct nfsd4_clid_slot *slot, int nfserr) |
| 1494 | { |
| 1495 | slot->sl_status = nfserr; |
| 1496 | memcpy(&slot->sl_cr_ses, cr_ses, sizeof(*cr_ses)); |
| 1497 | } |
| 1498 | |
| 1499 | static __be32 |
| 1500 | nfsd4_replay_create_session(struct nfsd4_create_session *cr_ses, |
| 1501 | struct nfsd4_clid_slot *slot) |
| 1502 | { |
| 1503 | memcpy(cr_ses, &slot->sl_cr_ses, sizeof(*cr_ses)); |
| 1504 | return slot->sl_status; |
| 1505 | } |
| 1506 | |
Mi Jinlong | 1b74c25 | 2011-07-14 14:50:17 +0800 | [diff] [blame] | 1507 | #define NFSD_MIN_REQ_HDR_SEQ_SZ ((\ |
| 1508 | 2 * 2 + /* credential,verifier: AUTH_NULL, length 0 */ \ |
| 1509 | 1 + /* MIN tag is length with zero, only length */ \ |
| 1510 | 3 + /* version, opcount, opcode */ \ |
| 1511 | XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ |
| 1512 | /* seqid, slotID, slotID, cache */ \ |
| 1513 | 4 ) * sizeof(__be32)) |
| 1514 | |
| 1515 | #define NFSD_MIN_RESP_HDR_SEQ_SZ ((\ |
| 1516 | 2 + /* verifier: AUTH_NULL, length 0 */\ |
| 1517 | 1 + /* status */ \ |
| 1518 | 1 + /* MIN tag is length with zero, only length */ \ |
| 1519 | 3 + /* opcount, opcode, opstatus*/ \ |
| 1520 | XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ |
| 1521 | /* seqid, slotID, slotID, slotID, status */ \ |
| 1522 | 5 ) * sizeof(__be32)) |
| 1523 | |
| 1524 | static __be32 check_forechannel_attrs(struct nfsd4_channel_attrs fchannel) |
| 1525 | { |
| 1526 | return fchannel.maxreq_sz < NFSD_MIN_REQ_HDR_SEQ_SZ |
| 1527 | || fchannel.maxresp_sz < NFSD_MIN_RESP_HDR_SEQ_SZ; |
| 1528 | } |
| 1529 | |
Andy Adamson | 069b6ad | 2009-04-03 08:27:58 +0300 | [diff] [blame] | 1530 | __be32 |
| 1531 | nfsd4_create_session(struct svc_rqst *rqstp, |
| 1532 | struct nfsd4_compound_state *cstate, |
| 1533 | struct nfsd4_create_session *cr_ses) |
| 1534 | { |
Jeff Layton | 363168b | 2009-08-14 12:57:56 -0400 | [diff] [blame] | 1535 | struct sockaddr *sa = svc_addr(rqstp); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1536 | struct nfs4_client *conf, *unconf; |
J. Bruce Fields | ac7c46f | 2010-06-14 19:01:57 -0400 | [diff] [blame] | 1537 | struct nfsd4_session *new; |
Andy Adamson | 49557cc | 2009-07-23 19:02:16 -0400 | [diff] [blame] | 1538 | struct nfsd4_clid_slot *cs_slot = NULL; |
J. Bruce Fields | 86c3e16 | 2010-10-02 17:04:00 -0400 | [diff] [blame] | 1539 | bool confirm_me = false; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1540 | int status = 0; |
| 1541 | |
Mi Jinlong | a62573d | 2011-03-23 17:57:07 +0800 | [diff] [blame] | 1542 | if (cr_ses->flags & ~SESSION4_FLAG_MASK_A) |
| 1543 | return nfserr_inval; |
| 1544 | |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1545 | nfs4_lock_state(); |
| 1546 | unconf = find_unconfirmed_client(&cr_ses->clientid); |
| 1547 | conf = find_confirmed_client(&cr_ses->clientid); |
| 1548 | |
| 1549 | if (conf) { |
Andy Adamson | 49557cc | 2009-07-23 19:02:16 -0400 | [diff] [blame] | 1550 | cs_slot = &conf->cl_cs_slot; |
| 1551 | status = check_slot_seqid(cr_ses->seqid, cs_slot->sl_seqid, 0); |
Andy Adamson | 38eb76a | 2009-04-03 08:28:32 +0300 | [diff] [blame] | 1552 | if (status == nfserr_replay_cache) { |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1553 | dprintk("Got a create_session replay! seqid= %d\n", |
Andy Adamson | 49557cc | 2009-07-23 19:02:16 -0400 | [diff] [blame] | 1554 | cs_slot->sl_seqid); |
Andy Adamson | 38eb76a | 2009-04-03 08:28:32 +0300 | [diff] [blame] | 1555 | /* Return the cached reply status */ |
Andy Adamson | 49557cc | 2009-07-23 19:02:16 -0400 | [diff] [blame] | 1556 | status = nfsd4_replay_create_session(cr_ses, cs_slot); |
Andy Adamson | 38eb76a | 2009-04-03 08:28:32 +0300 | [diff] [blame] | 1557 | goto out; |
Andy Adamson | 49557cc | 2009-07-23 19:02:16 -0400 | [diff] [blame] | 1558 | } else if (cr_ses->seqid != cs_slot->sl_seqid + 1) { |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1559 | status = nfserr_seq_misordered; |
| 1560 | dprintk("Sequence misordered!\n"); |
| 1561 | dprintk("Expected seqid= %d but got seqid= %d\n", |
Andy Adamson | 49557cc | 2009-07-23 19:02:16 -0400 | [diff] [blame] | 1562 | cs_slot->sl_seqid, cr_ses->seqid); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1563 | goto out; |
| 1564 | } |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1565 | } else if (unconf) { |
| 1566 | if (!same_creds(&unconf->cl_cred, &rqstp->rq_cred) || |
Jeff Layton | 363168b | 2009-08-14 12:57:56 -0400 | [diff] [blame] | 1567 | !rpc_cmp_addr(sa, (struct sockaddr *) &unconf->cl_addr)) { |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1568 | status = nfserr_clid_inuse; |
| 1569 | goto out; |
| 1570 | } |
| 1571 | |
Andy Adamson | 49557cc | 2009-07-23 19:02:16 -0400 | [diff] [blame] | 1572 | cs_slot = &unconf->cl_cs_slot; |
| 1573 | status = check_slot_seqid(cr_ses->seqid, cs_slot->sl_seqid, 0); |
Andy Adamson | 38eb76a | 2009-04-03 08:28:32 +0300 | [diff] [blame] | 1574 | if (status) { |
| 1575 | /* an unconfirmed replay returns misordered */ |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1576 | status = nfserr_seq_misordered; |
J. Bruce Fields | cd5b814 | 2010-10-02 17:03:35 -0400 | [diff] [blame] | 1577 | goto out; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1578 | } |
| 1579 | |
J. Bruce Fields | 86c3e16 | 2010-10-02 17:04:00 -0400 | [diff] [blame] | 1580 | confirm_me = true; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1581 | conf = unconf; |
| 1582 | } else { |
| 1583 | status = nfserr_stale_clientid; |
| 1584 | goto out; |
| 1585 | } |
| 1586 | |
J. Bruce Fields | 408b79b | 2010-04-15 15:11:09 -0400 | [diff] [blame] | 1587 | /* |
J. Bruce Fields | 8323c3b | 2010-10-19 19:36:51 -0400 | [diff] [blame] | 1588 | * XXX: we should probably set this at creation time, and check |
| 1589 | * for consistent minorversion use throughout: |
| 1590 | */ |
| 1591 | conf->cl_minorversion = 1; |
| 1592 | /* |
J. Bruce Fields | 408b79b | 2010-04-15 15:11:09 -0400 | [diff] [blame] | 1593 | * We do not support RDMA or persistent sessions |
| 1594 | */ |
| 1595 | cr_ses->flags &= ~SESSION4_PERSIST; |
| 1596 | cr_ses->flags &= ~SESSION4_RDMA; |
| 1597 | |
Mi Jinlong | 1b74c25 | 2011-07-14 14:50:17 +0800 | [diff] [blame] | 1598 | status = nfserr_toosmall; |
| 1599 | if (check_forechannel_attrs(cr_ses->fore_channel)) |
| 1600 | goto out; |
| 1601 | |
J. Bruce Fields | ac7c46f | 2010-06-14 19:01:57 -0400 | [diff] [blame] | 1602 | status = nfserr_jukebox; |
| 1603 | new = alloc_init_session(rqstp, conf, cr_ses); |
| 1604 | if (!new) |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1605 | goto out; |
J. Bruce Fields | ac7c46f | 2010-06-14 19:01:57 -0400 | [diff] [blame] | 1606 | status = nfs_ok; |
| 1607 | memcpy(cr_ses->sessionid.data, new->se_sessionid.data, |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1608 | NFS4_MAX_SESSIONID_LEN); |
Mi Jinlong | 1205065 | 2010-11-11 18:03:40 +0800 | [diff] [blame] | 1609 | memcpy(&cr_ses->fore_channel, &new->se_fchannel, |
| 1610 | sizeof(struct nfsd4_channel_attrs)); |
J. Bruce Fields | 86c3e16 | 2010-10-02 17:04:00 -0400 | [diff] [blame] | 1611 | cs_slot->sl_seqid++; |
Andy Adamson | 49557cc | 2009-07-23 19:02:16 -0400 | [diff] [blame] | 1612 | cr_ses->seqid = cs_slot->sl_seqid; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1613 | |
Andy Adamson | 49557cc | 2009-07-23 19:02:16 -0400 | [diff] [blame] | 1614 | /* cache solo and embedded create sessions under the state lock */ |
| 1615 | nfsd4_cache_create_session(cr_ses, cs_slot, status); |
J. Bruce Fields | 86c3e16 | 2010-10-02 17:04:00 -0400 | [diff] [blame] | 1616 | if (confirm_me) |
| 1617 | move_to_confirmed(conf); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1618 | out: |
| 1619 | nfs4_unlock_state(); |
| 1620 | dprintk("%s returns %d\n", __func__, ntohl(status)); |
| 1621 | return status; |
Andy Adamson | 069b6ad | 2009-04-03 08:27:58 +0300 | [diff] [blame] | 1622 | } |
| 1623 | |
J. Bruce Fields | 5771635 | 2010-04-21 12:27:19 -0400 | [diff] [blame] | 1624 | static bool nfsd4_last_compound_op(struct svc_rqst *rqstp) |
| 1625 | { |
| 1626 | struct nfsd4_compoundres *resp = rqstp->rq_resp; |
| 1627 | struct nfsd4_compoundargs *argp = rqstp->rq_argp; |
| 1628 | |
| 1629 | return argp->opcnt == resp->opcnt; |
| 1630 | } |
| 1631 | |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 1632 | static __be32 nfsd4_map_bcts_dir(u32 *dir) |
| 1633 | { |
| 1634 | switch (*dir) { |
| 1635 | case NFS4_CDFC4_FORE: |
| 1636 | case NFS4_CDFC4_BACK: |
| 1637 | return nfs_ok; |
| 1638 | case NFS4_CDFC4_FORE_OR_BOTH: |
| 1639 | case NFS4_CDFC4_BACK_OR_BOTH: |
| 1640 | *dir = NFS4_CDFC4_BOTH; |
| 1641 | return nfs_ok; |
| 1642 | }; |
| 1643 | return nfserr_inval; |
| 1644 | } |
| 1645 | |
| 1646 | __be32 nfsd4_bind_conn_to_session(struct svc_rqst *rqstp, |
| 1647 | struct nfsd4_compound_state *cstate, |
| 1648 | struct nfsd4_bind_conn_to_session *bcts) |
| 1649 | { |
| 1650 | __be32 status; |
| 1651 | |
| 1652 | if (!nfsd4_last_compound_op(rqstp)) |
| 1653 | return nfserr_not_only_op; |
| 1654 | spin_lock(&client_lock); |
| 1655 | cstate->session = find_in_sessionid_hashtbl(&bcts->sessionid); |
| 1656 | /* Sorta weird: we only need the refcnt'ing because new_conn acquires |
| 1657 | * client_lock iself: */ |
| 1658 | if (cstate->session) { |
| 1659 | nfsd4_get_session(cstate->session); |
| 1660 | atomic_inc(&cstate->session->se_client->cl_refcount); |
| 1661 | } |
| 1662 | spin_unlock(&client_lock); |
| 1663 | if (!cstate->session) |
| 1664 | return nfserr_badsession; |
| 1665 | |
| 1666 | status = nfsd4_map_bcts_dir(&bcts->dir); |
Bryan Schumaker | 1db2b9d | 2011-04-27 15:47:15 -0400 | [diff] [blame] | 1667 | if (!status) |
| 1668 | nfsd4_new_conn(rqstp, cstate->session, bcts->dir); |
| 1669 | return status; |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 1670 | } |
| 1671 | |
J. Bruce Fields | 5d4cec2 | 2010-05-01 12:56:06 -0400 | [diff] [blame] | 1672 | static bool nfsd4_compound_in_session(struct nfsd4_session *session, struct nfs4_sessionid *sid) |
| 1673 | { |
| 1674 | if (!session) |
| 1675 | return 0; |
| 1676 | return !memcmp(sid, &session->se_sessionid, sizeof(*sid)); |
| 1677 | } |
| 1678 | |
Andy Adamson | 069b6ad | 2009-04-03 08:27:58 +0300 | [diff] [blame] | 1679 | __be32 |
| 1680 | nfsd4_destroy_session(struct svc_rqst *r, |
| 1681 | struct nfsd4_compound_state *cstate, |
| 1682 | struct nfsd4_destroy_session *sessionid) |
| 1683 | { |
Benny Halevy | e10e0cf | 2009-04-03 08:28:38 +0300 | [diff] [blame] | 1684 | struct nfsd4_session *ses; |
| 1685 | u32 status = nfserr_badsession; |
| 1686 | |
| 1687 | /* Notes: |
| 1688 | * - The confirmed nfs4_client->cl_sessionid holds destroyed sessinid |
| 1689 | * - Should we return nfserr_back_chan_busy if waiting for |
| 1690 | * callbacks on to-be-destroyed session? |
| 1691 | * - Do we need to clear any callback info from previous session? |
| 1692 | */ |
| 1693 | |
J. Bruce Fields | 5d4cec2 | 2010-05-01 12:56:06 -0400 | [diff] [blame] | 1694 | if (nfsd4_compound_in_session(cstate->session, &sessionid->sessionid)) { |
J. Bruce Fields | 5771635 | 2010-04-21 12:27:19 -0400 | [diff] [blame] | 1695 | if (!nfsd4_last_compound_op(r)) |
| 1696 | return nfserr_not_only_op; |
| 1697 | } |
Benny Halevy | e10e0cf | 2009-04-03 08:28:38 +0300 | [diff] [blame] | 1698 | dump_sessionid(__func__, &sessionid->sessionid); |
Benny Halevy | 9089f1b | 2010-05-12 00:12:26 +0300 | [diff] [blame] | 1699 | spin_lock(&client_lock); |
Benny Halevy | e10e0cf | 2009-04-03 08:28:38 +0300 | [diff] [blame] | 1700 | ses = find_in_sessionid_hashtbl(&sessionid->sessionid); |
| 1701 | if (!ses) { |
Benny Halevy | 9089f1b | 2010-05-12 00:12:26 +0300 | [diff] [blame] | 1702 | spin_unlock(&client_lock); |
Benny Halevy | e10e0cf | 2009-04-03 08:28:38 +0300 | [diff] [blame] | 1703 | goto out; |
| 1704 | } |
| 1705 | |
| 1706 | unhash_session(ses); |
Benny Halevy | 9089f1b | 2010-05-12 00:12:26 +0300 | [diff] [blame] | 1707 | spin_unlock(&client_lock); |
Benny Halevy | e10e0cf | 2009-04-03 08:28:38 +0300 | [diff] [blame] | 1708 | |
Benny Halevy | ab707e15 | 2010-05-12 00:14:06 +0300 | [diff] [blame] | 1709 | nfs4_lock_state(); |
J. Bruce Fields | 84f5f7c | 2010-12-09 15:52:19 -0500 | [diff] [blame] | 1710 | nfsd4_probe_callback_sync(ses->se_client); |
Benny Halevy | ab707e15 | 2010-05-12 00:14:06 +0300 | [diff] [blame] | 1711 | nfs4_unlock_state(); |
J. Bruce Fields | 19cf5c0 | 2010-06-06 18:37:16 -0400 | [diff] [blame] | 1712 | |
| 1713 | nfsd4_del_conns(ses); |
| 1714 | |
Benny Halevy | e10e0cf | 2009-04-03 08:28:38 +0300 | [diff] [blame] | 1715 | nfsd4_put_session(ses); |
| 1716 | status = nfs_ok; |
| 1717 | out: |
| 1718 | dprintk("%s returns %d\n", __func__, ntohl(status)); |
| 1719 | return status; |
Andy Adamson | 069b6ad | 2009-04-03 08:27:58 +0300 | [diff] [blame] | 1720 | } |
| 1721 | |
J. Bruce Fields | a663bdd | 2010-10-21 17:17:31 -0400 | [diff] [blame] | 1722 | static struct nfsd4_conn *__nfsd4_find_conn(struct svc_xprt *xpt, struct nfsd4_session *s) |
J. Bruce Fields | 328ead2 | 2010-09-29 16:11:06 -0400 | [diff] [blame] | 1723 | { |
| 1724 | struct nfsd4_conn *c; |
| 1725 | |
| 1726 | list_for_each_entry(c, &s->se_conns, cn_persession) { |
J. Bruce Fields | a663bdd | 2010-10-21 17:17:31 -0400 | [diff] [blame] | 1727 | if (c->cn_xprt == xpt) { |
J. Bruce Fields | 328ead2 | 2010-09-29 16:11:06 -0400 | [diff] [blame] | 1728 | return c; |
| 1729 | } |
| 1730 | } |
| 1731 | return NULL; |
| 1732 | } |
| 1733 | |
J. Bruce Fields | a663bdd | 2010-10-21 17:17:31 -0400 | [diff] [blame] | 1734 | static void nfsd4_sequence_check_conn(struct nfsd4_conn *new, struct nfsd4_session *ses) |
J. Bruce Fields | 328ead2 | 2010-09-29 16:11:06 -0400 | [diff] [blame] | 1735 | { |
| 1736 | struct nfs4_client *clp = ses->se_client; |
J. Bruce Fields | a663bdd | 2010-10-21 17:17:31 -0400 | [diff] [blame] | 1737 | struct nfsd4_conn *c; |
J. Bruce Fields | 21b75b0 | 2010-10-26 10:07:17 -0400 | [diff] [blame] | 1738 | int ret; |
J. Bruce Fields | 328ead2 | 2010-09-29 16:11:06 -0400 | [diff] [blame] | 1739 | |
| 1740 | spin_lock(&clp->cl_lock); |
J. Bruce Fields | a663bdd | 2010-10-21 17:17:31 -0400 | [diff] [blame] | 1741 | c = __nfsd4_find_conn(new->cn_xprt, ses); |
J. Bruce Fields | 328ead2 | 2010-09-29 16:11:06 -0400 | [diff] [blame] | 1742 | if (c) { |
| 1743 | spin_unlock(&clp->cl_lock); |
| 1744 | free_conn(new); |
| 1745 | return; |
| 1746 | } |
| 1747 | __nfsd4_hash_conn(new, ses); |
| 1748 | spin_unlock(&clp->cl_lock); |
J. Bruce Fields | 21b75b0 | 2010-10-26 10:07:17 -0400 | [diff] [blame] | 1749 | ret = nfsd4_register_conn(new); |
| 1750 | if (ret) |
| 1751 | /* oops; xprt is already down: */ |
| 1752 | nfsd4_conn_lost(&new->cn_xpt_user); |
J. Bruce Fields | 328ead2 | 2010-09-29 16:11:06 -0400 | [diff] [blame] | 1753 | return; |
| 1754 | } |
| 1755 | |
Mi Jinlong | 868b89c | 2011-04-27 09:09:58 +0800 | [diff] [blame] | 1756 | static bool nfsd4_session_too_many_ops(struct svc_rqst *rqstp, struct nfsd4_session *session) |
| 1757 | { |
| 1758 | struct nfsd4_compoundargs *args = rqstp->rq_argp; |
| 1759 | |
| 1760 | return args->opcnt > session->se_fchannel.maxops; |
| 1761 | } |
| 1762 | |
Mi Jinlong | ae82a8d | 2011-07-14 14:56:02 +0800 | [diff] [blame] | 1763 | static bool nfsd4_request_too_big(struct svc_rqst *rqstp, |
| 1764 | struct nfsd4_session *session) |
| 1765 | { |
| 1766 | struct xdr_buf *xb = &rqstp->rq_arg; |
| 1767 | |
| 1768 | return xb->len > session->se_fchannel.maxreq_sz; |
| 1769 | } |
| 1770 | |
Andy Adamson | 069b6ad | 2009-04-03 08:27:58 +0300 | [diff] [blame] | 1771 | __be32 |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1772 | nfsd4_sequence(struct svc_rqst *rqstp, |
Andy Adamson | 069b6ad | 2009-04-03 08:27:58 +0300 | [diff] [blame] | 1773 | struct nfsd4_compound_state *cstate, |
| 1774 | struct nfsd4_sequence *seq) |
| 1775 | { |
Andy Adamson | f9bb94c4 | 2009-04-03 08:28:12 +0300 | [diff] [blame] | 1776 | struct nfsd4_compoundres *resp = rqstp->rq_resp; |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1777 | struct nfsd4_session *session; |
| 1778 | struct nfsd4_slot *slot; |
J. Bruce Fields | a663bdd | 2010-10-21 17:17:31 -0400 | [diff] [blame] | 1779 | struct nfsd4_conn *conn; |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1780 | int status; |
| 1781 | |
Andy Adamson | f9bb94c4 | 2009-04-03 08:28:12 +0300 | [diff] [blame] | 1782 | if (resp->opcnt != 1) |
| 1783 | return nfserr_sequence_pos; |
| 1784 | |
J. Bruce Fields | a663bdd | 2010-10-21 17:17:31 -0400 | [diff] [blame] | 1785 | /* |
| 1786 | * Will be either used or freed by nfsd4_sequence_check_conn |
| 1787 | * below. |
| 1788 | */ |
| 1789 | conn = alloc_conn(rqstp, NFS4_CDFC4_FORE); |
| 1790 | if (!conn) |
| 1791 | return nfserr_jukebox; |
| 1792 | |
Benny Halevy | 9089f1b | 2010-05-12 00:12:26 +0300 | [diff] [blame] | 1793 | spin_lock(&client_lock); |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1794 | status = nfserr_badsession; |
| 1795 | session = find_in_sessionid_hashtbl(&seq->sessionid); |
| 1796 | if (!session) |
| 1797 | goto out; |
| 1798 | |
Mi Jinlong | 868b89c | 2011-04-27 09:09:58 +0800 | [diff] [blame] | 1799 | status = nfserr_too_many_ops; |
| 1800 | if (nfsd4_session_too_many_ops(rqstp, session)) |
| 1801 | goto out; |
| 1802 | |
Mi Jinlong | ae82a8d | 2011-07-14 14:56:02 +0800 | [diff] [blame] | 1803 | status = nfserr_req_too_big; |
| 1804 | if (nfsd4_request_too_big(rqstp, session)) |
| 1805 | goto out; |
| 1806 | |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1807 | status = nfserr_badslot; |
Alexandros Batsakis | 6c18ba9 | 2009-06-16 04:19:13 +0300 | [diff] [blame] | 1808 | if (seq->slotid >= session->se_fchannel.maxreqs) |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1809 | goto out; |
| 1810 | |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 1811 | slot = session->se_slots[seq->slotid]; |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1812 | dprintk("%s: slotid %d\n", __func__, seq->slotid); |
| 1813 | |
Andy Adamson | a8dfdae | 2009-08-28 08:45:02 -0400 | [diff] [blame] | 1814 | /* We do not negotiate the number of slots yet, so set the |
| 1815 | * maxslots to the session maxreqs which is used to encode |
| 1816 | * sr_highest_slotid and the sr_target_slot id to maxslots */ |
| 1817 | seq->maxslots = session->se_fchannel.maxreqs; |
| 1818 | |
Andy Adamson | 88e588d | 2009-07-23 19:02:15 -0400 | [diff] [blame] | 1819 | status = check_slot_seqid(seq->seqid, slot->sl_seqid, slot->sl_inuse); |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1820 | if (status == nfserr_replay_cache) { |
| 1821 | cstate->slot = slot; |
| 1822 | cstate->session = session; |
Andy Adamson | da3846a | 2009-04-03 08:28:22 +0300 | [diff] [blame] | 1823 | /* Return the cached reply status and set cstate->status |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 1824 | * for nfsd4_proc_compound processing */ |
Andy Adamson | bf864a3 | 2009-04-03 08:28:35 +0300 | [diff] [blame] | 1825 | status = nfsd4_replay_cache_entry(resp, seq); |
Andy Adamson | da3846a | 2009-04-03 08:28:22 +0300 | [diff] [blame] | 1826 | cstate->status = nfserr_replay_cache; |
Benny Halevy | aaf84eb | 2009-08-20 03:21:56 +0300 | [diff] [blame] | 1827 | goto out; |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1828 | } |
| 1829 | if (status) |
| 1830 | goto out; |
| 1831 | |
J. Bruce Fields | a663bdd | 2010-10-21 17:17:31 -0400 | [diff] [blame] | 1832 | nfsd4_sequence_check_conn(conn, session); |
| 1833 | conn = NULL; |
J. Bruce Fields | 328ead2 | 2010-09-29 16:11:06 -0400 | [diff] [blame] | 1834 | |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1835 | /* Success! bump slot seqid */ |
| 1836 | slot->sl_inuse = true; |
| 1837 | slot->sl_seqid = seq->seqid; |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 1838 | slot->sl_cachethis = seq->cachethis; |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1839 | |
| 1840 | cstate->slot = slot; |
| 1841 | cstate->session = session; |
| 1842 | |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1843 | out: |
J. Bruce Fields | 26c0c75 | 2010-04-24 15:35:43 -0400 | [diff] [blame] | 1844 | /* Hold a session reference until done processing the compound. */ |
Benny Halevy | aaf84eb | 2009-08-20 03:21:56 +0300 | [diff] [blame] | 1845 | if (cstate->session) { |
J. Bruce Fields | 0d7bb71 | 2010-11-18 08:30:33 -0500 | [diff] [blame] | 1846 | struct nfs4_client *clp = session->se_client; |
| 1847 | |
Benny Halevy | 36acb66 | 2010-05-12 00:13:04 +0300 | [diff] [blame] | 1848 | nfsd4_get_session(cstate->session); |
J. Bruce Fields | 0d7bb71 | 2010-11-18 08:30:33 -0500 | [diff] [blame] | 1849 | atomic_inc(&clp->cl_refcount); |
| 1850 | if (clp->cl_cb_state == NFSD4_CB_DOWN) |
| 1851 | seq->status_flags |= SEQ4_STATUS_CB_PATH_DOWN; |
Benny Halevy | aaf84eb | 2009-08-20 03:21:56 +0300 | [diff] [blame] | 1852 | } |
J. Bruce Fields | a663bdd | 2010-10-21 17:17:31 -0400 | [diff] [blame] | 1853 | kfree(conn); |
Benny Halevy | 36acb66 | 2010-05-12 00:13:04 +0300 | [diff] [blame] | 1854 | spin_unlock(&client_lock); |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1855 | dprintk("%s: return %d\n", __func__, ntohl(status)); |
| 1856 | return status; |
Andy Adamson | 069b6ad | 2009-04-03 08:27:58 +0300 | [diff] [blame] | 1857 | } |
| 1858 | |
| 1859 | __be32 |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 1860 | nfsd4_reclaim_complete(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_reclaim_complete *rc) |
| 1861 | { |
Mi Jinlong | bcecf1c | 2011-04-27 09:14:30 +0800 | [diff] [blame] | 1862 | int status = 0; |
| 1863 | |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 1864 | if (rc->rca_one_fs) { |
| 1865 | if (!cstate->current_fh.fh_dentry) |
| 1866 | return nfserr_nofilehandle; |
| 1867 | /* |
| 1868 | * We don't take advantage of the rca_one_fs case. |
| 1869 | * That's OK, it's optional, we can safely ignore it. |
| 1870 | */ |
| 1871 | return nfs_ok; |
| 1872 | } |
Mi Jinlong | bcecf1c | 2011-04-27 09:14:30 +0800 | [diff] [blame] | 1873 | |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 1874 | nfs4_lock_state(); |
Mi Jinlong | bcecf1c | 2011-04-27 09:14:30 +0800 | [diff] [blame] | 1875 | status = nfserr_complete_already; |
| 1876 | if (cstate->session->se_client->cl_firststate) |
| 1877 | goto out; |
| 1878 | |
| 1879 | status = nfserr_stale_clientid; |
| 1880 | if (is_client_expired(cstate->session->se_client)) |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 1881 | /* |
| 1882 | * The following error isn't really legal. |
| 1883 | * But we only get here if the client just explicitly |
| 1884 | * destroyed the client. Surely it no longer cares what |
| 1885 | * error it gets back on an operation for the dead |
| 1886 | * client. |
| 1887 | */ |
Mi Jinlong | bcecf1c | 2011-04-27 09:14:30 +0800 | [diff] [blame] | 1888 | goto out; |
| 1889 | |
| 1890 | status = nfs_ok; |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 1891 | nfsd4_create_clid_dir(cstate->session->se_client); |
Mi Jinlong | bcecf1c | 2011-04-27 09:14:30 +0800 | [diff] [blame] | 1892 | out: |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 1893 | nfs4_unlock_state(); |
Mi Jinlong | bcecf1c | 2011-04-27 09:14:30 +0800 | [diff] [blame] | 1894 | return status; |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | __be32 |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 1898 | nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
| 1899 | struct nfsd4_setclientid *setclid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | struct xdr_netobj clname = { |
| 1902 | .len = setclid->se_namelen, |
| 1903 | .data = setclid->se_name, |
| 1904 | }; |
| 1905 | nfs4_verifier clverifier = setclid->se_verf; |
| 1906 | unsigned int strhashval; |
NeilBrown | 28ce605 | 2005-06-23 22:03:56 -0700 | [diff] [blame] | 1907 | struct nfs4_client *conf, *unconf, *new; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1908 | __be32 status; |
NeilBrown | a55370a | 2005-06-23 22:03:52 -0700 | [diff] [blame] | 1909 | char dname[HEXDIR_LEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | if (!check_name(clname)) |
Neil Brown | 73aea4e | 2005-09-13 01:25:39 -0700 | [diff] [blame] | 1912 | return nfserr_inval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | |
NeilBrown | a55370a | 2005-06-23 22:03:52 -0700 | [diff] [blame] | 1914 | status = nfs4_make_rec_clidname(dname, &clname); |
| 1915 | if (status) |
Neil Brown | 73aea4e | 2005-09-13 01:25:39 -0700 | [diff] [blame] | 1916 | return status; |
NeilBrown | a55370a | 2005-06-23 22:03:52 -0700 | [diff] [blame] | 1917 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | /* |
| 1919 | * XXX The Duplicate Request Cache (DRC) has been checked (??) |
| 1920 | * We get here on a DRC miss. |
| 1921 | */ |
| 1922 | |
NeilBrown | a55370a | 2005-06-23 22:03:52 -0700 | [diff] [blame] | 1923 | strhashval = clientstr_hashval(dname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | nfs4_lock_state(); |
J. Bruce Fields | e203d50 | 2010-11-24 17:30:54 -0500 | [diff] [blame] | 1926 | conf = find_confirmed_client_by_str(dname, strhashval); |
NeilBrown | 28ce605 | 2005-06-23 22:03:56 -0700 | [diff] [blame] | 1927 | if (conf) { |
J. Bruce Fields | a186e76 | 2007-11-20 16:11:27 -0500 | [diff] [blame] | 1928 | /* RFC 3530 14.2.33 CASE 0: */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | status = nfserr_clid_inuse; |
J. Bruce Fields | e203d50 | 2010-11-24 17:30:54 -0500 | [diff] [blame] | 1930 | if (clp_used_exchangeid(conf)) |
| 1931 | goto out; |
J. Bruce Fields | 026722c | 2009-03-18 15:06:26 -0400 | [diff] [blame] | 1932 | if (!same_creds(&conf->cl_cred, &rqstp->rq_cred)) { |
Jeff Layton | 363168b | 2009-08-14 12:57:56 -0400 | [diff] [blame] | 1933 | char addr_str[INET6_ADDRSTRLEN]; |
| 1934 | rpc_ntop((struct sockaddr *) &conf->cl_addr, addr_str, |
| 1935 | sizeof(addr_str)); |
| 1936 | dprintk("NFSD: setclientid: string in use by client " |
| 1937 | "at %s\n", addr_str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | goto out; |
| 1939 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | } |
J. Bruce Fields | a186e76 | 2007-11-20 16:11:27 -0500 | [diff] [blame] | 1941 | /* |
| 1942 | * section 14.2.33 of RFC 3530 (under the heading "IMPLEMENTATION") |
| 1943 | * has a description of SETCLIENTID request processing consisting |
| 1944 | * of 5 bullet points, labeled as CASE0 - CASE4 below. |
| 1945 | */ |
J. Bruce Fields | e203d50 | 2010-11-24 17:30:54 -0500 | [diff] [blame] | 1946 | unconf = find_unconfirmed_client_by_str(dname, strhashval); |
J. Bruce Fields | 3e77246 | 2011-08-10 19:07:33 -0400 | [diff] [blame^] | 1947 | status = nfserr_jukebox; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | if (!conf) { |
J. Bruce Fields | a186e76 | 2007-11-20 16:11:27 -0500 | [diff] [blame] | 1949 | /* |
| 1950 | * RFC 3530 14.2.33 CASE 4: |
| 1951 | * placed first, because it is the normal case |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | */ |
| 1953 | if (unconf) |
| 1954 | expire_client(unconf); |
Ricardo Labiaga | b09333c | 2009-09-10 12:27:34 +0300 | [diff] [blame] | 1955 | new = create_client(clname, dname, rqstp, &clverifier); |
NeilBrown | a55370a | 2005-06-23 22:03:52 -0700 | [diff] [blame] | 1956 | if (new == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | gen_clid(new); |
J. Bruce Fields | 599e0a2 | 2007-07-26 17:04:54 -0400 | [diff] [blame] | 1959 | } else if (same_verf(&conf->cl_verifier, &clverifier)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | /* |
J. Bruce Fields | a186e76 | 2007-11-20 16:11:27 -0500 | [diff] [blame] | 1961 | * RFC 3530 14.2.33 CASE 1: |
| 1962 | * probable callback update |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | */ |
NeilBrown | 31f4a6c | 2005-06-23 22:04:06 -0700 | [diff] [blame] | 1964 | if (unconf) { |
| 1965 | /* Note this is removing unconfirmed {*x***}, |
| 1966 | * which is stronger than RFC recommended {vxc**}. |
| 1967 | * This has the advantage that there is at most |
| 1968 | * one {*x***} in either list at any time. |
| 1969 | */ |
| 1970 | expire_client(unconf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | } |
Ricardo Labiaga | b09333c | 2009-09-10 12:27:34 +0300 | [diff] [blame] | 1972 | new = create_client(clname, dname, rqstp, &clverifier); |
NeilBrown | a55370a | 2005-06-23 22:03:52 -0700 | [diff] [blame] | 1973 | if (new == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | copy_clid(new, conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | } else if (!unconf) { |
| 1977 | /* |
J. Bruce Fields | a186e76 | 2007-11-20 16:11:27 -0500 | [diff] [blame] | 1978 | * RFC 3530 14.2.33 CASE 2: |
| 1979 | * probable client reboot; state will be removed if |
| 1980 | * confirmed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | */ |
Ricardo Labiaga | b09333c | 2009-09-10 12:27:34 +0300 | [diff] [blame] | 1982 | new = create_client(clname, dname, rqstp, &clverifier); |
NeilBrown | a55370a | 2005-06-23 22:03:52 -0700 | [diff] [blame] | 1983 | if (new == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | gen_clid(new); |
J. Bruce Fields | 49ba878 | 2007-11-19 19:09:50 -0500 | [diff] [blame] | 1986 | } else { |
J. Bruce Fields | a186e76 | 2007-11-20 16:11:27 -0500 | [diff] [blame] | 1987 | /* |
| 1988 | * RFC 3530 14.2.33 CASE 3: |
| 1989 | * probable client reboot; state will be removed if |
| 1990 | * confirmed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | */ |
| 1992 | expire_client(unconf); |
Ricardo Labiaga | b09333c | 2009-09-10 12:27:34 +0300 | [diff] [blame] | 1993 | new = create_client(clname, dname, rqstp, &clverifier); |
NeilBrown | a55370a | 2005-06-23 22:03:52 -0700 | [diff] [blame] | 1994 | if (new == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | gen_clid(new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1997 | } |
J. Bruce Fields | 8323c3b | 2010-10-19 19:36:51 -0400 | [diff] [blame] | 1998 | /* |
| 1999 | * XXX: we should probably set this at creation time, and check |
| 2000 | * for consistent minorversion use throughout: |
| 2001 | */ |
| 2002 | new->cl_minorversion = 0; |
Takuma Umeya | 6f3d772 | 2010-12-15 14:09:01 +0900 | [diff] [blame] | 2003 | gen_callback(new, setclid, rqstp); |
J. Bruce Fields | c175b83 | 2007-08-09 18:34:32 -0400 | [diff] [blame] | 2004 | add_to_unconfirmed(new, strhashval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | setclid->se_clientid.cl_boot = new->cl_clientid.cl_boot; |
| 2006 | setclid->se_clientid.cl_id = new->cl_clientid.cl_id; |
| 2007 | memcpy(setclid->se_confirm.data, new->cl_confirm.data, sizeof(setclid->se_confirm.data)); |
| 2008 | status = nfs_ok; |
| 2009 | out: |
| 2010 | nfs4_unlock_state(); |
| 2011 | return status; |
| 2012 | } |
| 2013 | |
| 2014 | |
| 2015 | /* |
J. Bruce Fields | a186e76 | 2007-11-20 16:11:27 -0500 | [diff] [blame] | 2016 | * Section 14.2.34 of RFC 3530 (under the heading "IMPLEMENTATION") has |
| 2017 | * a description of SETCLIENTID_CONFIRM request processing consisting of 4 |
| 2018 | * bullets, labeled as CASE1 - CASE4 below. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2020 | __be32 |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2021 | nfsd4_setclientid_confirm(struct svc_rqst *rqstp, |
| 2022 | struct nfsd4_compound_state *cstate, |
| 2023 | struct nfsd4_setclientid_confirm *setclientid_confirm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | { |
Jeff Layton | 363168b | 2009-08-14 12:57:56 -0400 | [diff] [blame] | 2025 | struct sockaddr *sa = svc_addr(rqstp); |
NeilBrown | 21ab45a | 2005-06-23 22:04:14 -0700 | [diff] [blame] | 2026 | struct nfs4_client *conf, *unconf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | nfs4_verifier confirm = setclientid_confirm->sc_confirm; |
| 2028 | clientid_t * clid = &setclientid_confirm->sc_clientid; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2029 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | |
| 2031 | if (STALE_CLIENTID(clid)) |
| 2032 | return nfserr_stale_clientid; |
| 2033 | /* |
| 2034 | * XXX The Duplicate Request Cache (DRC) has been checked (??) |
| 2035 | * We get here on a DRC miss. |
| 2036 | */ |
| 2037 | |
| 2038 | nfs4_lock_state(); |
NeilBrown | 21ab45a | 2005-06-23 22:04:14 -0700 | [diff] [blame] | 2039 | |
| 2040 | conf = find_confirmed_client(clid); |
| 2041 | unconf = find_unconfirmed_client(clid); |
| 2042 | |
| 2043 | status = nfserr_clid_inuse; |
Jeff Layton | 363168b | 2009-08-14 12:57:56 -0400 | [diff] [blame] | 2044 | if (conf && !rpc_cmp_addr((struct sockaddr *) &conf->cl_addr, sa)) |
NeilBrown | 21ab45a | 2005-06-23 22:04:14 -0700 | [diff] [blame] | 2045 | goto out; |
Jeff Layton | 363168b | 2009-08-14 12:57:56 -0400 | [diff] [blame] | 2046 | if (unconf && !rpc_cmp_addr((struct sockaddr *) &unconf->cl_addr, sa)) |
NeilBrown | 21ab45a | 2005-06-23 22:04:14 -0700 | [diff] [blame] | 2047 | goto out; |
| 2048 | |
J. Bruce Fields | a186e76 | 2007-11-20 16:11:27 -0500 | [diff] [blame] | 2049 | /* |
| 2050 | * section 14.2.34 of RFC 3530 has a description of |
| 2051 | * SETCLIENTID_CONFIRM request processing consisting |
| 2052 | * of 4 bullet points, labeled as CASE1 - CASE4 below. |
| 2053 | */ |
J. Bruce Fields | 366e0c1 | 2007-11-20 15:54:10 -0500 | [diff] [blame] | 2054 | if (conf && unconf && same_verf(&confirm, &unconf->cl_confirm)) { |
J. Bruce Fields | a186e76 | 2007-11-20 16:11:27 -0500 | [diff] [blame] | 2055 | /* |
| 2056 | * RFC 3530 14.2.34 CASE 1: |
| 2057 | * callback update |
| 2058 | */ |
J. Bruce Fields | 599e0a2 | 2007-07-26 17:04:54 -0400 | [diff] [blame] | 2059 | if (!same_creds(&conf->cl_cred, &unconf->cl_cred)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | status = nfserr_clid_inuse; |
| 2061 | else { |
J. Bruce Fields | 5a3c9d7 | 2010-10-19 17:56:52 -0400 | [diff] [blame] | 2062 | nfsd4_change_callback(conf, &unconf->cl_cb_conn); |
| 2063 | nfsd4_probe_callback(conf); |
NeilBrown | 1a69c17 | 2005-06-23 22:04:08 -0700 | [diff] [blame] | 2064 | expire_client(unconf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | status = nfs_ok; |
NeilBrown | 1a69c17 | 2005-06-23 22:04:08 -0700 | [diff] [blame] | 2066 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | } |
J. Bruce Fields | f3aba4e | 2007-11-20 16:52:07 -0500 | [diff] [blame] | 2068 | } else if (conf && !unconf) { |
J. Bruce Fields | a186e76 | 2007-11-20 16:11:27 -0500 | [diff] [blame] | 2069 | /* |
| 2070 | * RFC 3530 14.2.34 CASE 2: |
| 2071 | * probable retransmitted request; play it safe and |
| 2072 | * do nothing. |
NeilBrown | 7c79f73 | 2005-06-23 22:04:13 -0700 | [diff] [blame] | 2073 | */ |
J. Bruce Fields | 599e0a2 | 2007-07-26 17:04:54 -0400 | [diff] [blame] | 2074 | if (!same_creds(&conf->cl_cred, &rqstp->rq_cred)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | status = nfserr_clid_inuse; |
NeilBrown | 21ab45a | 2005-06-23 22:04:14 -0700 | [diff] [blame] | 2076 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2077 | status = nfs_ok; |
NeilBrown | 7c79f73 | 2005-06-23 22:04:13 -0700 | [diff] [blame] | 2078 | } else if (!conf && unconf |
J. Bruce Fields | 599e0a2 | 2007-07-26 17:04:54 -0400 | [diff] [blame] | 2079 | && same_verf(&unconf->cl_confirm, &confirm)) { |
J. Bruce Fields | a186e76 | 2007-11-20 16:11:27 -0500 | [diff] [blame] | 2080 | /* |
| 2081 | * RFC 3530 14.2.34 CASE 3: |
| 2082 | * Normal case; new or rebooted client: |
NeilBrown | 7c79f73 | 2005-06-23 22:04:13 -0700 | [diff] [blame] | 2083 | */ |
J. Bruce Fields | 599e0a2 | 2007-07-26 17:04:54 -0400 | [diff] [blame] | 2084 | if (!same_creds(&unconf->cl_cred, &rqstp->rq_cred)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | status = nfserr_clid_inuse; |
| 2086 | } else { |
NeilBrown | 1a69c17 | 2005-06-23 22:04:08 -0700 | [diff] [blame] | 2087 | unsigned int hash = |
| 2088 | clientstr_hashval(unconf->cl_recdir); |
| 2089 | conf = find_confirmed_client_by_str(unconf->cl_recdir, |
J. Bruce Fields | e203d50 | 2010-11-24 17:30:54 -0500 | [diff] [blame] | 2090 | hash); |
NeilBrown | 1a69c17 | 2005-06-23 22:04:08 -0700 | [diff] [blame] | 2091 | if (conf) { |
NeilBrown | c7b9a45 | 2005-06-23 22:04:30 -0700 | [diff] [blame] | 2092 | nfsd4_remove_clid_dir(conf); |
NeilBrown | 1a69c17 | 2005-06-23 22:04:08 -0700 | [diff] [blame] | 2093 | expire_client(conf); |
| 2094 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | move_to_confirmed(unconf); |
NeilBrown | 21ab45a | 2005-06-23 22:04:14 -0700 | [diff] [blame] | 2096 | conf = unconf; |
J. Bruce Fields | 5a3c9d7 | 2010-10-19 17:56:52 -0400 | [diff] [blame] | 2097 | nfsd4_probe_callback(conf); |
NeilBrown | 1a69c17 | 2005-06-23 22:04:08 -0700 | [diff] [blame] | 2098 | status = nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | } |
J. Bruce Fields | 599e0a2 | 2007-07-26 17:04:54 -0400 | [diff] [blame] | 2100 | } else if ((!conf || (conf && !same_verf(&conf->cl_confirm, &confirm))) |
| 2101 | && (!unconf || (unconf && !same_verf(&unconf->cl_confirm, |
NeilBrown | 7c79f73 | 2005-06-23 22:04:13 -0700 | [diff] [blame] | 2102 | &confirm)))) { |
J. Bruce Fields | a186e76 | 2007-11-20 16:11:27 -0500 | [diff] [blame] | 2103 | /* |
| 2104 | * RFC 3530 14.2.34 CASE 4: |
| 2105 | * Client probably hasn't noticed that we rebooted yet. |
NeilBrown | 7c79f73 | 2005-06-23 22:04:13 -0700 | [diff] [blame] | 2106 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | status = nfserr_stale_clientid; |
NeilBrown | 7c79f73 | 2005-06-23 22:04:13 -0700 | [diff] [blame] | 2108 | } else { |
NeilBrown | 08e8987 | 2005-06-23 22:04:11 -0700 | [diff] [blame] | 2109 | /* check that we have hit one of the cases...*/ |
| 2110 | status = nfserr_clid_inuse; |
| 2111 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | nfs4_unlock_state(); |
| 2114 | return status; |
| 2115 | } |
| 2116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | /* OPEN Share state helper functions */ |
| 2118 | static inline struct nfs4_file * |
| 2119 | alloc_init_file(struct inode *ino) |
| 2120 | { |
| 2121 | struct nfs4_file *fp; |
| 2122 | unsigned int hashval = file_hashval(ino); |
| 2123 | |
NeilBrown | e60d439 | 2005-06-23 22:03:01 -0700 | [diff] [blame] | 2124 | fp = kmem_cache_alloc(file_slab, GFP_KERNEL); |
| 2125 | if (fp) { |
J. Bruce Fields | 8b671b8 | 2009-02-22 14:51:34 -0800 | [diff] [blame] | 2126 | atomic_set(&fp->fi_ref, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | INIT_LIST_HEAD(&fp->fi_hash); |
NeilBrown | 8beefa2 | 2005-06-23 22:03:08 -0700 | [diff] [blame] | 2128 | INIT_LIST_HEAD(&fp->fi_stateids); |
| 2129 | INIT_LIST_HEAD(&fp->fi_delegations); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | fp->fi_inode = igrab(ino); |
| 2131 | fp->fi_id = current_fileid++; |
Meelap Shah | 47f9940 | 2007-07-17 04:04:40 -0700 | [diff] [blame] | 2132 | fp->fi_had_conflict = false; |
J. Bruce Fields | acfdf5c | 2011-01-31 19:20:39 -0500 | [diff] [blame] | 2133 | fp->fi_lease = NULL; |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 2134 | memset(fp->fi_fds, 0, sizeof(fp->fi_fds)); |
| 2135 | memset(fp->fi_access, 0, sizeof(fp->fi_access)); |
Pavel Emelyanov | 47cee54 | 2010-05-17 20:00:37 +0400 | [diff] [blame] | 2136 | spin_lock(&recall_lock); |
| 2137 | list_add(&fp->fi_hash, &file_hashtbl[hashval]); |
| 2138 | spin_unlock(&recall_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | return fp; |
| 2140 | } |
| 2141 | return NULL; |
| 2142 | } |
| 2143 | |
| 2144 | static void |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 2145 | nfsd4_free_slab(struct kmem_cache **slab) |
NeilBrown | e60d439 | 2005-06-23 22:03:01 -0700 | [diff] [blame] | 2146 | { |
NeilBrown | e60d439 | 2005-06-23 22:03:01 -0700 | [diff] [blame] | 2147 | if (*slab == NULL) |
| 2148 | return; |
Alexey Dobriyan | 1a1d92c | 2006-09-27 01:49:40 -0700 | [diff] [blame] | 2149 | kmem_cache_destroy(*slab); |
NeilBrown | e60d439 | 2005-06-23 22:03:01 -0700 | [diff] [blame] | 2150 | *slab = NULL; |
NeilBrown | e60d439 | 2005-06-23 22:03:01 -0700 | [diff] [blame] | 2151 | } |
| 2152 | |
J. Bruce Fields | e8ff2a8 | 2007-08-01 15:30:59 -0400 | [diff] [blame] | 2153 | void |
NeilBrown | e60d439 | 2005-06-23 22:03:01 -0700 | [diff] [blame] | 2154 | nfsd4_free_slabs(void) |
| 2155 | { |
| 2156 | nfsd4_free_slab(&stateowner_slab); |
| 2157 | nfsd4_free_slab(&file_slab); |
NeilBrown | 5ac049a | 2005-06-23 22:03:03 -0700 | [diff] [blame] | 2158 | nfsd4_free_slab(&stateid_slab); |
NeilBrown | 5b2d21c | 2005-06-23 22:03:04 -0700 | [diff] [blame] | 2159 | nfsd4_free_slab(&deleg_slab); |
NeilBrown | e60d439 | 2005-06-23 22:03:01 -0700 | [diff] [blame] | 2160 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | |
| 2162 | static int |
| 2163 | nfsd4_init_slabs(void) |
| 2164 | { |
| 2165 | stateowner_slab = kmem_cache_create("nfsd4_stateowners", |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 2166 | sizeof(struct nfs4_stateowner), 0, 0, NULL); |
NeilBrown | e60d439 | 2005-06-23 22:03:01 -0700 | [diff] [blame] | 2167 | if (stateowner_slab == NULL) |
| 2168 | goto out_nomem; |
| 2169 | file_slab = kmem_cache_create("nfsd4_files", |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 2170 | sizeof(struct nfs4_file), 0, 0, NULL); |
NeilBrown | e60d439 | 2005-06-23 22:03:01 -0700 | [diff] [blame] | 2171 | if (file_slab == NULL) |
| 2172 | goto out_nomem; |
NeilBrown | 5ac049a | 2005-06-23 22:03:03 -0700 | [diff] [blame] | 2173 | stateid_slab = kmem_cache_create("nfsd4_stateids", |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 2174 | sizeof(struct nfs4_stateid), 0, 0, NULL); |
NeilBrown | 5ac049a | 2005-06-23 22:03:03 -0700 | [diff] [blame] | 2175 | if (stateid_slab == NULL) |
| 2176 | goto out_nomem; |
NeilBrown | 5b2d21c | 2005-06-23 22:03:04 -0700 | [diff] [blame] | 2177 | deleg_slab = kmem_cache_create("nfsd4_delegations", |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 2178 | sizeof(struct nfs4_delegation), 0, 0, NULL); |
NeilBrown | 5b2d21c | 2005-06-23 22:03:04 -0700 | [diff] [blame] | 2179 | if (deleg_slab == NULL) |
| 2180 | goto out_nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | return 0; |
NeilBrown | e60d439 | 2005-06-23 22:03:01 -0700 | [diff] [blame] | 2182 | out_nomem: |
| 2183 | nfsd4_free_slabs(); |
| 2184 | dprintk("nfsd4: out of memory while initializing nfsv4\n"); |
| 2185 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | } |
| 2187 | |
| 2188 | void |
| 2189 | nfs4_free_stateowner(struct kref *kref) |
| 2190 | { |
| 2191 | struct nfs4_stateowner *sop = |
| 2192 | container_of(kref, struct nfs4_stateowner, so_ref); |
| 2193 | kfree(sop->so_owner.data); |
| 2194 | kmem_cache_free(stateowner_slab, sop); |
| 2195 | } |
| 2196 | |
| 2197 | static inline struct nfs4_stateowner * |
| 2198 | alloc_stateowner(struct xdr_netobj *owner) |
| 2199 | { |
| 2200 | struct nfs4_stateowner *sop; |
| 2201 | |
| 2202 | if ((sop = kmem_cache_alloc(stateowner_slab, GFP_KERNEL))) { |
| 2203 | if ((sop->so_owner.data = kmalloc(owner->len, GFP_KERNEL))) { |
| 2204 | memcpy(sop->so_owner.data, owner->data, owner->len); |
| 2205 | sop->so_owner.len = owner->len; |
| 2206 | kref_init(&sop->so_ref); |
| 2207 | return sop; |
| 2208 | } |
| 2209 | kmem_cache_free(stateowner_slab, sop); |
| 2210 | } |
| 2211 | return NULL; |
| 2212 | } |
| 2213 | |
| 2214 | static struct nfs4_stateowner * |
| 2215 | alloc_init_open_stateowner(unsigned int strhashval, struct nfs4_client *clp, struct nfsd4_open *open) { |
| 2216 | struct nfs4_stateowner *sop; |
| 2217 | struct nfs4_replay *rp; |
| 2218 | unsigned int idhashval; |
| 2219 | |
| 2220 | if (!(sop = alloc_stateowner(&open->op_owner))) |
| 2221 | return NULL; |
| 2222 | idhashval = ownerid_hashval(current_ownerid); |
| 2223 | INIT_LIST_HEAD(&sop->so_idhash); |
| 2224 | INIT_LIST_HEAD(&sop->so_strhash); |
| 2225 | INIT_LIST_HEAD(&sop->so_perclient); |
NeilBrown | ea1da63 | 2005-06-23 22:04:17 -0700 | [diff] [blame] | 2226 | INIT_LIST_HEAD(&sop->so_stateids); |
| 2227 | INIT_LIST_HEAD(&sop->so_perstateid); /* not used */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | INIT_LIST_HEAD(&sop->so_close_lru); |
| 2229 | sop->so_time = 0; |
| 2230 | list_add(&sop->so_idhash, &ownerid_hashtbl[idhashval]); |
| 2231 | list_add(&sop->so_strhash, &ownerstr_hashtbl[strhashval]); |
NeilBrown | ea1da63 | 2005-06-23 22:04:17 -0700 | [diff] [blame] | 2232 | list_add(&sop->so_perclient, &clp->cl_openowners); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2233 | sop->so_is_open_owner = 1; |
| 2234 | sop->so_id = current_ownerid++; |
| 2235 | sop->so_client = clp; |
| 2236 | sop->so_seqid = open->op_seqid; |
| 2237 | sop->so_confirmed = 0; |
| 2238 | rp = &sop->so_replay; |
Al Viro | de1ae28 | 2006-01-18 17:43:47 -0800 | [diff] [blame] | 2239 | rp->rp_status = nfserr_serverfault; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2240 | rp->rp_buflen = 0; |
| 2241 | rp->rp_buf = rp->rp_ibuf; |
| 2242 | return sop; |
| 2243 | } |
| 2244 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | static inline void |
| 2246 | init_stateid(struct nfs4_stateid *stp, struct nfs4_file *fp, struct nfsd4_open *open) { |
| 2247 | struct nfs4_stateowner *sop = open->op_stateowner; |
| 2248 | unsigned int hashval = stateid_hashval(sop->so_id, fp->fi_id); |
| 2249 | |
| 2250 | INIT_LIST_HEAD(&stp->st_hash); |
NeilBrown | ea1da63 | 2005-06-23 22:04:17 -0700 | [diff] [blame] | 2251 | INIT_LIST_HEAD(&stp->st_perstateowner); |
| 2252 | INIT_LIST_HEAD(&stp->st_lockowners); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | INIT_LIST_HEAD(&stp->st_perfile); |
| 2254 | list_add(&stp->st_hash, &stateid_hashtbl[hashval]); |
NeilBrown | ea1da63 | 2005-06-23 22:04:17 -0700 | [diff] [blame] | 2255 | list_add(&stp->st_perstateowner, &sop->so_stateids); |
NeilBrown | 8beefa2 | 2005-06-23 22:03:08 -0700 | [diff] [blame] | 2256 | list_add(&stp->st_perfile, &fp->fi_stateids); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2257 | stp->st_stateowner = sop; |
NeilBrown | 13cd218 | 2005-06-23 22:03:10 -0700 | [diff] [blame] | 2258 | get_nfs4_file(fp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | stp->st_file = fp; |
J. Bruce Fields | e4e83ea | 2010-04-22 16:21:39 -0400 | [diff] [blame] | 2260 | stp->st_stateid.si_boot = boot_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2261 | stp->st_stateid.si_stateownerid = sop->so_id; |
| 2262 | stp->st_stateid.si_fileid = fp->fi_id; |
| 2263 | stp->st_stateid.si_generation = 0; |
| 2264 | stp->st_access_bmap = 0; |
| 2265 | stp->st_deny_bmap = 0; |
Andy Adamson | 84459a1 | 2009-04-03 08:28:56 +0300 | [diff] [blame] | 2266 | __set_bit(open->op_share_access & ~NFS4_SHARE_WANT_MASK, |
| 2267 | &stp->st_access_bmap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | __set_bit(open->op_share_deny, &stp->st_deny_bmap); |
NeilBrown | 4c4cd22 | 2005-07-07 17:59:27 -0700 | [diff] [blame] | 2269 | stp->st_openstp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2270 | } |
| 2271 | |
| 2272 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | move_to_close_lru(struct nfs4_stateowner *sop) |
| 2274 | { |
| 2275 | dprintk("NFSD: move_to_close_lru nfs4_stateowner %p\n", sop); |
| 2276 | |
NeilBrown | 358dd55 | 2006-04-10 22:55:42 -0700 | [diff] [blame] | 2277 | list_move_tail(&sop->so_close_lru, &close_lru); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | sop->so_time = get_seconds(); |
| 2279 | } |
| 2280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2281 | static int |
J. Bruce Fields | 599e0a2 | 2007-07-26 17:04:54 -0400 | [diff] [blame] | 2282 | same_owner_str(struct nfs4_stateowner *sop, struct xdr_netobj *owner, |
| 2283 | clientid_t *clid) |
| 2284 | { |
| 2285 | return (sop->so_owner.len == owner->len) && |
| 2286 | 0 == memcmp(sop->so_owner.data, owner->data, owner->len) && |
| 2287 | (sop->so_client->cl_clientid.cl_id == clid->cl_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2288 | } |
| 2289 | |
| 2290 | static struct nfs4_stateowner * |
| 2291 | find_openstateowner_str(unsigned int hashval, struct nfsd4_open *open) |
| 2292 | { |
| 2293 | struct nfs4_stateowner *so = NULL; |
| 2294 | |
| 2295 | list_for_each_entry(so, &ownerstr_hashtbl[hashval], so_strhash) { |
J. Bruce Fields | 599e0a2 | 2007-07-26 17:04:54 -0400 | [diff] [blame] | 2296 | if (same_owner_str(so, &open->op_owner, &open->op_clientid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | return so; |
| 2298 | } |
| 2299 | return NULL; |
| 2300 | } |
| 2301 | |
| 2302 | /* search file_hashtbl[] for file */ |
| 2303 | static struct nfs4_file * |
| 2304 | find_file(struct inode *ino) |
| 2305 | { |
| 2306 | unsigned int hashval = file_hashval(ino); |
| 2307 | struct nfs4_file *fp; |
| 2308 | |
J. Bruce Fields | 8b671b8 | 2009-02-22 14:51:34 -0800 | [diff] [blame] | 2309 | spin_lock(&recall_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2310 | list_for_each_entry(fp, &file_hashtbl[hashval], fi_hash) { |
NeilBrown | 13cd218 | 2005-06-23 22:03:10 -0700 | [diff] [blame] | 2311 | if (fp->fi_inode == ino) { |
| 2312 | get_nfs4_file(fp); |
J. Bruce Fields | 8b671b8 | 2009-02-22 14:51:34 -0800 | [diff] [blame] | 2313 | spin_unlock(&recall_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | return fp; |
NeilBrown | 13cd218 | 2005-06-23 22:03:10 -0700 | [diff] [blame] | 2315 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | } |
J. Bruce Fields | 8b671b8 | 2009-02-22 14:51:34 -0800 | [diff] [blame] | 2317 | spin_unlock(&recall_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | return NULL; |
| 2319 | } |
| 2320 | |
Andy Adamson | d87a8ad | 2009-04-03 08:28:53 +0300 | [diff] [blame] | 2321 | static inline int access_valid(u32 x, u32 minorversion) |
J. Bruce Fields | ba5a6a1 | 2006-06-30 01:56:16 -0700 | [diff] [blame] | 2322 | { |
Andy Adamson | d87a8ad | 2009-04-03 08:28:53 +0300 | [diff] [blame] | 2323 | if ((x & NFS4_SHARE_ACCESS_MASK) < NFS4_SHARE_ACCESS_READ) |
J. Bruce Fields | 8838dc4 | 2008-01-14 13:12:19 -0500 | [diff] [blame] | 2324 | return 0; |
Andy Adamson | d87a8ad | 2009-04-03 08:28:53 +0300 | [diff] [blame] | 2325 | if ((x & NFS4_SHARE_ACCESS_MASK) > NFS4_SHARE_ACCESS_BOTH) |
| 2326 | return 0; |
| 2327 | x &= ~NFS4_SHARE_ACCESS_MASK; |
| 2328 | if (minorversion && x) { |
| 2329 | if ((x & NFS4_SHARE_WANT_MASK) > NFS4_SHARE_WANT_CANCEL) |
| 2330 | return 0; |
| 2331 | if ((x & NFS4_SHARE_WHEN_MASK) > NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED) |
| 2332 | return 0; |
| 2333 | x &= ~(NFS4_SHARE_WANT_MASK | NFS4_SHARE_WHEN_MASK); |
| 2334 | } |
| 2335 | if (x) |
J. Bruce Fields | 8838dc4 | 2008-01-14 13:12:19 -0500 | [diff] [blame] | 2336 | return 0; |
| 2337 | return 1; |
J. Bruce Fields | ba5a6a1 | 2006-06-30 01:56:16 -0700 | [diff] [blame] | 2338 | } |
| 2339 | |
J. Bruce Fields | 8838dc4 | 2008-01-14 13:12:19 -0500 | [diff] [blame] | 2340 | static inline int deny_valid(u32 x) |
J. Bruce Fields | ba5a6a1 | 2006-06-30 01:56:16 -0700 | [diff] [blame] | 2341 | { |
J. Bruce Fields | 8838dc4 | 2008-01-14 13:12:19 -0500 | [diff] [blame] | 2342 | /* Note: unlike access bits, deny bits may be zero. */ |
| 2343 | return x <= NFS4_SHARE_DENY_BOTH; |
J. Bruce Fields | ba5a6a1 | 2006-06-30 01:56:16 -0700 | [diff] [blame] | 2344 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2345 | |
J. Bruce Fields | 4f83aa3 | 2008-07-07 15:02:02 -0400 | [diff] [blame] | 2346 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | * Called to check deny when READ with all zero stateid or |
| 2348 | * WRITE with all zero or all one stateid |
| 2349 | */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2350 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | nfs4_share_conflict(struct svc_fh *current_fh, unsigned int deny_type) |
| 2352 | { |
| 2353 | struct inode *ino = current_fh->fh_dentry->d_inode; |
| 2354 | struct nfs4_file *fp; |
| 2355 | struct nfs4_stateid *stp; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2356 | __be32 ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2357 | |
| 2358 | dprintk("NFSD: nfs4_share_conflict\n"); |
| 2359 | |
| 2360 | fp = find_file(ino); |
NeilBrown | 13cd218 | 2005-06-23 22:03:10 -0700 | [diff] [blame] | 2361 | if (!fp) |
| 2362 | return nfs_ok; |
NeilBrown | b700949 | 2005-07-07 17:59:23 -0700 | [diff] [blame] | 2363 | ret = nfserr_locked; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | /* Search for conflicting share reservations */ |
NeilBrown | 13cd218 | 2005-06-23 22:03:10 -0700 | [diff] [blame] | 2365 | list_for_each_entry(stp, &fp->fi_stateids, st_perfile) { |
| 2366 | if (test_bit(deny_type, &stp->st_deny_bmap) || |
| 2367 | test_bit(NFS4_SHARE_DENY_BOTH, &stp->st_deny_bmap)) |
| 2368 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | } |
NeilBrown | 13cd218 | 2005-06-23 22:03:10 -0700 | [diff] [blame] | 2370 | ret = nfs_ok; |
| 2371 | out: |
| 2372 | put_nfs4_file(fp); |
| 2373 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | } |
| 2375 | |
J. Bruce Fields | 6b57d9c | 2011-01-31 11:54:04 -0500 | [diff] [blame] | 2376 | static void nfsd_break_one_deleg(struct nfs4_delegation *dp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2378 | /* We're assuming the state code never drops its reference |
| 2379 | * without first removing the lease. Since we're in this lease |
| 2380 | * callback (and since the lease code is serialized by the kernel |
| 2381 | * lock) we know the server hasn't removed the lease yet, we know |
| 2382 | * it's safe to take a reference: */ |
| 2383 | atomic_inc(&dp->dl_count); |
| 2384 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 | list_add_tail(&dp->dl_recall_lru, &del_recall_lru); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | |
Arnd Bergmann | 460781b | 2010-11-17 16:26:56 +0100 | [diff] [blame] | 2387 | /* only place dl_time is set. protected by lock_flocks*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | dp->dl_time = get_seconds(); |
| 2389 | |
J. Bruce Fields | 6b57d9c | 2011-01-31 11:54:04 -0500 | [diff] [blame] | 2390 | nfsd4_cb_recall(dp); |
| 2391 | } |
| 2392 | |
J. Bruce Fields | acfdf5c | 2011-01-31 19:20:39 -0500 | [diff] [blame] | 2393 | /* Called from break_lease() with lock_flocks() held. */ |
J. Bruce Fields | 6b57d9c | 2011-01-31 11:54:04 -0500 | [diff] [blame] | 2394 | static void nfsd_break_deleg_cb(struct file_lock *fl) |
| 2395 | { |
J. Bruce Fields | acfdf5c | 2011-01-31 19:20:39 -0500 | [diff] [blame] | 2396 | struct nfs4_file *fp = (struct nfs4_file *)fl->fl_owner; |
| 2397 | struct nfs4_delegation *dp; |
J. Bruce Fields | 6b57d9c | 2011-01-31 11:54:04 -0500 | [diff] [blame] | 2398 | |
J. Bruce Fields | acfdf5c | 2011-01-31 19:20:39 -0500 | [diff] [blame] | 2399 | BUG_ON(!fp); |
| 2400 | /* We assume break_lease is only called once per lease: */ |
| 2401 | BUG_ON(fp->fi_had_conflict); |
J. Bruce Fields | 0272e1f | 2007-09-12 18:56:12 -0400 | [diff] [blame] | 2402 | /* |
| 2403 | * We don't want the locks code to timeout the lease for us; |
J. Bruce Fields | acfdf5c | 2011-01-31 19:20:39 -0500 | [diff] [blame] | 2404 | * we'll remove it ourself if a delegation isn't returned |
J. Bruce Fields | 6b57d9c | 2011-01-31 11:54:04 -0500 | [diff] [blame] | 2405 | * in time: |
J. Bruce Fields | 0272e1f | 2007-09-12 18:56:12 -0400 | [diff] [blame] | 2406 | */ |
| 2407 | fl->fl_break_time = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | |
J. Bruce Fields | 5d926e8 | 2011-02-07 16:53:46 -0500 | [diff] [blame] | 2409 | spin_lock(&recall_lock); |
J. Bruce Fields | acfdf5c | 2011-01-31 19:20:39 -0500 | [diff] [blame] | 2410 | fp->fi_had_conflict = true; |
| 2411 | list_for_each_entry(dp, &fp->fi_delegations, dl_perfile) |
| 2412 | nfsd_break_one_deleg(dp); |
J. Bruce Fields | 5d926e8 | 2011-02-07 16:53:46 -0500 | [diff] [blame] | 2413 | spin_unlock(&recall_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | } |
| 2415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | static |
| 2417 | int nfsd_change_deleg_cb(struct file_lock **onlist, int arg) |
| 2418 | { |
| 2419 | if (arg & F_UNLCK) |
| 2420 | return lease_modify(onlist, arg); |
| 2421 | else |
| 2422 | return -EAGAIN; |
| 2423 | } |
| 2424 | |
Alexey Dobriyan | 7b02196 | 2009-09-21 17:01:12 -0700 | [diff] [blame] | 2425 | static const struct lock_manager_operations nfsd_lease_mng_ops = { |
J. Bruce Fields | 8fb47a4 | 2011-07-20 20:21:59 -0400 | [diff] [blame] | 2426 | .lm_break = nfsd_break_deleg_cb, |
| 2427 | .lm_change = nfsd_change_deleg_cb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | }; |
| 2429 | |
| 2430 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2431 | __be32 |
Andy Adamson | 6668958 | 2009-04-03 08:28:45 +0300 | [diff] [blame] | 2432 | nfsd4_process_open1(struct nfsd4_compound_state *cstate, |
| 2433 | struct nfsd4_open *open) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2435 | clientid_t *clientid = &open->op_clientid; |
| 2436 | struct nfs4_client *clp = NULL; |
| 2437 | unsigned int strhashval; |
| 2438 | struct nfs4_stateowner *sop = NULL; |
| 2439 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | if (!check_name(open->op_owner)) |
J. Bruce Fields | 0f442aa | 2006-01-18 17:43:34 -0800 | [diff] [blame] | 2441 | return nfserr_inval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | |
| 2443 | if (STALE_CLIENTID(&open->op_clientid)) |
| 2444 | return nfserr_stale_clientid; |
| 2445 | |
| 2446 | strhashval = ownerstr_hashval(clientid->cl_id, open->op_owner); |
| 2447 | sop = find_openstateowner_str(strhashval, open); |
J. Bruce Fields | 0f442aa | 2006-01-18 17:43:34 -0800 | [diff] [blame] | 2448 | open->op_stateowner = sop; |
| 2449 | if (!sop) { |
| 2450 | /* Make sure the client's lease hasn't expired. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | clp = find_confirmed_client(clientid); |
| 2452 | if (clp == NULL) |
J. Bruce Fields | 0f442aa | 2006-01-18 17:43:34 -0800 | [diff] [blame] | 2453 | return nfserr_expired; |
| 2454 | goto renew; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2455 | } |
Andy Adamson | 6668958 | 2009-04-03 08:28:45 +0300 | [diff] [blame] | 2456 | /* When sessions are used, skip open sequenceid processing */ |
| 2457 | if (nfsd4_has_session(cstate)) |
| 2458 | goto renew; |
J. Bruce Fields | 0f442aa | 2006-01-18 17:43:34 -0800 | [diff] [blame] | 2459 | if (!sop->so_confirmed) { |
| 2460 | /* Replace unconfirmed owners without checking for replay. */ |
| 2461 | clp = sop->so_client; |
J. Bruce Fields | f044ff8 | 2009-01-11 15:24:04 -0500 | [diff] [blame] | 2462 | release_openowner(sop); |
J. Bruce Fields | 0f442aa | 2006-01-18 17:43:34 -0800 | [diff] [blame] | 2463 | open->op_stateowner = NULL; |
| 2464 | goto renew; |
| 2465 | } |
| 2466 | if (open->op_seqid == sop->so_seqid - 1) { |
| 2467 | if (sop->so_replay.rp_buflen) |
Al Viro | a90b061 | 2006-10-19 23:29:03 -0700 | [diff] [blame] | 2468 | return nfserr_replay_me; |
J. Bruce Fields | 0f442aa | 2006-01-18 17:43:34 -0800 | [diff] [blame] | 2469 | /* The original OPEN failed so spectacularly |
| 2470 | * that we don't even have replay data saved! |
| 2471 | * Therefore, we have no choice but to continue |
| 2472 | * processing this OPEN; presumably, we'll |
| 2473 | * fail again for the same reason. |
| 2474 | */ |
| 2475 | dprintk("nfsd4_process_open1: replay with no replay cache\n"); |
| 2476 | goto renew; |
| 2477 | } |
| 2478 | if (open->op_seqid != sop->so_seqid) |
| 2479 | return nfserr_bad_seqid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | renew: |
J. Bruce Fields | 0f442aa | 2006-01-18 17:43:34 -0800 | [diff] [blame] | 2481 | if (open->op_stateowner == NULL) { |
| 2482 | sop = alloc_init_open_stateowner(strhashval, clp, open); |
| 2483 | if (sop == NULL) |
J. Bruce Fields | 3e77246 | 2011-08-10 19:07:33 -0400 | [diff] [blame^] | 2484 | return nfserr_jukebox; |
J. Bruce Fields | 0f442aa | 2006-01-18 17:43:34 -0800 | [diff] [blame] | 2485 | open->op_stateowner = sop; |
| 2486 | } |
| 2487 | list_del_init(&sop->so_close_lru); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | renew_client(sop->so_client); |
J. Bruce Fields | 0f442aa | 2006-01-18 17:43:34 -0800 | [diff] [blame] | 2489 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2490 | } |
| 2491 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2492 | static inline __be32 |
NeilBrown | 4a6e43e | 2005-06-23 22:02:50 -0700 | [diff] [blame] | 2493 | nfs4_check_delegmode(struct nfs4_delegation *dp, int flags) |
| 2494 | { |
| 2495 | if ((flags & WR_STATE) && (dp->dl_type == NFS4_OPEN_DELEGATE_READ)) |
| 2496 | return nfserr_openmode; |
| 2497 | else |
| 2498 | return nfs_ok; |
| 2499 | } |
| 2500 | |
NeilBrown | 52f4fb4 | 2005-06-23 22:02:49 -0700 | [diff] [blame] | 2501 | static struct nfs4_delegation * |
| 2502 | find_delegation_file(struct nfs4_file *fp, stateid_t *stid) |
| 2503 | { |
J. Bruce Fields | 32b007b | 2011-03-06 19:11:03 -0500 | [diff] [blame] | 2504 | struct nfs4_delegation *dp; |
NeilBrown | 52f4fb4 | 2005-06-23 22:02:49 -0700 | [diff] [blame] | 2505 | |
J. Bruce Fields | acfdf5c | 2011-01-31 19:20:39 -0500 | [diff] [blame] | 2506 | spin_lock(&recall_lock); |
J. Bruce Fields | 32b007b | 2011-03-06 19:11:03 -0500 | [diff] [blame] | 2507 | list_for_each_entry(dp, &fp->fi_delegations, dl_perfile) |
| 2508 | if (dp->dl_stateid.si_stateownerid == stid->si_stateownerid) { |
| 2509 | spin_unlock(&recall_lock); |
| 2510 | return dp; |
| 2511 | } |
J. Bruce Fields | acfdf5c | 2011-01-31 19:20:39 -0500 | [diff] [blame] | 2512 | spin_unlock(&recall_lock); |
J. Bruce Fields | 32b007b | 2011-03-06 19:11:03 -0500 | [diff] [blame] | 2513 | return NULL; |
NeilBrown | 52f4fb4 | 2005-06-23 22:02:49 -0700 | [diff] [blame] | 2514 | } |
| 2515 | |
Daniel Mack | c47d832 | 2011-05-16 16:38:14 +0200 | [diff] [blame] | 2516 | static int share_access_to_flags(u32 share_access) |
J. Bruce Fields | 24a0111 | 2010-05-18 20:01:35 -0400 | [diff] [blame] | 2517 | { |
| 2518 | share_access &= ~NFS4_SHARE_WANT_MASK; |
| 2519 | |
| 2520 | return share_access == NFS4_SHARE_ACCESS_READ ? RD_STATE : WR_STATE; |
| 2521 | } |
| 2522 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2523 | static __be32 |
NeilBrown | 567d982 | 2005-06-23 22:02:53 -0700 | [diff] [blame] | 2524 | nfs4_check_deleg(struct nfs4_file *fp, struct nfsd4_open *open, |
| 2525 | struct nfs4_delegation **dp) |
| 2526 | { |
| 2527 | int flags; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2528 | __be32 status = nfserr_bad_stateid; |
NeilBrown | 567d982 | 2005-06-23 22:02:53 -0700 | [diff] [blame] | 2529 | |
| 2530 | *dp = find_delegation_file(fp, &open->op_delegate_stateid); |
| 2531 | if (*dp == NULL) |
NeilBrown | c44c5ee | 2005-06-23 22:02:54 -0700 | [diff] [blame] | 2532 | goto out; |
J. Bruce Fields | 24a0111 | 2010-05-18 20:01:35 -0400 | [diff] [blame] | 2533 | flags = share_access_to_flags(open->op_share_access); |
NeilBrown | 567d982 | 2005-06-23 22:02:53 -0700 | [diff] [blame] | 2534 | status = nfs4_check_delegmode(*dp, flags); |
| 2535 | if (status) |
| 2536 | *dp = NULL; |
NeilBrown | c44c5ee | 2005-06-23 22:02:54 -0700 | [diff] [blame] | 2537 | out: |
| 2538 | if (open->op_claim_type != NFS4_OPEN_CLAIM_DELEGATE_CUR) |
| 2539 | return nfs_ok; |
| 2540 | if (status) |
| 2541 | return status; |
| 2542 | open->op_stateowner->so_confirmed = 1; |
| 2543 | return nfs_ok; |
NeilBrown | 567d982 | 2005-06-23 22:02:53 -0700 | [diff] [blame] | 2544 | } |
| 2545 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2546 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2547 | nfs4_check_open(struct nfs4_file *fp, struct nfsd4_open *open, struct nfs4_stateid **stpp) |
| 2548 | { |
| 2549 | struct nfs4_stateid *local; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2550 | __be32 status = nfserr_share_denied; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2551 | struct nfs4_stateowner *sop = open->op_stateowner; |
| 2552 | |
NeilBrown | 8beefa2 | 2005-06-23 22:03:08 -0700 | [diff] [blame] | 2553 | list_for_each_entry(local, &fp->fi_stateids, st_perfile) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2554 | /* ignore lock owners */ |
| 2555 | if (local->st_stateowner->so_is_open_owner == 0) |
| 2556 | continue; |
| 2557 | /* remember if we have seen this open owner */ |
| 2558 | if (local->st_stateowner == sop) |
| 2559 | *stpp = local; |
| 2560 | /* check for conflicting share reservations */ |
| 2561 | if (!test_share(local, open)) |
| 2562 | goto out; |
| 2563 | } |
| 2564 | status = 0; |
| 2565 | out: |
| 2566 | return status; |
| 2567 | } |
| 2568 | |
NeilBrown | 5ac049a | 2005-06-23 22:03:03 -0700 | [diff] [blame] | 2569 | static inline struct nfs4_stateid * |
| 2570 | nfs4_alloc_stateid(void) |
| 2571 | { |
| 2572 | return kmem_cache_alloc(stateid_slab, GFP_KERNEL); |
| 2573 | } |
| 2574 | |
J. Bruce Fields | 21fb401 | 2010-07-28 12:21:23 -0400 | [diff] [blame] | 2575 | static inline int nfs4_access_to_access(u32 nfs4_access) |
| 2576 | { |
| 2577 | int flags = 0; |
| 2578 | |
| 2579 | if (nfs4_access & NFS4_SHARE_ACCESS_READ) |
| 2580 | flags |= NFSD_MAY_READ; |
| 2581 | if (nfs4_access & NFS4_SHARE_ACCESS_WRITE) |
| 2582 | flags |= NFSD_MAY_WRITE; |
| 2583 | return flags; |
| 2584 | } |
| 2585 | |
Casey Bodley | 0c12eaf | 2011-07-23 14:58:10 -0400 | [diff] [blame] | 2586 | static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp, |
| 2587 | struct svc_fh *cur_fh, struct nfsd4_open *open) |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 2588 | { |
| 2589 | __be32 status; |
Casey Bodley | 0c12eaf | 2011-07-23 14:58:10 -0400 | [diff] [blame] | 2590 | int oflag = nfs4_access_to_omode(open->op_share_access); |
| 2591 | int access = nfs4_access_to_access(open->op_share_access); |
| 2592 | |
| 2593 | /* CLAIM_DELEGATE_CUR is used in response to a broken lease; |
| 2594 | * allowing it to break the lease and return EAGAIN leaves the |
| 2595 | * client unable to make progress in returning the delegation */ |
| 2596 | if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR) |
| 2597 | access |= NFSD_MAY_NOT_BREAK_LEASE; |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 2598 | |
| 2599 | if (!fp->fi_fds[oflag]) { |
| 2600 | status = nfsd_open(rqstp, cur_fh, S_IFREG, access, |
| 2601 | &fp->fi_fds[oflag]); |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 2602 | if (status) |
| 2603 | return status; |
| 2604 | } |
| 2605 | nfs4_file_get_access(fp, oflag); |
| 2606 | |
| 2607 | return nfs_ok; |
| 2608 | } |
| 2609 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2610 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2611 | nfs4_new_open(struct svc_rqst *rqstp, struct nfs4_stateid **stpp, |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 2612 | struct nfs4_file *fp, struct svc_fh *cur_fh, |
| 2613 | struct nfsd4_open *open) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2614 | { |
| 2615 | struct nfs4_stateid *stp; |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 2616 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | |
NeilBrown | 5ac049a | 2005-06-23 22:03:03 -0700 | [diff] [blame] | 2618 | stp = nfs4_alloc_stateid(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2619 | if (stp == NULL) |
J. Bruce Fields | 3e77246 | 2011-08-10 19:07:33 -0400 | [diff] [blame^] | 2620 | return nfserr_jukebox; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2621 | |
Casey Bodley | 0c12eaf | 2011-07-23 14:58:10 -0400 | [diff] [blame] | 2622 | status = nfs4_get_vfs_file(rqstp, fp, cur_fh, open); |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 2623 | if (status) { |
| 2624 | kmem_cache_free(stateid_slab, stp); |
| 2625 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | *stpp = stp; |
| 2628 | return 0; |
| 2629 | } |
| 2630 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2631 | static inline __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2632 | nfsd4_truncate(struct svc_rqst *rqstp, struct svc_fh *fh, |
| 2633 | struct nfsd4_open *open) |
| 2634 | { |
| 2635 | struct iattr iattr = { |
| 2636 | .ia_valid = ATTR_SIZE, |
| 2637 | .ia_size = 0, |
| 2638 | }; |
| 2639 | if (!open->op_truncate) |
| 2640 | return 0; |
| 2641 | if (!(open->op_share_access & NFS4_SHARE_ACCESS_WRITE)) |
Al Viro | 9246585 | 2006-01-18 17:43:46 -0800 | [diff] [blame] | 2642 | return nfserr_inval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2643 | return nfsd_setattr(rqstp, fh, &iattr, 0, (time_t)0); |
| 2644 | } |
| 2645 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2646 | static __be32 |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 2647 | nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, struct svc_fh *cur_fh, struct nfs4_stateid *stp, struct nfsd4_open *open) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | { |
J. Bruce Fields | 7d94784 | 2010-08-20 18:09:31 -0400 | [diff] [blame] | 2649 | u32 op_share_access = open->op_share_access & ~NFS4_SHARE_WANT_MASK; |
| 2650 | bool new_access; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2651 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2652 | |
J. Bruce Fields | 7d94784 | 2010-08-20 18:09:31 -0400 | [diff] [blame] | 2653 | new_access = !test_bit(op_share_access, &stp->st_access_bmap); |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 2654 | if (new_access) { |
Casey Bodley | 0c12eaf | 2011-07-23 14:58:10 -0400 | [diff] [blame] | 2655 | status = nfs4_get_vfs_file(rqstp, fp, cur_fh, open); |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 2656 | if (status) |
| 2657 | return status; |
J. Bruce Fields | 6c26d08 | 2006-01-18 17:43:38 -0800 | [diff] [blame] | 2658 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | status = nfsd4_truncate(rqstp, cur_fh, open); |
| 2660 | if (status) { |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 2661 | if (new_access) { |
J. Bruce Fields | f197c27 | 2011-06-29 08:23:50 -0400 | [diff] [blame] | 2662 | int oflag = nfs4_access_to_omode(op_share_access); |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 2663 | nfs4_file_put_access(fp, oflag); |
| 2664 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2665 | return status; |
| 2666 | } |
| 2667 | /* remember the open */ |
J. Bruce Fields | 24a0111 | 2010-05-18 20:01:35 -0400 | [diff] [blame] | 2668 | __set_bit(op_share_access, &stp->st_access_bmap); |
J. Bruce Fields | b55e0ba | 2008-04-28 18:22:50 -0400 | [diff] [blame] | 2669 | __set_bit(open->op_share_deny, &stp->st_deny_bmap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | |
| 2671 | return nfs_ok; |
| 2672 | } |
| 2673 | |
| 2674 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2675 | static void |
NeilBrown | 3751517 | 2005-07-07 17:59:16 -0700 | [diff] [blame] | 2676 | nfs4_set_claim_prev(struct nfsd4_open *open) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | { |
NeilBrown | 3751517 | 2005-07-07 17:59:16 -0700 | [diff] [blame] | 2678 | open->op_stateowner->so_confirmed = 1; |
| 2679 | open->op_stateowner->so_client->cl_firststate = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | } |
| 2681 | |
J. Bruce Fields | 14a24e9 | 2010-12-10 19:02:49 -0500 | [diff] [blame] | 2682 | /* Should we give out recallable state?: */ |
| 2683 | static bool nfsd4_cb_channel_good(struct nfs4_client *clp) |
| 2684 | { |
| 2685 | if (clp->cl_cb_state == NFSD4_CB_UP) |
| 2686 | return true; |
| 2687 | /* |
| 2688 | * In the sessions case, since we don't have to establish a |
| 2689 | * separate connection for callbacks, we assume it's OK |
| 2690 | * until we hear otherwise: |
| 2691 | */ |
| 2692 | return clp->cl_minorversion && clp->cl_cb_state == NFSD4_CB_UNKNOWN; |
| 2693 | } |
| 2694 | |
J. Bruce Fields | 22d38c4 | 2011-01-31 11:55:12 -0500 | [diff] [blame] | 2695 | static struct file_lock *nfs4_alloc_init_lease(struct nfs4_delegation *dp, int flag) |
| 2696 | { |
| 2697 | struct file_lock *fl; |
| 2698 | |
| 2699 | fl = locks_alloc_lock(); |
| 2700 | if (!fl) |
| 2701 | return NULL; |
| 2702 | locks_init_lock(fl); |
| 2703 | fl->fl_lmops = &nfsd_lease_mng_ops; |
| 2704 | fl->fl_flags = FL_LEASE; |
| 2705 | fl->fl_type = flag == NFS4_OPEN_DELEGATE_READ? F_RDLCK: F_WRLCK; |
| 2706 | fl->fl_end = OFFSET_MAX; |
J. Bruce Fields | acfdf5c | 2011-01-31 19:20:39 -0500 | [diff] [blame] | 2707 | fl->fl_owner = (fl_owner_t)(dp->dl_file); |
J. Bruce Fields | 22d38c4 | 2011-01-31 11:55:12 -0500 | [diff] [blame] | 2708 | fl->fl_pid = current->tgid; |
J. Bruce Fields | 22d38c4 | 2011-01-31 11:55:12 -0500 | [diff] [blame] | 2709 | return fl; |
| 2710 | } |
| 2711 | |
J. Bruce Fields | edab978 | 2011-01-31 17:58:10 -0500 | [diff] [blame] | 2712 | static int nfs4_setlease(struct nfs4_delegation *dp, int flag) |
| 2713 | { |
J. Bruce Fields | acfdf5c | 2011-01-31 19:20:39 -0500 | [diff] [blame] | 2714 | struct nfs4_file *fp = dp->dl_file; |
J. Bruce Fields | edab978 | 2011-01-31 17:58:10 -0500 | [diff] [blame] | 2715 | struct file_lock *fl; |
| 2716 | int status; |
| 2717 | |
| 2718 | fl = nfs4_alloc_init_lease(dp, flag); |
| 2719 | if (!fl) |
| 2720 | return -ENOMEM; |
J. Bruce Fields | acfdf5c | 2011-01-31 19:20:39 -0500 | [diff] [blame] | 2721 | fl->fl_file = find_readable_file(fp); |
| 2722 | list_add(&dp->dl_perclnt, &dp->dl_client->cl_delegations); |
| 2723 | status = vfs_setlease(fl->fl_file, fl->fl_type, &fl); |
J. Bruce Fields | edab978 | 2011-01-31 17:58:10 -0500 | [diff] [blame] | 2724 | if (status) { |
J. Bruce Fields | acfdf5c | 2011-01-31 19:20:39 -0500 | [diff] [blame] | 2725 | list_del_init(&dp->dl_perclnt); |
J. Bruce Fields | edab978 | 2011-01-31 17:58:10 -0500 | [diff] [blame] | 2726 | locks_free_lock(fl); |
| 2727 | return -ENOMEM; |
| 2728 | } |
J. Bruce Fields | acfdf5c | 2011-01-31 19:20:39 -0500 | [diff] [blame] | 2729 | fp->fi_lease = fl; |
| 2730 | fp->fi_deleg_file = fl->fl_file; |
| 2731 | get_file(fp->fi_deleg_file); |
| 2732 | atomic_set(&fp->fi_delegees, 1); |
| 2733 | list_add(&dp->dl_perfile, &fp->fi_delegations); |
| 2734 | return 0; |
| 2735 | } |
| 2736 | |
| 2737 | static int nfs4_set_delegation(struct nfs4_delegation *dp, int flag) |
| 2738 | { |
| 2739 | struct nfs4_file *fp = dp->dl_file; |
| 2740 | |
| 2741 | if (!fp->fi_lease) |
| 2742 | return nfs4_setlease(dp, flag); |
| 2743 | spin_lock(&recall_lock); |
| 2744 | if (fp->fi_had_conflict) { |
| 2745 | spin_unlock(&recall_lock); |
| 2746 | return -EAGAIN; |
| 2747 | } |
| 2748 | atomic_inc(&fp->fi_delegees); |
| 2749 | list_add(&dp->dl_perfile, &fp->fi_delegations); |
| 2750 | spin_unlock(&recall_lock); |
| 2751 | list_add(&dp->dl_perclnt, &dp->dl_client->cl_delegations); |
J. Bruce Fields | edab978 | 2011-01-31 17:58:10 -0500 | [diff] [blame] | 2752 | return 0; |
| 2753 | } |
| 2754 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2755 | /* |
| 2756 | * Attempt to hand out a delegation. |
| 2757 | */ |
| 2758 | static void |
| 2759 | nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_stateid *stp) |
| 2760 | { |
| 2761 | struct nfs4_delegation *dp; |
| 2762 | struct nfs4_stateowner *sop = stp->st_stateowner; |
J. Bruce Fields | 14a24e9 | 2010-12-10 19:02:49 -0500 | [diff] [blame] | 2763 | int cb_up; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | int status, flag = 0; |
| 2765 | |
J. Bruce Fields | 14a24e9 | 2010-12-10 19:02:49 -0500 | [diff] [blame] | 2766 | cb_up = nfsd4_cb_channel_good(sop->so_client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2767 | flag = NFS4_OPEN_DELEGATE_NONE; |
NeilBrown | 7b190fe | 2005-06-23 22:03:23 -0700 | [diff] [blame] | 2768 | open->op_recall = 0; |
| 2769 | switch (open->op_claim_type) { |
| 2770 | case NFS4_OPEN_CLAIM_PREVIOUS: |
J. Bruce Fields | 2bf2387 | 2010-03-08 12:37:27 -0500 | [diff] [blame] | 2771 | if (!cb_up) |
NeilBrown | 7b190fe | 2005-06-23 22:03:23 -0700 | [diff] [blame] | 2772 | open->op_recall = 1; |
| 2773 | flag = open->op_delegate_type; |
| 2774 | if (flag == NFS4_OPEN_DELEGATE_NONE) |
| 2775 | goto out; |
| 2776 | break; |
| 2777 | case NFS4_OPEN_CLAIM_NULL: |
| 2778 | /* Let's not give out any delegations till everyone's |
| 2779 | * had the chance to reclaim theirs.... */ |
J. Bruce Fields | af558e3 | 2007-09-06 12:34:25 -0400 | [diff] [blame] | 2780 | if (locks_in_grace()) |
NeilBrown | 7b190fe | 2005-06-23 22:03:23 -0700 | [diff] [blame] | 2781 | goto out; |
J. Bruce Fields | 2bf2387 | 2010-03-08 12:37:27 -0500 | [diff] [blame] | 2782 | if (!cb_up || !sop->so_confirmed) |
NeilBrown | 7b190fe | 2005-06-23 22:03:23 -0700 | [diff] [blame] | 2783 | goto out; |
| 2784 | if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) |
| 2785 | flag = NFS4_OPEN_DELEGATE_WRITE; |
| 2786 | else |
| 2787 | flag = NFS4_OPEN_DELEGATE_READ; |
| 2788 | break; |
| 2789 | default: |
| 2790 | goto out; |
| 2791 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | |
| 2793 | dp = alloc_init_deleg(sop->so_client, stp, fh, flag); |
J. Bruce Fields | dd239cc | 2011-01-31 17:14:55 -0500 | [diff] [blame] | 2794 | if (dp == NULL) |
| 2795 | goto out_no_deleg; |
J. Bruce Fields | acfdf5c | 2011-01-31 19:20:39 -0500 | [diff] [blame] | 2796 | status = nfs4_set_delegation(dp, flag); |
J. Bruce Fields | edab978 | 2011-01-31 17:58:10 -0500 | [diff] [blame] | 2797 | if (status) |
J. Bruce Fields | dd239cc | 2011-01-31 17:14:55 -0500 | [diff] [blame] | 2798 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | |
| 2800 | memcpy(&open->op_delegate_stateid, &dp->dl_stateid, sizeof(dp->dl_stateid)); |
| 2801 | |
Benny Halevy | 8c10cbd | 2009-10-19 12:04:53 +0200 | [diff] [blame] | 2802 | dprintk("NFSD: delegation stateid=" STATEID_FMT "\n", |
| 2803 | STATEID_VAL(&dp->dl_stateid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | out: |
NeilBrown | 7b190fe | 2005-06-23 22:03:23 -0700 | [diff] [blame] | 2805 | if (open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS |
| 2806 | && flag == NFS4_OPEN_DELEGATE_NONE |
| 2807 | && open->op_delegate_type != NFS4_OPEN_DELEGATE_NONE) |
J. Bruce Fields | 2fdada0 | 2007-07-27 16:10:37 -0400 | [diff] [blame] | 2808 | dprintk("NFSD: WARNING: refusing delegation reclaim\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2809 | open->op_delegate_type = flag; |
J. Bruce Fields | dd239cc | 2011-01-31 17:14:55 -0500 | [diff] [blame] | 2810 | return; |
| 2811 | out_free: |
J. Bruce Fields | acfdf5c | 2011-01-31 19:20:39 -0500 | [diff] [blame] | 2812 | nfs4_put_delegation(dp); |
J. Bruce Fields | dd239cc | 2011-01-31 17:14:55 -0500 | [diff] [blame] | 2813 | out_no_deleg: |
| 2814 | flag = NFS4_OPEN_DELEGATE_NONE; |
| 2815 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | } |
| 2817 | |
| 2818 | /* |
| 2819 | * called with nfs4_lock_state() held. |
| 2820 | */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2821 | __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open) |
| 2823 | { |
Andy Adamson | 6668958 | 2009-04-03 08:28:45 +0300 | [diff] [blame] | 2824 | struct nfsd4_compoundres *resp = rqstp->rq_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2825 | struct nfs4_file *fp = NULL; |
| 2826 | struct inode *ino = current_fh->fh_dentry->d_inode; |
| 2827 | struct nfs4_stateid *stp = NULL; |
NeilBrown | 567d982 | 2005-06-23 22:02:53 -0700 | [diff] [blame] | 2828 | struct nfs4_delegation *dp = NULL; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2829 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | |
| 2831 | status = nfserr_inval; |
Andy Adamson | d87a8ad | 2009-04-03 08:28:53 +0300 | [diff] [blame] | 2832 | if (!access_valid(open->op_share_access, resp->cstate.minorversion) |
J. Bruce Fields | ba5a6a1 | 2006-06-30 01:56:16 -0700 | [diff] [blame] | 2833 | || !deny_valid(open->op_share_deny)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | goto out; |
| 2835 | /* |
| 2836 | * Lookup file; if found, lookup stateid and check open request, |
| 2837 | * and check for delegations in the process of being recalled. |
| 2838 | * If not found, create the nfs4_file struct |
| 2839 | */ |
| 2840 | fp = find_file(ino); |
| 2841 | if (fp) { |
| 2842 | if ((status = nfs4_check_open(fp, open, &stp))) |
| 2843 | goto out; |
NeilBrown | c44c5ee | 2005-06-23 22:02:54 -0700 | [diff] [blame] | 2844 | status = nfs4_check_deleg(fp, open, &dp); |
| 2845 | if (status) |
| 2846 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | } else { |
NeilBrown | c44c5ee | 2005-06-23 22:02:54 -0700 | [diff] [blame] | 2848 | status = nfserr_bad_stateid; |
| 2849 | if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR) |
| 2850 | goto out; |
J. Bruce Fields | 3e77246 | 2011-08-10 19:07:33 -0400 | [diff] [blame^] | 2851 | status = nfserr_jukebox; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | fp = alloc_init_file(ino); |
| 2853 | if (fp == NULL) |
| 2854 | goto out; |
| 2855 | } |
| 2856 | |
| 2857 | /* |
| 2858 | * OPEN the file, or upgrade an existing OPEN. |
| 2859 | * If truncate fails, the OPEN fails. |
| 2860 | */ |
| 2861 | if (stp) { |
| 2862 | /* Stateid was found, this is an OPEN upgrade */ |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 2863 | status = nfs4_upgrade_open(rqstp, fp, current_fh, stp, open); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2864 | if (status) |
| 2865 | goto out; |
NeilBrown | 444c2c0 | 2005-07-07 17:59:22 -0700 | [diff] [blame] | 2866 | update_stateid(&stp->st_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2867 | } else { |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 2868 | status = nfs4_new_open(rqstp, &stp, fp, current_fh, open); |
NeilBrown | 567d982 | 2005-06-23 22:02:53 -0700 | [diff] [blame] | 2869 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2870 | goto out; |
| 2871 | init_stateid(stp, fp, open); |
| 2872 | status = nfsd4_truncate(rqstp, current_fh, open); |
| 2873 | if (status) { |
J. Bruce Fields | 2283963 | 2009-01-11 14:27:17 -0500 | [diff] [blame] | 2874 | release_open_stateid(stp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | goto out; |
| 2876 | } |
Andy Adamson | 6668958 | 2009-04-03 08:28:45 +0300 | [diff] [blame] | 2877 | if (nfsd4_has_session(&resp->cstate)) |
| 2878 | update_stateid(&stp->st_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | } |
| 2880 | memcpy(&open->op_stateid, &stp->st_stateid, sizeof(stateid_t)); |
| 2881 | |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 2882 | if (nfsd4_has_session(&resp->cstate)) |
Andy Adamson | 6668958 | 2009-04-03 08:28:45 +0300 | [diff] [blame] | 2883 | open->op_stateowner->so_confirmed = 1; |
| 2884 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2885 | /* |
| 2886 | * Attempt to hand out a delegation. No error return, because the |
| 2887 | * OPEN succeeds even if we fail. |
| 2888 | */ |
| 2889 | nfs4_open_delegation(current_fh, open, stp); |
| 2890 | |
| 2891 | status = nfs_ok; |
| 2892 | |
Benny Halevy | 8c10cbd | 2009-10-19 12:04:53 +0200 | [diff] [blame] | 2893 | dprintk("%s: stateid=" STATEID_FMT "\n", __func__, |
| 2894 | STATEID_VAL(&stp->st_stateid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | out: |
NeilBrown | 13cd218 | 2005-06-23 22:03:10 -0700 | [diff] [blame] | 2896 | if (fp) |
| 2897 | put_nfs4_file(fp); |
NeilBrown | 3751517 | 2005-07-07 17:59:16 -0700 | [diff] [blame] | 2898 | if (status == 0 && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS) |
| 2899 | nfs4_set_claim_prev(open); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | /* |
| 2901 | * To finish the open response, we just need to set the rflags. |
| 2902 | */ |
| 2903 | open->op_rflags = NFS4_OPEN_RESULT_LOCKTYPE_POSIX; |
Andy Adamson | 6668958 | 2009-04-03 08:28:45 +0300 | [diff] [blame] | 2904 | if (!open->op_stateowner->so_confirmed && |
| 2905 | !nfsd4_has_session(&resp->cstate)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | open->op_rflags |= NFS4_OPEN_RESULT_CONFIRM; |
| 2907 | |
| 2908 | return status; |
| 2909 | } |
| 2910 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2911 | __be32 |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 2912 | nfsd4_renew(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
| 2913 | clientid_t *clid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2914 | { |
| 2915 | struct nfs4_client *clp; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2916 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2917 | |
| 2918 | nfs4_lock_state(); |
| 2919 | dprintk("process_renew(%08x/%08x): starting\n", |
| 2920 | clid->cl_boot, clid->cl_id); |
| 2921 | status = nfserr_stale_clientid; |
| 2922 | if (STALE_CLIENTID(clid)) |
| 2923 | goto out; |
| 2924 | clp = find_confirmed_client(clid); |
| 2925 | status = nfserr_expired; |
| 2926 | if (clp == NULL) { |
| 2927 | /* We assume the client took too long to RENEW. */ |
| 2928 | dprintk("nfsd4_renew: clientid not found!\n"); |
| 2929 | goto out; |
| 2930 | } |
| 2931 | renew_client(clp); |
| 2932 | status = nfserr_cb_path_down; |
NeilBrown | ea1da63 | 2005-06-23 22:04:17 -0700 | [diff] [blame] | 2933 | if (!list_empty(&clp->cl_delegations) |
J. Bruce Fields | 77a3569 | 2010-04-30 18:51:44 -0400 | [diff] [blame] | 2934 | && clp->cl_cb_state != NFSD4_CB_UP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2935 | goto out; |
| 2936 | status = nfs_ok; |
| 2937 | out: |
| 2938 | nfs4_unlock_state(); |
| 2939 | return status; |
| 2940 | } |
| 2941 | |
Daniel Mack | c47d832 | 2011-05-16 16:38:14 +0200 | [diff] [blame] | 2942 | static struct lock_manager nfsd4_manager = { |
J. Bruce Fields | af558e3 | 2007-09-06 12:34:25 -0400 | [diff] [blame] | 2943 | }; |
| 2944 | |
NeilBrown | a76b431 | 2005-06-23 22:04:01 -0700 | [diff] [blame] | 2945 | static void |
J. Bruce Fields | af558e3 | 2007-09-06 12:34:25 -0400 | [diff] [blame] | 2946 | nfsd4_end_grace(void) |
NeilBrown | a76b431 | 2005-06-23 22:04:01 -0700 | [diff] [blame] | 2947 | { |
| 2948 | dprintk("NFSD: end of grace period\n"); |
NeilBrown | c7b9a45 | 2005-06-23 22:04:30 -0700 | [diff] [blame] | 2949 | nfsd4_recdir_purge_old(); |
J. Bruce Fields | af558e3 | 2007-09-06 12:34:25 -0400 | [diff] [blame] | 2950 | locks_end_grace(&nfsd4_manager); |
J. Bruce Fields | e46b498 | 2010-03-01 19:21:21 -0500 | [diff] [blame] | 2951 | /* |
| 2952 | * Now that every NFSv4 client has had the chance to recover and |
| 2953 | * to see the (possibly new, possibly shorter) lease time, we |
| 2954 | * can safely set the next grace time to the current lease time: |
| 2955 | */ |
| 2956 | nfsd4_grace = nfsd4_lease; |
NeilBrown | a76b431 | 2005-06-23 22:04:01 -0700 | [diff] [blame] | 2957 | } |
| 2958 | |
NeilBrown | fd39ca9 | 2005-06-23 22:04:03 -0700 | [diff] [blame] | 2959 | static time_t |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2960 | nfs4_laundromat(void) |
| 2961 | { |
| 2962 | struct nfs4_client *clp; |
| 2963 | struct nfs4_stateowner *sop; |
| 2964 | struct nfs4_delegation *dp; |
| 2965 | struct list_head *pos, *next, reaplist; |
J. Bruce Fields | cf07d2e | 2010-02-28 23:20:19 -0500 | [diff] [blame] | 2966 | time_t cutoff = get_seconds() - nfsd4_lease; |
| 2967 | time_t t, clientid_val = nfsd4_lease; |
| 2968 | time_t u, test_val = nfsd4_lease; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | |
| 2970 | nfs4_lock_state(); |
| 2971 | |
| 2972 | dprintk("NFSD: laundromat service - starting\n"); |
J. Bruce Fields | af558e3 | 2007-09-06 12:34:25 -0400 | [diff] [blame] | 2973 | if (locks_in_grace()) |
| 2974 | nfsd4_end_grace(); |
Benny Halevy | 36acb66 | 2010-05-12 00:13:04 +0300 | [diff] [blame] | 2975 | INIT_LIST_HEAD(&reaplist); |
| 2976 | spin_lock(&client_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | list_for_each_safe(pos, next, &client_lru) { |
| 2978 | clp = list_entry(pos, struct nfs4_client, cl_lru); |
| 2979 | if (time_after((unsigned long)clp->cl_time, (unsigned long)cutoff)) { |
| 2980 | t = clp->cl_time - cutoff; |
| 2981 | if (clientid_val > t) |
| 2982 | clientid_val = t; |
| 2983 | break; |
| 2984 | } |
Benny Halevy | d768298 | 2010-05-12 00:13:54 +0300 | [diff] [blame] | 2985 | if (atomic_read(&clp->cl_refcount)) { |
| 2986 | dprintk("NFSD: client in use (clientid %08x)\n", |
| 2987 | clp->cl_clientid.cl_id); |
| 2988 | continue; |
| 2989 | } |
| 2990 | unhash_client_locked(clp); |
| 2991 | list_add(&clp->cl_lru, &reaplist); |
Benny Halevy | 36acb66 | 2010-05-12 00:13:04 +0300 | [diff] [blame] | 2992 | } |
| 2993 | spin_unlock(&client_lock); |
| 2994 | list_for_each_safe(pos, next, &reaplist) { |
| 2995 | clp = list_entry(pos, struct nfs4_client, cl_lru); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2996 | dprintk("NFSD: purging unused client (clientid %08x)\n", |
| 2997 | clp->cl_clientid.cl_id); |
NeilBrown | c7b9a45 | 2005-06-23 22:04:30 -0700 | [diff] [blame] | 2998 | nfsd4_remove_clid_dir(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2999 | expire_client(clp); |
| 3000 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | spin_lock(&recall_lock); |
| 3002 | list_for_each_safe(pos, next, &del_recall_lru) { |
| 3003 | dp = list_entry (pos, struct nfs4_delegation, dl_recall_lru); |
| 3004 | if (time_after((unsigned long)dp->dl_time, (unsigned long)cutoff)) { |
| 3005 | u = dp->dl_time - cutoff; |
| 3006 | if (test_val > u) |
| 3007 | test_val = u; |
| 3008 | break; |
| 3009 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | list_move(&dp->dl_recall_lru, &reaplist); |
| 3011 | } |
| 3012 | spin_unlock(&recall_lock); |
| 3013 | list_for_each_safe(pos, next, &reaplist) { |
| 3014 | dp = list_entry (pos, struct nfs4_delegation, dl_recall_lru); |
| 3015 | list_del_init(&dp->dl_recall_lru); |
| 3016 | unhash_delegation(dp); |
| 3017 | } |
J. Bruce Fields | cf07d2e | 2010-02-28 23:20:19 -0500 | [diff] [blame] | 3018 | test_val = nfsd4_lease; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3019 | list_for_each_safe(pos, next, &close_lru) { |
| 3020 | sop = list_entry(pos, struct nfs4_stateowner, so_close_lru); |
| 3021 | if (time_after((unsigned long)sop->so_time, (unsigned long)cutoff)) { |
| 3022 | u = sop->so_time - cutoff; |
| 3023 | if (test_val > u) |
| 3024 | test_val = u; |
| 3025 | break; |
| 3026 | } |
| 3027 | dprintk("NFSD: purging unused open stateowner (so_id %d)\n", |
| 3028 | sop->so_id); |
J. Bruce Fields | f044ff8 | 2009-01-11 15:24:04 -0500 | [diff] [blame] | 3029 | release_openowner(sop); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | } |
| 3031 | if (clientid_val < NFSD_LAUNDROMAT_MINTIMEOUT) |
| 3032 | clientid_val = NFSD_LAUNDROMAT_MINTIMEOUT; |
| 3033 | nfs4_unlock_state(); |
| 3034 | return clientid_val; |
| 3035 | } |
| 3036 | |
Harvey Harrison | a254b24 | 2008-02-20 12:49:00 -0800 | [diff] [blame] | 3037 | static struct workqueue_struct *laundry_wq; |
| 3038 | static void laundromat_main(struct work_struct *); |
| 3039 | static DECLARE_DELAYED_WORK(laundromat_work, laundromat_main); |
| 3040 | |
| 3041 | static void |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3042 | laundromat_main(struct work_struct *not_used) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3043 | { |
| 3044 | time_t t; |
| 3045 | |
| 3046 | t = nfs4_laundromat(); |
| 3047 | dprintk("NFSD: laundromat_main - sleeping for %ld seconds\n", t); |
NeilBrown | 58da282 | 2005-06-23 22:03:19 -0700 | [diff] [blame] | 3048 | queue_delayed_work(laundry_wq, &laundromat_work, t*HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3049 | } |
| 3050 | |
NeilBrown | fd39ca9 | 2005-06-23 22:04:03 -0700 | [diff] [blame] | 3051 | static struct nfs4_stateowner * |
NeilBrown | f881651 | 2005-07-07 17:59:25 -0700 | [diff] [blame] | 3052 | search_close_lru(u32 st_id, int flags) |
| 3053 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | struct nfs4_stateowner *local = NULL; |
| 3055 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | if (flags & CLOSE_STATE) { |
| 3057 | list_for_each_entry(local, &close_lru, so_close_lru) { |
| 3058 | if (local->so_id == st_id) |
| 3059 | return local; |
| 3060 | } |
| 3061 | } |
| 3062 | return NULL; |
| 3063 | } |
| 3064 | |
| 3065 | static inline int |
| 3066 | nfs4_check_fh(struct svc_fh *fhp, struct nfs4_stateid *stp) |
| 3067 | { |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 3068 | return fhp->fh_dentry->d_inode != stp->st_file->fi_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3069 | } |
| 3070 | |
| 3071 | static int |
| 3072 | STALE_STATEID(stateid_t *stateid) |
| 3073 | { |
J. Bruce Fields | e4e83ea | 2010-04-22 16:21:39 -0400 | [diff] [blame] | 3074 | if (stateid->si_boot == boot_time) |
| 3075 | return 0; |
| 3076 | dprintk("NFSD: stale stateid " STATEID_FMT "!\n", |
Benny Halevy | 8c10cbd | 2009-10-19 12:04:53 +0200 | [diff] [blame] | 3077 | STATEID_VAL(stateid)); |
J. Bruce Fields | e4e83ea | 2010-04-22 16:21:39 -0400 | [diff] [blame] | 3078 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | } |
| 3080 | |
| 3081 | static inline int |
| 3082 | access_permit_read(unsigned long access_bmap) |
| 3083 | { |
| 3084 | return test_bit(NFS4_SHARE_ACCESS_READ, &access_bmap) || |
| 3085 | test_bit(NFS4_SHARE_ACCESS_BOTH, &access_bmap) || |
| 3086 | test_bit(NFS4_SHARE_ACCESS_WRITE, &access_bmap); |
| 3087 | } |
| 3088 | |
| 3089 | static inline int |
| 3090 | access_permit_write(unsigned long access_bmap) |
| 3091 | { |
| 3092 | return test_bit(NFS4_SHARE_ACCESS_WRITE, &access_bmap) || |
| 3093 | test_bit(NFS4_SHARE_ACCESS_BOTH, &access_bmap); |
| 3094 | } |
| 3095 | |
| 3096 | static |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3097 | __be32 nfs4_check_openmode(struct nfs4_stateid *stp, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3098 | { |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3099 | __be32 status = nfserr_openmode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3100 | |
J. Bruce Fields | 0292191 | 2010-07-29 15:16:59 -0400 | [diff] [blame] | 3101 | /* For lock stateid's, we test the parent open, not the lock: */ |
| 3102 | if (stp->st_openstp) |
| 3103 | stp = stp->st_openstp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3104 | if ((flags & WR_STATE) && (!access_permit_write(stp->st_access_bmap))) |
| 3105 | goto out; |
| 3106 | if ((flags & RD_STATE) && (!access_permit_read(stp->st_access_bmap))) |
| 3107 | goto out; |
| 3108 | status = nfs_ok; |
| 3109 | out: |
| 3110 | return status; |
| 3111 | } |
| 3112 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3113 | static inline __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3114 | check_special_stateids(svc_fh *current_fh, stateid_t *stateid, int flags) |
| 3115 | { |
J. Bruce Fields | 203a8c8 | 2009-02-21 13:29:14 -0800 | [diff] [blame] | 3116 | if (ONE_STATEID(stateid) && (flags & RD_STATE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3117 | return nfs_ok; |
J. Bruce Fields | af558e3 | 2007-09-06 12:34:25 -0400 | [diff] [blame] | 3118 | else if (locks_in_grace()) { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3119 | /* Answer in remaining cases depends on existence of |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | * conflicting state; so we must wait out the grace period. */ |
| 3121 | return nfserr_grace; |
| 3122 | } else if (flags & WR_STATE) |
| 3123 | return nfs4_share_conflict(current_fh, |
| 3124 | NFS4_SHARE_DENY_WRITE); |
| 3125 | else /* (flags & RD_STATE) && ZERO_STATEID(stateid) */ |
| 3126 | return nfs4_share_conflict(current_fh, |
| 3127 | NFS4_SHARE_DENY_READ); |
| 3128 | } |
| 3129 | |
| 3130 | /* |
| 3131 | * Allow READ/WRITE during grace period on recovered state only for files |
| 3132 | * that are not able to provide mandatory locking. |
| 3133 | */ |
| 3134 | static inline int |
J. Bruce Fields | 18f8273 | 2009-02-21 15:23:01 -0800 | [diff] [blame] | 3135 | grace_disallows_io(struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3136 | { |
J. Bruce Fields | 203a8c8 | 2009-02-21 13:29:14 -0800 | [diff] [blame] | 3137 | return locks_in_grace() && mandatory_lock(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3138 | } |
| 3139 | |
Andy Adamson | 6668958 | 2009-04-03 08:28:45 +0300 | [diff] [blame] | 3140 | static int check_stateid_generation(stateid_t *in, stateid_t *ref, int flags) |
J. Bruce Fields | 0836f58 | 2008-01-26 19:08:12 -0500 | [diff] [blame] | 3141 | { |
Andy Adamson | 6668958 | 2009-04-03 08:28:45 +0300 | [diff] [blame] | 3142 | /* |
| 3143 | * When sessions are used the stateid generation number is ignored |
| 3144 | * when it is zero. |
| 3145 | */ |
| 3146 | if ((flags & HAS_SESSION) && in->si_generation == 0) |
| 3147 | goto out; |
| 3148 | |
J. Bruce Fields | 0836f58 | 2008-01-26 19:08:12 -0500 | [diff] [blame] | 3149 | /* If the client sends us a stateid from the future, it's buggy: */ |
| 3150 | if (in->si_generation > ref->si_generation) |
| 3151 | return nfserr_bad_stateid; |
| 3152 | /* |
| 3153 | * The following, however, can happen. For example, if the |
| 3154 | * client sends an open and some IO at the same time, the open |
| 3155 | * may bump si_generation while the IO is still in flight. |
| 3156 | * Thanks to hard links and renames, the client never knows what |
| 3157 | * file an open will affect. So it could avoid that situation |
| 3158 | * only by serializing all opens and IO from the same open |
| 3159 | * owner. To recover from the old_stateid error, the client |
| 3160 | * will just have to retry the IO: |
| 3161 | */ |
| 3162 | if (in->si_generation < ref->si_generation) |
| 3163 | return nfserr_old_stateid; |
Andy Adamson | 6668958 | 2009-04-03 08:28:45 +0300 | [diff] [blame] | 3164 | out: |
J. Bruce Fields | 0836f58 | 2008-01-26 19:08:12 -0500 | [diff] [blame] | 3165 | return nfs_ok; |
| 3166 | } |
| 3167 | |
J. Bruce Fields | 3e63307 | 2009-02-21 13:17:19 -0800 | [diff] [blame] | 3168 | static int is_delegation_stateid(stateid_t *stateid) |
| 3169 | { |
| 3170 | return stateid->si_fileid == 0; |
| 3171 | } |
| 3172 | |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 3173 | static int is_open_stateid(struct nfs4_stateid *stateid) |
| 3174 | { |
| 3175 | return stateid->st_openstp == NULL; |
| 3176 | } |
| 3177 | |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 3178 | __be32 nfs4_validate_stateid(stateid_t *stateid, int flags) |
| 3179 | { |
| 3180 | struct nfs4_stateid *stp = NULL; |
| 3181 | __be32 status = nfserr_stale_stateid; |
| 3182 | |
| 3183 | if (STALE_STATEID(stateid)) |
| 3184 | goto out; |
| 3185 | |
| 3186 | status = nfserr_expired; |
| 3187 | stp = search_for_stateid(stateid); |
| 3188 | if (!stp) |
| 3189 | goto out; |
| 3190 | status = nfserr_bad_stateid; |
| 3191 | |
| 3192 | if (!stp->st_stateowner->so_confirmed) |
| 3193 | goto out; |
| 3194 | |
| 3195 | status = check_stateid_generation(stateid, &stp->st_stateid, flags); |
| 3196 | if (status) |
| 3197 | goto out; |
| 3198 | |
| 3199 | status = nfs_ok; |
| 3200 | out: |
| 3201 | return status; |
| 3202 | } |
| 3203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | /* |
| 3205 | * Checks for stateid operations |
| 3206 | */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3207 | __be32 |
Benny Halevy | dd453df | 2009-04-03 08:28:41 +0300 | [diff] [blame] | 3208 | nfs4_preprocess_stateid_op(struct nfsd4_compound_state *cstate, |
| 3209 | stateid_t *stateid, int flags, struct file **filpp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | { |
| 3211 | struct nfs4_stateid *stp = NULL; |
| 3212 | struct nfs4_delegation *dp = NULL; |
Benny Halevy | dd453df | 2009-04-03 08:28:41 +0300 | [diff] [blame] | 3213 | struct svc_fh *current_fh = &cstate->current_fh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | struct inode *ino = current_fh->fh_dentry->d_inode; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3215 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | if (filpp) |
| 3218 | *filpp = NULL; |
| 3219 | |
J. Bruce Fields | 18f8273 | 2009-02-21 15:23:01 -0800 | [diff] [blame] | 3220 | if (grace_disallows_io(ino)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | return nfserr_grace; |
| 3222 | |
Andy Adamson | 6668958 | 2009-04-03 08:28:45 +0300 | [diff] [blame] | 3223 | if (nfsd4_has_session(cstate)) |
| 3224 | flags |= HAS_SESSION; |
| 3225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | if (ZERO_STATEID(stateid) || ONE_STATEID(stateid)) |
| 3227 | return check_special_stateids(current_fh, stateid, flags); |
| 3228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | status = nfserr_stale_stateid; |
| 3230 | if (STALE_STATEID(stateid)) |
| 3231 | goto out; |
| 3232 | |
J. Bruce Fields | 3351514 | 2010-10-02 18:42:39 -0400 | [diff] [blame] | 3233 | /* |
| 3234 | * We assume that any stateid that has the current boot time, |
| 3235 | * but that we can't find, is expired: |
| 3236 | */ |
| 3237 | status = nfserr_expired; |
J. Bruce Fields | 3e63307 | 2009-02-21 13:17:19 -0800 | [diff] [blame] | 3238 | if (is_delegation_stateid(stateid)) { |
J. Bruce Fields | a4455be | 2009-02-21 10:40:22 -0800 | [diff] [blame] | 3239 | dp = find_delegation_stateid(ino, stateid); |
J. Bruce Fields | e4e83ea | 2010-04-22 16:21:39 -0400 | [diff] [blame] | 3240 | if (!dp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3241 | goto out; |
Andy Adamson | 6668958 | 2009-04-03 08:28:45 +0300 | [diff] [blame] | 3242 | status = check_stateid_generation(stateid, &dp->dl_stateid, |
| 3243 | flags); |
J. Bruce Fields | 0c2a498 | 2009-02-21 11:11:50 -0800 | [diff] [blame] | 3244 | if (status) |
| 3245 | goto out; |
J. Bruce Fields | dc9bf70 | 2009-02-21 11:14:43 -0800 | [diff] [blame] | 3246 | status = nfs4_check_delegmode(dp, flags); |
| 3247 | if (status) |
| 3248 | goto out; |
| 3249 | renew_client(dp->dl_client); |
Dan Carpenter | 43b0178 | 2010-10-27 23:19:04 +0200 | [diff] [blame] | 3250 | if (filpp) { |
J. Bruce Fields | acfdf5c | 2011-01-31 19:20:39 -0500 | [diff] [blame] | 3251 | *filpp = dp->dl_file->fi_deleg_file; |
Dan Carpenter | 43b0178 | 2010-10-27 23:19:04 +0200 | [diff] [blame] | 3252 | BUG_ON(!*filpp); |
| 3253 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | } else { /* open or lock stateid */ |
J. Bruce Fields | a4455be | 2009-02-21 10:40:22 -0800 | [diff] [blame] | 3255 | stp = find_stateid(stateid, flags); |
J. Bruce Fields | e4e83ea | 2010-04-22 16:21:39 -0400 | [diff] [blame] | 3256 | if (!stp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3257 | goto out; |
J. Bruce Fields | 3351514 | 2010-10-02 18:42:39 -0400 | [diff] [blame] | 3258 | status = nfserr_bad_stateid; |
J. Bruce Fields | 6150ef0 | 2009-02-21 13:36:16 -0800 | [diff] [blame] | 3259 | if (nfs4_check_fh(current_fh, stp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | goto out; |
| 3261 | if (!stp->st_stateowner->so_confirmed) |
| 3262 | goto out; |
Andy Adamson | 6668958 | 2009-04-03 08:28:45 +0300 | [diff] [blame] | 3263 | status = check_stateid_generation(stateid, &stp->st_stateid, |
| 3264 | flags); |
J. Bruce Fields | 0c2a498 | 2009-02-21 11:11:50 -0800 | [diff] [blame] | 3265 | if (status) |
| 3266 | goto out; |
J. Bruce Fields | a4455be | 2009-02-21 10:40:22 -0800 | [diff] [blame] | 3267 | status = nfs4_check_openmode(stp, flags); |
| 3268 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3269 | goto out; |
| 3270 | renew_client(stp->st_stateowner->so_client); |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 3271 | if (filpp) { |
| 3272 | if (flags & RD_STATE) |
| 3273 | *filpp = find_readable_file(stp->st_file); |
| 3274 | else |
| 3275 | *filpp = find_writeable_file(stp->st_file); |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 3276 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3277 | } |
| 3278 | status = nfs_ok; |
| 3279 | out: |
| 3280 | return status; |
| 3281 | } |
| 3282 | |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 3283 | static __be32 |
| 3284 | nfsd4_free_delegation_stateid(stateid_t *stateid) |
| 3285 | { |
| 3286 | struct nfs4_delegation *dp = search_for_delegation(stateid); |
| 3287 | if (dp) |
| 3288 | return nfserr_locks_held; |
| 3289 | return nfserr_bad_stateid; |
| 3290 | } |
| 3291 | |
| 3292 | static __be32 |
| 3293 | nfsd4_free_lock_stateid(struct nfs4_stateid *stp) |
| 3294 | { |
| 3295 | if (check_for_locks(stp->st_file, stp->st_stateowner)) |
| 3296 | return nfserr_locks_held; |
| 3297 | release_lock_stateid(stp); |
| 3298 | return nfs_ok; |
| 3299 | } |
| 3300 | |
| 3301 | /* |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 3302 | * Test if the stateid is valid |
| 3303 | */ |
| 3304 | __be32 |
| 3305 | nfsd4_test_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
| 3306 | struct nfsd4_test_stateid *test_stateid) |
| 3307 | { |
| 3308 | test_stateid->ts_has_session = nfsd4_has_session(cstate); |
| 3309 | return nfs_ok; |
| 3310 | } |
| 3311 | |
| 3312 | /* |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 3313 | * Free a state id |
| 3314 | */ |
| 3315 | __be32 |
| 3316 | nfsd4_free_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
| 3317 | struct nfsd4_free_stateid *free_stateid) |
| 3318 | { |
| 3319 | stateid_t *stateid = &free_stateid->fr_stateid; |
| 3320 | struct nfs4_stateid *stp; |
| 3321 | __be32 ret; |
| 3322 | |
| 3323 | nfs4_lock_state(); |
| 3324 | if (is_delegation_stateid(stateid)) { |
| 3325 | ret = nfsd4_free_delegation_stateid(stateid); |
| 3326 | goto out; |
| 3327 | } |
| 3328 | |
| 3329 | stp = search_for_stateid(stateid); |
| 3330 | if (!stp) { |
| 3331 | ret = nfserr_bad_stateid; |
| 3332 | goto out; |
| 3333 | } |
| 3334 | if (stateid->si_generation != 0) { |
| 3335 | if (stateid->si_generation < stp->st_stateid.si_generation) { |
| 3336 | ret = nfserr_old_stateid; |
| 3337 | goto out; |
| 3338 | } |
| 3339 | if (stateid->si_generation > stp->st_stateid.si_generation) { |
| 3340 | ret = nfserr_bad_stateid; |
| 3341 | goto out; |
| 3342 | } |
| 3343 | } |
| 3344 | |
| 3345 | if (is_open_stateid(stp)) { |
| 3346 | ret = nfserr_locks_held; |
| 3347 | goto out; |
| 3348 | } else { |
| 3349 | ret = nfsd4_free_lock_stateid(stp); |
| 3350 | goto out; |
| 3351 | } |
| 3352 | |
| 3353 | out: |
| 3354 | nfs4_unlock_state(); |
| 3355 | return ret; |
| 3356 | } |
| 3357 | |
NeilBrown | 4c4cd22 | 2005-07-07 17:59:27 -0700 | [diff] [blame] | 3358 | static inline int |
| 3359 | setlkflg (int type) |
| 3360 | { |
| 3361 | return (type == NFS4_READW_LT || type == NFS4_READ_LT) ? |
| 3362 | RD_STATE : WR_STATE; |
| 3363 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3364 | |
| 3365 | /* |
| 3366 | * Checks for sequence id mutating operations. |
| 3367 | */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3368 | static __be32 |
Benny Halevy | dd453df | 2009-04-03 08:28:41 +0300 | [diff] [blame] | 3369 | nfs4_preprocess_seqid_op(struct nfsd4_compound_state *cstate, u32 seqid, |
| 3370 | stateid_t *stateid, int flags, |
| 3371 | struct nfs4_stateowner **sopp, |
| 3372 | struct nfs4_stateid **stpp, struct nfsd4_lock *lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | struct nfs4_stateid *stp; |
| 3375 | struct nfs4_stateowner *sop; |
Benny Halevy | dd453df | 2009-04-03 08:28:41 +0300 | [diff] [blame] | 3376 | struct svc_fh *current_fh = &cstate->current_fh; |
J. Bruce Fields | 0836f58 | 2008-01-26 19:08:12 -0500 | [diff] [blame] | 3377 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3378 | |
Benny Halevy | 8c10cbd | 2009-10-19 12:04:53 +0200 | [diff] [blame] | 3379 | dprintk("NFSD: %s: seqid=%d stateid = " STATEID_FMT "\n", __func__, |
| 3380 | seqid, STATEID_VAL(stateid)); |
NeilBrown | 3a4f98b | 2005-07-07 17:59:26 -0700 | [diff] [blame] | 3381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3382 | *stpp = NULL; |
| 3383 | *sopp = NULL; |
| 3384 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3385 | if (ZERO_STATEID(stateid) || ONE_STATEID(stateid)) { |
J. Bruce Fields | 2fdada0 | 2007-07-27 16:10:37 -0400 | [diff] [blame] | 3386 | dprintk("NFSD: preprocess_seqid_op: magic stateid!\n"); |
NeilBrown | 3a4f98b | 2005-07-07 17:59:26 -0700 | [diff] [blame] | 3387 | return nfserr_bad_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | } |
| 3389 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | if (STALE_STATEID(stateid)) |
NeilBrown | 3a4f98b | 2005-07-07 17:59:26 -0700 | [diff] [blame] | 3391 | return nfserr_stale_stateid; |
Andy Adamson | 6668958 | 2009-04-03 08:28:45 +0300 | [diff] [blame] | 3392 | |
| 3393 | if (nfsd4_has_session(cstate)) |
| 3394 | flags |= HAS_SESSION; |
| 3395 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | /* |
| 3397 | * We return BAD_STATEID if filehandle doesn't match stateid, |
| 3398 | * the confirmed flag is incorrecly set, or the generation |
| 3399 | * number is incorrect. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3400 | */ |
NeilBrown | f881651 | 2005-07-07 17:59:25 -0700 | [diff] [blame] | 3401 | stp = find_stateid(stateid, flags); |
| 3402 | if (stp == NULL) { |
| 3403 | /* |
| 3404 | * Also, we should make sure this isn't just the result of |
| 3405 | * a replayed close: |
| 3406 | */ |
| 3407 | sop = search_close_lru(stateid->si_stateownerid, flags); |
J. Bruce Fields | 3351514 | 2010-10-02 18:42:39 -0400 | [diff] [blame] | 3408 | /* It's not stale; let's assume it's expired: */ |
NeilBrown | f881651 | 2005-07-07 17:59:25 -0700 | [diff] [blame] | 3409 | if (sop == NULL) |
J. Bruce Fields | 3351514 | 2010-10-02 18:42:39 -0400 | [diff] [blame] | 3410 | return nfserr_expired; |
NeilBrown | f881651 | 2005-07-07 17:59:25 -0700 | [diff] [blame] | 3411 | *sopp = sop; |
| 3412 | goto check_replay; |
| 3413 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3414 | |
J. Bruce Fields | 39325bd | 2007-11-26 17:06:39 -0500 | [diff] [blame] | 3415 | *stpp = stp; |
| 3416 | *sopp = sop = stp->st_stateowner; |
| 3417 | |
NeilBrown | 4c4cd22 | 2005-07-07 17:59:27 -0700 | [diff] [blame] | 3418 | if (lock) { |
NeilBrown | 4c4cd22 | 2005-07-07 17:59:27 -0700 | [diff] [blame] | 3419 | clientid_t *lockclid = &lock->v.new.clientid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | struct nfs4_client *clp = sop->so_client; |
NeilBrown | 4c4cd22 | 2005-07-07 17:59:27 -0700 | [diff] [blame] | 3421 | int lkflg = 0; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3422 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3423 | |
NeilBrown | 4c4cd22 | 2005-07-07 17:59:27 -0700 | [diff] [blame] | 3424 | lkflg = setlkflg(lock->lk_type); |
| 3425 | |
| 3426 | if (lock->lk_is_new) { |
J. Bruce Fields | 599e0a2 | 2007-07-26 17:04:54 -0400 | [diff] [blame] | 3427 | if (!sop->so_is_open_owner) |
| 3428 | return nfserr_bad_stateid; |
Andy Adamson | 60adfc5 | 2009-04-03 08:28:50 +0300 | [diff] [blame] | 3429 | if (!(flags & HAS_SESSION) && |
| 3430 | !same_clid(&clp->cl_clientid, lockclid)) |
| 3431 | return nfserr_bad_stateid; |
J. Bruce Fields | 599e0a2 | 2007-07-26 17:04:54 -0400 | [diff] [blame] | 3432 | /* stp is the open stateid */ |
| 3433 | status = nfs4_check_openmode(stp, lkflg); |
| 3434 | if (status) |
| 3435 | return status; |
| 3436 | } else { |
| 3437 | /* stp is the lock stateid */ |
| 3438 | status = nfs4_check_openmode(stp->st_openstp, lkflg); |
| 3439 | if (status) |
| 3440 | return status; |
NeilBrown | 4c4cd22 | 2005-07-07 17:59:27 -0700 | [diff] [blame] | 3441 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3442 | } |
| 3443 | |
J. Bruce Fields | f336273 | 2008-01-26 14:58:45 -0500 | [diff] [blame] | 3444 | if (nfs4_check_fh(current_fh, stp)) { |
J. Bruce Fields | 2fdada0 | 2007-07-27 16:10:37 -0400 | [diff] [blame] | 3445 | dprintk("NFSD: preprocess_seqid_op: fh-stateid mismatch!\n"); |
NeilBrown | 3a4f98b | 2005-07-07 17:59:26 -0700 | [diff] [blame] | 3446 | return nfserr_bad_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3447 | } |
| 3448 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3449 | /* |
| 3450 | * We now validate the seqid and stateid generation numbers. |
| 3451 | * For the moment, we ignore the possibility of |
| 3452 | * generation number wraparound. |
| 3453 | */ |
Andy Adamson | 6668958 | 2009-04-03 08:28:45 +0300 | [diff] [blame] | 3454 | if (!(flags & HAS_SESSION) && seqid != sop->so_seqid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | goto check_replay; |
| 3456 | |
NeilBrown | 3a4f98b | 2005-07-07 17:59:26 -0700 | [diff] [blame] | 3457 | if (sop->so_confirmed && flags & CONFIRM) { |
J. Bruce Fields | 2fdada0 | 2007-07-27 16:10:37 -0400 | [diff] [blame] | 3458 | dprintk("NFSD: preprocess_seqid_op: expected" |
NeilBrown | 3a4f98b | 2005-07-07 17:59:26 -0700 | [diff] [blame] | 3459 | " unconfirmed stateowner!\n"); |
| 3460 | return nfserr_bad_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3461 | } |
NeilBrown | 3a4f98b | 2005-07-07 17:59:26 -0700 | [diff] [blame] | 3462 | if (!sop->so_confirmed && !(flags & CONFIRM)) { |
J. Bruce Fields | 2fdada0 | 2007-07-27 16:10:37 -0400 | [diff] [blame] | 3463 | dprintk("NFSD: preprocess_seqid_op: stateowner not" |
NeilBrown | 3a4f98b | 2005-07-07 17:59:26 -0700 | [diff] [blame] | 3464 | " confirmed yet!\n"); |
| 3465 | return nfserr_bad_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | } |
Andy Adamson | 6668958 | 2009-04-03 08:28:45 +0300 | [diff] [blame] | 3467 | status = check_stateid_generation(stateid, &stp->st_stateid, flags); |
J. Bruce Fields | 0836f58 | 2008-01-26 19:08:12 -0500 | [diff] [blame] | 3468 | if (status) |
| 3469 | return status; |
NeilBrown | 52fd004 | 2005-07-07 17:59:24 -0700 | [diff] [blame] | 3470 | renew_client(sop->so_client); |
NeilBrown | 3a4f98b | 2005-07-07 17:59:26 -0700 | [diff] [blame] | 3471 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3473 | check_replay: |
NeilBrown | bd9aac5 | 2005-07-07 17:59:19 -0700 | [diff] [blame] | 3474 | if (seqid == sop->so_seqid - 1) { |
Neil Brown | 849823c | 2005-09-13 01:25:36 -0700 | [diff] [blame] | 3475 | dprintk("NFSD: preprocess_seqid_op: retransmission?\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3476 | /* indicate replay to calling function */ |
Al Viro | a90b061 | 2006-10-19 23:29:03 -0700 | [diff] [blame] | 3477 | return nfserr_replay_me; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | } |
J. Bruce Fields | 2fdada0 | 2007-07-27 16:10:37 -0400 | [diff] [blame] | 3479 | dprintk("NFSD: preprocess_seqid_op: bad seqid (expected %d, got %d)\n", |
NeilBrown | 3a4f98b | 2005-07-07 17:59:26 -0700 | [diff] [blame] | 3480 | sop->so_seqid, seqid); |
| 3481 | *sopp = NULL; |
| 3482 | return nfserr_bad_seqid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3483 | } |
| 3484 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3485 | __be32 |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 3486 | nfsd4_open_confirm(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
J.Bruce Fields | a4f1706a9 | 2006-12-13 00:35:28 -0800 | [diff] [blame] | 3487 | struct nfsd4_open_confirm *oc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3488 | { |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3489 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3490 | struct nfs4_stateowner *sop; |
| 3491 | struct nfs4_stateid *stp; |
| 3492 | |
| 3493 | dprintk("NFSD: nfsd4_open_confirm on file %.*s\n", |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 3494 | (int)cstate->current_fh.fh_dentry->d_name.len, |
| 3495 | cstate->current_fh.fh_dentry->d_name.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 3497 | status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0); |
J. Bruce Fields | a8cddc5 | 2006-06-30 01:56:13 -0700 | [diff] [blame] | 3498 | if (status) |
| 3499 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | |
| 3501 | nfs4_lock_state(); |
| 3502 | |
Benny Halevy | dd453df | 2009-04-03 08:28:41 +0300 | [diff] [blame] | 3503 | if ((status = nfs4_preprocess_seqid_op(cstate, |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 3504 | oc->oc_seqid, &oc->oc_req_stateid, |
J. Bruce Fields | f336273 | 2008-01-26 14:58:45 -0500 | [diff] [blame] | 3505 | CONFIRM | OPEN_STATE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3506 | &oc->oc_stateowner, &stp, NULL))) |
| 3507 | goto out; |
| 3508 | |
| 3509 | sop = oc->oc_stateowner; |
| 3510 | sop->so_confirmed = 1; |
| 3511 | update_stateid(&stp->st_stateid); |
| 3512 | memcpy(&oc->oc_resp_stateid, &stp->st_stateid, sizeof(stateid_t)); |
Benny Halevy | 8c10cbd | 2009-10-19 12:04:53 +0200 | [diff] [blame] | 3513 | dprintk("NFSD: %s: success, seqid=%d stateid=" STATEID_FMT "\n", |
| 3514 | __func__, oc->oc_seqid, STATEID_VAL(&stp->st_stateid)); |
NeilBrown | c7b9a45 | 2005-06-23 22:04:30 -0700 | [diff] [blame] | 3515 | |
| 3516 | nfsd4_create_clid_dir(sop->so_client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3517 | out: |
Neil Brown | f2327d9 | 2005-09-13 01:25:37 -0700 | [diff] [blame] | 3518 | if (oc->oc_stateowner) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3519 | nfs4_get_stateowner(oc->oc_stateowner); |
J.Bruce Fields | a4f1706a9 | 2006-12-13 00:35:28 -0800 | [diff] [blame] | 3520 | cstate->replay_owner = oc->oc_stateowner; |
Neil Brown | f2327d9 | 2005-09-13 01:25:37 -0700 | [diff] [blame] | 3521 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3522 | nfs4_unlock_state(); |
| 3523 | return status; |
| 3524 | } |
| 3525 | |
J. Bruce Fields | f197c27 | 2011-06-29 08:23:50 -0400 | [diff] [blame] | 3526 | static inline void nfs4_file_downgrade(struct nfs4_stateid *stp, unsigned int to_access) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3527 | { |
| 3528 | int i; |
J. Bruce Fields | f197c27 | 2011-06-29 08:23:50 -0400 | [diff] [blame] | 3529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3530 | for (i = 1; i < 4; i++) { |
J. Bruce Fields | f197c27 | 2011-06-29 08:23:50 -0400 | [diff] [blame] | 3531 | if (test_bit(i, &stp->st_access_bmap) && !(i & to_access)) { |
| 3532 | nfs4_file_put_access(stp->st_file, i); |
| 3533 | __clear_bit(i, &stp->st_access_bmap); |
| 3534 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | } |
| 3536 | } |
| 3537 | |
| 3538 | static void |
| 3539 | reset_union_bmap_deny(unsigned long deny, unsigned long *bmap) |
| 3540 | { |
| 3541 | int i; |
| 3542 | for (i = 0; i < 4; i++) { |
| 3543 | if ((i & deny) != i) |
| 3544 | __clear_bit(i, bmap); |
| 3545 | } |
| 3546 | } |
| 3547 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3548 | __be32 |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 3549 | nfsd4_open_downgrade(struct svc_rqst *rqstp, |
| 3550 | struct nfsd4_compound_state *cstate, |
J.Bruce Fields | a4f1706a9 | 2006-12-13 00:35:28 -0800 | [diff] [blame] | 3551 | struct nfsd4_open_downgrade *od) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3552 | { |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3553 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3554 | struct nfs4_stateid *stp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | |
| 3556 | dprintk("NFSD: nfsd4_open_downgrade on file %.*s\n", |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 3557 | (int)cstate->current_fh.fh_dentry->d_name.len, |
| 3558 | cstate->current_fh.fh_dentry->d_name.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3559 | |
Andy Adamson | d87a8ad | 2009-04-03 08:28:53 +0300 | [diff] [blame] | 3560 | if (!access_valid(od->od_share_access, cstate->minorversion) |
J. Bruce Fields | ba5a6a1 | 2006-06-30 01:56:16 -0700 | [diff] [blame] | 3561 | || !deny_valid(od->od_share_deny)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3562 | return nfserr_inval; |
| 3563 | |
| 3564 | nfs4_lock_state(); |
Benny Halevy | dd453df | 2009-04-03 08:28:41 +0300 | [diff] [blame] | 3565 | if ((status = nfs4_preprocess_seqid_op(cstate, |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 3566 | od->od_seqid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3567 | &od->od_stateid, |
J. Bruce Fields | f336273 | 2008-01-26 14:58:45 -0500 | [diff] [blame] | 3568 | OPEN_STATE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3569 | &od->od_stateowner, &stp, NULL))) |
| 3570 | goto out; |
| 3571 | |
| 3572 | status = nfserr_inval; |
| 3573 | if (!test_bit(od->od_share_access, &stp->st_access_bmap)) { |
| 3574 | dprintk("NFSD:access not a subset current bitmap: 0x%lx, input access=%08x\n", |
| 3575 | stp->st_access_bmap, od->od_share_access); |
| 3576 | goto out; |
| 3577 | } |
| 3578 | if (!test_bit(od->od_share_deny, &stp->st_deny_bmap)) { |
| 3579 | dprintk("NFSD:deny not a subset current bitmap: 0x%lx, input deny=%08x\n", |
| 3580 | stp->st_deny_bmap, od->od_share_deny); |
| 3581 | goto out; |
| 3582 | } |
J. Bruce Fields | f197c27 | 2011-06-29 08:23:50 -0400 | [diff] [blame] | 3583 | nfs4_file_downgrade(stp, od->od_share_access); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3584 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | reset_union_bmap_deny(od->od_share_deny, &stp->st_deny_bmap); |
| 3586 | |
| 3587 | update_stateid(&stp->st_stateid); |
| 3588 | memcpy(&od->od_stateid, &stp->st_stateid, sizeof(stateid_t)); |
| 3589 | status = nfs_ok; |
| 3590 | out: |
Neil Brown | f2327d9 | 2005-09-13 01:25:37 -0700 | [diff] [blame] | 3591 | if (od->od_stateowner) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3592 | nfs4_get_stateowner(od->od_stateowner); |
J.Bruce Fields | a4f1706a9 | 2006-12-13 00:35:28 -0800 | [diff] [blame] | 3593 | cstate->replay_owner = od->od_stateowner; |
Neil Brown | f2327d9 | 2005-09-13 01:25:37 -0700 | [diff] [blame] | 3594 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | nfs4_unlock_state(); |
| 3596 | return status; |
| 3597 | } |
| 3598 | |
| 3599 | /* |
| 3600 | * nfs4_unlock_state() called after encode |
| 3601 | */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3602 | __be32 |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 3603 | nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
J.Bruce Fields | a4f1706a9 | 2006-12-13 00:35:28 -0800 | [diff] [blame] | 3604 | struct nfsd4_close *close) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3605 | { |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3606 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3607 | struct nfs4_stateid *stp; |
| 3608 | |
| 3609 | dprintk("NFSD: nfsd4_close on file %.*s\n", |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 3610 | (int)cstate->current_fh.fh_dentry->d_name.len, |
| 3611 | cstate->current_fh.fh_dentry->d_name.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3612 | |
| 3613 | nfs4_lock_state(); |
| 3614 | /* check close_lru for replay */ |
Benny Halevy | dd453df | 2009-04-03 08:28:41 +0300 | [diff] [blame] | 3615 | if ((status = nfs4_preprocess_seqid_op(cstate, |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 3616 | close->cl_seqid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3617 | &close->cl_stateid, |
J. Bruce Fields | f336273 | 2008-01-26 14:58:45 -0500 | [diff] [blame] | 3618 | OPEN_STATE | CLOSE_STATE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | &close->cl_stateowner, &stp, NULL))) |
| 3620 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3621 | status = nfs_ok; |
| 3622 | update_stateid(&stp->st_stateid); |
| 3623 | memcpy(&close->cl_stateid, &stp->st_stateid, sizeof(stateid_t)); |
| 3624 | |
J. Bruce Fields | 04ef595 | 2006-01-18 17:43:21 -0800 | [diff] [blame] | 3625 | /* release_stateid() calls nfsd_close() if needed */ |
J. Bruce Fields | 2283963 | 2009-01-11 14:27:17 -0500 | [diff] [blame] | 3626 | release_open_stateid(stp); |
J. Bruce Fields | 04ef595 | 2006-01-18 17:43:21 -0800 | [diff] [blame] | 3627 | |
| 3628 | /* place unused nfs4_stateowners on so_close_lru list to be |
| 3629 | * released by the laundromat service after the lease period |
| 3630 | * to enable us to handle CLOSE replay |
| 3631 | */ |
| 3632 | if (list_empty(&close->cl_stateowner->so_stateids)) |
| 3633 | move_to_close_lru(close->cl_stateowner); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3634 | out: |
Neil Brown | f2327d9 | 2005-09-13 01:25:37 -0700 | [diff] [blame] | 3635 | if (close->cl_stateowner) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3636 | nfs4_get_stateowner(close->cl_stateowner); |
J.Bruce Fields | a4f1706a9 | 2006-12-13 00:35:28 -0800 | [diff] [blame] | 3637 | cstate->replay_owner = close->cl_stateowner; |
Neil Brown | f2327d9 | 2005-09-13 01:25:37 -0700 | [diff] [blame] | 3638 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3639 | nfs4_unlock_state(); |
| 3640 | return status; |
| 3641 | } |
| 3642 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3643 | __be32 |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 3644 | nfsd4_delegreturn(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
| 3645 | struct nfsd4_delegreturn *dr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3646 | { |
J. Bruce Fields | 203a8c8 | 2009-02-21 13:29:14 -0800 | [diff] [blame] | 3647 | struct nfs4_delegation *dp; |
| 3648 | stateid_t *stateid = &dr->dr_stateid; |
| 3649 | struct inode *inode; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3650 | __be32 status; |
Andy Adamson | 6668958 | 2009-04-03 08:28:45 +0300 | [diff] [blame] | 3651 | int flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 3653 | if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0))) |
J. Bruce Fields | 203a8c8 | 2009-02-21 13:29:14 -0800 | [diff] [blame] | 3654 | return status; |
| 3655 | inode = cstate->current_fh.fh_dentry->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3656 | |
Andy Adamson | 6668958 | 2009-04-03 08:28:45 +0300 | [diff] [blame] | 3657 | if (nfsd4_has_session(cstate)) |
| 3658 | flags |= HAS_SESSION; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3659 | nfs4_lock_state(); |
J. Bruce Fields | 203a8c8 | 2009-02-21 13:29:14 -0800 | [diff] [blame] | 3660 | status = nfserr_bad_stateid; |
| 3661 | if (ZERO_STATEID(stateid) || ONE_STATEID(stateid)) |
| 3662 | goto out; |
| 3663 | status = nfserr_stale_stateid; |
| 3664 | if (STALE_STATEID(stateid)) |
| 3665 | goto out; |
J. Bruce Fields | 7e0f7cf | 2009-02-21 13:32:28 -0800 | [diff] [blame] | 3666 | status = nfserr_bad_stateid; |
J. Bruce Fields | 203a8c8 | 2009-02-21 13:29:14 -0800 | [diff] [blame] | 3667 | if (!is_delegation_stateid(stateid)) |
| 3668 | goto out; |
J. Bruce Fields | 3351514 | 2010-10-02 18:42:39 -0400 | [diff] [blame] | 3669 | status = nfserr_expired; |
J. Bruce Fields | 203a8c8 | 2009-02-21 13:29:14 -0800 | [diff] [blame] | 3670 | dp = find_delegation_stateid(inode, stateid); |
J. Bruce Fields | e4e83ea | 2010-04-22 16:21:39 -0400 | [diff] [blame] | 3671 | if (!dp) |
J. Bruce Fields | 203a8c8 | 2009-02-21 13:29:14 -0800 | [diff] [blame] | 3672 | goto out; |
Andy Adamson | 6668958 | 2009-04-03 08:28:45 +0300 | [diff] [blame] | 3673 | status = check_stateid_generation(stateid, &dp->dl_stateid, flags); |
J. Bruce Fields | 203a8c8 | 2009-02-21 13:29:14 -0800 | [diff] [blame] | 3674 | if (status) |
| 3675 | goto out; |
| 3676 | renew_client(dp->dl_client); |
| 3677 | |
| 3678 | unhash_delegation(dp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3679 | out: |
J. Bruce Fields | 203a8c8 | 2009-02-21 13:29:14 -0800 | [diff] [blame] | 3680 | nfs4_unlock_state(); |
| 3681 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3682 | return status; |
| 3683 | } |
| 3684 | |
| 3685 | |
| 3686 | /* |
| 3687 | * Lock owner state (byte-range locks) |
| 3688 | */ |
| 3689 | #define LOFF_OVERFLOW(start, len) ((u64)(len) > ~(u64)(start)) |
| 3690 | #define LOCK_HASH_BITS 8 |
| 3691 | #define LOCK_HASH_SIZE (1 << LOCK_HASH_BITS) |
| 3692 | #define LOCK_HASH_MASK (LOCK_HASH_SIZE - 1) |
| 3693 | |
Benny Halevy | 87df4de | 2008-12-15 19:42:03 +0200 | [diff] [blame] | 3694 | static inline u64 |
| 3695 | end_offset(u64 start, u64 len) |
| 3696 | { |
| 3697 | u64 end; |
| 3698 | |
| 3699 | end = start + len; |
| 3700 | return end >= start ? end: NFS4_MAX_UINT64; |
| 3701 | } |
| 3702 | |
| 3703 | /* last octet in a range */ |
| 3704 | static inline u64 |
| 3705 | last_byte_offset(u64 start, u64 len) |
| 3706 | { |
| 3707 | u64 end; |
| 3708 | |
| 3709 | BUG_ON(!len); |
| 3710 | end = start + len; |
| 3711 | return end > start ? end - 1: NFS4_MAX_UINT64; |
| 3712 | } |
| 3713 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3714 | #define lockownerid_hashval(id) \ |
| 3715 | ((id) & LOCK_HASH_MASK) |
| 3716 | |
| 3717 | static inline unsigned int |
| 3718 | lock_ownerstr_hashval(struct inode *inode, u32 cl_id, |
| 3719 | struct xdr_netobj *ownername) |
| 3720 | { |
| 3721 | return (file_hashval(inode) + cl_id |
| 3722 | + opaque_hashval(ownername->data, ownername->len)) |
| 3723 | & LOCK_HASH_MASK; |
| 3724 | } |
| 3725 | |
| 3726 | static struct list_head lock_ownerid_hashtbl[LOCK_HASH_SIZE]; |
| 3727 | static struct list_head lock_ownerstr_hashtbl[LOCK_HASH_SIZE]; |
| 3728 | static struct list_head lockstateid_hashtbl[STATEID_HASH_SIZE]; |
| 3729 | |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 3730 | static int |
| 3731 | same_stateid(stateid_t *id_one, stateid_t *id_two) |
| 3732 | { |
| 3733 | if (id_one->si_stateownerid != id_two->si_stateownerid) |
| 3734 | return 0; |
| 3735 | return id_one->si_fileid == id_two->si_fileid; |
| 3736 | } |
| 3737 | |
NeilBrown | fd39ca9 | 2005-06-23 22:04:03 -0700 | [diff] [blame] | 3738 | static struct nfs4_stateid * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3739 | find_stateid(stateid_t *stid, int flags) |
| 3740 | { |
Krishna Kumar | 9346eff | 2008-10-20 11:44:28 +0530 | [diff] [blame] | 3741 | struct nfs4_stateid *local; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3742 | u32 st_id = stid->si_stateownerid; |
| 3743 | u32 f_id = stid->si_fileid; |
| 3744 | unsigned int hashval; |
| 3745 | |
| 3746 | dprintk("NFSD: find_stateid flags 0x%x\n",flags); |
Krishna Kumar | 9346eff | 2008-10-20 11:44:28 +0530 | [diff] [blame] | 3747 | if (flags & (LOCK_STATE | RD_STATE | WR_STATE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3748 | hashval = stateid_hashval(st_id, f_id); |
| 3749 | list_for_each_entry(local, &lockstateid_hashtbl[hashval], st_hash) { |
| 3750 | if ((local->st_stateid.si_stateownerid == st_id) && |
| 3751 | (local->st_stateid.si_fileid == f_id)) |
| 3752 | return local; |
| 3753 | } |
| 3754 | } |
Krishna Kumar | 9346eff | 2008-10-20 11:44:28 +0530 | [diff] [blame] | 3755 | |
| 3756 | if (flags & (OPEN_STATE | RD_STATE | WR_STATE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3757 | hashval = stateid_hashval(st_id, f_id); |
| 3758 | list_for_each_entry(local, &stateid_hashtbl[hashval], st_hash) { |
| 3759 | if ((local->st_stateid.si_stateownerid == st_id) && |
| 3760 | (local->st_stateid.si_fileid == f_id)) |
| 3761 | return local; |
| 3762 | } |
Neil Brown | 849823c | 2005-09-13 01:25:36 -0700 | [diff] [blame] | 3763 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3764 | return NULL; |
| 3765 | } |
| 3766 | |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 3767 | static struct nfs4_stateid * |
| 3768 | search_for_stateid(stateid_t *stid) |
| 3769 | { |
| 3770 | struct nfs4_stateid *local; |
| 3771 | unsigned int hashval = stateid_hashval(stid->si_stateownerid, stid->si_fileid); |
| 3772 | |
| 3773 | list_for_each_entry(local, &lockstateid_hashtbl[hashval], st_hash) { |
| 3774 | if (same_stateid(&local->st_stateid, stid)) |
| 3775 | return local; |
| 3776 | } |
| 3777 | |
| 3778 | list_for_each_entry(local, &stateid_hashtbl[hashval], st_hash) { |
| 3779 | if (same_stateid(&local->st_stateid, stid)) |
| 3780 | return local; |
| 3781 | } |
| 3782 | return NULL; |
| 3783 | } |
| 3784 | |
| 3785 | static struct nfs4_delegation * |
| 3786 | search_for_delegation(stateid_t *stid) |
| 3787 | { |
| 3788 | struct nfs4_file *fp; |
| 3789 | struct nfs4_delegation *dp; |
| 3790 | struct list_head *pos; |
| 3791 | int i; |
| 3792 | |
| 3793 | for (i = 0; i < FILE_HASH_SIZE; i++) { |
| 3794 | list_for_each_entry(fp, &file_hashtbl[i], fi_hash) { |
| 3795 | list_for_each(pos, &fp->fi_delegations) { |
| 3796 | dp = list_entry(pos, struct nfs4_delegation, dl_perfile); |
| 3797 | if (same_stateid(&dp->dl_stateid, stid)) |
| 3798 | return dp; |
| 3799 | } |
| 3800 | } |
| 3801 | } |
| 3802 | return NULL; |
| 3803 | } |
| 3804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3805 | static struct nfs4_delegation * |
| 3806 | find_delegation_stateid(struct inode *ino, stateid_t *stid) |
| 3807 | { |
NeilBrown | 13cd218 | 2005-06-23 22:03:10 -0700 | [diff] [blame] | 3808 | struct nfs4_file *fp; |
| 3809 | struct nfs4_delegation *dl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3810 | |
Benny Halevy | 8c10cbd | 2009-10-19 12:04:53 +0200 | [diff] [blame] | 3811 | dprintk("NFSD: %s: stateid=" STATEID_FMT "\n", __func__, |
| 3812 | STATEID_VAL(stid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | fp = find_file(ino); |
NeilBrown | 13cd218 | 2005-06-23 22:03:10 -0700 | [diff] [blame] | 3815 | if (!fp) |
| 3816 | return NULL; |
| 3817 | dl = find_delegation_file(fp, stid); |
| 3818 | put_nfs4_file(fp); |
| 3819 | return dl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3820 | } |
| 3821 | |
| 3822 | /* |
| 3823 | * TODO: Linux file offsets are _signed_ 64-bit quantities, which means that |
| 3824 | * we can't properly handle lock requests that go beyond the (2^63 - 1)-th |
| 3825 | * byte, because of sign extension problems. Since NFSv4 calls for 64-bit |
| 3826 | * locking, this prevents us from being completely protocol-compliant. The |
| 3827 | * real solution to this problem is to start using unsigned file offsets in |
| 3828 | * the VFS, but this is a very deep change! |
| 3829 | */ |
| 3830 | static inline void |
| 3831 | nfs4_transform_lock_offset(struct file_lock *lock) |
| 3832 | { |
| 3833 | if (lock->fl_start < 0) |
| 3834 | lock->fl_start = OFFSET_MAX; |
| 3835 | if (lock->fl_end < 0) |
| 3836 | lock->fl_end = OFFSET_MAX; |
| 3837 | } |
| 3838 | |
NeilBrown | d5b9026 | 2006-04-10 22:55:22 -0700 | [diff] [blame] | 3839 | /* Hack!: For now, we're defining this just so we can use a pointer to it |
| 3840 | * as a unique cookie to identify our (NFSv4's) posix locks. */ |
Alexey Dobriyan | 7b02196 | 2009-09-21 17:01:12 -0700 | [diff] [blame] | 3841 | static const struct lock_manager_operations nfsd_posix_mng_ops = { |
NeilBrown | d5b9026 | 2006-04-10 22:55:22 -0700 | [diff] [blame] | 3842 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | |
| 3844 | static inline void |
| 3845 | nfs4_set_lock_denied(struct file_lock *fl, struct nfsd4_lock_denied *deny) |
| 3846 | { |
NeilBrown | d5b9026 | 2006-04-10 22:55:22 -0700 | [diff] [blame] | 3847 | struct nfs4_stateowner *sop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3848 | |
NeilBrown | d5b9026 | 2006-04-10 22:55:22 -0700 | [diff] [blame] | 3849 | if (fl->fl_lmops == &nfsd_posix_mng_ops) { |
| 3850 | sop = (struct nfs4_stateowner *) fl->fl_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3851 | kref_get(&sop->so_ref); |
| 3852 | deny->ld_sop = sop; |
| 3853 | deny->ld_clientid = sop->so_client->cl_clientid; |
NeilBrown | d5b9026 | 2006-04-10 22:55:22 -0700 | [diff] [blame] | 3854 | } else { |
| 3855 | deny->ld_sop = NULL; |
| 3856 | deny->ld_clientid.cl_boot = 0; |
| 3857 | deny->ld_clientid.cl_id = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3858 | } |
| 3859 | deny->ld_start = fl->fl_start; |
Benny Halevy | 87df4de | 2008-12-15 19:42:03 +0200 | [diff] [blame] | 3860 | deny->ld_length = NFS4_MAX_UINT64; |
| 3861 | if (fl->fl_end != NFS4_MAX_UINT64) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3862 | deny->ld_length = fl->fl_end - fl->fl_start + 1; |
| 3863 | deny->ld_type = NFS4_READ_LT; |
| 3864 | if (fl->fl_type != F_RDLCK) |
| 3865 | deny->ld_type = NFS4_WRITE_LT; |
| 3866 | } |
| 3867 | |
| 3868 | static struct nfs4_stateowner * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3869 | find_lockstateowner_str(struct inode *inode, clientid_t *clid, |
| 3870 | struct xdr_netobj *owner) |
| 3871 | { |
| 3872 | unsigned int hashval = lock_ownerstr_hashval(inode, clid->cl_id, owner); |
| 3873 | struct nfs4_stateowner *op; |
| 3874 | |
| 3875 | list_for_each_entry(op, &lock_ownerstr_hashtbl[hashval], so_strhash) { |
J. Bruce Fields | 599e0a2 | 2007-07-26 17:04:54 -0400 | [diff] [blame] | 3876 | if (same_owner_str(op, owner, clid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3877 | return op; |
| 3878 | } |
| 3879 | return NULL; |
| 3880 | } |
| 3881 | |
| 3882 | /* |
| 3883 | * Alloc a lock owner structure. |
| 3884 | * Called in nfsd4_lock - therefore, OPEN and OPEN_CONFIRM (if needed) has |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3885 | * occurred. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3886 | * |
| 3887 | * strhashval = lock_ownerstr_hashval |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3888 | */ |
| 3889 | |
| 3890 | static struct nfs4_stateowner * |
| 3891 | alloc_init_lock_stateowner(unsigned int strhashval, struct nfs4_client *clp, struct nfs4_stateid *open_stp, struct nfsd4_lock *lock) { |
| 3892 | struct nfs4_stateowner *sop; |
| 3893 | struct nfs4_replay *rp; |
| 3894 | unsigned int idhashval; |
| 3895 | |
| 3896 | if (!(sop = alloc_stateowner(&lock->lk_new_owner))) |
| 3897 | return NULL; |
| 3898 | idhashval = lockownerid_hashval(current_ownerid); |
| 3899 | INIT_LIST_HEAD(&sop->so_idhash); |
| 3900 | INIT_LIST_HEAD(&sop->so_strhash); |
| 3901 | INIT_LIST_HEAD(&sop->so_perclient); |
NeilBrown | ea1da63 | 2005-06-23 22:04:17 -0700 | [diff] [blame] | 3902 | INIT_LIST_HEAD(&sop->so_stateids); |
| 3903 | INIT_LIST_HEAD(&sop->so_perstateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3904 | INIT_LIST_HEAD(&sop->so_close_lru); /* not used */ |
| 3905 | sop->so_time = 0; |
| 3906 | list_add(&sop->so_idhash, &lock_ownerid_hashtbl[idhashval]); |
| 3907 | list_add(&sop->so_strhash, &lock_ownerstr_hashtbl[strhashval]); |
NeilBrown | ea1da63 | 2005-06-23 22:04:17 -0700 | [diff] [blame] | 3908 | list_add(&sop->so_perstateid, &open_stp->st_lockowners); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3909 | sop->so_is_open_owner = 0; |
| 3910 | sop->so_id = current_ownerid++; |
| 3911 | sop->so_client = clp; |
Neil Brown | b59e3c0 | 2005-09-13 01:25:38 -0700 | [diff] [blame] | 3912 | /* It is the openowner seqid that will be incremented in encode in the |
| 3913 | * case of new lockowners; so increment the lock seqid manually: */ |
| 3914 | sop->so_seqid = lock->lk_new_lock_seqid + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3915 | sop->so_confirmed = 1; |
| 3916 | rp = &sop->so_replay; |
Al Viro | de1ae28 | 2006-01-18 17:43:47 -0800 | [diff] [blame] | 3917 | rp->rp_status = nfserr_serverfault; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3918 | rp->rp_buflen = 0; |
| 3919 | rp->rp_buf = rp->rp_ibuf; |
| 3920 | return sop; |
| 3921 | } |
| 3922 | |
NeilBrown | fd39ca9 | 2005-06-23 22:04:03 -0700 | [diff] [blame] | 3923 | static struct nfs4_stateid * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3924 | alloc_init_lock_stateid(struct nfs4_stateowner *sop, struct nfs4_file *fp, struct nfs4_stateid *open_stp) |
| 3925 | { |
| 3926 | struct nfs4_stateid *stp; |
| 3927 | unsigned int hashval = stateid_hashval(sop->so_id, fp->fi_id); |
| 3928 | |
NeilBrown | 5ac049a | 2005-06-23 22:03:03 -0700 | [diff] [blame] | 3929 | stp = nfs4_alloc_stateid(); |
| 3930 | if (stp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3931 | goto out; |
| 3932 | INIT_LIST_HEAD(&stp->st_hash); |
| 3933 | INIT_LIST_HEAD(&stp->st_perfile); |
NeilBrown | ea1da63 | 2005-06-23 22:04:17 -0700 | [diff] [blame] | 3934 | INIT_LIST_HEAD(&stp->st_perstateowner); |
| 3935 | INIT_LIST_HEAD(&stp->st_lockowners); /* not used */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3936 | list_add(&stp->st_hash, &lockstateid_hashtbl[hashval]); |
NeilBrown | 8beefa2 | 2005-06-23 22:03:08 -0700 | [diff] [blame] | 3937 | list_add(&stp->st_perfile, &fp->fi_stateids); |
NeilBrown | ea1da63 | 2005-06-23 22:04:17 -0700 | [diff] [blame] | 3938 | list_add(&stp->st_perstateowner, &sop->so_stateids); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3939 | stp->st_stateowner = sop; |
NeilBrown | 13cd218 | 2005-06-23 22:03:10 -0700 | [diff] [blame] | 3940 | get_nfs4_file(fp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3941 | stp->st_file = fp; |
J. Bruce Fields | e4e83ea | 2010-04-22 16:21:39 -0400 | [diff] [blame] | 3942 | stp->st_stateid.si_boot = boot_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3943 | stp->st_stateid.si_stateownerid = sop->so_id; |
| 3944 | stp->st_stateid.si_fileid = fp->fi_id; |
| 3945 | stp->st_stateid.si_generation = 0; |
J. Bruce Fields | 0997b17 | 2011-03-02 18:01:35 -0500 | [diff] [blame] | 3946 | stp->st_access_bmap = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3947 | stp->st_deny_bmap = open_stp->st_deny_bmap; |
NeilBrown | 4c4cd22 | 2005-07-07 17:59:27 -0700 | [diff] [blame] | 3948 | stp->st_openstp = open_stp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3949 | |
| 3950 | out: |
| 3951 | return stp; |
| 3952 | } |
| 3953 | |
NeilBrown | fd39ca9 | 2005-06-23 22:04:03 -0700 | [diff] [blame] | 3954 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3955 | check_lock_length(u64 offset, u64 length) |
| 3956 | { |
Benny Halevy | 87df4de | 2008-12-15 19:42:03 +0200 | [diff] [blame] | 3957 | return ((length == 0) || ((length != NFS4_MAX_UINT64) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3958 | LOFF_OVERFLOW(offset, length))); |
| 3959 | } |
| 3960 | |
J. Bruce Fields | 0997b17 | 2011-03-02 18:01:35 -0500 | [diff] [blame] | 3961 | static void get_lock_access(struct nfs4_stateid *lock_stp, u32 access) |
| 3962 | { |
| 3963 | struct nfs4_file *fp = lock_stp->st_file; |
| 3964 | int oflag = nfs4_access_to_omode(access); |
| 3965 | |
| 3966 | if (test_bit(access, &lock_stp->st_access_bmap)) |
| 3967 | return; |
| 3968 | nfs4_file_get_access(fp, oflag); |
| 3969 | __set_bit(access, &lock_stp->st_access_bmap); |
| 3970 | } |
| 3971 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3972 | /* |
| 3973 | * LOCK operation |
| 3974 | */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3975 | __be32 |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 3976 | nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
J.Bruce Fields | a4f1706a9 | 2006-12-13 00:35:28 -0800 | [diff] [blame] | 3977 | struct nfsd4_lock *lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3978 | { |
NeilBrown | 3e9e3db | 2005-06-23 22:04:20 -0700 | [diff] [blame] | 3979 | struct nfs4_stateowner *open_sop = NULL; |
Neil Brown | b59e3c0 | 2005-09-13 01:25:38 -0700 | [diff] [blame] | 3980 | struct nfs4_stateowner *lock_sop = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3981 | struct nfs4_stateid *lock_stp; |
J. Bruce Fields | 7d94784 | 2010-08-20 18:09:31 -0400 | [diff] [blame] | 3982 | struct nfs4_file *fp; |
| 3983 | struct file *filp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3984 | struct file_lock file_lock; |
Andy Adamson | 8dc7c31 | 2006-03-20 13:44:26 -0500 | [diff] [blame] | 3985 | struct file_lock conflock; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3986 | __be32 status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | unsigned int strhashval; |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 3988 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3989 | |
| 3990 | dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n", |
| 3991 | (long long) lock->lk_offset, |
| 3992 | (long long) lock->lk_length); |
| 3993 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3994 | if (check_lock_length(lock->lk_offset, lock->lk_length)) |
| 3995 | return nfserr_inval; |
| 3996 | |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 3997 | if ((status = fh_verify(rqstp, &cstate->current_fh, |
Miklos Szeredi | 8837abc | 2008-06-16 13:20:29 +0200 | [diff] [blame] | 3998 | S_IFREG, NFSD_MAY_LOCK))) { |
Andy Adamson | a6f6ef2 | 2006-01-18 17:43:17 -0800 | [diff] [blame] | 3999 | dprintk("NFSD: nfsd4_lock: permission denied!\n"); |
| 4000 | return status; |
| 4001 | } |
| 4002 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4003 | nfs4_lock_state(); |
| 4004 | |
| 4005 | if (lock->lk_is_new) { |
NeilBrown | 893f877 | 2005-07-07 17:59:17 -0700 | [diff] [blame] | 4006 | /* |
| 4007 | * Client indicates that this is a new lockowner. |
| 4008 | * Use open owner and open stateid to create lock owner and |
| 4009 | * lock stateid. |
| 4010 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4011 | struct nfs4_stateid *open_stp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4012 | |
| 4013 | status = nfserr_stale_clientid; |
Andy Adamson | 60adfc5 | 2009-04-03 08:28:50 +0300 | [diff] [blame] | 4014 | if (!nfsd4_has_session(cstate) && |
| 4015 | STALE_CLIENTID(&lock->lk_new_clientid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4016 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4018 | /* validate and update open stateid and open seqid */ |
Benny Halevy | dd453df | 2009-04-03 08:28:41 +0300 | [diff] [blame] | 4019 | status = nfs4_preprocess_seqid_op(cstate, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4020 | lock->lk_new_open_seqid, |
| 4021 | &lock->lk_new_open_stateid, |
J. Bruce Fields | f336273 | 2008-01-26 14:58:45 -0500 | [diff] [blame] | 4022 | OPEN_STATE, |
J. Bruce Fields | 3a65588 | 2006-01-18 17:43:19 -0800 | [diff] [blame] | 4023 | &lock->lk_replay_owner, &open_stp, |
Neil Brown | b59e3c0 | 2005-09-13 01:25:38 -0700 | [diff] [blame] | 4024 | lock); |
NeilBrown | 3751517 | 2005-07-07 17:59:16 -0700 | [diff] [blame] | 4025 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4026 | goto out; |
J. Bruce Fields | 3a65588 | 2006-01-18 17:43:19 -0800 | [diff] [blame] | 4027 | open_sop = lock->lk_replay_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4028 | /* create lockowner and lock stateid */ |
| 4029 | fp = open_stp->st_file; |
| 4030 | strhashval = lock_ownerstr_hashval(fp->fi_inode, |
| 4031 | open_sop->so_client->cl_clientid.cl_id, |
| 4032 | &lock->v.new.owner); |
NeilBrown | 3e9e3db | 2005-06-23 22:04:20 -0700 | [diff] [blame] | 4033 | /* XXX: Do we need to check for duplicate stateowners on |
| 4034 | * the same file, or should they just be allowed (and |
| 4035 | * create new stateids)? */ |
J. Bruce Fields | 3e77246 | 2011-08-10 19:07:33 -0400 | [diff] [blame^] | 4036 | status = nfserr_jukebox; |
Neil Brown | b59e3c0 | 2005-09-13 01:25:38 -0700 | [diff] [blame] | 4037 | lock_sop = alloc_init_lock_stateowner(strhashval, |
| 4038 | open_sop->so_client, open_stp, lock); |
| 4039 | if (lock_sop == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4040 | goto out; |
Neil Brown | b59e3c0 | 2005-09-13 01:25:38 -0700 | [diff] [blame] | 4041 | lock_stp = alloc_init_lock_stateid(lock_sop, fp, open_stp); |
J. Bruce Fields | 8a28051 | 2006-01-18 17:43:18 -0800 | [diff] [blame] | 4042 | if (lock_stp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4044 | } else { |
| 4045 | /* lock (lock owner + lock stateid) already exists */ |
Benny Halevy | dd453df | 2009-04-03 08:28:41 +0300 | [diff] [blame] | 4046 | status = nfs4_preprocess_seqid_op(cstate, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | lock->lk_old_lock_seqid, |
| 4048 | &lock->lk_old_lock_stateid, |
J. Bruce Fields | f336273 | 2008-01-26 14:58:45 -0500 | [diff] [blame] | 4049 | LOCK_STATE, |
J. Bruce Fields | 3a65588 | 2006-01-18 17:43:19 -0800 | [diff] [blame] | 4050 | &lock->lk_replay_owner, &lock_stp, lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4051 | if (status) |
| 4052 | goto out; |
J. Bruce Fields | 3a65588 | 2006-01-18 17:43:19 -0800 | [diff] [blame] | 4053 | lock_sop = lock->lk_replay_owner; |
J. Bruce Fields | 7d94784 | 2010-08-20 18:09:31 -0400 | [diff] [blame] | 4054 | fp = lock_stp->st_file; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4055 | } |
J. Bruce Fields | 3a65588 | 2006-01-18 17:43:19 -0800 | [diff] [blame] | 4056 | /* lock->lk_replay_owner and lock_stp have been created or found */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4057 | |
NeilBrown | 0dd395d | 2005-07-07 17:59:15 -0700 | [diff] [blame] | 4058 | status = nfserr_grace; |
J. Bruce Fields | af558e3 | 2007-09-06 12:34:25 -0400 | [diff] [blame] | 4059 | if (locks_in_grace() && !lock->lk_reclaim) |
NeilBrown | 0dd395d | 2005-07-07 17:59:15 -0700 | [diff] [blame] | 4060 | goto out; |
| 4061 | status = nfserr_no_grace; |
J. Bruce Fields | af558e3 | 2007-09-06 12:34:25 -0400 | [diff] [blame] | 4062 | if (!locks_in_grace() && lock->lk_reclaim) |
NeilBrown | 0dd395d | 2005-07-07 17:59:15 -0700 | [diff] [blame] | 4063 | goto out; |
| 4064 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4065 | locks_init_lock(&file_lock); |
| 4066 | switch (lock->lk_type) { |
| 4067 | case NFS4_READ_LT: |
| 4068 | case NFS4_READW_LT: |
J. Bruce Fields | 0997b17 | 2011-03-02 18:01:35 -0500 | [diff] [blame] | 4069 | filp = find_readable_file(lock_stp->st_file); |
| 4070 | if (filp) |
| 4071 | get_lock_access(lock_stp, NFS4_SHARE_ACCESS_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4072 | file_lock.fl_type = F_RDLCK; |
J. Bruce Fields | 529d7b2 | 2011-03-02 23:48:33 -0500 | [diff] [blame] | 4073 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4074 | case NFS4_WRITE_LT: |
| 4075 | case NFS4_WRITEW_LT: |
J. Bruce Fields | 0997b17 | 2011-03-02 18:01:35 -0500 | [diff] [blame] | 4076 | filp = find_writeable_file(lock_stp->st_file); |
| 4077 | if (filp) |
| 4078 | get_lock_access(lock_stp, NFS4_SHARE_ACCESS_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4079 | file_lock.fl_type = F_WRLCK; |
J. Bruce Fields | 529d7b2 | 2011-03-02 23:48:33 -0500 | [diff] [blame] | 4080 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4081 | default: |
| 4082 | status = nfserr_inval; |
| 4083 | goto out; |
| 4084 | } |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 4085 | if (!filp) { |
| 4086 | status = nfserr_openmode; |
| 4087 | goto out; |
| 4088 | } |
Neil Brown | b59e3c0 | 2005-09-13 01:25:38 -0700 | [diff] [blame] | 4089 | file_lock.fl_owner = (fl_owner_t)lock_sop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4090 | file_lock.fl_pid = current->tgid; |
| 4091 | file_lock.fl_file = filp; |
| 4092 | file_lock.fl_flags = FL_POSIX; |
NeilBrown | d5b9026 | 2006-04-10 22:55:22 -0700 | [diff] [blame] | 4093 | file_lock.fl_lmops = &nfsd_posix_mng_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4094 | |
| 4095 | file_lock.fl_start = lock->lk_offset; |
Benny Halevy | 87df4de | 2008-12-15 19:42:03 +0200 | [diff] [blame] | 4096 | file_lock.fl_end = last_byte_offset(lock->lk_offset, lock->lk_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4097 | nfs4_transform_lock_offset(&file_lock); |
| 4098 | |
| 4099 | /* |
| 4100 | * Try to lock the file in the VFS. |
| 4101 | * Note: locks.c uses the BKL to protect the inode's lock list. |
| 4102 | */ |
| 4103 | |
J. Bruce Fields | 529d7b2 | 2011-03-02 23:48:33 -0500 | [diff] [blame] | 4104 | err = vfs_lock_file(filp, F_SETLK, &file_lock, &conflock); |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 4105 | switch (-err) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4106 | case 0: /* success! */ |
| 4107 | update_stateid(&lock_stp->st_stateid); |
| 4108 | memcpy(&lock->lk_resp_stateid, &lock_stp->st_stateid, |
| 4109 | sizeof(stateid_t)); |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 4110 | status = 0; |
Andy Adamson | eb76b3f | 2006-03-26 01:37:26 -0800 | [diff] [blame] | 4111 | break; |
| 4112 | case (EAGAIN): /* conflock holds conflicting lock */ |
| 4113 | status = nfserr_denied; |
| 4114 | dprintk("NFSD: nfsd4_lock: conflicting lock found!\n"); |
| 4115 | nfs4_set_lock_denied(&conflock, &lock->lk_denied); |
| 4116 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4117 | case (EDEADLK): |
| 4118 | status = nfserr_deadlock; |
Andy Adamson | eb76b3f | 2006-03-26 01:37:26 -0800 | [diff] [blame] | 4119 | break; |
J. Bruce Fields | 3e77246 | 2011-08-10 19:07:33 -0400 | [diff] [blame^] | 4120 | default: |
Marc Eshel | fd85b81 | 2006-11-28 16:26:41 -0500 | [diff] [blame] | 4121 | dprintk("NFSD: nfsd4_lock: vfs_lock_file() failed! status %d\n",err); |
J. Bruce Fields | 3e77246 | 2011-08-10 19:07:33 -0400 | [diff] [blame^] | 4122 | status = nfserrno(err); |
Andy Adamson | eb76b3f | 2006-03-26 01:37:26 -0800 | [diff] [blame] | 4123 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4125 | out: |
J. Bruce Fields | 8a28051 | 2006-01-18 17:43:18 -0800 | [diff] [blame] | 4126 | if (status && lock->lk_is_new && lock_sop) |
J. Bruce Fields | f044ff8 | 2009-01-11 15:24:04 -0500 | [diff] [blame] | 4127 | release_lockowner(lock_sop); |
J. Bruce Fields | 3a65588 | 2006-01-18 17:43:19 -0800 | [diff] [blame] | 4128 | if (lock->lk_replay_owner) { |
| 4129 | nfs4_get_stateowner(lock->lk_replay_owner); |
J.Bruce Fields | a4f1706a9 | 2006-12-13 00:35:28 -0800 | [diff] [blame] | 4130 | cstate->replay_owner = lock->lk_replay_owner; |
Neil Brown | f2327d9 | 2005-09-13 01:25:37 -0700 | [diff] [blame] | 4131 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4132 | nfs4_unlock_state(); |
| 4133 | return status; |
| 4134 | } |
| 4135 | |
| 4136 | /* |
J. Bruce Fields | 55ef127 | 2008-12-20 11:58:38 -0800 | [diff] [blame] | 4137 | * The NFSv4 spec allows a client to do a LOCKT without holding an OPEN, |
| 4138 | * so we do a temporary open here just to get an open file to pass to |
| 4139 | * vfs_test_lock. (Arguably perhaps test_lock should be done with an |
| 4140 | * inode operation.) |
| 4141 | */ |
| 4142 | static int nfsd_test_lock(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file_lock *lock) |
| 4143 | { |
| 4144 | struct file *file; |
| 4145 | int err; |
| 4146 | |
| 4147 | err = nfsd_open(rqstp, fhp, S_IFREG, NFSD_MAY_READ, &file); |
| 4148 | if (err) |
| 4149 | return err; |
| 4150 | err = vfs_test_lock(file, lock); |
| 4151 | nfsd_close(file); |
| 4152 | return err; |
| 4153 | } |
| 4154 | |
| 4155 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4156 | * LOCKT operation |
| 4157 | */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4158 | __be32 |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 4159 | nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
| 4160 | struct nfsd4_lockt *lockt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4161 | { |
| 4162 | struct inode *inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4163 | struct file_lock file_lock; |
Marc Eshel | fd85b81 | 2006-11-28 16:26:41 -0500 | [diff] [blame] | 4164 | int error; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4165 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 | |
J. Bruce Fields | af558e3 | 2007-09-06 12:34:25 -0400 | [diff] [blame] | 4167 | if (locks_in_grace()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4168 | return nfserr_grace; |
| 4169 | |
| 4170 | if (check_lock_length(lockt->lt_offset, lockt->lt_length)) |
| 4171 | return nfserr_inval; |
| 4172 | |
| 4173 | lockt->lt_stateowner = NULL; |
| 4174 | nfs4_lock_state(); |
| 4175 | |
| 4176 | status = nfserr_stale_clientid; |
Andy Adamson | 60adfc5 | 2009-04-03 08:28:50 +0300 | [diff] [blame] | 4177 | if (!nfsd4_has_session(cstate) && STALE_CLIENTID(&lockt->lt_clientid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | |
J. Bruce Fields | 75c096f | 2011-08-15 18:39:32 -0400 | [diff] [blame] | 4180 | if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4181 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4182 | |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 4183 | inode = cstate->current_fh.fh_dentry->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4184 | locks_init_lock(&file_lock); |
| 4185 | switch (lockt->lt_type) { |
| 4186 | case NFS4_READ_LT: |
| 4187 | case NFS4_READW_LT: |
| 4188 | file_lock.fl_type = F_RDLCK; |
| 4189 | break; |
| 4190 | case NFS4_WRITE_LT: |
| 4191 | case NFS4_WRITEW_LT: |
| 4192 | file_lock.fl_type = F_WRLCK; |
| 4193 | break; |
| 4194 | default: |
J. Bruce Fields | 2fdada0 | 2007-07-27 16:10:37 -0400 | [diff] [blame] | 4195 | dprintk("NFSD: nfs4_lockt: bad lock type!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4196 | status = nfserr_inval; |
| 4197 | goto out; |
| 4198 | } |
| 4199 | |
| 4200 | lockt->lt_stateowner = find_lockstateowner_str(inode, |
| 4201 | &lockt->lt_clientid, &lockt->lt_owner); |
| 4202 | if (lockt->lt_stateowner) |
| 4203 | file_lock.fl_owner = (fl_owner_t)lockt->lt_stateowner; |
| 4204 | file_lock.fl_pid = current->tgid; |
| 4205 | file_lock.fl_flags = FL_POSIX; |
| 4206 | |
| 4207 | file_lock.fl_start = lockt->lt_offset; |
Benny Halevy | 87df4de | 2008-12-15 19:42:03 +0200 | [diff] [blame] | 4208 | file_lock.fl_end = last_byte_offset(lockt->lt_offset, lockt->lt_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4209 | |
| 4210 | nfs4_transform_lock_offset(&file_lock); |
| 4211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4212 | status = nfs_ok; |
J. Bruce Fields | 55ef127 | 2008-12-20 11:58:38 -0800 | [diff] [blame] | 4213 | error = nfsd_test_lock(rqstp, &cstate->current_fh, &file_lock); |
Marc Eshel | fd85b81 | 2006-11-28 16:26:41 -0500 | [diff] [blame] | 4214 | if (error) { |
| 4215 | status = nfserrno(error); |
| 4216 | goto out; |
| 4217 | } |
Marc Eshel | 9d6a8c5 | 2007-02-21 00:55:18 -0500 | [diff] [blame] | 4218 | if (file_lock.fl_type != F_UNLCK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4219 | status = nfserr_denied; |
Marc Eshel | 9d6a8c5 | 2007-02-21 00:55:18 -0500 | [diff] [blame] | 4220 | nfs4_set_lock_denied(&file_lock, &lockt->lt_denied); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4221 | } |
| 4222 | out: |
| 4223 | nfs4_unlock_state(); |
| 4224 | return status; |
| 4225 | } |
| 4226 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4227 | __be32 |
J.Bruce Fields | ca36431 | 2006-12-13 00:35:27 -0800 | [diff] [blame] | 4228 | nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
J.Bruce Fields | a4f1706a9 | 2006-12-13 00:35:28 -0800 | [diff] [blame] | 4229 | struct nfsd4_locku *locku) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4230 | { |
| 4231 | struct nfs4_stateid *stp; |
| 4232 | struct file *filp = NULL; |
| 4233 | struct file_lock file_lock; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4234 | __be32 status; |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 4235 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4236 | |
| 4237 | dprintk("NFSD: nfsd4_locku: start=%Ld length=%Ld\n", |
| 4238 | (long long) locku->lu_offset, |
| 4239 | (long long) locku->lu_length); |
| 4240 | |
| 4241 | if (check_lock_length(locku->lu_offset, locku->lu_length)) |
| 4242 | return nfserr_inval; |
| 4243 | |
| 4244 | nfs4_lock_state(); |
| 4245 | |
Benny Halevy | dd453df | 2009-04-03 08:28:41 +0300 | [diff] [blame] | 4246 | if ((status = nfs4_preprocess_seqid_op(cstate, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4247 | locku->lu_seqid, |
| 4248 | &locku->lu_stateid, |
J. Bruce Fields | f336273 | 2008-01-26 14:58:45 -0500 | [diff] [blame] | 4249 | LOCK_STATE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4250 | &locku->lu_stateowner, &stp, NULL))) |
| 4251 | goto out; |
| 4252 | |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 4253 | filp = find_any_file(stp->st_file); |
| 4254 | if (!filp) { |
| 4255 | status = nfserr_lock_range; |
| 4256 | goto out; |
| 4257 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4258 | BUG_ON(!filp); |
| 4259 | locks_init_lock(&file_lock); |
| 4260 | file_lock.fl_type = F_UNLCK; |
| 4261 | file_lock.fl_owner = (fl_owner_t) locku->lu_stateowner; |
| 4262 | file_lock.fl_pid = current->tgid; |
| 4263 | file_lock.fl_file = filp; |
| 4264 | file_lock.fl_flags = FL_POSIX; |
NeilBrown | d5b9026 | 2006-04-10 22:55:22 -0700 | [diff] [blame] | 4265 | file_lock.fl_lmops = &nfsd_posix_mng_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4266 | file_lock.fl_start = locku->lu_offset; |
| 4267 | |
Benny Halevy | 87df4de | 2008-12-15 19:42:03 +0200 | [diff] [blame] | 4268 | file_lock.fl_end = last_byte_offset(locku->lu_offset, locku->lu_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4269 | nfs4_transform_lock_offset(&file_lock); |
| 4270 | |
| 4271 | /* |
| 4272 | * Try to unlock the file in the VFS. |
| 4273 | */ |
Marc Eshel | fd85b81 | 2006-11-28 16:26:41 -0500 | [diff] [blame] | 4274 | err = vfs_lock_file(filp, F_SETLK, &file_lock, NULL); |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 4275 | if (err) { |
Marc Eshel | fd85b81 | 2006-11-28 16:26:41 -0500 | [diff] [blame] | 4276 | dprintk("NFSD: nfs4_locku: vfs_lock_file failed!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4277 | goto out_nfserr; |
| 4278 | } |
| 4279 | /* |
| 4280 | * OK, unlock succeeded; the only thing left to do is update the stateid. |
| 4281 | */ |
| 4282 | update_stateid(&stp->st_stateid); |
| 4283 | memcpy(&locku->lu_stateid, &stp->st_stateid, sizeof(stateid_t)); |
| 4284 | |
| 4285 | out: |
Neil Brown | f2327d9 | 2005-09-13 01:25:37 -0700 | [diff] [blame] | 4286 | if (locku->lu_stateowner) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4287 | nfs4_get_stateowner(locku->lu_stateowner); |
J.Bruce Fields | a4f1706a9 | 2006-12-13 00:35:28 -0800 | [diff] [blame] | 4288 | cstate->replay_owner = locku->lu_stateowner; |
Neil Brown | f2327d9 | 2005-09-13 01:25:37 -0700 | [diff] [blame] | 4289 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4290 | nfs4_unlock_state(); |
| 4291 | return status; |
| 4292 | |
| 4293 | out_nfserr: |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 4294 | status = nfserrno(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4295 | goto out; |
| 4296 | } |
| 4297 | |
| 4298 | /* |
| 4299 | * returns |
| 4300 | * 1: locks held by lockowner |
| 4301 | * 0: no locks held by lockowner |
| 4302 | */ |
| 4303 | static int |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 4304 | check_for_locks(struct nfs4_file *filp, struct nfs4_stateowner *lowner) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4305 | { |
| 4306 | struct file_lock **flpp; |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 4307 | struct inode *inode = filp->fi_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4308 | int status = 0; |
| 4309 | |
Arnd Bergmann | b89f432 | 2010-09-18 15:09:31 +0200 | [diff] [blame] | 4310 | lock_flocks(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4311 | for (flpp = &inode->i_flock; *flpp != NULL; flpp = &(*flpp)->fl_next) { |
J. Bruce Fields | 796dadf | 2006-01-18 17:43:22 -0800 | [diff] [blame] | 4312 | if ((*flpp)->fl_owner == (fl_owner_t)lowner) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4313 | status = 1; |
| 4314 | goto out; |
J. Bruce Fields | 796dadf | 2006-01-18 17:43:22 -0800 | [diff] [blame] | 4315 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4316 | } |
| 4317 | out: |
Arnd Bergmann | b89f432 | 2010-09-18 15:09:31 +0200 | [diff] [blame] | 4318 | unlock_flocks(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4319 | return status; |
| 4320 | } |
| 4321 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4322 | __be32 |
J.Bruce Fields | b591480 | 2006-12-13 00:35:38 -0800 | [diff] [blame] | 4323 | nfsd4_release_lockowner(struct svc_rqst *rqstp, |
| 4324 | struct nfsd4_compound_state *cstate, |
| 4325 | struct nfsd4_release_lockowner *rlockowner) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | { |
| 4327 | clientid_t *clid = &rlockowner->rl_clientid; |
NeilBrown | 3e9e3db | 2005-06-23 22:04:20 -0700 | [diff] [blame] | 4328 | struct nfs4_stateowner *sop; |
| 4329 | struct nfs4_stateid *stp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | struct xdr_netobj *owner = &rlockowner->rl_owner; |
NeilBrown | 3e9e3db | 2005-06-23 22:04:20 -0700 | [diff] [blame] | 4331 | struct list_head matches; |
| 4332 | int i; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4333 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4334 | |
| 4335 | dprintk("nfsd4_release_lockowner clientid: (%08x/%08x):\n", |
| 4336 | clid->cl_boot, clid->cl_id); |
| 4337 | |
| 4338 | /* XXX check for lease expiration */ |
| 4339 | |
| 4340 | status = nfserr_stale_clientid; |
Neil Brown | 849823c | 2005-09-13 01:25:36 -0700 | [diff] [blame] | 4341 | if (STALE_CLIENTID(clid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4342 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4343 | |
| 4344 | nfs4_lock_state(); |
| 4345 | |
NeilBrown | 3e9e3db | 2005-06-23 22:04:20 -0700 | [diff] [blame] | 4346 | status = nfserr_locks_held; |
| 4347 | /* XXX: we're doing a linear search through all the lockowners. |
| 4348 | * Yipes! For now we'll just hope clients aren't really using |
| 4349 | * release_lockowner much, but eventually we have to fix these |
| 4350 | * data structures. */ |
| 4351 | INIT_LIST_HEAD(&matches); |
| 4352 | for (i = 0; i < LOCK_HASH_SIZE; i++) { |
| 4353 | list_for_each_entry(sop, &lock_ownerid_hashtbl[i], so_idhash) { |
J. Bruce Fields | 599e0a2 | 2007-07-26 17:04:54 -0400 | [diff] [blame] | 4354 | if (!same_owner_str(sop, owner, clid)) |
NeilBrown | 3e9e3db | 2005-06-23 22:04:20 -0700 | [diff] [blame] | 4355 | continue; |
| 4356 | list_for_each_entry(stp, &sop->so_stateids, |
| 4357 | st_perstateowner) { |
J. Bruce Fields | f9d7562 | 2010-07-08 11:02:09 -0400 | [diff] [blame] | 4358 | if (check_for_locks(stp->st_file, sop)) |
NeilBrown | 3e9e3db | 2005-06-23 22:04:20 -0700 | [diff] [blame] | 4359 | goto out; |
| 4360 | /* Note: so_perclient unused for lockowners, |
| 4361 | * so it's OK to fool with here. */ |
| 4362 | list_add(&sop->so_perclient, &matches); |
| 4363 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4364 | } |
NeilBrown | 3e9e3db | 2005-06-23 22:04:20 -0700 | [diff] [blame] | 4365 | } |
| 4366 | /* Clients probably won't expect us to return with some (but not all) |
| 4367 | * of the lockowner state released; so don't release any until all |
| 4368 | * have been checked. */ |
| 4369 | status = nfs_ok; |
NeilBrown | 0fa822e | 2005-07-07 17:59:14 -0700 | [diff] [blame] | 4370 | while (!list_empty(&matches)) { |
| 4371 | sop = list_entry(matches.next, struct nfs4_stateowner, |
| 4372 | so_perclient); |
| 4373 | /* unhash_stateowner deletes so_perclient only |
| 4374 | * for openowners. */ |
| 4375 | list_del(&sop->so_perclient); |
J. Bruce Fields | f044ff8 | 2009-01-11 15:24:04 -0500 | [diff] [blame] | 4376 | release_lockowner(sop); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4377 | } |
| 4378 | out: |
| 4379 | nfs4_unlock_state(); |
| 4380 | return status; |
| 4381 | } |
| 4382 | |
| 4383 | static inline struct nfs4_client_reclaim * |
NeilBrown | a55370a | 2005-06-23 22:03:52 -0700 | [diff] [blame] | 4384 | alloc_reclaim(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4385 | { |
NeilBrown | a55370a | 2005-06-23 22:03:52 -0700 | [diff] [blame] | 4386 | return kmalloc(sizeof(struct nfs4_client_reclaim), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4387 | } |
| 4388 | |
NeilBrown | c7b9a45 | 2005-06-23 22:04:30 -0700 | [diff] [blame] | 4389 | int |
Andy Adamson | a1bcecd | 2009-04-03 08:28:05 +0300 | [diff] [blame] | 4390 | nfs4_has_reclaimed_state(const char *name, bool use_exchange_id) |
NeilBrown | c7b9a45 | 2005-06-23 22:04:30 -0700 | [diff] [blame] | 4391 | { |
| 4392 | unsigned int strhashval = clientstr_hashval(name); |
| 4393 | struct nfs4_client *clp; |
| 4394 | |
J. Bruce Fields | e203d50 | 2010-11-24 17:30:54 -0500 | [diff] [blame] | 4395 | clp = find_confirmed_client_by_str(name, strhashval); |
NeilBrown | c7b9a45 | 2005-06-23 22:04:30 -0700 | [diff] [blame] | 4396 | return clp ? 1 : 0; |
| 4397 | } |
| 4398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4399 | /* |
| 4400 | * failure => all reset bets are off, nfserr_no_grace... |
| 4401 | */ |
NeilBrown | 190e4fb | 2005-06-23 22:04:25 -0700 | [diff] [blame] | 4402 | int |
| 4403 | nfs4_client_to_reclaim(const char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4404 | { |
| 4405 | unsigned int strhashval; |
| 4406 | struct nfs4_client_reclaim *crp = NULL; |
| 4407 | |
NeilBrown | a55370a | 2005-06-23 22:03:52 -0700 | [diff] [blame] | 4408 | dprintk("NFSD nfs4_client_to_reclaim NAME: %.*s\n", HEXDIR_LEN, name); |
| 4409 | crp = alloc_reclaim(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4410 | if (!crp) |
| 4411 | return 0; |
NeilBrown | a55370a | 2005-06-23 22:03:52 -0700 | [diff] [blame] | 4412 | strhashval = clientstr_hashval(name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4413 | INIT_LIST_HEAD(&crp->cr_strhash); |
| 4414 | list_add(&crp->cr_strhash, &reclaim_str_hashtbl[strhashval]); |
NeilBrown | a55370a | 2005-06-23 22:03:52 -0700 | [diff] [blame] | 4415 | memcpy(crp->cr_recdir, name, HEXDIR_LEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4416 | reclaim_str_hashtbl_size++; |
| 4417 | return 1; |
| 4418 | } |
| 4419 | |
| 4420 | static void |
| 4421 | nfs4_release_reclaim(void) |
| 4422 | { |
| 4423 | struct nfs4_client_reclaim *crp = NULL; |
| 4424 | int i; |
| 4425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4426 | for (i = 0; i < CLIENT_HASH_SIZE; i++) { |
| 4427 | while (!list_empty(&reclaim_str_hashtbl[i])) { |
| 4428 | crp = list_entry(reclaim_str_hashtbl[i].next, |
| 4429 | struct nfs4_client_reclaim, cr_strhash); |
| 4430 | list_del(&crp->cr_strhash); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4431 | kfree(crp); |
| 4432 | reclaim_str_hashtbl_size--; |
| 4433 | } |
| 4434 | } |
| 4435 | BUG_ON(reclaim_str_hashtbl_size); |
| 4436 | } |
| 4437 | |
| 4438 | /* |
| 4439 | * called from OPEN, CLAIM_PREVIOUS with a new clientid. */ |
NeilBrown | fd39ca9 | 2005-06-23 22:04:03 -0700 | [diff] [blame] | 4440 | static struct nfs4_client_reclaim * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4441 | nfs4_find_reclaim_client(clientid_t *clid) |
| 4442 | { |
| 4443 | unsigned int strhashval; |
| 4444 | struct nfs4_client *clp; |
| 4445 | struct nfs4_client_reclaim *crp = NULL; |
| 4446 | |
| 4447 | |
| 4448 | /* find clientid in conf_id_hashtbl */ |
| 4449 | clp = find_confirmed_client(clid); |
| 4450 | if (clp == NULL) |
| 4451 | return NULL; |
| 4452 | |
NeilBrown | a55370a | 2005-06-23 22:03:52 -0700 | [diff] [blame] | 4453 | dprintk("NFSD: nfs4_find_reclaim_client for %.*s with recdir %s\n", |
| 4454 | clp->cl_name.len, clp->cl_name.data, |
| 4455 | clp->cl_recdir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | |
| 4457 | /* find clp->cl_name in reclaim_str_hashtbl */ |
NeilBrown | a55370a | 2005-06-23 22:03:52 -0700 | [diff] [blame] | 4458 | strhashval = clientstr_hashval(clp->cl_recdir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4459 | list_for_each_entry(crp, &reclaim_str_hashtbl[strhashval], cr_strhash) { |
NeilBrown | a55370a | 2005-06-23 22:03:52 -0700 | [diff] [blame] | 4460 | if (same_name(crp->cr_recdir, clp->cl_recdir)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4461 | return crp; |
| 4462 | } |
| 4463 | } |
| 4464 | return NULL; |
| 4465 | } |
| 4466 | |
| 4467 | /* |
| 4468 | * Called from OPEN. Look for clientid in reclaim list. |
| 4469 | */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4470 | __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | nfs4_check_open_reclaim(clientid_t *clid) |
| 4472 | { |
NeilBrown | dfc8356 | 2005-06-23 22:03:16 -0700 | [diff] [blame] | 4473 | return nfs4_find_reclaim_client(clid) ? nfs_ok : nfserr_reclaim_bad; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4474 | } |
| 4475 | |
NeilBrown | ac4d8ff2 | 2005-06-23 22:03:30 -0700 | [diff] [blame] | 4476 | /* initialization to perform at module load time: */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4477 | |
J. Bruce Fields | e8ff2a8 | 2007-08-01 15:30:59 -0400 | [diff] [blame] | 4478 | int |
NeilBrown | ac4d8ff2 | 2005-06-23 22:03:30 -0700 | [diff] [blame] | 4479 | nfs4_state_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4480 | { |
J. Bruce Fields | e8ff2a8 | 2007-08-01 15:30:59 -0400 | [diff] [blame] | 4481 | int i, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4482 | |
J. Bruce Fields | e8ff2a8 | 2007-08-01 15:30:59 -0400 | [diff] [blame] | 4483 | status = nfsd4_init_slabs(); |
| 4484 | if (status) |
| 4485 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4486 | for (i = 0; i < CLIENT_HASH_SIZE; i++) { |
| 4487 | INIT_LIST_HEAD(&conf_id_hashtbl[i]); |
| 4488 | INIT_LIST_HEAD(&conf_str_hashtbl[i]); |
| 4489 | INIT_LIST_HEAD(&unconf_str_hashtbl[i]); |
| 4490 | INIT_LIST_HEAD(&unconf_id_hashtbl[i]); |
Wang Chen | 02cb285 | 2009-04-24 15:41:57 +0800 | [diff] [blame] | 4491 | INIT_LIST_HEAD(&reclaim_str_hashtbl[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4492 | } |
Marc Eshel | 5282fd7 | 2009-04-03 08:27:52 +0300 | [diff] [blame] | 4493 | for (i = 0; i < SESSION_HASH_SIZE; i++) |
| 4494 | INIT_LIST_HEAD(&sessionid_hashtbl[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | for (i = 0; i < FILE_HASH_SIZE; i++) { |
| 4496 | INIT_LIST_HEAD(&file_hashtbl[i]); |
| 4497 | } |
| 4498 | for (i = 0; i < OWNER_HASH_SIZE; i++) { |
| 4499 | INIT_LIST_HEAD(&ownerstr_hashtbl[i]); |
| 4500 | INIT_LIST_HEAD(&ownerid_hashtbl[i]); |
| 4501 | } |
| 4502 | for (i = 0; i < STATEID_HASH_SIZE; i++) { |
| 4503 | INIT_LIST_HEAD(&stateid_hashtbl[i]); |
| 4504 | INIT_LIST_HEAD(&lockstateid_hashtbl[i]); |
| 4505 | } |
| 4506 | for (i = 0; i < LOCK_HASH_SIZE; i++) { |
| 4507 | INIT_LIST_HEAD(&lock_ownerid_hashtbl[i]); |
| 4508 | INIT_LIST_HEAD(&lock_ownerstr_hashtbl[i]); |
| 4509 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4510 | memset(&onestateid, ~0, sizeof(stateid_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4511 | INIT_LIST_HEAD(&close_lru); |
| 4512 | INIT_LIST_HEAD(&client_lru); |
| 4513 | INIT_LIST_HEAD(&del_recall_lru); |
NeilBrown | ac4d8ff2 | 2005-06-23 22:03:30 -0700 | [diff] [blame] | 4514 | reclaim_str_hashtbl_size = 0; |
J. Bruce Fields | e8ff2a8 | 2007-08-01 15:30:59 -0400 | [diff] [blame] | 4515 | return 0; |
NeilBrown | ac4d8ff2 | 2005-06-23 22:03:30 -0700 | [diff] [blame] | 4516 | } |
| 4517 | |
NeilBrown | 190e4fb | 2005-06-23 22:04:25 -0700 | [diff] [blame] | 4518 | static void |
| 4519 | nfsd4_load_reboot_recovery_data(void) |
| 4520 | { |
| 4521 | int status; |
| 4522 | |
NeilBrown | 0964a3d | 2005-06-23 22:04:32 -0700 | [diff] [blame] | 4523 | nfs4_lock_state(); |
J. Bruce Fields | 48483bf | 2011-08-26 20:40:28 -0400 | [diff] [blame] | 4524 | nfsd4_init_recdir(); |
NeilBrown | 190e4fb | 2005-06-23 22:04:25 -0700 | [diff] [blame] | 4525 | status = nfsd4_recdir_load(); |
NeilBrown | 0964a3d | 2005-06-23 22:04:32 -0700 | [diff] [blame] | 4526 | nfs4_unlock_state(); |
NeilBrown | 190e4fb | 2005-06-23 22:04:25 -0700 | [diff] [blame] | 4527 | if (status) |
| 4528 | printk("NFSD: Failure reading reboot recovery data\n"); |
| 4529 | } |
| 4530 | |
Meelap Shah | c2f1a55 | 2007-07-17 04:04:39 -0700 | [diff] [blame] | 4531 | /* |
| 4532 | * Since the lifetime of a delegation isn't limited to that of an open, a |
| 4533 | * client may quite reasonably hang on to a delegation as long as it has |
| 4534 | * the inode cached. This becomes an obvious problem the first time a |
| 4535 | * client's inode cache approaches the size of the server's total memory. |
| 4536 | * |
| 4537 | * For now we avoid this problem by imposing a hard limit on the number |
| 4538 | * of delegations, which varies according to the server's memory size. |
| 4539 | */ |
| 4540 | static void |
| 4541 | set_max_delegations(void) |
| 4542 | { |
| 4543 | /* |
| 4544 | * Allow at most 4 delegations per megabyte of RAM. Quick |
| 4545 | * estimates suggest that in the worst case (where every delegation |
| 4546 | * is for a different inode), a delegation could take about 1.5K, |
| 4547 | * giving a worst case usage of about 6% of memory. |
| 4548 | */ |
| 4549 | max_delegations = nr_free_buffer_pages() >> (20 - 2 - PAGE_SHIFT); |
| 4550 | } |
| 4551 | |
NeilBrown | ac4d8ff2 | 2005-06-23 22:03:30 -0700 | [diff] [blame] | 4552 | /* initialization to perform when the nfsd service is started: */ |
| 4553 | |
J. Bruce Fields | 29ab23c | 2009-09-15 15:56:50 -0400 | [diff] [blame] | 4554 | static int |
NeilBrown | ac4d8ff2 | 2005-06-23 22:03:30 -0700 | [diff] [blame] | 4555 | __nfs4_state_start(void) |
| 4556 | { |
J. Bruce Fields | b5a1a81 | 2010-03-03 14:52:55 -0500 | [diff] [blame] | 4557 | int ret; |
| 4558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | boot_time = get_seconds(); |
J. Bruce Fields | af558e3 | 2007-09-06 12:34:25 -0400 | [diff] [blame] | 4560 | locks_start_grace(&nfsd4_manager); |
Marc Eshel | 9a8db97 | 2007-07-17 04:04:35 -0700 | [diff] [blame] | 4561 | printk(KERN_INFO "NFSD: starting %ld-second grace period\n", |
J. Bruce Fields | e46b498 | 2010-03-01 19:21:21 -0500 | [diff] [blame] | 4562 | nfsd4_grace); |
J. Bruce Fields | b5a1a81 | 2010-03-03 14:52:55 -0500 | [diff] [blame] | 4563 | ret = set_callback_cred(); |
| 4564 | if (ret) |
| 4565 | return -ENOMEM; |
NeilBrown | 58da282 | 2005-06-23 22:03:19 -0700 | [diff] [blame] | 4566 | laundry_wq = create_singlethread_workqueue("nfsd4"); |
J. Bruce Fields | 29ab23c | 2009-09-15 15:56:50 -0400 | [diff] [blame] | 4567 | if (laundry_wq == NULL) |
| 4568 | return -ENOMEM; |
J. Bruce Fields | b5a1a81 | 2010-03-03 14:52:55 -0500 | [diff] [blame] | 4569 | ret = nfsd4_create_callback_queue(); |
| 4570 | if (ret) |
| 4571 | goto out_free_laundry; |
J. Bruce Fields | e46b498 | 2010-03-01 19:21:21 -0500 | [diff] [blame] | 4572 | queue_delayed_work(laundry_wq, &laundromat_work, nfsd4_grace * HZ); |
Meelap Shah | c2f1a55 | 2007-07-17 04:04:39 -0700 | [diff] [blame] | 4573 | set_max_delegations(); |
J. Bruce Fields | b5a1a81 | 2010-03-03 14:52:55 -0500 | [diff] [blame] | 4574 | return 0; |
| 4575 | out_free_laundry: |
| 4576 | destroy_workqueue(laundry_wq); |
| 4577 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4578 | } |
| 4579 | |
J. Bruce Fields | 29ab23c | 2009-09-15 15:56:50 -0400 | [diff] [blame] | 4580 | int |
NeilBrown | 76a3550 | 2005-06-23 22:03:26 -0700 | [diff] [blame] | 4581 | nfs4_state_start(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4582 | { |
NeilBrown | 190e4fb | 2005-06-23 22:04:25 -0700 | [diff] [blame] | 4583 | nfsd4_load_reboot_recovery_data(); |
Jeff Layton | 4ad9a34 | 2010-07-19 16:50:04 -0400 | [diff] [blame] | 4584 | return __nfs4_state_start(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4585 | } |
| 4586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4587 | static void |
| 4588 | __nfs4_state_shutdown(void) |
| 4589 | { |
| 4590 | int i; |
| 4591 | struct nfs4_client *clp = NULL; |
| 4592 | struct nfs4_delegation *dp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4593 | struct list_head *pos, *next, reaplist; |
| 4594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4595 | for (i = 0; i < CLIENT_HASH_SIZE; i++) { |
| 4596 | while (!list_empty(&conf_id_hashtbl[i])) { |
| 4597 | clp = list_entry(conf_id_hashtbl[i].next, struct nfs4_client, cl_idhash); |
| 4598 | expire_client(clp); |
| 4599 | } |
| 4600 | while (!list_empty(&unconf_str_hashtbl[i])) { |
| 4601 | clp = list_entry(unconf_str_hashtbl[i].next, struct nfs4_client, cl_strhash); |
| 4602 | expire_client(clp); |
| 4603 | } |
| 4604 | } |
| 4605 | INIT_LIST_HEAD(&reaplist); |
| 4606 | spin_lock(&recall_lock); |
| 4607 | list_for_each_safe(pos, next, &del_recall_lru) { |
| 4608 | dp = list_entry (pos, struct nfs4_delegation, dl_recall_lru); |
| 4609 | list_move(&dp->dl_recall_lru, &reaplist); |
| 4610 | } |
| 4611 | spin_unlock(&recall_lock); |
| 4612 | list_for_each_safe(pos, next, &reaplist) { |
| 4613 | dp = list_entry (pos, struct nfs4_delegation, dl_recall_lru); |
| 4614 | list_del_init(&dp->dl_recall_lru); |
| 4615 | unhash_delegation(dp); |
| 4616 | } |
| 4617 | |
NeilBrown | 190e4fb | 2005-06-23 22:04:25 -0700 | [diff] [blame] | 4618 | nfsd4_shutdown_recdir(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4619 | } |
| 4620 | |
| 4621 | void |
| 4622 | nfs4_state_shutdown(void) |
| 4623 | { |
Tejun Heo | afe2c51 | 2010-12-14 16:21:17 +0100 | [diff] [blame] | 4624 | cancel_delayed_work_sync(&laundromat_work); |
NeilBrown | 5e8d5c2 | 2006-04-10 22:55:37 -0700 | [diff] [blame] | 4625 | destroy_workqueue(laundry_wq); |
J. Bruce Fields | 2c5e761 | 2008-11-20 14:36:17 -0600 | [diff] [blame] | 4626 | locks_end_grace(&nfsd4_manager); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4627 | nfs4_lock_state(); |
| 4628 | nfs4_release_reclaim(); |
| 4629 | __nfs4_state_shutdown(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4630 | nfs4_unlock_state(); |
J. Bruce Fields | c3935e3 | 2010-06-04 16:42:08 -0400 | [diff] [blame] | 4631 | nfsd4_destroy_callback_queue(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4632 | } |