mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-27 15:57:09 +00:00
runtime: virtcontainers: vhost-user-blk/scsi are block device nodes
When checking if a device is an emulated vhost-user-blk or vhost-user-scsi one, we should not only check for their major number but also their device node type. They must be block devices. Fixes: #401 Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
b9f0f57f1a
commit
1c56abb761
@ -139,10 +139,10 @@ func isLargeBarSpace(resourcePath string) (bool, error) {
|
|||||||
|
|
||||||
// isVhostUserBlk checks if the device is a VhostUserBlk device.
|
// isVhostUserBlk checks if the device is a VhostUserBlk device.
|
||||||
func isVhostUserBlk(devInfo config.DeviceInfo) bool {
|
func isVhostUserBlk(devInfo config.DeviceInfo) bool {
|
||||||
return devInfo.Major == config.VhostUserBlkMajor
|
return devInfo.DevType == "b" && devInfo.Major == config.VhostUserBlkMajor
|
||||||
}
|
}
|
||||||
|
|
||||||
// isVhostUserSCSI checks if the device is a VhostUserSCSI device.
|
// isVhostUserSCSI checks if the device is a VhostUserSCSI device.
|
||||||
func isVhostUserSCSI(devInfo config.DeviceInfo) bool {
|
func isVhostUserSCSI(devInfo config.DeviceInfo) bool {
|
||||||
return devInfo.Major == config.VhostUserSCSIMajor
|
return devInfo.DevType == "b" && devInfo.Major == config.VhostUserSCSIMajor
|
||||||
}
|
}
|
||||||
|
@ -58,36 +58,50 @@ func TestIsBlock(t *testing.T) {
|
|||||||
|
|
||||||
func TestIsVhostUserBlk(t *testing.T) {
|
func TestIsVhostUserBlk(t *testing.T) {
|
||||||
type testData struct {
|
type testData struct {
|
||||||
|
devType string
|
||||||
major int64
|
major int64
|
||||||
expected bool
|
expected bool
|
||||||
}
|
}
|
||||||
|
|
||||||
data := []testData{
|
data := []testData{
|
||||||
{config.VhostUserBlkMajor, true},
|
{"b", config.VhostUserBlkMajor, true},
|
||||||
{config.VhostUserSCSIMajor, false},
|
{"c", config.VhostUserBlkMajor, false},
|
||||||
{240, false},
|
{"b", config.VhostUserSCSIMajor, false},
|
||||||
|
{"c", config.VhostUserSCSIMajor, false},
|
||||||
|
{"b", 240, false},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, d := range data {
|
for _, d := range data {
|
||||||
isVhostUserBlk := isVhostUserBlk(config.DeviceInfo{Major: d.major})
|
isVhostUserBlk := isVhostUserBlk(
|
||||||
|
config.DeviceInfo{
|
||||||
|
DevType: d.devType,
|
||||||
|
Major: d.major,
|
||||||
|
})
|
||||||
assert.Equal(t, d.expected, isVhostUserBlk)
|
assert.Equal(t, d.expected, isVhostUserBlk)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsVhostUserSCSI(t *testing.T) {
|
func TestIsVhostUserSCSI(t *testing.T) {
|
||||||
type testData struct {
|
type testData struct {
|
||||||
|
devType string
|
||||||
major int64
|
major int64
|
||||||
expected bool
|
expected bool
|
||||||
}
|
}
|
||||||
|
|
||||||
data := []testData{
|
data := []testData{
|
||||||
{config.VhostUserBlkMajor, false},
|
{"b", config.VhostUserBlkMajor, false},
|
||||||
{config.VhostUserSCSIMajor, true},
|
{"c", config.VhostUserBlkMajor, false},
|
||||||
{240, false},
|
{"b", config.VhostUserSCSIMajor, true},
|
||||||
|
{"c", config.VhostUserSCSIMajor, false},
|
||||||
|
{"b", 240, false},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, d := range data {
|
for _, d := range data {
|
||||||
isVhostUserSCSI := isVhostUserSCSI(config.DeviceInfo{Major: d.major})
|
isVhostUserSCSI := isVhostUserSCSI(
|
||||||
|
config.DeviceInfo{
|
||||||
|
DevType: d.devType,
|
||||||
|
Major: d.major,
|
||||||
|
})
|
||||||
assert.Equal(t, d.expected, isVhostUserSCSI)
|
assert.Equal(t, d.expected, isVhostUserSCSI)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user