lib: rename wrappers of pthread_rwlock

Current lib/util.h wraps stuff related to pthread_rwlock with the
prefix like "sd_lock".

It is confusing because we also need to wrap pthread_mutex. This patch
changes the convention from sd_lock to sd_rw_lock.

Renamed stuff list:
- struct sd_lock -> struct sd_rw_lock
- sd_init_lock() -> sd_init_rw_lock()
- sd_destroy_lock() -> sd_destroy_rw_lock()
- sd_unlock() -> sd_rw_unlock()

Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>

Conflicts:
	lib/event.c
	sheep/cluster/local.c
	sheep/cluster/zookeeper.c
	sheep/md.c
	sheep/object_cache.c
	sheep/object_list_cache.c
	sheep/vdi.c

Conflicts were resolved by Hitoshi Mitake.
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
lib: introduce new wrappers for pthread_mutex and pthread_cond

There is a possibility that pthread_mutex_* functions can return
undocumented error code, we need to wrap them. This patch introduces
wrapper functions and a new data structure for them.

In addition, pthread_cond_* things should also be wrapped. Because we
don't use pthread_mutex_t directly any more, we cannot use
pthread_cond_wait(). This patch also adds wrappers for them.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
[ fixed compile error - Yuan ]
Signed-off-by: Liu Yuan <namei.unix@gmail.com>

Conflicts:
	sheep/cluster/zookeeper.c
	sheep/request.c

Conflicts were resolved by Hitoshi Mitake.
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
lib: add a wrapper for pthread_mutex_trylock()

Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheep: don't update vdi_iocb in vdi_* functions

We are using vdi_iocb to get a snapid from a vdi object, but it looks
like abusing of vdi_iocb.  This patch makes how to use vdi_iocb and
vdi_info clear like as follows.

 - vdi_iocb is used to pass parameters from clients.
 - vdi_info is used to get info from sheepdog.

To prevent from abusing them again, this patch makes some vdi_iocb
variables constant where possible.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheep: split create_vdi_obj() into 4 functions

create_vdi_obj() is very complex because it contains four kinds of
operations:

 - create fresh vdi
 - clone vdi
 - snapshot vdi
 - rebase vdi (rollback)

Splitting them apart makes the code much easier to read.

This patch is just a cleanup and doesn't change its logic at all.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheep: cleaning vdi deletion process of sheep daemon

Current code of vdi deletion process in sheep deamon is a real
disaster. Especially, its irregular usage of work queue is terrible
thing for maintenance. In addition, the vdi deletion process can
potentially notify a completion of deletion to a dog process before
actual completion.

This patch cleans the VDI deletion code and removes the above bug.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>

Conflicts:
	sheep/vdi.c

Conflicts were resolved by Hitoshi Mitake.
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
sheep: correct error code of vdi deletion

The previous refactoring commit (5e460b4d64441) broke QA 016. This
patch fixes the problem.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheep: remove fd leak in vdi deletion process

The commit 5e460b4d6444 introduced fd leak in the vdi deletion
process. This patch removes it.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheep: cleaning vdi deletion process, round 2

This patch cleans the vdi deletion process of sheep. Current vdi
deletion code creates one work for one deletion. It seems that there
is no reason to create so many work. This patch lets the code to
create only one work for vdi deletion request.

With this change, this patch improves simplicity of the code. For
example, the queue of struct deletion_info and related code are
removed.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>

Conflicts:
	sheep/vdi.c

Conflicts were resolved by Hitoshi Mitake.
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>