From patchwork Mon Jul 26 11:45:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12399293 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E034AC4320A for ; Mon, 26 Jul 2021 11:45:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C020460F37 for ; Mon, 26 Jul 2021 11:45:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233320AbhGZLF0 (ORCPT ); Mon, 26 Jul 2021 07:05:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233362AbhGZLFZ (ORCPT ); Mon, 26 Jul 2021 07:05:25 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99DD0C061757 for ; Mon, 26 Jul 2021 04:45:54 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id mt6so12540436pjb.1 for ; Mon, 26 Jul 2021 04:45:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CuqvT/cJSMj5kcRveqXd8IQygFBFWWKqxuz48jlUDJs=; b=ERTQmCK2wZrBSM16qvTaN0mfLTLNJVt3jvE9cTaxjo71N6KvOQX4hpe6Llxs1Ecqx5 aU9ynvT3txnxojYYd5Vdcd+lPoNFrpnyuqa0MeNFwH/wpj3DrtQL3xKQtlhvszGWpFxc ARAZRbs3SeDME9F4azn3e2XkFtYb5vLttQf9iZDxE7QZOUEqhLzoJHSba1RA0hkq51EJ 0QgdYg8Qhl2D2OHDT0GCh+VGBtWRbpIW1SXvxX5ppEvV2fAIh5mmtH0WQYGj7AyvzAXd mIrK63gHyHcL9srOG1sakODyKemmbVkB/8XxkkLwngRP8YbZoCI6b+Zk6jQOu6UH6FN9 LiZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CuqvT/cJSMj5kcRveqXd8IQygFBFWWKqxuz48jlUDJs=; b=J3v1NqtyXu69u9izFA52kvxQpItE/2A0p1PTVEBkZ3elpoULOQ3VG49G+fvri6wvVc qiX4tS8jaeUKJHRiBEicgqz8HsnJ1GUhXx+h2jdGS36ukjCBZLleTCfoB+W3VoCzYH6n OO8gsAR6lWaaCM+XV/Cxgb1PMAsYjehjFgxzxOdabX/7uMODb4V+gTVgP0rvKBC8mabe IHo+iihgWdPYWVidbUKQIH/xxVOMn8g5mocfOYOiq49/VkPXRLM1Dc20dA+wrIJQ5axv wROe3yhLHhPKd9ZU/nyEeSXWcwyR4WjFHPV+hVP50FBP55AT2c41HQejstyENz0giffY ihpg== X-Gm-Message-State: AOAM5312UDFfAi9bF79snW7cWjvdlWIwj1P7IxTp2yggr1oKfahmD8Rc Vas9gpiaR/0nAq9lYB0AAW9Kn17s80Y= X-Google-Smtp-Source: ABdhPJzj/5ZytPzNeaqnAPtopgPuVCVv8fxMKTpOr+T81vvg/S13u57mXuYoF+zLig/TeEsZHjjD3g== X-Received: by 2002:a17:902:f691:b029:12c:5bf:41cc with SMTP id l17-20020a170902f691b029012c05bf41ccmr7484621plg.68.1627299954105; Mon, 26 Jul 2021 04:45:54 -0700 (PDT) Received: from localhost.localdomain ([122.179.41.55]) by smtp.gmail.com with ESMTPSA id k8sm50833919pgr.91.2021.07.26.04.45.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 04:45:53 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , djwong@kernel.org Subject: [PATCH V2 01/12] xfs: Move extent count limits to xfs_format.h Date: Mon, 26 Jul 2021 17:15:30 +0530 Message-Id: <20210726114541.24898-2-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210726114541.24898-1-chandanrlinux@gmail.com> References: <20210726114541.24898-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Maximum values associated with extent counters i.e. Maximum extent length, Maximum data extents and Maximum xattr extents are dictated by the on-disk format. Hence move these definitions over to xfs_format.h. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_format.h | 7 +++++++ fs/xfs/libxfs/xfs_types.h | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h index 8cd48a651b96..37cca918d2ba 100644 --- a/fs/xfs/libxfs/xfs_format.h +++ b/fs/xfs/libxfs/xfs_format.h @@ -1109,6 +1109,13 @@ enum xfs_dinode_fmt { { XFS_DINODE_FMT_BTREE, "btree" }, \ { XFS_DINODE_FMT_UUID, "uuid" } +/* + * Max values for extlen, extnum, aextnum. + */ +#define MAXEXTLEN ((uint32_t)0x001fffff) /* 21 bits */ +#define MAXEXTNUM ((int32_t)0x7fffffff) /* signed int */ +#define MAXAEXTNUM ((int16_t)0x7fff) /* signed short */ + /* * Inode minimum and maximum sizes. */ diff --git a/fs/xfs/libxfs/xfs_types.h b/fs/xfs/libxfs/xfs_types.h index 5c0cc806068b..8908346b1deb 100644 --- a/fs/xfs/libxfs/xfs_types.h +++ b/fs/xfs/libxfs/xfs_types.h @@ -56,13 +56,6 @@ typedef void * xfs_failaddr_t; #define NULLFSINO ((xfs_ino_t)-1) #define NULLAGINO ((xfs_agino_t)-1) -/* - * Max values for extlen, extnum, aextnum. - */ -#define MAXEXTLEN ((xfs_extlen_t)0x001fffff) /* 21 bits */ -#define MAXEXTNUM ((xfs_extnum_t)0x7fffffff) /* signed int */ -#define MAXAEXTNUM ((xfs_aextnum_t)0x7fff) /* signed short */ - /* * Minimum and maximum blocksize and sectorsize. * The blocksize upper limit is pretty much arbitrary. From patchwork Mon Jul 26 11:45:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12399297 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 911C6C4338F for ; Mon, 26 Jul 2021 11:45:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 739E8601FD for ; Mon, 26 Jul 2021 11:45:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233452AbhGZLF2 (ORCPT ); Mon, 26 Jul 2021 07:05:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233362AbhGZLF2 (ORCPT ); Mon, 26 Jul 2021 07:05:28 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DCF9C061757 for ; Mon, 26 Jul 2021 04:45:56 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id a20so11464385plm.0 for ; Mon, 26 Jul 2021 04:45:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U1Uaxe85ctweAghCw4ywmDZvzrupPIXJFV78a1i/shg=; b=No6JxzHsrqrdNSCjHYTJokjXuq86cev40L6b/jJeUZhfd5cpU5GN0vj9gr4Rl+kd1V TQ2MmU6AIrcJ0qApfC0SMKXf+FqPdWSddp3jkdhLodj2LCad7ewVq6Sn2IeBfaqS3tIz LPWF1YPuJGJOTFNdY73kAM5ks+Oi8IXnFWqWHN1siZfRZmJPskUOctFw5mh/WhKE/x7N vuexy/2SMwWJjoDHSal5mE/KrqwOvj3zFHD5r0Y009Z3e870BeNDMSPMaawAu11UsZnz +hHHwt3hUOjPH13HQ9/8VwQxKsLwPceJkrNahMfynyH2IIa5olEPAPSjpxEvyBqLLopE 8Hcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U1Uaxe85ctweAghCw4ywmDZvzrupPIXJFV78a1i/shg=; b=hTGke9nqi4XP1nxUa3Tax/eu4x4U0iPFgixMg5Gh7b8CH1OJrMTEF1e5b+qBOLgpV9 fmmiQI4R/IBaHZH2+QjG5sETzws0YNEXePiN851UTaXvIm2VtG5njxbAAfRJrtu5BUmw EWdFX4elshhsi87yxAY7UlGv2u2pNsrbh5xuWfPNLiFGZ2C7RDiyRSWoiQ4nfPJgwOc9 p/SzO+1kdnVVZbHMru49Lz2ZOLzn3aHjrG033myD356dZ9pbp+kTW0HjzjbTpbAoMASy pIF2SClGzk/OKHbA4BnlleG5q1Tvxd06gH8ASuCWqlA+Ii+i9jvN6nIYje/FIJjqBvgi d+4g== X-Gm-Message-State: AOAM530mozfltWEzP1JtyxxoEUBFDHkvBLKYqDJ2oSA6mc5vE+BmAWIU QbK2XXeZ0WhNPqIIdRk1xMgXjFj4Akw= X-Google-Smtp-Source: ABdhPJx6xomQ8aGSnRbEekMydTcVkGCjyf6w7aqcV9R+Qfktk1hiHH+Fhp4cjCnfB8KqkvMCd/63fw== X-Received: by 2002:a65:4244:: with SMTP id d4mr18080480pgq.83.1627299955674; Mon, 26 Jul 2021 04:45:55 -0700 (PDT) Received: from localhost.localdomain ([122.179.41.55]) by smtp.gmail.com with ESMTPSA id k8sm50833919pgr.91.2021.07.26.04.45.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 04:45:55 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , djwong@kernel.org Subject: [PATCH V2 02/12] xfs: Rename MAXEXTNUM, MAXAEXTNUM to XFS_IFORK_EXTCNT_MAXS32, XFS_IFORK_EXTCNT_MAXS16 Date: Mon, 26 Jul 2021 17:15:31 +0530 Message-Id: <20210726114541.24898-3-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210726114541.24898-1-chandanrlinux@gmail.com> References: <20210726114541.24898-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org In preparation for introducing larger extent count limits, this commit renames existing extent count limits based on their signedness and width. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_bmap.c | 4 ++-- fs/xfs/libxfs/xfs_format.h | 8 ++++---- fs/xfs/libxfs/xfs_inode_buf.c | 4 ++-- fs/xfs/libxfs/xfs_inode_fork.c | 3 ++- fs/xfs/scrub/inode_repair.c | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index f3c9a0ebb0a5..8f262405a5b5 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -76,10 +76,10 @@ xfs_bmap_compute_maxlevels( * available. */ if (whichfork == XFS_DATA_FORK) { - maxleafents = MAXEXTNUM; + maxleafents = XFS_IFORK_EXTCNT_MAXS32; sz = xfs_bmdr_space_calc(MINDBTPTRS); } else { - maxleafents = MAXAEXTNUM; + maxleafents = XFS_IFORK_EXTCNT_MAXS16; sz = xfs_bmdr_space_calc(MINABTPTRS); } maxrootrecs = xfs_bmdr_maxrecs(sz, 0); diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h index 37cca918d2ba..920e3f9c418f 100644 --- a/fs/xfs/libxfs/xfs_format.h +++ b/fs/xfs/libxfs/xfs_format.h @@ -1110,11 +1110,11 @@ enum xfs_dinode_fmt { { XFS_DINODE_FMT_UUID, "uuid" } /* - * Max values for extlen, extnum, aextnum. + * Max values for extlen and disk inode's extent counters. */ -#define MAXEXTLEN ((uint32_t)0x001fffff) /* 21 bits */ -#define MAXEXTNUM ((int32_t)0x7fffffff) /* signed int */ -#define MAXAEXTNUM ((int16_t)0x7fff) /* signed short */ +#define MAXEXTLEN ((uint32_t)0x1fffff) /* 21 bits */ +#define XFS_IFORK_EXTCNT_MAXS32 ((int32_t)0x7fffffff) /* Signed 32-bits */ +#define XFS_IFORK_EXTCNT_MAXS16 ((int16_t)0x7fff) /* Signed 16-bits */ /* * Inode minimum and maximum sizes. diff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c index 5625df1ddd95..66d13e8fa420 100644 --- a/fs/xfs/libxfs/xfs_inode_buf.c +++ b/fs/xfs/libxfs/xfs_inode_buf.c @@ -365,9 +365,9 @@ xfs_dinode_verify_fork( break; case XFS_DINODE_FMT_BTREE: if (whichfork == XFS_ATTR_FORK) { - if (di_nextents > MAXAEXTNUM) + if (di_nextents > XFS_IFORK_EXTCNT_MAXS16) return __this_address; - } else if (di_nextents > MAXEXTNUM) { + } else if (di_nextents > XFS_IFORK_EXTCNT_MAXS32) { return __this_address; } break; diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index 801a6f7dbd0c..6f4b14d3d381 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.c +++ b/fs/xfs/libxfs/xfs_inode_fork.c @@ -736,7 +736,8 @@ xfs_iext_count_may_overflow( if (whichfork == XFS_COW_FORK) return 0; - max_exts = (whichfork == XFS_ATTR_FORK) ? MAXAEXTNUM : MAXEXTNUM; + max_exts = (whichfork == XFS_ATTR_FORK) ? + XFS_IFORK_EXTCNT_MAXS16 : XFS_IFORK_EXTCNT_MAXS32; if (XFS_TEST_ERROR(false, ip->i_mount, XFS_ERRTAG_REDUCE_MAX_IEXTENTS)) max_exts = 10; diff --git a/fs/xfs/scrub/inode_repair.c b/fs/xfs/scrub/inode_repair.c index a80cd633fe59..c44f8d06939b 100644 --- a/fs/xfs/scrub/inode_repair.c +++ b/fs/xfs/scrub/inode_repair.c @@ -1198,7 +1198,7 @@ xrep_inode_blockcounts( return error; if (count >= sc->mp->m_sb.sb_dblocks) return -EFSCORRUPTED; - if (nextents >= MAXAEXTNUM) + if (nextents >= XFS_IFORK_EXTCNT_MAXS16) return -EFSCORRUPTED; ifp->if_nextents = nextents; } else { From patchwork Mon Jul 26 11:45:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12399299 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1699C4320A for ; Mon, 26 Jul 2021 11:45:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D6A70601FD for ; Mon, 26 Jul 2021 11:45:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233362AbhGZLF3 (ORCPT ); Mon, 26 Jul 2021 07:05:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233456AbhGZLF2 (ORCPT ); Mon, 26 Jul 2021 07:05:28 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF197C061757 for ; Mon, 26 Jul 2021 04:45:57 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id pf12-20020a17090b1d8cb0290175c085e7a5so19351086pjb.0 for ; Mon, 26 Jul 2021 04:45:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ke1thBOtJ83M3Pzz4Z3GvQJqecw53ADoUBZbHqtzRmw=; b=sALBoOoH60baireqjgH49MIQqp5WYpRrAR4PO0jheJRcwXtiV9wSYThq2Obn+JbEB4 YMWQ2uNvHWaQELuUs1E2BLV1F4THgiLi155kpsuwqkJhL3WeZME3GmonJ26gpVfxuKPU qh4blaDon2WYX9CnF4CD6Vk5uVxxLAmHCNdcZir+yueEH6FKV52M0IhM1cwCqKDXvSEJ lIewOHLar0fnAatLim3CxZi46vO5Qbhc6R4mys9/DD7rRPXQ2YJ70tb79O+vLYlEHSES xRl+XoNRSdh+iW79l82oQlax5TalA8fSqRtuAD0fFrh21WKkBHliP8HoFGaYAlEy2dZo 1zsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ke1thBOtJ83M3Pzz4Z3GvQJqecw53ADoUBZbHqtzRmw=; b=blkOQ9AkzJK1q4+sf2A7bHXrpHQ4iuryoOA7wZhawA+WIG9BETHWUgMZuyXzcC57Oy 5tPSr8gx4+/6OUNSnbJTeEcEZqTo2KXTl4NO6wTCKx4ZQu77XJcAawd81cpemaPRHAmJ Y7ZQy4hjS3oI5l+mIv/2M0w3EmvII+dkSWr9Ea2h5y46Qd1PWMGotvnrI2B2ocjFJYsF 10NJ9iPg1Roz3PEI5Dm7sNUjYWHbVeivxQyolANeOdzp68WiEQgYuD0ITqfXRk+TtpYs 27yu5CPuMYICBO6DfV2aQr+RACb5Z7agZtCWfvw+XqN21er8+6egmyg406UII2dGu1zb Sqlg== X-Gm-Message-State: AOAM530jtVzEFFR8RioFqpi7ApAQhSHXRg8mtFOyr1Fti98o1spu1rSS HpEcS8E+Lz7OeeUIPKINvWBVCxzgGGs= X-Google-Smtp-Source: ABdhPJwWNwph7+uAy1B9BjTvt7yuUjN7jkLrHrMWF4HALCHNgOxwh2WQmnfH7oRtEhH6gJGtFMLQdg== X-Received: by 2002:a17:90a:b78d:: with SMTP id m13mr7951727pjr.178.1627299957305; Mon, 26 Jul 2021 04:45:57 -0700 (PDT) Received: from localhost.localdomain ([122.179.41.55]) by smtp.gmail.com with ESMTPSA id k8sm50833919pgr.91.2021.07.26.04.45.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 04:45:57 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , djwong@kernel.org Subject: [PATCH V2 03/12] xfs: Introduce xfs_iext_max() helper Date: Mon, 26 Jul 2021 17:15:32 +0530 Message-Id: <20210726114541.24898-4-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210726114541.24898-1-chandanrlinux@gmail.com> References: <20210726114541.24898-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org xfs_iext_max() returns the maximum number of extents possible for one of data, cow or attribute fork. This helper will be extended further in a future commit when maximum extent counts associated with data/attribute forks are increased. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_bmap.c | 9 ++++----- fs/xfs/libxfs/xfs_inode_buf.c | 8 +++----- fs/xfs/libxfs/xfs_inode_fork.c | 6 +++--- fs/xfs/libxfs/xfs_inode_fork.h | 8 ++++++++ fs/xfs/scrub/inode_repair.c | 2 +- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 8f262405a5b5..282aeb3c0e49 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -75,13 +75,12 @@ xfs_bmap_compute_maxlevels( * ATTR2 we have to assume the worst case scenario of a minimum size * available. */ - if (whichfork == XFS_DATA_FORK) { - maxleafents = XFS_IFORK_EXTCNT_MAXS32; + maxleafents = xfs_iext_max(mp, whichfork); + if (whichfork == XFS_DATA_FORK) sz = xfs_bmdr_space_calc(MINDBTPTRS); - } else { - maxleafents = XFS_IFORK_EXTCNT_MAXS16; + else sz = xfs_bmdr_space_calc(MINABTPTRS); - } + maxrootrecs = xfs_bmdr_maxrecs(sz, 0); minleafrecs = mp->m_bmap_dmnr[0]; minnoderecs = mp->m_bmap_dmnr[1]; diff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c index 66d13e8fa420..419b92dc6ac8 100644 --- a/fs/xfs/libxfs/xfs_inode_buf.c +++ b/fs/xfs/libxfs/xfs_inode_buf.c @@ -343,6 +343,7 @@ xfs_dinode_verify_fork( int whichfork) { uint32_t di_nextents = XFS_DFORK_NEXTENTS(dip, whichfork); + xfs_extnum_t max_extents; switch (XFS_DFORK_FORMAT(dip, whichfork)) { case XFS_DINODE_FMT_LOCAL: @@ -364,12 +365,9 @@ xfs_dinode_verify_fork( return __this_address; break; case XFS_DINODE_FMT_BTREE: - if (whichfork == XFS_ATTR_FORK) { - if (di_nextents > XFS_IFORK_EXTCNT_MAXS16) - return __this_address; - } else if (di_nextents > XFS_IFORK_EXTCNT_MAXS32) { + max_extents = xfs_iext_max(mp, whichfork); + if (di_nextents > max_extents) return __this_address; - } break; default: return __this_address; diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index 6f4b14d3d381..c6856ec95335 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.c +++ b/fs/xfs/libxfs/xfs_inode_fork.c @@ -729,6 +729,7 @@ xfs_iext_count_may_overflow( int whichfork, int nr_to_add) { + struct xfs_mount *mp = ip->i_mount; struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork); uint64_t max_exts; uint64_t nr_exts; @@ -736,10 +737,9 @@ xfs_iext_count_may_overflow( if (whichfork == XFS_COW_FORK) return 0; - max_exts = (whichfork == XFS_ATTR_FORK) ? - XFS_IFORK_EXTCNT_MAXS16 : XFS_IFORK_EXTCNT_MAXS32; + max_exts = xfs_iext_max(mp, whichfork); - if (XFS_TEST_ERROR(false, ip->i_mount, XFS_ERRTAG_REDUCE_MAX_IEXTENTS)) + if (XFS_TEST_ERROR(false, mp, XFS_ERRTAG_REDUCE_MAX_IEXTENTS)) max_exts = 10; nr_exts = ifp->if_nextents + nr_to_add; diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index cf82be263b48..1eda2163603e 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -133,6 +133,14 @@ static inline int8_t xfs_ifork_format(struct xfs_ifork *ifp) return ifp->if_format; } +static inline xfs_extnum_t xfs_iext_max(struct xfs_mount *mp, int whichfork) +{ + if (whichfork == XFS_DATA_FORK || whichfork == XFS_COW_FORK) + return XFS_IFORK_EXTCNT_MAXS32; + else + return XFS_IFORK_EXTCNT_MAXS16; +} + struct xfs_ifork *xfs_ifork_alloc(enum xfs_dinode_fmt format, xfs_extnum_t nextents); struct xfs_ifork *xfs_iext_state_to_fork(struct xfs_inode *ip, int state); diff --git a/fs/xfs/scrub/inode_repair.c b/fs/xfs/scrub/inode_repair.c index c44f8d06939b..a44d7b48c374 100644 --- a/fs/xfs/scrub/inode_repair.c +++ b/fs/xfs/scrub/inode_repair.c @@ -1198,7 +1198,7 @@ xrep_inode_blockcounts( return error; if (count >= sc->mp->m_sb.sb_dblocks) return -EFSCORRUPTED; - if (nextents >= XFS_IFORK_EXTCNT_MAXS16) + if (nextents >= xfs_iext_max(sc->mp, XFS_ATTR_FORK)) return -EFSCORRUPTED; ifp->if_nextents = nextents; } else { From patchwork Mon Jul 26 11:45:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12399301 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94131C432BE for ; Mon, 26 Jul 2021 11:46:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 72ABE603E9 for ; Mon, 26 Jul 2021 11:46:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233502AbhGZLFa (ORCPT ); Mon, 26 Jul 2021 07:05:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233456AbhGZLFa (ORCPT ); Mon, 26 Jul 2021 07:05:30 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CECDC061757 for ; Mon, 26 Jul 2021 04:45:59 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id pf12-20020a17090b1d8cb0290175c085e7a5so19351183pjb.0 for ; Mon, 26 Jul 2021 04:45:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=egX49VLOYW0Ka8wk9leDQQi6L1Fb5WhS4AtKGZoZ0bg=; b=IOE+jhbCLmqeyOiwYg07UIOXrvX+xkpf8RxMKUlfAvTwnuX+B3TPAmhAJjOi4HAvGa Wr03ekmVaiQYB/v5Wyagu1iKHX4D3uN5MHLlRH/2NcfJaMXsqVREZrOhGoU2M/HlTyHR ifg+Um6pIawEWmxvEDp2SlLLXQRlNOdde4eyDw79NrMaqdOEeP1v2sHPkz7gIqekqPXO 5yN8IbUYt0Odojtl4kvoDLwAaJZyCCSgG0uemxkbf858usij2HJON6/XbCP3qwnfc5q+ lx1T+Qq1wOFaF70MH2HxALi2Yr0SaQ2Y8eVd8ptiCJ/CMyyGOo5byvMJZDLeIeaM0F3Z otkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=egX49VLOYW0Ka8wk9leDQQi6L1Fb5WhS4AtKGZoZ0bg=; b=VwfTbfScYGNJEdBxLsNfZmrVLMUZgivNDz4mqvrG7SFvosY9hyh/LyItStnjSeNYhC 4GblHjraFvMyhxW2lvWD67VeaJLgBEKqA1E6zmV8V6Hu+p9dzdFEOP84W0y0571rpzpR fUmnRyG5ew95vYi5b12fhLCf7RL13bXy0W0viegB5vzTaZFXjTVQTbCpZ4BGRf0fcCD2 1sBSecv8PnsBxVSr2uICMmXnlkKnA1p2QpYM8Eulf6VuGJ0/Zv5QL1FqxaleRZ5OQ67O HZQpPfxFKXK9UWKVfaZkIXDRbPgk8Waj+8AAf86mk/iijROpEvd4HNXG0+D/QVzBOROc 3Eow== X-Gm-Message-State: AOAM5316E/IfZq7QyZarIfGeFMgWk4klPpxAurfzrSt8DuTraw3ZF0eo w+P5YqCHihmQr3Is/7g1aJHN3C3ul54= X-Google-Smtp-Source: ABdhPJzt1n97hswKbwIWVEJ/VGYLv59nImFoi0wmXwzBPH3+0AOaQLewuC+AqAs16f92kBzTXV4W6w== X-Received: by 2002:a17:90a:ea98:: with SMTP id h24mr25422740pjz.7.1627299958846; Mon, 26 Jul 2021 04:45:58 -0700 (PDT) Received: from localhost.localdomain ([122.179.41.55]) by smtp.gmail.com with ESMTPSA id k8sm50833919pgr.91.2021.07.26.04.45.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 04:45:58 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , djwong@kernel.org Subject: [PATCH V2 04/12] xfs: Use xfs_extnum_t instead of basic data types Date: Mon, 26 Jul 2021 17:15:33 +0530 Message-Id: <20210726114541.24898-5-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210726114541.24898-1-chandanrlinux@gmail.com> References: <20210726114541.24898-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org xfs_extnum_t is the type to use to declare variables which have values obtained from xfs_dinode->di_[a]nextents. This commit replaces basic types (e.g. uint32_t) with xfs_extnum_t for such variables. Signed-off-by: Chandan Babu R Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_bmap.c | 2 +- fs/xfs/libxfs/xfs_inode_buf.c | 2 +- fs/xfs/libxfs/xfs_inode_fork.c | 2 +- fs/xfs/scrub/inode.c | 2 +- fs/xfs/scrub/inode_repair.c | 2 +- fs/xfs/xfs_trace.h | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 282aeb3c0e49..e5d243fd187d 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -53,9 +53,9 @@ xfs_bmap_compute_maxlevels( xfs_mount_t *mp, /* file system mount structure */ int whichfork) /* data or attr fork */ { + xfs_extnum_t maxleafents; /* max leaf entries possible */ int level; /* btree level */ uint maxblocks; /* max blocks at this level */ - uint maxleafents; /* max leaf entries possible */ int maxrootrecs; /* max records in root block */ int minleafrecs; /* min records in leaf block */ int minnoderecs; /* min records in node block */ diff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c index 419b92dc6ac8..cba9a38f3270 100644 --- a/fs/xfs/libxfs/xfs_inode_buf.c +++ b/fs/xfs/libxfs/xfs_inode_buf.c @@ -342,7 +342,7 @@ xfs_dinode_verify_fork( struct xfs_mount *mp, int whichfork) { - uint32_t di_nextents = XFS_DFORK_NEXTENTS(dip, whichfork); + xfs_extnum_t di_nextents = XFS_DFORK_NEXTENTS(dip, whichfork); xfs_extnum_t max_extents; switch (XFS_DFORK_FORMAT(dip, whichfork)) { diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index c6856ec95335..a1e40df585a3 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.c +++ b/fs/xfs/libxfs/xfs_inode_fork.c @@ -107,7 +107,7 @@ xfs_iformat_extents( struct xfs_mount *mp = ip->i_mount; struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork); int state = xfs_bmap_fork_to_state(whichfork); - int nex = XFS_DFORK_NEXTENTS(dip, whichfork); + xfs_extnum_t nex = XFS_DFORK_NEXTENTS(dip, whichfork); int size = nex * sizeof(xfs_bmbt_rec_t); struct xfs_iext_cursor icur; struct xfs_bmbt_rec *dp; diff --git a/fs/xfs/scrub/inode.c b/fs/xfs/scrub/inode.c index e6068590484b..246d11ca133f 100644 --- a/fs/xfs/scrub/inode.c +++ b/fs/xfs/scrub/inode.c @@ -219,7 +219,7 @@ xchk_dinode( size_t fork_recs; unsigned long long isize; uint64_t flags2; - uint32_t nextents; + xfs_extnum_t nextents; prid_t prid; uint16_t flags; uint16_t mode; diff --git a/fs/xfs/scrub/inode_repair.c b/fs/xfs/scrub/inode_repair.c index a44d7b48c374..042c7d0bc0f5 100644 --- a/fs/xfs/scrub/inode_repair.c +++ b/fs/xfs/scrub/inode_repair.c @@ -597,9 +597,9 @@ xrep_dinode_bad_extents_fork( { struct xfs_bmbt_irec new; struct xfs_bmbt_rec *dp; + xfs_extnum_t nex; bool isrt; int i; - int nex; int fork_size; nex = XFS_DFORK_NEXTENTS(dip, whichfork); diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h index affc9b5834fb..5ed11f894f79 100644 --- a/fs/xfs/xfs_trace.h +++ b/fs/xfs/xfs_trace.h @@ -2338,7 +2338,7 @@ DECLARE_EVENT_CLASS(xfs_swap_extent_class, __field(int, which) __field(xfs_ino_t, ino) __field(int, format) - __field(int, nex) + __field(xfs_extnum_t, nex) __field(int, broot_size) __field(int, fork_off) ), From patchwork Mon Jul 26 11:45:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12399303 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60DADC4338F for ; Mon, 26 Jul 2021 11:46:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 447C660238 for ; Mon, 26 Jul 2021 11:46:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233517AbhGZLFd (ORCPT ); Mon, 26 Jul 2021 07:05:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233456AbhGZLFd (ORCPT ); Mon, 26 Jul 2021 07:05:33 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E3CAC061757 for ; Mon, 26 Jul 2021 04:46:01 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id m2-20020a17090a71c2b0290175cf22899cso13847480pjs.2 for ; Mon, 26 Jul 2021 04:46:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t5tFtySNTcoqYVjZAD1fSWj/eaMueRAEiHn5A4OLxXg=; b=NVryYrpH9n77iSMw1a4b0ZAjphoT5SDB+t4dtP0QLpPwfrlWheuC9MHmhJ6dlRPFxu Tr64NM7JAfkFRS5Z7SHyTw7j3Eg2cvNEGDaIjsF7lIBnarTiTt/oRU7P0Oau7ZSl1N2r u0FvzExYVQGhx8TcRsWn+GyHqy7wWsoH1N0hzv8K0DOvEuz+wMWKEgRq89dZs5CjgFUI CSXVlHPDSm3T0blY9VURrL17dDy0K/zPHGw7D19afMCLiNKyx685VeIxM5al/TL58aAh 3u+EhrIMgbW2lnJxMtFBQWXGvREcHwMnpe2yP6gJg4zgpxHdvZt5BPGaAmJkHGIGnmwo tZKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=t5tFtySNTcoqYVjZAD1fSWj/eaMueRAEiHn5A4OLxXg=; b=X5nEocySDcXk15XgZfTlNvt1pyxaKrec+iKcVvhmzqCHaaRYp8B1UiEx7Z9mqudyrO PCuB0TT182JwiTj23uRaRtF4kNWxy9QiCiNC034AKOpsDYnvJtJTltyjPiNNrKjB4/Vp o9pFi7mHhs0Hq2f/EnENkNWeBL165wtEq/KfVhg3iaAJ3jIVjkuSp6pfPIOIZ3HZ8KHf nwFjvZruqQovMvI6734KzB+0aXFmhUFQ7ygwX+3QOZ1moA60uMVfjx9Kep7CX6xrQc8n NwB97ewmLIxAth5k7cbGUj9Vt5No2V8BtETs+nulhnb9s887SqVJ/o1gvtIu8mDoLSHW 2Rpw== X-Gm-Message-State: AOAM532sVg2TlG6uriPVjsM94TwXpFZuCB43L+0Ob6dCiWpBvUT0Z0YE 7EAWk9CeKCPmZ+dd27tlsDDfAxY67OM= X-Google-Smtp-Source: ABdhPJxUCVuVA21FeFwxAm854HEi2umjnDEJpQvRsPZoHjmWH1fe2kmxljObgdEHgS4dTpoMjZ/I8A== X-Received: by 2002:a17:90a:404a:: with SMTP id k10mr16899194pjg.145.1627299960606; Mon, 26 Jul 2021 04:46:00 -0700 (PDT) Received: from localhost.localdomain ([122.179.41.55]) by smtp.gmail.com with ESMTPSA id k8sm50833919pgr.91.2021.07.26.04.45.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 04:46:00 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , djwong@kernel.org Subject: [PATCH V2 05/12] xfs: Introduce xfs_dfork_nextents() helper Date: Mon, 26 Jul 2021 17:15:34 +0530 Message-Id: <20210726114541.24898-6-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210726114541.24898-1-chandanrlinux@gmail.com> References: <20210726114541.24898-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit replaces the macro XFS_DFORK_NEXTENTS() with the helper function xfs_dfork_nextents(). As of this commit, xfs_dfork_nextents() returns the same value as XFS_DFORK_NEXTENTS(). A future commit which extends inode's extent counter fields will add more logic to this helper. This commit also replaces direct accesses to xfs_dinode->di_[a]nextents with calls to xfs_dfork_nextents(). No functional changes have been made. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_format.h | 4 ---- fs/xfs/libxfs/xfs_inode_buf.c | 41 +++++++++++++++++++++++++++++----- fs/xfs/libxfs/xfs_inode_buf.h | 2 ++ fs/xfs/libxfs/xfs_inode_fork.c | 12 ++++++---- fs/xfs/scrub/inode.c | 19 +++++++++------- fs/xfs/scrub/inode_repair.c | 38 +++++++++++++++++++------------ 6 files changed, 81 insertions(+), 35 deletions(-) diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h index 920e3f9c418f..001a4077a7c6 100644 --- a/fs/xfs/libxfs/xfs_format.h +++ b/fs/xfs/libxfs/xfs_format.h @@ -1166,10 +1166,6 @@ enum xfs_dinode_fmt { ((w) == XFS_DATA_FORK ? \ (dip)->di_format : \ (dip)->di_aformat) -#define XFS_DFORK_NEXTENTS(dip,w) \ - ((w) == XFS_DATA_FORK ? \ - be32_to_cpu((dip)->di_nextents) : \ - be16_to_cpu((dip)->di_anextents)) /* * For block and character special files the 32bit dev_t is stored at the diff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c index cba9a38f3270..6bef0757fca4 100644 --- a/fs/xfs/libxfs/xfs_inode_buf.c +++ b/fs/xfs/libxfs/xfs_inode_buf.c @@ -342,9 +342,11 @@ xfs_dinode_verify_fork( struct xfs_mount *mp, int whichfork) { - xfs_extnum_t di_nextents = XFS_DFORK_NEXTENTS(dip, whichfork); + xfs_extnum_t di_nextents; xfs_extnum_t max_extents; + di_nextents = xfs_dfork_nextents(mp, dip, whichfork); + switch (XFS_DFORK_FORMAT(dip, whichfork)) { case XFS_DINODE_FMT_LOCAL: /* @@ -375,6 +377,31 @@ xfs_dinode_verify_fork( return NULL; } +xfs_extnum_t +xfs_dfork_nextents( + struct xfs_mount *mp, + struct xfs_dinode *dip, + int whichfork) +{ + xfs_extnum_t nextents = 0; + + switch (whichfork) { + case XFS_DATA_FORK: + nextents = be32_to_cpu(dip->di_nextents); + break; + + case XFS_ATTR_FORK: + nextents = be16_to_cpu(dip->di_anextents); + break; + + default: + ASSERT(0); + break; + } + + return nextents; +} + static xfs_failaddr_t xfs_dinode_verify_forkoff( struct xfs_dinode *dip, @@ -474,6 +501,8 @@ xfs_dinode_verify( uint16_t flags; uint64_t flags2; uint64_t di_size; + xfs_extnum_t nextents; + int64_t nblocks; if (dip->di_magic != cpu_to_be16(XFS_DINODE_MAGIC)) return __this_address; @@ -504,10 +533,12 @@ xfs_dinode_verify( if ((S_ISLNK(mode) || S_ISDIR(mode)) && di_size == 0) return __this_address; + nextents = xfs_dfork_nextents(mp, dip, XFS_DATA_FORK); + nextents += xfs_dfork_nextents(mp, dip, XFS_ATTR_FORK); + nblocks = be64_to_cpu(dip->di_nblocks); + /* Fork checks carried over from xfs_iformat_fork */ - if (mode && - be32_to_cpu(dip->di_nextents) + be16_to_cpu(dip->di_anextents) > - be64_to_cpu(dip->di_nblocks)) + if (mode && nextents > nblocks) return __this_address; if (mode && XFS_DFORK_BOFF(dip) > mp->m_sb.sb_inodesize) @@ -564,7 +595,7 @@ xfs_dinode_verify( default: return __this_address; } - if (dip->di_anextents) + if (xfs_dfork_nextents(mp, dip, XFS_ATTR_FORK)) return __this_address; } diff --git a/fs/xfs/libxfs/xfs_inode_buf.h b/fs/xfs/libxfs/xfs_inode_buf.h index a30b7676098a..ea2c35091609 100644 --- a/fs/xfs/libxfs/xfs_inode_buf.h +++ b/fs/xfs/libxfs/xfs_inode_buf.h @@ -36,6 +36,8 @@ xfs_failaddr_t xfs_inode_validate_extsize(struct xfs_mount *mp, xfs_failaddr_t xfs_inode_validate_cowextsize(struct xfs_mount *mp, uint32_t cowextsize, uint16_t mode, uint16_t flags, uint64_t flags2); +xfs_extnum_t xfs_dfork_nextents(struct xfs_mount *mp, struct xfs_dinode *dip, + int whichfork); static inline uint64_t xfs_inode_encode_bigtime(struct timespec64 tv) { diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index a1e40df585a3..38dd2dfc31fa 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.c +++ b/fs/xfs/libxfs/xfs_inode_fork.c @@ -107,7 +107,7 @@ xfs_iformat_extents( struct xfs_mount *mp = ip->i_mount; struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork); int state = xfs_bmap_fork_to_state(whichfork); - xfs_extnum_t nex = XFS_DFORK_NEXTENTS(dip, whichfork); + xfs_extnum_t nex = xfs_dfork_nextents(mp, dip, whichfork); int size = nex * sizeof(xfs_bmbt_rec_t); struct xfs_iext_cursor icur; struct xfs_bmbt_rec *dp; @@ -226,6 +226,7 @@ xfs_iformat_data_fork( struct xfs_inode *ip, struct xfs_dinode *dip) { + struct xfs_mount *mp = ip->i_mount; struct inode *inode = VFS_I(ip); int error; @@ -234,7 +235,7 @@ xfs_iformat_data_fork( * depend on it. */ ip->i_df.if_format = dip->di_format; - ip->i_df.if_nextents = be32_to_cpu(dip->di_nextents); + ip->i_df.if_nextents = xfs_dfork_nextents(mp, dip, XFS_DATA_FORK); switch (inode->i_mode & S_IFMT) { case S_IFIFO: @@ -301,14 +302,17 @@ xfs_iformat_attr_fork( struct xfs_inode *ip, struct xfs_dinode *dip) { + struct xfs_mount *mp = ip->i_mount; + xfs_extnum_t nextents; int error = 0; + nextents = xfs_dfork_nextents(mp, dip, XFS_ATTR_FORK); + /* * Initialize the extent count early, as the per-format routines may * depend on it. */ - ip->i_afp = xfs_ifork_alloc(dip->di_aformat, - be16_to_cpu(dip->di_anextents)); + ip->i_afp = xfs_ifork_alloc(dip->di_aformat, nextents); switch (ip->i_afp->if_format) { case XFS_DINODE_FMT_LOCAL: diff --git a/fs/xfs/scrub/inode.c b/fs/xfs/scrub/inode.c index 246d11ca133f..a161dac31a6f 100644 --- a/fs/xfs/scrub/inode.c +++ b/fs/xfs/scrub/inode.c @@ -220,6 +220,7 @@ xchk_dinode( unsigned long long isize; uint64_t flags2; xfs_extnum_t nextents; + xfs_extnum_t naextents; prid_t prid; uint16_t flags; uint16_t mode; @@ -378,7 +379,7 @@ xchk_dinode( xchk_inode_extsize(sc, dip, ino, mode, flags); /* di_nextents */ - nextents = be32_to_cpu(dip->di_nextents); + nextents = xfs_dfork_nextents(mp, dip, XFS_DATA_FORK); fork_recs = XFS_DFORK_DSIZE(dip, mp) / sizeof(struct xfs_bmbt_rec); switch (dip->di_format) { case XFS_DINODE_FMT_EXTENTS: @@ -395,10 +396,12 @@ xchk_dinode( break; } + naextents = xfs_dfork_nextents(mp, dip, XFS_ATTR_FORK); + /* di_forkoff */ if (XFS_DFORK_APTR(dip) >= (char *)dip + mp->m_sb.sb_inodesize) xchk_ino_set_corrupt(sc, ino); - if (dip->di_anextents != 0 && dip->di_forkoff == 0) + if (naextents != 0 && dip->di_forkoff == 0) xchk_ino_set_corrupt(sc, ino); if (dip->di_forkoff == 0 && dip->di_aformat != XFS_DINODE_FMT_EXTENTS) xchk_ino_set_corrupt(sc, ino); @@ -410,19 +413,18 @@ xchk_dinode( xchk_ino_set_corrupt(sc, ino); /* di_anextents */ - nextents = be16_to_cpu(dip->di_anextents); fork_recs = XFS_DFORK_ASIZE(dip, mp) / sizeof(struct xfs_bmbt_rec); switch (dip->di_aformat) { case XFS_DINODE_FMT_EXTENTS: - if (nextents > fork_recs) + if (naextents > fork_recs) xchk_ino_set_corrupt(sc, ino); break; case XFS_DINODE_FMT_BTREE: - if (nextents <= fork_recs) + if (naextents <= fork_recs) xchk_ino_set_corrupt(sc, ino); break; default: - if (nextents != 0) + if (naextents != 0) xchk_ino_set_corrupt(sc, ino); } @@ -487,6 +489,7 @@ xchk_inode_xref_bmap( struct xfs_scrub *sc, struct xfs_dinode *dip) { + struct xfs_mount *mp = sc->mp; xfs_extnum_t nextents; xfs_filblks_t count; xfs_filblks_t acount; @@ -500,14 +503,14 @@ xchk_inode_xref_bmap( &nextents, &count); if (!xchk_should_check_xref(sc, &error, NULL)) return; - if (nextents < be32_to_cpu(dip->di_nextents)) + if (nextents < xfs_dfork_nextents(mp, dip, XFS_DATA_FORK)) xchk_ino_xref_set_corrupt(sc, sc->ip->i_ino); error = xfs_bmap_count_blocks(sc->tp, sc->ip, XFS_ATTR_FORK, &nextents, &acount); if (!xchk_should_check_xref(sc, &error, NULL)) return; - if (nextents != be16_to_cpu(dip->di_anextents)) + if (nextents != xfs_dfork_nextents(mp, dip, XFS_ATTR_FORK)) xchk_ino_xref_set_corrupt(sc, sc->ip->i_ino); /* Check nblocks against the inode. */ diff --git a/fs/xfs/scrub/inode_repair.c b/fs/xfs/scrub/inode_repair.c index 042c7d0bc0f5..bdb4685923c0 100644 --- a/fs/xfs/scrub/inode_repair.c +++ b/fs/xfs/scrub/inode_repair.c @@ -602,7 +602,7 @@ xrep_dinode_bad_extents_fork( int i; int fork_size; - nex = XFS_DFORK_NEXTENTS(dip, whichfork); + nex = xfs_dfork_nextents(sc->mp, dip, whichfork); fork_size = nex * sizeof(struct xfs_bmbt_rec); if (fork_size < 0 || fork_size > dfork_size) return true; @@ -636,7 +636,7 @@ xrep_dinode_bad_btree_fork( int nrecs; int level; - if (XFS_DFORK_NEXTENTS(dip, whichfork) <= + if (xfs_dfork_nextents(sc->mp, dip, whichfork) <= dfork_size / sizeof(struct xfs_bmbt_rec)) return true; @@ -831,12 +831,16 @@ xrep_dinode_ensure_forkoff( struct xrep_dinode_stats *dis) { struct xfs_bmdr_block *bmdr; + xfs_extnum_t anextents, dnextents; size_t bmdr_minsz = xfs_bmdr_space_calc(1); unsigned int lit_sz = XFS_LITINO(sc->mp); unsigned int afork_min, dfork_min; trace_xrep_dinode_ensure_forkoff(sc, dip); + dnextents = xfs_dfork_nextents(sc->mp, dip, XFS_DATA_FORK); + anextents = xfs_dfork_nextents(sc->mp, dip, XFS_ATTR_FORK); + /* * Before calling this function, xrep_dinode_core ensured that both * forks actually fit inside their respective literal areas. If this @@ -857,15 +861,14 @@ xrep_dinode_ensure_forkoff( afork_min = XFS_DFORK_SIZE(dip, sc->mp, XFS_ATTR_FORK); break; case XFS_DINODE_FMT_EXTENTS: - if (dip->di_anextents) { + if (anextents) { /* * We must maintain sufficient space to hold the entire * extent map array in the data fork. Note that we * previously zapped the fork if it had no chance of * fitting in the inode. */ - afork_min = sizeof(struct xfs_bmbt_rec) * - be16_to_cpu(dip->di_anextents); + afork_min = sizeof(struct xfs_bmbt_rec) * anextents; } else if (dis->attr_extents > 0) { /* * The attr fork thinks it has zero extents, but we @@ -908,15 +911,14 @@ xrep_dinode_ensure_forkoff( dfork_min = be64_to_cpu(dip->di_size); break; case XFS_DINODE_FMT_EXTENTS: - if (dip->di_nextents) { + if (dnextents) { /* * We must maintain sufficient space to hold the entire * extent map array in the data fork. Note that we * previously zapped the fork if it had no chance of * fitting in the inode. */ - dfork_min = sizeof(struct xfs_bmbt_rec) * - be32_to_cpu(dip->di_nextents); + dfork_min = sizeof(struct xfs_bmbt_rec) * dnextents; } else if (dis->data_extents > 0 || dis->rt_extents > 0) { /* * The data fork thinks it has zero extents, but we @@ -956,7 +958,7 @@ xrep_dinode_ensure_forkoff( * recovery fork, move the attr fork up. */ if (dip->di_format == XFS_DINODE_FMT_EXTENTS && - dip->di_nextents == 0 && + dnextents == 0 && (dis->data_extents > 0 || dis->rt_extents > 0) && bmdr_minsz > XFS_DFORK_DSIZE(dip, sc->mp)) { if (bmdr_minsz + afork_min > lit_sz) { @@ -982,7 +984,7 @@ xrep_dinode_ensure_forkoff( * recovery fork, move the attr fork down. */ if (dip->di_aformat == XFS_DINODE_FMT_EXTENTS && - dip->di_anextents == 0 && + anextents == 0 && dis->attr_extents > 0 && bmdr_minsz > XFS_DFORK_ASIZE(dip, sc->mp)) { if (dip->di_format == XFS_DINODE_FMT_BTREE) { @@ -1019,6 +1021,9 @@ xrep_dinode_zap_forks( struct xfs_dinode *dip, struct xrep_dinode_stats *dis) { + uint64_t nblocks; + xfs_extnum_t nextents; + xfs_extnum_t naextents; uint16_t mode; bool zap_datafork = false; bool zap_attrfork = false; @@ -1028,12 +1033,17 @@ xrep_dinode_zap_forks( mode = be16_to_cpu(dip->di_mode); /* Inode counters don't make sense? */ - if (be32_to_cpu(dip->di_nextents) > be64_to_cpu(dip->di_nblocks)) + nblocks = be64_to_cpu(dip->di_nblocks); + + nextents = xfs_dfork_nextents(sc->mp, dip, XFS_DATA_FORK); + if (nextents > nblocks) zap_datafork = true; - if (be16_to_cpu(dip->di_anextents) > be64_to_cpu(dip->di_nblocks)) + + naextents = xfs_dfork_nextents(sc->mp, dip, XFS_ATTR_FORK); + if (naextents > nblocks) zap_attrfork = true; - if (be32_to_cpu(dip->di_nextents) + be16_to_cpu(dip->di_anextents) > - be64_to_cpu(dip->di_nblocks)) + + if (nextents + naextents > nblocks) zap_datafork = zap_attrfork = true; if (!zap_datafork) From patchwork Mon Jul 26 11:45:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12399305 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91F55C432BE for ; Mon, 26 Jul 2021 11:46:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7971A601FD for ; Mon, 26 Jul 2021 11:46:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233534AbhGZLFf (ORCPT ); Mon, 26 Jul 2021 07:05:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233529AbhGZLFf (ORCPT ); Mon, 26 Jul 2021 07:05:35 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25E3BC061757 for ; Mon, 26 Jul 2021 04:46:03 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id i10so8135746pla.3 for ; Mon, 26 Jul 2021 04:46:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=F+r72Te+F8cUTUcRAmXJ3uWdLTbuw0R9WiR1Ocn6a+A=; b=fXHTuMNDTXj1NPJOQ6YI/LDooRGEsMpen0eufFxYBqPEBPm3Xzx9fpl8tzY6P8PZo+ IT5sw1KZJk3sHTMXL5kUA6Sc/9I2/8TbEK5+xeUNjoILed1A0yVNeVP0CddyBOCD3czC objAOcePEdYmJ4M/hScVfl9reWfeC7lS/hdgK+QT0ZAoivNMQlc8QGy+XkHHUOeO3u/8 rYBRL3sVTYWVGVv6+Jj/E5NM+47U29PDvgMlt+ZKZT+qXWwACU2tWZ0xBfBNzw1nEkRi Cs9uVSaG2MuOgyFtUhgks8sqsn1SMw+m8V8LI653F2+FfBUpA0qiHlxsPTz1qNaPa7Wy IHOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=F+r72Te+F8cUTUcRAmXJ3uWdLTbuw0R9WiR1Ocn6a+A=; b=ihMw+NQ41bc+kGisNx0MPqtQSTWAU8+vvKYIBzKS8XtDB1WYGw0n0jNC2ceIi26DdX epAKDODSSEZHHI9pNbH9VzICRyKso6Co+rxDrjL90K7KdrAuAd4ZskkW0IiRm3MeGPv4 ejgmXfi1xHqy1wrl43tWz2+HrZue36tCLH5WQ3ki+msA+gSLsfirlA13Z0GTM762X2uc GS4Uen6Kzpnpmold1U5+kn93Wtqb7xi9vZSD6RUeASJ8G3iHwfN8fGL/zY9UQF1qen3L H8N7buOL85bpFOtAvAd/TRqP9MbO5vJh3bvYEkXgHE9i0shsiKPfH5nhtpPX27Tow87v kKiw== X-Gm-Message-State: AOAM53048mQmfv8aKRoNm8yMoRXwrwg8eFPDtu7/JyTvsgV60dGqdkrS /fWBBigv09jHpORAWyfc5213f2lcCQc= X-Google-Smtp-Source: ABdhPJw15JE87XCntKGbglwOqO8clyBa7tnvBoIGcJqfTxpEmBo6Rfs8uFhQNVSgPcEv/57rOqGnIw== X-Received: by 2002:a62:5a86:0:b029:334:567b:d80e with SMTP id o128-20020a625a860000b0290334567bd80emr17478914pfb.44.1627299962564; Mon, 26 Jul 2021 04:46:02 -0700 (PDT) Received: from localhost.localdomain ([122.179.41.55]) by smtp.gmail.com with ESMTPSA id k8sm50833919pgr.91.2021.07.26.04.46.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 04:46:02 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , djwong@kernel.org Subject: [PATCH V2 06/12] xfs: xfs_dfork_nextents: Return extent count via an out argument Date: Mon, 26 Jul 2021 17:15:35 +0530 Message-Id: <20210726114541.24898-7-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210726114541.24898-1-chandanrlinux@gmail.com> References: <20210726114541.24898-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit changes xfs_dfork_nextents() to return an error code. The extent count itself is now returned through an out argument. This facility will be used by a future commit to indicate an inconsistent ondisk extent count. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_buf.c | 29 +++++++---- fs/xfs/libxfs/xfs_inode_buf.h | 4 +- fs/xfs/libxfs/xfs_inode_fork.c | 22 ++++++-- fs/xfs/scrub/inode.c | 94 +++++++++++++++++++++------------- fs/xfs/scrub/inode_repair.c | 34 ++++++++---- 5 files changed, 119 insertions(+), 64 deletions(-) diff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c index 6bef0757fca4..9ed04da2e2b1 100644 --- a/fs/xfs/libxfs/xfs_inode_buf.c +++ b/fs/xfs/libxfs/xfs_inode_buf.c @@ -345,7 +345,8 @@ xfs_dinode_verify_fork( xfs_extnum_t di_nextents; xfs_extnum_t max_extents; - di_nextents = xfs_dfork_nextents(mp, dip, whichfork); + if (xfs_dfork_nextents(mp, dip, whichfork, &di_nextents)) + return __this_address; switch (XFS_DFORK_FORMAT(dip, whichfork)) { case XFS_DINODE_FMT_LOCAL: @@ -377,29 +378,31 @@ xfs_dinode_verify_fork( return NULL; } -xfs_extnum_t +int xfs_dfork_nextents( struct xfs_mount *mp, struct xfs_dinode *dip, - int whichfork) + int whichfork, + xfs_extnum_t *nextents) { - xfs_extnum_t nextents = 0; + int error = 0; switch (whichfork) { case XFS_DATA_FORK: - nextents = be32_to_cpu(dip->di_nextents); + *nextents = be32_to_cpu(dip->di_nextents); break; case XFS_ATTR_FORK: - nextents = be16_to_cpu(dip->di_anextents); + *nextents = be16_to_cpu(dip->di_anextents); break; default: ASSERT(0); + error = -EINVAL; break; } - return nextents; + return error; } static xfs_failaddr_t @@ -502,6 +505,7 @@ xfs_dinode_verify( uint64_t flags2; uint64_t di_size; xfs_extnum_t nextents; + xfs_extnum_t naextents; int64_t nblocks; if (dip->di_magic != cpu_to_be16(XFS_DINODE_MAGIC)) @@ -533,8 +537,13 @@ xfs_dinode_verify( if ((S_ISLNK(mode) || S_ISDIR(mode)) && di_size == 0) return __this_address; - nextents = xfs_dfork_nextents(mp, dip, XFS_DATA_FORK); - nextents += xfs_dfork_nextents(mp, dip, XFS_ATTR_FORK); + if (xfs_dfork_nextents(mp, dip, XFS_DATA_FORK, &nextents)) + return __this_address; + + if (xfs_dfork_nextents(mp, dip, XFS_ATTR_FORK, &naextents)) + return __this_address; + + nextents += naextents; nblocks = be64_to_cpu(dip->di_nblocks); /* Fork checks carried over from xfs_iformat_fork */ @@ -595,7 +604,7 @@ xfs_dinode_verify( default: return __this_address; } - if (xfs_dfork_nextents(mp, dip, XFS_ATTR_FORK)) + if (naextents) return __this_address; } diff --git a/fs/xfs/libxfs/xfs_inode_buf.h b/fs/xfs/libxfs/xfs_inode_buf.h index ea2c35091609..20f796610d46 100644 --- a/fs/xfs/libxfs/xfs_inode_buf.h +++ b/fs/xfs/libxfs/xfs_inode_buf.h @@ -36,8 +36,8 @@ xfs_failaddr_t xfs_inode_validate_extsize(struct xfs_mount *mp, xfs_failaddr_t xfs_inode_validate_cowextsize(struct xfs_mount *mp, uint32_t cowextsize, uint16_t mode, uint16_t flags, uint64_t flags2); -xfs_extnum_t xfs_dfork_nextents(struct xfs_mount *mp, struct xfs_dinode *dip, - int whichfork); +int xfs_dfork_nextents(struct xfs_mount *mp, struct xfs_dinode *dip, + int whichfork, xfs_extnum_t *nextents); static inline uint64_t xfs_inode_encode_bigtime(struct timespec64 tv) { diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index 38dd2dfc31fa..7f7ffe29436d 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.c +++ b/fs/xfs/libxfs/xfs_inode_fork.c @@ -107,13 +107,20 @@ xfs_iformat_extents( struct xfs_mount *mp = ip->i_mount; struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork); int state = xfs_bmap_fork_to_state(whichfork); - xfs_extnum_t nex = xfs_dfork_nextents(mp, dip, whichfork); - int size = nex * sizeof(xfs_bmbt_rec_t); + xfs_extnum_t nex; + int size; struct xfs_iext_cursor icur; struct xfs_bmbt_rec *dp; struct xfs_bmbt_irec new; + int error; int i; + error = xfs_dfork_nextents(mp, dip, whichfork, &nex); + if (error) + return error; + + size = nex * sizeof(xfs_bmbt_rec_t); + /* * If the number of extents is unreasonable, then something is wrong and * we just bail out rather than crash in kmem_alloc() or memcpy() below. @@ -235,7 +242,10 @@ xfs_iformat_data_fork( * depend on it. */ ip->i_df.if_format = dip->di_format; - ip->i_df.if_nextents = xfs_dfork_nextents(mp, dip, XFS_DATA_FORK); + error = xfs_dfork_nextents(mp, dip, XFS_DATA_FORK, + &ip->i_df.if_nextents); + if (error) + return error; switch (inode->i_mode & S_IFMT) { case S_IFIFO: @@ -304,9 +314,11 @@ xfs_iformat_attr_fork( { struct xfs_mount *mp = ip->i_mount; xfs_extnum_t nextents; - int error = 0; + int error; - nextents = xfs_dfork_nextents(mp, dip, XFS_ATTR_FORK); + error = xfs_dfork_nextents(mp, dip, XFS_ATTR_FORK, &nextents); + if (error) + return error; /* * Initialize the extent count early, as the per-format routines may diff --git a/fs/xfs/scrub/inode.c b/fs/xfs/scrub/inode.c index a161dac31a6f..e9dc3749ea08 100644 --- a/fs/xfs/scrub/inode.c +++ b/fs/xfs/scrub/inode.c @@ -208,6 +208,44 @@ xchk_dinode_nsec( xchk_ino_set_corrupt(sc, ino); } +STATIC void +xchk_dinode_fork_recs( + struct xfs_scrub *sc, + struct xfs_dinode *dip, + xfs_ino_t ino, + xfs_extnum_t nextents, + int whichfork) +{ + struct xfs_mount *mp = sc->mp; + size_t fork_recs; + unsigned char format; + + if (whichfork == XFS_DATA_FORK) { + fork_recs = XFS_DFORK_DSIZE(dip, mp) + / sizeof(struct xfs_bmbt_rec); + format = dip->di_format; + } else if (whichfork == XFS_ATTR_FORK) { + fork_recs = XFS_DFORK_ASIZE(dip, mp) + / sizeof(struct xfs_bmbt_rec); + format = dip->di_aformat; + } + + switch (format) { + case XFS_DINODE_FMT_EXTENTS: + if (nextents > fork_recs) + xchk_ino_set_corrupt(sc, ino); + break; + case XFS_DINODE_FMT_BTREE: + if (nextents <= fork_recs) + xchk_ino_set_corrupt(sc, ino); + break; + default: + if (nextents != 0) + xchk_ino_set_corrupt(sc, ino); + break; + } +} + /* Scrub all the ondisk inode fields. */ STATIC void xchk_dinode( @@ -216,7 +254,6 @@ xchk_dinode( xfs_ino_t ino) { struct xfs_mount *mp = sc->mp; - size_t fork_recs; unsigned long long isize; uint64_t flags2; xfs_extnum_t nextents; @@ -224,6 +261,7 @@ xchk_dinode( prid_t prid; uint16_t flags; uint16_t mode; + int error; flags = be16_to_cpu(dip->di_flags); if (dip->di_version >= 3) @@ -379,33 +417,22 @@ xchk_dinode( xchk_inode_extsize(sc, dip, ino, mode, flags); /* di_nextents */ - nextents = xfs_dfork_nextents(mp, dip, XFS_DATA_FORK); - fork_recs = XFS_DFORK_DSIZE(dip, mp) / sizeof(struct xfs_bmbt_rec); - switch (dip->di_format) { - case XFS_DINODE_FMT_EXTENTS: - if (nextents > fork_recs) - xchk_ino_set_corrupt(sc, ino); - break; - case XFS_DINODE_FMT_BTREE: - if (nextents <= fork_recs) - xchk_ino_set_corrupt(sc, ino); - break; - default: - if (nextents != 0) - xchk_ino_set_corrupt(sc, ino); - break; - } - - naextents = xfs_dfork_nextents(mp, dip, XFS_ATTR_FORK); + error = xfs_dfork_nextents(mp, dip, XFS_DATA_FORK, &nextents); + if (error) + xchk_ino_set_corrupt(sc, ino); + else + xchk_dinode_fork_recs(sc, dip, ino, nextents, XFS_DATA_FORK); /* di_forkoff */ if (XFS_DFORK_APTR(dip) >= (char *)dip + mp->m_sb.sb_inodesize) xchk_ino_set_corrupt(sc, ino); - if (naextents != 0 && dip->di_forkoff == 0) - xchk_ino_set_corrupt(sc, ino); if (dip->di_forkoff == 0 && dip->di_aformat != XFS_DINODE_FMT_EXTENTS) xchk_ino_set_corrupt(sc, ino); + error = xfs_dfork_nextents(mp, dip, XFS_ATTR_FORK, &naextents); + if (error || (naextents != 0 && dip->di_forkoff == 0)) + xchk_ino_set_corrupt(sc, ino); + /* di_aformat */ if (dip->di_aformat != XFS_DINODE_FMT_LOCAL && dip->di_aformat != XFS_DINODE_FMT_EXTENTS && @@ -413,20 +440,8 @@ xchk_dinode( xchk_ino_set_corrupt(sc, ino); /* di_anextents */ - fork_recs = XFS_DFORK_ASIZE(dip, mp) / sizeof(struct xfs_bmbt_rec); - switch (dip->di_aformat) { - case XFS_DINODE_FMT_EXTENTS: - if (naextents > fork_recs) - xchk_ino_set_corrupt(sc, ino); - break; - case XFS_DINODE_FMT_BTREE: - if (naextents <= fork_recs) - xchk_ino_set_corrupt(sc, ino); - break; - default: - if (naextents != 0) - xchk_ino_set_corrupt(sc, ino); - } + if (!error) + xchk_dinode_fork_recs(sc, dip, ino, naextents, XFS_ATTR_FORK); if (dip->di_version >= 3) { xchk_dinode_nsec(sc, ino, dip, dip->di_crtime); @@ -490,6 +505,7 @@ xchk_inode_xref_bmap( struct xfs_dinode *dip) { struct xfs_mount *mp = sc->mp; + xfs_extnum_t dip_nextents; xfs_extnum_t nextents; xfs_filblks_t count; xfs_filblks_t acount; @@ -503,14 +519,18 @@ xchk_inode_xref_bmap( &nextents, &count); if (!xchk_should_check_xref(sc, &error, NULL)) return; - if (nextents < xfs_dfork_nextents(mp, dip, XFS_DATA_FORK)) + + error = xfs_dfork_nextents(mp, dip, XFS_DATA_FORK, &dip_nextents); + if (error || nextents < dip_nextents) xchk_ino_xref_set_corrupt(sc, sc->ip->i_ino); error = xfs_bmap_count_blocks(sc->tp, sc->ip, XFS_ATTR_FORK, &nextents, &acount); if (!xchk_should_check_xref(sc, &error, NULL)) return; - if (nextents != xfs_dfork_nextents(mp, dip, XFS_ATTR_FORK)) + + error = xfs_dfork_nextents(mp, dip, XFS_ATTR_FORK, &dip_nextents); + if (error || nextents < dip_nextents) xchk_ino_xref_set_corrupt(sc, sc->ip->i_ino); /* Check nblocks against the inode. */ diff --git a/fs/xfs/scrub/inode_repair.c b/fs/xfs/scrub/inode_repair.c index bdb4685923c0..521c8df00990 100644 --- a/fs/xfs/scrub/inode_repair.c +++ b/fs/xfs/scrub/inode_repair.c @@ -602,7 +602,9 @@ xrep_dinode_bad_extents_fork( int i; int fork_size; - nex = xfs_dfork_nextents(sc->mp, dip, whichfork); + if (xfs_dfork_nextents(sc->mp, dip, whichfork, &nex)) + return true; + fork_size = nex * sizeof(struct xfs_bmbt_rec); if (fork_size < 0 || fork_size > dfork_size) return true; @@ -633,11 +635,14 @@ xrep_dinode_bad_btree_fork( int whichfork) { struct xfs_bmdr_block *dfp; + xfs_extnum_t nextents; int nrecs; int level; - if (xfs_dfork_nextents(sc->mp, dip, whichfork) <= - dfork_size / sizeof(struct xfs_bmbt_rec)) + if (xfs_dfork_nextents(sc->mp, dip, whichfork, &nextents)) + return true; + + if (nextents <= dfork_size / sizeof(struct xfs_bmbt_rec)) return true; if (dfork_size < sizeof(struct xfs_bmdr_block)) @@ -774,11 +779,15 @@ xrep_dinode_check_afork( struct xfs_dinode *dip) { struct xfs_attr_shortform *sfp; + xfs_extnum_t nextents; int size; + if (xfs_dfork_nextents(sc->mp, dip, XFS_ATTR_FORK, &nextents)) + return true; + if (XFS_DFORK_BOFF(dip) == 0) return dip->di_aformat != XFS_DINODE_FMT_EXTENTS || - dip->di_anextents != 0; + nextents != 0; size = XFS_DFORK_SIZE(dip, sc->mp, XFS_ATTR_FORK); switch (XFS_DFORK_FORMAT(dip, XFS_ATTR_FORK)) { @@ -835,11 +844,15 @@ xrep_dinode_ensure_forkoff( size_t bmdr_minsz = xfs_bmdr_space_calc(1); unsigned int lit_sz = XFS_LITINO(sc->mp); unsigned int afork_min, dfork_min; + int error; trace_xrep_dinode_ensure_forkoff(sc, dip); - dnextents = xfs_dfork_nextents(sc->mp, dip, XFS_DATA_FORK); - anextents = xfs_dfork_nextents(sc->mp, dip, XFS_ATTR_FORK); + error = xfs_dfork_nextents(sc->mp, dip, XFS_DATA_FORK, &dnextents); + ASSERT(error == 0); + + error = xfs_dfork_nextents(sc->mp, dip, XFS_ATTR_FORK, &anextents); + ASSERT(error == 0); /* * Before calling this function, xrep_dinode_core ensured that both @@ -1027,6 +1040,7 @@ xrep_dinode_zap_forks( uint16_t mode; bool zap_datafork = false; bool zap_attrfork = false; + int error; trace_xrep_dinode_zap_forks(sc, dip); @@ -1035,12 +1049,12 @@ xrep_dinode_zap_forks( /* Inode counters don't make sense? */ nblocks = be64_to_cpu(dip->di_nblocks); - nextents = xfs_dfork_nextents(sc->mp, dip, XFS_DATA_FORK); - if (nextents > nblocks) + error = xfs_dfork_nextents(sc->mp, dip, XFS_DATA_FORK, &nextents); + if (error || nextents > nblocks) zap_datafork = true; - naextents = xfs_dfork_nextents(sc->mp, dip, XFS_ATTR_FORK); - if (naextents > nblocks) + error = xfs_dfork_nextents(sc->mp, dip, XFS_ATTR_FORK, &naextents); + if (error || naextents > nblocks) zap_attrfork = true; if (nextents + naextents > nblocks) From patchwork Mon Jul 26 11:45:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12399307 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0483FC4338F for ; Mon, 26 Jul 2021 11:46:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E437660F4F for ; Mon, 26 Jul 2021 11:46:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233456AbhGZLFh (ORCPT ); Mon, 26 Jul 2021 07:05:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233568AbhGZLFg (ORCPT ); Mon, 26 Jul 2021 07:05:36 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0755C061757 for ; Mon, 26 Jul 2021 04:46:04 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id e21so6734244pla.5 for ; Mon, 26 Jul 2021 04:46:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Vd1m9BkEbiXXE3/pf4xji9GW7ljAdFcqcBAA/yO6MUM=; b=hSDSl5TFX16pXLCM0oEClSYYZNObrtE5iBNo7vJCzhaEYlUKl1kvKTvrcOuiKHBKQs cMxa73b/AO/5DKpdiwIZR9jLrSoKNVU/J+AtefOwOQz56lktZBTL2ChwGcxblMZoS+EA 9e/qAtWVeuUOL4O7CdcTaTrRDTXuZiMRHWDs+DF70cthW/3XIoAvj5VRDJGUF6Tgus0B 5/lm9o58KSljIIaU7OXobWD9pGKOcyn5WbgSJ24PQevrS9wc/aHFhvxA++t2nZIAAqtR VIlzc1QqZnNEP7ahJ/ruW4M1kZQLep8x/U0uq2TQTsdjU/cOYHSdKVg9M7KYsEWKUAVa aflA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Vd1m9BkEbiXXE3/pf4xji9GW7ljAdFcqcBAA/yO6MUM=; b=AGuk4ElcoRlmp2bDZ1QRR73kJc9D4iUG6eM0Tj8uQIgV1F224zKzotiT7MZf+EnIaF WvNqrFE23pGWZHYBcR+jw2EqfWVxpUxkJC9JCYSMdIMX3wcxf24aaK8kH0goo9CWPxgQ 7ieAk/vLUVVvSL6yrkUVCUhnvzg3NfvCA5QR9u5y8Ld4IhaJQQBD/m3CZl0GSsNPDx/e Q94HrBbvQa2zIFSU3lAfLI6P6jZ1KOZ/VGCNqopIXFuuqEs9Uvqvv3e4Tdt87pIUTMOO PhdiLhFa8msTjmWqnv/vexh9eB18pvQ/V7ldwRL4bIO+ZaM4YFuq/3IUb1+RNsc6iWAz xcKQ== X-Gm-Message-State: AOAM530CmebPFvLjRRPFzY4Oy13111RsNEPKtOcEktNlwRT5ufadQ338 HvB64v/cgrcV9IKz/1BZYsFvuw/yDm8= X-Google-Smtp-Source: ABdhPJzbjuV972RD/ZNDwPgxbsAXpv13C9BfgPiWMbsgtAHL2HsuLhB5Kj1i6WehmP48KwDz51BIEw== X-Received: by 2002:a65:6487:: with SMTP id e7mr17756105pgv.27.1627299964237; Mon, 26 Jul 2021 04:46:04 -0700 (PDT) Received: from localhost.localdomain ([122.179.41.55]) by smtp.gmail.com with ESMTPSA id k8sm50833919pgr.91.2021.07.26.04.46.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 04:46:04 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , djwong@kernel.org Subject: [PATCH V2 07/12] xfs: Rename inode's extent counter fields based on their width Date: Mon, 26 Jul 2021 17:15:36 +0530 Message-Id: <20210726114541.24898-8-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210726114541.24898-1-chandanrlinux@gmail.com> References: <20210726114541.24898-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit renames extent counter fields in "struct xfs_dinode" and "struct xfs_log_dinode" based on the width of the fields. As of this commit, the 32-bit field will be used to count data fork extents and the 16-bit field will be used to count attr fork extents. This change is done to enable a future commit to introduce a new 64-bit extent counter field. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_format.h | 4 ++-- fs/xfs/libxfs/xfs_inode_buf.c | 8 ++++---- fs/xfs/libxfs/xfs_log_format.h | 4 ++-- fs/xfs/scrub/inode_repair.c | 4 ++-- fs/xfs/scrub/trace.h | 14 +++++++------- fs/xfs/xfs_inode_item.c | 4 ++-- fs/xfs/xfs_inode_item_recover.c | 8 ++++---- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h index 001a4077a7c6..2362cc005cc6 100644 --- a/fs/xfs/libxfs/xfs_format.h +++ b/fs/xfs/libxfs/xfs_format.h @@ -1039,8 +1039,8 @@ typedef struct xfs_dinode { __be64 di_size; /* number of bytes in file */ __be64 di_nblocks; /* # of direct & btree blocks used */ __be32 di_extsize; /* basic/minimum extent size for file */ - __be32 di_nextents; /* number of extents in data fork */ - __be16 di_anextents; /* number of extents in attribute fork*/ + __be32 di_nextents32; /* number of extents in data fork */ + __be16 di_nextents16; /* number of extents in attribute fork*/ __u8 di_forkoff; /* attr fork offs, <<3 for 64b align */ __s8 di_aformat; /* format of attr fork's data */ __be32 di_dmevmask; /* DMIG event mask */ diff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c index 9ed04da2e2b1..65d753e16007 100644 --- a/fs/xfs/libxfs/xfs_inode_buf.c +++ b/fs/xfs/libxfs/xfs_inode_buf.c @@ -313,8 +313,8 @@ xfs_inode_to_disk( to->di_size = cpu_to_be64(ip->i_disk_size); to->di_nblocks = cpu_to_be64(ip->i_nblocks); to->di_extsize = cpu_to_be32(ip->i_extsize); - to->di_nextents = cpu_to_be32(xfs_ifork_nextents(&ip->i_df)); - to->di_anextents = cpu_to_be16(xfs_ifork_nextents(ip->i_afp)); + to->di_nextents32 = cpu_to_be32(xfs_ifork_nextents(&ip->i_df)); + to->di_nextents16 = cpu_to_be16(xfs_ifork_nextents(ip->i_afp)); to->di_forkoff = ip->i_forkoff; to->di_aformat = xfs_ifork_format(ip->i_afp); to->di_flags = cpu_to_be16(ip->i_diflags); @@ -389,11 +389,11 @@ xfs_dfork_nextents( switch (whichfork) { case XFS_DATA_FORK: - *nextents = be32_to_cpu(dip->di_nextents); + *nextents = be32_to_cpu(dip->di_nextents32); break; case XFS_ATTR_FORK: - *nextents = be16_to_cpu(dip->di_anextents); + *nextents = be16_to_cpu(dip->di_nextents16); break; default: diff --git a/fs/xfs/libxfs/xfs_log_format.h b/fs/xfs/libxfs/xfs_log_format.h index 0c888f92184e..ca8e4ad8312a 100644 --- a/fs/xfs/libxfs/xfs_log_format.h +++ b/fs/xfs/libxfs/xfs_log_format.h @@ -402,8 +402,8 @@ struct xfs_log_dinode { xfs_fsize_t di_size; /* number of bytes in file */ xfs_rfsblock_t di_nblocks; /* # of direct & btree blocks used */ xfs_extlen_t di_extsize; /* basic/minimum extent size for file */ - xfs_extnum_t di_nextents; /* number of extents in data fork */ - xfs_aextnum_t di_anextents; /* number of extents in attribute fork*/ + uint32_t di_nextents32; /* number of extents in data fork */ + uint16_t di_nextents16; /* number of extents in attribute fork*/ uint8_t di_forkoff; /* attr fork offs, <<3 for 64b align */ int8_t di_aformat; /* format of attr fork's data */ uint32_t di_dmevmask; /* DMIG event mask */ diff --git a/fs/xfs/scrub/inode_repair.c b/fs/xfs/scrub/inode_repair.c index 521c8df00990..4d773a16f886 100644 --- a/fs/xfs/scrub/inode_repair.c +++ b/fs/xfs/scrub/inode_repair.c @@ -736,7 +736,7 @@ xrep_dinode_zap_dfork( { trace_xrep_dinode_zap_dfork(sc, dip); - dip->di_nextents = 0; + dip->di_nextents32 = 0; /* Special files always get reset to DEV */ switch (mode & S_IFMT) { @@ -823,7 +823,7 @@ xrep_dinode_zap_afork( trace_xrep_dinode_zap_afork(sc, dip); dip->di_aformat = XFS_DINODE_FMT_EXTENTS; - dip->di_anextents = 0; + dip->di_nextents16 = 0; dip->di_forkoff = 0; dip->di_mode = cpu_to_be16(mode & ~0777); diff --git a/fs/xfs/scrub/trace.h b/fs/xfs/scrub/trace.h index fd03685b1f6b..a0303f692e52 100644 --- a/fs/xfs/scrub/trace.h +++ b/fs/xfs/scrub/trace.h @@ -1209,8 +1209,8 @@ DECLARE_EVENT_CLASS(xrep_dinode_class, __field(uint64_t, size) __field(uint64_t, nblocks) __field(uint32_t, extsize) - __field(uint32_t, nextents) - __field(uint16_t, anextents) + __field(uint32_t, nextents32) + __field(uint16_t, nextents16) __field(uint8_t, forkoff) __field(uint8_t, aformat) __field(uint16_t, flags) @@ -1229,8 +1229,8 @@ DECLARE_EVENT_CLASS(xrep_dinode_class, __entry->size = be64_to_cpu(dip->di_size); __entry->nblocks = be64_to_cpu(dip->di_nblocks); __entry->extsize = be32_to_cpu(dip->di_extsize); - __entry->nextents = be32_to_cpu(dip->di_nextents); - __entry->anextents = be16_to_cpu(dip->di_anextents); + __entry->nextents32 = be32_to_cpu(dip->di_nextents32); + __entry->nextents16 = be16_to_cpu(dip->di_nextents16); __entry->forkoff = dip->di_forkoff; __entry->aformat = dip->di_aformat; __entry->flags = be16_to_cpu(dip->di_flags); @@ -1238,7 +1238,7 @@ DECLARE_EVENT_CLASS(xrep_dinode_class, __entry->flags2 = be64_to_cpu(dip->di_flags2); __entry->cowextsize = be32_to_cpu(dip->di_cowextsize); ), - TP_printk("dev %d:%d ino 0x%llx mode 0x%x version %u format %u uid %u gid %u size %llu nblocks %llu extsize %u nextents %u anextents %u forkoff %u aformat %u flags 0x%x gen 0x%x flags2 0x%llx cowextsize %u", + TP_printk("dev %d:%d ino 0x%llx mode 0x%x version %u format %u uid %u gid %u size %llu nblocks %llu extsize %u nextents32 %u nextents16 %u forkoff %u aformat %u flags 0x%x gen 0x%x flags2 0x%llx cowextsize %u", MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, __entry->mode, @@ -1249,8 +1249,8 @@ DECLARE_EVENT_CLASS(xrep_dinode_class, __entry->size, __entry->nblocks, __entry->extsize, - __entry->nextents, - __entry->anextents, + __entry->nextents32, + __entry->nextents16, __entry->forkoff, __entry->aformat, __entry->flags, diff --git a/fs/xfs/xfs_inode_item.c b/fs/xfs/xfs_inode_item.c index 35de30849fcc..f54ce7468ba1 100644 --- a/fs/xfs/xfs_inode_item.c +++ b/fs/xfs/xfs_inode_item.c @@ -385,8 +385,8 @@ xfs_inode_to_log_dinode( to->di_size = ip->i_disk_size; to->di_nblocks = ip->i_nblocks; to->di_extsize = ip->i_extsize; - to->di_nextents = xfs_ifork_nextents(&ip->i_df); - to->di_anextents = xfs_ifork_nextents(ip->i_afp); + to->di_nextents32 = xfs_ifork_nextents(&ip->i_df); + to->di_nextents16 = xfs_ifork_nextents(ip->i_afp); to->di_forkoff = ip->i_forkoff; to->di_aformat = xfs_ifork_format(ip->i_afp); to->di_flags = ip->i_diflags; diff --git a/fs/xfs/xfs_inode_item_recover.c b/fs/xfs/xfs_inode_item_recover.c index 7b79518b6c20..40af9d1265c7 100644 --- a/fs/xfs/xfs_inode_item_recover.c +++ b/fs/xfs/xfs_inode_item_recover.c @@ -166,8 +166,8 @@ xfs_log_dinode_to_disk( to->di_size = cpu_to_be64(from->di_size); to->di_nblocks = cpu_to_be64(from->di_nblocks); to->di_extsize = cpu_to_be32(from->di_extsize); - to->di_nextents = cpu_to_be32(from->di_nextents); - to->di_anextents = cpu_to_be16(from->di_anextents); + to->di_nextents32 = cpu_to_be32(from->di_nextents32); + to->di_nextents16 = cpu_to_be16(from->di_nextents16); to->di_forkoff = from->di_forkoff; to->di_aformat = from->di_aformat; to->di_dmevmask = cpu_to_be32(from->di_dmevmask); @@ -332,7 +332,7 @@ xlog_recover_inode_commit_pass2( goto out_release; } } - if (unlikely(ldip->di_nextents + ldip->di_anextents > ldip->di_nblocks)){ + if (unlikely(ldip->di_nextents32 + ldip->di_nextents16 > ldip->di_nblocks)) { XFS_CORRUPTION_ERROR("xlog_recover_inode_pass2(5)", XFS_ERRLEVEL_LOW, mp, ldip, sizeof(*ldip)); @@ -340,7 +340,7 @@ xlog_recover_inode_commit_pass2( "%s: Bad inode log record, rec ptr "PTR_FMT", dino ptr "PTR_FMT", " "dino bp "PTR_FMT", ino %Ld, total extents = %d, nblocks = %Ld", __func__, item, dip, bp, in_f->ilf_ino, - ldip->di_nextents + ldip->di_anextents, + ldip->di_nextents32 + ldip->di_nextents16, ldip->di_nblocks); error = -EFSCORRUPTED; goto out_release; From patchwork Mon Jul 26 11:45:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12399309 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10795C4320A for ; Mon, 26 Jul 2021 11:46:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EDEB360238 for ; Mon, 26 Jul 2021 11:46:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233568AbhGZLFj (ORCPT ); Mon, 26 Jul 2021 07:05:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233589AbhGZLFi (ORCPT ); Mon, 26 Jul 2021 07:05:38 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77C34C061760 for ; Mon, 26 Jul 2021 04:46:06 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id ca5so134669pjb.5 for ; Mon, 26 Jul 2021 04:46:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rH5AlrKnAvQHjsk3yhTjD6OevEzHh93UPQA+LPt9xaM=; b=UY6VQh68PgaX5BJ8SrXbt9xE7/Di8v8pKc8F5Yh0L7nuoJ2CINHQacuxU3HbbzV/NI X6RxiQ18RCRwFEvv7bdOG555IooZKQqKMo/kTxB0WIniIsxOYRQkxxCYn9kQrXRMi7VL XeggZp5BHgisZB/0zohyW9C1mQbNG6VniAsl4DerT/WWU85drxHaZiEQp12Ye+Ar0dXQ RblU99BOhQRcKxEs9SGt7O4RjuA7a56fC5ljtEAQEAdi1rC43kvBwyyehFAPiHJstq9V 1YUe9ymgJJMGJW4KKxZx57Fd4M49cxdt3jTanGqwdMe7oapn9iS6Qecd4PIAJ7hurI6j Ip3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rH5AlrKnAvQHjsk3yhTjD6OevEzHh93UPQA+LPt9xaM=; b=KgIaDEDj6AEDkSTJbSQlLKQXs4XK4OYH3C7qKEEkBN2kDGfk0juRMuM58CXcjAm0Ij OvlQwxI1XmdzKi3Di6XknlC+vF8ye57TI80I87I9HYkYvOHsXGkVEHKy5mAiNlKhLUVA UMC+I5krbNiuTEm2dodJAxWaMVuufVNvDPiJ7tItqoFM10LH2yFgOQRBrH+xNMx33VEt E073dO9tKUaodnhSjuVNuoJ4JW6CEw/hkcl//pytql+449qjK2F8b/ha14klS93h0hPF 4S07HLOscuwgWLP/6mNHlx2wQOtgLTpsgLGMUJMVgeRpW068DZMl2jhy/eEKXzNdXABb vvAA== X-Gm-Message-State: AOAM531A1kVYXpMBtwHo4JsVYU3qY/gDkaC0Fgql7vesdB5G4hUJVufW B8f3sA3c9XiazGiSqvX1u9FtUsMNsnQ= X-Google-Smtp-Source: ABdhPJxH6ovHFoz8A9E33XPqw7T85Fp8BwTgEOvPOQznwyZ+DXPa4nKYZbsn+wfIBtHfTSJK+m5TBg== X-Received: by 2002:a17:90b:1a92:: with SMTP id ng18mr17090886pjb.86.1627299965943; Mon, 26 Jul 2021 04:46:05 -0700 (PDT) Received: from localhost.localdomain ([122.179.41.55]) by smtp.gmail.com with ESMTPSA id k8sm50833919pgr.91.2021.07.26.04.46.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 04:46:05 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , djwong@kernel.org Subject: [PATCH V2 08/12] xfs: Promote xfs_extnum_t and xfs_aextnum_t to 64 and 32-bits respectively Date: Mon, 26 Jul 2021 17:15:37 +0530 Message-Id: <20210726114541.24898-9-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210726114541.24898-1-chandanrlinux@gmail.com> References: <20210726114541.24898-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org A future commit will introduce a 64-bit on-disk data extent counter and a 32-bit on-disk attr extent counter. This commit promotes xfs_extnum_t and xfs_aextnum_t to 64 and 32-bits in order to correctly handle in-core versions of these quantities. Signed-off-by: Chandan Babu R Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_bmap.c | 2 +- fs/xfs/libxfs/xfs_inode_fork.c | 2 +- fs/xfs/libxfs/xfs_types.h | 4 ++-- fs/xfs/scrub/attr_repair.c | 2 +- fs/xfs/scrub/trace.h | 2 +- fs/xfs/xfs_inode.c | 4 ++-- fs/xfs/xfs_trace.h | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index e5d243fd187d..a27d57ea301c 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -472,7 +472,7 @@ xfs_bmap_check_leaf_extents( if (bp_release) xfs_trans_brelse(NULL, bp); error_norelse: - xfs_warn(mp, "%s: BAD after btree leaves for %d extents", + xfs_warn(mp, "%s: BAD after btree leaves for %llu extents", __func__, i); xfs_err(mp, "%s: CORRUPTED BTREE OR SOMETHING", __func__); xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE); diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index 7f7ffe29436d..336eee69703c 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.c +++ b/fs/xfs/libxfs/xfs_inode_fork.c @@ -126,7 +126,7 @@ xfs_iformat_extents( * we just bail out rather than crash in kmem_alloc() or memcpy() below. */ if (unlikely(size < 0 || size > XFS_DFORK_SIZE(dip, mp, whichfork))) { - xfs_warn(ip->i_mount, "corrupt inode %Lu ((a)extents = %d).", + xfs_warn(ip->i_mount, "corrupt inode %llu ((a)extents = %llu).", (unsigned long long) ip->i_ino, nex); xfs_inode_verifier_error(ip, -EFSCORRUPTED, "xfs_iformat_extents(1)", dip, sizeof(*dip), diff --git a/fs/xfs/libxfs/xfs_types.h b/fs/xfs/libxfs/xfs_types.h index 8908346b1deb..584fa61e338e 100644 --- a/fs/xfs/libxfs/xfs_types.h +++ b/fs/xfs/libxfs/xfs_types.h @@ -12,8 +12,8 @@ typedef uint32_t xfs_agblock_t; /* blockno in alloc. group */ typedef uint32_t xfs_agino_t; /* inode # within allocation grp */ typedef uint32_t xfs_extlen_t; /* extent length in blocks */ typedef uint32_t xfs_agnumber_t; /* allocation group number */ -typedef int32_t xfs_extnum_t; /* # of extents in a file */ -typedef int16_t xfs_aextnum_t; /* # extents in an attribute fork */ +typedef uint64_t xfs_extnum_t; /* # of extents in a file */ +typedef uint32_t xfs_aextnum_t; /* # extents in an attribute fork */ typedef int64_t xfs_fsize_t; /* bytes in a file */ typedef uint64_t xfs_ufsize_t; /* unsigned bytes in a file */ diff --git a/fs/xfs/scrub/attr_repair.c b/fs/xfs/scrub/attr_repair.c index 7d92195d286b..aad4b269949d 100644 --- a/fs/xfs/scrub/attr_repair.c +++ b/fs/xfs/scrub/attr_repair.c @@ -769,7 +769,7 @@ xrep_xattr_fork_remove( unsigned int i = 0; xfs_emerg(sc->mp, - "inode 0x%llx attr fork still has %u attr extents, format %d?!", + "inode 0x%llx attr fork still has %llu attr extents, format %d?!", ip->i_ino, ifp->if_nextents, ifp->if_format); for_each_xfs_iext(ifp, &icur, &irec) { xfs_err(sc->mp, "[%u]: startoff %llu startblock %llu blockcount %llu state %u", i++, irec.br_startoff, irec.br_startblock, irec.br_blockcount, irec.br_state); diff --git a/fs/xfs/scrub/trace.h b/fs/xfs/scrub/trace.h index a0303f692e52..f9be7812c8ce 100644 --- a/fs/xfs/scrub/trace.h +++ b/fs/xfs/scrub/trace.h @@ -1363,7 +1363,7 @@ TRACE_EVENT(xrep_dinode_count_rmaps, __entry->attr_extents = attr_extents; __entry->block0 = block0; ), - TP_printk("dev %d:%d ino 0x%llx dblocks %llu rtblocks %llu ablocks %llu dextents %u rtextents %u aextents %u block0 %llu", + TP_printk("dev %d:%d ino 0x%llx dblocks %llu rtblocks %llu ablocks %llu dextents %llu rtextents %llu aextents %u block0 %llu", MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, __entry->data_blocks, diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index f152f6dace0c..4070fb01350c 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -2510,8 +2510,8 @@ xfs_iflush( if (XFS_TEST_ERROR(ip->i_df.if_nextents + xfs_ifork_nextents(ip->i_afp) > ip->i_nblocks, mp, XFS_ERRTAG_IFLUSH_5)) { xfs_alert_tag(mp, XFS_PTAG_IFLUSH, - "%s: detected corrupt incore inode %Lu, " - "total extents = %d, nblocks = %Ld, ptr "PTR_FMT, + "%s: detected corrupt incore inode %llu, " + "total extents = %llu nblocks = %lld, ptr "PTR_FMT, __func__, ip->i_ino, ip->i_df.if_nextents + xfs_ifork_nextents(ip->i_afp), ip->i_nblocks, ip); diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h index 5ed11f894f79..af426b9824db 100644 --- a/fs/xfs/xfs_trace.h +++ b/fs/xfs/xfs_trace.h @@ -2351,7 +2351,7 @@ DECLARE_EVENT_CLASS(xfs_swap_extent_class, __entry->broot_size = ip->i_df.if_broot_bytes; __entry->fork_off = XFS_IFORK_BOFF(ip); ), - TP_printk("dev %d:%d ino 0x%llx (%s), %s format, num_extents %d, " + TP_printk("dev %d:%d ino 0x%llx (%s), %s format, num_extents %llu, " "broot size %d, fork offset %d", MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, @@ -4588,7 +4588,7 @@ TRACE_EVENT(xfs_swapext_delta_nextents, __entry->d_nexts1 = d_nexts1; __entry->d_nexts2 = d_nexts2; ), - TP_printk("dev %d:%d ino1 0x%llx nexts %u ino2 0x%llx nexts %u delta1 %lld delta2 %lld", + TP_printk("dev %d:%d ino1 0x%llx nexts %llu ino2 0x%llx nexts %llu delta1 %lld delta2 %lld", MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino1, __entry->nexts1, __entry->ino2, __entry->nexts2, From patchwork Mon Jul 26 11:45:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12399311 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FA7FC4338F for ; Mon, 26 Jul 2021 11:46:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8716A60238 for ; Mon, 26 Jul 2021 11:46:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233671AbhGZLFn (ORCPT ); Mon, 26 Jul 2021 07:05:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233589AbhGZLFk (ORCPT ); Mon, 26 Jul 2021 07:05:40 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22CDEC061757 for ; Mon, 26 Jul 2021 04:46:08 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id mt6so12541201pjb.1 for ; Mon, 26 Jul 2021 04:46:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+sNe0biOTzrw8FH/FH+7krQPI3MEAik336cuQ1PpaBU=; b=o+RrJ1EcRK/kr/Ni7noL1i/HVVUUp50/Q6SSGEaLO68YGw24/YLDPHJJLDmSdadq6F +rGduVV0egO3oDh7MxgTHmbsKTMGfibeYjryFxqyx91dSocLuCD+xp4IzHeqbfc+PEXd 0e7ECo2arJnZWWcgbxEWV70qqPGYyg63v5Xc+SbsRx4kZeTVblCZVuUSbqiPquVsP5ac wgl0M4M+jdr8VmYeYNlcXQsjcsSH7s46/R3IjYpltkMvNuXtPSqrt3u48Scl1FWHtkf3 OEU2M93LRrxIH6Lua5sB9bWD2v6VXUzSuwnsQDn9L1HqfWOjLGCHwCioXi9+1moA8Xub Vf0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+sNe0biOTzrw8FH/FH+7krQPI3MEAik336cuQ1PpaBU=; b=ejQVJYQ69mA/AQzqJAoj3ETEo5/3FKZvCrwRHdHaQKfUY+HR9+zwQc9Ma7fSs5UBt4 0c3Qslr352Vlunto59d8Q/AT4qasiSWHNlM18hQezP+JI41nJQR8kcWgbRNnd7/55Eek QXpB35UYOggZaovs2D8SaF4LAa67Ss1wc1obZ2Ef0UqkDERxDWPlCrYjbdGlhiDNWSlH M5mTisXTEBt2PqzQR9g0cA3lw74PN+rvhPBBYxy3mtXd4iNQ9J/KSWvDiksE/uxpNV6Z A7SMh+Bt2wrFagb6/VF/yARyG/XaJhhiDprthFQ8mpFKURbLp+2sxsSHtHh3MUDGSxJ/ 8QYA== X-Gm-Message-State: AOAM530WGdQg08mImeyZLaNfuR7VzEx2JFql8zj4QinotSNQqqSjr940 obbXJzocvhdP/tMBjhIUtgVlDzttmdI= X-Google-Smtp-Source: ABdhPJzhT/CJ9don88L8lTuTF4cMA/5pNguX6ZIhBXy3WGDcGDBsA4Qz6k+jP5kVz3jRMZ9DQaUQ/A== X-Received: by 2002:a17:90a:2f62:: with SMTP id s89mr1524586pjd.33.1627299967567; Mon, 26 Jul 2021 04:46:07 -0700 (PDT) Received: from localhost.localdomain ([122.179.41.55]) by smtp.gmail.com with ESMTPSA id k8sm50833919pgr.91.2021.07.26.04.46.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 04:46:07 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , djwong@kernel.org Subject: [PATCH V2 09/12] xfs: Rename XFS_IOC_BULKSTAT to XFS_IOC_BULKSTAT_V5 Date: Mon, 26 Jul 2021 17:15:38 +0530 Message-Id: <20210726114541.24898-10-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210726114541.24898-1-chandanrlinux@gmail.com> References: <20210726114541.24898-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit renames XFS_IOC_BULKSTAT to XFS_IOC_BULKSTAT_V5 to allow a future commit to extend bulkstat facility to support 64-bit extent counters. To this end, this commit also renames xfs_bulkstat->bs_extents field to xfs_bulkstat->bs_extents32. Signed-off-by: Chandan Babu R Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_fs.h | 4 ++-- fs/xfs/xfs_ioctl.c | 27 ++++++++++++++++++++++----- fs/xfs/xfs_ioctl32.c | 7 +++++++ fs/xfs/xfs_itable.c | 4 ++-- fs/xfs/xfs_itable.h | 1 + 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h index 2594fb647384..d760a969599e 100644 --- a/fs/xfs/libxfs/xfs_fs.h +++ b/fs/xfs/libxfs/xfs_fs.h @@ -394,7 +394,7 @@ struct xfs_bulkstat { uint32_t bs_extsize_blks; /* extent size hint, blocks */ uint32_t bs_nlink; /* number of links */ - uint32_t bs_extents; /* number of extents */ + uint32_t bs_extents32; /* number of extents */ uint32_t bs_aextents; /* attribute number of extents */ uint16_t bs_version; /* structure version */ uint16_t bs_forkoff; /* inode fork offset in bytes */ @@ -853,7 +853,7 @@ struct xfs_scrub_metadata { #define XFS_IOC_FSGEOMETRY_V4 _IOR ('X', 124, struct xfs_fsop_geom_v4) #define XFS_IOC_GOINGDOWN _IOR ('X', 125, uint32_t) #define XFS_IOC_FSGEOMETRY _IOR ('X', 126, struct xfs_fsop_geom) -#define XFS_IOC_BULKSTAT _IOR ('X', 127, struct xfs_bulkstat_req) +#define XFS_IOC_BULKSTAT_V5 _IOR ('X', 127, struct xfs_bulkstat_req) #define XFS_IOC_INUMBERS _IOR ('X', 128, struct xfs_inumbers_req) /* FIEXCHANGE_RANGE ----------- hoisted 129 */ /* XFS_IOC_GETFSUUID ---------- deprecated 140 */ diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index 2da90f81e6e3..85f45340cb16 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -715,6 +715,8 @@ xfs_fsbulkstat_one_fmt( { struct xfs_bstat bs1; + ASSERT(breq->version == XFS_BULKSTAT_VERSION_V1); + xfs_bulkstat_to_bstat(breq->mp, &bs1, bstat); if (copy_to_user(breq->ubuffer, &bs1, sizeof(bs1))) return -EFAULT; @@ -728,6 +730,8 @@ xfs_fsinumbers_fmt( { struct xfs_inogrp ig1; + ASSERT(breq->version == XFS_INUMBERS_VERSION_V1); + xfs_inumbers_to_inogrp(&ig1, igrp); if (copy_to_user(breq->ubuffer, &ig1, sizeof(struct xfs_inogrp))) return -EFAULT; @@ -787,14 +791,17 @@ xfs_ioc_fsbulkstat( */ if (cmd == XFS_IOC_FSINUMBERS) { breq.startino = lastino ? lastino + 1 : 0; + breq.version = XFS_INUMBERS_VERSION_V1; error = xfs_inumbers(&breq, xfs_fsinumbers_fmt); lastino = breq.startino - 1; } else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE) { breq.startino = lastino; breq.icount = 1; + breq.version = XFS_BULKSTAT_VERSION_V1; error = xfs_bulkstat_one(&breq, xfs_fsbulkstat_one_fmt); } else { /* XFS_IOC_FSBULKSTAT */ breq.startino = lastino ? lastino + 1 : 0; + breq.version = XFS_BULKSTAT_VERSION_V1; error = xfs_bulkstat(&breq, xfs_fsbulkstat_one_fmt); lastino = breq.startino - 1; } @@ -819,6 +826,8 @@ xfs_bulkstat_fmt( struct xfs_ibulk *breq, const struct xfs_bulkstat *bstat) { + ASSERT(breq->version == XFS_BULKSTAT_VERSION_V5); + if (copy_to_user(breq->ubuffer, bstat, sizeof(struct xfs_bulkstat))) return -EFAULT; return xfs_ibulk_advance(breq, sizeof(struct xfs_bulkstat)); @@ -918,13 +927,15 @@ STATIC int xfs_ioc_bulkstat( struct file *file, unsigned int cmd, - struct xfs_bulkstat_req __user *arg) + struct xfs_bulkstat_req __user *arg, + int version) { struct xfs_mount *mp = XFS_I(file_inode(file))->i_mount; struct xfs_bulk_ireq hdr; struct xfs_ibulk breq = { .mp = mp, .mnt_userns = file_mnt_user_ns(file), + .version = version, }; int error; @@ -960,6 +971,8 @@ xfs_inumbers_fmt( struct xfs_ibulk *breq, const struct xfs_inumbers *igrp) { + ASSERT(breq->version == XFS_INUMBERS_VERSION_V5); + if (copy_to_user(breq->ubuffer, igrp, sizeof(struct xfs_inumbers))) return -EFAULT; return xfs_ibulk_advance(breq, sizeof(struct xfs_inumbers)); @@ -970,11 +983,13 @@ STATIC int xfs_ioc_inumbers( struct xfs_mount *mp, unsigned int cmd, - struct xfs_inumbers_req __user *arg) + struct xfs_inumbers_req __user *arg, + int version) { struct xfs_bulk_ireq hdr; struct xfs_ibulk breq = { .mp = mp, + .version = version, }; int error; @@ -1882,10 +1897,12 @@ xfs_file_ioctl( case XFS_IOC_FSINUMBERS: return xfs_ioc_fsbulkstat(filp, cmd, arg); - case XFS_IOC_BULKSTAT: - return xfs_ioc_bulkstat(filp, cmd, arg); + case XFS_IOC_BULKSTAT_V5: + return xfs_ioc_bulkstat(filp, cmd, arg, + XFS_BULKSTAT_VERSION_V5); case XFS_IOC_INUMBERS: - return xfs_ioc_inumbers(mp, cmd, arg); + return xfs_ioc_inumbers(mp, cmd, arg, + XFS_INUMBERS_VERSION_V5); case XFS_IOC_FSGEOMETRY_V1: return xfs_ioc_fsgeometry(mp, arg, 3); diff --git a/fs/xfs/xfs_ioctl32.c b/fs/xfs/xfs_ioctl32.c index bef19060f4aa..d9a7abc209b5 100644 --- a/fs/xfs/xfs_ioctl32.c +++ b/fs/xfs/xfs_ioctl32.c @@ -88,6 +88,8 @@ xfs_fsinumbers_fmt_compat( struct xfs_inogrp ig1; struct xfs_inogrp *igrp = &ig1; + ASSERT(breq->version == XFS_INUMBERS_VERSION_V1); + xfs_inumbers_to_inogrp(&ig1, ig); if (put_user(igrp->xi_startino, &p32->xi_startino) || @@ -177,6 +179,8 @@ xfs_fsbulkstat_one_fmt_compat( struct xfs_bstat bs1; struct xfs_bstat *buffer = &bs1; + ASSERT(breq->version == XFS_BULKSTAT_VERSION_V1); + xfs_bulkstat_to_bstat(breq->mp, &bs1, bstat); if (put_user(buffer->bs_ino, &p32->bs_ino) || @@ -293,15 +297,18 @@ xfs_compat_ioc_fsbulkstat( */ if (cmd == XFS_IOC_FSINUMBERS_32) { breq.startino = lastino ? lastino + 1 : 0; + breq.version = XFS_INUMBERS_VERSION_V1; error = xfs_inumbers(&breq, inumbers_func); lastino = breq.startino - 1; } else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE_32) { breq.startino = lastino; breq.icount = 1; + breq.version = XFS_BULKSTAT_VERSION_V1; error = xfs_bulkstat_one(&breq, bs_one_func); lastino = breq.startino; } else if (cmd == XFS_IOC_FSBULKSTAT_32) { breq.startino = lastino ? lastino + 1 : 0; + breq.version = XFS_BULKSTAT_VERSION_V1; error = xfs_bulkstat(&breq, bs_one_func); lastino = breq.startino - 1; } else { diff --git a/fs/xfs/xfs_itable.c b/fs/xfs/xfs_itable.c index 65c194cdea79..f0daa65e61ff 100644 --- a/fs/xfs/xfs_itable.c +++ b/fs/xfs/xfs_itable.c @@ -134,7 +134,7 @@ xfs_bulkstat_one_int( buf->bs_xflags = xfs_ip2xflags(ip); buf->bs_extsize_blks = ip->i_extsize; - buf->bs_extents = xfs_ifork_nextents(&ip->i_df); + buf->bs_extents32 = xfs_ifork_nextents(&ip->i_df); xfs_bulkstat_health(ip, buf); buf->bs_aextents = xfs_ifork_nextents(ip->i_afp); buf->bs_forkoff = XFS_IFORK_BOFF(ip); @@ -356,7 +356,7 @@ xfs_bulkstat_to_bstat( bs1->bs_blocks = bstat->bs_blocks; bs1->bs_xflags = bstat->bs_xflags; bs1->bs_extsize = XFS_FSB_TO_B(mp, bstat->bs_extsize_blks); - bs1->bs_extents = bstat->bs_extents; + bs1->bs_extents = bstat->bs_extents32; bs1->bs_gen = bstat->bs_gen; bs1->bs_projid_lo = bstat->bs_projectid & 0xFFFF; bs1->bs_forkoff = bstat->bs_forkoff; diff --git a/fs/xfs/xfs_itable.h b/fs/xfs/xfs_itable.h index f5a13f69883a..ee4d8d0461ca 100644 --- a/fs/xfs/xfs_itable.h +++ b/fs/xfs/xfs_itable.h @@ -14,6 +14,7 @@ struct xfs_ibulk { unsigned int icount; /* number of elements in ubuffer */ unsigned int ocount; /* number of records returned */ unsigned int flags; /* see XFS_IBULK_FLAG_* */ + int version; /* structure version to be returned */ }; /* Only iterate within the same AG as startino */ From patchwork Mon Jul 26 11:45:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12399317 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E50B4C4338F for ; Mon, 26 Jul 2021 11:46:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE03C60238 for ; Mon, 26 Jul 2021 11:46:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233656AbhGZLFr (ORCPT ); Mon, 26 Jul 2021 07:05:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233669AbhGZLFn (ORCPT ); Mon, 26 Jul 2021 07:05:43 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A996AC061760 for ; Mon, 26 Jul 2021 04:46:09 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id l19so12605393pjz.0 for ; Mon, 26 Jul 2021 04:46:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=znSA5RStZM3Z97yY0DOr1Pxi36RUJ6xfhLKiW9+thY0=; b=fEWci3OQ9eUmyjuz8wH9mvRl5LEzuMo2tMqRCNl4GAvaGosZ7iV6wLsvswnOKGu4mL hlQ305B3NSM2l0fgM9ymsjd4QH4NKyV92NeRU6iJ3NOTdGGPiRJX1fOPTYBFHf2l3HDQ popPlXmV8jCDf2Z7sCfLW7yMru0SgLcD32/FUc7q2L1ughI6iz7/iv4FRQYg1TTOu4HW J2v01qc8MnAzkOIu0OnXBCsgp/m6Fvy/IeOkR3KQz21Uppx9FeBotPbGTSPVV8kgXYXB R/SyZMz96mXqTsk9WpyQZGn10bIbfdJjO0crkuNv+QkoQU+EvD+b4YQw33NKsYPekMqO JS4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=znSA5RStZM3Z97yY0DOr1Pxi36RUJ6xfhLKiW9+thY0=; b=p1vMedu4G9eadkXGcffdYrAYSPes4MUGVXpRuQfRIsHCuDOYDA1Sz0lwbtGAuAOgGe Vi3Fm0kHapxnVEnCPWy/P29f3UcIH9H7v61yDqSntR8gD9bzVCigOTt/zz48L/2lDx2l KCYpP5dCd1/SONKJTRn0L+ek1SCfMHwKel02JjajHLWrTP+ai+V4mHDPvXKZYL8OgN7t yQfDO7TNwZT1W22QzvXjfAolyvARDl5NXM5Lfoh/XuzP5JGZzG55byC4Pjk+EyB9BtWA vJ4vrODLaV2ZDqVzR7cfptCCmU44TgktKFeWC6Y88/atKVwziqoVgzJJRfWXYdvCMgWd K6yQ== X-Gm-Message-State: AOAM530EJomSJQFQxeWlHbZpR8/VDU2OCY3cY+TQoKXxBlw7YOJS7fvH kiQ6K+KBsY3TagPhpIg+YtZ75K7wKqw= X-Google-Smtp-Source: ABdhPJyVUS7YeowaO8CZwqB8T54BCP67SkjE7IfqGz7EqFRR7iVLDNP9Wp3PJVOFMabwBOudzDt7Iw== X-Received: by 2002:aa7:8b07:0:b029:2f7:d38e:ff1 with SMTP id f7-20020aa78b070000b02902f7d38e0ff1mr17825578pfd.72.1627299969143; Mon, 26 Jul 2021 04:46:09 -0700 (PDT) Received: from localhost.localdomain ([122.179.41.55]) by smtp.gmail.com with ESMTPSA id k8sm50833919pgr.91.2021.07.26.04.46.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 04:46:08 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , djwong@kernel.org Subject: [PATCH V2 10/12] xfs: Enable bulkstat ioctl to support 64-bit extent counters Date: Mon, 26 Jul 2021 17:15:39 +0530 Message-Id: <20210726114541.24898-11-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210726114541.24898-1-chandanrlinux@gmail.com> References: <20210726114541.24898-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit adds XFS_IOC_BULKSTAT_V6 to support 64-bit inode extent counters. The new field xfs_bulkstat->bs_extents64 is added to hold data extent count for filesystems supporting 64-bit data extent counters. However, the accessibility of this ioctl is deferred to a future commit which actually adds support for 64-bit data extent counter. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_fs.h | 6 ++++-- fs/xfs/xfs_ioctl.c | 5 +++-- fs/xfs/xfs_itable.c | 26 +++++++++++++++++++++++--- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h index d760a969599e..756be4ff5996 100644 --- a/fs/xfs/libxfs/xfs_fs.h +++ b/fs/xfs/libxfs/xfs_fs.h @@ -394,7 +394,7 @@ struct xfs_bulkstat { uint32_t bs_extsize_blks; /* extent size hint, blocks */ uint32_t bs_nlink; /* number of links */ - uint32_t bs_extents32; /* number of extents */ + uint32_t bs_extents32; /* number of extents; v5 only */ uint32_t bs_aextents; /* attribute number of extents */ uint16_t bs_version; /* structure version */ uint16_t bs_forkoff; /* inode fork offset in bytes */ @@ -403,12 +403,14 @@ struct xfs_bulkstat { uint16_t bs_checked; /* checked inode metadata */ uint16_t bs_mode; /* type and mode */ uint16_t bs_pad2; /* zeroed */ + uint64_t bs_extents64; /* number of extents; v6 only */ - uint64_t bs_pad[7]; /* zeroed */ + uint64_t bs_pad[6]; /* zeroed */ }; #define XFS_BULKSTAT_VERSION_V1 (1) #define XFS_BULKSTAT_VERSION_V5 (5) +#define XFS_BULKSTAT_VERSION_V6 (6) /* bs_sick flags */ #define XFS_BS_SICK_INODE (1 << 0) /* inode core */ diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index 85f45340cb16..19964b394dc4 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -826,7 +826,8 @@ xfs_bulkstat_fmt( struct xfs_ibulk *breq, const struct xfs_bulkstat *bstat) { - ASSERT(breq->version == XFS_BULKSTAT_VERSION_V5); + ASSERT(breq->version == XFS_BULKSTAT_VERSION_V5 || + breq->version == XFS_BULKSTAT_VERSION_V6); if (copy_to_user(breq->ubuffer, bstat, sizeof(struct xfs_bulkstat))) return -EFAULT; @@ -922,7 +923,7 @@ xfs_bulk_ireq_teardown( hdr->ocount = breq->ocount; } -/* Handle the v5 bulkstat ioctl. */ +/* Handle the v5/v6 bulkstat ioctl. */ STATIC int xfs_ioc_bulkstat( struct file *file, diff --git a/fs/xfs/xfs_itable.c b/fs/xfs/xfs_itable.c index f0daa65e61ff..8493870a0a87 100644 --- a/fs/xfs/xfs_itable.c +++ b/fs/xfs/xfs_itable.c @@ -74,6 +74,7 @@ xfs_bulkstat_one_int( struct xfs_inode *ip; /* incore inode pointer */ struct inode *inode; struct xfs_bulkstat *buf = bc->buf; + xfs_extnum_t nextents; int error = -EINVAL; error = xfs_iget(mp, tp, ino, @@ -95,7 +96,12 @@ xfs_bulkstat_one_int( buf->bs_gen = inode->i_generation; buf->bs_mode = inode->i_mode & S_IFMT; xfs_bulkstat_health(ip, buf); - buf->bs_version = XFS_BULKSTAT_VERSION_V5; + + if (bc->breq->version != XFS_BULKSTAT_VERSION_V6) + buf->bs_version = XFS_BULKSTAT_VERSION_V5; + else + buf->bs_version = XFS_BULKSTAT_VERSION_V6; + xfs_iunlock(ip, XFS_ILOCK_SHARED); xfs_irele(ip); @@ -134,11 +140,25 @@ xfs_bulkstat_one_int( buf->bs_xflags = xfs_ip2xflags(ip); buf->bs_extsize_blks = ip->i_extsize; - buf->bs_extents32 = xfs_ifork_nextents(&ip->i_df); + + nextents = xfs_ifork_nextents(&ip->i_df); + if (bc->breq->version != XFS_BULKSTAT_VERSION_V6) { + if (nextents > XFS_IFORK_EXTCNT_MAXS32) { + xfs_iunlock(ip, XFS_ILOCK_SHARED); + xfs_irele(ip); + error = -EINVAL; + goto out_advance; + } + buf->bs_extents32 = nextents; + buf->bs_version = XFS_BULKSTAT_VERSION_V5; + } else { + buf->bs_extents64 = nextents; + buf->bs_version = XFS_BULKSTAT_VERSION_V6; + } + xfs_bulkstat_health(ip, buf); buf->bs_aextents = xfs_ifork_nextents(ip->i_afp); buf->bs_forkoff = XFS_IFORK_BOFF(ip); - buf->bs_version = XFS_BULKSTAT_VERSION_V5; if (xfs_sb_version_has_v3inode(&mp->m_sb)) { buf->bs_btime = ip->i_crtime.tv_sec; From patchwork Mon Jul 26 11:45:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12399315 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A4FAC432BE for ; Mon, 26 Jul 2021 11:46:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 43ED8601FD for ; Mon, 26 Jul 2021 11:46:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233665AbhGZLFq (ORCPT ); Mon, 26 Jul 2021 07:05:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233666AbhGZLFm (ORCPT ); Mon, 26 Jul 2021 07:05:42 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C68A3C0613C1 for ; Mon, 26 Jul 2021 04:46:11 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id l19so12605496pjz.0 for ; Mon, 26 Jul 2021 04:46:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4fZIvyob7RfieDxGSP0AV2zfWaAq+JJb0XiBbgQyPqQ=; b=QbFHVfsKaIX0sLWpeBOINI7oYhwESoyQhzMM1XRTlkz4CyeLEXrxqyAtStm022pkaW bEgwCj83mZ3Z6LTtD/bCJVdYuF0kbqdpetQLTuq4cbc6KlLaOxzQOSFH2jQuCzhAbQN2 Ebmk0PgXta5o2OXzoD1/hfNzeLMHwc9MtOF+OJqLcOaNLci+VaUemlW1BSFc6S0Yy3Wg otSPtGJK4yfNL90PlQVGVsPS3RqSd6/PtUkonJb5eJ22xmhuNS+tOp46iK3I6j3CoBey aNK82L4IiNUuZq+XPv/ITJJB0U28agYocdv0z4h+ABiY9ZKEMvhyTZRjgdv8+CDXgsUp fmDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4fZIvyob7RfieDxGSP0AV2zfWaAq+JJb0XiBbgQyPqQ=; b=HxOS8YG9Kd5QKQlpzl9qzLXGaFFYZcuadnY0zRz2qrLEoSzOQ8bMeB+DyF0AAIv8Sh axpyF0ERDQw16FDD+c2EEUEC9/ZLnm0HwNa0s1uY1Xm4InWhzwwR5A7vzpL3U3TADqK0 vL8M9zNAKW0kxaQpCTZvyKWrr3NVgxz7XnfhaOmtqgR79+LlMPTUxNL0NHrHR16yRVfV yD+AXvFNNParIFmFEwTcTX1YdilC3ke7azkHUgAoTg17TY7CmA/CrfhP+S+LjIFsJpp8 WcZteSm1SUvZRelixdoxL8JtLERXBPLPyTELS6fr78irVCVoqIeuOlwppIfor4+TpMvo hmHA== X-Gm-Message-State: AOAM533vRadgmM4kRpxjxx0Pu17VcUM0RMlQJPMVXR04HL/F+ORa0hW5 s29ZStfySBrEKLKanBdDborPDY2cy1A= X-Google-Smtp-Source: ABdhPJwAE3fPMtyAtk9ygCSDPdRnc51nXOGjMJ7Z0+ntcFwf+GANQWnmUiTw9OSbteRxhOXx44nzvQ== X-Received: by 2002:a17:902:d389:b029:12b:b3cc:457c with SMTP id e9-20020a170902d389b029012bb3cc457cmr14175514pld.31.1627299970965; Mon, 26 Jul 2021 04:46:10 -0700 (PDT) Received: from localhost.localdomain ([122.179.41.55]) by smtp.gmail.com with ESMTPSA id k8sm50833919pgr.91.2021.07.26.04.46.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 04:46:10 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , djwong@kernel.org Subject: [PATCH V2 11/12] xfs: Extend per-inode extent counter widths Date: Mon, 26 Jul 2021 17:15:40 +0530 Message-Id: <20210726114541.24898-12-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210726114541.24898-1-chandanrlinux@gmail.com> References: <20210726114541.24898-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit adds a new 64-bit per-inode data extent counter. However the maximum number of extents that a data fork can hold is limited to 2^48 extents. This feature is available only when XFS_SB_FEAT_INCOMPAT_EXTCOUNT_64BIT feature bit is enabled on the filesystem. Also, enabling this feature bit causes attr fork extent counter to use the 32-bit extent counter that was previously used to hold the data fork extent counter. This implies that the attr fork can now occupy a maximum of 2^32 extents. This commit also exposes the newly introduced XFS_IOC_BULKSTAT_V6 ioctl interface to user space. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_bmap.c | 8 +++----- fs/xfs/libxfs/xfs_format.h | 27 ++++++++++++++++++++++++--- fs/xfs/libxfs/xfs_fs.h | 1 + fs/xfs/libxfs/xfs_inode_buf.c | 28 ++++++++++++++++++++++++---- fs/xfs/libxfs/xfs_inode_fork.h | 22 +++++++++++++++++----- fs/xfs/libxfs/xfs_log_format.h | 3 ++- fs/xfs/scrub/inode_repair.c | 11 +++++++++-- fs/xfs/xfs_inode.c | 2 +- fs/xfs/xfs_inode_item.c | 15 +++++++++++++-- fs/xfs/xfs_inode_item_recover.c | 25 +++++++++++++++++++------ fs/xfs/xfs_ioctl.c | 3 +++ 11 files changed, 116 insertions(+), 29 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index a27d57ea301c..e05898c9acbc 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -54,18 +54,16 @@ xfs_bmap_compute_maxlevels( int whichfork) /* data or attr fork */ { xfs_extnum_t maxleafents; /* max leaf entries possible */ + uint64_t maxblocks; /* max blocks at this level */ int level; /* btree level */ - uint maxblocks; /* max blocks at this level */ int maxrootrecs; /* max records in root block */ int minleafrecs; /* min records in leaf block */ int minnoderecs; /* min records in node block */ int sz; /* root block size */ /* - * The maximum number of extents in a file, hence the maximum number of - * leaf entries, is controlled by the size of the on-disk extent count, - * either a signed 32-bit number for the data fork, or a signed 16-bit - * number for the attr fork. + * The maximum number of extents in a fork, hence the maximum number of + * leaf entries, is controlled by the size of the on-disk extent count. * * Note that we can no longer assume that if we are in ATTR1 that the * fork offset of all the inodes will be diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h index 2362cc005cc6..3aa83d75670d 100644 --- a/fs/xfs/libxfs/xfs_format.h +++ b/fs/xfs/libxfs/xfs_format.h @@ -485,13 +485,15 @@ xfs_sb_has_ro_compat_feature( #define XFS_SB_FEAT_INCOMPAT_BIGTIME (1 << 3) /* large timestamps */ #define XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR (1 << 4) /* needs xfs_repair */ #define XFS_SB_FEAT_INCOMPAT_METADIR (1 << 5) /* metadata dir tree */ -#define XFS_SB_FEAT_INCOMPAT_ALL \ +#define XFS_SB_FEAT_INCOMPAT_EXTCOUNT_64BIT (1 << 6) /* 64-bit inode fork extent counter */ +#define XFS_SB_FEAT_INCOMPAT_ALL \ (XFS_SB_FEAT_INCOMPAT_FTYPE| \ XFS_SB_FEAT_INCOMPAT_SPINODES| \ XFS_SB_FEAT_INCOMPAT_META_UUID| \ XFS_SB_FEAT_INCOMPAT_BIGTIME| \ XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR| \ - XFS_SB_FEAT_INCOMPAT_METADIR) + XFS_SB_FEAT_INCOMPAT_METADIR| \ + XFS_SB_FEAT_INCOMPAT_EXTCOUNT_64BIT) #define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL static inline bool @@ -591,6 +593,12 @@ static inline bool xfs_sb_version_hasmetauuid(struct xfs_sb *sbp) (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_META_UUID); } +static inline bool xfs_sb_version_hasextcount_64bit(struct xfs_sb *sbp) +{ + return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) && + (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_EXTCOUNT_64BIT); +} + static inline bool xfs_sb_version_hasrmapbt(struct xfs_sb *sbp) { return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) && @@ -1039,6 +1047,16 @@ typedef struct xfs_dinode { __be64 di_size; /* number of bytes in file */ __be64 di_nblocks; /* # of direct & btree blocks used */ __be32 di_extsize; /* basic/minimum extent size for file */ + + /* + * On a extcnt64bit filesystem, di_nextents64 holds the data fork + * extent count, di_nextents32 holds the attr fork extent count, + * and di_nextents16 must be zero. + * + * Otherwise, di_nextents32 holds the data fork extent count, + * di_nextents16 holds the attr fork extent count, and di_nextents64 + * must be zero. + */ __be32 di_nextents32; /* number of extents in data fork */ __be16 di_nextents16; /* number of extents in attribute fork*/ __u8 di_forkoff; /* attr fork offs, <<3 for 64b align */ @@ -1057,7 +1075,8 @@ typedef struct xfs_dinode { __be64 di_lsn; /* flush sequence */ __be64 di_flags2; /* more random flags */ __be32 di_cowextsize; /* basic cow extent size for file */ - __u8 di_pad2[12]; /* more padding for future expansion */ + __u8 di_pad2[4]; /* more padding for future expansion */ + __be64 di_nextents64; /* fields only written to during inode creation */ xfs_timestamp_t di_crtime; /* time created */ @@ -1113,6 +1132,8 @@ enum xfs_dinode_fmt { * Max values for extlen and disk inode's extent counters. */ #define MAXEXTLEN ((uint32_t)0x1fffff) /* 21 bits */ +#define XFS_IFORK_EXTCNT_MAXU48 ((uint64_t)0xffffffffffff) /* Unsigned 48-bits */ +#define XFS_IFORK_EXTCNT_MAXU32 ((uint32_t)0xffffffff) /* Unsigned 32-bits */ #define XFS_IFORK_EXTCNT_MAXS32 ((int32_t)0x7fffffff) /* Signed 32-bits */ #define XFS_IFORK_EXTCNT_MAXS16 ((int16_t)0x7fff) /* Signed 16-bits */ diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h index 756be4ff5996..57f67445f095 100644 --- a/fs/xfs/libxfs/xfs_fs.h +++ b/fs/xfs/libxfs/xfs_fs.h @@ -858,6 +858,7 @@ struct xfs_scrub_metadata { #define XFS_IOC_BULKSTAT_V5 _IOR ('X', 127, struct xfs_bulkstat_req) #define XFS_IOC_INUMBERS _IOR ('X', 128, struct xfs_inumbers_req) /* FIEXCHANGE_RANGE ----------- hoisted 129 */ +#define XFS_IOC_BULKSTAT_V6 _IOR ('X', 130, struct xfs_bulkstat_req) /* XFS_IOC_GETFSUUID ---------- deprecated 140 */ diff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c index 65d753e16007..28e49394edbb 100644 --- a/fs/xfs/libxfs/xfs_inode_buf.c +++ b/fs/xfs/libxfs/xfs_inode_buf.c @@ -291,6 +291,7 @@ xfs_inode_to_disk( struct xfs_dinode *to, xfs_lsn_t lsn) { + struct xfs_sb *sbp = &ip->i_mount->m_sb; struct inode *inode = VFS_I(ip); to->di_magic = cpu_to_be16(XFS_DINODE_MAGIC); @@ -313,8 +314,6 @@ xfs_inode_to_disk( to->di_size = cpu_to_be64(ip->i_disk_size); to->di_nblocks = cpu_to_be64(ip->i_nblocks); to->di_extsize = cpu_to_be32(ip->i_extsize); - to->di_nextents32 = cpu_to_be32(xfs_ifork_nextents(&ip->i_df)); - to->di_nextents16 = cpu_to_be16(xfs_ifork_nextents(ip->i_afp)); to->di_forkoff = ip->i_forkoff; to->di_aformat = xfs_ifork_format(ip->i_afp); to->di_flags = cpu_to_be16(ip->i_diflags); @@ -334,6 +333,19 @@ xfs_inode_to_disk( to->di_version = 2; to->di_flushiter = cpu_to_be16(ip->i_flushiter); } + + if (xfs_sb_version_hasextcount_64bit(sbp)) { + to->di_nextents64 = cpu_to_be64(xfs_ifork_nextents(&ip->i_df)); + to->di_nextents32 = cpu_to_be32(xfs_ifork_nextents(ip->i_afp)); + /* + * xchk_dinode() passes an uninitialized disk inode. Hence, + * clear di_nextents16 field explicitly. + */ + to->di_nextents16 = cpu_to_be16(0); + } else { + to->di_nextents32 = cpu_to_be32(xfs_ifork_nextents(&ip->i_df)); + to->di_nextents16 = cpu_to_be16(xfs_ifork_nextents(ip->i_afp)); + } } static xfs_failaddr_t @@ -386,14 +398,22 @@ xfs_dfork_nextents( xfs_extnum_t *nextents) { int error = 0; + bool has_64bit_extcnt; + + has_64bit_extcnt = xfs_sb_version_hasextcount_64bit(&mp->m_sb); + + if (has_64bit_extcnt && dip->di_nextents16 != 0) + return -EFSCORRUPTED; switch (whichfork) { case XFS_DATA_FORK: - *nextents = be32_to_cpu(dip->di_nextents32); + *nextents = has_64bit_extcnt ? be64_to_cpu(dip->di_nextents64) + : be32_to_cpu(dip->di_nextents32); break; case XFS_ATTR_FORK: - *nextents = be16_to_cpu(dip->di_nextents16); + *nextents = has_64bit_extcnt ? be32_to_cpu(dip->di_nextents32) + : be16_to_cpu(dip->di_nextents16); break; default: diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index 1eda2163603e..ffdd2abcd73c 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -21,9 +21,9 @@ struct xfs_ifork { void *if_root; /* extent tree root */ char *if_data; /* inline file data */ } if_u1; + xfs_extnum_t if_nextents; /* # of extents in this fork */ short if_broot_bytes; /* bytes allocated for root */ int8_t if_format; /* format of this fork */ - xfs_extnum_t if_nextents; /* # of extents in this fork */ }; /* @@ -135,10 +135,22 @@ static inline int8_t xfs_ifork_format(struct xfs_ifork *ifp) static inline xfs_extnum_t xfs_iext_max(struct xfs_mount *mp, int whichfork) { - if (whichfork == XFS_DATA_FORK || whichfork == XFS_COW_FORK) - return XFS_IFORK_EXTCNT_MAXS32; - else - return XFS_IFORK_EXTCNT_MAXS16; + bool has_64bit_extcnt = xfs_sb_version_hasextcount_64bit(&mp->m_sb); + + switch (whichfork) { + case XFS_DATA_FORK: + case XFS_COW_FORK: + return has_64bit_extcnt ? XFS_IFORK_EXTCNT_MAXU48 + : XFS_IFORK_EXTCNT_MAXS32; + + case XFS_ATTR_FORK: + return has_64bit_extcnt ? XFS_IFORK_EXTCNT_MAXU32 + : XFS_IFORK_EXTCNT_MAXS16; + + default: + ASSERT(0); + return 0; + } } struct xfs_ifork *xfs_ifork_alloc(enum xfs_dinode_fmt format, diff --git a/fs/xfs/libxfs/xfs_log_format.h b/fs/xfs/libxfs/xfs_log_format.h index ca8e4ad8312a..9b5d64708ed1 100644 --- a/fs/xfs/libxfs/xfs_log_format.h +++ b/fs/xfs/libxfs/xfs_log_format.h @@ -420,7 +420,8 @@ struct xfs_log_dinode { xfs_lsn_t di_lsn; /* flush sequence */ uint64_t di_flags2; /* more random flags */ uint32_t di_cowextsize; /* basic cow extent size for file */ - uint8_t di_pad2[12]; /* more padding for future expansion */ + uint8_t di_pad2[4]; /* more padding for future expansion */ + uint64_t di_nextents64; /* higher part of data fork extent count */ /* fields only written to during inode creation */ xfs_log_timestamp_t di_crtime; /* time created */ diff --git a/fs/xfs/scrub/inode_repair.c b/fs/xfs/scrub/inode_repair.c index 4d773a16f886..dde6b700e891 100644 --- a/fs/xfs/scrub/inode_repair.c +++ b/fs/xfs/scrub/inode_repair.c @@ -736,7 +736,10 @@ xrep_dinode_zap_dfork( { trace_xrep_dinode_zap_dfork(sc, dip); - dip->di_nextents32 = 0; + if (xfs_sb_version_hasextcount_64bit(&sc->mp->m_sb)) + dip->di_nextents64 = 0; + else + dip->di_nextents32 = 0; /* Special files always get reset to DEV */ switch (mode & S_IFMT) { @@ -823,7 +826,11 @@ xrep_dinode_zap_afork( trace_xrep_dinode_zap_afork(sc, dip); dip->di_aformat = XFS_DINODE_FMT_EXTENTS; - dip->di_nextents16 = 0; + + if (xfs_sb_version_hasextcount_64bit(&sc->mp->m_sb)) + dip->di_nextents32 = 0; + else + dip->di_nextents16 = 0; dip->di_forkoff = 0; dip->di_mode = cpu_to_be16(mode & ~0777); diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 4070fb01350c..19d525093702 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -2511,7 +2511,7 @@ xfs_iflush( ip->i_nblocks, mp, XFS_ERRTAG_IFLUSH_5)) { xfs_alert_tag(mp, XFS_PTAG_IFLUSH, "%s: detected corrupt incore inode %llu, " - "total extents = %llu nblocks = %lld, ptr "PTR_FMT, + "total extents = %llu, nblocks = %lld, ptr "PTR_FMT, __func__, ip->i_ino, ip->i_df.if_nextents + xfs_ifork_nextents(ip->i_afp), ip->i_nblocks, ip); diff --git a/fs/xfs/xfs_inode_item.c b/fs/xfs/xfs_inode_item.c index f54ce7468ba1..3fa73100484b 100644 --- a/fs/xfs/xfs_inode_item.c +++ b/fs/xfs/xfs_inode_item.c @@ -364,6 +364,7 @@ xfs_inode_to_log_dinode( struct xfs_log_dinode *to, xfs_lsn_t lsn) { + struct xfs_sb *sbp = &ip->i_mount->m_sb; struct inode *inode = VFS_I(ip); to->di_magic = XFS_DINODE_MAGIC; @@ -385,8 +386,6 @@ xfs_inode_to_log_dinode( to->di_size = ip->i_disk_size; to->di_nblocks = ip->i_nblocks; to->di_extsize = ip->i_extsize; - to->di_nextents32 = xfs_ifork_nextents(&ip->i_df); - to->di_nextents16 = xfs_ifork_nextents(ip->i_afp); to->di_forkoff = ip->i_forkoff; to->di_aformat = xfs_ifork_format(ip->i_afp); to->di_flags = ip->i_diflags; @@ -402,6 +401,16 @@ xfs_inode_to_log_dinode( to->di_crtime = xfs_inode_to_log_dinode_ts(ip, ip->i_crtime); to->di_flags2 = ip->i_diflags2; to->di_cowextsize = ip->i_cowextsize; + if (xfs_sb_version_hasextcount_64bit(sbp)) { + to->di_nextents64 = xfs_ifork_nextents(&ip->i_df); + to->di_nextents32 = xfs_ifork_nextents(ip->i_afp); + to->di_nextents16 = 0; + } else { + to->di_nextents64 = 0; + to->di_nextents32 = xfs_ifork_nextents(&ip->i_df); + to->di_nextents16 = xfs_ifork_nextents(ip->i_afp); + } + to->di_ino = ip->i_ino; to->di_lsn = lsn; memset(to->di_pad2, 0, sizeof(to->di_pad2)); @@ -410,6 +419,8 @@ xfs_inode_to_log_dinode( } else { to->di_version = 2; to->di_flushiter = ip->i_flushiter; + to->di_nextents32 = xfs_ifork_nextents(&ip->i_df); + to->di_nextents16 = xfs_ifork_nextents(ip->i_afp); } } diff --git a/fs/xfs/xfs_inode_item_recover.c b/fs/xfs/xfs_inode_item_recover.c index 40af9d1265c7..fcf360c03bc1 100644 --- a/fs/xfs/xfs_inode_item_recover.c +++ b/fs/xfs/xfs_inode_item_recover.c @@ -166,8 +166,6 @@ xfs_log_dinode_to_disk( to->di_size = cpu_to_be64(from->di_size); to->di_nblocks = cpu_to_be64(from->di_nblocks); to->di_extsize = cpu_to_be32(from->di_extsize); - to->di_nextents32 = cpu_to_be32(from->di_nextents32); - to->di_nextents16 = cpu_to_be16(from->di_nextents16); to->di_forkoff = from->di_forkoff; to->di_aformat = from->di_aformat; to->di_dmevmask = cpu_to_be32(from->di_dmevmask); @@ -181,12 +179,17 @@ xfs_log_dinode_to_disk( from->di_crtime); to->di_flags2 = cpu_to_be64(from->di_flags2); to->di_cowextsize = cpu_to_be32(from->di_cowextsize); + to->di_nextents64 = cpu_to_be64(from->di_nextents64); + to->di_nextents32 = cpu_to_be32(from->di_nextents32); + to->di_nextents16 = cpu_to_be16(from->di_nextents16); to->di_ino = cpu_to_be64(from->di_ino); to->di_lsn = cpu_to_be64(from->di_lsn); memcpy(to->di_pad2, from->di_pad2, sizeof(to->di_pad2)); uuid_copy(&to->di_uuid, &from->di_uuid); to->di_flushiter = 0; } else { + to->di_nextents32 = cpu_to_be32(from->di_nextents32); + to->di_nextents16 = cpu_to_be16(from->di_nextents16); to->di_flushiter = cpu_to_be16(from->di_flushiter); } } @@ -202,6 +205,8 @@ xlog_recover_inode_commit_pass2( struct xfs_mount *mp = log->l_mp; struct xfs_buf *bp; struct xfs_dinode *dip; + xfs_extnum_t nextents; + xfs_aextnum_t anextents; int len; char *src; char *dest; @@ -332,16 +337,24 @@ xlog_recover_inode_commit_pass2( goto out_release; } } - if (unlikely(ldip->di_nextents32 + ldip->di_nextents16 > ldip->di_nblocks)) { + + if (xfs_sb_version_hasextcount_64bit(&mp->m_sb)) { + nextents = ldip->di_nextents64; + anextents = ldip->di_nextents32; + } else { + nextents = ldip->di_nextents32; + anextents = ldip->di_nextents16; + } + + if (unlikely(nextents + anextents > ldip->di_nblocks)) { XFS_CORRUPTION_ERROR("xlog_recover_inode_pass2(5)", XFS_ERRLEVEL_LOW, mp, ldip, sizeof(*ldip)); xfs_alert(mp, "%s: Bad inode log record, rec ptr "PTR_FMT", dino ptr "PTR_FMT", " - "dino bp "PTR_FMT", ino %Ld, total extents = %d, nblocks = %Ld", + "dino bp "PTR_FMT", ino %Ld, total extents = %llu, nblocks = %Ld", __func__, item, dip, bp, in_f->ilf_ino, - ldip->di_nextents32 + ldip->di_nextents16, - ldip->di_nblocks); + nextents + anextents, ldip->di_nblocks); error = -EFSCORRUPTED; goto out_release; } diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index 19964b394dc4..2d44aa655f41 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -1901,6 +1901,9 @@ xfs_file_ioctl( case XFS_IOC_BULKSTAT_V5: return xfs_ioc_bulkstat(filp, cmd, arg, XFS_BULKSTAT_VERSION_V5); + case XFS_IOC_BULKSTAT_V6: + return xfs_ioc_bulkstat(filp, cmd, arg, + XFS_BULKSTAT_VERSION_V6); case XFS_IOC_INUMBERS: return xfs_ioc_inumbers(mp, cmd, arg, XFS_INUMBERS_VERSION_V5); From patchwork Mon Jul 26 11:45:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12399313 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94A30C4320A for ; Mon, 26 Jul 2021 11:46:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D42C60238 for ; Mon, 26 Jul 2021 11:46:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233660AbhGZLFq (ORCPT ); Mon, 26 Jul 2021 07:05:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233656AbhGZLFp (ORCPT ); Mon, 26 Jul 2021 07:05:45 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 180FEC061757 for ; Mon, 26 Jul 2021 04:46:13 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id ca5so135015pjb.5 for ; Mon, 26 Jul 2021 04:46:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LtzGqbqNtf2wpW85/3/glrq9hlOpReMPhax778/j8KQ=; b=nXBXt8AbKV3HS2fxmCpFDm+QK4KwxvdnH0a6ldzgK8z6y+pFx8czQwoC2nsvGXqsKd 5wkGySfYhEpLNcV6n+JHo2ai76pnVKHmgjA6a9T4yeyk1BDNRSUjfw2HEuG/lsjh64NU Lj+lkWlFz9zIogngCU8EJP12bDRfsGnKFTls8CuJnqRzSPDjnxzIBkhLbleckiASZxi9 SukrdDPtv0mwX1K7NBHa4L1hRL0EHcfOAp8kWFXL11G6XRSNkiNg4woI2H+U34jWiMzL pf6cOWAVLPEZ3MW/sEbnVcPVyMbMQ3ZDif/wlwYEXDcE62Fy8BWnlRzRMr3X9n4BpCSE u3/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LtzGqbqNtf2wpW85/3/glrq9hlOpReMPhax778/j8KQ=; b=LXf+BksVInutMtQCDLM/e04nPczMt5cKTVMpBucIADSYHM36MRmqX1GZROTfWrGaTt JZZeExlrSx1SEDctWO+h1WSVt/FI7XSUwrqGDhzRE08vmeIbMQ6I6DTx27YUHbMw1SS4 ZC4GzcmtlojHTQlFdLpLVZN2edW38+LGITAFTnchF3lsPqGt1oiqVsXTNJGvbRlWEPsG ty/ndyPbM+e5KjBNRx8Y7mrOVMzoxI7NJji7XOR31kMM2ya0iwSK8K++gQclR8aIkUbl 8GWK+gH/kx21V4H9p1x7xe6v1/Hf1mYRCOOmDOl+KDwYuAhPWtDxysbr1cjng8RmhfGs 4h9w== X-Gm-Message-State: AOAM530s822NtmkaHnMAYo/ytrnw6/zGVSy8buLlOmXn6kgO8dJc3eRc PTIJv5jgsZcsEvfJVppyxwuIHwDxWXU= X-Google-Smtp-Source: ABdhPJxNG103/QEc3socKjgpeGOTKTWE6QW83QXC38b70mwPkCSJ2ouzOxsCEfW8s48WK30NCgwrsg== X-Received: by 2002:aa7:8812:0:b029:32d:8252:fd0 with SMTP id c18-20020aa788120000b029032d82520fd0mr17900518pfo.48.1627299972531; Mon, 26 Jul 2021 04:46:12 -0700 (PDT) Received: from localhost.localdomain ([122.179.41.55]) by smtp.gmail.com with ESMTPSA id k8sm50833919pgr.91.2021.07.26.04.46.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 04:46:12 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , djwong@kernel.org Subject: [PATCH V2 12/12] xfs: Error tag to test if v5 bulkstat skips inodes with large extent count Date: Mon, 26 Jul 2021 17:15:41 +0530 Message-Id: <20210726114541.24898-13-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210726114541.24898-1-chandanrlinux@gmail.com> References: <20210726114541.24898-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit adds a new error tag to allow user space tests to check if V5 bulkstat ioctl skips reporting inodes with large extent count. Signed-off-by: Chandan Babu R Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_errortag.h | 4 +++- fs/xfs/xfs_error.c | 3 +++ fs/xfs/xfs_itable.c | 9 ++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/fs/xfs/libxfs/xfs_errortag.h b/fs/xfs/libxfs/xfs_errortag.h index f5fa2151e05d..b2c533153737 100644 --- a/fs/xfs/libxfs/xfs_errortag.h +++ b/fs/xfs/libxfs/xfs_errortag.h @@ -60,7 +60,8 @@ #define XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT 37 #define XFS_ERRTAG_AG_RESV_FAIL 38 #define XFS_ERRTAG_SWAPEXT_FINISH_ONE 39 -#define XFS_ERRTAG_MAX 40 +#define XFS_ERRTAG_BULKSTAT_REDUCE_MAX_IEXTENTS 40 +#define XFS_ERRTAG_MAX 41 /* * Random factors for above tags, 1 means always, 2 means 1/2 time, etc. @@ -105,5 +106,6 @@ #define XFS_RANDOM_BMAP_ALLOC_MINLEN_EXTENT 1 #define XFS_RANDOM_AG_RESV_FAIL 1 #define XFS_RANDOM_SWAPEXT_FINISH_ONE 1 +#define XFS_RANDOM_BULKSTAT_REDUCE_MAX_IEXTENTS 1 #endif /* __XFS_ERRORTAG_H_ */ diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c index e25b440cbfd3..e2a9446fb025 100644 --- a/fs/xfs/xfs_error.c +++ b/fs/xfs/xfs_error.c @@ -58,6 +58,7 @@ static unsigned int xfs_errortag_random_default[] = { XFS_RANDOM_BMAP_ALLOC_MINLEN_EXTENT, XFS_RANDOM_AG_RESV_FAIL, XFS_RANDOM_SWAPEXT_FINISH_ONE, + XFS_RANDOM_BULKSTAT_REDUCE_MAX_IEXTENTS, }; struct xfs_errortag_attr { @@ -172,6 +173,7 @@ XFS_ERRORTAG_ATTR_RW(reduce_max_iextents, XFS_ERRTAG_REDUCE_MAX_IEXTENTS); XFS_ERRORTAG_ATTR_RW(bmap_alloc_minlen_extent, XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT); XFS_ERRORTAG_ATTR_RW(ag_resv_fail, XFS_ERRTAG_AG_RESV_FAIL); XFS_ERRORTAG_ATTR_RW(swapext_finish_one, XFS_RANDOM_SWAPEXT_FINISH_ONE); +XFS_ERRORTAG_ATTR_RW(bulkstat_reduce_max_iextents, XFS_ERRTAG_BULKSTAT_REDUCE_MAX_IEXTENTS); static struct attribute *xfs_errortag_attrs[] = { XFS_ERRORTAG_ATTR_LIST(noerror), @@ -214,6 +216,7 @@ static struct attribute *xfs_errortag_attrs[] = { XFS_ERRORTAG_ATTR_LIST(bmap_alloc_minlen_extent), XFS_ERRORTAG_ATTR_LIST(ag_resv_fail), XFS_ERRORTAG_ATTR_LIST(swapext_finish_one), + XFS_ERRORTAG_ATTR_LIST(bulkstat_reduce_max_iextents), NULL, }; diff --git a/fs/xfs/xfs_itable.c b/fs/xfs/xfs_itable.c index 8493870a0a87..1b252d1cda9d 100644 --- a/fs/xfs/xfs_itable.c +++ b/fs/xfs/xfs_itable.c @@ -20,6 +20,7 @@ #include "xfs_icache.h" #include "xfs_health.h" #include "xfs_trans.h" +#include "xfs_errortag.h" /* * Bulk Stat @@ -143,7 +144,13 @@ xfs_bulkstat_one_int( nextents = xfs_ifork_nextents(&ip->i_df); if (bc->breq->version != XFS_BULKSTAT_VERSION_V6) { - if (nextents > XFS_IFORK_EXTCNT_MAXS32) { + xfs_extnum_t max_nextents = XFS_IFORK_EXTCNT_MAXS32; + + if (unlikely(XFS_TEST_ERROR(false, mp, + XFS_ERRTAG_BULKSTAT_REDUCE_MAX_IEXTENTS))) + max_nextents = 10; + + if (nextents > max_nextents) { xfs_iunlock(ip, XFS_ILOCK_SHARED); xfs_irele(ip); error = -EINVAL;