virtcontainers/utils: Implement function to check vsocks support

Implement function to check if the system has support for vsocks.
This function looks for vsock and vhost-vsock devices returning
true if those exist, otherwise false.

Signed-off-by: Jose Carlos Venegas Munoz <jose.carlos.venegas.munoz@intel.com>
Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
Julio Montes
2018-07-19 08:44:55 -05:00
parent 8ae28888e0
commit 2339ac3f93
2 changed files with 50 additions and 0 deletions

View File

@@ -23,6 +23,12 @@ const fileMode0755 = os.FileMode(0755)
// See unix(7).
const MaxSocketPathLen = 107
// VSockDevicePath path to vsock device
var VSockDevicePath = "/dev/vsock"
// VHostVSockDevicePath path to vhost-vsock device
var VHostVSockDevicePath = "/dev/vhost-vsock"
// FileCopy copys files from srcPath to dstPath
func FileCopy(srcPath, dstPath string) error {
if srcPath == "" {
@@ -200,3 +206,16 @@ func BuildSocketPath(elements ...string) (string, error) {
return result, nil
}
// SupportsVsocks returns true if vsocks are supported, otherwise false
func SupportsVsocks() bool {
if _, err := os.Stat(VSockDevicePath); err != nil {
return false
}
if _, err := os.Stat(VHostVSockDevicePath); err != nil {
return false
}
return true
}