Skip to content

InitDevices: handle device denied reason and PartTableType #1000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions pkg/device/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ func (d Device) Make() string {
return strings.Join(tokens, " ")
}

// PartTableType returns partition table type.
func (d Device) PartTableType() string {
return d.udevData["E:ID_PART_TABLE_TYPE"]
}

// FSType returns filesystem type.
func (d Device) FSType() string {
return d.udevData["E:ID_FS_TYPE"]
Expand All @@ -111,8 +116,8 @@ func (d Device) FSUUID() string {
return d.udevData["E:ID_FS_UUID"]
}

// deniedReason returns the reason if the device is denied for initialization.
func (d Device) deniedReason() string {
// DeniedReason returns the reason if the device is denied for initialization.
func (d Device) DeniedReason() string {
var reasons []string

if d.Size < minSupportedDeviceSize {
Expand Down Expand Up @@ -175,7 +180,7 @@ func (d Device) ToNodeDevice(nodeID directpvtypes.NodeID) types.Device {
Make: d.Make(),
FSType: d.FSType(),
FSUUID: d.FSUUID(),
DeniedReason: d.deniedReason(),
DeniedReason: d.DeniedReason(),
}
}

Expand Down
20 changes: 12 additions & 8 deletions pkg/initrequest/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,19 @@ func (handler *initRequestEventHandler) initDevices(ctx context.Context, req *ty
case !found:
results[i].Error = "device not found"
case device.ID(handler.nodeID) != req.Spec.Devices[i].ID:
results[i].Error = "device's state changed"
results[i].Error = "device state changed"
default:
wg.Add(1)
go func(i int, device pkgdevice.Device, force bool) {
defer wg.Done()
if err := handler.initDevice(device, force); err != nil {
results[i].Error = err.Error()
}
}(i, device, req.Spec.Devices[i].Force)
if deniedReason := device.DeniedReason(); deniedReason == "" {
wg.Add(1)
go func(i int, device pkgdevice.Device, force bool) {
defer wg.Done()
if err := handler.initDevice(device, force); err != nil {
results[i].Error = err.Error()
}
}(i, device, req.Spec.Devices[i].Force || device.PartTableType() != "")
} else {
results[i].Error = "device init not permitted; " + deniedReason
}
}
}
wg.Wait()
Expand Down
Loading