@@ -13,7 +13,6 @@ import (
1313 "regexp"
1414 "runtime"
1515 "strings"
16- "syscall"
1716 "unicode"
1817 "unicode/utf8"
1918
@@ -641,6 +640,38 @@ func (v *Validator) CheckLinux() (errs error) {
641640 errs = multierror .Append (errs , fmt .Errorf ("on Linux, hostname requires a new UTS namespace to be specified as well" ))
642641 }
643642
643+ errs = multierror .Append (errs , v .CheckLinuxDevices ())
644+
645+ if v .spec .Linux .Resources != nil {
646+ errs = multierror .Append (errs , v .CheckLinuxResources ())
647+ }
648+
649+ for _ , maskedPath := range v .spec .Linux .MaskedPaths {
650+ if ! strings .HasPrefix (maskedPath , "/" ) {
651+ errs = multierror .Append (errs ,
652+ specerror .NewError (
653+ specerror .MaskedPathsAbs ,
654+ fmt .Errorf ("maskedPath %v is not an absolute path" , maskedPath ),
655+ rspec .Version ))
656+ }
657+ }
658+
659+ for _ , readonlyPath := range v .spec .Linux .ReadonlyPaths {
660+ if ! strings .HasPrefix (readonlyPath , "/" ) {
661+ errs = multierror .Append (errs ,
662+ specerror .NewError (
663+ specerror .ReadonlyPathsAbs ,
664+ fmt .Errorf ("readonlyPath %v is not an absolute path" , readonlyPath ),
665+ rspec .Version ))
666+ }
667+ }
668+
669+ return
670+ }
671+
672+ // CheckLinuxDevices checks v.spec.LinuxDevices.
673+ func (v * Validator ) CheckLinuxDevices () (errs error ) {
674+ logrus .Debugf ("check linux.devices" )
644675 // Linux devices validation
645676 devList := make (map [string ]bool )
646677 devTypeList := make (map [string ]bool )
@@ -654,6 +685,7 @@ func (v *Validator) CheckLinux() (errs error) {
654685 errs = multierror .Append (errs , fmt .Errorf ("device %s is duplicated" , device .Path ))
655686 } else {
656687 var rootfsPath string
688+ // FIXME: use osFilepath for this
657689 if filepath .IsAbs (v .spec .Root .Path ) {
658690 rootfsPath = v .spec .Root .Path
659691 } else {
@@ -666,61 +698,7 @@ func (v *Validator) CheckLinux() (errs error) {
666698 } else if err != nil {
667699 errs = multierror .Append (errs , err )
668700 } else {
669- fStat , ok := fi .Sys ().(* syscall.Stat_t )
670- if ! ok {
671- errs = multierror .Append (errs , specerror .NewError (specerror .DevicesAvailable ,
672- fmt .Errorf ("cannot determine state for device %s" , device .Path ), rspec .Version ))
673- continue
674- }
675- var devType string
676- switch fStat .Mode & syscall .S_IFMT {
677- case syscall .S_IFCHR :
678- devType = "c"
679- case syscall .S_IFBLK :
680- devType = "b"
681- case syscall .S_IFIFO :
682- devType = "p"
683- default :
684- devType = "unmatched"
685- }
686- if devType != device .Type || (devType == "c" && device .Type == "u" ) {
687- errs = multierror .Append (errs , specerror .NewError (specerror .DevicesFileNotMatch ,
688- fmt .Errorf ("unmatched %s already exists in filesystem" , device .Path ), rspec .Version ))
689- continue
690- }
691- if devType != "p" {
692- dev := fStat .Rdev
693- major := (dev >> 8 ) & 0xfff
694- minor := (dev & 0xff ) | ((dev >> 12 ) & 0xfff00 )
695- if int64 (major ) != device .Major || int64 (minor ) != device .Minor {
696- errs = multierror .Append (errs , specerror .NewError (specerror .DevicesFileNotMatch ,
697- fmt .Errorf ("unmatched %s already exists in filesystem" , device .Path ), rspec .Version ))
698- continue
699- }
700- }
701- if device .FileMode != nil {
702- expectedPerm := * device .FileMode & os .ModePerm
703- actualPerm := fi .Mode () & os .ModePerm
704- if expectedPerm != actualPerm {
705- errs = multierror .Append (errs , specerror .NewError (specerror .DevicesFileNotMatch ,
706- fmt .Errorf ("unmatched %s already exists in filesystem" , device .Path ), rspec .Version ))
707- continue
708- }
709- }
710- if device .UID != nil {
711- if * device .UID != fStat .Uid {
712- errs = multierror .Append (errs , specerror .NewError (specerror .DevicesFileNotMatch ,
713- fmt .Errorf ("unmatched %s already exists in filesystem" , device .Path ), rspec .Version ))
714- continue
715- }
716- }
717- if device .GID != nil {
718- if * device .GID != fStat .Gid {
719- errs = multierror .Append (errs , specerror .NewError (specerror .DevicesFileNotMatch ,
720- fmt .Errorf ("unmatched %s already exists in filesystem" , device .Path ), rspec .Version ))
721- continue
722- }
723- }
701+ errs = multierror .Append (errs , v .checkPosixFilesystemDevice (& device , fi ))
724702 }
725703 }
726704
@@ -739,31 +717,7 @@ func (v *Validator) CheckLinux() (errs error) {
739717 }
740718 }
741719
742- if v .spec .Linux .Resources != nil {
743- errs = multierror .Append (errs , v .CheckLinuxResources ())
744- }
745-
746- for _ , maskedPath := range v .spec .Linux .MaskedPaths {
747- if ! strings .HasPrefix (maskedPath , "/" ) {
748- errs = multierror .Append (errs ,
749- specerror .NewError (
750- specerror .MaskedPathsAbs ,
751- fmt .Errorf ("maskedPath %v is not an absolute path" , maskedPath ),
752- rspec .Version ))
753- }
754- }
755-
756- for _ , readonlyPath := range v .spec .Linux .ReadonlyPaths {
757- if ! strings .HasPrefix (readonlyPath , "/" ) {
758- errs = multierror .Append (errs ,
759- specerror .NewError (
760- specerror .ReadonlyPathsAbs ,
761- fmt .Errorf ("readonlyPath %v is not an absolute path" , readonlyPath ),
762- rspec .Version ))
763- }
764- }
765-
766- return
720+ return errs
767721}
768722
769723// CheckLinuxResources checks v.spec.Linux.Resources
0 commit comments