From: Anand Jain <anand.jain@oracle.com>
To: David Sterba <dsterba@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 3/6] btrfs: introduce try-lock semantics for exclusive op start
Date: Thu, 27 May 2021 15:43:46 +0800 [thread overview]
Message-ID: <dc12e388-70b9-1349-1e20-85a7fc60d350@oracle.com> (raw)
In-Reply-To: <9a99c2204e431bc7a40bd1fb7c26ebb5fa741910.1621526221.git.dsterba@suse.com>
On 21/05/2021 20:06, David Sterba wrote:
> Add try-lock for exclusive operation start to allow callers to do more
> checks. The same operation must already be running. The try-lock and
> unlock must pair and are a substitute for btrfs_exclop_start, thus it
> must also pair with btrfs_exclop_finish to release the exclop context.
>
> Signed-off-by: David Sterba <dsterba@suse.com>
> ---
> fs/btrfs/ctree.h | 3 +++
> fs/btrfs/ioctl.c | 26 ++++++++++++++++++++++++++
> 2 files changed, 29 insertions(+)
>
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> index 3dfc32a3ebab..0dffc06b5ad4 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -3231,6 +3231,9 @@ void btrfs_update_ioctl_balance_args(struct btrfs_fs_info *fs_info,
> struct btrfs_ioctl_balance_args *bargs);
> bool btrfs_exclop_start(struct btrfs_fs_info *fs_info,
> enum btrfs_exclusive_operation type);
> +bool btrfs_exclop_start_try_lock(struct btrfs_fs_info *fs_info,
> + enum btrfs_exclusive_operation type);
> +void btrfs_exclop_start_unlock(struct btrfs_fs_info *fs_info);
> void btrfs_exclop_finish(struct btrfs_fs_info *fs_info);
>
> /* file.c */
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index c4e710ea08ba..cacd6ee17d8e 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -371,6 +371,32 @@ bool btrfs_exclop_start(struct btrfs_fs_info *fs_info,
> return ret;
> }
>
> +/*
> + * Conditionally allow to enter the exclusive operation in case it's compatible
> + * with the running one. This must be paired with btrfs_exclop_start_unlock and
> + * btrfs_exclop_finish.
> + *
> + * Compatibility:
> + * - the same type is already running
> + * - not BTRFS_EXCLOP_NONE - this is intentionally incompatible and the caller
> + * must check the condition first that would allow none -> @type
> + */
> +bool btrfs_exclop_start_try_lock(struct btrfs_fs_info *fs_info,
> + enum btrfs_exclusive_operation type)
> +{
> + spin_lock(&fs_info->super_lock);
> + if (fs_info->exclusive_operation == type)
> + return true;
> +
> + spin_unlock(&fs_info->super_lock);
> + return false;
> +}
> +
Sorry for the late comment.
Nit:
This function implements a conditional lock. But the function name
misleads to some operation similar to spin_trylock() or
mutex_trylock(). How about btrfs_exclop_start_cond_lock() instead?
Otherwise, looks good.
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Thanks.
> +void btrfs_exclop_start_unlock(struct btrfs_fs_info *fs_info)
> +{
> + spin_unlock(&fs_info->super_lock);
> +}
> +
> void btrfs_exclop_finish(struct btrfs_fs_info *fs_info)
> {
> spin_lock(&fs_info->super_lock);
>
next prev parent reply other threads:[~2021-05-27 7:44 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-21 12:06 [PATCH 0/6] Support resize and device delete cancel ops David Sterba
2021-05-21 12:06 ` [PATCH 1/6] btrfs: protect exclusive_operation by super_lock David Sterba
2021-05-21 13:37 ` Josef Bacik
2021-05-21 12:06 ` [PATCH 2/6] btrfs: add cancelable chunk relocation support David Sterba
2021-05-21 13:21 ` Josef Bacik
2021-05-26 22:56 ` David Sterba
2021-06-16 13:54 ` Filipe Manana
2021-06-16 13:55 ` Filipe Manana
2021-06-16 15:53 ` David Sterba
2021-06-16 15:58 ` [PATCH v2] btrfs: add cancellable " David Sterba
2021-06-17 9:18 ` Filipe Manana
2021-05-21 12:06 ` [PATCH 3/6] btrfs: introduce try-lock semantics for exclusive op start David Sterba
2021-05-21 13:38 ` Josef Bacik
2021-05-27 7:43 ` Anand Jain [this message]
2021-05-28 12:30 ` David Sterba
2021-05-29 13:48 ` Anand Jain
2021-05-31 18:23 ` David Sterba
2021-05-21 12:06 ` [PATCH 4/6] btrfs: add wrapper for conditional start of exclusive operation David Sterba
2021-05-21 13:29 ` Josef Bacik
2021-05-21 16:45 ` David Sterba
2021-05-26 22:24 ` David Sterba
2021-05-21 12:06 ` [PATCH 5/6] btrfs: add cancelation to resize David Sterba
2021-05-21 13:38 ` Josef Bacik
2021-05-21 12:06 ` [PATCH 6/6] btrfs: add device delete cancel David Sterba
2021-05-21 13:38 ` Josef Bacik
2021-05-21 12:06 ` [PATCH 1/2] btrfs-progs: device remove: add support for cancel David Sterba
2021-05-21 12:06 ` [PATCH 2/2] btrfs-progs: fi resize: " David Sterba
2021-12-14 14:49 ` [PATCH 0/6] Support resize and device delete cancel ops Anand Jain
2021-12-15 15:13 ` David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dc12e388-70b9-1349-1e20-85a7fc60d350@oracle.com \
--to=anand.jain@oracle.com \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).