diff --git a/src/runtime/virtcontainers/device/api/interface.go b/src/runtime/virtcontainers/device/api/interface.go index 5048535e75..f627aff414 100644 --- a/src/runtime/virtcontainers/device/api/interface.go +++ b/src/runtime/virtcontainers/device/api/interface.go @@ -56,6 +56,9 @@ type Device interface { // GetMajorMinor returns major and minor numbers GetMajorMinor() (int64, int64) + // GetHostPath return the device path in the host + GetHostPath() string + // GetDeviceInfo returns device specific data used for hotplugging by hypervisor // Caller could cast the return value to device specific struct // e.g. Block device returns *config.BlockDrive, diff --git a/src/runtime/virtcontainers/device/drivers/generic.go b/src/runtime/virtcontainers/device/drivers/generic.go index 059f95ab19..805bf21361 100644 --- a/src/runtime/virtcontainers/device/drivers/generic.go +++ b/src/runtime/virtcontainers/device/drivers/generic.go @@ -68,6 +68,14 @@ func (device *GenericDevice) GetMajorMinor() (int64, int64) { 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 func (device *GenericDevice) Reference() uint { if device.RefCount != intMax { diff --git a/src/runtime/virtcontainers/device/drivers/generic_test.go b/src/runtime/virtcontainers/device/drivers/generic_test.go index 89b09ecf1e..f67dde15b6 100644 --- a/src/runtime/virtcontainers/device/drivers/generic_test.go +++ b/src/runtime/virtcontainers/device/drivers/generic_test.go @@ -8,6 +8,7 @@ package drivers import ( "testing" + "github.com/kata-containers/runtime/virtcontainers/device/config" "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()) +}