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