mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-19 16:38:00 +00:00
mount: support checking multiple kinds of block device driver
Device mapper is the only supported block device driver so far, which seems limiting. Kata Containers can work well with other block devices. It is necessary to enhance supporting of multiple kinds of host block device. Fixes #4714 Signed-off-by: yuchen.cc <yuchen.cc@alibaba-inc.com>
This commit is contained in:
parent
48e5596186
commit
1cd1558a92
@ -1319,12 +1319,12 @@ func (c *Container) hotplugDrive(ctx context.Context) error {
|
|||||||
"mount-point": dev.mountPoint,
|
"mount-point": dev.mountPoint,
|
||||||
}).Info("device details")
|
}).Info("device details")
|
||||||
|
|
||||||
isDM, err := checkStorageDriver(dev.major, dev.minor)
|
isBD, err := checkStorageDriver(dev.major, dev.minor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isDM {
|
if !isBD {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,14 +194,14 @@ func getDeviceForPath(path string) (device, error) {
|
|||||||
return dev, nil
|
return dev, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var blockFormatTemplate = "/sys/dev/block/%d:%d/dm"
|
var blockFormatTemplate = "/sys/dev/block/%d:%d/"
|
||||||
|
|
||||||
var checkStorageDriver = isDeviceMapper
|
var checkStorageDriver = isBlockDevice
|
||||||
|
|
||||||
// isDeviceMapper checks if the device with the major and minor numbers is a devicemapper block device
|
// isBlockDevice checks if the device with the major and minor numbers is a block device
|
||||||
func isDeviceMapper(major, minor int) (bool, error) {
|
func isBlockDevice(major, minor int) (bool, error) {
|
||||||
|
|
||||||
//Check if /sys/dev/block/${major}-${minor}/dm exists
|
//Check if /sys/dev/block/${major}-${minor}/ exists
|
||||||
sysPath := fmt.Sprintf(blockFormatTemplate, major, minor)
|
sysPath := fmt.Sprintf(blockFormatTemplate, major, minor)
|
||||||
|
|
||||||
_, err := os.Stat(sysPath)
|
_, err := os.Stat(sysPath)
|
||||||
@ -209,9 +209,9 @@ func isDeviceMapper(major, minor int) (bool, error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
} else if os.IsNotExist(err) {
|
} else if os.IsNotExist(err) {
|
||||||
return false, nil
|
return false, nil
|
||||||
|
} else {
|
||||||
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return false, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const mountPerm = os.FileMode(0755)
|
const mountPerm = os.FileMode(0755)
|
||||||
|
@ -305,20 +305,31 @@ func TestGetDeviceForPathValidMount(t *testing.T) {
|
|||||||
assert.Equal(dev.mountPoint, expected)
|
assert.Equal(dev.mountPoint, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsDeviceMapper(t *testing.T) {
|
func TestIsBlockDevice(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
// known major, minor for /dev/tty
|
// known major, minor for /dev/tty
|
||||||
major := 5
|
major := 5
|
||||||
minor := 0
|
minor := 0
|
||||||
|
|
||||||
isDM, err := isDeviceMapper(major, minor)
|
isBD, err := isBlockDevice(major, minor)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.False(isDM)
|
assert.False(isBD)
|
||||||
|
|
||||||
// fake the block device format
|
// fake the block device format
|
||||||
|
blockFormatTemplateOld := blockFormatTemplate
|
||||||
|
defer func() {
|
||||||
|
blockFormatTemplate = blockFormatTemplateOld
|
||||||
|
}()
|
||||||
|
|
||||||
blockFormatTemplate = "/sys/dev/char/%d:%d"
|
blockFormatTemplate = "/sys/dev/char/%d:%d"
|
||||||
isDM, err = isDeviceMapper(major, minor)
|
isBD, err = isBlockDevice(major, minor)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.True(isDM)
|
assert.True(isBD)
|
||||||
|
|
||||||
|
// invalid template
|
||||||
|
blockFormatTemplate = "\000/sys/dev/char/%d:%d"
|
||||||
|
isBD, err = isBlockDevice(major, minor)
|
||||||
|
assert.Error(err)
|
||||||
|
assert.False(isBD)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user