From patchwork Fri Feb 6 05:45:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 5788691 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CD7F1BF440 for ; Fri, 6 Feb 2015 05:48:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0E05B20165 for ; Fri, 6 Feb 2015 05:48:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2704620160 for ; Fri, 6 Feb 2015 05:48:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753638AbbBFFry (ORCPT ); Fri, 6 Feb 2015 00:47:54 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:62547 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751580AbbBFFrp (ORCPT ); Fri, 6 Feb 2015 00:47:45 -0500 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="57209720" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 06 Feb 2015 13:44:12 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t165l0BO016596 for ; Fri, 6 Feb 2015 13:47:00 +0800 Received: from localhost.localdomain (10.167.226.33) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Fri, 6 Feb 2015 13:47:44 +0800 From: Qu Wenruo To: Subject: [PATCH v7 8/9] btrfs: Use sb_want_write() to protect label change. Date: Fri, 6 Feb 2015 13:45:33 +0800 Message-ID: <1423201534-19309-9-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1423201534-19309-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1423201534-19309-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.33] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use the new vfs API sb_want_write() to do the write protection of the label change transaction. Signed-off-by: Qu Wenruo --- v4: Newly introduced. v5: Change to use sb_want_write(). v6: Move sb_want_write() at the beginning of the function. v7: None --- fs/btrfs/sysfs.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index b2e7bb4..7e548f7 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "ctree.h" #include "disk-io.h" @@ -377,8 +378,9 @@ 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; + ret = sb_want_write(fs_info->sb); + if (ret) + return ret; /* * p_len is the len until the first occurrence of either @@ -386,12 +388,17 @@ static ssize_t btrfs_label_store(struct kobject *kobj, */ p_len = strcspn(buf, "\n"); - if (p_len >= BTRFS_LABEL_SIZE) - return -EINVAL; + if (p_len >= BTRFS_LABEL_SIZE) { + ret = -EINVAL; + goto out; + } + 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 +406,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);