tests: Fix failing tests which rename files in trash

Tests which rename files in trash and immediately try to undelete them
might fail because of a race. The following code:

  echo new_name > /mnt/lzfs-meta/trash/*some_file
  mv /mnt/lzfs-meta/trash/*new_name /mnt/lzfs-meta/trash/undel

has a race: the file in trash is renamed in the fuse_release handler,
which is called just after close() on a file written by echo returns.
This makes it run in parallel with the forthcoming mv command and
(especially when using valgrind) causes mv to fail if fuse_rename is
executed before fuse_release finishes.

This commit fixes races in tests which rename files in trash by adding
assert_eventually (which waits for rename to finish) after each rename
operation on files from trash.

A new test is attached to this commit. This tests uses the rename
feature in LizardFS trash a lot to verify if it works properly. The race
can be observed if the 'assert_eventually "test -e (...)"' is commented
out and the test is executed with USE_VALGRIND=YES.

Change-Id: I2aed03310cc0e31fd67a45f711b52a5924983935
master: Fix bugs found by static code analyzers

This commit fixes the following bugs found by static code analyzers
(cppcheck and clang's analyzer):

* Double frees which might have occured in case of truncated metadata
  files or I/O errors when reading them.
* Missing 'throw' in Lockfile::lock which caused wrong exception to be
  thrown when creating a lockfile for the metadata failed (not the one
  generated by fopen, by one generated by flock on -1 descriptor).
* Wrong assignment in chunks.cc, instead of:
    if (usage > maxUsage) { maxUsage = usage; }
  there was:
    if (usage > maxUsage) { usage = maxUsage; }
  This caused wrong chunks to be chosen for deletion (not the one on
  a machine with the highest disk usage, but the oldest one). This was
  a bug which caused chunk rebalancing process to be less effective.
* In masterconn_read there was no check for eptr->mode==KILL which makes
  the static analyzer complain and might cause other issues.

It also fixes some issues pointed by clang which are not bugs, mainly
assignments to variables which are never read after such an assignment
(in some cases due to the presence of #ifdefs in the code).

Change-Id: If1072c095cec203f4d56f593ff555b957baf77e7