cluster/local: don't process leave event of gateway node

We must not call sd_leave_handler() when the gateway node leaves cluster.  It is
because we already processed the event when the node became gateway.

The local driver can pass tests/048 with this patch.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
sheep: check whether there is a pending recovery correctly

Comparing current_rinfo->epoch and sys->epoch is not enough because sheep may
start recovery without incrementing sys->epoch (e.g. unplugging a md disk).
Checking next_rinfo is correct and more straightforward.

This fixes an error of tests/056.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
md: correct partial plug failure handling

If we plug multiple disks and some of them fail to purge directory, just call
md_del_disk and keep processing because successful plugging already add some
disks in the array.

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
sheep: clean vdi_state when formatting cluster

Signed-off-by: Kai Zhang <kyle@zelin.io>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
zk: actively remove itself after leave_cluster() is called

actively remove itself from zookeeper than waitting for timeout.

Signed-off-by: ChenZhe <cz@de3eb.cn>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
[don't merge] tests: valgrind option for lower memory machine

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
[tmp] tests: don't use /dev/urandom for better performance

/dev/urandom is too slow.  We don't need good random values to fill vdis.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
[tmp] work: reduce global variables

- make worker_info_list a static variable

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
work: rename init_wqueue_eventfd and init_work_queue

init_wqueue_eventfd() is not good as a global name because all the work queue
users don't have to know that the work queue uses eventfd.  This renames
init_wqueue_eventfd() to init_work_queue(), and init_work_queue() to
create_work_queue().

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
work: remove sheep_priv.h from include files

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
work: remove trace.h from include files

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
move work queue codes from sheep to lib

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
[tmp] work: increase the number of threads in done

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
[tmp] collie: add primitive

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep: add operation to get object sha1 digest

Currently, we compare entire object contents to check whether there is no
difference among them.  However, this wastes a lot of network bandwidth and some
operations like vdi check or object recovery take too long time to complete.

This adds an operation SD_OP_GET_HASH to get the sha1 digest of the object, and
enables us to do faster vdi check and recovery.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
collie: use hash for collie check

This patch checks the hash values of the target objects and skips check and
repair when there is no difference between them.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
[tmp] tests: fix vdi check order

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep: recover from local when target node has same content

This checks the hash value of the target object before reading the entire data,
and recovers from local if there is a same object in the stale directory.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>