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

Commit

Permalink
newContainer: Not attach device if it is a CDROM
Browse files Browse the repository at this point in the history
Got "docker: Error response from daemon: OCI runtime create failed:
QMP command failed: unknown." when "docker run --privileged" with kata.
In qemu part, it got:
"Could not open '/dev/sr0': Read-only file system"
or
"No medium found"
The cause is qemu need open block device to get its status.
But /dev/sr0 is a CDROM that cannot be opened.

This patch let newContainer doesn't attach device if it is a CDROM
to handle the issue.

Fixes #829

Signed-off-by: Hui Zhu <[email protected]>
  • Loading branch information
teawater committed Oct 30, 2018
1 parent 58ce1b8 commit f895466
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions virtcontainers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ import (
"github.com/kata-containers/runtime/virtcontainers/utils"
)

var cDROMMajors = map[int64]string{
11: "SCSI_CDROM_MAJOR",
15: "CDU31A_CDROM_MAJOR",
16: "GOLDSTAR_CDROM_MAJOR",
17: "OPTICS_CDROM_MAJOR",
18: "SANYO_CDROM_MAJOR",
20: "MITSUMI_X_CDROM_MAJOR",
23: "MITSUMI_CDROM_MAJOR",
24: "CDU535_CDROM_MAJOR",
25: "MATSUSHITA_CDROM_MAJOR",
26: "MATSUSHITA_CDROM2_MAJOR",
27: "MATSUSHITA_CDROM3_MAJOR",
28: "MATSUSHITA_CDROM4_MAJOR",
29: "AZTECH_CDROM_MAJOR",
32: "CM206_CDROM_MAJOR",
}

// Process gathers data related to a container process.
type Process struct {
// Token is the process execution context ID. It must be
Expand Down Expand Up @@ -598,9 +615,7 @@ func newContainer(sandbox *Sandbox, contConfig ContainerConfig) (*Container, err
// Devices will be found in storage after create stage has completed.
// We fetch devices from storage at all other stages.
storedDevices, err := c.fetchDevices()
if err == nil {
c.devices = storedDevices
} else {
if err != nil {
// If devices were not found in storage, create Device implementations
// from the configuration. This should happen at create.
for _, info := range contConfig.DeviceInfos {
Expand All @@ -609,12 +624,22 @@ func newContainer(sandbox *Sandbox, contConfig ContainerConfig) (*Container, err
return &Container{}, err
}

c.devices = append(c.devices, ContainerDevice{
storedDevices = append(storedDevices, ContainerDevice{
ID: dev.DeviceID(),
ContainerPath: info.ContainerPath,
})
}
}
for _, dev := range storedDevices {
major,_ := sandbox.devManager.GetDeviceByID(dev.ID).GetMajorMinor()
if _, ok := cDROMMajors[major]; ok {
c.Logger().WithFields(logrus.Fields{
"device": dev.ContainerPath,
}).Info("Not attach device because it is a CDROM")
continue
}
c.devices = append(c.devices, dev)
}

return c, nil
}
Expand Down

0 comments on commit f895466

Please sign in to comment.