[sheepdog] [PATCH v1 3/4] sheep/cluster: let local implementation of lock() support embedding

Liu Yuan namei.unix at gmail.com
Fri Feb 21 08:39:57 CET 2014


On Fri, Feb 21, 2014 at 02:47:32PM +0800, Robin Dong wrote:
> From: Robin Dong <sanbai at taobao.com>
> 
> In kv_create_object(), we need to lock bucket and then lock allocator of it, so
> all the implementations for ->lock() in cluster must support embeded lock.

this should be called nested lock.

> 
> Signed-off-by: Robin Dong <sanbai at taobao.com>
> ---
>  sheep/cluster/local.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/sheep/cluster/local.c b/sheep/cluster/local.c
> index 7f9a6eb..264afdb 100644
> --- a/sheep/cluster/local.c
> +++ b/sheep/cluster/local.c
> @@ -627,12 +627,15 @@ static void local_lock(uint64_t lock_id)
>  
>  	if (xflock(entry->fd, LOCK_EX) < 0)
>  		panic("lock failed %"PRIx64", %m", lock_id);
> +
> +	sd_rw_unlock(&lock_tree_lock);

lock_tree_lock is to make sure locking between differnt threads in the same
process, so you can't call sd_rw_unlock(&lock_tree_lock); here.

I chose lock_tree_lock because flock() doesn't support threads in the same
process.

Thanks
Yuan



More information about the sheepdog mailing list