Remove unused or duplicate fileds from state_deleg_t

Fields sd_open_state and sd_deleg_list are not used. sd_stateid is
already part of state_t in some form, so there is no reason to have it
here.

Signed-off-by: Malahal Naineni <malahal@us.ibm.com>
Minor code reorg in nfs4_op_delegreturn

Some unneeded checks were removed. Used SAME_STATEID for stateid
comparision. Removed NFS4ERR_BAD_SEQID error return along with its
missing an unlock call.

Signed-off-by: Malahal Naineni <malahal@us.ibm.com>
Added state_lock_locked and state_unlock_locked functions

Some callers already have pthread read/write "state_lock" acquired, so
they need locked versions of state_lock and state_unlock functions.

Signed-off-by: Malahal Naineni <malahal@us.ibm.com>
nfs4_op_delegreturn should hold the state_lock while using found state

After finding a delegation state, the current nfs4_op_delegreturn() drops
cache inode entry's read-write lock, state_lock, and still uses
found state. This commit uses state_unlock_locked and avoid dropping the
lock!

Signed-off-by: Malahal Naineni <malahal@us.ibm.com>
Move state lock inside delerecall_impl.

Process all deleg entries in case server has granted
more delegations(Should not happen ideally) while recall
path is not holding the state lock.

Signed-off-by: Srikrishan Malik <srimalik@in.ibm.com>
cb_chan_down doesn't need a lock for synchronization.

cb_chan_down is a bool, it should not need a lock for its loading or
storing unless there is some other dependency. As I see no such
dependency, lock holding is removed.

Signed-off-by: Malahal Naineni <malahal@us.ibm.com>
Signed-off-by: Srikrishan Malik <srimalik@in.ibm.com>
Move CB channel state in channel struct.

Signed-off-by: Srikrishan Malik <srimalik@in.ibm.com>
Some code cleanup.

-memset not required for rpc args.
-CB_RECALL needs only one arg
-code reorg in deleg_recall_one
-cleanup delegation state in deleg_revoke.
-lock type check not required for entries in deleg_list.
-s/TRUE/true s/FALSE/false.
Use state_unlock_locked in deleg_revoke.

This will prevent races between deleg_revoke and delegreturn.
Also, if delegation recall fails and we can not schedule a
retry, revoke the delegation.

Signed-off-by: Srikrishan Malik <srimalik@in.ibm.com>
Keep refs on the cache inode entry and clientid.

We do not want these to go away in case of delegreturns.
These refs will be released as soon as we find the the delegation
has been returned or revoked by the server.

Signed-off-by: Srikrishan Malik <srimalik@in.ibm.com>
Use single copy of delegation_context for a recall.

Signed-off-by: Srikrishan Malik <srimalik@in.ibm.com>
Make CB_RECALL response handling async.

The server will keep retrying unless the client returns
the delegation or revoke criteria is matched.
Remove unrequired config var.

Signed-off-by: Srikrishan Malik <srimalik@in.ibm.com>
state lock not required in subtract_deleg_from_list.

Signed-off-by: Srikrishan Malik <srimalik@in.ibm.com>
Fix delayed_get_work() erroneously returning delayed_unemployed

delayed_get_work() seems to work only when there is one node in the AVL
tree (used as heap)! In the current implementation, a node can exist
without any tasks (after the tasks of a node are completed). It returns
delayed_unemployed when all tasks in the first node are emptied even if
the heap has other tasks. This commits makes sure that there is no node
without any tasks and returns delayed_unemployed only if the tree is
empty.

Signed-off-by: Malahal Naineni <malahal@us.ibm.com>
Acked-by: Jim Lieb <jlieb@panasas.com>
(cherry picked from commit 1335d1cfe92eb71a84d9d1eec360b8c46c622ec2)
Use LIST_EMPTY, LIST_FIRST macros insread of lh_first field

Signed-off-by: Malahal Naineni <malahal@us.ibm.com>
Acked-by: Dominique Martinet <dominique.martinet@cea.fr>
(cherry picked from commit 80602e48a919ac78de45e090b415fc37106ddb7d)
Use delayed exec thread instead of fridge thread.

Signed-off-by: Srikrishan Malik <srimalik@in.ibm.com>
Use state_lock while getting delegation

Removed delegation related code block from nfs4_op_open, and added it
into a new function called do_delegation(). Modified the existing
get_delegation() code to work while holding state_lock.

Signed-off-by: Malahal Naineni <malahal@us.ibm.com>