mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-26 18:44:47 +01:00
164bd8ctest/fmt: drop extra newlines73555a4qmp: add query-status API234e0edqemu: fix memory prealloc handling30bfcaaqemu: add debug logfile dep now checks for dependency recersively. runtime-spec and gogo protobuf are also updated as being required by kata agent. Solving failure: No versions of github.com/kata-containers/agent met constraints: 94e2a254a94a77c02280f4f84d7f82269be163ce: Could not introduce github.com/kata-containers/agent@94e2a254a94a77c02280f4f84d7f82269be163ce, as it has a dependency on github.com/opencontainers/runtime-spec with constraint a1b50f621a48ad13f8f696a162f684a241307db0, which has no overlap with existing constraint 5806c35637336642129d03657419829569abc5aa from (root) Solving failure: No versions of github.com/kata-containers/agent met constraints: 94e2a254a94a77c02280f4f84d7f82269be163ce: Could not introduce github.com/kata-containers/agent@94e2a254a94a77c02280f4f84d7f82269be163ce, as it has a dependency on github.com/gogo/protobuf with constraint 4cbf7e384e768b4e01799441fdf2a706a5635ae7, which has no overlap with existing constraint 342cbe0a04158f6dcb03ca0079991a51a4248c02 from (root) Signed-off-by: Peng Tao <bergwolf@hyper.sh>
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package vsock
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"unsafe"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
// A fs is an interface over the filesystem and ioctl, to enable testing.
|
|
type fs interface {
|
|
Open(name string) (*os.File, error)
|
|
Ioctl(fd uintptr, request int, argp unsafe.Pointer) error
|
|
}
|
|
|
|
// contextID retrieves the local context ID for this system.
|
|
func contextID() (uint32, error) {
|
|
// Fetch the context ID using a real filesystem.
|
|
var cid uint32
|
|
if err := sysContextID(sysFS{}, &cid); err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return cid, nil
|
|
}
|
|
|
|
// sysContextID retrieves the local context ID for this system, using the
|
|
// methods from fs. The context ID is stored in cid for later use.
|
|
//
|
|
// This method uses this signature to enable easier testing without unsafe
|
|
// usage of unsafe.Pointer.
|
|
func sysContextID(fs fs, cid *uint32) error {
|
|
f, err := fs.Open(devVsock)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer f.Close()
|
|
|
|
// Retrieve the context ID of this machine from /dev/vsock.
|
|
return fs.Ioctl(f.Fd(), unix.IOCTL_VM_SOCKETS_GET_LOCAL_CID, unsafe.Pointer(cid))
|
|
}
|
|
|
|
// A sysFS is the system call implementation of fs.
|
|
type sysFS struct{}
|
|
|
|
func (sysFS) Open(name string) (*os.File, error) { return os.Open(name) }
|
|
func (sysFS) Ioctl(fd uintptr, request int, argp unsafe.Pointer) error {
|
|
_, _, errno := unix.Syscall(
|
|
unix.SYS_IOCTL,
|
|
fd,
|
|
uintptr(request),
|
|
// Note that the conversion from unsafe.Pointer to uintptr _must_
|
|
// occur in the call expression. See the package unsafe documentation
|
|
// for more details.
|
|
uintptr(argp),
|
|
)
|
|
if errno != 0 {
|
|
return os.NewSyscallError("ioctl", fmt.Errorf("%d", int(errno)))
|
|
}
|
|
|
|
return nil
|
|
}
|