Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * fs/nfs/nfs4session.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2012 Trond Myklebust <Trond.Myklebust@netapp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/printk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/sunrpc/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/sunrpc/bc_xprt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/nfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/nfs4.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/nfs_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "nfs4_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "nfs4session.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "callback.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define NFSDBG_FACILITY		NFSDBG_STATE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static void nfs4_init_slot_table(struct nfs4_slot_table *tbl, const char *queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	tbl->highest_used_slotid = NFS4_NO_SLOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	spin_lock_init(&tbl->slot_tbl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	init_waitqueue_head(&tbl->slot_waitq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	init_completion(&tbl->complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * nfs4_shrink_slot_table - free retired slots from the slot table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static void nfs4_shrink_slot_table(struct nfs4_slot_table  *tbl, u32 newsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct nfs4_slot **p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	if (newsize >= tbl->max_slots)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	p = &tbl->slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	while (newsize--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		p = &(*p)->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	while (*p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		struct nfs4_slot *slot = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		*p = slot->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		kfree(slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		tbl->max_slots--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * nfs4_slot_tbl_drain_complete - wake waiters when drain is complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * @tbl: controlling slot table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) void nfs4_slot_tbl_drain_complete(struct nfs4_slot_table *tbl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	if (nfs4_slot_tbl_draining(tbl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		complete(&tbl->complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * nfs4_free_slot - free a slot and efficiently update slot table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * freeing a slot is trivially done by clearing its respective bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  * in the bitmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  * If the freed slotid equals highest_used_slotid we want to update it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * so that the server would be able to size down the slot table if needed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  * otherwise we know that the highest_used_slotid is still in use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * When updating highest_used_slotid there may be "holes" in the bitmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * so we need to scan down from highest_used_slotid to 0 looking for the now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * highest slotid in use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * If none found, highest_used_slotid is set to NFS4_NO_SLOT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * Must be called while holding tbl->slot_tbl_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) void nfs4_free_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	u32 slotid = slot->slot_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	/* clear used bit in bitmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	__clear_bit(slotid, tbl->used_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	/* update highest_used_slotid when it is freed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	if (slotid == tbl->highest_used_slotid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		u32 new_max = find_last_bit(tbl->used_slots, slotid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		if (new_max < slotid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			tbl->highest_used_slotid = new_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			tbl->highest_used_slotid = NFS4_NO_SLOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			nfs4_slot_tbl_drain_complete(tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	dprintk("%s: slotid %u highest_used_slotid %u\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		slotid, tbl->highest_used_slotid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static struct nfs4_slot *nfs4_new_slot(struct nfs4_slot_table  *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		u32 slotid, u32 seq_init, gfp_t gfp_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	struct nfs4_slot *slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	slot = kzalloc(sizeof(*slot), gfp_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (slot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		slot->table = tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		slot->slot_nr = slotid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		slot->seq_nr = seq_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		slot->seq_nr_highest_sent = seq_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		slot->seq_nr_last_acked = seq_init - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	return slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static struct nfs4_slot *nfs4_find_or_create_slot(struct nfs4_slot_table  *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		u32 slotid, u32 seq_init, gfp_t gfp_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	struct nfs4_slot **p, *slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	p = &tbl->slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		if (*p == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			*p = nfs4_new_slot(tbl, tbl->max_slots,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 					seq_init, gfp_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			if (*p == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			tbl->max_slots++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		slot = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		if (slot->slot_nr == slotid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			return slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		p = &slot->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static void nfs4_lock_slot(struct nfs4_slot_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		struct nfs4_slot *slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	u32 slotid = slot->slot_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	__set_bit(slotid, tbl->used_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (slotid > tbl->highest_used_slotid ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	    tbl->highest_used_slotid == NFS4_NO_SLOT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		tbl->highest_used_slotid = slotid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	slot->generation = tbl->generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  * nfs4_try_to_lock_slot - Given a slot try to allocate it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  * Note: must be called with the slot_tbl_lock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) bool nfs4_try_to_lock_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	if (nfs4_test_locked_slot(tbl, slot->slot_nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	nfs4_lock_slot(tbl, slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)  * nfs4_lookup_slot - Find a slot but don't allocate it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)  * Note: must be called with the slot_tbl_lock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct nfs4_slot *nfs4_lookup_slot(struct nfs4_slot_table *tbl, u32 slotid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	if (slotid <= tbl->max_slotid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		return nfs4_find_or_create_slot(tbl, slotid, 0, GFP_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	return ERR_PTR(-E2BIG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static int nfs4_slot_get_seqid(struct nfs4_slot_table  *tbl, u32 slotid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		u32 *seq_nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	__must_hold(&tbl->slot_tbl_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	struct nfs4_slot *slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	slot = nfs4_lookup_slot(tbl, slotid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	ret = PTR_ERR_OR_ZERO(slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		*seq_nr = slot->seq_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  * nfs4_slot_seqid_in_use - test if a slot sequence id is still in use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  * Given a slot table, slot id and sequence number, determine if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  * RPC call in question is still in flight. This function is mainly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  * intended for use by the callback channel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static bool nfs4_slot_seqid_in_use(struct nfs4_slot_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		u32 slotid, u32 seq_nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	u32 cur_seq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	bool ret = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	spin_lock(&tbl->slot_tbl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	if (nfs4_slot_get_seqid(tbl, slotid, &cur_seq) == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	    cur_seq == seq_nr && test_bit(slotid, tbl->used_slots))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		ret = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	spin_unlock(&tbl->slot_tbl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  * nfs4_slot_wait_on_seqid - wait until a slot sequence id is complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)  * Given a slot table, slot id and sequence number, wait until the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)  * corresponding RPC call completes. This function is mainly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  * intended for use by the callback channel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) int nfs4_slot_wait_on_seqid(struct nfs4_slot_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		u32 slotid, u32 seq_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		unsigned long timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	if (wait_event_timeout(tbl->slot_waitq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			!nfs4_slot_seqid_in_use(tbl, slotid, seq_nr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			timeout) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		return -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  * nfs4_alloc_slot - efficiently look for a free slot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  * nfs4_alloc_slot looks for an unset bit in the used_slots bitmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  * If found, we mark the slot as used, update the highest_used_slotid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  * and respectively set up the sequence operation args.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  * Note: must be called with under the slot_tbl_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct nfs4_slot *nfs4_alloc_slot(struct nfs4_slot_table *tbl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	struct nfs4_slot *ret = ERR_PTR(-EBUSY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	u32 slotid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	dprintk("--> %s used_slots=%04lx highest_used=%u max_slots=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		__func__, tbl->used_slots[0], tbl->highest_used_slotid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		tbl->max_slotid + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slotid + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if (slotid <= tbl->max_slotid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		ret = nfs4_find_or_create_slot(tbl, slotid, 1, GFP_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		if (!IS_ERR(ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 			nfs4_lock_slot(tbl, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	dprintk("<-- %s used_slots=%04lx highest_used=%u slotid=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		__func__, tbl->used_slots[0], tbl->highest_used_slotid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		!IS_ERR(ret) ? ret->slot_nr : NFS4_NO_SLOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) static int nfs4_grow_slot_table(struct nfs4_slot_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		 u32 max_reqs, u32 ivalue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	if (max_reqs <= tbl->max_slots)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	if (!IS_ERR(nfs4_find_or_create_slot(tbl, max_reqs - 1, ivalue, GFP_NOFS)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static void nfs4_reset_slot_table(struct nfs4_slot_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		u32 server_highest_slotid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		u32 ivalue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	struct nfs4_slot **p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	nfs4_shrink_slot_table(tbl, server_highest_slotid + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	p = &tbl->slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	while (*p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		(*p)->seq_nr = ivalue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		(*p)->seq_nr_highest_sent = ivalue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		(*p)->seq_nr_last_acked = ivalue - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		p = &(*p)->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	tbl->highest_used_slotid = NFS4_NO_SLOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	tbl->target_highest_slotid = server_highest_slotid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	tbl->server_highest_slotid = server_highest_slotid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	tbl->d_target_highest_slotid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	tbl->d2_target_highest_slotid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	tbl->max_slotid = server_highest_slotid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)  * (re)Initialise a slot table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static int nfs4_realloc_slot_table(struct nfs4_slot_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		u32 max_reqs, u32 ivalue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	dprintk("--> %s: max_reqs=%u, tbl->max_slots %u\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		max_reqs, tbl->max_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	if (max_reqs > NFS4_MAX_SLOT_TABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		max_reqs = NFS4_MAX_SLOT_TABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	ret = nfs4_grow_slot_table(tbl, max_reqs, ivalue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	spin_lock(&tbl->slot_tbl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	nfs4_reset_slot_table(tbl, max_reqs - 1, ivalue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	spin_unlock(&tbl->slot_tbl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	dprintk("%s: tbl=%p slots=%p max_slots=%u\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		tbl, tbl->slots, tbl->max_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	dprintk("<-- %s: return %d\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)  * nfs4_release_slot_table - release all slot table entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) static void nfs4_release_slot_table(struct nfs4_slot_table *tbl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	nfs4_shrink_slot_table(tbl, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)  * nfs4_shutdown_slot_table - release resources attached to a slot table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)  * @tbl: slot table to shut down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) void nfs4_shutdown_slot_table(struct nfs4_slot_table *tbl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	nfs4_release_slot_table(tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	rpc_destroy_wait_queue(&tbl->slot_tbl_waitq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)  * nfs4_setup_slot_table - prepare a stand-alone slot table for use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)  * @tbl: slot table to set up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)  * @max_reqs: maximum number of requests allowed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)  * @queue: name to give RPC wait queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)  * Returns zero on success, or a negative errno.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) int nfs4_setup_slot_table(struct nfs4_slot_table *tbl, unsigned int max_reqs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		const char *queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	nfs4_init_slot_table(tbl, queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	return nfs4_realloc_slot_table(tbl, max_reqs, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) static bool nfs41_assign_slot(struct rpc_task *task, void *pslot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	struct nfs4_sequence_args *args = task->tk_msg.rpc_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	struct nfs4_sequence_res *res = task->tk_msg.rpc_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	struct nfs4_slot *slot = pslot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	struct nfs4_slot_table *tbl = slot->table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	slot->generation = tbl->generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	args->sa_slot = slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	res->sr_timestamp = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	res->sr_slot = slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	res->sr_status_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	res->sr_status = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) static bool __nfs41_wake_and_assign_slot(struct nfs4_slot_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		struct nfs4_slot *slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	if (rpc_wake_up_first(&tbl->slot_tbl_waitq, nfs41_assign_slot, slot))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) bool nfs41_wake_and_assign_slot(struct nfs4_slot_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		struct nfs4_slot *slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	if (slot->slot_nr > tbl->max_slotid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	return __nfs41_wake_and_assign_slot(tbl, slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) static bool nfs41_try_wake_next_slot_table_entry(struct nfs4_slot_table *tbl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	struct nfs4_slot *slot = nfs4_alloc_slot(tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	if (!IS_ERR(slot)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		bool ret = __nfs41_wake_and_assign_slot(tbl, slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		nfs4_free_slot(tbl, slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) void nfs41_wake_slot_table(struct nfs4_slot_table *tbl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		if (!nfs41_try_wake_next_slot_table_entry(tbl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) #if defined(CONFIG_NFS_V4_1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) static void nfs41_set_max_slotid_locked(struct nfs4_slot_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		u32 target_highest_slotid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	u32 max_slotid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	max_slotid = min(NFS4_MAX_SLOT_TABLE - 1, target_highest_slotid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	if (max_slotid > tbl->server_highest_slotid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		max_slotid = tbl->server_highest_slotid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	if (max_slotid > tbl->target_highest_slotid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		max_slotid = tbl->target_highest_slotid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	tbl->max_slotid = max_slotid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	nfs41_wake_slot_table(tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) /* Update the client's idea of target_highest_slotid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) static void nfs41_set_target_slotid_locked(struct nfs4_slot_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		u32 target_highest_slotid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	if (tbl->target_highest_slotid == target_highest_slotid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	tbl->target_highest_slotid = target_highest_slotid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	tbl->generation++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) void nfs41_set_target_slotid(struct nfs4_slot_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		u32 target_highest_slotid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	spin_lock(&tbl->slot_tbl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	nfs41_set_target_slotid_locked(tbl, target_highest_slotid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	tbl->d_target_highest_slotid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	tbl->d2_target_highest_slotid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	nfs41_set_max_slotid_locked(tbl, target_highest_slotid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	spin_unlock(&tbl->slot_tbl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) static void nfs41_set_server_slotid_locked(struct nfs4_slot_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		u32 highest_slotid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	if (tbl->server_highest_slotid == highest_slotid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	if (tbl->highest_used_slotid > highest_slotid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	/* Deallocate slots */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	nfs4_shrink_slot_table(tbl, highest_slotid + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	tbl->server_highest_slotid = highest_slotid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) static s32 nfs41_derivative_target_slotid(s32 s1, s32 s2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	s1 -= s2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	if (s1 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	if (s1 < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		return (s1 - 1) >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	return (s1 + 1) >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) static int nfs41_sign_s32(s32 s1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	if (s1 > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	if (s1 < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) static bool nfs41_same_sign_or_zero_s32(s32 s1, s32 s2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	if (!s1 || !s2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	return nfs41_sign_s32(s1) == nfs41_sign_s32(s2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) /* Try to eliminate outliers by checking for sharp changes in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)  * derivatives and second derivatives
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) static bool nfs41_is_outlier_target_slotid(struct nfs4_slot_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		u32 new_target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	s32 d_target, d2_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	bool ret = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	d_target = nfs41_derivative_target_slotid(new_target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 			tbl->target_highest_slotid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	d2_target = nfs41_derivative_target_slotid(d_target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 			tbl->d_target_highest_slotid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	/* Is first derivative same sign? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	if (nfs41_same_sign_or_zero_s32(d_target, tbl->d_target_highest_slotid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		ret = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	/* Is second derivative same sign? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	if (nfs41_same_sign_or_zero_s32(d2_target, tbl->d2_target_highest_slotid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		ret = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	tbl->d_target_highest_slotid = d_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	tbl->d2_target_highest_slotid = d2_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) void nfs41_update_target_slotid(struct nfs4_slot_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		struct nfs4_slot *slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		struct nfs4_sequence_res *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	spin_lock(&tbl->slot_tbl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	if (!nfs41_is_outlier_target_slotid(tbl, res->sr_target_highest_slotid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 		nfs41_set_target_slotid_locked(tbl, res->sr_target_highest_slotid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	if (tbl->generation == slot->generation)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		nfs41_set_server_slotid_locked(tbl, res->sr_highest_slotid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	nfs41_set_max_slotid_locked(tbl, res->sr_target_highest_slotid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	spin_unlock(&tbl->slot_tbl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) static void nfs4_release_session_slot_tables(struct nfs4_session *session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	nfs4_release_slot_table(&session->fc_slot_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	nfs4_release_slot_table(&session->bc_slot_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)  * Initialize or reset the forechannel and backchannel tables
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) int nfs4_setup_session_slot_tables(struct nfs4_session *ses)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	struct nfs4_slot_table *tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	dprintk("--> %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	/* Fore channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	tbl = &ses->fc_slot_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	tbl->session = ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	status = nfs4_realloc_slot_table(tbl, ses->fc_attrs.max_reqs, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	if (status || !(ses->flags & SESSION4_BACK_CHAN)) /* -ENOMEM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	/* Back channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	tbl = &ses->bc_slot_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	tbl->session = ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	status = nfs4_realloc_slot_table(tbl, ses->bc_attrs.max_reqs, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	if (status && tbl->slots == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 		/* Fore and back channel share a connection so get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 		 * both slot tables or neither */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 		nfs4_release_session_slot_tables(ses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	struct nfs4_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	if (!session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	nfs4_init_slot_table(&session->fc_slot_table, "ForeChannel Slot table");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	nfs4_init_slot_table(&session->bc_slot_table, "BackChannel Slot table");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	session->session_state = 1<<NFS4_SESSION_INITING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	session->clp = clp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	return session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) static void nfs4_destroy_session_slot_tables(struct nfs4_session *session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	nfs4_shutdown_slot_table(&session->fc_slot_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	nfs4_shutdown_slot_table(&session->bc_slot_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) void nfs4_destroy_session(struct nfs4_session *session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	struct rpc_xprt *xprt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	const struct cred *cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	cred = nfs4_get_clid_cred(session->clp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	nfs4_proc_destroy_session(session, cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	put_cred(cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	xprt = rcu_dereference(session->clp->cl_rpcclient->cl_xprt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	dprintk("%s Destroy backchannel for xprt %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 		__func__, xprt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	xprt_destroy_backchannel(xprt, NFS41_BC_MIN_CALLBACKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	nfs4_destroy_session_slot_tables(session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	kfree(session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)  * With sessions, the client is not marked ready until after a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)  * successful EXCHANGE_ID and CREATE_SESSION.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)  * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)  * other versions of NFS can be tried.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) static int nfs41_check_session_ready(struct nfs_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	if (clp->cl_cons_state == NFS_CS_SESSION_INITING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 		ret = nfs4_client_recover_expired_lease(clp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	if (clp->cl_cons_state < NFS_CS_READY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 		return -EPROTONOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	smp_rmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) int nfs4_init_session(struct nfs_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	if (!nfs4_has_session(clp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	clear_bit(NFS4_SESSION_INITING, &clp->cl_session->session_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	return nfs41_check_session_ready(clp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) int nfs4_init_ds_session(struct nfs_client *clp, unsigned long lease_time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	struct nfs4_session *session = clp->cl_session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	spin_lock(&clp->cl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 		 * Do not set NFS_CS_CHECK_LEASE_TIME instead set the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 		 * DS lease to be equal to the MDS lease.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 		clp->cl_lease_time = lease_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 		clp->cl_last_renewal = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	spin_unlock(&clp->cl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	ret = nfs41_check_session_ready(clp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	/* Test for the DS role */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	if (!is_ds_client(clp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) EXPORT_SYMBOL_GPL(nfs4_init_ds_session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) #endif	/* defined(CONFIG_NFS_V4_1) */