From patchwork Thu Nov 25 09:56:41 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Xie X-Patchwork-Id: 356462 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oAP9uGS3025571 for ; Thu, 25 Nov 2010 09:56:17 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752013Ab0KYJzu (ORCPT ); Thu, 25 Nov 2010 04:55:50 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:54785 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751902Ab0KYJzr (ORCPT ); Thu, 25 Nov 2010 04:55:47 -0500 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 69165170E9A; Thu, 25 Nov 2010 17:55:45 +0800 (CST) Received: from mailserver.fnst.cn.fujitus.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id oAP9pBtt013792; Thu, 25 Nov 2010 17:51:13 +0800 Received: from [10.167.225.64] ([10.167.225.64]) by mailserver.fnst.cn.fujitus.com (Lotus Domino Release 8.5.1FP4) with ESMTP id 2010112517560077-101242 ; Thu, 25 Nov 2010 17:56:00 +0800 Message-ID: <4CEE32D9.8060207@cn.fujitsu.com> Date: Thu, 25 Nov 2010 17:56:41 +0800 From: Miao Xie Reply-To: miaox@cn.fujitsu.com User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100413 Fedora/3.0.4-2.fc13 Thunderbird/3.0.4 MIME-Version: 1.0 To: Chris Mason , Josef Bacik CC: Linux Btrfs , Liu Bo Subject: [RFC PATCH 4/4] Btrfs: deal with filesystem state at mount, umount and remount X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2010-11-25 17:56:00, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2010-11-25 17:56:02, Serialize complete at 2010-11-25 17:56:02 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Thu, 25 Nov 2010 09:56:18 +0000 (UTC) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index fb827d0..15ff468 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -43,6 +43,8 @@ static struct extent_io_ops btree_extent_io_ops; static void end_workqueue_fn(struct btrfs_work *work); static void free_fs_root(struct btrfs_root *root); +static void btrfs_check_super_valid(struct btrfs_fs_info *fs_info, + int read_only); /* * end_io_wq structs are used to do processing in task context when an IO is @@ -1700,6 +1702,11 @@ struct btrfs_root *open_ctree(struct super_block *sb, if (!btrfs_super_root(disk_super)) goto fail_iput; + /* check filesystem state */ + fs_info->fs_state |= btrfs_super_flags(disk_super); + + btrfs_check_super_valid(fs_info, sb->s_flags & MS_RDONLY); + ret = btrfs_parse_options(tree_root, options); if (ret) { err = ret; @@ -2409,6 +2416,7 @@ int btrfs_commit_super(struct btrfs_root *root) int close_ctree(struct btrfs_root *root) { struct btrfs_fs_info *fs_info = root->fs_info; + struct btrfs_super_block *sb = &fs_info->super_for_commit; int ret; fs_info->closing = 1; @@ -2416,6 +2424,7 @@ int close_ctree(struct btrfs_root *root) btrfs_put_block_group_cache(fs_info); if (!(fs_info->sb->s_flags & MS_RDONLY)) { + sb->flags |= cpu_to_le64(fs_info->fs_state); ret = btrfs_commit_super(root); if (ret) printk(KERN_ERR "btrfs: commit super ret %d\n", ret); @@ -2592,6 +2601,20 @@ out: return 0; } +static void btrfs_check_super_valid(struct btrfs_fs_info *fs_info, + int read_only) +{ + if (read_only) + return; + + if (!(fs_info->fs_state & BTRFS_SUPER_FLAG_VALID)) + printk(KERN_WARNING "warning: mount unchecked fs, " + "running btfsck is recommended\n"); + else if (fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR) + printk(KERN_WARNING "warning: mount fs with errors, " + "running btfsck is recommended\n"); +} + static struct extent_io_ops btree_extent_io_ops = { .write_cache_pages_lock_hook = btree_lock_page_hook, .readpage_end_io_hook = btree_readpage_end_io_hook, diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 48fac6e..40130e8 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -771,6 +771,8 @@ error_free_subvol_name: static int btrfs_remount(struct super_block *sb, int *flags, char *data) { struct btrfs_root *root = btrfs_sb(sb); + struct btrfs_fs_info *fs_info = root->fs_info; + struct btrfs_super_block *disk_super = &fs_info->super_copy; int ret; ret = btrfs_parse_options(root, data); @@ -782,17 +784,21 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data) if (*flags & MS_RDONLY) { sb->s_flags |= MS_RDONLY; + if (!(disk_super->flags & + cpu_to_le64(BTRFS_SUPER_FLAG_VALID)) && + (fs_info->fs_state & BTRFS_SUPER_FLAG_VALID)) + disk_super->flags |= cpu_to_le64(fs_info->fs_state); ret = btrfs_commit_super(root); WARN_ON(ret); } else { - if (root->fs_info->fs_devices->rw_devices == 0) + if (fs_info->fs_devices->rw_devices == 0) return -EACCES; - if (btrfs_super_log_root(&root->fs_info->super_copy) != 0) + if (btrfs_super_log_root(disk_super) != 0) return -EINVAL; - ret = btrfs_cleanup_fs_roots(root->fs_info); + ret = btrfs_cleanup_fs_roots(fs_info); WARN_ON(ret); /* recover relocation */