[Ocfs2-devel] [PATCH 22/39] ocfs2: Add refcount tree lock mechanism.

Joel Becker Joel.Becker at oracle.com
Thu May 7 18:17:35 PDT 2009


On Thu, Apr 30, 2009 at 06:58:34AM +0800, Tao Ma wrote:
> +/*
> + * Lock the refcount tree pointed by ref_blkno and return the tree.
> + * In most case, we lock the tree and read the refcount block.
> + * So read it here if the caller really need it.
> + */
> +int ocfs2_lock_refcount_tree(struct ocfs2_super *osb, u64 ref_blkno, int rw,
> +			     struct ocfs2_refcount_tree **ret_tree,
> +			     struct buffer_head **ref_bh)
> +{
> +	int ret;
> +	struct ocfs2_refcount_tree *tree = NULL;
> +
> +	ret = ocfs2_get_refcount_tree(osb, ref_blkno, &tree);
> +	if (ret) {
> +		mlog_errno(ret);
> +		goto out;
> +	}
> +
> +	ret = ocfs2_refcount_lock(&tree->rf_lockres, rw);
> +	if (ret) {
> +		mlog_errno(ret);
> +		goto out;
> +	}
> +
> +	if (rw)
> +		down_write(&tree->rf_sem);
> +	else
> +		down_read(&tree->rf_sem);
> +
> +	if (ref_bh) {
> +		ret = ocfs2_read_refcount_block(&tree->rf_ci,
> +						ref_blkno, ref_bh);
> +		if (ret) {
> +			mlog_errno(ret);
> +			ocfs2_unlock_refcount_tree(osb, tree, rw);
> +			goto out;
> +		}
> +	}
> +
> +	*ret_tree = tree;
> +out:
> +	return ret;
> +}
> +
> +void ocfs2_unlock_refcount_tree(struct ocfs2_super *osb,
> +				struct ocfs2_refcount_tree *tree, int rw)
> +{
> +	ocfs2_refcount_unlock(&tree->rf_lockres, rw);
> +
> +	if (rw)
> +		up_write(&tree->rf_sem);
> +	else
> +		up_read(&tree->rf_sem);
> +}

	You lock "cluster, mutex", but you also unlock "cluster, mutex".
I would think you'd want to unlock "mutex, cluster".


-- 

"Here's a nickle -- get yourself a better X server."
	- Keith Packard

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127



More information about the Ocfs2-devel mailing list