Created
December 5, 2018 19:41
-
-
Save sameo/5cc49394937ddbab27bd3fbe8e0fa797 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/virtcontainers/utils/utils_linux.go b/virtcontainers/utils/utils_linux.go | |
index 31cb7d1..5f16aba 100644 | |
--- a/virtcontainers/utils/utils_linux.go | |
+++ b/virtcontainers/utils/utils_linux.go | |
@@ -6,9 +6,9 @@ | |
package utils | |
import ( | |
- "crypto/rand" | |
+// "crypto/rand" | |
"fmt" | |
- "math/big" | |
+// "math/big" | |
"os" | |
"syscall" | |
"unsafe" | |
@@ -54,13 +54,9 @@ func ioctl(fd uintptr, request int, arg1 uint64) error { | |
func FindContextID() (*os.File, uint32, error) { | |
// context IDs 0x0, 0x1 and 0x2 are reserved, 0x3 is the first context ID usable. | |
var firstContextID uint32 = 0x3 | |
- var contextID = firstContextID | |
+// var contextID = firstContextID | |
// Generate a random number | |
- n, err := rand.Int(rand.Reader, big.NewInt(int64(maxUInt))) | |
- if err == nil && n.Int64() >= int64(firstContextID) { | |
- contextID = uint32(n.Int64()) | |
- } | |
// Open vhost-vsock device to check what context ID is available. | |
// This file descriptor holds/locks the context ID and it should be | |
@@ -70,20 +66,5 @@ func FindContextID() (*os.File, uint32, error) { | |
return nil, 0, err | |
} | |
- // Looking for the first available context ID. | |
- for cid := contextID; cid <= maxUInt; cid++ { | |
- if err := ioctlFunc(vsockFd.Fd(), ioctlVhostVsockSetGuestCid, uint64(cid)); err == nil { | |
- return vsockFd, cid, nil | |
- } | |
- } | |
- | |
- // Last chance to get a free context ID. | |
- for cid := contextID - 1; cid >= firstContextID; cid-- { | |
- if err := ioctlFunc(vsockFd.Fd(), ioctlVhostVsockSetGuestCid, uint64(cid)); err == nil { | |
- return vsockFd, cid, nil | |
- } | |
- } | |
- | |
- vsockFd.Close() | |
- return nil, 0, fmt.Errorf("Could not get a unique context ID for the vsock") | |
+ return vsockFd, firstContextID, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment