Add check and refcount to prevent junctions and export roots from unlink

Any cache inode that is an active junction must be protected from unlink
as must any node that is an export root. Since an inode may be the root
of more than one export (with a different tag and/or Pseudo path), we
must refcount export root nodes rather than flagging the node as a root.

Note that this does not prevent non-Ganesha tasks from unlinking these
nodes. That is a task for another day.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Fix a difference in definition of open_fd_count

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Add routine set_current_entry to unify setting of data->current_entry

This routine sets:

cache_inode_put(data->current_entry)
data->current_entry
data->current_filetype
data->current_stateid_valid = false;
data->current_ds->ops->put(data->current_ds);
data->current_ds = NULL;

It will optionally take an extra reference on the current_entry

It may be passed NULL for current_entry in which case it effectively
clears current_entry.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Make SAVEFH and RESTOREFH work correctly with DS handles

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Maintain list of exports rooted on a particular cache inode

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 pin reference instead of LRU reference on export root and junction cache inodes

In order for cache_inode_kill_entry to work properly if an export root
or junction inode is deleted in the underlying file system, we must
pin the entries instead of taking an LRU reference.

Proper cleanup will be in the next patch.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Fix definition of cache_inode_dec_pin_ref to be a void function

Also document the 2nd closefile parameter.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Fix callers of cache_inode_dec_pin_ref to use false/true instead of FALSE/TRUE

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Convert gsh_client and gsh_export lock from mutex to rwlock

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
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>
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>