Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
agent: update resources list with the right device major-minor number
Browse files Browse the repository at this point in the history
Host device's major-minor numbers are mapped to guest major-minor numbers,
for example in the host the major-minor number for /dev/loop0p1 is 259:1,
when it's attached to the VM now the major-minor number is 8:0, these
conversion must be reflected in devices and resources lists, the first list
is used to mount the device in the container and the second one is to update
the devices cgroup.

fixes #351

Signed-off-by: Julio Montes <julio.montes@intel.com>
  • Loading branch information
Julio Montes committed Aug 31, 2018
1 parent 5765593 commit 3b6cced
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,28 @@ func updateSpecDeviceList(device pb.Device, spec *pb.Spec) error {
// Update the spec
for idx, d := range spec.Linux.Devices {
if d.Path == device.ContainerPath {
hostMajor := spec.Linux.Devices[idx].Major
hostMinor := spec.Linux.Devices[idx].Minor
agentLog.WithFields(logrus.Fields{
"device-path": device.VmPath,
"host-device-major": spec.Linux.Devices[idx].Major,
"host-device-minor": spec.Linux.Devices[idx].Minor,
"host-device-major": hostMajor,
"host-device-minor": hostMinor,
"guest-device-major": major,
"guest-device-minor": minor,
}).Info("updating block device major/minor into the spec")

spec.Linux.Devices[idx].Major = major
spec.Linux.Devices[idx].Minor = minor

// Resources MUST BE updated since they are used to identify the
// device in the devices cgrup
for idxRsrc, dRsrc := range spec.Linux.Resources.Devices {
if dRsrc.Major == hostMajor && dRsrc.Minor == hostMinor {
spec.Linux.Resources.Devices[idxRsrc].Major = major
spec.Linux.Resources.Devices[idxRsrc].Minor = minor
}
}

return nil
}
}
Expand Down

0 comments on commit 3b6cced

Please # to comment.