From patchwork Mon Jan 9 05:38:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 9503781 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B2E1D6071A for ; Mon, 9 Jan 2017 05:38:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9966D27BFF for ; Mon, 9 Jan 2017 05:38:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E21D27CF5; Mon, 9 Jan 2017 05:38:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C3E827BFF for ; Mon, 9 Jan 2017 05:38:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933821AbdAIFiV (ORCPT ); Mon, 9 Jan 2017 00:38:21 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:41070 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S932110AbdAIFiU (ORCPT ); Mon, 9 Jan 2017 00:38:20 -0500 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="14584779" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 09 Jan 2017 13:38:05 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 6C34D46701DB for ; Mon, 9 Jan 2017 13:37:58 +0800 (CST) Received: from localhost.localdomain (10.167.226.129) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 9 Jan 2017 13:38:09 +0800 From: Su Yue To: Subject: [PATCH 2/2] btrfs-progs: cmds-check.c: supports inode isize fix in lowmem Date: Mon, 9 Jan 2017 13:38:08 +0800 Message-ID: <20170109053808.1979-2-suy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170109053808.1979-1-suy.fnst@cn.fujitsu.com> References: <20170109053808.1979-1-suy.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.129] X-yoursite-MailScanner-ID: 6C34D46701DB.AB44C X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: suy.fnst@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a function 'repair_inode_isize' to support inode isize repair. Signed-off-by: Su Yue --- cmds-check.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/cmds-check.c b/cmds-check.c index 567ca80..088c0d8 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -2457,6 +2457,45 @@ out: } /* + * Set inode's isize to correct value in @info + * + * Returns <0 means on error + * Returns 0 means successful repair + */ +static int repair_inode_isize_lowmem(struct btrfs_trans_handle *trans, + struct btrfs_root *root, + struct inode_item_fix_info *info) +{ + struct btrfs_inode_item *ei; + struct btrfs_key key; + struct btrfs_path path; + int ret; + + ASSERT(info); + key.objectid = info->ino; + key.type = BTRFS_INODE_ITEM_KEY; + key.offset = 0; + + ret = btrfs_search_slot(trans, root, &key, &path, 0, 1); + if (ret < 0) + goto out; + if (ret > 0) { + ret = -ENOENT; + goto out; + } + + ei = btrfs_item_ptr(path.nodes[0], path.slots[0], + struct btrfs_inode_item); + btrfs_set_inode_size(path.nodes[0], ei, info->isize); + btrfs_mark_buffer_dirty(path.nodes[0]); + printf("reset isize for inode %llu root %llu\n", info->ino, + root->root_key.objectid); +out: + btrfs_release_path(&path); + return ret; +} + +/* * repair_inode_item - repair inode item errors * * Repair the inode item if error can be repaired. Any caller should compare @@ -2484,7 +2523,7 @@ static int repair_inode_item(struct btrfs_root *root, ret = 0; goto out; } - if (!(err & NBYTES_ERROR)) { + if (!(err & NBYTES_ERROR) && !(err & ISIZE_ERROR)) { warning("root %llu INODE[%llu] have error(s) can't repair, error : %d", root->objectid, info->ino, err); /* can't fix any errors, ret should be positive */ @@ -2505,6 +2544,13 @@ static int repair_inode_item(struct btrfs_root *root, else if (ret < 0) goto out; } + if (err & ISIZE_ERROR) { + ret = repair_inode_isize_lowmem(trans, root, info); + if (ret == 0) + err &= ~ISIZE_ERROR; + else if (ret < 0) + goto out; + } if (err != info->err) { info->err = err; @@ -5039,6 +5085,7 @@ out: if (isize != size) { err |= ISIZE_ERROR; + info->isize = size; error("root %llu DIR INODE [%llu] size(%llu) not equal to %llu", root->objectid, inode_id, isize, size); }