Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/nfs/callback_proc.c |
| 3 | * |
| 4 | * Copyright (C) 2004 Trond Myklebust |
| 5 | * |
| 6 | * NFSv4 callback procedures |
| 7 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/nfs4.h> |
| 9 | #include <linux/nfs_fs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 11 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include "callback.h" |
| 13 | #include "delegation.h" |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 14 | #include "internal.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Chuck Lever | 1d98fe6 | 2007-12-10 14:57:23 -0500 | [diff] [blame] | 16 | #ifdef NFS_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #define NFSDBG_FACILITY NFSDBG_CALLBACK |
Chuck Lever | 1d98fe6 | 2007-12-10 14:57:23 -0500 | [diff] [blame] | 18 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 20 | __be32 nfs4_callback_getattr(struct cb_getattrargs *args, struct cb_getattrres *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | { |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 22 | struct nfs_client *clp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | struct nfs_delegation *delegation; |
| 24 | struct nfs_inode *nfsi; |
| 25 | struct inode *inode; |
Chuck Lever | 1d98fe6 | 2007-12-10 14:57:23 -0500 | [diff] [blame] | 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | res->bitmap[0] = res->bitmap[1] = 0; |
| 28 | res->status = htonl(NFS4ERR_BADHANDLE); |
Chuck Lever | ff05264 | 2007-12-10 14:58:44 -0500 | [diff] [blame] | 29 | clp = nfs_find_client(args->addr, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | if (clp == NULL) |
| 31 | goto out; |
Chuck Lever | 1d98fe6 | 2007-12-10 14:57:23 -0500 | [diff] [blame] | 32 | |
| 33 | dprintk("NFS: GETATTR callback request from %s\n", |
| 34 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)); |
| 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | inode = nfs_delegation_find_inode(clp, &args->fh); |
| 37 | if (inode == NULL) |
| 38 | goto out_putclient; |
| 39 | nfsi = NFS_I(inode); |
| 40 | down_read(&nfsi->rwsem); |
| 41 | delegation = nfsi->delegation; |
| 42 | if (delegation == NULL || (delegation->type & FMODE_WRITE) == 0) |
| 43 | goto out_iput; |
| 44 | res->size = i_size_read(inode); |
Trond Myklebust | beb2a5e | 2006-01-03 09:55:37 +0100 | [diff] [blame] | 45 | res->change_attr = delegation->change_attr; |
| 46 | if (nfsi->npages != 0) |
| 47 | res->change_attr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | res->ctime = inode->i_ctime; |
| 49 | res->mtime = inode->i_mtime; |
| 50 | res->bitmap[0] = (FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE) & |
| 51 | args->bitmap[0]; |
| 52 | res->bitmap[1] = (FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY) & |
| 53 | args->bitmap[1]; |
| 54 | res->status = 0; |
| 55 | out_iput: |
| 56 | up_read(&nfsi->rwsem); |
| 57 | iput(inode); |
| 58 | out_putclient: |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 59 | nfs_put_client(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 61 | dprintk("%s: exit with status = %d\n", __func__, ntohl(res->status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | return res->status; |
| 63 | } |
| 64 | |
Alexandros Batsakis | 2597641 | 2009-12-05 13:48:55 -0500 | [diff] [blame] | 65 | static int (*nfs_validate_delegation_stateid(struct nfs_client *clp))(struct nfs_delegation *, const nfs4_stateid *) |
| 66 | { |
| 67 | #if defined(CONFIG_NFS_V4_1) |
| 68 | if (clp->cl_minorversion > 0) |
| 69 | return nfs41_validate_delegation_stateid; |
| 70 | #endif |
| 71 | return nfs4_validate_delegation_stateid; |
| 72 | } |
| 73 | |
| 74 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 75 | __be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | { |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 77 | struct nfs_client *clp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | struct inode *inode; |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 79 | __be32 res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | res = htonl(NFS4ERR_BADHANDLE); |
Chuck Lever | ff05264 | 2007-12-10 14:58:44 -0500 | [diff] [blame] | 82 | clp = nfs_find_client(args->addr, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | if (clp == NULL) |
| 84 | goto out; |
Chuck Lever | 1d98fe6 | 2007-12-10 14:57:23 -0500 | [diff] [blame] | 85 | |
| 86 | dprintk("NFS: RECALL callback request from %s\n", |
| 87 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)); |
| 88 | |
Trond Myklebust | 3fbd67a | 2008-01-26 01:06:40 -0500 | [diff] [blame] | 89 | do { |
| 90 | struct nfs_client *prev = clp; |
| 91 | |
| 92 | inode = nfs_delegation_find_inode(clp, &args->fh); |
| 93 | if (inode != NULL) { |
| 94 | /* Set up a helper thread to actually return the delegation */ |
Alexandros Batsakis | 2597641 | 2009-12-05 13:48:55 -0500 | [diff] [blame] | 95 | switch (nfs_async_inode_return_delegation(inode, &args->stateid, |
| 96 | nfs_validate_delegation_stateid(clp))) { |
Trond Myklebust | 3fbd67a | 2008-01-26 01:06:40 -0500 | [diff] [blame] | 97 | case 0: |
| 98 | res = 0; |
| 99 | break; |
| 100 | case -ENOENT: |
| 101 | if (res != 0) |
| 102 | res = htonl(NFS4ERR_BAD_STATEID); |
| 103 | break; |
| 104 | default: |
| 105 | res = htonl(NFS4ERR_RESOURCE); |
| 106 | } |
| 107 | iput(inode); |
| 108 | } |
| 109 | clp = nfs_find_client_next(prev); |
| 110 | nfs_put_client(prev); |
| 111 | } while (clp != NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 113 | dprintk("%s: exit with status = %d\n", __func__, ntohl(res)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | return res; |
| 115 | } |
Benny Halevy | d49433e | 2009-04-01 09:23:25 -0400 | [diff] [blame] | 116 | |
Alexandros Batsakis | 2597641 | 2009-12-05 13:48:55 -0500 | [diff] [blame] | 117 | int nfs4_validate_delegation_stateid(struct nfs_delegation *delegation, const nfs4_stateid *stateid) |
| 118 | { |
| 119 | if (delegation == NULL || memcmp(delegation->stateid.data, stateid->data, |
| 120 | sizeof(delegation->stateid.data)) != 0) |
| 121 | return 0; |
| 122 | return 1; |
| 123 | } |
| 124 | |
Benny Halevy | d49433e | 2009-04-01 09:23:25 -0400 | [diff] [blame] | 125 | #if defined(CONFIG_NFS_V4_1) |
| 126 | |
Alexandros Batsakis | 2597641 | 2009-12-05 13:48:55 -0500 | [diff] [blame] | 127 | int nfs41_validate_delegation_stateid(struct nfs_delegation *delegation, const nfs4_stateid *stateid) |
| 128 | { |
| 129 | if (delegation == NULL) |
| 130 | return 0; |
| 131 | |
| 132 | /* seqid is 4-bytes long */ |
| 133 | if (((u32 *) &stateid->data)[0] != 0) |
| 134 | return 0; |
| 135 | if (memcmp(&delegation->stateid.data[4], &stateid->data[4], |
| 136 | sizeof(stateid->data)-4)) |
| 137 | return 0; |
| 138 | |
| 139 | return 1; |
| 140 | } |
| 141 | |
Ricardo Labiaga | 963891a | 2009-04-01 09:23:34 -0400 | [diff] [blame] | 142 | /* |
Ricardo Labiaga | 68f3f90 | 2009-04-01 09:23:35 -0400 | [diff] [blame] | 143 | * Validate the sequenceID sent by the server. |
| 144 | * Return success if the sequenceID is one more than what we last saw on |
| 145 | * this slot, accounting for wraparound. Increments the slot's sequence. |
| 146 | * |
Andy Adamson | 4911096 | 2010-01-14 17:45:08 -0500 | [diff] [blame] | 147 | * We don't yet implement a duplicate request cache, instead we set the |
| 148 | * back channel ca_maxresponsesize_cached to zero. This is OK for now |
Ricardo Labiaga | 68f3f90 | 2009-04-01 09:23:35 -0400 | [diff] [blame] | 149 | * since we only currently implement idempotent callbacks anyway. |
| 150 | * |
| 151 | * We have a single slot backchannel at this time, so we don't bother |
| 152 | * checking the used_slots bit array on the table. The lower layer guarantees |
| 153 | * a single outstanding callback request at a time. |
| 154 | */ |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 155 | static __be32 |
Andy Adamson | b2f28bd | 2010-01-14 17:45:07 -0500 | [diff] [blame] | 156 | validate_seqid(struct nfs4_slot_table *tbl, struct cb_sequenceargs * args) |
Ricardo Labiaga | 68f3f90 | 2009-04-01 09:23:35 -0400 | [diff] [blame] | 157 | { |
| 158 | struct nfs4_slot *slot; |
| 159 | |
| 160 | dprintk("%s enter. slotid %d seqid %d\n", |
Andy Adamson | b2f28bd | 2010-01-14 17:45:07 -0500 | [diff] [blame] | 161 | __func__, args->csa_slotid, args->csa_sequenceid); |
Ricardo Labiaga | 68f3f90 | 2009-04-01 09:23:35 -0400 | [diff] [blame] | 162 | |
Andy Adamson | b2f28bd | 2010-01-14 17:45:07 -0500 | [diff] [blame] | 163 | if (args->csa_slotid > NFS41_BC_MAX_CALLBACKS) |
Ricardo Labiaga | 68f3f90 | 2009-04-01 09:23:35 -0400 | [diff] [blame] | 164 | return htonl(NFS4ERR_BADSLOT); |
| 165 | |
Andy Adamson | b2f28bd | 2010-01-14 17:45:07 -0500 | [diff] [blame] | 166 | slot = tbl->slots + args->csa_slotid; |
Ricardo Labiaga | 68f3f90 | 2009-04-01 09:23:35 -0400 | [diff] [blame] | 167 | dprintk("%s slot table seqid: %d\n", __func__, slot->seq_nr); |
| 168 | |
| 169 | /* Normal */ |
Andy Adamson | b2f28bd | 2010-01-14 17:45:07 -0500 | [diff] [blame] | 170 | if (likely(args->csa_sequenceid == slot->seq_nr + 1)) { |
Ricardo Labiaga | 68f3f90 | 2009-04-01 09:23:35 -0400 | [diff] [blame] | 171 | slot->seq_nr++; |
| 172 | return htonl(NFS4_OK); |
| 173 | } |
| 174 | |
| 175 | /* Replay */ |
Andy Adamson | b2f28bd | 2010-01-14 17:45:07 -0500 | [diff] [blame] | 176 | if (args->csa_sequenceid == slot->seq_nr) { |
Andy Adamson | 4911096 | 2010-01-14 17:45:08 -0500 | [diff] [blame] | 177 | dprintk("%s seqid %d is a replay\n", |
Andy Adamson | b2f28bd | 2010-01-14 17:45:07 -0500 | [diff] [blame] | 178 | __func__, args->csa_sequenceid); |
Andy Adamson | 4911096 | 2010-01-14 17:45:08 -0500 | [diff] [blame] | 179 | /* Signal process_op to set this error on next op */ |
| 180 | if (args->csa_cachethis == 0) |
| 181 | return htonl(NFS4ERR_RETRY_UNCACHED_REP); |
| 182 | |
| 183 | /* The ca_maxresponsesize_cached is 0 with no DRC */ |
| 184 | else if (args->csa_cachethis == 1) |
| 185 | return htonl(NFS4ERR_REP_TOO_BIG_TO_CACHE); |
Ricardo Labiaga | 68f3f90 | 2009-04-01 09:23:35 -0400 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | /* Wraparound */ |
Andy Adamson | b2f28bd | 2010-01-14 17:45:07 -0500 | [diff] [blame] | 189 | if (args->csa_sequenceid == 1 && (slot->seq_nr + 1) == 0) { |
Ricardo Labiaga | 68f3f90 | 2009-04-01 09:23:35 -0400 | [diff] [blame] | 190 | slot->seq_nr = 1; |
| 191 | return htonl(NFS4_OK); |
| 192 | } |
| 193 | |
| 194 | /* Misordered request */ |
| 195 | return htonl(NFS4ERR_SEQ_MISORDERED); |
| 196 | } |
| 197 | |
| 198 | /* |
Ricardo Labiaga | 963891a | 2009-04-01 09:23:34 -0400 | [diff] [blame] | 199 | * Returns a pointer to a held 'struct nfs_client' that matches the server's |
| 200 | * address, major version number, and session ID. It is the caller's |
| 201 | * responsibility to release the returned reference. |
| 202 | * |
| 203 | * Returns NULL if there are no connections with sessions, or if no session |
| 204 | * matches the one of interest. |
| 205 | */ |
| 206 | static struct nfs_client *find_client_with_session( |
| 207 | const struct sockaddr *addr, u32 nfsversion, |
| 208 | struct nfs4_sessionid *sessionid) |
| 209 | { |
| 210 | struct nfs_client *clp; |
| 211 | |
| 212 | clp = nfs_find_client(addr, 4); |
| 213 | if (clp == NULL) |
| 214 | return NULL; |
| 215 | |
| 216 | do { |
| 217 | struct nfs_client *prev = clp; |
| 218 | |
| 219 | if (clp->cl_session != NULL) { |
| 220 | if (memcmp(clp->cl_session->sess_id.data, |
| 221 | sessionid->data, |
| 222 | NFS4_MAX_SESSIONID_LEN) == 0) { |
| 223 | /* Returns a held reference to clp */ |
| 224 | return clp; |
| 225 | } |
| 226 | } |
| 227 | clp = nfs_find_client_next(prev); |
| 228 | nfs_put_client(prev); |
| 229 | } while (clp != NULL); |
| 230 | |
| 231 | return NULL; |
| 232 | } |
| 233 | |
Mike Sager | a7989c3 | 2010-01-19 12:54:40 -0500 | [diff] [blame] | 234 | /* |
| 235 | * For each referring call triple, check the session's slot table for |
| 236 | * a match. If the slot is in use and the sequence numbers match, the |
| 237 | * client is still waiting for a response to the original request. |
| 238 | */ |
| 239 | static bool referring_call_exists(struct nfs_client *clp, |
| 240 | uint32_t nrclists, |
| 241 | struct referring_call_list *rclists) |
| 242 | { |
| 243 | bool status = 0; |
| 244 | int i, j; |
| 245 | struct nfs4_session *session; |
| 246 | struct nfs4_slot_table *tbl; |
| 247 | struct referring_call_list *rclist; |
| 248 | struct referring_call *ref; |
| 249 | |
| 250 | /* |
| 251 | * XXX When client trunking is implemented, this becomes |
| 252 | * a session lookup from within the loop |
| 253 | */ |
| 254 | session = clp->cl_session; |
| 255 | tbl = &session->fc_slot_table; |
| 256 | |
| 257 | for (i = 0; i < nrclists; i++) { |
| 258 | rclist = &rclists[i]; |
| 259 | if (memcmp(session->sess_id.data, |
| 260 | rclist->rcl_sessionid.data, |
| 261 | NFS4_MAX_SESSIONID_LEN) != 0) |
| 262 | continue; |
| 263 | |
| 264 | for (j = 0; j < rclist->rcl_nrefcalls; j++) { |
| 265 | ref = &rclist->rcl_refcalls[j]; |
| 266 | |
| 267 | dprintk("%s: sessionid %x:%x:%x:%x sequenceid %u " |
| 268 | "slotid %u\n", __func__, |
| 269 | ((u32 *)&rclist->rcl_sessionid.data)[0], |
| 270 | ((u32 *)&rclist->rcl_sessionid.data)[1], |
| 271 | ((u32 *)&rclist->rcl_sessionid.data)[2], |
| 272 | ((u32 *)&rclist->rcl_sessionid.data)[3], |
| 273 | ref->rc_sequenceid, ref->rc_slotid); |
| 274 | |
| 275 | spin_lock(&tbl->slot_tbl_lock); |
| 276 | status = (test_bit(ref->rc_slotid, tbl->used_slots) && |
| 277 | tbl->slots[ref->rc_slotid].seq_nr == |
| 278 | ref->rc_sequenceid); |
| 279 | spin_unlock(&tbl->slot_tbl_lock); |
| 280 | if (status) |
| 281 | goto out; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | out: |
| 286 | return status; |
| 287 | } |
| 288 | |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 289 | __be32 nfs4_callback_sequence(struct cb_sequenceargs *args, |
Benny Halevy | d49433e | 2009-04-01 09:23:25 -0400 | [diff] [blame] | 290 | struct cb_sequenceres *res) |
| 291 | { |
Ricardo Labiaga | 68f3f90 | 2009-04-01 09:23:35 -0400 | [diff] [blame] | 292 | struct nfs_client *clp; |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 293 | int i; |
| 294 | __be32 status; |
Benny Halevy | d49433e | 2009-04-01 09:23:25 -0400 | [diff] [blame] | 295 | |
Ricardo Labiaga | 68f3f90 | 2009-04-01 09:23:35 -0400 | [diff] [blame] | 296 | status = htonl(NFS4ERR_BADSESSION); |
| 297 | clp = find_client_with_session(args->csa_addr, 4, &args->csa_sessionid); |
| 298 | if (clp == NULL) |
| 299 | goto out; |
| 300 | |
Andy Adamson | b2f28bd | 2010-01-14 17:45:07 -0500 | [diff] [blame] | 301 | status = validate_seqid(&clp->cl_session->bc_slot_table, args); |
Ricardo Labiaga | 68f3f90 | 2009-04-01 09:23:35 -0400 | [diff] [blame] | 302 | if (status) |
| 303 | goto out_putclient; |
| 304 | |
Mike Sager | 72ce2b3 | 2010-01-19 12:54:41 -0500 | [diff] [blame] | 305 | /* |
| 306 | * Check for pending referring calls. If a match is found, a |
| 307 | * related callback was received before the response to the original |
| 308 | * call. |
| 309 | */ |
| 310 | if (referring_call_exists(clp, args->csa_nrclists, args->csa_rclists)) { |
| 311 | status = htonl(NFS4ERR_DELAY); |
| 312 | goto out_putclient; |
| 313 | } |
| 314 | |
Benny Halevy | d49433e | 2009-04-01 09:23:25 -0400 | [diff] [blame] | 315 | memcpy(&res->csr_sessionid, &args->csa_sessionid, |
| 316 | sizeof(res->csr_sessionid)); |
| 317 | res->csr_sequenceid = args->csa_sequenceid; |
| 318 | res->csr_slotid = args->csa_slotid; |
| 319 | res->csr_highestslotid = NFS41_BC_MAX_CALLBACKS - 1; |
| 320 | res->csr_target_highestslotid = NFS41_BC_MAX_CALLBACKS - 1; |
| 321 | |
Ricardo Labiaga | 68f3f90 | 2009-04-01 09:23:35 -0400 | [diff] [blame] | 322 | out_putclient: |
| 323 | nfs_put_client(clp); |
| 324 | out: |
Mike Sager | 72ce2b3 | 2010-01-19 12:54:41 -0500 | [diff] [blame] | 325 | for (i = 0; i < args->csa_nrclists; i++) |
| 326 | kfree(args->csa_rclists[i].rcl_refcalls); |
| 327 | kfree(args->csa_rclists); |
| 328 | |
Andy Adamson | 4911096 | 2010-01-14 17:45:08 -0500 | [diff] [blame] | 329 | if (status == htonl(NFS4ERR_RETRY_UNCACHED_REP)) |
| 330 | res->csr_status = 0; |
| 331 | else |
| 332 | res->csr_status = status; |
| 333 | dprintk("%s: exit with status = %d res->csr_status %d\n", __func__, |
| 334 | ntohl(status), ntohl(res->csr_status)); |
| 335 | return status; |
Benny Halevy | d49433e | 2009-04-01 09:23:25 -0400 | [diff] [blame] | 336 | } |
| 337 | |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 338 | __be32 nfs4_callback_recallany(struct cb_recallanyargs *args, void *dummy) |
Alexandros Batsakis | 31f0960 | 2009-12-05 13:27:02 -0500 | [diff] [blame] | 339 | { |
| 340 | struct nfs_client *clp; |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 341 | __be32 status; |
Alexandros Batsakis | 31f0960 | 2009-12-05 13:27:02 -0500 | [diff] [blame] | 342 | fmode_t flags = 0; |
| 343 | |
| 344 | status = htonl(NFS4ERR_OP_NOT_IN_SESSION); |
| 345 | clp = nfs_find_client(args->craa_addr, 4); |
| 346 | if (clp == NULL) |
| 347 | goto out; |
| 348 | |
| 349 | dprintk("NFS: RECALL_ANY callback request from %s\n", |
| 350 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)); |
| 351 | |
| 352 | if (test_bit(RCA4_TYPE_MASK_RDATA_DLG, (const unsigned long *) |
| 353 | &args->craa_type_mask)) |
| 354 | flags = FMODE_READ; |
| 355 | if (test_bit(RCA4_TYPE_MASK_WDATA_DLG, (const unsigned long *) |
| 356 | &args->craa_type_mask)) |
| 357 | flags |= FMODE_WRITE; |
| 358 | |
| 359 | if (flags) |
| 360 | nfs_expire_all_delegation_types(clp, flags); |
| 361 | status = htonl(NFS4_OK); |
| 362 | out: |
| 363 | dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); |
| 364 | return status; |
| 365 | } |
Andy Adamson | b9efa1b | 2010-01-20 16:06:27 -0500 | [diff] [blame] | 366 | |
| 367 | /* Reduce the fore channel's max_slots to the target value */ |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 368 | __be32 nfs4_callback_recallslot(struct cb_recallslotargs *args, void *dummy) |
Andy Adamson | b9efa1b | 2010-01-20 16:06:27 -0500 | [diff] [blame] | 369 | { |
| 370 | struct nfs_client *clp; |
| 371 | struct nfs4_slot_table *fc_tbl; |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 372 | __be32 status; |
Andy Adamson | b9efa1b | 2010-01-20 16:06:27 -0500 | [diff] [blame] | 373 | |
| 374 | status = htonl(NFS4ERR_OP_NOT_IN_SESSION); |
| 375 | clp = nfs_find_client(args->crsa_addr, 4); |
| 376 | if (clp == NULL) |
| 377 | goto out; |
| 378 | |
| 379 | dprintk("NFS: CB_RECALL_SLOT request from %s target max slots %d\n", |
| 380 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 381 | args->crsa_target_max_slots); |
| 382 | |
| 383 | fc_tbl = &clp->cl_session->fc_slot_table; |
| 384 | |
| 385 | status = htonl(NFS4ERR_BAD_HIGH_SLOT); |
Andy Adamson | bae0ac0 | 2010-01-21 14:19:16 -0500 | [diff] [blame] | 386 | if (args->crsa_target_max_slots > fc_tbl->max_slots || |
Andy Adamson | b9efa1b | 2010-01-20 16:06:27 -0500 | [diff] [blame] | 387 | args->crsa_target_max_slots < 1) |
Andy Adamson | bae0ac0 | 2010-01-21 14:19:16 -0500 | [diff] [blame] | 388 | goto out_putclient; |
| 389 | |
| 390 | status = htonl(NFS4_OK); |
| 391 | if (args->crsa_target_max_slots == fc_tbl->max_slots) |
| 392 | goto out_putclient; |
Andy Adamson | b9efa1b | 2010-01-20 16:06:27 -0500 | [diff] [blame] | 393 | |
| 394 | fc_tbl->target_max_slots = args->crsa_target_max_slots; |
| 395 | nfs41_handle_recall_slot(clp); |
Andy Adamson | bae0ac0 | 2010-01-21 14:19:16 -0500 | [diff] [blame] | 396 | out_putclient: |
Andy Adamson | b9efa1b | 2010-01-20 16:06:27 -0500 | [diff] [blame] | 397 | nfs_put_client(clp); /* balance nfs_find_client */ |
| 398 | out: |
| 399 | dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); |
| 400 | return status; |
| 401 | } |
Benny Halevy | d49433e | 2009-04-01 09:23:25 -0400 | [diff] [blame] | 402 | #endif /* CONFIG_NFS_V4_1 */ |