Skip to content

Commit d1b9a5d

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 d1b9a5d

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

validate/validate.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,33 @@ 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]bool)
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+
368+
if _, exists := devList[device.Path]; exists {
369+
msgs = append(msgs, fmt.Sprintf("device %s is duplicated", device.Path))
370+
} else {
371+
devList[device.Path] = true
372+
}
373+
374+
// unify u->c when comparing, they are synonyms
375+
var devId string
376+
if device.Type == "u" {
377+
devId = fmt.Sprintf("%s:%d:%d", "c", device.Major, device.Minor)
378+
} else {
379+
devId = fmt.Sprintf("%s:%d:%d", device.Type, device.Major, device.Minor)
380+
}
381+
382+
if _, exists := typeList[devId]; exists {
383+
logrus.Warnf("type:%s, major:%d and minor:%d for linux devices is duplicated", device.Type, device.Major, device.Minor)
384+
} else {
385+
typeList[devId] = true
362386
}
363387
}
364388

0 commit comments

Comments
 (0)