Skip to contentSkip to conversation

mkfs: Round down log device size if aligned value is larger than device size

PATCH Superseded Chandan Rajendra 2 participants 4 messages Mar 17, 2019 – Mar 19, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mkfs: Round down log device size if aligned value is larger than device size

When using a disk of size 798903808 bytes as the log device and when having a log stripe unit size of 32768, align_log_size() rounds up log device size to 195048 4k blocks i.e. 798916608. This value is larger than the device size. Hence the last call to write(2) inside libxfs_device_zero() would end up returning an error.

To fix this bug, we now round down the log device size if the newly computed size is larger than the actual log device size.

---
 mkfs/xfs_mkfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mkfs/xfs_mkfs.c +2 -1
index d1387ddf..bd05d071 100644
@@ -2938,7 +2938,8 @@ _("log size %lld is not a multiple of the log stripe unit %d\n"),
 
 	/* If the log is too large, round down instead of round up */
 	if ((tmp_logblocks > XFS_MAX_LOG_BLOCKS) ||
-	    ((tmp_logblocks << cfg->blocklog) > XFS_MAX_LOG_BYTES)) {
+		((tmp_logblocks << cfg->blocklog) > XFS_MAX_LOG_BYTES) ||
+		(tmp_logblocks > cfg->logblocks)) {
 		tmp_logblocks = (cfg->logblocks / sunit) * sunit;
 	}
 	cfg->logblocks = tmp_logblocks;
Signature · 1 line
2.19.1
#1 lore raw
Quoted 19 lines · Chandan Rajendra

When using a disk of size 798903808 bytes as the log device and when having a log stripe unit size of 32768, align_log_size() rounds up log device size to 195048 4k blocks i.e. 798916608. This value is larger than the device size. Hence the last call to write(2) inside libxfs_device_zero() would end up returning an error.

To fix this bug, we now round down the log device size if the newly computed size is larger than the actual log device size.

---
 mkfs/xfs_mkfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mkfs/xfs_mkfs.c +0 -0
index d1387ddf..bd05d071 100644

mkfs/xfs_mkfs.c _("log size %lld is not a multiple of the log stripe unit %d\n"), · line 2942

Quoted 6 lines
mkfs/xfs_mkfs.c +2 -1
@@ -2938,7 +2938,8 @@ _("log size %lld is not a multiple of the log stripe unit %d\n"),
 
 	/* If the log is too large, round down instead of round up */
 	if ((tmp_logblocks > XFS_MAX_LOG_BLOCKS) ||
-	    ((tmp_logblocks << cfg->blocklog) > XFS_MAX_LOG_BYTES)) {
+		((tmp_logblocks << cfg->blocklog) > XFS_MAX_LOG_BYTES) ||
+		(tmp_logblocks > cfg->logblocks)) {

I kinda wish you had turned all that into:

if (tmp_logblocks > XFS_MAX_LOG_BLOCKS ||

    tmp_logblocks > cfg->logblocks ||
    (tmp_logblocks << cfg->blocklog) > XFS_MAX_LOG_BYTES) {
	/* foo bar baz */
}

But otherwise the idea seems ok to me...

--D

Quoted 6 lines
mkfs/xfs_mkfs.c +0 -0
 		tmp_logblocks = (cfg->logblocks / sunit) * sunit;
 	}
 	cfg->logblocks = tmp_logblocks;
Signature · 1 line
2.19.1
#2 lore raw

PATCH v2 1/1 mkfs: Round down log device size if aligned value is larger than device size

When using a disk of size 798903808 bytes as the log device and when having a log stripe unit size of 32768, align_log_size() rounds up log device size to 195048 4k blocks i.e. 798916608. This value is larger than the device size. Hence the last call to write(2) inside libxfs_device_zero() would end up returning an error.

To fix this bug, we now round down the log device size if the newly computed size is larger than the actual log device size.

---
Changelog:
v1 -> v2:
1. Remove extraneous parenthesis around conditions.

 mkfs/xfs_mkfs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mkfs/xfs_mkfs.c +3 -2
index d1387ddf..c9e22560 100644
@@ -2937,8 +2937,9 @@ _("log size %lld is not a multiple of the log stripe unit %d\n"),
 	tmp_logblocks = ((cfg->logblocks + (sunit - 1)) / sunit) * sunit;
 
 	/* If the log is too large, round down instead of round up */
-	if ((tmp_logblocks > XFS_MAX_LOG_BLOCKS) ||
-	    ((tmp_logblocks << cfg->blocklog) > XFS_MAX_LOG_BYTES)) {
+	if (tmp_logblocks > XFS_MAX_LOG_BLOCKS ||
+	    tmp_logblocks > cfg->logblocks ||
+	    (tmp_logblocks << cfg->blocklog) > XFS_MAX_LOG_BYTES) {
 		tmp_logblocks = (cfg->logblocks / sunit) * sunit;
 	}
 	cfg->logblocks = tmp_logblocks;
Signature · 1 line
2.19.1
Reviewed-by on v2 1/1
#3 lore raw
Quoted 23 lines · Chandan Rajendra

When using a disk of size 798903808 bytes as the log device and when having a log stripe unit size of 32768, align_log_size() rounds up log device size to 195048 4k blocks i.e. 798916608. This value is larger than the device size. Hence the last call to write(2) inside libxfs_device_zero() would end up returning an error.

To fix this bug, we now round down the log device size if the newly computed size is larger than the actual log device size.

---
Changelog:
v1 -> v2:
1. Remove extraneous parenthesis around conditions.

 mkfs/xfs_mkfs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mkfs/xfs_mkfs.c +0 -0
index d1387ddf..c9e22560 100644

mkfs/xfs_mkfs.c _("log size %lld is not a multiple of the log stripe unit %d\n"), · line 2943

Quoted 9 lines
mkfs/xfs_mkfs.c +3 -2
@@ -2937,8 +2937,9 @@ _("log size %lld is not a multiple of the log stripe unit %d\n"),
 	tmp_logblocks = ((cfg->logblocks + (sunit - 1)) / sunit) * sunit;
 
 	/* If the log is too large, round down instead of round up */
-	if ((tmp_logblocks > XFS_MAX_LOG_BLOCKS) ||
-	    ((tmp_logblocks << cfg->blocklog) > XFS_MAX_LOG_BYTES)) {
+	if (tmp_logblocks > XFS_MAX_LOG_BLOCKS ||
+	    tmp_logblocks > cfg->logblocks ||
+	    (tmp_logblocks << cfg->blocklog) > XFS_MAX_LOG_BYTES) {
 		tmp_logblocks = (cfg->logblocks / sunit) * sunit;

Looks better,

--D

Quoted 5 lines
mkfs/xfs_mkfs.c +0 -0
 	}
 	cfg->logblocks = tmp_logblocks;
Signature · 1 line
2.19.1