linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <quwenruo@cn.fujitsu.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v5 8/9] btrfs: Use sb_want_write() to protect label change.
Date: Fri, 30 Jan 2015 19:34:55 +0100	[thread overview]
Message-ID: <20150130183455.GR3641@twin.jikos.cz> (raw)
In-Reply-To: <1422609654-19519-9-git-send-email-quwenruo@cn.fujitsu.com>

On Fri, Jan 30, 2015 at 05:20:53PM +0800, Qu Wenruo wrote:
> Use the new vfs API sb_want_write() to do the write protection of the
> label change transaction.
> 
> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
> ---
> v4:
>   Newly introduced.
> v5:
>   Change to use sb_want_write().
> ---
>  fs/btrfs/sysfs.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
> index b2e7bb4..3218245 100644
> --- a/fs/btrfs/sysfs.c
> +++ b/fs/btrfs/sysfs.c
> @@ -25,6 +25,7 @@
>  #include <linux/bug.h>
>  #include <linux/genhd.h>
>  #include <linux/debugfs.h>
> +#include <linux/mount.h>
>  
>  #include "ctree.h"
>  #include "disk-io.h"
> @@ -377,8 +378,6 @@ static ssize_t btrfs_label_store(struct kobject *kobj,
>  	int ret;
>  	size_t p_len;
>  
> -	if (fs_info->sb->s_flags & MS_RDONLY)
> -		return -EROFS;
>  
>  	/*
>  	 * p_len is the len until the first occurrence of either
> @@ -389,9 +388,15 @@ static ssize_t btrfs_label_store(struct kobject *kobj,
>  	if (p_len >= BTRFS_LABEL_SIZE)
>  		return -EINVAL;
>  
> +	ret = sb_want_write(fs_info->sb);
> +	if (ret)
> +		return ret;

Please move the check to the beginning of the function, where the
original MS_RDONLY check was.

> +
>  	trans = btrfs_start_transaction(root, 0);
> -	if (IS_ERR(trans))
> -		return PTR_ERR(trans);
> +	if (IS_ERR(trans)) {
> +		ret = PTR_ERR(trans);
> +		goto out;
> +	}
>  
>  	spin_lock(&root->fs_info->super_lock);
>  	memset(fs_info->super_copy->label, 0, BTRFS_LABEL_SIZE);
> @@ -399,9 +404,10 @@ static ssize_t btrfs_label_store(struct kobject *kobj,
>  	spin_unlock(&root->fs_info->super_lock);
>  	ret = btrfs_commit_transaction(trans, root);
>  
> +out:
> +	sb_drop_write(fs_info->sb);
>  	if (!ret)
>  		return len;
> -
>  	return ret;
>  }
>  BTRFS_ATTR_RW(label, btrfs_label_show, btrfs_label_store);

  reply	other threads:[~2015-01-30 18:34 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-30  9:20 [PATCH v5 0/9] btrfs: Fix freeze/sysfs deadlock in better method Qu Wenruo
2015-01-30  9:20 ` [PATCH v5 1/9] Revert "btrfs: add support for processing pending changes" related commits Qu Wenruo
2015-01-30 19:14   ` David Sterba
2015-01-30  9:20 ` [PATCH v5 2/9] btrfs: Make btrfs_parse_options() parse mount option in a atomic way Qu Wenruo
2015-01-30 18:28   ` David Sterba
2015-01-30  9:20 ` [PATCH v5 3/9] btrfs: Introduce per-transaction mount_opt to keep mount option consistent during transaction Qu Wenruo
2015-01-30 19:12   ` David Sterba
2015-01-30  9:20 ` [PATCH v5 4/9] btrfs: Use btrfs_test_trans_opt() to handle SPACE_CACHE if it's under transaction protect Qu Wenruo
2015-01-30 19:12   ` David Sterba
2015-01-30  9:20 ` [PATCH v5 5/9] btrfs: Use btrfs_test_trans_opt() to handle INODE_CACHE " Qu Wenruo
2015-01-30 19:12   ` David Sterba
2015-01-30  9:20 ` [PATCH v5 6/9] vfs: Add sb_want_write() function to get vfsmount from a given sb Qu Wenruo
2015-01-30 19:11   ` David Sterba
2015-01-30  9:20 ` [PATCH v5 7/9] btrfs: Move btrfs_sysfs_remove_one(fs_info) before transcation thread cleanup Qu Wenruo
2015-01-30 18:56   ` David Sterba
2015-01-30  9:20 ` [PATCH v5 8/9] btrfs: Use sb_want_write() to protect label change Qu Wenruo
2015-01-30 18:34   ` David Sterba [this message]
2015-01-30  9:20 ` [PATCH v5 9/9] btrfs: Use sb_want_write() to protect sysfs feature change Qu Wenruo
2015-01-30 18:35   ` David Sterba
2015-01-30 19:17 ` [PATCH v5 0/9] btrfs: Fix freeze/sysfs deadlock in better method David Sterba
2015-01-31  2:30   ` Miao Xie
2015-02-02  1:36     ` Qu Wenruo

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=20150130183455.GR3641@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=quwenruo@cn.fujitsu.com \
    /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).