mds: Use map for CInode pinrefs

Implements pin refs on the inode as a map instead of
a multiset, allowing individual ref counts to act as
real references with values that can be >1.
The pin refs are only used for debugging, but allowing
them to be >1 avoids the need for a separate state field
for things like DIRTYPARENT.

Signed-off-by: Sam Lang <sam.lang@inktank.com>
mds: New backtrace handling

Add unified backtrace handling for storing a backtrace on file objects
(the first data object) and dirs.  The backtrace store operation is
queued on the LogSegment (for performing the store on log segment
expire).  We encode the backtrace on queue to avoid keeping a reference
around to the CInode, which may get dropped from the cache by the time
the log segment is expired (and the backtrace is written out).
Fetching the backtrace is implemented on the CInode.

Also allow incrementing/decrementing the DIRTYPARENT pin ref as needed,
instead of using a state semaphore to keep track of whether itsset or
not.  This allows us to remove the STATE_DIRTYPARENT field
on CInode.

Signed-off-by: Sam Lang <sam.lang@inktank.com>
mds: Backtrace for create,rename,mkdir,setlayout

Design info:
http://www.spinics.net/lists/ceph-devel/msg11872.html

Adds a backtrace to the data pool for supporting lookup-by-ino,
storing the backtrace on the first object in the data pool
or the metadata pool for a directory, as the 'parent' xattr
on the object (named by inode) in that pool.  For create, rename,
mkdir, and setlayout operations, the backtrace is
queued (with the current log segment) after the journal is
committed and the safe reply is returned to the client, but the
the backtrace operation itself isn't started until the log segment is
expired.

For journal replay, we queue the backtrace so that it gets
written out on journal expire.  Inodes get added to the EMetaBlob
in the fullbits list, so we queue backtraces while iterating through
the fullbits during replay.

Using setlayout or setxattr('ceph.file.layout.pool'),
the data pool for a file can be changed after it is created
but before anything is written to the file.  A forwarding backtrace
is written to the old pool on a setlayout, to ensure we can always find
the latest backtrace.  We store a list of old pools with the backtrace
for cleaning up all forwarding pointers of an inode.

Signed-off-by: Sam Lang <sam.lang@inktank.com>
dencoder:  Add inode_backtrace_t to types

Signed-off-by: Sam Lang <sam.lang@inktank.com>
mds: Cleanup new segment conditionals

The second conditional for adding a new segment is always
true when the first conditional is true.  Clean this up
to simply create a new segment when we've reached the end of
the current segment.

Signed-off-by: Sam Lang <sam.lang@inktank.com>
pybind/cephfs:  Add initial py wrappers for cephfs.

Signed-off-by: Sam Lang <sam.lang@inktank.com>
test/mds:  Add test to check backtraces

Signed-off-by: Sam Lang <sam.lang@inktank.com>
mds: Add kill points for backtrace testing

Signed-off-by: Sam Lang <sam.lang@inktank.com>
pybind/libcephfs:  Minor fixes

Signed-off-by: Sam Lang <sam.lang@inktank.com>
message/mds:  Fix client reconnect decode

Flip the conditional so that snap realms are
decoded, otherwise this results in an assertion
failure of the mds when a client attempts to
reconnect.

Signed-off-by: Sam Lang <sam.lang@inktank.com>
include/elist: Fix clear() to use pop_front()

elist<T>::clear() is calling remove(), which isn't a
method defined on elist<T> (it was never defined according
to git).  Because elist is templated and no references
to clear() are ever made, the compiler matches remove(T) to the
remove(const char *) system call defined in stdio.h.

Once clear is invoked on an instance of elist<T>, we get the
compile error shown below.

The fix here is to use pop_front() instead of remove().

Compile error is:
In file included from ../../src/mds/CInode.h:22:0,
                 from ../../src/mds/CInode.cc:19:
../../src/include/elist.h: In instantiation of ‘void elist<T>::clear() [with T = cinode_backtrace_info_t*]’:
../../src/mds/CInode.cc:1129:20:   required from here
../../src/include/elist.h:101:7: error: no matching function for call to ‘remove(cinode_backtrace_info_t*)’
../../src/include/elist.h:101:7: note: candidates are:
In file included from ../../src/mds/CInode.cc:17:0:
/usr/include/stdio.h:179:12: note: int remove(const char*)
/usr/include/stdio.h:179:12: note:   no known conversion for argument 1 from ‘cinode_backtrace_info_t*’ to ‘const char*’
In file included from /usr/include/c++/4.7/algorithm:63:0,
                 from /usr/include/c++/4.7/backward/hashtable.h:65,
                 from /usr/include/c++/4.7/ext/hash_map:65,
                 from ../../src/include/encoding.h:292,
                 from ../../src/common/entity_name.h:22,
                 from ../../src/common/config.h:26,
                 from ../../src/mds/CInode.h:20,
                 from ../../src/mds/CInode.cc:19:
/usr/include/c++/4.7/bits/stl_algo.h:1117:5: note: template<class _FIter, class _Tp> _FIter std::remove(_FIter, _FIter, const _Tp&)
/usr/include/c++/4.7/bits/stl_algo.h:1117:5: note:   template argument deduction/substitution failed:
In file included from ../../src/mds/CInode.h:22:0,
                 from ../../src/mds/CInode.cc:19:
../../src/include/elist.h:101:7: note:   candidate expects 3 arguments, 1 provided

Signed-off-by: Sam Lang <sam.lang@inktank.com>
client: Ensure inode/dentries are ref counted

The MetaRequest holds onto inodes and dentries
for retrying unsafe requests, but those objects
might be removed from the cache (unlink for example)
causing the inode/dentry to be freed.  Ensure that
the inode/dentry is never freed while the MetaRequest
holds onto it by putting/getting the refs using
set/get interfaces.

Signed-off-by: Sam Lang <sam.lang@inktank.com>