NFSv4.1: Allow SEQUENCE to resize the slot table on the fly
Instead of an array of slots, use a singly linked list of slots that can be dynamically appended to or shrunk. Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
This commit is contained in:
parent
97e548a93d
commit
87dda67e73
@ -258,10 +258,10 @@ extern int nfs4_proc_get_lease_time(struct nfs_client *clp,
|
|||||||
extern int nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data,
|
extern int nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data,
|
||||||
bool sync);
|
bool sync);
|
||||||
|
|
||||||
extern struct nfs4_slot *nfs4_alloc_slots(struct nfs4_slot_table *table,
|
|
||||||
u32 max_slots, gfp_t gfp_flags);
|
|
||||||
extern void nfs41_set_target_slotid(struct nfs4_slot_table *tbl,
|
extern void nfs41_set_target_slotid(struct nfs4_slot_table *tbl,
|
||||||
u32 target_highest_slotid);
|
u32 target_highest_slotid);
|
||||||
|
extern int nfs4_resize_slot_table(struct nfs4_slot_table *tbl,
|
||||||
|
u32 max_reqs, u32 ivalue);
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
is_ds_only_client(struct nfs_client *clp)
|
is_ds_only_client(struct nfs_client *clp)
|
||||||
|
@ -396,6 +396,27 @@ static void renew_lease(const struct nfs_server *server, unsigned long timestamp
|
|||||||
|
|
||||||
#if defined(CONFIG_NFS_V4_1)
|
#if defined(CONFIG_NFS_V4_1)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nfs4_shrink_slot_table - free retired slots from the slot table
|
||||||
|
*/
|
||||||
|
static void nfs4_shrink_slot_table(struct nfs4_slot_table *tbl, u32 newsize)
|
||||||
|
{
|
||||||
|
struct nfs4_slot **p;
|
||||||
|
if (newsize >= tbl->max_slots)
|
||||||
|
return;
|
||||||
|
|
||||||
|
p = &tbl->slots;
|
||||||
|
while (newsize--)
|
||||||
|
p = &(*p)->next;
|
||||||
|
while (*p) {
|
||||||
|
struct nfs4_slot *slot = *p;
|
||||||
|
|
||||||
|
*p = slot->next;
|
||||||
|
kfree(slot);
|
||||||
|
tbl->max_slots--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nfs4_free_slot - free a slot and efficiently update slot table.
|
* nfs4_free_slot - free a slot and efficiently update slot table.
|
||||||
*
|
*
|
||||||
@ -499,7 +520,7 @@ static void nfs41_set_target_slotid_locked(struct nfs4_slot_table *tbl,
|
|||||||
tbl->target_highest_slotid = target_highest_slotid;
|
tbl->target_highest_slotid = target_highest_slotid;
|
||||||
tbl->generation++;
|
tbl->generation++;
|
||||||
|
|
||||||
max_slotid = min(tbl->max_slots - 1, tbl->target_highest_slotid);
|
max_slotid = min(NFS4_MAX_SLOT_TABLE - 1, tbl->target_highest_slotid);
|
||||||
for (i = tbl->max_slotid + 1; i <= max_slotid; i++)
|
for (i = tbl->max_slotid + 1; i <= max_slotid; i++)
|
||||||
rpc_wake_up_next(&tbl->slot_tbl_waitq);
|
rpc_wake_up_next(&tbl->slot_tbl_waitq);
|
||||||
tbl->max_slotid = max_slotid;
|
tbl->max_slotid = max_slotid;
|
||||||
@ -516,16 +537,12 @@ void nfs41_set_target_slotid(struct nfs4_slot_table *tbl,
|
|||||||
static void nfs41_set_server_slotid_locked(struct nfs4_slot_table *tbl,
|
static void nfs41_set_server_slotid_locked(struct nfs4_slot_table *tbl,
|
||||||
u32 highest_slotid)
|
u32 highest_slotid)
|
||||||
{
|
{
|
||||||
unsigned int max_slotid, i;
|
|
||||||
|
|
||||||
if (tbl->server_highest_slotid == highest_slotid)
|
if (tbl->server_highest_slotid == highest_slotid)
|
||||||
return;
|
return;
|
||||||
if (tbl->highest_used_slotid > highest_slotid)
|
if (tbl->highest_used_slotid > highest_slotid)
|
||||||
return;
|
return;
|
||||||
max_slotid = min(tbl->max_slots - 1, highest_slotid);
|
/* Deallocate slots */
|
||||||
/* Reset the seq_nr for deallocated slots */
|
nfs4_shrink_slot_table(tbl, highest_slotid + 1);
|
||||||
for (i = tbl->server_highest_slotid + 1; i <= max_slotid; i++)
|
|
||||||
tbl->slots[i].seq_nr = 1;
|
|
||||||
tbl->server_highest_slotid = highest_slotid;
|
tbl->server_highest_slotid = highest_slotid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -612,6 +629,42 @@ static int nfs4_sequence_done(struct rpc_task *task,
|
|||||||
return nfs41_sequence_done(task, res);
|
return nfs41_sequence_done(task, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct nfs4_slot *nfs4_new_slot(struct nfs4_slot_table *tbl,
|
||||||
|
u32 slotid, u32 seq_init, gfp_t gfp_mask)
|
||||||
|
{
|
||||||
|
struct nfs4_slot *slot;
|
||||||
|
|
||||||
|
slot = kzalloc(sizeof(*slot), gfp_mask);
|
||||||
|
if (slot) {
|
||||||
|
slot->table = tbl;
|
||||||
|
slot->slot_nr = slotid;
|
||||||
|
slot->seq_nr = seq_init;
|
||||||
|
}
|
||||||
|
return slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct nfs4_slot *nfs4_find_or_create_slot(struct nfs4_slot_table *tbl,
|
||||||
|
u32 slotid, u32 seq_init, gfp_t gfp_mask)
|
||||||
|
{
|
||||||
|
struct nfs4_slot **p, *slot;
|
||||||
|
|
||||||
|
p = &tbl->slots;
|
||||||
|
for (;;) {
|
||||||
|
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 NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nfs4_alloc_slot - efficiently look for a free slot
|
* nfs4_alloc_slot - efficiently look for a free slot
|
||||||
*
|
*
|
||||||
@ -628,15 +681,17 @@ static struct nfs4_slot *nfs4_alloc_slot(struct nfs4_slot_table *tbl)
|
|||||||
|
|
||||||
dprintk("--> %s used_slots=%04lx highest_used=%u max_slots=%u\n",
|
dprintk("--> %s used_slots=%04lx highest_used=%u max_slots=%u\n",
|
||||||
__func__, tbl->used_slots[0], tbl->highest_used_slotid,
|
__func__, tbl->used_slots[0], tbl->highest_used_slotid,
|
||||||
tbl->max_slots);
|
tbl->max_slotid + 1);
|
||||||
slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slotid + 1);
|
slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slotid + 1);
|
||||||
if (slotid > tbl->max_slotid)
|
if (slotid > tbl->max_slotid)
|
||||||
goto out;
|
goto out;
|
||||||
|
ret = nfs4_find_or_create_slot(tbl, slotid, 1, GFP_NOWAIT);
|
||||||
|
if (ret == NULL)
|
||||||
|
goto out;
|
||||||
__set_bit(slotid, tbl->used_slots);
|
__set_bit(slotid, tbl->used_slots);
|
||||||
if (slotid > tbl->highest_used_slotid ||
|
if (slotid > tbl->highest_used_slotid ||
|
||||||
tbl->highest_used_slotid == NFS4_NO_SLOT)
|
tbl->highest_used_slotid == NFS4_NO_SLOT)
|
||||||
tbl->highest_used_slotid = slotid;
|
tbl->highest_used_slotid = slotid;
|
||||||
ret = &tbl->slots[slotid];
|
|
||||||
ret->renewal_time = jiffies;
|
ret->renewal_time = jiffies;
|
||||||
ret->generation = tbl->generation;
|
ret->generation = tbl->generation;
|
||||||
|
|
||||||
@ -5718,67 +5773,56 @@ int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct nfs4_slot *nfs4_alloc_slots(struct nfs4_slot_table *table,
|
static int nfs4_grow_slot_table(struct nfs4_slot_table *tbl,
|
||||||
u32 max_slots, gfp_t gfp_flags)
|
u32 max_reqs, u32 ivalue)
|
||||||
{
|
{
|
||||||
struct nfs4_slot *tbl;
|
if (max_reqs <= tbl->max_slots)
|
||||||
u32 i;
|
return 0;
|
||||||
|
if (nfs4_find_or_create_slot(tbl, max_reqs - 1, ivalue, GFP_NOFS))
|
||||||
tbl = kmalloc_array(max_slots, sizeof(*tbl), gfp_flags);
|
return 0;
|
||||||
if (tbl != NULL) {
|
return -ENOMEM;
|
||||||
for (i = 0; i < max_slots; i++) {
|
|
||||||
tbl[i].table = table;
|
|
||||||
tbl[i].slot_nr = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tbl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void nfs4_add_and_init_slots(struct nfs4_slot_table *tbl,
|
static void nfs4_reset_slot_table(struct nfs4_slot_table *tbl,
|
||||||
struct nfs4_slot *new,
|
u32 server_highest_slotid,
|
||||||
u32 max_slots,
|
|
||||||
u32 ivalue)
|
u32 ivalue)
|
||||||
{
|
{
|
||||||
struct nfs4_slot *old = NULL;
|
struct nfs4_slot **p;
|
||||||
u32 i;
|
|
||||||
|
|
||||||
spin_lock(&tbl->slot_tbl_lock);
|
nfs4_shrink_slot_table(tbl, server_highest_slotid + 1);
|
||||||
if (new) {
|
p = &tbl->slots;
|
||||||
old = tbl->slots;
|
while (*p) {
|
||||||
tbl->slots = new;
|
(*p)->seq_nr = ivalue;
|
||||||
tbl->max_slots = max_slots;
|
p = &(*p)->next;
|
||||||
}
|
}
|
||||||
tbl->highest_used_slotid = NFS4_NO_SLOT;
|
tbl->highest_used_slotid = NFS4_NO_SLOT;
|
||||||
tbl->target_highest_slotid = max_slots - 1;
|
tbl->target_highest_slotid = server_highest_slotid;
|
||||||
tbl->server_highest_slotid = max_slots - 1;
|
tbl->server_highest_slotid = server_highest_slotid;
|
||||||
tbl->max_slotid = max_slots - 1;
|
tbl->max_slotid = server_highest_slotid;
|
||||||
for (i = 0; i < tbl->max_slots; i++)
|
|
||||||
tbl->slots[i].seq_nr = ivalue;
|
|
||||||
spin_unlock(&tbl->slot_tbl_lock);
|
|
||||||
kfree(old);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (re)Initialise a slot table
|
* (re)Initialise a slot table
|
||||||
*/
|
*/
|
||||||
static int nfs4_realloc_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs,
|
static int nfs4_realloc_slot_table(struct nfs4_slot_table *tbl,
|
||||||
u32 ivalue)
|
u32 max_reqs, u32 ivalue)
|
||||||
{
|
{
|
||||||
struct nfs4_slot *new = NULL;
|
int ret;
|
||||||
int ret = -ENOMEM;
|
|
||||||
|
|
||||||
dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__,
|
dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__,
|
||||||
max_reqs, tbl->max_slots);
|
max_reqs, tbl->max_slots);
|
||||||
|
|
||||||
/* Does the newly negotiated max_reqs match the existing slot table? */
|
if (max_reqs > NFS4_MAX_SLOT_TABLE)
|
||||||
if (max_reqs != tbl->max_slots) {
|
max_reqs = NFS4_MAX_SLOT_TABLE;
|
||||||
new = nfs4_alloc_slots(tbl, max_reqs, GFP_NOFS);
|
|
||||||
if (!new)
|
ret = nfs4_grow_slot_table(tbl, max_reqs, ivalue);
|
||||||
goto out;
|
if (ret)
|
||||||
}
|
goto out;
|
||||||
ret = 0;
|
|
||||||
|
spin_lock(&tbl->slot_tbl_lock);
|
||||||
|
nfs4_reset_slot_table(tbl, max_reqs - 1, ivalue);
|
||||||
|
spin_unlock(&tbl->slot_tbl_lock);
|
||||||
|
|
||||||
nfs4_add_and_init_slots(tbl, new, max_reqs, ivalue);
|
|
||||||
dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__,
|
dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__,
|
||||||
tbl, tbl->slots, tbl->max_slots);
|
tbl, tbl->slots, tbl->max_slots);
|
||||||
out:
|
out:
|
||||||
@ -5786,18 +5830,28 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int nfs4_resize_slot_table(struct nfs4_slot_table *tbl,
|
||||||
|
u32 max_reqs, u32 ivalue)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (max_reqs > NFS4_MAX_SLOT_TABLE)
|
||||||
|
max_reqs = NFS4_MAX_SLOT_TABLE;
|
||||||
|
ret = nfs4_grow_slot_table(tbl, max_reqs, ivalue);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
spin_lock(&tbl->slot_tbl_lock);
|
||||||
|
nfs4_shrink_slot_table(tbl, max_reqs);
|
||||||
|
tbl->max_slotid = max_reqs - 1;
|
||||||
|
spin_unlock(&tbl->slot_tbl_lock);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Destroy the slot table */
|
/* Destroy the slot table */
|
||||||
static void nfs4_destroy_slot_tables(struct nfs4_session *session)
|
static void nfs4_destroy_slot_tables(struct nfs4_session *session)
|
||||||
{
|
{
|
||||||
if (session->fc_slot_table.slots != NULL) {
|
nfs4_shrink_slot_table(&session->fc_slot_table, 0);
|
||||||
kfree(session->fc_slot_table.slots);
|
nfs4_shrink_slot_table(&session->bc_slot_table, 0);
|
||||||
session->fc_slot_table.slots = NULL;
|
|
||||||
}
|
|
||||||
if (session->bc_slot_table.slots != NULL) {
|
|
||||||
kfree(session->bc_slot_table.slots);
|
|
||||||
session->bc_slot_table.slots = NULL;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2025,29 +2025,15 @@ out:
|
|||||||
static int nfs4_recall_slot(struct nfs_client *clp)
|
static int nfs4_recall_slot(struct nfs_client *clp)
|
||||||
{
|
{
|
||||||
struct nfs4_slot_table *fc_tbl;
|
struct nfs4_slot_table *fc_tbl;
|
||||||
struct nfs4_slot *new, *old;
|
u32 new_size;
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!nfs4_has_session(clp))
|
if (!nfs4_has_session(clp))
|
||||||
return 0;
|
return 0;
|
||||||
nfs4_begin_drain_session(clp);
|
nfs4_begin_drain_session(clp);
|
||||||
|
|
||||||
fc_tbl = &clp->cl_session->fc_slot_table;
|
fc_tbl = &clp->cl_session->fc_slot_table;
|
||||||
new = nfs4_alloc_slots(fc_tbl, fc_tbl->target_highest_slotid + 1, GFP_NOFS);
|
new_size = fc_tbl->server_highest_slotid + 1;
|
||||||
if (!new)
|
return nfs4_resize_slot_table(fc_tbl, new_size, 1);
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
spin_lock(&fc_tbl->slot_tbl_lock);
|
|
||||||
for (i = 0; i <= fc_tbl->target_highest_slotid; i++)
|
|
||||||
new[i].seq_nr = fc_tbl->slots[i].seq_nr;
|
|
||||||
old = fc_tbl->slots;
|
|
||||||
fc_tbl->slots = new;
|
|
||||||
fc_tbl->max_slots = fc_tbl->target_highest_slotid + 1;
|
|
||||||
fc_tbl->max_slotid = fc_tbl->target_highest_slotid;
|
|
||||||
clp->cl_session->fc_attrs.max_reqs = fc_tbl->max_slots;
|
|
||||||
spin_unlock(&fc_tbl->slot_tbl_lock);
|
|
||||||
|
|
||||||
kfree(old);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nfs4_bind_conn_to_session(struct nfs_client *clp)
|
static int nfs4_bind_conn_to_session(struct nfs_client *clp)
|
||||||
|
@ -188,6 +188,7 @@ struct nfs4_channel_attrs {
|
|||||||
/* nfs41 sessions slot seqid */
|
/* nfs41 sessions slot seqid */
|
||||||
struct nfs4_slot {
|
struct nfs4_slot {
|
||||||
struct nfs4_slot_table *table;
|
struct nfs4_slot_table *table;
|
||||||
|
struct nfs4_slot *next;
|
||||||
unsigned long generation;
|
unsigned long generation;
|
||||||
unsigned long renewal_time;
|
unsigned long renewal_time;
|
||||||
u32 slot_nr;
|
u32 slot_nr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user