object cache: use the correct unlock flag for lockf()

Manual says we should use F_ULOCK to unlock lockf()

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

reset zk_nr_nodes to 0 when clear node_btree

Signed-off-by: Yunkai Zhang <qiushu.zyk@taobao.com>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
zookeeper: fix master transfer logic

When a sheep joins into the cluster, master will call
sd_check_join_cb() to get the join_result which will be
update to ev.buf, and all sheep will receive this update.

If join_result equals to CJ_RES_MASTER_TRANSFER, master will
kill itself by exit(). Zookeeper needs at most SESSION_TIMEOUT
to detect master's leaving action, it's better to call zk_leave()
explicitly before master exit. On the other hand, other sheeps
will continue to process the updated JOIN EVENT.

But now, Sheepdog assumes that only one sheep(the joining sheep)
is alive in MASTER_TRANSFER scenario, this can simplify processing
logic(maybe we will overthrow this assumption in the future for other
corner-case).

Based on this assumption, the joining sheep just need to reset
its member_list(saved in node_btree in zookeeper driver), make
it only contains itself.

Signed-off-by: Yunkai Zhang <qiushu.zyk@taobao.com>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
sheep: lock against concurrent access to the store directory

This patch uses lockf on a specially create lock file in the base directory
to detect early on if another sheep is using this directory and abort with
a useful error message.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
local: do not zero the event queue

Reading, including through mmap from sparse files always returns zeroes,
so there is no need to memset the shm queue.  Zeroing it causes backing
pages to be allocated to it in tmpfs, and thus increases the memory
usage for a not fully used queue.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
consolidate the MAX_EVENT_BUF_SIZE definitions

The accord, local and zookeeper drivers all need an upper bound of the
message size the sheepdog might send for their communication queues.

Centralize the definition into a single place, and make sure we never
send larger messages from the core sheepdog code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
farm: use access(2) to check file existence

This simplifies the code a bit.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
cluster/accord: fix compile errors

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
sheep: set sys->epoch correctly before becoming master

This fixes a bug introduced by commit 43a2f684e, and necessary to pass
the following testcase:

  #!/bin/bash
  set -ex

  for i in 0 1 2; do ./sheep/sheep /store/$i -z $i -p 700$i; sleep 1; done
  ./collie/collie cluster format
  for i in 0 1 2; do pkill -f "sheep /store/$i"; sleep 1; done
  for i in 1 0 2; do ./sheep/sheep /store/$i -z $i -p 700$i; sleep 1; done
  for i in 0 1 2; do ./sheep/sheep /store/$i -z $i -p 700$i; sleep 1; done
  for i in 0 1 2; do ./collie/collie cluster info -p 700$i; done

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
sheep: update sd_store only when the correct driver name is specified

Users may run 'collie cluster format -b ?' to get the store driver
list.  In such cases, we shouldn't update sd_store.

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