Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3501799ybv; Tue, 25 Feb 2020 02:28:05 -0800 (PST) X-Google-Smtp-Source: APXvYqy7TaXIS7cwWBS3iskizyBs9n019/4TVqaLkFGAIyrKPDXV+3QxtBst9KQc2gfzj+rnhRRg X-Received: by 2002:a54:4396:: with SMTP id u22mr2900810oiv.128.1582626485581; Tue, 25 Feb 2020 02:28:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582626485; cv=none; d=google.com; s=arc-20160816; b=jDLY7RT5hiwWeVK1LWhkNeVmlI4M7zAz1gZ9AR2tNYcI1Z4UK1o09Kk+dTsBA+c25V kWJMHi4WSBq0oMOOUdzyLz5NMYnG1YzxbX5oQukFGbkFeLOhvqYRHMMJGSZA7Rt+hClr rqDC52xxVGDyEYM9znbZIGhnrIFJfU5/MRsrkWmjxNb5A86j1gSoxAilmg2kbxXZTeaW m7ldAPCt0mm567vDPeQHh2io4Qgb2C/9UOI59T52OqhHJOW+RR/9oSCJaC6I3HS2ASsQ 1F8v6TIdX1A605xDLKIrp/AWt+LI0CofVMEEvtrdyw0FdgU0HmDYUx/k4DiJsjWCObJS 0LSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=yh3yHc8FNRKMP5MovoaGUM7mVoAref2m5b26LjlsAEg=; b=bnYub5e8nPlHD09yQmO+UyKCvKLcFaNjgQdGioB263S2WyBUVtEYpaX9dTjH7Bwsh6 8OSqgdn/Fe2gjrg2DGNJLsXBq/cIYpui5WQISh9gmtzgjYKIcAWDkoe2vbHv54baWvJN aALBxOy9Hwqg/uvuMDU94mKbF1cNi5tKL34x9g1vl+g9CaDnEbhNj2zZRScE1H++FmLr WS5ONFHJhELS54M9/8oztkniIEKVD1INpcPAm9knpgZ8fTyhOvoO5LVOX8NpdckOt9NK fuyX2SWxAHTFecbxCg4p4fQah1YF7WGX36lIvA3/a2hwAQI8u3PtD+yVv1PfLluUzNQF m71w== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p83si6753264oih.198.2020.02.25.02.27.52; Tue, 25 Feb 2020 02:28:05 -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 S1730274AbgBYK05 (ORCPT + 99 others); Tue, 25 Feb 2020 05:26:57 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:34454 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730154AbgBYK05 (ORCPT ); Tue, 25 Feb 2020 05:26:57 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 8C569BA817E84CD5D94D; Tue, 25 Feb 2020 18:26:55 +0800 (CST) Received: from szvp000203569.huawei.com (10.120.216.130) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.439.0; Tue, 25 Feb 2020 18:26:48 +0800 From: Chao Yu To: CC: , , , Chao Yu Subject: [PATCH] f2fs: fix to check i_compr_blocks correctly Date: Tue, 25 Feb 2020 18:26:46 +0800 Message-ID: <20200225102646.43367-1-yuchao0@huawei.com> X-Mailer: git-send-email 2.18.0.rc1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.120.216.130] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org inode.i_blocks counts based on 512byte sector, we need to convert to 4kb sized block count before comparing to i_compr_blocks. In addition, add to print message when sanity check on inode compression configs failed. Signed-off-by: Chao Yu --- fs/f2fs/inode.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index 156cc5ef3044..299611562f7e 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -291,13 +291,30 @@ static bool sanity_check_inode(struct inode *inode, struct page *node_page) fi->i_flags & F2FS_COMPR_FL && F2FS_FITS_IN_INODE(ri, fi->i_extra_isize, i_log_cluster_size)) { - if (ri->i_compress_algorithm >= COMPRESS_MAX) + if (ri->i_compress_algorithm >= COMPRESS_MAX) { + f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported " + "compress algorithm: %u, run fsck to fix", + __func__, inode->i_ino, + ri->i_compress_algorithm); return false; - if (le64_to_cpu(ri->i_compr_blocks) > inode->i_blocks) + } + if (le64_to_cpu(ri->i_compr_blocks) > + SECTOR_TO_BLOCK(inode->i_blocks)) { + f2fs_warn(sbi, "%s: inode (ino=%lx) hash inconsistent " + "i_compr_blocks:%llu, i_blocks:%llu, run fsck to fix", + __func__, inode->i_ino, + le64_to_cpu(ri->i_compr_blocks), + SECTOR_TO_BLOCK(inode->i_blocks)); return false; + } if (ri->i_log_cluster_size < MIN_COMPRESS_LOG_SIZE || - ri->i_log_cluster_size > MAX_COMPRESS_LOG_SIZE) + ri->i_log_cluster_size > MAX_COMPRESS_LOG_SIZE) { + f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported " + "log cluster size: %u, run fsck to fix", + __func__, inode->i_ino, + ri->i_log_cluster_size); return false; + } } return true; -- 2.18.0.rc1