mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-10 21:29:01 +00:00
device: add GetHostPath() to generic device
`GetHostPath()` method returns the device path in the host, this way the runtime can get the device information for updating the sandbox's device cgroup. Signed-off-by: Julio Montes <julio.montes@intel.com> Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
@@ -56,6 +56,9 @@ type Device interface {
|
|||||||
// GetMajorMinor returns major and minor numbers
|
// GetMajorMinor returns major and minor numbers
|
||||||
GetMajorMinor() (int64, int64)
|
GetMajorMinor() (int64, int64)
|
||||||
|
|
||||||
|
// GetHostPath return the device path in the host
|
||||||
|
GetHostPath() string
|
||||||
|
|
||||||
// GetDeviceInfo returns device specific data used for hotplugging by hypervisor
|
// GetDeviceInfo returns device specific data used for hotplugging by hypervisor
|
||||||
// Caller could cast the return value to device specific struct
|
// Caller could cast the return value to device specific struct
|
||||||
// e.g. Block device returns *config.BlockDrive,
|
// e.g. Block device returns *config.BlockDrive,
|
||||||
|
@@ -68,6 +68,14 @@ func (device *GenericDevice) GetMajorMinor() (int64, int64) {
|
|||||||
return device.DeviceInfo.Major, device.DeviceInfo.Minor
|
return device.DeviceInfo.Major, device.DeviceInfo.Minor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetHostPath return the device path in the host
|
||||||
|
func (device *GenericDevice) GetHostPath() string {
|
||||||
|
if device.DeviceInfo != nil {
|
||||||
|
return device.DeviceInfo.HostPath
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
// Reference adds one reference to device
|
// Reference adds one reference to device
|
||||||
func (device *GenericDevice) Reference() uint {
|
func (device *GenericDevice) Reference() uint {
|
||||||
if device.RefCount != intMax {
|
if device.RefCount != intMax {
|
||||||
|
@@ -8,6 +8,7 @@ package drivers
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -42,3 +43,15 @@ func TestBumpAttachCount(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetHostPath(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
dev := &GenericDevice{}
|
||||||
|
assert.Empty(dev.GetHostPath())
|
||||||
|
|
||||||
|
expectedHostPath := "/dev/null"
|
||||||
|
dev.DeviceInfo = &config.DeviceInfo{
|
||||||
|
HostPath: expectedHostPath,
|
||||||
|
}
|
||||||
|
assert.Equal(expectedHostPath, dev.GetHostPath())
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user