Skip to content

Commit 7433145

Browse files
committed
InitDevices: handle device denied reason and PartTableType
* Return error if denied device is passed * Use force flag if device PartTableType is set Signed-off-by: Bala.FA <[email protected]>
1 parent 8f8e033 commit 7433145

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

pkg/device/probe.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ func (d Device) Make() string {
101101
return strings.Join(tokens, " ")
102102
}
103103

104+
// PartTableType returns partition table type.
105+
func (d Device) PartTableType() string {
106+
return d.udevData["E:ID_PART_TABLE_TYPE"]
107+
}
108+
104109
// FSType returns filesystem type.
105110
func (d Device) FSType() string {
106111
return d.udevData["E:ID_FS_TYPE"]
@@ -111,8 +116,8 @@ func (d Device) FSUUID() string {
111116
return d.udevData["E:ID_FS_UUID"]
112117
}
113118

114-
// deniedReason returns the reason if the device is denied for initialization.
115-
func (d Device) deniedReason() string {
119+
// DeniedReason returns the reason if the device is denied for initialization.
120+
func (d Device) DeniedReason() string {
116121
var reasons []string
117122

118123
if d.Size < minSupportedDeviceSize {
@@ -175,7 +180,7 @@ func (d Device) ToNodeDevice(nodeID directpvtypes.NodeID) types.Device {
175180
Make: d.Make(),
176181
FSType: d.FSType(),
177182
FSUUID: d.FSUUID(),
178-
DeniedReason: d.deniedReason(),
183+
DeniedReason: d.DeniedReason(),
179184
}
180185
}
181186

pkg/initrequest/event.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,19 @@ func (handler *initRequestEventHandler) initDevices(ctx context.Context, req *ty
191191
case !found:
192192
results[i].Error = "device not found"
193193
case device.ID(handler.nodeID) != req.Spec.Devices[i].ID:
194-
results[i].Error = "device's state changed"
194+
results[i].Error = "device state changed"
195195
default:
196-
wg.Add(1)
197-
go func(i int, device pkgdevice.Device, force bool) {
198-
defer wg.Done()
199-
if err := handler.initDevice(device, force); err != nil {
200-
results[i].Error = err.Error()
201-
}
202-
}(i, device, req.Spec.Devices[i].Force)
196+
if deniedReason := device.DeniedReason(); deniedReason == "" {
197+
wg.Add(1)
198+
go func(i int, device pkgdevice.Device, force bool) {
199+
defer wg.Done()
200+
if err := handler.initDevice(device, force); err != nil {
201+
results[i].Error = err.Error()
202+
}
203+
}(i, device, req.Spec.Devices[i].Force || device.PartTableType() != "")
204+
} else {
205+
results[i].Error = "device init not permitted; " + deniedReason
206+
}
203207
}
204208
}
205209
wg.Wait()

0 commit comments

Comments
 (0)