mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mateusz Guzik <mguzik@redhat.com>
To: Florian Margaine <florian@margaine.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
	Jeff Layton <jlayton@poochiereds.net>,
	"J. Bruce Fields" <bfields@fieldses.org>,
	linux-fsdevel@vger.kernel.org,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] fs: reintroduce freezing nesting
Date: Tue, 19 Apr 2016 23:39:06 +0200	[thread overview]
Message-ID: <20160419213905.fgd5rdgqgq5gbelt@mguzik> (raw)
In-Reply-To: <1461098921.2921.3.camel@margaine.com>

On Tue, Apr 19, 2016 at 10:48:41PM +0200, Florian Margaine wrote:
> The behavior was removed in 18e9e5104fcd9a973ffe3eed3816c87f2a1b6cd2
> noting that this was a better idea than using a counter. However, this
> behavior is actually wanted if multiple applications want to freeze
> concurrently while remaining non-racy.
> 
> This patch reintroduces this feature by using a counter.
> 

This patch is wrong.

It uses non-atomic ops to modify the counter and no locks are
held to protect it.

I would argue the code should track that freezing has started and
additional freezers must only return when the state is
SB_FREEZE_COMPLETE.

> ---
>  fs/super.c         | 15 +++++++++++----
>  include/linux/fs.h |  1 +
>  2 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/super.c b/fs/super.c
> index 74914b1..9fa8ca1 100644
> --- a/fs/super.c
> +++ b/fs/super.c
> @@ -231,6 +231,7 @@ static struct super_block *alloc_super(struct
> file_system_type *type, int flags)
>  	 */
>  	down_write_nested(&s->s_umount, SINGLE_DEPTH_NESTING);
>  	s->s_count = 1;
> +	s->s_freezers = 0;
>  	atomic_set(&s->s_active, 1);
>  	mutex_init(&s->s_vfs_rename_mutex);
>  	lockdep_set_class(&s->s_vfs_rename_mutex, &type-
> >s_vfs_rename_key);
> @@ -1275,12 +1276,12 @@ int freeze_super(struct super_block *sb)
>  {
>  	int ret;
>  
> +	sb->s_freezers++;
> +	if (sb->s_writers.frozen != SB_UNFROZEN)
> +		return 0;
> +
>  	atomic_inc(&sb->s_active);
>  	down_write(&sb->s_umount);
> -	if (sb->s_writers.frozen != SB_UNFROZEN) {
> -		deactivate_locked_super(sb);
> -		return -EBUSY;
> -	}
>  
>  	if (!(sb->s_flags & MS_BORN)) {
>  		up_write(&sb->s_umount);
> @@ -1338,14 +1339,20 @@ EXPORT_SYMBOL(freeze_super);
>   * @sb: the super to thaw
>   *
>   * Unlocks the filesystem and marks it writeable again after
> freeze_super().
> + * Since nesting freezes is allowed, only the last freeze actually
> unlocks.
>   */
>  int thaw_super(struct super_block *sb)
>  {
>  	int error;
>  
> +	sb->s_freezers--;
> +	if (sb->s_freezers > 0)
> +		return 0;
> +
>  	down_write(&sb->s_umount);
>  	if (sb->s_writers.frozen == SB_UNFROZEN) {
>  		up_write(&sb->s_umount);
> +		sb->s_freezers++;
>  		return -EINVAL;
>  	}
>  
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index e514f76..c045e2a 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -1333,6 +1333,7 @@ struct super_block {
>  	struct quota_info	s_dquot;	/* Diskquota specific
> options */
>  
>  	struct sb_writers	s_writers;
> +	int			s_freezers;
>  
>  	char s_id[32];				/* Informational
> name */
>  	u8 s_uuid[16];				/* UUID */
> -- 
> 2.8.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
Mateusz Guzik

  reply	other threads:[~2016-04-19 21:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-19 20:48 Florian Margaine
2016-04-19 21:39 ` Mateusz Guzik [this message]
2016-04-22 21:54   ` Florian Margaine

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=20160419213905.fgd5rdgqgq5gbelt@mguzik \
    --to=mguzik@redhat.com \
    --cc=bfields@fieldses.org \
    --cc=florian@margaine.com \
    --cc=jlayton@poochiereds.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®