tests/unit: unit test failed because interfaces were changed.

This patch only let 'make check' workable, does not add any cases.

Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
dog:fix dog command misinterpretation when characters are mixed in a -p option

This bug is reported in https://bugs.launchpad.net/sheepdog-project/+bug/1309301
I added a check code if the port number (specified in -p option) is numeric or not.

=== Bug Description ===
I found that dog command misinterprets when characters are mixed in a numeric option.

Here's the example.

$dog vdi list -p 7X000
  Name Id Size Used Shared Creation time VDI id Copies Tag
failed to connect to 127.0.0.1:7: Connection refused
failed to connect to 127.0.0.1:7: Connection refused

dog interpreted "7X000" as "7".
I think that dog should output error message " Invalid port number '7X000' ".

=== After modified ===
$dog vdi list -p 7X000
Invalid port number '7X000'

Signed-off-by: Yuichi Bando <bando.yuichi@lab.ntt.co.jp>
Reviewed-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
dog/cluster: code optimize for confirmation of cluster_force_recover

reuse confirm() is better, no need to handle it from scratch.

Signed-off-by: Ruoyu <liangry@ucweb.com>
Reviewed-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
dog/farm/snap: fix incorrect conditional statement

Both sides of != is the same.

Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheep/object_cache: fix potential crash in object_cache_remove

If object is not found, entry reference to NULL, the below statement
will cause a crash.
struct object_cache *oc = entry->oc;

Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheep/ops: fix potential type conversion error

Similar to lib/logger, epoch_log_read_with_timestamp will return -1
for any failure and it cannot be assigned to a variable in type of
size_t. Otherwise, the error branch will never be reached.

Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheepfs/http: fix variable uninitialized in curl_get_object_size

If curl_easy_init is failure, the variable content_length will be
uninitialized. This will come into unexpected problem.

Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
dog/vdi: fix memory leak in dog vdi command

Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
lib/logger: fix potential type conversion error

The return type of snprintf is int. If an output error is encountered,
a negative value is returned. Assigning a negative value to a variable
in type of size_t is danger. The result will be a huge positive number
and the error branch will never be reached.
To avoid it, change the type of variable 'len' to ssize_t. In Comparison,
convert it back to size_t.

Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
dog/farm/slice: fix memory leak in dog cluster snapshot load command

Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
dog/node: add raw output support for dog node md info

As titled. A command line crash as below is also fixed.

$ dog node md plug -A
dog exits unexpectedly (Segmentation fault).
dog() [0x405dda]
/lib/x86_64-linux-gnu/libpthread.so.0(+0xfbaf) [0x7fd6003c9baf]
dog() [0x40d8b2]
dog() [0x40706e]
dog() [0x40398c]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf4) [0x7fd600013de4]
dog() [0x403cea]
Segmentation fault

Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheep/recovery: allocate old vinfo by using sys->cinfo

Scene:

  1. start up 4 sheep daemons in one cluster

  2. write data into the cluster

  3. "dog kill node 2" and wait for recovery complete
     current epoch status ('O' for update epoch, 'X' for stale epoch):

        node:  1  2  3  4
        epoch: O  X  O  O

  4. kill all nodes

  5. start up all 4 sheep daemons again and wait for recovery complete

    5.1: start up node 1, 2, 3

        node:  1   2   3
        epoch: O   X   O  (wait for join status)

    5.2: join the node 4
        node:  1   2   3   4
        epoch: O   X   O   O (okay status)

    but now node 4's old cluster info is wrong

        wrong old cinfo: [1, 2, 3]
        right old cinfo: [1, 3, 4]

then we read out the data and will find out it is corrupted.

The reason is the code use information from cluster as old vinfo, but the
information from cluster present 4 nodes, not previous 3 nodes status.
We don't need to worry about "node 2" who's epoch is stale, it will find
out oid correctly in recovery process because it use current_vnode_info as
'cur_info' argument in start_recovery().

To solve this problem, we allocate old vinfo by using nodes information stored
in epoch (which has been loaded into sys->cinfo) instead of which read out from
new cluster (zookeeper/corosync, etc.).

Cc: Liu Yuan <namei.unix@gmail.com>
Cc: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Robin Dong <sanbai@taobao.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheep: add test case for recovery from failed cluster

Cc: Liu Yuan <namei.unix@gmail.com>
Cc: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Robin Dong <sanbai@taobao.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
tests/func/030: refine test to reflect default format parameter

Now we can restore 100% for 'cluster snapshot' so add test for it.

Reviewed-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
CHANGELOG.md: add 'cluster snapshot' enhancement description

Reviewed-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
tests/functional: use dog instead of qemu-img in 016

It seems that qemu-img command has a bug of using cluster's nr_copies
instead of vdi's original nr_copies when it creates snapshot. This
patch lets 016 not use qemu-img.

Cc: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Cc: Valerio Pachera <sirio81@gmail.com>
Cc: Alessandro Bolgia <alessandro@extensys.it>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
dog: forbid creating snapshot of hypervolume

Currently it is not supported.

Cc: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Cc: Valerio Pachera <sirio81@gmail.com>
Cc: Alessandro Bolgia <alessandro@extensys.it>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
dog: add a new subcommand "dog vdi object dump-inode" for diagnosing inode object

This patch adds a tool for diagnosing inode object.

How to use:
$ dog vdi object dump-inode <path of inode file>

Sample of output:
name: test
tag:
create_time: 5368f57a0a96d0c0
snap_ctime: 0
vm_clock_nsec: 0
copy_policy: 0
store_policy: 0
nr_copies: 3
block_size_shift: 22
snap_id: 1
vdi_id: 7c2b25
parent_vdi_id: 0
btree_counter: 0
data_vdi_id:

Cc: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Cc: Valerio Pachera <sirio81@gmail.com>
Cc: Alessandro Bolgia <alessandro@extensys.it>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
dog: use nr_copies of inode object instead of command line parameter

Current "dog vdi clone" has a possibility of creating clone volume
which has a different replica number from its original volume when it
receives -c option. This patch forbid such a situation by letting
vdi_clone() use inode->nr_copies instead of vdi_cmd_data.nr_copies
(the variable which holds a value passed with -c option).

Cc: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Cc: Valerio Pachera <sirio81@gmail.com>
Cc: Alessandro Bolgia <alessandro@extensys.it>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheep: introduce generational reference counting for object reclaim

Generational reference counting is an algorithm to reclaim data
efficiently without race conditions on distributed system.  This
extends vdi objects structure to store generational reference counts,
and increments the counts when creating snapshots.

Cc: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Cc: Valerio Pachera <sirio81@gmail.com>
Cc: Alessandro Bolgia <alessandro@extensys.it>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>