sheepdog 0.5.5

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep: fix a sheep hang problem

We observed that eventfd_read() in exec_local_request() might get 'Bad file
destriptor' and led the sheep daemon hang in 'goto loop'. We can only safely
loop in EINTR cases, for others, let gateway retry the request.

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
collie: more strick check against 'node kill'

We should only allow numberic parameter, otherwise, error return.

Reported-and-tested-by: Valerio Pachera <sirio81@gmail.com>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
object cache: handle partial write due to unexpected crash

Partial written object will lead sheep to leave cluster due to EIO returned.

Let's code create_cache_object() to do all-or-nothing write(2) for the pulled
object.

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
collie: add comfirm for cluster format when cluster is not empty

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
collie: add 'collie vdi cache flush' to flush dirty cache

This command can flush cache of an VDI in specified node, which is
useful when QEMU terminates accidentally, left the dirty cache data
unflushed, this command helps us to flush and delete this cache into
the cluster.

Signed-off-by: levin li <xingke.lwp@taobao.com>
Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
collie: add 'collie vdi cache delete' to delete cache

When VMs are migrated or terminated accidentally, the cache of
the VMs won't be deleted at once, by this command we can delete
the cache of an specified VDI in all nodes of the cluster.

Signed-off-by: levin li <xingke.lwp@taobao.com>
Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
zookeeper: rework zoo helpers

- panic() inside to reduce redundant checks outside
- introduce zoo_init_node() for init

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
zookeeper: fix clientid when sesstion changes

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
zookeeper: refactor event handling

- use function pointers to replace lengthy switch case

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
zookeeper: use PRId32_t to print queue_pos

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
zookeeper: cleanup paramter passing

- we don't have to pass zhandle each time to every function
- reduce the paramters as much as possible

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
zookeeper: refactor zk_queue_push_back()

- directly write 'queue_pos--' when we want it instead of calling
zk_queue_push_back(NULL)

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
zookeeper: use rbtree instead of glib's binary tree

rbtree works better than balanced binary tree most of the time and it is easy to
maintain because it is used throughout the sheepdog.

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
zookeeper: refactor zk_member_init()

- remove static finished

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
zookeeper: further reduce the parameters of zoo_xxx helpers

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
zookeeper: remove field 'join' of zk_node

It is not referenced semantically, so remove it.

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
zookeeper: remove clientid from zk_node

It is not used at all in the code so better remove it.

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
zookeeper: rework block/unblock and leave event handling

This patch kicks start zookeeper driver to work with the current master.

- Put all the events into the zk_queue and result in a totally ordered event
sequence.
- Block/unblock events are linked into a dedicated list to implement blocking
semantics as corosyn
- better master choosing method to allow concurrent start of multile nodes.

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
zookeeper: add an option to control heartbeat timeout

the new interface will be:
 sheep -c zookeeper:ip:port,ip:port,ip:port,timeout=XXX
or
 sheep -c zookeeper:ip:port,ip:port,ip:port # use default timeout

- change the default value as 10s

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