journal: remove journaling support for config

The journaling support for config cannot work well because it causes
deadlock in the initialization sequence of sheep.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
util: move def_fmode and def_dmode to libsheepdog.a

For avoiding duplicate declaration, this patch moves def_fmode and
def_dmode to libsheepdog.a. The new names are sd_def_fmode and
sd_def_dmode.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
util: add a new API atomic_create_and_write()

This patch adds a new API atomic_create_and_write(). As the name
implies, the API creates and writes data to a file.

atomic_create_and_write() creates a file path.tmp (path is a
parameter) internally. During the initialization process of sheep,
every user of this API should detect and clean temporal files.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
sheep: let config use atomic_create_and_write()

Because config of sheep cannot use the journaling mechanism, it should
use atomic_create_and_write() for safe update of its data.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
sheep: add helper functions to check the current thread

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep: fix comment of put_vnode_info

We can call this function in the worker threads because urcu atomics
guard vnode_info.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep/recovery: guard next_rw with RCU

We have to manipulate next_rw atomically because next_rw can be
accessed by both main and worker threads.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep: introduce helpers to handle thread-unsafe variables

We have some variables that can be accessed only in the main thread.
This patch introduces the macro 'thrad_unsafe' to guard it with
assert().

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep: define some thread unsafe variables as thread_unsafe

This declares current_vnode_info, sys->pending_block_list,
sys->pending_notify_list, and recovering_work as thread_unsafe
variables.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep: set vnode_info even against force operation

We usually call force operation even after the cluster starts up, so
this patch gives a chance for it to access vnode_info.  With this
patch, get_vnode_info() returns NULL if cluster is not started yet.

This prepares for the next patch.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep: don't call get_vnode_info in epoch_log_read_remote()

We cannot call get_vnode_info() in epoch_log_read_remote() (in the
worker thread).  We already have the current vnode info, so let's use
it.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
work: don't call get_node_info in the worker thread

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep: assert when exec_req are called in the main thread

Calling these functions in the main thread lead to dead-lock and must
be avoided.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep: allow process_work to set response data when SD_FLAG_CMD_WRITE is not set

Currently, we assume that process_main sets the response data when
SD_FLAG_CMD_WRITE is not set.  This also allows process_work to set
the data and notify it to all the nodes.

This prepares for the next patch.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep: fix dead lock problem of cluster_force_recover

We cannot call exec_req in cluster_force_recover (in the main thread).
With this patch, sheep gets epoch info in the worker thread, and
notifies it to all the node.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
sheep: init journal file after init_disk_space()

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

The correct format strings are:
 - %zd for ssize_t
 - %zu for size_t
 - %PRIu64 for uint64_t

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