Revert "test: collect logs of sheeps after tests"

This reverts commit 26cdf0dee923ad16989ed22436692272af1a071a.

I iterate the check script many times everyday and can pass all the
test cases in most cases.  However, this patch generates a log.*
directory for each time even if there is no errors, and a large number
of log directories have been annoying me.  In addition, this collects
log files only of the last test, and does nothing against the other
ones.

Rather than improving this half baked patch, let's revert it for now
and reconsider the best way to collect logs.  IMHO collecting log
files should be done outside of the test scripts, though.

Cc: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
tests: use $* instead of $@

The behavior of $@ in double quotations depends on the environment.
Actually, './check -valgrind' doesn't work on Fedora 16.  It is safe
to use $* instead of it.

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

Valgrind prints only error messages with this patch.

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

This prevents non-root users from running tests which need root
privilege.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
tests: wait for sheep to be stopped

This patch ensures that the next sheep can start successfully by
checking that its port is not in LISTEN state.  We can use this, e.g.,
after 'collie cluster shutdown'.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
tests: wait for sheep to be started

This adds _wait_for_sheep where it is necessary to avoid a false
alarm.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
tests: refine start up of valgrind sheep

This removes a lock file before starting sheep because we wait for
sheep's start-up by checking the lock file existence.  This also
checks the sheep process to avoid infinite loop.

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

This narrows the scopes of variables and makes the scripts much easier
to read and safer.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
tests: use different directory for each test case

With this patch, log files aren't removed by the succeeding tests, and
it makes it easier for us to look into the cause of errors.

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

Currently, some test cases assume that we use /tmp/sheepdog for sheep
store.  This patch normalizes their outputs and allows us to run tests
on another directory.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
tests: wait format at most 60 seconds

036 and 038 cannot stop when 'collie cluster format' never succeeds.
This patch fixes it.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
tests/001: sleep before starting next sheep

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
tests/017: remove the current state after rolling back

This addresses the recent change in QEMU, "sheepdog: fix loadvm
operation".

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
tests/057: fix output based on the current store directory

The result of tests/057 changes based on the store directory.  We
moved the default store from from /tmp/sheepdog to /tmp/sheepdog/057,
so this patch also modifies the 057.out.

When we set the store directory manually, this patch skips 057.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
remove sd_*_req and sd_*_rsp

This patch removes all the sd_*_req and sd_*_rsp in internal_proto.h,
and adds the necessary fields to sd_req and sd_rsp.  It is not good to
include internal protocols in sheepdog_proto.h, but the change can
decrease many casting, improve type safety, and simplify codes a lot.

This also checks the size of sd_req and sd_rsp so that we don't break
them.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
don't see errno when read/2 returns zero

read/2 sets errno only when it returns -1.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
store: return SD_RES_NETWORK_ERROR when error is retryable

We have to avoid SD_RES_EIO as far as we can.  When the backend store
returns n retryable error, it should return SD_RES_NETWORK_ERROR for
gateway to try the request again.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
sheep: mute gcc warning of uninitialized devnull_fd

sheep.c:446:8: warning: ‘devnull_fd’ may be used uninitialized in this function [-Wuninitialized]
sheep.c:395:11: note: ‘devnull_fd’ was declared here

Just init devnull_fd to mute the warning.

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
move vdi_is_snapshot() to sheepdog_proto.h

This allows us to use the macro outside of sheep/vdi.c.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
sheep: make oid_to_vid support any kind of objects

get_obj_copy_number() doesn't take into account vmstate objects.  This
fixes the problem by changing oid_to_vid() so that it supports any
kind of objects.

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