8 #include <linux/nfs4.h>
9 #include <linux/nfs_fs.h>
10 #include <linux/slab.h>
19 #define NFSDBG_FACILITY NFSDBG_CALLBACK
26 struct nfs_delegation *delegation;
37 dprintk_rcu(
"NFS: GETATTR callback request from %s\n",
48 res->
size = i_size_read(inode);
77 dprintk_rcu(
"NFS: RECALL callback request from %s\n",
97 dprintk(
"%s: exit with status = %d\n", __func__,
ntohl(res));
101 #if defined(CONFIG_NFS_V4_1)
112 static struct pnfs_layout_hdr * get_layout_by_fh_locked(
struct nfs_client *clp,
struct nfs_fh *fh)
116 struct pnfs_layout_hdr *
lo;
118 list_for_each_entry_rcu(server, &clp->
cl_superblocks, client_link) {
120 if (nfs_compare_fh(fh, &NFS_I(lo->plh_inode)->fh))
122 ino =
igrab(lo->plh_inode);
127 if (NFS_I(ino)->
layout != lo) {
128 spin_unlock(&ino->
i_lock);
133 spin_unlock(&ino->
i_lock);
141 static struct pnfs_layout_hdr * get_layout_by_fh(
struct nfs_client *clp,
struct nfs_fh *fh)
143 struct pnfs_layout_hdr *lo;
145 spin_lock(&clp->cl_lock);
147 lo = get_layout_by_fh_locked(clp, fh);
149 spin_unlock(&clp->cl_lock);
155 struct cb_layoutrecallargs *args)
158 struct pnfs_layout_hdr *lo;
162 lo = get_layout_by_fh(clp, &args->cbl_fh);
168 if (
test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags) ||
175 spin_unlock(&ino->
i_lock);
183 struct cb_layoutrecallargs *args)
186 struct pnfs_layout_hdr *lo;
189 struct pnfs_layout_hdr *
tmp;
198 spin_lock(&clp->cl_lock);
200 list_for_each_entry_rcu(server, &clp->
cl_superblocks, client_link) {
207 ino =
igrab(lo->plh_inode);
212 if (NFS_I(ino)->
layout != lo) {
213 spin_unlock(&ino->
i_lock);
218 spin_unlock(&ino->
i_lock);
219 BUG_ON(!list_empty(&lo->plh_bulk_recall));
220 list_add(&lo->plh_bulk_recall, &recall_list);
224 spin_unlock(&clp->cl_lock);
227 &recall_list, plh_bulk_recall) {
230 set_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags);
233 list_del_init(&lo->plh_bulk_recall);
234 spin_unlock(&ino->
i_lock);
243 struct cb_layoutrecallargs *args)
247 dprintk(
"%s enter, type=%i\n", __func__, args->cbl_recall_type);
249 res = initiate_file_draining(clp, args);
251 res = initiate_bulk_draining(clp, args);
252 dprintk(
"%s returning %i\n", __func__, res);
257 __be32 nfs4_callback_layoutrecall(
struct cb_layoutrecallargs *args,
262 dprintk(
"%s: -->\n", __func__);
265 res = do_callback_layoutrecall(cps->
clp, args);
269 dprintk(
"%s: exit with status = %d\n", __func__, res);
273 static void pnfs_recall_all_layouts(
struct nfs_client *clp)
275 struct cb_layoutrecallargs args;
278 memset(&args, 0,
sizeof(args));
281 do_callback_layoutrecall(clp, &args);
284 __be32 nfs4_callback_devicenotify(
struct cb_devicenotifyargs *args,
292 dprintk(
"%s: -->\n", __func__);
299 for (i = 0; i < args->ndevs; i++) {
300 struct cb_devicenotifyitem *
dev = &args->devs[
i];
303 server->pnfs_curr_ld->id != dev->cbd_layout_type) {
305 list_for_each_entry_rcu(server, &clp->
cl_superblocks, client_link)
306 if (server->pnfs_curr_ld &&
307 server->pnfs_curr_ld->
id == dev->cbd_layout_type) {
312 dprintk(
"%s: layout type %u not found\n",
313 __func__, dev->cbd_layout_type);
319 dprintk(
"%s: NOTIFY_DEVICEID4_CHANGE not supported, "
320 "deleting instead\n", __func__);
326 dprintk(
"%s: exit with status = %u\n",
345 validate_seqid(
struct nfs4_slot_table *tbl,
struct cb_sequenceargs * args)
349 dprintk(
"%s enter. slotid %d seqid %d\n",
350 __func__, args->csa_slotid, args->csa_sequenceid);
355 slot = tbl->slots + args->csa_slotid;
356 dprintk(
"%s slot table seqid: %d\n", __func__, slot->
seq_nr);
365 if (args->csa_sequenceid == slot->
seq_nr) {
366 dprintk(
"%s seqid %d is a replay\n",
367 __func__, args->csa_sequenceid);
369 if (args->csa_cachethis == 0)
373 else if (args->csa_cachethis == 1)
378 if (args->csa_sequenceid == 1 && (slot->
seq_nr + 1) == 0) {
386 tbl->highest_used_slotid = args->csa_slotid;
395 static bool referring_call_exists(
struct nfs_client *clp,
397 struct referring_call_list *rclists)
401 struct nfs4_session *session;
402 struct nfs4_slot_table *tbl;
403 struct referring_call_list *rclist;
404 struct referring_call *ref;
410 session = clp->cl_session;
411 tbl = &session->fc_slot_table;
413 for (i = 0; i < nrclists; i++) {
414 rclist = &rclists[
i];
415 if (
memcmp(session->sess_id.data,
416 rclist->rcl_sessionid.data,
420 for (j = 0; j < rclist->rcl_nrefcalls; j++) {
421 ref = &rclist->rcl_refcalls[
j];
423 dprintk(
"%s: sessionid %x:%x:%x:%x sequenceid %u "
424 "slotid %u\n", __func__,
425 ((
u32 *)&rclist->rcl_sessionid.data)[0],
426 ((
u32 *)&rclist->rcl_sessionid.data)[1],
427 ((
u32 *)&rclist->rcl_sessionid.data)[2],
428 ((
u32 *)&rclist->rcl_sessionid.data)[3],
429 ref->rc_sequenceid, ref->rc_slotid);
431 spin_lock(&tbl->slot_tbl_lock);
432 status = (
test_bit(ref->rc_slotid, tbl->used_slots) &&
433 tbl->slots[ref->rc_slotid].seq_nr ==
435 spin_unlock(&tbl->slot_tbl_lock);
445 __be32 nfs4_callback_sequence(
struct cb_sequenceargs *args,
446 struct cb_sequenceres *res,
449 struct nfs4_slot_table *tbl;
458 tbl = &clp->cl_session->bc_slot_table;
460 spin_lock(&tbl->slot_tbl_lock);
462 if (
test_bit(NFS4_SESSION_DRAINING, &clp->cl_session->session_state)) {
463 spin_unlock(&tbl->slot_tbl_lock);
468 if (
test_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state))
473 status = validate_seqid(&clp->cl_session->bc_slot_table, args);
474 spin_unlock(&tbl->slot_tbl_lock);
478 cps->
slotid = args->csa_slotid;
485 if (referring_call_exists(clp, args->csa_nrclists, args->csa_rclists)) {
490 memcpy(&res->csr_sessionid, &args->csa_sessionid,
491 sizeof(res->csr_sessionid));
492 res->csr_sequenceid = args->csa_sequenceid;
493 res->csr_slotid = args->csa_slotid;
499 for (i = 0; i < args->csa_nrclists; i++)
500 kfree(args->csa_rclists[i].rcl_refcalls);
501 kfree(args->csa_rclists);
509 dprintk(
"%s: exit with status = %d res->csr_status %d\n", __func__,
515 validate_bitmap_values(
unsigned long mask)
517 return (mask & ~RCA4_TYPE_MASK_ALL) == 0;
520 __be32 nfs4_callback_recallany(
struct cb_recallanyargs *args,
void *dummy,
530 dprintk_rcu(
"NFS: RECALL_ANY callback request from %s\n",
534 if (!validate_bitmap_values(args->craa_type_mask))
538 if (
test_bit(RCA4_TYPE_MASK_RDATA_DLG, (
const unsigned long *)
539 &args->craa_type_mask))
541 if (
test_bit(RCA4_TYPE_MASK_WDATA_DLG, (
const unsigned long *)
542 &args->craa_type_mask))
544 if (
test_bit(RCA4_TYPE_MASK_FILE_LAYOUT, (
const unsigned long *)
545 &args->craa_type_mask))
546 pnfs_recall_all_layouts(cps->
clp);
550 dprintk(
"%s: exit with status = %d\n", __func__,
ntohl(status));
555 __be32 nfs4_callback_recallslot(
struct cb_recallslotargs *args,
void *dummy,
558 struct nfs4_slot_table *fc_tbl;
565 dprintk_rcu(
"NFS: CB_RECALL_SLOT request from %s target max slots %d\n",
567 args->crsa_target_max_slots);
569 fc_tbl = &cps->
clp->cl_session->fc_slot_table;
572 if (args->crsa_target_max_slots > fc_tbl->max_slots ||
573 args->crsa_target_max_slots < 1)
577 if (args->crsa_target_max_slots == fc_tbl->max_slots)
580 fc_tbl->target_max_slots = args->crsa_target_max_slots;
581 nfs41_handle_recall_slot(cps->
clp);
583 dprintk(
"%s: exit with status = %d\n", __func__,
ntohl(status));