collie: correct command-line options parser

"collie cluster recover disable -p7001" not work.
getopt_long() will permutes the elements of ARGV.
so,the subcmd who needs third arg shoud take argv[optind] instead of
argv[3].

Signed-off-by: ChenZhe <cz@de3eb.cn>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
collie: don't create VDI when there are not enough nodes

If we have less nodes than required copies, just error return.

Reported-by: Valerio Pachera <sirio81@gmail.com>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep: fix automatic stale object purging

If sheep process have differert disk size,after recovery. ./stale directory
still have objects.because in the cluster_recovery_completion function,
the memcmp function parameter vnode_info->nodes and recovereds will have
different nr_vnodes number after recovery completion.so i just compare
node_id to fix this problem.

Signed-off-by: wangfan <wangfan1985@gmail.com>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
tests/054: test automatic stale object purging

test whether .stale directory has a object file.
if use -md option,it can also check.

Signed-off-by: wangfan <wangfan1985@gmail.com>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
sheep: make epoch_log_read() clean

Current epoch_log_read() and the way of treating epoch files are
confusing. Because they heavily depend on the condition:
sizeof(time_t) < sizeof(struct sd_node). The condition is true
currently, but this requirement is implicit and hard to understand.

In addition, epoch_log_read() doesn't handle a rise of EINTR when it
calls read(). This behavior might cause a subtle bug.

This patch eliminates the implicit requirement and adds the handling
of EINTR. For doing it, this patch implements a new function,
epoch_log_read_with_timestamp(). If callers require a timestamp at
tails of epoch files, they should call this one instead of
epoch_log_read().

Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
gateway: print oid on error case

This would be helpful when sheep daemon is started without '-d'.

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
util: add xmkdir that check EEXIST internally

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
use xmkdir where possible

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep: comment out store->begin_recover

No users currently, so comment it out for possible use. This will remove
unnecessary if check for now.

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep: use xzalloc in start_recovery()

The caller of start_recovery() don't handle malloc failure, so panic-out is
a better choice than letting non-recoverable sheep daemon keep running.

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
checkpatch: add more strict checking for block comments

This patch try to uniform the block comments, which gives more
consistent view to code reviewer.

 A:
    /* foo
     * bar */
 B:
    /*
     * foo
     * bar */
 C:
    /*
     * one-liner
     */
 D:
    /* one-liner
     */
 E:
    /* foo
     * bar
     * baz
     */
 A, B, C, D, E is not preferred

   /*
    * This block comments style
    * is preferred
    */

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
use preferred block comments style

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
tests/043: refine it to cache more bugs

Current master couldn't pass this refined version

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
sheep: rename some stuff about local request handling

This is a prepare patch for later patch.

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
sheep: use single list for request wait queue

Multi-queues aims to provide more finer requests retry control but end up being
much more error prone. We don't need multi-queues because
 1) VM mostly just issue several IO requests in one go and won't progress until
    getting response of those previous IO requests, so most likely we don't have
    huge number of requests on the wait queues.
 2) single queue is very easy to make correct

This patch 
 a) fixes a bug found by refined 043
 b) use single list instead of multi-lists for wait queue
 c) add comment for requests retry
 d) refactor the code and rename the helpers a bit

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
sheep: don't start recovery for leave node

There is no sense for leave node (gateway only) to recover objects

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
sheep: prepare and cleanup err_to_stderr() for MD recovery

MD recovery relies on the err_to_stderr to catch EIO and do its own EIO handling
tricks.

We don't handle EIO for object cache and journal file gracefully and use
err_to_stderr() to translate errno is non-sense for now because MD recovery
don't care about other path except backend stores.

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
work queue: don't call worker func if not assigned

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
recovery: start tgt_epoch with rw->epoch instead of 'rw->epoch - 1'

MD recovery will start recovery without epoch lifted. This will cause troulbe
when sys_epoch = 1, which will result in tgt_target = 0, and wrap around later
to be a very large but valid epoch to the recovery code and cause trouble.

This is a prepare patch for MD recovery.

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
md: implement automatic recovery

I choose to take advantage of current node recovery mechanism because:
 1. It supports multiple failure events
 2. It provide nice race-free and wait queue mechanism for VM IO requests and
    recovery IO requests.
 3. already-made logic that can recover objects from other nodes. This is very
    crutial to md recovery because we distribute objects across disks without
    extra copies.
 4. Maintan one mechanism is always better than two

So disk failure will simply be seen as a node recovery without epoch lifted and
md recovery has all the merits of node recovery:
 1. multiple disk failures handling
 2. serve VM IO requests while in recovery
 3. can hot-plug and hot-unplug the disks (missing part yet)

Besides, another nice spin-off is that with unified recovery, both node and disk
recovery can suspend and supersede each other (missing part yet)

The missing parts will be implemented in later patch.

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>