Bug 261850 - fs/ext2fs: Fix bug in disk data block allocation
Summary: fs/ext2fs: Fix bug in disk data block allocation
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 13.0-STABLE
Hardware: Any Any
: --- Affects Some People
Assignee: Fedor Uporov
URL:
Keywords: needs-qa
Depends on:
Blocks:
 
Reported: 2022-02-10 02:10 UTC by chenguang.wang
Modified: 2023-02-11 07:15 UTC (History)
7 users (show)

See Also:
koobs: maintainer-feedback? (fsu)
koobs: maintainer-feedback? (mjg)
koobs: maintainer-feedback? (nc)
koobs: mfc-stable13?
koobs: mfc-stable12?


Attachments
fs/ext2fs: Fix bug in disk data block allocation. (246 bytes, patch)
2022-02-10 07:19 UTC, chenguang.wang
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description chenguang.wang 2022-02-10 02:10:07 UTC
git diff fs/ext2fs/ext2_alloc.c
diff --git a/fs/ext2fs/ext2_alloc.c b/fs/ext2fs/ext2_alloc.c
index 4c265a1a8..9e05d02de 100644
--- a/fs/ext2fs/ext2_alloc.c
+++ b/fs/ext2fs/ext2_alloc.c
@@ -1067,7 +1067,7 @@ ext2_alloccg(struct inode *ip, int cg, daddr_t bpref, int size)
                start = dtogd(fs, bpref) / NBBY;
        else
                start = 0;
-       end = howmany(fs->e2fs_fpg, NBBY) - start;
+       end = howmany(fs->e2fs_fpg, NBBY);
 retry:
        runlen = 0;
        runstart = 0;

    In this function, the variable "start" is the starting position where we traverse the block bitmap of a cylinder group , and the variable "end" is the ending position. Therefore, I don't think we should subtract "start" in the process of calculating "end".
    In fact, I'm not sure if there's something wrong with my understanding. I would be very grateful if someone could help me!
Comment 1 Kubilay Kocak freebsd_committer freebsd_triage 2022-02-10 02:33:47 UTC
Thank you for the bug report and patch. Could you include it as an attachment please? Thanks :)

^Triage: Loop in original committer and people playing in that area of the tree recently
Comment 2 chenguang.wang 2022-02-10 04:39:17 UTC
(In reply to Kubilay Kocak from comment #1)
Hi, Kubilay Kocak
    We will submit the patch after solving the local network problem. Thank you very much!
Comment 3 chenguang.wang 2022-02-10 07:19:35 UTC
Created attachment 231702 [details]
fs/ext2fs: Fix bug in disk data block allocation.

git diff fs/ext2fs/ext2_alloc.c
diff --git a/fs/ext2fs/ext2_alloc.c b/fs/ext2fs/ext2_alloc.c
index 4c265a1a8..9e05d02de 100644
--- a/fs/ext2fs/ext2_alloc.c
+++ b/fs/ext2fs/ext2_alloc.c
@@ -1067,7 +1067,7 @@ ext2_alloccg(struct inode *ip, int cg, daddr_t bpref, int size)
                start = dtogd(fs, bpref) / NBBY;
        else
                start = 0;
-       end = howmany(fs->e2fs_fpg, NBBY) - start;
+       end = howmany(fs->e2fs_fpg, NBBY);
 retry:
        runlen = 0;
        runstart = 0;
Comment 4 Ka Ho Ng freebsd_committer freebsd_triage 2022-02-10 07:23:00 UTC
The change looks good in my eye. You just need to open a differential review in https://review.freebsd.org .
Comment 5 Ka Ho Ng freebsd_committer freebsd_triage 2022-02-10 07:23:54 UTC
(In reply to Ka Ho Ng from comment #4)

Sorry. It should be https://reviews.freebsd.org .
Comment 6 commit-hook freebsd_committer freebsd_triage 2023-01-29 08:19:57 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=344243fc9213f78b2af5f089cb8b9e0e60706705

commit 344243fc9213f78b2af5f089cb8b9e0e60706705
Author:     Fedor Uporov <fsu@FreeBSD.org>
AuthorDate: 2023-01-26 10:06:25 +0000
Commit:     Fedor Uporov <fsu@FreeBSD.org>
CommitDate: 2023-01-29 08:11:02 +0000

    Fix block bitmap end position computation

    PR:                     261850
    Reported by:            chenguang.wang
    MFC after:              2 weeks

 sys/fs/ext2fs/ext2_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)