Skip to content

Commit

Permalink
- list partitions in devices
Browse files Browse the repository at this point in the history
- include the zospxe check for partitions as well
  • Loading branch information
Omarabdul3ziz committed Dec 2, 2024
1 parent 6ee91c9 commit 6117a0f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 45 deletions.
20 changes: 14 additions & 6 deletions pkg/storage/filesystem/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ type blockDevices struct {
type DeviceInfo struct {
mgr DeviceManager

Path string `json:"path"`
Label string `json:"label"`
Size uint64 `json:"size"`
Filesystem FSType `json:"fstype"`
Rota bool `json:"rota"`
Subsystems string `json:"subsystems"`
Path string `json:"path"`
Label string `json:"label"`
Size uint64 `json:"size"`
Filesystem FSType `json:"fstype"`
Rota bool `json:"rota"`
Subsystems string `json:"subsystems"`
Children []DeviceInfo `json:"children,omitempty"`
}

func (i *DeviceInfo) Name() string {
Expand All @@ -77,6 +78,10 @@ func (d *DeviceInfo) Mountpoint(ctx context.Context) (string, error) {
return d.mgr.Mountpoint(ctx, d.Path)
}

func (d *DeviceInfo) IsPXEPartition() bool {
return d.Label == "ZOSPXE"
}

// lsblkDeviceManager uses the lsblk utility to scann the disk for devices, and
// caches the result.
//
Expand Down Expand Up @@ -187,6 +192,9 @@ func (l *lsblkDeviceManager) lsblk(ctx context.Context) ([]DeviceInfo, error) {

for i := range devices.BlockDevices {
devices.BlockDevices[i].mgr = l
for j := range devices.BlockDevices[i].Children {
devices.BlockDevices[i].Children[j].mgr = l
}
}

return devices.BlockDevices, nil
Expand Down
91 changes: 52 additions & 39 deletions pkg/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,53 @@ func (s *Module) poolType(pool filesystem.Pool, vm bool) (zos.DeviceType, error)
return typ, nil
}

func (s *Module) mountPool(device filesystem.DeviceInfo, vm bool) {
log.Debug().Str("path", device.Path).Msg("mounting device")

if device.IsPXEPartition() {
log.Error().Str("device", device.Path).Msg("device has 'zospxe' label")
s.brokenDevices = append(s.brokenDevices, pkg.BrokenDevice{Path: device.Path, Err: fmt.Errorf("device is a PXE partition")})
return
}

pool, err := filesystem.NewBtrfsPool(device)
if err != nil {
log.Error().Err(err).Str("device", device.Path).Msg("failed to create pool on device")
s.brokenDevices = append(s.brokenDevices, pkg.BrokenDevice{Path: device.Path, Err: err})
return
}

_, err = pool.Mount()
if err != nil {
log.Error().Err(err).Str("device", device.Path).Msg("failed to mount pool")
s.brokenPools = append(s.brokenPools, pkg.BrokenPool{Label: pool.Name(), Err: err})
return
}

usage, err := pool.Usage()
if err != nil {
log.Error().Err(err).Str("pool", pool.Name()).Str("device", device.Path).Msg("failed to get usage of pool")
}

typ, err := s.poolType(pool, vm)
if err != nil {
log.Error().Str("device", device.Path).Err(err).Msg("failed to get device type")
s.brokenDevices = append(s.brokenDevices, pkg.BrokenDevice{Path: device.Path, Err: err})
return
}

switch typ {
case zos.SSDDevice:
s.totalSSD += usage.Size
s.ssds = append(s.ssds, pool)
case zos.HDDDevice:
s.totalHDD += usage.Size
s.hdds = append(s.hdds, pool)
default:
log.Error().Str("type", string(typ)).Str("device", device.Path).Msg("unknown device type")
}
}

/*
*
initialize, must be called at least onetime each boot.
Expand Down Expand Up @@ -229,47 +276,13 @@ func (s *Module) initialize(ctx context.Context) error {
for _, device := range devices {
log.Debug().Msgf("device: %+v", device)

if device.Label == PXELABEL {
log.Error().Err(err).Str("device", device.Path).Msg("device has 'zospxe' label")
s.brokenDevices = append(s.brokenDevices, pkg.BrokenDevice{Path: device.Path, Err: err})
continue
}

pool, err := filesystem.NewBtrfsPool(device)
if err != nil {
log.Error().Err(err).Str("device", device.Path).Msg("failed to create pool on device")
s.brokenDevices = append(s.brokenDevices, pkg.BrokenDevice{Path: device.Path, Err: err})
continue
}

_, err = pool.Mount()
if err != nil {
log.Error().Err(err).Str("device", device.Path).Msg("failed to mount pool")
s.brokenPools = append(s.brokenPools, pkg.BrokenPool{Label: pool.Name(), Err: err})
continue
}
usage, err := pool.Usage()
if err != nil {
log.Error().Err(err).Str("pool", pool.Name()).Str("device", device.Path).Msg("failed to get usage of pool")
}

typ, err := s.poolType(pool, vm)
if err != nil {
log.Error().Str("device", device.Path).Err(err).Msg("failed to get device type")
s.brokenDevices = append(s.brokenDevices, pkg.BrokenDevice{Path: device.Path, Err: err})
if len(device.Children) != 0 {
for _, part := range device.Children {
s.mountPool(part, vm)
}
continue
}

switch typ {
case zos.SSDDevice:
s.totalSSD += usage.Size
s.ssds = append(s.ssds, pool)
case zos.HDDDevice:
s.totalHDD += usage.Size
s.hdds = append(s.hdds, pool)
default:
log.Error().Str("type", string(typ)).Str("device", device.Path).Msg("unknown device type")
}
s.mountPool(device, vm)
}

log.Info().
Expand Down

0 comments on commit 6117a0f

Please sign in to comment.