Make state_del only deal with unlocked case, and get LRU ref

If the entry is stale, then skip.

The one place that called state_del(state, true) could just call
state_del_locked(state).

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Replace release_lockstate with cleaned up/simplified release_lock_owner

Now that release_lockstate was only being used for the release lock owner
case, simplify it.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Make sure release_openstate handles stale cache entry and export

Make sure everything is refcounted properly, also hold owner so_mutex
appropriately to protect looking at list of states belonging to owner.

Now, if we are unable to release all the owner's shares due to too many errors,
issue a LogFatal rather than having Ganesha continue with dangling pointers.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Make sure state_export_unlock_all properly handles ref counting

state_export_unlock_all must protect the cache entry, owner, and state_t
(for NFS v4 locks) that it finds from the lock entry.

When tallying errors, we don't worry about stale cache inode entry errors
since such a cache inode entry will quickly have all it's locks removed,
so the export lock list WILL drain to empty despite the stale entry error.

We no longer take a reference on the lock entry itself since we only use it
while holding the export lock (which prevents the entry from becoming invalid)
to get references on the other objects in order to make a state_unlock
call to unlock the entire file (removing this lock entry and potentially
others if the owner had multiple locks on this file).

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Remove notion of lock type from state_lock.c functions except do_lock_op

All the higher level functions are ONLY called for POSIX_LOCKs.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Replace lock_type_t with enum fsal_sle_type

This was kind of flakey with the lock_type_t being converted to an
enum fsal_sle_type with no validation that the values were the same.

Easier to just use enum fsal_sle_type in the first place.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
MORE Make sure state_nlm_notify properly handles stale cache inodes and exports

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
MORE Make sure state_export_unlock_all properly handles ref counting

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
SQUASH Take an LRU reference any time we pin a cache entry for range locks

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Make state_export_unshare_all consistent with state_export_unlock_all

The refcounting was fine, but handle errors the same way and other
cosmetic cleanup to make the code more consistent.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
MORE Take an LRU reference any time we pin a cache entry for range locks

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
MORE Make sure state_export_unlock_all properly handles ref counting

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
MOVE Take an LRU reference any time we pin a cache entry for NLM shares

A pin ref will no longer guarantee the existence of the cache inode
entry, thus we must ALSO hold an long term LRU reference.

Because cleanup no longer depends on the LRU refcount going to zero, this
is now safe.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
MORE Introduce return value to cache_inode_lru_ref to prevent new refs to stale entry

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Use cache_inode_lru_ref instead of cache_inode_get_protected

Now that cache_inode_lru_ref has provision to return CACHE_INODE_ESTALE
when the cache entry is about to die and not take an LRU reference, we
can dispense with cache_inode_get_protected.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Remove cache_inode_get_protected now that it isn't necessary

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Use proper refcounting of state_t, state_owner_t, and export in layoutrecall.

Take a reference on each state_t in the recall list.

Take a reference to the state_owner_t to assure that is good also
before using it.

Use get_state_export_ref to properly reference state_export and handle
an export going stale.

Also, since the recall list is for a single cache inode entry, we don't
actually need to look at state_entry.

Also make some cosmetic changes to make the code easier to follow.

Also, fix a memory free ordering bug (free the handle FIRST, then the
cb_data that holds the layout recall that holds the pointer to the handle).

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>