Skip to content

Commit 52bec59

Browse files
authored
Merge pull request #28 from threefoldtech/main_exclude_pxe_device
exclude devices labeled zospxe while booting
2 parents 0a81fa1 + 5e82a32 commit 52bec59

File tree

3 files changed

+69
-40
lines changed

3 files changed

+69
-40
lines changed

pkg/storage/filesystem/btrfs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (p *btrfsPool) Device() DeviceInfo {
5353
}
5454

5555
func (p *btrfsPool) prepare() error {
56-
p.name = p.device.Label
56+
p.name = p.device.UUID
5757
if p.device.Used() {
5858
// device already have filesystem
5959
return nil

pkg/storage/filesystem/device.go

+16-7
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ type blockDevices struct {
5151
type DeviceInfo struct {
5252
mgr DeviceManager
5353

54-
Path string `json:"path"`
55-
Label string `json:"label"`
56-
Size uint64 `json:"size"`
57-
Filesystem FSType `json:"fstype"`
58-
Rota bool `json:"rota"`
59-
Subsystems string `json:"subsystems"`
54+
Path string `json:"path"`
55+
Label string `json:"label"`
56+
Size uint64 `json:"size"`
57+
Filesystem FSType `json:"fstype"`
58+
Rota bool `json:"rota"`
59+
Subsystems string `json:"subsystems"`
60+
UUID string `json:"uuid"`
61+
Children []DeviceInfo `json:"children,omitempty"`
6062
}
6163

6264
func (i *DeviceInfo) Name() string {
@@ -77,6 +79,10 @@ func (d *DeviceInfo) Mountpoint(ctx context.Context) (string, error) {
7779
return d.mgr.Mountpoint(ctx, d.Path)
7880
}
7981

82+
func (d *DeviceInfo) IsPXEPartition() bool {
83+
return d.Label == "ZOSPXE"
84+
}
85+
8086
// lsblkDeviceManager uses the lsblk utility to scann the disk for devices, and
8187
// caches the result.
8288
//
@@ -163,7 +169,7 @@ func (l *lsblkDeviceManager) lsblk(ctx context.Context) ([]DeviceInfo, error) {
163169
args := []string{
164170
"--json",
165171
"-o",
166-
"PATH,NAME,SIZE,SUBSYSTEMS,FSTYPE,LABEL,ROTA",
172+
"PATH,NAME,SIZE,SUBSYSTEMS,FSTYPE,LABEL,ROTA,UUID",
167173
"--bytes",
168174
"--exclude",
169175
"1,2,11",
@@ -187,6 +193,9 @@ func (l *lsblkDeviceManager) lsblk(ctx context.Context) ([]DeviceInfo, error) {
187193

188194
for i := range devices.BlockDevices {
189195
devices.BlockDevices[i].mgr = l
196+
for j := range devices.BlockDevices[i].Children {
197+
devices.BlockDevices[i].Children[j].mgr = l
198+
}
190199
}
191200

192201
return devices.BlockDevices, nil

pkg/storage/storage.go

+52-32
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,53 @@ func (s *Module) poolType(pool filesystem.Pool, vm bool) (zos.DeviceType, error)
195195
return typ, nil
196196
}
197197

198+
func (s *Module) mountPool(device filesystem.DeviceInfo, vm bool) {
199+
log.Debug().Str("path", device.Path).Msg("mounting device")
200+
201+
if device.IsPXEPartition() {
202+
log.Info().Str("device", device.Path).Msg("device has 'ZOSPXE' label")
203+
s.brokenDevices = append(s.brokenDevices, pkg.BrokenDevice{Path: device.Path, Err: fmt.Errorf("device is a PXE partition")})
204+
return
205+
}
206+
207+
pool, err := filesystem.NewBtrfsPool(device)
208+
if err != nil {
209+
log.Error().Err(err).Str("device", device.Path).Msg("failed to create pool on device")
210+
s.brokenDevices = append(s.brokenDevices, pkg.BrokenDevice{Path: device.Path, Err: err})
211+
return
212+
}
213+
214+
_, err = pool.Mount()
215+
if err != nil {
216+
log.Error().Err(err).Str("device", device.Path).Msg("failed to mount pool")
217+
s.brokenPools = append(s.brokenPools, pkg.BrokenPool{Label: pool.Name(), Err: err})
218+
return
219+
}
220+
221+
usage, err := pool.Usage()
222+
if err != nil {
223+
log.Error().Err(err).Str("pool", pool.Name()).Str("device", device.Path).Msg("failed to get usage of pool")
224+
}
225+
226+
typ, err := s.poolType(pool, vm)
227+
if err != nil {
228+
log.Error().Str("device", device.Path).Err(err).Msg("failed to get device type")
229+
s.brokenDevices = append(s.brokenDevices, pkg.BrokenDevice{Path: device.Path, Err: err})
230+
return
231+
}
232+
233+
switch typ {
234+
case zos.SSDDevice:
235+
s.totalSSD += usage.Size
236+
s.ssds = append(s.ssds, pool)
237+
case zos.HDDDevice:
238+
s.totalHDD += usage.Size
239+
s.hdds = append(s.hdds, pool)
240+
default:
241+
log.Error().Str("type", string(typ)).Str("device", device.Path).Msg("unknown device type")
242+
}
243+
}
244+
198245
/*
199246
*
200247
initialize, must be called at least onetime each boot.
@@ -226,41 +273,14 @@ func (s *Module) initialize(ctx context.Context) error {
226273

227274
for _, device := range devices {
228275
log.Debug().Msgf("device: %+v", device)
229-
pool, err := filesystem.NewBtrfsPool(device)
230-
if err != nil {
231-
log.Error().Err(err).Str("device", device.Path).Msg("failed to create pool on device")
232-
s.brokenDevices = append(s.brokenDevices, pkg.BrokenDevice{Path: device.Path, Err: err})
233-
continue
234-
}
235-
236-
_, err = pool.Mount()
237-
if err != nil {
238-
log.Error().Err(err).Str("device", device.Path).Msg("failed to mount pool")
239-
s.brokenPools = append(s.brokenPools, pkg.BrokenPool{Label: pool.Name(), Err: err})
240-
continue
241-
}
242-
usage, err := pool.Usage()
243-
if err != nil {
244-
log.Error().Err(err).Str("pool", pool.Name()).Str("device", device.Path).Msg("failed to get usage of pool")
245-
}
246276

247-
typ, err := s.poolType(pool, vm)
248-
if err != nil {
249-
log.Error().Str("device", device.Path).Err(err).Msg("failed to get device type")
250-
s.brokenDevices = append(s.brokenDevices, pkg.BrokenDevice{Path: device.Path, Err: err})
277+
if len(device.Children) != 0 {
278+
for _, part := range device.Children {
279+
s.mountPool(part, vm)
280+
}
251281
continue
252282
}
253-
254-
switch typ {
255-
case zos.SSDDevice:
256-
s.totalSSD += usage.Size
257-
s.ssds = append(s.ssds, pool)
258-
case zos.HDDDevice:
259-
s.totalHDD += usage.Size
260-
s.hdds = append(s.hdds, pool)
261-
default:
262-
log.Error().Str("type", string(typ)).Str("device", device.Path).Msg("unknown device type")
263-
}
283+
s.mountPool(device, vm)
264284
}
265285

266286
log.Info().

0 commit comments

Comments
 (0)