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>
Handle more response types for CB_RECALL.

- Wait for delegreturn for NFS4_OK.
- Schedule a recall for BAD_STATEID instead of directly revoking it.
  A client might have a valid file handle for the file from a open
  which did not result in a delegation grant from server.
  If the client does another open which results in granting of deleg,
  but before the client receives the response to second open, the
  server issues a recall. In this case the client will reply with
  BAD_STATID because the stateid in the recall does not represent a
  valid delegation at the cleint. The server should retry the recall
  in this case.
- Schedule a recall retry for all others.

Signed-off-by: Srikrishan Malik <srimalik@in.ibm.com>
Revoke the delegation, If schedule on deleyed_exec thread fails.

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