Skip to content

Commit

Permalink
ios: Fix handling of devices with empty physical_block_size
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Wilson <[email protected]>
  • Loading branch information
aaronnw committed Aug 28, 2024
1 parent 595e262 commit f8fd327
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions ios/dutils_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ type (
BlockDevices []*blockDev
)

var (
errEmptyPhysBlock = errors.New("empty physical block size")
)

func (bd *blockDev) MarshalJSON() ([]byte, error) {
l := len(bd.children)
if l == 0 {
Expand All @@ -67,6 +71,14 @@ func (bd *blockDev) MarshalJSON() ([]byte, error) {
return cos.UnsafeB(s), nil
}

func _dump(blockDevs BlockDevices) {
dump, _ := jsoniter.MarshalIndent(blockDevs, "", " ") // (custom MarshalJSON above)
s := strings.Repeat("=", 32)
nlog.Infoln("Begin dump block devices", s)
nlog.Infoln(string(dump))
nlog.Infoln("End dump block devices ", s)
}

// fs2disks retrieves the underlying disk or disks; it may return multiple disks
// but only if the filesystem is RAID; it is called upon adding/enabling mountpath.
// NOTE: blockDevs here are not nil only at startup - see fs.New()
Expand All @@ -91,6 +103,10 @@ func fs2disks(mpath, fs string, label Label, blockDevs BlockDevices, num int, te
return disks, nil // unit tests
}

if cmn.Rom.FastV(4, cos.SmoduleIOS) {
_dump(blockDevs)
}

switch {
case len(disks) > 0:
s := disks._str()
Expand All @@ -102,11 +118,7 @@ func fs2disks(mpath, fs string, label Label, blockDevs BlockDevices, num int, te
e := errors.New("empty label implies _resolvable_ underlying disk (" + trimmedFS + ")")
err = cmn.NewErrMpathNoDisks(mpath, fs, e)
nlog.Errorln(err)
dump, _ := jsoniter.MarshalIndent(blockDevs, "", " ") // (custom MarshalJSON above)
s := strings.Repeat("=", 32)
nlog.Infoln("Begin dump block devices", s)
nlog.Infoln(string(dump))
nlog.Infoln("End dump block devices ", s)
_dump(blockDevs)
default:
nlog.Infoln("No disks for", fs, "[", trimmedFS, label, "]")
}
Expand Down Expand Up @@ -192,11 +204,17 @@ func _lsblk(parentDir string, parent *blockDev) (BlockDevices, error) {
// Try to read block size of this device/partition.
blksize, err := _readAny[int64](filepath.Join(devDirPath, "queue", "physical_block_size"))
if err != nil {
if !errors.Is(err, fs.ErrNotExist) || parent == nil {
switch {
case err == errEmptyPhysBlock:
// Empty physical_block_size file -- likely not a block device, proceed to next entry
continue
case errors.Is(err, fs.ErrNotExist) && parent != nil:
// Inherit value from parent if physical_block_size file does not exist
blksize = parent.blksize
default:
// Real error when reading
return nil, err
}
// If `physical_block_size` file doesn't exist then we should inherit value from parent.
blksize = parent.blksize
}

bd := &blockDev{
Expand Down Expand Up @@ -232,6 +250,9 @@ func _readAny[T any](path string) (value T, err error) {
case string:
return any(strings.TrimSpace(string(data))).(T), nil
case int64:
if len(data) == 0 {
return value, errEmptyPhysBlock
}
v, err := strconv.ParseInt(strings.TrimSpace(string(data)), 10, 64)
if err != nil {
return value, fmt.Errorf("_readAny: failed to parse %q, err: %w", path, err)
Expand Down

0 comments on commit f8fd327

Please sign in to comment.