Protect export root and junction fields with gsh_export lock

The fields so protected are:

exp_root_cache_inode
exp_mounted_on_file_id
exp_junction_inode
exp_parent_exp

Also fix a leaked fsal_obj_handle in mnt_Mnt

9p code takes a reference to exp_root_cache_inode without taking
an additional reference. That is something that must be fixed but'
is beyond the scope of this patch.

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

This routine enables taking a reference on a cache inode given a pointer
to one (that is guaranteed to not go bad based on the lock passed to
cache_inode_get_protected). The reference is taken by copying the
entry's key under the lock provided, and then doing a regular hash look
up using that key.

The passed lock MUST guarantee the inode can not proceed far enough
along being cleaned to have it's key released (nor the cache_entry_t
memory either).

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Use cache_inode_get_protected in nfs_export_get_root_entry

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Make nfs3_FSALToFhandle and nfs2_FSALToFhandle be passed the relevant export

The handle must be converted using the relevant export_id, so we need to
pass the export in instead of relying on the export in the FSAL handle.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Make nfs4_FSALToFhandle be passed the relevant export

The handle must be converted using the relevant export_id, so we need to
pass the export in instead of relying on the export in the FSAL handle.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Eliminate use of fsal_export exp_entry where easy to do so

We should use the gsh_export passed in req_op_context where possible.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Build better faked up req_op_context when real one isn't available

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Remove req_op_context from state async functions

Many of these functions have no need of a req_op_context.

If one of these functions actually needs a req_op_context it already is
building the best one it can given the information available to it.
There is no sense faking up a root context without an export.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Remove an extra cache_inode_lru_ref from state_owner_unlock_all

An extra reference was introduced by commit
fa00240948f85add87a8baf2c617394c22cddf04 though that reference is
actually in the right place, so remove the one that existed before that
is in the wrong place...

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Fix calls to nfs4_return_one_state where lock is held

These calls indicated lock was not held, when in fact it was
held, guaranteeing a deadlock.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Add req_op_context to FSAL commit op

Also since this is an API change, bump major API to 2

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Make state_del, state_del_locked, and nfs4_State_Del void

There really is no failure here. If the HashTable_del fails, it is
because the entry actually is not in the hash table, which may signify
an inconsistency but isn't worth passing up the stack.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Remove exportid from cache inode key

Exportid is not needed in the cache inode key, and cache inodes are
going to be associated with multiple exports.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Add req_op_context to cache_inode_new_entry

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Add TODO notes in places with attribute races

Here are some places attributes are accessed without attr_lock.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Don't call cache_inode_lock_trust_attrs in cache_inode_get

Anyone who uses attributes calls cache_inode_lock_trust_attrs before
using them in any case.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Call cache_inode_kill_entry on unlink failure

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Properly init rw locks in cache_entry_t

Since a recycled cache inode entry is cleaned first, which destroys the
rw locks, we must init them for recylced entries as well as newly
allocated entries.

Also, if the initialization of rw locks fails, we must destroy any
already initialized locks before releasing entry.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Fix up issues in cache_inode_hash.h

Check for NULL alloc in cih_hash_entry

cache_inode_new_entry will check the return code in the next patch.

Fix comparison in cih_fh_cmpf:

1. check hash first, if equal, then
2. check key len second, if equal then
3. compare key third

Old code didn't look at length at all, and worse, didn't actually
compare the keys...

Remove /n from log messages

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Fixup cache_inode_new_entry error paths and cleanup

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