From 8cf0f0602ff0205739b6bd90b99947c1b78f614c Mon Sep 17 00:00:00 2001 From: Nitesh Konkar Date: Fri, 30 Aug 2019 14:32:26 +0530 Subject: [PATCH] vsock: set VHOST_VSOCK_SET_GUEST_CID based based on arch set VHOST_VSOCK_SET_GUEST_CID depending on the host architecture. Fixes: #1988 Signed-off-by: Nitesh Konkar --- virtcontainers/utils/utils_linux.go | 5 +---- virtcontainers/utils/utils_linux_generic.go | 16 ++++++++++++++++ virtcontainers/utils/utils_linux_ppc64le.go | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 virtcontainers/utils/utils_linux_generic.go create mode 100644 virtcontainers/utils/utils_linux_ppc64le.go diff --git a/virtcontainers/utils/utils_linux.go b/virtcontainers/utils/utils_linux.go index efc109e3f8..49d89dbd71 100644 --- a/virtcontainers/utils/utils_linux.go +++ b/virtcontainers/utils/utils_linux.go @@ -16,10 +16,6 @@ import ( "golang.org/x/sys/unix" ) -// from -// VHOST_VSOCK_SET_GUEST_CID = _IOW(VHOST_VIRTIO, 0x60, __u64) -const ioctlVhostVsockSetGuestCid = 0x4008AF60 - var ioctlFunc = Ioctl // maxUInt represents the maximum valid value for the context ID. @@ -78,6 +74,7 @@ func FindContextID() (*os.File, uint64, error) { } } + ioctlVhostVsockSetGuestCid := getIoctlVhostVsockGuestCid() // Last chance to get a free context ID. for cid := contextID - 1; cid >= firstContextID; cid-- { if err = ioctlFunc(vsockFd.Fd(), ioctlVhostVsockSetGuestCid, uintptr(unsafe.Pointer(&cid))); err == nil { diff --git a/virtcontainers/utils/utils_linux_generic.go b/virtcontainers/utils/utils_linux_generic.go new file mode 100644 index 0000000000..bd99f530bf --- /dev/null +++ b/virtcontainers/utils/utils_linux_generic.go @@ -0,0 +1,16 @@ +// +build amd64 arm64 s390x !ppc64le + +// Copyright (c) 2019 IBM +// +// SPDX-License-Identifier: Apache-2.0 +// + +package utils + +// from +// VHOST_VSOCK_SET_GUEST_CID = _IOW(VHOST_VIRTIO, 0x60, __u64) +const ioctlVhostVsockSetGuestCid = 0x4008AF60 + +func getIoctlVhostVsockGuestCid() uintptr { + return ioctlVhostVsockSetGuestCid +} diff --git a/virtcontainers/utils/utils_linux_ppc64le.go b/virtcontainers/utils/utils_linux_ppc64le.go new file mode 100644 index 0000000000..a49ae5737b --- /dev/null +++ b/virtcontainers/utils/utils_linux_ppc64le.go @@ -0,0 +1,18 @@ +// Copyright (c) 2019 IBM +// +// SPDX-License-Identifier: Apache-2.0 +// + +package utils + +// from +// VHOST_VSOCK_SET_GUEST_CID = _IOW(VHOST_VIRTIO, 0x60, __u64) + +// _IOC_WRITE is 1 for arch generic and 4 for powerpc +// Code reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/powerpc/include/uapi/asm/ioctl.h +// Explanation: https://github.com/kata-containers/runtime/pull/1989#issuecomment-525993135 +const ioctlVhostVsockSetGuestCid = 0x8008AF60 + +func getIoctlVhostVsockGuestCid() uintptr { + return ioctlVhostVsockSetGuestCid +}