From: Filipe Manana <fdmanana@gmail.com>
To: David Sterba <dsterba@suse.com>
Cc: "linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH 3/3] btrfs: sysfs: protect reading label by lock
Date: Tue, 26 Apr 2016 16:52:09 +0100 [thread overview]
Message-ID: <CAL3q7H7myUQ6FbkwTcr1Qb0oqyCt2iV=My2k_rf2P606oTWoNQ@mail.gmail.com> (raw)
In-Reply-To: <f7692e58a8e6a7bd28160adfc664e9e8ccfa6fcc.1461681045.git.dsterba@suse.com>
On Tue, Apr 26, 2016 at 3:32 PM, David Sterba <dsterba@suse.com> wrote:
> If the label setting ioctl races with sysfs label handler, we could get
> mixed result in the output, part old part new. We should either get the
> old or new label. The chances to hit this race are low.
>
> Signed-off-by: David Sterba <dsterba@suse.com>
> ---
> fs/btrfs/sysfs.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
> index 3d14618ce54b..7b0da1dcb6df 100644
> --- a/fs/btrfs/sysfs.c
> +++ b/fs/btrfs/sysfs.c
> @@ -367,7 +367,12 @@ static ssize_t btrfs_label_show(struct kobject *kobj,
> {
> struct btrfs_fs_info *fs_info = to_fs_info(kobj);
> char *label = fs_info->super_copy->label;
> - return snprintf(buf, PAGE_SIZE, label[0] ? "%s\n" : "%s", label);
> +
> + spin_lock(&fs_info->super_lock);
> + snprintf(buf, PAGE_SIZE, label[0] ? "%s\n" : "%s", label);
> + spin_unlock(&fs_info->super_lock);
> +
> + return buf;
We should return a ssize_t value, not a char *. I.e. return what
snprintf returns. This should make gcc emit a warning.
> }
>
> static ssize_t btrfs_label_store(struct kobject *kobj,
> --
> 2.7.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Filipe David Manana,
"Reasonable men adapt themselves to the world.
Unreasonable men adapt the world to themselves.
That's why all progress depends on unreasonable men."
next prev parent reply other threads:[~2016-04-26 15:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-26 14:32 [PATCH 0/3] Minor updates to sysfs David Sterba
2016-04-26 14:32 ` [PATCH 1/3] btrfs: add read-only check to sysfs handler of features David Sterba
2016-04-26 14:32 ` [PATCH 2/3] btrfs: add check to sysfs handler of label David Sterba
2016-04-26 14:32 ` [PATCH 3/3] btrfs: sysfs: protect reading label by lock David Sterba
2016-04-26 15:52 ` Filipe Manana [this message]
2016-04-26 21:44 ` 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='CAL3q7H7myUQ6FbkwTcr1Qb0oqyCt2iV=My2k_rf2P606oTWoNQ@mail.gmail.com' \
--to=fdmanana@gmail.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).