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>
Check open conflicts before delegation recalls

Modified state_add_impl() to call state_conflict() before calling
check_deleg_conflict(). Also fixed freeing the state and releasing
pin_ref on the cache inode entry if delegations are recalled.

Also removed some conflict detection dead code!

Signed-off-by: Malahal Naineni <malahal@us.ibm.com>
Use deleg_list for only REGULAR_FILE objects

nfs4_op_delegreturn() should check to make sure that it is a regular
file before using deleg_list as it is not initialized for any other file
type.  Also changed a check for non DIRECTORY to REGULAR_FILE in
do_delegation().

Signed-off-by: Malahal Naineni <malahal@us.ibm.com>
Self deadlock in delegrecall_impl

The state_lock is pushed inside delegrecall_impl, so avoid acquiring
state_lock in queue_delegrecall while calling delegrecall_impl.

Signed-off-by: Malahal Naineni <malahal@us.ibm.com>
Acked-by: Srikrishan Malik <srimalik@in.ibm.com>
Use COPY_STATEID to copy stateid.

Removed an unused call to state_share_check_conflict(), used
COPY_STATEID to copy delegation stateid.

Signed-off-by: Malahal Naineni <malahal@us.ibm.com>
Reviewed-by: Srikrishan Malik <srimalik@in.ibm.com>
Clean up in nfs4_op_delegreturn

Signed-off-by: Malahal Naineni <malahal@us.ibm.com>
Reviewed-by: Srikrishan Malik <srimalik@in.ibm.com>
Don't overwrite the delegation recall time

We should keep the first time when we attempt to recall the delegation
for calculating when to revoke. Don't overwrite that value with every
attempt to recall the delegation.

Signed-off-by: Malahal Naineni <malahal@us.ibm.com>
Reviewed-by: Srikrishan Malik <srimalik@in.ibm.com>
Set lock_reclaim in get_delegation

Signed-off-by: Malahal Naineni <malahal@us.ibm.com>
Reviewed-by: Srikrishan Malik <srimalik@in.ibm.com>