From nobody Tue Sep 9 21:28:52 2025 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 255703019B7; Fri, 5 Sep 2025 08:15:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757060115; cv=none; b=hfgeBAbTnuMAQjktiatkn4KQCrXpBwAGu/ao4QngSQDnzO84eOv37OSmGEyeBgqzoS6oNYm7L37p7ryXqRkvoy8H5hIqpMwzLtkyR8IoiOHAmEnfdW/DLOp2iZkY5ZiYLntBO5pZTLoH57MzmBSDcaZiZ8uAp6xgsbdyLyHPFN0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757060115; c=relaxed/simple; bh=sm/TzjrAehkEUJaQufVHn5YoM2USZj2WUOJf4X0XQQ8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pzNam1+AWI3B9h9HVmzwqKbvj/xveKVQueiGLMxhCk+b/kSM3mdULtnSuTTVm5bewbfrDx+nmcgtFW8JbIthYYZTvRDXv6n//ZQ6KPMZKUbqVgYuPX+S3n3Mu7SsRS4q3eTE7qsK7dXAdwYRh06o10d0b5ahN3qr792gPlDagsE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=FWyEfsS3; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="FWyEfsS3" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5856pQ2M011377; Fri, 5 Sep 2025 08:14:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=WJGB95gX2Zofxj8Ia +KLEl69WUYf3/kubsB1SAz4ElY=; b=FWyEfsS3WzAFn/aqc9M35/HaScmjxEEvm SBagatKo6VvkLvyqMnprWa4r5vWY/LpQL7sBVFenChcA5wO4Hz6/V/TlmWp1lqpR RqiyXDJWZBoJ5GxB5b2Odss3kbWsmqcWB3hHSJ3MyU5C6qsZpu1x8r7Bns1Cwac+ cgZUOYqmxgZyL15hbr+v13X5eGgVeHURnK4fREWcCbCFCS0oVme4H++6qKO9PEBc 8pGiek9cWsKfojGGNAzYrPxAkQsvYrwuN/b5DhE4eYzTVBz2lWNhBXAUJ8gzDnwD FrQpxlgLTBFB0umHpmkQVBgA9wWXeIfQDlu1/hhUhsTcWa4Uuf1IA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 48usuaearf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 05 Sep 2025 08:14:56 +0000 (GMT) Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.18.1.12/8.18.0.8) with ESMTP id 5858EuOe004747; Fri, 5 Sep 2025 08:14:56 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 48usuaearb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 05 Sep 2025 08:14:55 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 58558Kaq019404; Fri, 5 Sep 2025 08:14:55 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 48vd4n8edn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 05 Sep 2025 08:14:55 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 5858ErmL48628062 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 5 Sep 2025 08:14:53 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5FD9D2004E; Fri, 5 Sep 2025 08:14:53 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CFCC72004B; Fri, 5 Sep 2025 08:14:51 +0000 (GMT) Received: from li-dc0c254c-257c-11b2-a85c-98b6c1322444.ibm.com (unknown [9.39.27.144]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 5 Sep 2025 08:14:51 +0000 (GMT) From: Ojaswin Mujoo To: linux-ext4@vger.kernel.org, "Theodore Ts'o" Cc: Ritesh Harjani , Zhang Yi , linux-kernel@vger.kernel.org, "Darrick J . Wong" Subject: [PATCH 1/2] ext4: Correctly handle queries for metadata mappings Date: Fri, 5 Sep 2025 13:44:46 +0530 Message-ID: <023f37e35ee280cd9baac0296cbadcbe10995cab.1757058211.git.ojaswin@linux.ibm.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 7W_8CZXIMvu61FOfgH7_tqLM-Z7g2N1b X-Authority-Analysis: v=2.4 cv=U6uSDfru c=1 sm=1 tr=0 ts=68ba9c00 cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=yJojWOMRYYMA:10 a=GcyzOjIWAAAA:8 a=pGLkceISAAAA:8 a=VnNF1IyMAAAA:8 a=aYyh5IJWwJZTkH4q8vMA:9 a=P-ljAEOyBtQA:10 a=hQL3dl6oAZ8NdCsdz28n:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwODMwMDAzNCBTYWx0ZWRfX9bVTc2nbTmUn VncM9sJc7VuD45kDhzOZPxJhTzgPGWgAHoBB3h4LPJH7lyFbIBMfmJ0R7uhTCHHDzBCYqBKfZ7y Km9eVZ2mC19efrwjKXaqJYcXbd2jjmeZaVpVl1SaA2/KIeW3/344tui/y/LlWOXIQkFdYyVpPPx kPXXSbEtlkzLwBWX4MYCB73bmZslvB7hslH9KIo46EY+RKgzkWqWztyqtw2/mt1tKThfHE32GTp agd/+iTK4ddNMezF0yhL6qjQTUULCI/jyQdeZKuuUvimeF8d5gPwMKLmZdKmYz7FzsP8yawZE7O 6OQRr1BbzERmI1yjQZ4MndH8mArwKWftDWlvohnjCerirl/6EVd3cXHUVwb2EjjyjTfQ04Manjq +g76qZkD X-Proofpoint-ORIG-GUID: c_pbiMSC9Gi3bcn5NSIR1XSKOVJH6ZBR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1117,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-09-05_02,2025-09-04_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 adultscore=0 clxscore=1015 suspectscore=0 priorityscore=1501 spamscore=0 bulkscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2507300000 definitions=main-2508300034 Content-Type: text/plain; charset="utf-8" Currently, our handling of metadata is _ambiguous_ in some scenarios, that is, we end up returning unknown if the range only covers the mapping partially. For example, in the following case: $ xfs_io -c fsmap -d 0: 254:16 [0..7]: static fs metadata 8 1: 254:16 [8..15]: special 102:1 8 2: 254:16 [16..5127]: special 102:2 5112 3: 254:16 [5128..5255]: special 102:3 128 4: 254:16 [5256..5383]: special 102:4 128 5: 254:16 [5384..70919]: inodes 65536 6: 254:16 [70920..70967]: unknown 48 ... $ xfs_io -c fsmap -d 24 33 0: 254:16 [24..39]: unknown 16 <--- incomplete reporting $ xfs_io -c fsmap -d 24 33 (With patch) 0: 254:16 [16..5127]: special 102:2 5112 This is because earlier in ext4_getfsmap_meta_helper, we end up ignoring any extent that starts before our queried range, but overlaps it. While the man page [1] is a bit ambiguous on this, this fix makes the output make more sense since we are anyways returning an "unknown" extent. This is also consistent to how XFS does it: $ xfs_io -c fsmap -d ... 6: 254:16 [104..127]: free space 24 7: 254:16 [128..191]: inodes 64 ... $ xfs_io -c fsmap -d 137 150 0: 254:16 [128..191]: inodes 64 <-- full extent returned [1] https://man7.org/linux/man-pages/man2/ioctl_getfsmap.2.html Reported-by: Ritesh Harjani (IBM) Signed-off-by: Ojaswin Mujoo --- fs/ext4/fsmap.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/fs/ext4/fsmap.c b/fs/ext4/fsmap.c index 91185c40f755..22fc333244ef 100644 --- a/fs/ext4/fsmap.c +++ b/fs/ext4/fsmap.c @@ -74,7 +74,8 @@ static int ext4_getfsmap_dev_compare(const void *p1, cons= t void *p2) static bool ext4_getfsmap_rec_before_low_key(struct ext4_getfsmap_info *in= fo, struct ext4_fsmap *rec) { - return rec->fmr_physical < info->gfi_low.fmr_physical; + return rec->fmr_physical + rec->fmr_length <=3D + info->gfi_low.fmr_physical; } =20 /* @@ -200,15 +201,18 @@ static int ext4_getfsmap_meta_helper(struct super_blo= ck *sb, ext4_group_first_block_no(sb, agno)); fs_end =3D fs_start + EXT4_C2B(sbi, len); =20 - /* Return relevant extents from the meta_list */ + /* + * Return relevant extents from the meta_list. We emit all extents that + * partially/fully overlap with the query range + */ list_for_each_entry_safe(p, tmp, &info->gfi_meta_list, fmr_list) { - if (p->fmr_physical < info->gfi_next_fsblk) { + if (p->fmr_physical + p->fmr_length <=3D info->gfi_next_fsblk) { list_del(&p->fmr_list); kfree(p); continue; } - if (p->fmr_physical <=3D fs_start || - p->fmr_physical + p->fmr_length <=3D fs_end) { + if (p->fmr_physical <=3D fs_end && + p->fmr_physical + p->fmr_length > fs_start) { /* Emit the retained free extent record if present */ if (info->gfi_lastfree.fmr_owner) { error =3D ext4_getfsmap_helper(sb, info, --=20 2.49.0 From nobody Tue Sep 9 21:28:52 2025 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CC593043D1; Fri, 5 Sep 2025 08:15:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757060119; cv=none; b=D4WQwnCp1UXDQ17yktkYjgbgbr24Oyl9VF2wBOb2xH64kZSgiEpdqiqLW4RPhW6Vi9jDmhR8iGYXe1O6WWjT7f5PGmcmCM4TKn+oLobpfReAqf8yH1gGTHXjtxMdDXljIaMKFth0nXwsYo5n81X+ZH7iRQ2RnHsHlcfksC8BQy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757060119; c=relaxed/simple; bh=dGl3HPk4ea6xcz1AY9xoYbL2hRSpczO81jV7mfFdqyA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SChvX6nlD2J/A5Omt8Lgvg8dTChdOOnKe2VDGAZQOSAcqklGVI1i+j4cCfdZQVK1zs62mAAxOuOyOmL1aCeBLKZY8xFO0jIQ/8cfcakYhk65IuU6JhKTZDGlbJ84K6321jEzKAwZztYiZGvBS54H0CXkfTrLJZKmU+TVvlpzFRE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=T8Q+Kfqy; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="T8Q+Kfqy" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5857q0fN000693; Fri, 5 Sep 2025 08:14:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=tXHNtHbn1eNK0FlZE 95i5qXhKjyxOQpxjAPzGwb8hhE=; b=T8Q+KfqyRgTbSXDzG5hx7oeHciyJ8ct/l tzN5SEp+WvaZWS9ynuURmbQKv+uEdB8fBrONKDLiSaDO9Y16ufFSWlpCMMAEJgBL pFncCOPE3eda7qhsyqYjboOPxNjV6kCldIFQd0yEDKZkFUsgNWSxAi1P0rE22KVH fq2AdXh1kOeHJlkLr4Ac2mc20YL8i8YQo8rR/sLoZUgTdSMXr/TrmXCSuMYd8WMA +qrMLPto955Tzr6MavbC7dkGFhv/fqRc08/IpSfYPq4iOSm9+Hgpw7yD8bMgy/VI CFQTroIkxlqBp7nZ8kDUe45bJfEWWZr86VrvVb/GvFZYMQQoGfFxw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 48wshfajh0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 05 Sep 2025 08:14:58 +0000 (GMT) Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.18.1.12/8.18.0.8) with ESMTP id 58587gUe000714; Fri, 5 Sep 2025 08:14:58 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 48wshfajgx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 05 Sep 2025 08:14:58 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 5855YZQW019331; Fri, 5 Sep 2025 08:14:57 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 48vd4n8edw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 05 Sep 2025 08:14:57 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 5858EteO18743792 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 5 Sep 2025 08:14:55 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6B8B02004E; Fri, 5 Sep 2025 08:14:55 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C315C2004B; Fri, 5 Sep 2025 08:14:53 +0000 (GMT) Received: from li-dc0c254c-257c-11b2-a85c-98b6c1322444.ibm.com (unknown [9.39.27.144]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 5 Sep 2025 08:14:53 +0000 (GMT) From: Ojaswin Mujoo To: linux-ext4@vger.kernel.org, "Theodore Ts'o" Cc: Ritesh Harjani , Zhang Yi , linux-kernel@vger.kernel.org, "Darrick J . Wong" Subject: [PATCH 2/2] fsmap: use blocksize units instead of cluster units Date: Fri, 5 Sep 2025 13:44:47 +0530 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: QuBKTN1BuvLfJlVwgvUEdxckXIIn9pVo X-Authority-Analysis: v=2.4 cv=do3bC0g4 c=1 sm=1 tr=0 ts=68ba9c02 cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=yJojWOMRYYMA:10 a=VnNF1IyMAAAA:8 a=dPYBfUDpcxx5Ehpc6mMA:9 X-Proofpoint-ORIG-GUID: RNbF0Ua0YLOdPSlSzHWyyMkt1q7j7HoA X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwOTAyMDA0MCBTYWx0ZWRfX49T+ikf78h6B eiRaF+GWoxrOYjnpwrtbCpNqc2CBv5dStP5lUfO1V6R7mOPVQ2GpEywknulH1FVIW9TDxpnlhR8 VAoqxg3E4uZ66Y2M2tDtWecLvRPer4wuI8heRhcGw09PdflG9RXKvRtYjiGyetVxD5aZ+fIaZB6 VgXhGaAZ0x2tcSMd7deHn9WUm1lGT2etsQghh3QGvlaBS0Dx5WwznukGultsxO5GRG099YZBNLY GOL2vmz/Jc0f48ITFqMxJbBXirQX4+uBWdAF7wuSBUizWQBlmEPkf4htcROpiwIS/TQXJN8wuVx Nih4YbE8mL698+lWGJ5gxt6Kk4nnkkQajtq5Kqzelg6lK1IiaIkMxs6Wc23A2fQUhj2vrLdt0Au ofzWMyjx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1117,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-09-05_02,2025-09-04_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1015 impostorscore=0 bulkscore=0 suspectscore=0 malwarescore=0 spamscore=0 priorityscore=1501 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2507300000 definitions=main-2509020040 Content-Type: text/plain; charset="utf-8" Currently, ext4's implementation of fsmap converts the ranges to cluster units if bigalloc is enabled and then converts to block units whenever needed. However, this back and forth conversion has known to cause several edge case issues since even with bigalloc the metadata is still in block size unit. Hence, convert the code to use block size instead of cluster size. Cluster size is only used when dealing with mballoc bitmap. This takes care of the existing issues with the code, example, for a mapping as follows: xfs_io -c fsmap -d (bs=3D4096, clustersize=3D65536) 0: 254:16 [0..7]: static fs metadata 8 1: 254:16 [8..15]: special 102:1 8 2: 254:16 [16..327]: special 102:2 312 3: 254:16 [328..351]: special 102:3 24 4: 254:16 [352..375]: special 102:4 24 ... xfs_io -c fsmap -d 6 16 (before this patch): 0: 254:16 [0..7]: static fs metadata 8 1: 254:16 [8..23]: unknown 16 <--- incorrect/ambiguous entry xfs_io -c fsmap -d 6 16 (after this patch): 0: 254:16 [0..7]: static fs metadata 8 1: 254:16 [8..15]: special 102:1 8 2: 254:16 [16..327]: special 102:2 312 Signed-off-by: Ojaswin Mujoo --- fs/ext4/fsmap.c | 42 +++++++++++++++++++++++------------------- fs/ext4/mballoc.c | 25 +++++++++++++++++-------- 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/fs/ext4/fsmap.c b/fs/ext4/fsmap.c index 22fc333244ef..02e5d501dda8 100644 --- a/fs/ext4/fsmap.c +++ b/fs/ext4/fsmap.c @@ -193,13 +193,11 @@ static int ext4_getfsmap_meta_helper(struct super_blo= ck *sb, struct ext4_getfsmap_info *info =3D priv; struct ext4_fsmap *p; struct ext4_fsmap *tmp; - struct ext4_sb_info *sbi =3D EXT4_SB(sb); ext4_fsblk_t fsb, fs_start, fs_end; int error; =20 - fs_start =3D fsb =3D (EXT4_C2B(sbi, start) + - ext4_group_first_block_no(sb, agno)); - fs_end =3D fs_start + EXT4_C2B(sbi, len); + fs_start =3D fsb =3D start + ext4_group_first_block_no(sb, agno); + fs_end =3D fs_start + len; =20 /* * Return relevant extents from the meta_list. We emit all extents that @@ -248,13 +246,12 @@ static int ext4_getfsmap_datadev_helper(struct super_= block *sb, struct ext4_getfsmap_info *info =3D priv; struct ext4_fsmap *p; struct ext4_fsmap *tmp; - struct ext4_sb_info *sbi =3D EXT4_SB(sb); ext4_fsblk_t fsb; ext4_fsblk_t fslen; int error; =20 - fsb =3D (EXT4_C2B(sbi, start) + ext4_group_first_block_no(sb, agno)); - fslen =3D EXT4_C2B(sbi, len); + fsb =3D start + ext4_group_first_block_no(sb, agno); + fslen =3D len; =20 /* If the retained free extent record is set... */ if (info->gfi_lastfree.fmr_owner) { @@ -531,13 +528,13 @@ static int ext4_getfsmap_datadev(struct super_block *= sb, { struct ext4_sb_info *sbi =3D EXT4_SB(sb); ext4_fsblk_t start_fsb; - ext4_fsblk_t end_fsb; + ext4_fsblk_t end_fsb, orig_end_fsb; ext4_fsblk_t bofs; ext4_fsblk_t eofs; ext4_group_t start_ag; ext4_group_t end_ag; - ext4_grpblk_t first_cluster; - ext4_grpblk_t last_cluster; + ext4_grpblk_t first_grpblk; + ext4_grpblk_t last_grpblk; struct ext4_fsmap irec; int error =3D 0; =20 @@ -553,10 +550,18 @@ static int ext4_getfsmap_datadev(struct super_block *= sb, return 0; start_fsb =3D keys[0].fmr_physical; end_fsb =3D keys[1].fmr_physical; + orig_end_fsb =3D end_fsb; =20 - /* Determine first and last group to examine based on start and end */ - ext4_get_group_no_and_offset(sb, start_fsb, &start_ag, &first_cluster); - ext4_get_group_no_and_offset(sb, end_fsb, &end_ag, &last_cluster); + /* + * Determine first and last group to examine based on start and end. + * NOTE: do_div() should take ext4_fsblk_t instead of ext4_group_t as + * first argument else it will fail on 32bit archs. + */ + first_grpblk =3D do_div(start_fsb, EXT4_BLOCKS_PER_GROUP(sb)); + last_grpblk =3D do_div(end_fsb, EXT4_BLOCKS_PER_GROUP(sb)); + + start_ag =3D start_fsb; + end_ag =3D end_fsb; =20 /* * Convert the fsmap low/high keys to bg based keys. Initialize @@ -564,7 +569,7 @@ static int ext4_getfsmap_datadev(struct super_block *sb, * of the bg. */ info->gfi_low =3D keys[0]; - info->gfi_low.fmr_physical =3D EXT4_C2B(sbi, first_cluster); + info->gfi_low.fmr_physical =3D first_grpblk; info->gfi_low.fmr_length =3D 0; =20 memset(&info->gfi_high, 0xFF, sizeof(info->gfi_high)); @@ -584,8 +589,7 @@ static int ext4_getfsmap_datadev(struct super_block *sb, */ if (info->gfi_agno =3D=3D end_ag) { info->gfi_high =3D keys[1]; - info->gfi_high.fmr_physical =3D EXT4_C2B(sbi, - last_cluster); + info->gfi_high.fmr_physical =3D last_grpblk; info->gfi_high.fmr_length =3D 0; } =20 @@ -600,8 +604,8 @@ static int ext4_getfsmap_datadev(struct super_block *sb, info->gfi_high.fmr_owner); =20 error =3D ext4_mballoc_query_range(sb, info->gfi_agno, - EXT4_B2C(sbi, info->gfi_low.fmr_physical), - EXT4_B2C(sbi, info->gfi_high.fmr_physical), + info->gfi_low.fmr_physical, + info->gfi_high.fmr_physical, ext4_getfsmap_meta_helper, ext4_getfsmap_datadev_helper, info); if (error) @@ -627,7 +631,7 @@ static int ext4_getfsmap_datadev(struct super_block *sb, * any allocated blocks at the end of the range. */ irec.fmr_device =3D 0; - irec.fmr_physical =3D end_fsb + 1; + irec.fmr_physical =3D orig_end_fsb + 1; irec.fmr_length =3D 0; irec.fmr_owner =3D EXT4_FMR_OWN_FREE; irec.fmr_flags =3D 0; diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 5898d92ba19f..cf78776940dd 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -7117,6 +7117,8 @@ ext4_mballoc_query_range( ext4_grpblk_t start, next; struct ext4_buddy e4b; int error; + struct ext4_sb_info *sbi =3D EXT4_SB(sb); + ext4_grpblk_t start_c, end_c, next_c; =20 error =3D ext4_mb_load_buddy(sb, group, &e4b); if (error) @@ -7125,9 +7127,9 @@ ext4_mballoc_query_range( =20 ext4_lock_group(sb, group); =20 - start =3D max(e4b.bd_info->bb_first_free, first); - if (end >=3D EXT4_CLUSTERS_PER_GROUP(sb)) - end =3D EXT4_CLUSTERS_PER_GROUP(sb) - 1; + start =3D max(EXT4_C2B(sbi, e4b.bd_info->bb_first_free), first); + if (end >=3D EXT4_BLOCKS_PER_GROUP(sb)) + end =3D EXT4_BLOCKS_PER_GROUP(sb) - 1; if (meta_formatter && start !=3D first) { if (start > end) start =3D end; @@ -7138,19 +7140,26 @@ ext4_mballoc_query_range( goto out_unload; ext4_lock_group(sb, group); } - while (start <=3D end) { - start =3D mb_find_next_zero_bit(bitmap, end + 1, start); - if (start > end) + + start_c =3D EXT4_B2C(sbi, start); + end_c =3D EXT4_B2C(sbi, end); + + while (start_c <=3D end_c) { + start_c =3D mb_find_next_zero_bit(bitmap, end_c + 1, start_c); + if (start_c > end_c) break; - next =3D mb_find_next_bit(bitmap, end + 1, start); + next_c =3D mb_find_next_bit(bitmap, end_c + 1, start_c); =20 ext4_unlock_group(sb, group); + + start =3D EXT4_C2B(sbi, start_c); + next =3D EXT4_C2B(sbi, next_c); error =3D formatter(sb, group, start, next - start, priv); if (error) goto out_unload; ext4_lock_group(sb, group); =20 - start =3D next + 1; + start_c =3D next_c + 1; } =20 ext4_unlock_group(sb, group); --=20 2.49.0