[PATCH] mkfs.xfs: sanity check stripe geometry from blkid

Eric Sandeen
2020-05-15T19:14:24Z

We validate commandline options for stripe unit and stripe width, and
if a device returns nonsensical values via libblkid, the superbock write
verifier will eventually catch it and fail (noisily and cryptically) but
it seems a bit cleaner to just do a basic sanity check on the numbers
as soon as we get them from blkid, and if they're bogus, ignore them from
the start.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

diff --git a/libfrog/topology.c b/libfrog/topology.c
index b1b470c9..38ed03b7 100644
--- a/libfrog/topology.c
+++ b/libfrog/topology.c
@@ -213,6 +213,19 @@ static void blkid_get_topology(
val = blkid_topology_get_optimal_io_size(tp);
*swidth = val;

+ /*
+ * Occasionally, firmware is broken and returns optimal < minimum,
+ * or optimal which is not a multiple of minimum.
+ * In that case just give up and set both to zero, we can't trust
+ * information from this device. Similar to xfs_validate_sb_common().
+ */
+ if (*sunit) {
+ if ((*sunit > *swidth) || (*swidth % *sunit != 0)) {
+ *sunit = 0;
+ *swidth = 0;
+ }
+ }
+
/*
* If the reported values are the same as the physical sector size
* do not bother to report anything. It will only cause warnings