Skip to contentSkip to conversation

mkfs.gfs2: Tighten minimum journal size checks

PATCH New Andrew Price 1 participant 1 message Aug 28, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mkfs.gfs2: Tighten minimum journal size checks

mkfs.gfs2 chooses the default journal size based on the block size and the size of the target device, and when the device is small enough a minimum journal size is enforced. If the block size is less than 4K and the device is small enough a journal size can be chosen that is smaller than the minimum and gfs2 will not mount it, as it has a hardcoded check for >=8MB journals. To avoid that we can just clamp the journal size back to 8MB in these cases. A validity check for the minimum has already been done in default_journal_size().

Resolves: rhbz#1779806

---
 gfs2/mkfs/main_mkfs.c | 8 +++++++-
 tests/mkfs.at         | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)
gfs2/mkfs/main_mkfs.c +7 -1
index 3fb2eb92..df194dff 100644
@@ -929,11 +929,17 @@ static void sbd_init(struct gfs2_sbd *sdp, struct mkfs_opts *opts, unsigned bsiz
 	   will fit. For user-provided journal sizes, limit it to half of the fs. */
 	if (!opts->got_jsize) {
 		int default_jsize = default_journal_size(sdp->bsize, sdp->device.length / opts->journals);
+		unsigned jsize_mb;
+
 		if (default_jsize < 0) {
 			fprintf(stderr, _("gfs2 will not fit on this device.\n"));
 			exit(1);
 		}
-		opts->jsize = (default_jsize * sdp->bsize) >> 20;
+		jsize_mb = (default_jsize * sdp->bsize) >> 20;
+		if (jsize_mb < GFS2_MIN_JSIZE)
+			opts->jsize = GFS2_MIN_JSIZE;
+		else
+			opts->jsize = jsize_mb;
 	} else if ((((opts->jsize * opts->journals) << 20) / sdp->bsize) > (sdp->device.length / 2)) {
 		unsigned max_jsize = (sdp->device.length / 2 * sdp->bsize / opts->journals) >> 20;
 
tests/mkfs.at +2 -0
index 96c4f6ab..73cdfee6 100644
@@ -78,6 +78,8 @@ AT_CLEANUP
 AT_SETUP([Min. journal size])
 AT_KEYWORDS(mkfs.gfs2 mkfs)
 GFS_FSCK_CHECK([$GFS_MKFS -p lock_nolock -J 8 $GFS_TGT])
+GFS_FSCK_CHECK([$GFS_MKFS -p lock_nolock -b 1024 $GFS_TGT 511996])
+AT_CHECK([gfs2_edit -p journal0 field di_size $GFS_TGT | tr -d '\n'], 0, [8388608], [ignore])
 AT_CLEANUP
 
 AT_SETUP([Max. quota change file size])
Signature · 1 line
2.26.2