From patchwork Tue Dec 15 09:17:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 58411 Delivered-To: patch@linaro.org Received: by 10.112.129.4 with SMTP id ns4csp74706lbb; Tue, 15 Dec 2015 01:18:12 -0800 (PST) X-Received: by 10.66.237.102 with SMTP id vb6mr52599116pac.133.1450171092372; Tue, 15 Dec 2015 01:18:12 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 18si727457pfc.4.2015.12.15.01.18.12; Tue, 15 Dec 2015 01:18:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964842AbbLOJSJ (ORCPT + 28 others); Tue, 15 Dec 2015 04:18:09 -0500 Received: from mailout2.samsung.com ([203.254.224.25]:54297 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933291AbbLOJSG (ORCPT ); Tue, 15 Dec 2015 04:18:06 -0500 Received: from epcpsbgm2new.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NZE02XO3760ZT60@mailout2.samsung.com> for linux-kernel@vger.kernel.org; Tue, 15 Dec 2015 18:18:03 +0900 (KST) X-AuditID: cbfee61b-f793c6d00000236c-bb-566fdacb6be5 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id 5B.F5.09068.BCADF665; Tue, 15 Dec 2015 18:18:03 +0900 (KST) Received: from yuchao ([109.123.105.89]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0NZE0068374X3080@mmp1.samsung.com>; Tue, 15 Dec 2015 18:18:03 +0900 (KST) From: Chao Yu To: Jaegeuk Kim , Yunlei He Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] f2fs: backup raw_super in sbi Date: Tue, 15 Dec 2015 17:17:20 +0800 Message-id: <010401d13719$803b6020$80b22060$@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-index: AdE3F82kGufPxPCnQPu7qRY4IzmsWA== Content-language: zh-cn X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrKLMWRmVeSWpSXmKPExsVy+t9jAd3Tt/LDDN7+tbTYejzG4sn6WcwW lxa5W1zeNYfNgcWj5chbVo9NqzrZPHYv+Mzk8XmTXABLFJdNSmpOZllqkb5dAlfGlft3GQue iVac+n+bsYHxgWAXIyeHhICJxMSf01khbDGJC/fWs3UxcnEICSxllJjQNJsFwnnFKPH6+k5m kCo2ARWJ5R3/mUBsEQFXiel9HWBxZgEPicaO72CThAWMJK5fnQFmswioSsw7PpENxOYVsJTY M2EVM4QtKPFj8j0WiF4tifU7jzNB2PISm9e8ZYa4SEFix9nXjBC79CT2n3zJClEjLrHxyC2W CYwCs5CMmoVk1Cwko2YhaVnAyLKKUSK1ILmgOCk91ygvtVyvODG3uDQvXS85P3cTIziwn0nv YDy8y/0QowAHoxIP7w/W/DAh1sSy4srcQ4wSHMxKIrzfLwGFeFMSK6tSi/Lji0pzUosPMUpz sCiJ8+67FBkmJJCeWJKanZpakFoEk2Xi4JRqYJymEXXwcrrBGcFrO09dPcwa97ZoVvNUIw8J hxo2CffoswcOWoZ9XOFQlLDqJQu79fE7L6uz/B2/CS58PlfctMKtquGete/jkq9vJT0Wb68r 7DqvYPagfc6OD9//2WlP/dBaN+uTXu6zV38kim2uuk66fqKHdVfgmpsZ2Yvrr1YLNuxaZLqV 46oSS3FGoqEWc1FxIgBDN55eaAIAAA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yunlei He f2fs use fields of f2fs_super_block struct directly in a grabbed buffer. Once the buffer happen to be destroyed (e.g. through dd), it may bring in unpredictable effect on f2fs. This patch fixes to allocate additional buffer to store datas of super block rather than using grabbed block buffer directly. Signed-off-by: Yunlei He Signed-off-by: Jaegeuk Kim Signed-off-by: Chao Yu --- fs/f2fs/super.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) -- 2.6.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 694e092..a6eb79a 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -578,6 +578,7 @@ static void f2fs_put_super(struct super_block *sb) sb->s_fs_info = NULL; brelse(sbi->raw_super_buf); + kfree(sbi->raw_super); kfree(sbi); } @@ -1153,6 +1154,9 @@ static int read_raw_super_block(struct super_block *sb, struct f2fs_super_block *super; int err = 0; + super = kzalloc(sizeof(struct f2fs_super_block), GFP_KERNEL); + if (!super) + return -ENOMEM; retry: buffer = sb_bread(sb, block); if (!buffer) { @@ -1168,8 +1172,7 @@ retry: } } - super = (struct f2fs_super_block *) - ((char *)(buffer)->b_data + F2FS_SUPER_OFFSET); + memcpy(super, buffer->b_data + F2FS_SUPER_OFFSET, sizeof(*super)); /* sanity checking of raw super */ if (sanity_check_raw_super(sb, super)) { @@ -1203,14 +1206,17 @@ retry: out: /* No valid superblock */ - if (!*raw_super) + if (!*raw_super) { + kfree(super); return err; + } return 0; } int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover) { + struct f2fs_super_block *super = F2FS_RAW_SUPER(sbi); struct buffer_head *sbh = sbi->raw_super_buf; struct buffer_head *bh; int err; @@ -1221,7 +1227,7 @@ int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover) return -EIO; lock_buffer(bh); - memcpy(bh->b_data, sbh->b_data, sbh->b_size); + memcpy(bh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super)); WARN_ON(sbh->b_size != F2FS_BLKSIZE); set_buffer_uptodate(bh); set_buffer_dirty(bh); @@ -1237,6 +1243,10 @@ int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover) /* write current valid superblock */ lock_buffer(sbh); + if (memcmp(sbh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super))) { + f2fs_msg(sbi->sb, KERN_INFO, "Write modified valid superblock"); + memcpy(sbh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super)); + } set_buffer_dirty(sbh); unlock_buffer(sbh); @@ -1513,6 +1523,7 @@ free_options: kfree(options); free_sb_buf: brelse(raw_super_buf); + kfree(raw_super); free_sbi: kfree(sbi);