Skip to contentSkip to conversation

mkfs.gfs2: Don't exceed IOV_MAX when zeroing first alignment gap

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

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mkfs.gfs2: Don't exceed IOV_MAX when zeroing first alignment gap

The first resource group can be aligned far away from the superblock when the device has large stripes, and zeroing that gap with a small block size can mean that the iovec used exceeds IOV_MAX and causes pwritev to fail with EINVAL. Split the writes to guard against that.

---
 gfs2/mkfs/main_mkfs.c | 13 ++++++++++---
 tests/mkfs.at         |  1 +
 2 files changed, 11 insertions(+), 3 deletions(-)
gfs2/mkfs/main_mkfs.c +10 -3
index 36fd08e7..3fb2eb92 100644
@@ -711,9 +711,16 @@ static int place_rgrp(struct gfs2_sbd *sdp, lgfs2_rgrp_t rg, int debug)
 		prev_end = lgfs2_rgrp_index(prev)->ri_data0 +
 		           lgfs2_rgrp_index(prev)->ri_data;
 	}
-	err = zero_gap(sdp, prev_end, ri->ri_addr - prev_end);
-	if (err != 0)
-		return -1;
+	while (prev_end < ri->ri_addr) {
+		size_t gap_len = ri->ri_addr - prev_end;
+
+		if (gap_len > IOV_MAX)
+			gap_len = IOV_MAX;
+		err = zero_gap(sdp, prev_end, gap_len);
+		if (err != 0)
+			return -1;
+		prev_end += gap_len;
+	}
 	err = lgfs2_rgrp_write(sdp->device_fd, rg);
 	if (err != 0) {
 		perror(_("Failed to write resource group"));
tests/mkfs.at +1 -0
index 4c8b2249..96c4f6ab 100644
@@ -117,6 +117,7 @@ AT_CHECK([gfs2_edit -p sb field sb_bsize $GFS_TGT | tr -d '\n' ], 0, [4096], [ig
 AT_CHECK([$GFS_MKFS -p lock_nolock -o test_topology=7168:512:0:33553920:512 $GFS_TGT], 0, [ignore], [ignore])
 AT_CHECK([$GFS_MKFS -p lock_nolock -o test_topology=7168:512:8192:33553920:512 $GFS_TGT], 0, [ignore], [Warning: device is not properly aligned. This may harm performance.
 ])
+AT_CHECK([$GFS_MKFS -p lock_nolock -o test_topology=0:512:4194304:8388608:512 -b 1024 $GFS_TGT], 0, [ignore], [ignore])
 AT_CLEANUP
 
 AT_SETUP([Resource group alignment])
Signature · 1 line
2.26.2