Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
vsock: set VHOST_VSOCK_SET_GUEST_CID based based on arch
Browse files Browse the repository at this point in the history
set VHOST_VSOCK_SET_GUEST_CID depending on
the host architecture.

Fixes: #1988

Signed-off-by: Nitesh Konkar <niteshkonkar@in.ibm.com>
  • Loading branch information
nitkon committed Aug 30, 2019
1 parent a1e0a4c commit 8cf0f06
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
5 changes: 1 addition & 4 deletions virtcontainers/utils/utils_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ import (
"golang.org/x/sys/unix"
)

// from <linux/vhost.h>
// 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.
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 16 additions & 0 deletions virtcontainers/utils/utils_linux_generic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// +build amd64 arm64 s390x !ppc64le

// Copyright (c) 2019 IBM
//
// SPDX-License-Identifier: Apache-2.0
//

package utils

// from <linux/vhost.h>
// VHOST_VSOCK_SET_GUEST_CID = _IOW(VHOST_VIRTIO, 0x60, __u64)
const ioctlVhostVsockSetGuestCid = 0x4008AF60

func getIoctlVhostVsockGuestCid() uintptr {
return ioctlVhostVsockSetGuestCid
}
18 changes: 18 additions & 0 deletions virtcontainers/utils/utils_linux_ppc64le.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2019 IBM
//
// SPDX-License-Identifier: Apache-2.0
//

package utils

// from <linux/vhost.h>
// 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
}

0 comments on commit 8cf0f06

Please sign in to comment.