From patchwork Mon Nov 26 08:43:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Xie X-Patchwork-Id: 1800791 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 3E0CC3FC23 for ; Mon, 26 Nov 2012 08:43:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753744Ab2KZInX (ORCPT ); Mon, 26 Nov 2012 03:43:23 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:15734 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1753533Ab2KZInW (ORCPT ); Mon, 26 Nov 2012 03:43:22 -0500 X-IronPort-AV: E=Sophos;i="4.83,319,1352044800"; d="scan'208";a="6276188" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 26 Nov 2012 16:41:37 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id qAQ8hLQ5006688 for ; Mon, 26 Nov 2012 16:43:21 +0800 Received: from [10.167.225.199] ([10.167.225.199]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2012112616425766-61069 ; Mon, 26 Nov 2012 16:42:57 +0800 Message-ID: <50B32BC1.7040201@cn.fujitsu.com> Date: Mon, 26 Nov 2012 16:43:45 +0800 From: Miao Xie Reply-To: miaox@cn.fujitsu.com User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Linux Btrfs Subject: [PATCH 5/9] Btrfs: get write access when doing resize fs References: <50B32ABF.7040803@cn.fujitsu.com> In-Reply-To: <50B32ABF.7040803@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/11/26 16:42:57, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/11/26 16:42:57, Serialize complete at 2012/11/26 16:42:57 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Steps to reproduce: # mkfs.btrfs # mount -o ro # mount -o ro # mount -o remount,rw # umount # btrfs fi resize 10g We re-sized a R/O filesystem. The reason is that we just check the R/O flag of the super block object. It is not enough, because the kernel may set the R/O flag only for the mount point. We need invoke mnt_want_write_file() to do a full check. Signed-off-by: Miao Xie --- fs/btrfs/ioctl.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 7d0214b..c4bcba5 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1293,12 +1293,13 @@ out_ra: return ret; } -static noinline int btrfs_ioctl_resize(struct btrfs_root *root, +static noinline int btrfs_ioctl_resize(struct file *file, void __user *arg) { u64 new_size; u64 old_size; u64 devid = 1; + struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root; struct btrfs_ioctl_vol_args *vol_args; struct btrfs_trans_handle *trans; struct btrfs_device *device = NULL; @@ -1307,12 +1308,13 @@ static noinline int btrfs_ioctl_resize(struct btrfs_root *root, int ret = 0; int mod = 0; - if (root->fs_info->sb->s_flags & MS_RDONLY) - return -EROFS; - if (!capable(CAP_SYS_ADMIN)) return -EPERM; + ret = mnt_want_write_file(file); + if (ret) + return ret; + mutex_lock(&root->fs_info->volume_mutex); if (root->fs_info->balance_ctl) { printk(KERN_INFO "btrfs: balance in progress\n"); @@ -1415,6 +1417,7 @@ out_free: kfree(vol_args); out: mutex_unlock(&root->fs_info->volume_mutex); + mnt_drop_write_file(file); return ret; } @@ -3759,7 +3762,7 @@ long btrfs_ioctl(struct file *file, unsigned int case BTRFS_IOC_DEFRAG_RANGE: return btrfs_ioctl_defrag(file, argp); case BTRFS_IOC_RESIZE: - return btrfs_ioctl_resize(root, argp); + return btrfs_ioctl_resize(file, argp); case BTRFS_IOC_ADD_DEV: return btrfs_ioctl_add_dev(root, argp); case BTRFS_IOC_RM_DEV: