On Tue, Nov 8, 2022 at 7:33 PM Ryusuke Konishi wrote: > On Tue, Nov 8, 2022 at 3:49 PM Liu Shixin wrote: > > Then in nilfs_segctor_extend_segments(), we set sb_segnum by prev->sb_nextnum directly, > > and calculate next sb_segnum by nilfs_sufile_alloc(), since last_alloc is not updated, > > we will get sb_segnum again. > > nilfs_segctor_extend_segments() pre-allocates one or more segments > large enough to store updated blocks of metadata files that need to be > written in a series of logs at once, and sets up a chain of segbufs. > (Sorry for the missing function comment). > > sb_segnum is set by prev->sb_nextnum to form a chain of buffers for > segments. This is expected behavior. > And, the sb_nextnum (= next sb_segnum) will be given by > nilfs_sufile_alloc(). This is also expected. > It looks like the problem is that nilfs_sufile_alloc() here allocates > the same segnum again. > > Because sb_segnum is set by prev->sb_nextnum which is allocated by the > previous nilfs_sufile_alloc() call, > this usually does not happen. > > A possible anomaly is if the segment pointed by the first nextnum (or > segnum) was not marked dirty on sufile. > This may happen if the sufile is corrupted on the test disk image that > syzbot provided (mounted). > > Can you confirm if this is actually happening? If we can mount the test disk image, the state of sufile can be confirmed quickly with lssu command: $ lssu SEGNUM DATE TIME STAT NBLOCKS 3 2022-11-04 23:23:49 -d- 2048 4 2022-11-04 23:23:50 ad- 103 5 ---------- --:--:-- ad- 0 Here, the flag "d" in STAT means the segment is dirty (in-use) and the segment of ns_segnum or ns_nextnum is indicated with the "a" flag. This is an example of a normal disk image. Or, if it's easy to insert debug code to check, that's fine too. Regards, Ryusuke Konishi