[Ocfs2-tools-devel] [PATCH 4/6] libo2dlm: Don't drop locks at unlock.

Sunil Mushran sunil.mushran at oracle.com
Fri Mar 5 17:31:53 PST 2010


sob

Joel Becker wrote:
> Currently, libo2dlm unlinks files from dlmfs when a lock is unlocked.
> This drops the lock in the DLM, losing the contents of the LVB and
> removing any lock caching.  While o2dlm holds onto a lock for a few
> seconds, no DLM guarantees this will happen.  We don't want that!
>
> Instead, we change o2dlm_unlock() to leave the lock file around in
> dlmfs.  This is a truly cached lock.  The calling program can explicitly
> drop the lock with o2dlm_drop_lock().  Otherwise, the lock is dropped
> when the domain is shut down.
>
> lvb_torture now passes with fsdlm.
>
> Signed-off-by: Joel Becker <joel.becker at oracle.com>
> ---
>  include/o2dlm/o2dlm.h |    4 ++++
>  libo2dlm/o2dlm.c      |   44 ++++++++++++++++++++++++++++++++++----------
>  2 files changed, 38 insertions(+), 10 deletions(-)
>
> diff --git a/include/o2dlm/o2dlm.h b/include/o2dlm/o2dlm.h
> index bb9aca8..2919b23 100644
> --- a/include/o2dlm/o2dlm.h
> +++ b/include/o2dlm/o2dlm.h
> @@ -94,6 +94,10 @@ errcode_t o2dlm_lock_with_bast(struct o2dlm_ctxt *ctxt,
>  errcode_t o2dlm_unlock(struct o2dlm_ctxt *ctxt,
>  		       const char *lockid);
>  
> +/* Remove an unlocked lock from the domain */
> +errcode_t o2dlm_drop_lock(struct o2dlm_ctxt *ctxt, const char *lockid);
> +
> +
>  /* Read the LVB out of a lock.
>   * 'len' is the amount to read into 'lvb'
>   *
> diff --git a/libo2dlm/o2dlm.c b/libo2dlm/o2dlm.c
> index ee7f34c..dbc642b 100644
> --- a/libo2dlm/o2dlm.c
> +++ b/libo2dlm/o2dlm.c
> @@ -509,24 +509,23 @@ static errcode_t o2dlm_lock_classic(struct o2dlm_ctxt *ctxt,
>  	return 0;
>  }
>  
> -static errcode_t o2dlm_unlock_lock_res_classic(struct o2dlm_ctxt *ctxt,
> -					       struct o2dlm_lock_res *lockres)
> +static errcode_t o2dlm_drop_lock_classic(struct o2dlm_ctxt *ctxt,
> +					 const char *lockid)
>  {
>  	int ret, len = PATH_MAX + 1;
>  	char *path;
>  
> -	/* This does the actual unlock. */
> -	close(lockres->l_fd);
> -
> -	/* From here on down, we're trying to unlink the lockres file
> -	 * from the dlm file system. Note that EBUSY from unlink is
> -	 * not a fatal error here -- it simply means that the lock is
> -	 * in use by some other process. */
> +	/*
> +	 * We're trying to unlink the lockres file from the dlm file
> +	 * system. Note that EBUSY from unlink is not a fatal error here
> +	 * -- it simply means that the lock is in use by some other
> +	 * process.
> +	 * */
>  	path = malloc(len);
>  	if (!path)
>  		return O2DLM_ET_NO_MEMORY;
>  
> -	ret = o2dlm_full_path(path, ctxt, lockres->l_id);
> +	ret = o2dlm_full_path(path, ctxt, lockid);
>  	if (ret) {
>  		free(path);
>  		return ret;
> @@ -542,6 +541,13 @@ static errcode_t o2dlm_unlock_lock_res_classic(struct o2dlm_ctxt *ctxt,
>  	return 0;
>  }
>  
> +static errcode_t o2dlm_unlock_lock_res_classic(struct o2dlm_ctxt *ctxt,
> +					       struct o2dlm_lock_res *lockres)
> +{
> +	close(lockres->l_fd);
> +	return 0;
> +}
> +
>  static errcode_t o2dlm_read_lvb_classic(struct o2dlm_ctxt *ctxt,
>  					char *lockid,
>  					char *lvb,
> @@ -1260,6 +1266,24 @@ static errcode_t o2dlm_unlock_lock_res(struct o2dlm_ctxt *ctxt,
>  		return o2dlm_unlock_lock_res_fsdlm(ctxt, lockres);
>  }
>  
> +/*
> + * Dropping locks is only available on dlmfs.  No one should be using
> + * libdlm if they can help it.
> + */
> +errcode_t o2dlm_drop_lock(struct o2dlm_ctxt *ctxt, const char *lockid)
> +{
> +	if (!ctxt || !lockid)
> +		return O2DLM_ET_INVALID_ARGS;
> +
> +	if (o2dlm_find_lock_res(ctxt, lockid))
> +		return O2DLM_ET_BUSY_LOCK;
> +
> +	if (ctxt->ct_classic)
> +		return o2dlm_drop_lock_classic(ctxt, lockid);
> +	else
> +		return O2DLM_ET_SERVICE_UNAVAILABLE;
> +}
> +
>  errcode_t o2dlm_unlock(struct o2dlm_ctxt *ctxt,
>  		       const char *lockid)
>  {
>   




More information about the Ocfs2-tools-devel mailing list