MCPcopy Create free account
hub / github.com/78/tenbox / GetKvmFd

Function GetKvmFd

src/platform/linux/hypervisor/kvm_platform.cpp:23–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21}
22
23int GetKvmFd() {
24 std::lock_guard<std::mutex> lock(KvmFdMutex());
25 if (g_kvm_fd >= 0) return g_kvm_fd;
26
27 int fd = ::open("/dev/kvm", O_RDWR | O_CLOEXEC);
28 if (fd < 0) {
29 LOG_ERROR("kvm: open(/dev/kvm) failed: %s", strerror(errno));
30 return -1;
31 }
32
33 int api = ::ioctl(fd, KVM_GET_API_VERSION, 0);
34 if (api != KVM_API_VERSION) {
35 LOG_ERROR("kvm: KVM_GET_API_VERSION=%d, expected %d", api, KVM_API_VERSION);
36 ::close(fd);
37 return -1;
38 }
39
40 g_kvm_fd = fd;
41 return g_kvm_fd;
42}
43
44bool IsHypervisorPresent() {
45 if (::access("/dev/kvm", R_OK | W_OK) != 0) {

Callers 4

IsHypervisorPresentFunction · 0.85
CreateMethod · 0.85
SetupCpuidMethod · 0.85
CreateMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected