Skip to content

Commit cc3f4be

Browse files
author
Ma Shimiao
committed
validate: enhance linux devices validation
duplicated device path is invalid duplicated type and major:minor is not recommended Signed-off-by: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>
1 parent f3499f2 commit cc3f4be

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

validate/validate.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,24 @@ func (v *Validator) CheckLinux() (msgs []string) {
356356
msgs = append(msgs, fmt.Sprintf("On Linux, hostname requires a new UTS namespace to be specified as well"))
357357
}
358358

359+
// Linux devices validation
360+
devList := make(map[string]bool)
361+
typeList := make(map[string]string)
359362
for index := 0; index < len(v.spec.Linux.Devices); index++ {
360-
if !deviceValid(v.spec.Linux.Devices[index]) {
361-
msgs = append(msgs, fmt.Sprintf("device %v is invalid.", v.spec.Linux.Devices[index]))
363+
device := v.spec.Linux.Devices[index]
364+
if !deviceValid(device) {
365+
msgs = append(msgs, fmt.Sprintf("device %v is invalid.", device))
366+
}
367+
if _, exists := devList[device.Path]; exists {
368+
msgs = append(msgs, fmt.Sprintf("device %s is duplicated", device.Path))
369+
} else {
370+
devList[device.Path] = true
371+
}
372+
devId := fmt.Sprintf("%d:%d", device.Major, device.Minor)
373+
if existId, exists := typeList[device.Type]; exists && existId == devId {
374+
logrus.Warnf("type: %s, major:%d and minor:%d for linux devices is duplicated", device.Type, device.Major, device.Minor)
375+
} else {
376+
typeList[device.Type] = devId
362377
}
363378
}
364379

0 commit comments

Comments
 (0)