跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

qemu_linux_amd64.go

56 行 · 1.8 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package qemu
5
6import (
7 "errors"
8 "io/fs"
9 "os"
10 "path/filepath"
11 "strings"
12
13 "github.com/coreos/go-semver/semver"
14 "github.com/sirupsen/logrus"
15
16 "github.com/lima-vm/lima/v2/pkg/limatype"
17)
18
19// nestedVirtualizationEnabled reports whether the host can provide nested virtualization
20// for the given guest configuration.
21//
22// On x86_64 Linux, nested virtualization is controlled by the host KVM module
23// (the `nested` parameter of kvm_intel / kvm_amd) and is exposed to the guest via `-cpu host`.
24// No minimum QEMU version is required.
25func nestedVirtualizationEnabled(arch, accel, cpu string, _ *semver.Version) (bool, error) {
26 if arch != limatype.X8664 {
27 logrus.Warnf("field `nestedVirtualization` is not supported for architecture %#q, ignoring", arch)
28 return false, nil
29 }
30 if accel != "kvm" {
31 logrus.Warnf("field `nestedVirtualization` is not supported with accelerator %#q for architecture %#q, ignoring", accel, arch)
32 return false, nil
33 }
34 for _, module := range []string{"kvm_intel", "kvm_amd"} {
35 b, err := os.ReadFile(filepath.Join("/sys/module", module, "parameters", "nested"))
36 if err != nil {
37 if errors.Is(err, fs.ErrNotExist) {
38 continue
39 }
40 logrus.WithError(err).Warn("Failed to check whether nested virtualization is enabled in the host KVM module")
41 return false, nil
42 }
43 enabled, err := parseKVMNestedParam(string(b))
44 if err != nil {
45 return false, err
46 }
47 if !enabled {
48 return false, errors.New("nested virtualization is disabled in the host KVM module (`nested` parameter of kvm_intel / kvm_amd)")
49 }
50 if !strings.HasPrefix(cpu, "host") {
51 logrus.Warnf("nested virtualization on x86_64 requires CPU type `host`, got %#q", cpu)
52 }
53 return true, nil
54 }
55 return false, errors.New("neither kvm_intel nor kvm_amd is loaded")
56}