fs/nfs/nfs4session.c

Source file repositories/reference/linux-study-clean/fs/nfs/nfs4session.c

File Facts

System
Linux kernel
Corpus path
fs/nfs/nfs4session.c
Extension
.c
Size
17235 bytes
Lines
654
Domain
Core OS
Bucket
VFS And Filesystem Core
Inferred role
Core OS: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

if (*p == NULL) {
			*p = nfs4_new_slot(tbl, tbl->max_slots,
					seq_init, gfp_mask);
			if (*p == NULL)
				break;
			tbl->max_slots++;
		}
		slot = *p;
		if (slot->slot_nr == slotid)
			return slot;
		p = &slot->next;
	}
	return ERR_PTR(-ENOMEM);
}

static void nfs4_lock_slot(struct nfs4_slot_table *tbl,
		struct nfs4_slot *slot)
{
	u32 slotid = slot->slot_nr;

	__set_bit(slotid, tbl->used_slots);
	if (slotid > tbl->highest_used_slotid ||
	    tbl->highest_used_slotid == NFS4_NO_SLOT)
		tbl->highest_used_slotid = slotid;
	slot->generation = tbl->generation;
}

/*
 * nfs4_try_to_lock_slot - Given a slot try to allocate it
 *
 * Note: must be called with the slot_tbl_lock held.
 */
bool nfs4_try_to_lock_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *slot)
{
	if (nfs4_test_locked_slot(tbl, slot->slot_nr))
		return false;
	nfs4_lock_slot(tbl, slot);
	return true;
}

/*
 * nfs4_lookup_slot - Find a slot but don't allocate it
 *
 * Note: must be called with the slot_tbl_lock held.
 */
struct nfs4_slot *nfs4_lookup_slot(struct nfs4_slot_table *tbl, u32 slotid)
{
	if (slotid <= tbl->max_slotid)
		return nfs4_find_or_create_slot(tbl, slotid, 0, GFP_NOWAIT);
	return ERR_PTR(-E2BIG);
}

static int nfs4_slot_get_seqid(struct nfs4_slot_table  *tbl, u32 slotid,
		u32 *seq_nr)
	__must_hold(&tbl->slot_tbl_lock)
{
	struct nfs4_slot *slot;
	int ret;

	slot = nfs4_lookup_slot(tbl, slotid);
	ret = PTR_ERR_OR_ZERO(slot);
	if (!ret)
		*seq_nr = slot->seq_nr;

	return ret;
}

/*
 * nfs4_slot_seqid_in_use - test if a slot sequence id is still in use
 *
 * Given a slot table, slot id and sequence number, determine if the
 * RPC call in question is still in flight. This function is mainly
 * intended for use by the callback channel.
 */
static bool nfs4_slot_seqid_in_use(struct nfs4_slot_table *tbl,
		u32 slotid, u32 seq_nr)
{
	u32 cur_seq = 0;
	bool ret = false;

	spin_lock(&tbl->slot_tbl_lock);
	if (nfs4_slot_get_seqid(tbl, slotid, &cur_seq) == 0 &&
	    cur_seq == seq_nr && test_bit(slotid, tbl->used_slots))
		ret = true;
	spin_unlock(&tbl->slot_tbl_lock);
	return ret;
}

/*
 * nfs4_slot_wait_on_seqid - wait until a slot sequence id is complete

Annotation

Implementation Notes