CID#23364 Resource leak

If entry is a junction and client doesn't have access to it
then variable name is not freed upon return. Since memory
has been allocated by nfs4_utf8string2dynamic, it can't
be reclaimed has one can expect.
CID#18496 Resource leak

If getextattr_value_by_id returns an error, data isn't freed.
We have to free this buffer here since it's used and retained
later in the process (I first thought of putting it in the
out section but that would cause a segfault later).
CID#18494 Resource leak

secinfo_fh_name is allocated by nfs4_utf8string2dynamic but isn't
freed if we reuse the lookup result.
CID#18487 Resource leak

The structure pointed by myself isn't freed if
fsal_export_init returns an error code (!= 0).
Let the FSAL control the expiration interval for the inode cahce.
Avoid refcnt underrun on xprt stall.

Do not release dispatch xprt ref on stall return from
nfs_rpc_cond_stall_xprt, as it protects rechability from
the stallq itself.

The stall thread appears to do the right thing, returning
its own reference, after first re-arming EPOLL.

This change (I believe) implements the fix
proposed by Shyamsundar Ranganathan <srangana@redhat.com>,
in reporting this issue.

Signed-off-by: Matt Benjamin <matt@linuxbox.com>
Cleanup killed cache entries inline.

Removes cleanup queue processing from lru_run, in favor
of inline cleanup on return of last ref.

Also, change the order of cih_remove_checked and cleanup push
operations in cache_inode_kill entry.

It also appears that the (removed) cleanup processing incorrectly
returned a cache entry reference.  This likely resulted in leaks
and use-after-free conditions.

Signed-off-by: Matt Benjamin <matt@linuxbox.com>
Fix arguments in return_one_state from nfs4_op_close

And fix a locking bug while we're at it.

Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
Signed-off-by: Adam C. Emerson <aemerson@linuxbox.com>
Mark defective last-segment check

Diagnostic prints always show it as false.

Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
Signed-off-by: Adam C. Emerson <aemerson@linuxbox.com>
Merge remote-tracking branch 'linuxbox2/next' into merge_next

Signed-off-by: Jim Lieb <jlieb@panasas.com>
Merge remote-tracking branch 'marc/dev48-expire-inode' into merge_next

Merging inode expiry based on seconds instead of nsecs for now.
We will leave the second step to a 2.1 rework of time management.

Signed-off-by: Jim Lieb <jlieb@panasas.com>
Return cache_entry refs in dirent populate callback.

The dirent populate callback routine leaked cache entry
references, which are returned indirectly from
cache_inode_new_entry.

The desired behavior is to return each reference immediately.
The LRU mechanism and policies will take care of its lifetime
in the entry cache.

For improved readability, rename the callback from "populate"
to "populate_dirent."  Simplify error handling, just return
false at the error point, since the error label did no work.
Use STYLE(9) return.

Thanks to Dominique Martinet <dominique.martinet@cea.fr> for
finding and reporting this.

Signed-off-by: Matt Benjamin <matt@linuxbox.com>
Avoid overrunning buffer strcaller if getpeername fails.

Typo.

Signed-off-by: Matt Benjamin <matt@linuxbox.com>
Initialize grp_tail proc_export (werror).

The surrounding code must assure that grp_tail actually
has a value in all cases, I've not attempted to verify
this.

Signed-off-by: Matt Benjamin <matt@linuxbox.com>
Assign RES_READDIR3_OK invariantly (werror).

GCC decided that RES_READDIR3 might be used uninitialized.
Just do so in the prologue.

Signed-off-by: Matt Benjamin <matt@linuxbox.com>
Break out cast pointing into sockaddr_in6.s6_addr (strict aliasing).

It is not clear to me that the flagged code was incorrect, or that
it presented a real aliasing problem, but gcc 4.7.2 seems to think
so, perhaps due to the nested casts.

Signed-off-by: Matt Benjamin <matt@linuxbox.com>
Break out cast pointing into sockaddr_in6.s6_addr (strict aliasing).

It is not clear to me that the flagged code was incorrect, or that
it presented a real aliasing problem, but gcc 4.7.2 seems to think
so, perhaps due to the nested casts.

Signed-off-by: Matt Benjamin <matt@linuxbox.com>
Make some cosmetic changes to readdir to make porting easier

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Restructure cache_inode_readdir callback to be made from cache_inode_getattr

For the subsequent patch to fix mounted_on_fileid, we will need to use
cache_inode_getattr from readdir, so we will utilize its callback
mechanism to make the callback to the protocol readdir handlers.

Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
Fix MOUNTED_ON_FILEID, setting from export if entry is export root

This is a complete rework of 1.5 patch
6aa4a7800602b2f89a129986b5795bc47c05c8a8

Added mounted_on_fileid parameter to cache_inode_getattr callback.

cache_inode_getattr handles selecting the correct value for
mounted_on_fileid based on the req_ctx and the inode entry.

Call cache_inode_getattr from cache_inode_readdir instead of calling
cache_inode_lock_trust_attrs directly. cache_inode_readdir now does not
have it's own callback, the callback for each entry will come from
cache_inode_getattr. To accomplish this, the readdir callers pass a
common structure to cache_inode_readdir, which will fill in the readdir
entry parameters, and then call cache_inode_getattr. The callback
function will then have both the directory entry items and the
correct attributes with a correct mounted_on_fileid having been passed.

Remove mounted_on_fileid from struct attrlist. Since mounted_on_fileid
is an NFS server attribute and is not at all an underlying filesystem
attribute, it is not appropriate for this attribute to be part of the
FSAL attrlist.

Add mounted_on_fileid to xdr_attrs_args so that it is available to
encode_mounted_on_fileid. nfs4_PseudoToFattr sets this from the
pseudo_id for PsuedoFS READDIR of a non-junction PseudoFS inode.
cache_entry_To_Fattr accomplishes thsi via Fattr_filler which is a
getattr callback function for GETATTR and PseudoFS READDIR of a
junction. nfs4_readdir_callback accomplishes this for all other
READDIR calls.

Note that a PseudoFS junction which resutls in an NFS4ERR_WRONGSEC for
the client attempting to cross, for which the client was just requesting
FATTR4_MOUNTED_ON_FILEID via READDIR of the PseudoFS directory, will
get mounted_on_fileid via nfs4_PseudoToFattr using the "trick" that
the mounted_on_fileid for the junction node is the same as it's fileid.
This is code that will be obsoleted in the future when FSAL_PSEUDO is
introduced as a first class FSAL and junctions are fully supported (in
that case, all junctions will be handled by cache_inode_readdir which
will then have to handle the NFS4ERR_WRONGSEC case - probably by
calling cache_inode_getattr anyway).

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

Conflicts:
	src/Protocols/9P/9p_readdir.c
	src/Protocols/NFS/nfs4_op_readdir.c