tests/functional: add test to check wrong node joining with newer epoch

This test can be passed after I refined the sheepdog start-up
procedure, but it's still meaningful to have this test for detecting
degradation.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheep: clean up log_current_epoch call

This moves epoch incrementation into log_current_epoch() to simplify
codes, and adds a check of the return value of the function.  As a
result, log_current_epoch() is renamed to inc_and_log_epoch().

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheep: remove inc_epoch from join_message

This moves the check of epoch incrementation from
cluster_wait_for_join_check() to update_cluster_info() and removes the
inc_epoch field from the join_message structure.

This changes the size of the join_message structure,
SD_SHEEP_PROTO_VER is also updated.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheep: handle node failure during atomic_create_and_write

If sheep fails after creating a temporary file and before renaming it
in atomic_create_and_write(), sheep cannot create the file any more
since no one doesn't clean up the temporary file.  This patch adds a
force option to atomic_create_and_write() and cleans up the temporary
file when it is enabled.

It is okay for write_config() and update_epoch_log_() to set the force
option because these function cannot be called from multiple threads
at the same time.  However, md_move_object() can be called from
multiple threads, so this patch keeps the function's behavior as it
was.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheep: simplify cluster_sanity_check

It is enough to check the cluster creation time to detect wrong node
joining.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
tests/functional: test join to the clean cluster

This test can be passed with the next patch.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheep: merge wait_for_format and wait_for_join

We have a simple rule for cluster start-up now, so don't have to
distinguish WAIT_FOR_JOIN and WAIT_FOR_FORMAT strictly.

With this patch, a sheep with an old data can join to the cluster
whose status is WAIT_FOR_FORMAT.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheep: remove finish_join from system_info

It is obvious that the sheep finishes a join phase when
update_cluster_info() is called against itself.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheep: use the same logic in sd_check_join_cb()

Even if the joining node is the first one, we can use the same logic.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>