libxfs: report device open errors during topology probing
PATCH 1/1 libxfs: report device open errors during topology probing
mkfs probes the device topology before libxfs_init opens the target. If blkid cannot open the device, blkid_new_probe_from_filename returns NULL and leaves the topology sector sizes initialized to zero. This causes mkfs to report the misleading error "illegal sector size 0".
Report the underlying open error immediately so that permission failures are diagnosed correctly. For example:
cannot probe device topology for device /dev/nvme1n1: Permission denied
--- libxfs/topology.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
libxfs/topology.c +6 -2
@@ -230,8 +230,12 @@ blkid_get_topology(blkid_probe pr; pr =blkid_new_probe_from_filename (device); -if (!pr) -return ; +if (!pr) { +fprintf (stderr, +_ ("cannot probe device topology for device %s: %s\n" ), + device,strerror (errno)); +exit (EXIT_FAILURE ); + } tp =blkid_probe_get_topology (pr);if (!tp)
Signature · 1 line
2.53.0
Quoted 9 lines · Hans Holmberg
mkfs probes the device topology before
libxfs_initopens the target. If blkid cannot open the device,blkid_new_probe_from_filenamereturns NULL and leaves the topology sector sizes initialized to zero. This causes mkfs to report the misleading error "illegal sector size 0".Report the underlying open error immediately so that permission failures are diagnosed correctly. For example:
cannot probe device topology for device
/dev/nvme1n1: Permission denied
Did you also accidentally run mkfs as a regular users? :) That's how I ran into this, but didn't get around fixing it.
Quoted 12 lines
Signed-off-by Hans Holmberg <[email protected]>--- libxfs/topology.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)libxfs/topology.c +0
-0@@ -230,8 +230,12 @@ blkid_get_topology(blkid_probe pr;
libxfs/topology.c blkid_get_topology( · line 238
Quoted 10 lines
libxfs/topology.c +6
-2pr =blkid_new_probe_from_filename (device); -if (!pr) -return ; +if (!pr) { +fprintf (stderr, +_ ("cannot probe device topology for device %s: %s\n" ), + device,strerror (errno)); +exit (EXIT_FAILURE ); + }
I wonder if there are any valid failures from blkid_new_probe_from_filename where we'd want to continue? Probably not as it doesn't really have an obvious failure path, but so far we continue here. So the print is useful for sure, but I wonder if failing here might cause regressions in some really odd use case (containers without sysfs? Although we'd run into trouble with that quickly in other places).
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Hans Holmberg
mkfs probes the device topology before
libxfs_initopens the target. If blkid cannot open the device,blkid_new_probe_from_filenamereturns NULL and leaves the topology sector sizes initialized to zero. This causes mkfs to report the misleading error "illegal sector size 0".
Quoted 7 lines
Quoted 4 lines
Report the underlying open error immediately so that permission failures are diagnosed correctly. For example:
cannot probe device topology for device
/dev/nvme1n1: Permission deniedDid you also accidentally run mkfs as a regular users? :) That's how I ran into this, but didn't get around fixing it.
Yeah, I do this all the time and became so annoyed with the wierd error message i had to fix it :)
Quoted 14 lines
Quoted 14 lines
Signed-off-by Hans Holmberg <[email protected]>--- libxfs/topology.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)libxfs/topology.c +0
-0@@ -230,8 +230,12 @@ blkid_get_topology(blkid_probe pr;
Quoted 16 lines
libxfs/topology.c blkid_get_topology( · line 238
Quoted 9 lines
libxfs/topology.c +6
-2pr =blkid_new_probe_from_filename (device); -if (!pr) -return ; +if (!pr) { +fprintf (stderr, +_ ("cannot probe device topology for device %s: %s\n" ), + device,strerror (errno)); +exit (EXIT_FAILURE ); + }I wonder if there are any valid failures from
blkid_new_probe_from_filenamewhere we'd want to continue? Probably not as it doesn't really have an obvious failure path, but so far we continue here. So the print is useful for sure, but I wonder if failing here might cause regressions in some really odd use case (containers without sysfs? Although we'd run into trouble with that quickly in other places).
Yeah, it might be safer to just print the warning, and that would solve my problem (no instructive error message),
On the other hand it's nice to fail early - but not if it causes regressions of course.
Quoted 8 lines · Hans Holmberg
Quoted 6 lines
I wonder if there are any valid failures from
blkid_new_probe_from_filenamewhere we'd want to continue? Probably not as it doesn't really have an obvious failure path, but so far we continue here. So the print is useful for sure, but I wonder if failing here might cause regressions in some really odd use case (containers without sysfs? Although we'd run into trouble with that quickly in other places).
Quoted 5 lines
Yeah, it might be safer to just print the warning, and that would solve my problem (no instructive error message),
On the other hand it's nice to fail early - but not if it causes regressions of course.
Yeah, failing early is nice, but I'm a bit fearful we might break existing (but really weird setups).
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Hans Holmberg
Quoted 6 lines
I wonder if there are any valid failures from
blkid_new_probe_from_filenamewhere we'd want to continue? Probably not as it doesn't really have an obvious failure path, but so far we continue here. So the print is useful for sure, but I wonder if failing here might cause regressions in some really odd use case (containers without sysfs? Although we'd run into trouble with that quickly in other places).
Quoted 8 lines
Quoted 5 lines
Yeah, it might be safer to just print the warning, and that would solve my problem (no instructive error message),
On the other hand it's nice to fail early - but not if it causes regressions of course.
Yeah, failing early is nice, but I'm a bit fearful we might break existing (but really weird setups).
AFAICT hidden sysfs doesn't seem to break libbkid's probing of devices:
# mount moo /sys/ -t tmpfs ; mkfs.xfs -f /dev/sda
meta-data=/dev/sda isize=512 agcount=4, agsize=644992 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=1
= reflink=1 bigtime=1 inobtcount=1 nrext64=1
= exchange=1 metadir=1
data = bsize=4096 blocks=2579968, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1, parent=1
log =internal log bsize=4096 blocks=16384, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
= rgcount=0 rgsize=268435456 extents
= zoned=0 start=0 reserved=0
Discarding blocks...Done.--D
Christoph Hellwig
Reviewed-byQuoted 1 line · Darrick J. Wong
AFAICT hidden sysfs doesn't seem to break libbkid's probing of devices:
Great. So *knocking on wood*, let's go with Hans's patch: