Skip to content

Commit 7dad8a3

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 7dad8a3

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

.github/workflows/functests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
strategy:
2222
matrix:
2323
kube-version: ['v1.20.15', 'v1.21.14', 'v1.22.17', 'v1.23.17', 'v1.24.17', 'v1.25.16', 'v1.26.15', 'v1.27.16', 'v1.28.15', 'v1.29.14', 'v1.30.10', 'v1.31.6', 'v1.32.2']
24-
os: [ubuntu-20.04, ubuntu-22.04]
24+
os: [ubuntu-22.04, ubuntu-24.04]
2525

2626
steps:
2727
- uses: actions/checkout@v4

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)