@@ -85,11 +85,13 @@ func (e *ContainerEdits) Apply(spec *oci.Spec) error {
8585 }
8686
8787 for _ , d := range e .DeviceNodes {
88- dev := d .ToOCI ()
89- if err := fillMissingInfo (& dev ); err != nil {
88+ dn := DeviceNode {d }
89+
90+ err := dn .fillMissingInfo ()
91+ if err != nil {
9092 return err
9193 }
92-
94+ dev := d . ToOCI ()
9395 if dev .UID == nil && spec .Process != nil {
9496 if uid := spec .Process .User .UID ; uid > 0 {
9597 dev .UID = & uid
@@ -288,26 +290,31 @@ func ensureOCIHooks(spec *oci.Spec) {
288290}
289291
290292// fillMissingInfo fills in missing mandatory attributes from the host device.
291- func fillMissingInfo (dev * oci.LinuxDevice ) error {
292- if dev .Type != "" && (dev .Major != 0 || dev .Type == "p" ) {
293+ func (d * DeviceNode ) fillMissingInfo () error {
294+ if d .HostPath == "" {
295+ d .HostPath = d .Path
296+ }
297+
298+ if d .Type != "" && (d .Major != 0 || d .Type == "p" ) {
293299 return nil
294300 }
295- hostDev , err := runc .DeviceFromPath (dev .Path , "rwm" )
301+
302+ hostDev , err := runc .DeviceFromPath (d .HostPath , "rwm" )
296303 if err != nil {
297- return errors .Wrapf (err , "failed to stat CDI host device %q" , dev . Path )
304+ return errors .Wrapf (err , "failed to stat CDI host device %q" , d . HostPath )
298305 }
299306
300- if dev .Type == "" {
301- dev .Type = string (hostDev .Type )
307+ if d .Type == "" {
308+ d .Type = string (hostDev .Type )
302309 } else {
303- if dev .Type != string (hostDev .Type ) {
304- return errors .Errorf ("CDI device %q , host type mismatch (%s, %s)" ,
305- dev .Path , dev .Type , string (hostDev .Type ))
310+ if d .Type != string (hostDev .Type ) {
311+ return errors .Errorf ("CDI device (%q, %q) , host type mismatch (%s, %s)" ,
312+ d .Path , d . HostPath , d .Type , string (hostDev .Type ))
306313 }
307314 }
308- if dev .Major == 0 && dev .Type != "p" {
309- dev .Major = hostDev .Major
310- dev .Minor = hostDev .Minor
315+ if d .Major == 0 && d .Type != "p" {
316+ d .Major = hostDev .Major
317+ d .Minor = hostDev .Minor
311318 }
312319
313320 return nil
0 commit comments