sheep: fix object cache size setting

Use megabytes as unit and allow users to spefify size ranging from 1 ~ 4294967295
megabytes for object cache.

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep: refine the object cache size value range

sys->object_cache_size is uint32, we shouldn't use -1 to indicate invalid value.
Instead, we allow 1 to UINT32_MAX inclusive by using 0 to indicate invalid value

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep: fix a little bug of is_master() in corosync.c

Current is_master() in sheep/cluster/corosync.c has a possibility of
reading array with invalid index. This patch fix the little bug.

Signed-off-by: Hitoshi Mitake <h.mitake@gmail.com>
Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Add command line option for binding to a specified interface.

Currently sheep will try to bind to all interfaces.  This patch
provides a command line option allowing you to specify the ip address
of the interface where you could like sheep to bind.  If you don't
provide this option, sheep continues binding to all interfaces as
usual.

Signed-off-by: Bryan D. Payne <bdpayne@acm.org>
Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep: check sheepdog data layout version before starting up

This avoids data store corruption when there is no compatibility
between the running sheep and the existing data.  The format version
of 0.4.0 is 0, and one of 0.5.x is 1.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep: add support for upgrading sheep store

This adds a '-u' option to sheep usage.  If we start a sheep daemon
with the option, it will upgrade the underlying store layout if
necessary.

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

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep: write config data when config file is zero byte

If sheep is killed just after config file is created but before no
bytes is written, the size of the config file would be zero byte.  In
this case, we should recreate config file rather than exiting with a
version error.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep: new assert() for better error messages

This patch removes direct usage of assert() in sheep. assert() in
daemon process causes problem because assert() writes its error
message to stderr. In addition, typical daemon processes including
sheep close stderr and dup() other fd. Actually, logger process of
sheep dup() /dev/null for stderr.

From my experience, using assert() directly in daemon processes makes
debugging hard. So this patch adds assert() as a wrapper of
panic(). With this patch, assert() can find suitable output fd for
error messages with vprintf() and the error messages can appear in a
log file of sheep.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
migrate: update config file with a new format version

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
migrate: create backup before upgrading store

Upgrading cluster can break store layout if the upgrade process fails.
To avoid the worst case, this patch creates backup files before
beforehand.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep: use ftruncate instead of writing to the last sector

This also moves err_to_sderr to outside prealloc because we cannot
know the oid of the file inside prealloc.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
make sd_rsp 64 bit aligned

Without this patch, the header size will end up being changed if we
add a 64 bit field to sd_rsp->obj or sd_rsp->vdi.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
trim redundant zero bytes of network and disk I/O data

This will save a lot of network and disk I/Os especially when
recoverying sparse objects.

This updates the protocol version between sheep and other programs,
but the older one is also supported.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
use bool for boolean variables

This improves code readability.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
use offsetof in stddef.h

Current code doesn't use pre-defiend compiler macro for offsetof
because __compiler_offsetof is not defined anywhere.  This patch
includes stddef.h, which defines offsetof with __builtin_offsetof,
rather than redefining it.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
add support for sparse check

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

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

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