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>
Removed unused function free_deleg_locked

Signed-off-by: Malahal Naineni <malahal@us.ibm.com>
Acked-by: Venkateswararao Jujjuri (JV) <jvrao@linux.vnet.ibm.com>
Update deleg stats before the lock entry is freed.

Signed-off-by: Srikrishan Malik <srimalik@in.ibm.com>
Update delegation stats in deleg_revoke.

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

Delegation locks are full length locks unlike range locks, so there
is no need to do any subtraction!  Hence renamed the function to
remove_deleg_lock. This calls remove_from_locklist to properly free
the lock.

Signed-off-by: Malahal Naineni <malahal@us.ibm.com>
Added base support for CLAIM_DELEGATE_PREV

Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Added nfs4_populate_revoked_delegs() to read revoked handles from
stable storage into memory.

Signed-off-by: Venkateswararao Jujjuri (JV) <jvrao@linux.vnet.ibm.com>
Corrected code under deleg_reclaim_current

Signed-off-by: Venkateswararao Jujjuri (JV) <jvrao@linux.vnet.ibm.com>
Added support for recording revoked file handles.

Signed-off-by: Venkateswararao Jujjuri (JV) <jvrao@linux.vnet.ibm.com>
Added support to check if the deleg_reclaim_prev can be granted.

Signed-off-by: Venkateswararao Jujjuri (JV) <jvrao@linux.vnet.ibm.com>
Simple name/debug changes

Signed-off-by: Venkateswararao Jujjuri (JV) <jvrao@linux.vnet.ibm.com>