mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-21 21:18:54 +00:00
virtcontainers: reimplement createBlockDevices
Reimplement `createBlockDevices` to identify possible volumes that can be used as pmem devices Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
parent
abbdf078cd
commit
84e0ee13c8
@ -643,6 +643,11 @@ func filterDevices(c *Container, devices []ContainerDevice) (ret []ContainerDevi
|
||||
}
|
||||
|
||||
func (c *Container) createBlockDevices() error {
|
||||
if !c.checkBlockDeviceSupport() {
|
||||
c.Logger().Warn("Block device not supported")
|
||||
return nil
|
||||
}
|
||||
|
||||
// iterate all mounts and create block device if it's block based.
|
||||
for i, m := range c.mounts {
|
||||
if len(m.BlockDeviceID) > 0 || m.Type != "bind" {
|
||||
@ -657,18 +662,36 @@ func (c *Container) createBlockDevices() error {
|
||||
return fmt.Errorf("stat %q failed: %v", m.Source, err)
|
||||
}
|
||||
|
||||
var di *config.DeviceInfo
|
||||
var err error
|
||||
|
||||
// Check if mount is a block device file. If it is, the block device will be attached to the host
|
||||
// instead of passing this as a shared mount.
|
||||
if c.checkBlockDeviceSupport() && stat.Mode&unix.S_IFBLK == unix.S_IFBLK {
|
||||
b, err := c.sandbox.devManager.NewDevice(config.DeviceInfo{
|
||||
if stat.Mode&unix.S_IFBLK == unix.S_IFBLK {
|
||||
di = &config.DeviceInfo{
|
||||
HostPath: m.Source,
|
||||
ContainerPath: m.Destination,
|
||||
DevType: "b",
|
||||
Major: int64(unix.Major(stat.Rdev)),
|
||||
Minor: int64(unix.Minor(stat.Rdev)),
|
||||
})
|
||||
}
|
||||
// check whether source can be used as a pmem device
|
||||
} else if di, err = config.PmemDeviceInfo(m.Source, m.Destination); err != nil {
|
||||
c.Logger().WithError(err).
|
||||
WithField("mount-source", m.Source).
|
||||
Debug("no loop device")
|
||||
}
|
||||
|
||||
if err == nil && di != nil {
|
||||
b, err := c.sandbox.devManager.NewDevice(*di)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("device manager failed to create new device for %q: %v", m.Source, err)
|
||||
// Do not return an error, try to create
|
||||
// devices for other mounts
|
||||
c.Logger().WithError(err).WithField("mount-source", m.Source).
|
||||
Error("device manager failed to create new device")
|
||||
continue
|
||||
|
||||
}
|
||||
|
||||
c.mounts[i].BlockDeviceID = b.DeviceID()
|
||||
|
@ -98,11 +98,15 @@ func (dm *deviceManager) findDeviceByMajorMinor(major, minor int64) api.Device {
|
||||
|
||||
// createDevice creates one device based on DeviceInfo
|
||||
func (dm *deviceManager) createDevice(devInfo config.DeviceInfo) (dev api.Device, err error) {
|
||||
path, err := config.GetHostPathFunc(devInfo, dm.vhostUserStoreEnabled, dm.vhostUserStorePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
// pmem device may points to block devices or raw files,
|
||||
// do not change its HostPath.
|
||||
if !devInfo.Pmem {
|
||||
path, err := config.GetHostPathFunc(devInfo, dm.vhostUserStoreEnabled, dm.vhostUserStorePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
devInfo.HostPath = path
|
||||
}
|
||||
devInfo.HostPath = path
|
||||
|
||||
defer func() {
|
||||
if err == nil {
|
||||
@ -119,7 +123,7 @@ func (dm *deviceManager) createDevice(devInfo config.DeviceInfo) (dev api.Device
|
||||
if devInfo.ID, err = dm.newDeviceID(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if isVFIO(path) {
|
||||
if isVFIO(devInfo.HostPath) {
|
||||
return drivers.NewVFIODevice(&devInfo), nil
|
||||
} else if isVhostUserBlk(devInfo) {
|
||||
if devInfo.DriverOptions == nil {
|
||||
@ -134,7 +138,7 @@ func (dm *deviceManager) createDevice(devInfo config.DeviceInfo) (dev api.Device
|
||||
devInfo.DriverOptions["block-driver"] = dm.blockDriver
|
||||
return drivers.NewBlockDevice(&devInfo), nil
|
||||
} else {
|
||||
deviceLogger().WithField("device", path).Info("Device has not been passed to the container")
|
||||
deviceLogger().WithField("device", devInfo.HostPath).Info("Device has not been passed to the container")
|
||||
return drivers.NewGenericDevice(&devInfo), nil
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user