From 471d752009adb8f3aaeb79691faaf367b0e0070b Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Mon, 9 Dec 2024 17:50:07 +0800 Subject: [PATCH 1/2] feat(region,host): loongarch support --- cmd/climc/shell/image/images.go | 2 +- pkg/apis/compute/guest_const.go | 2 +- pkg/apis/const.go | 15 ++-- pkg/cloudcommon/db/archs.go | 6 ++ pkg/cloudcommon/options/options.go | 9 +- pkg/compute/guestdrivers/kvm.go | 6 +- pkg/compute/models/disks.go | 2 + pkg/compute/models/guest_actions.go | 4 +- pkg/hostman/guestfs/fsdriver/linux.go | 8 ++ pkg/hostman/guestfs/fsdriver/windows.go | 6 ++ pkg/hostman/guestman/arch/arch.go | 7 +- pkg/hostman/guestman/arch/loongarch64.go | 86 +++++++++++++++++++ pkg/hostman/guestman/guestman.go | 2 +- pkg/hostman/guestman/qemu-kvm.go | 2 + pkg/hostman/guestman/qemu-kvmhelper.go | 17 ++-- pkg/hostman/guestman/qemu/generate.go | 6 +- pkg/hostman/guestman/qemu/qemu.go | 5 +- pkg/hostman/guestman/qemu/v9_0_1.go | 31 +++++++ pkg/hostman/hostinfo/hostinfo.go | 6 ++ pkg/hostman/hostutils/hostutils.go | 1 + .../predicates/guest/cpu_predicate.go | 17 ++-- pkg/util/qemutils/qemutils.go | 4 + 22 files changed, 205 insertions(+), 39 deletions(-) create mode 100644 pkg/hostman/guestman/arch/loongarch64.go diff --git a/cmd/climc/shell/image/images.go b/cmd/climc/shell/image/images.go index ab34401205b..26794929326 100644 --- a/cmd/climc/shell/image/images.go +++ b/cmd/climc/shell/image/images.go @@ -52,7 +52,7 @@ type ImageOptionalOptions struct { OsDist string `help:"Distribution name of OS" metavar:"OS_DISTRIBUTION"` OsVersion string `help:"Version of OS"` OsCodename string `help:"Codename of OS"` - OsArch string `help:"Os hardware architecture" choices:"x86|x86_64|aarch32|aarch64"` + OsArch string `help:"Os hardware architecture" choices:"x86|x86_64|aarch32|aarch64|loongarch64"` OsLang string `help:"OS Language" choices:"zh_CN|en_US"` Preference int64 `help:"Disk preferences"` Notes string `help:"Notes about the image"` diff --git a/pkg/apis/compute/guest_const.go b/pkg/apis/compute/guest_const.go index 849f166780f..9922d0d1ebd 100644 --- a/pkg/apis/compute/guest_const.go +++ b/pkg/apis/compute/guest_const.go @@ -247,7 +247,7 @@ const ( VM_MACHINE_TYPE_PC = "pc" VM_MACHINE_TYPE_Q35 = "q35" - VM_MACHINE_TYPE_ARM_VIRT = "virt" + VM_MACHINE_TYPE_VIRT = "virt" VM_VDI_PROTOCOL_VNC = "vnc" VM_VDI_PROTOCOL_SPICE = "spice" diff --git a/pkg/apis/const.go b/pkg/apis/const.go index 0015ed2f6ef..b7259990b53 100644 --- a/pkg/apis/const.go +++ b/pkg/apis/const.go @@ -118,11 +118,12 @@ const ( OS_ARCH_X86 = "x86" OS_ARCH_ARM = "arm" - OS_ARCH_I386 = "i386" - OS_ARCH_X86_32 = "x86_32" - OS_ARCH_X86_64 = "x86_64" - OS_ARCH_AARCH32 = "aarch32" - OS_ARCH_AARCH64 = "aarch64" + OS_ARCH_I386 = "i386" + OS_ARCH_X86_32 = "x86_32" + OS_ARCH_X86_64 = "x86_64" + OS_ARCH_AARCH32 = "aarch32" + OS_ARCH_AARCH64 = "aarch64" + OS_ARCH_LOONGARCH64 = "loongarch64" ) var ( @@ -143,6 +144,10 @@ func IsARM(osArch string) bool { return utils.IsInStringArray(osArch, ARCH_ARM) } +func IsLoongarch64(osArch string) bool { + return osArch == OS_ARCH_LOONGARCH64 +} + func IsIllegalSearchDomain(domain string) bool { switch domain { case "cloud.onecloud.io": diff --git a/pkg/cloudcommon/db/archs.go b/pkg/cloudcommon/db/archs.go index 12b187ebbb2..07aef764b8d 100644 --- a/pkg/cloudcommon/db/archs.go +++ b/pkg/cloudcommon/db/archs.go @@ -62,6 +62,12 @@ func ListQueryByArchitecture(q *sqlchemy.SQuery, fieldKey string, archs []string sqlchemy.Equals(q.Field(fieldKey), apis.OS_ARCH_AARCH32), sqlchemy.Equals(q.Field(fieldKey), apis.OS_ARCH_AARCH64), )) + + } else if arch == apis.OS_ARCH_LOONGARCH64 { + conditions = append(conditions, sqlchemy.OR( + sqlchemy.Startswith(q.Field(fieldKey), arch), + sqlchemy.Equals(q.Field(fieldKey), apis.OS_ARCH_LOONGARCH64), + )) } else { conditions = append(conditions, sqlchemy.Startswith(q.Field(fieldKey), arch)) } diff --git a/pkg/cloudcommon/options/options.go b/pkg/cloudcommon/options/options.go index f65b8863c0e..77842ff465d 100644 --- a/pkg/cloudcommon/options/options.go +++ b/pkg/cloudcommon/options/options.go @@ -74,10 +74,11 @@ type BaseOptions struct { DefaultProcessTimeoutSeconds int `default:"60" help:"request process timeout, default is 60 seconds"` - EnableSsl bool `help:"Enable https"` - SslCaCerts string `help:"ssl certificate ca root file, separating ca and cert file is not encouraged" alias:"ca-file"` - SslCertfile string `help:"ssl certification file, normally combines all the certificates in the chain" alias:"cert-file"` - SslKeyfile string `help:"ssl certification private key file" alias:"key-file"` + EnableEtcdEndpointPuller bool `help:"Enable etcd endpoint puller" default:"true"` + EnableSsl bool `help:"Enable https"` + SslCaCerts string `help:"ssl certificate ca root file, separating ca and cert file is not encouraged" alias:"ca-file"` + SslCertfile string `help:"ssl certification file, normally combines all the certificates in the chain" alias:"cert-file"` + SslKeyfile string `help:"ssl certification private key file" alias:"key-file"` NotifyAdminUsers []string `default:"sysadmin" help:"System administrator user ID or name to notify system events, if domain is not default, specify domain as prefix ending with double backslash, e.g. domain\\\\user"` NotifyAdminGroups []string `help:"System administrator group ID or name to notify system events, if domain is not default, specify domain as prefix ending with double backslash, e.g. domain\\\\group"` diff --git a/pkg/compute/guestdrivers/kvm.go b/pkg/compute/guestdrivers/kvm.go index 4d3b2a57439..3aaefd3544b 100644 --- a/pkg/compute/guestdrivers/kvm.go +++ b/pkg/compute/guestdrivers/kvm.go @@ -966,8 +966,8 @@ func (self *SKVMGuestDriver) validateVGA(ovdi, ovga string, nvdi, nvga *string) func (self *SKVMGuestDriver) validateMachineType(machine string, osArch string) error { var candidate []string - if apis.IsARM(osArch) { - candidate = []string{api.VM_MACHINE_TYPE_ARM_VIRT} + if apis.IsARM(osArch) || apis.IsLoongarch64(osArch) { + candidate = []string{api.VM_MACHINE_TYPE_VIRT} } else { candidate = []string{api.VM_MACHINE_TYPE_PC, api.VM_MACHINE_TYPE_Q35} } @@ -1248,7 +1248,7 @@ func (kvm *SKVMGuestDriver) ValidateGuestHotChangeConfigInput(ctx context.Contex if guest.GetMetadata(ctx, api.VM_METADATA_HOTPLUG_CPU_MEM, nil) != "enable" { return confs, errors.Wrap(errors.ErrInvalidStatus, "host plug cpu memory is disabled") } - if apis.IsARM(guest.OsArch) { + if apis.IsARM(guest.OsArch) || apis.IsLoongarch64(guest.OsArch) { return confs, errors.Wrap(errors.ErrInvalidStatus, "cpu architecture is arm") } return confs, nil diff --git a/pkg/compute/models/disks.go b/pkg/compute/models/disks.go index cea88d953a3..0a1df49d048 100644 --- a/pkg/compute/models/disks.go +++ b/pkg/compute/models/disks.go @@ -1433,6 +1433,8 @@ func (self *SDisk) GetMasterHost(storage *SStorage) (*SHost, error) { q = q.In("cpu_architecture", apis.ARCH_X86) case apis.OS_ARCH_ARM: q = q.In("cpu_architecture", apis.ARCH_ARM) + case apis.OS_ARCH_LOONGARCH64: + q = q.Equals("cpu_architecture", apis.OS_ARCH_LOONGARCH64) } } host := SHost{} diff --git a/pkg/compute/models/guest_actions.go b/pkg/compute/models/guest_actions.go index dc33771ee9d..726d735a2ea 100644 --- a/pkg/compute/models/guest_actions.go +++ b/pkg/compute/models/guest_actions.go @@ -179,7 +179,7 @@ func (self *SGuest) PerformSaveImage(ctx context.Context, userCred mcclient.Toke input.OsType = "Linux" } input.OsArch = self.OsArch - if apis.IsARM(self.OsArch) { + if apis.IsARM(self.OsArch) || apis.IsLoongarch64(self.OsArch) { if osArch := self.GetMetadata(ctx, "os_arch", nil); len(osArch) == 0 { host, _ := self.GetHost() input.OsArch = host.CpuArchitecture @@ -260,7 +260,7 @@ func (self *SGuest) PerformSaveGuestImage(ctx context.Context, userCred mcclient } kwargs.Properties["os_type"] = osType - if apis.IsARM(self.OsArch) { + if apis.IsARM(self.OsArch) || apis.IsLoongarch64(self.OsArch) { var osArch string if osArch = self.GetMetadata(ctx, "os_arch", nil); len(osArch) == 0 { host, _ := self.GetHost() diff --git a/pkg/hostman/guestfs/fsdriver/linux.go b/pkg/hostman/guestfs/fsdriver/linux.go index cbfd87993da..44879e7c95f 100644 --- a/pkg/hostman/guestfs/fsdriver/linux.go +++ b/pkg/hostman/guestfs/fsdriver/linux.go @@ -116,6 +116,9 @@ func (l *sLinuxRootFs) DeployQgaService(rootFs IDiskPartition) error { // qemu-ga has been installed return nil } + if !fileutils2.Exists(QGA_BINARY_PATH) { + return nil + } output, err := procutils.NewCommand("cp", "-f", QGA_BINARY_PATH, path.Join(rootFs.GetMountPath(), qemuGuestAgentPath)).Output() if err != nil { @@ -546,6 +549,8 @@ func (l *sLinuxRootFs) GetArch(rootFs IDiskPartition) string { return apis.OS_ARCH_AARCH64 case elf.EM_ARM: return apis.OS_ARCH_AARCH32 + case elf.EM_LOONGARCH: + return apis.OS_ARCH_LOONGARCH64 } } } @@ -768,6 +773,9 @@ func (l *sLinuxRootFs) IsCloudinitInstall() bool { } func (d *sLinuxRootFs) DeployTelegraf(config string) (bool, error) { + if !fileutils2.Exists(TELEGRAF_BINARY_PATH) { + return false, nil + } var ( part = d.GetPartition() modeRwxOwner = syscall.S_IRUSR | syscall.S_IWUSR | syscall.S_IXUSR diff --git a/pkg/hostman/guestfs/fsdriver/windows.go b/pkg/hostman/guestfs/fsdriver/windows.go index 973e4e10377..5596cdd1058 100644 --- a/pkg/hostman/guestfs/fsdriver/windows.go +++ b/pkg/hostman/guestfs/fsdriver/windows.go @@ -582,6 +582,9 @@ func (l *SWindowsRootFs) IsResizeFsPartitionSupport() bool { } func (w *SWindowsRootFs) DeployQgaService(part IDiskPartition) error { + if !fileutils2.Exists(QGA_WIN_MSI_INSTALLER_PATH) { + return nil + } if err := w.rootFs.Mkdir(WIN_QGA_PATH, syscall.S_IRUSR|syscall.S_IWUSR|syscall.S_IXUSR, true); err != nil { return errors.Wrap(err, "mkdir qemu-ga path") } @@ -604,6 +607,9 @@ func (w *SWindowsRootFs) DeployQgaBlackList(part IDiskPartition) error { } func (w *SWindowsRootFs) DeployTelegraf(config string) (bool, error) { + if !fileutils2.Exists(WIN_TELEGRAF_BINARY_PATH) { + return false, nil + } if err := w.rootFs.Mkdir(WIN_TELEGRAF_PATH, syscall.S_IRUSR|syscall.S_IWUSR|syscall.S_IXUSR, true); err != nil { return false, errors.Wrap(err, "mkdir telegraf path") } diff --git a/pkg/hostman/guestman/arch/arch.go b/pkg/hostman/guestman/arch/arch.go index 8916f0bb35e..554e0f47758 100644 --- a/pkg/hostman/guestman/arch/arch.go +++ b/pkg/hostman/guestman/arch/arch.go @@ -17,8 +17,9 @@ package arch import "yunion.io/x/onecloud/pkg/hostman/guestman/desc" const ( - Arch_x86_64 string = "x86_64" - Arch_aarch64 string = "aarch64" + Arch_x86_64 string = "x86_64" + Arch_aarch64 string = "aarch64" + Arch_loongarch64 string = "loongarch64" ) type Arch interface { @@ -50,6 +51,8 @@ func NewArch(arch string) Arch { return &X86{} case Arch_aarch64: return &ARM{} + case Arch_loongarch64: + return &LOONGARCH64{} } return nil } diff --git a/pkg/hostman/guestman/arch/loongarch64.go b/pkg/hostman/guestman/arch/loongarch64.go new file mode 100644 index 00000000000..e37026c340d --- /dev/null +++ b/pkg/hostman/guestman/arch/loongarch64.go @@ -0,0 +1,86 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package arch + +import ( + "fmt" + + "yunion.io/x/onecloud/pkg/hostman/guestman/desc" +) + +const ( + LOONGARCH64_MAX_CPUS = 8 + LOONGARCH64_SOCKETS = 1 + LOONGARCH64_CORES = 8 + LOONGARCH64_THREADS = 1 + + LOONGARCH64_MEM_DEFAULT_SLOTS = 4 + LOONGARCH64_MAX_MEM_MB = 262144 +) + +type LOONGARCH64 struct { + archBase +} + +// -device scsi-cd,drive=cd0,share-rw=true +// if=none,file=%s,id=cd0,media=cdrom +func (*LOONGARCH64) GenerateCdromDesc(osName string, cdrom *desc.SGuestCdrom) { + id := fmt.Sprintf("scsi%d-cd0", cdrom.Ordinal) + scsiDev := desc.NewScsiDevice("", "scsi-cd", id) + scsiDev.Options = map[string]string{"share-rw": "true"} + driveOptions := map[string]string{ + "if": "none", + "media": "cdrom", + } + cdrom.Scsi = scsiDev + cdrom.DriveOptions = driveOptions + cdrom.Id = id +} + +func (*LOONGARCH64) GenerateFloppyDesc(osName string, floppy *desc.SGuestFloppy) { + +} + +func (*LOONGARCH64) GenerateMachineDesc(accel string) *desc.SGuestMachine { + return &desc.SGuestMachine{ + Accel: accel, + } +} + +func (*LOONGARCH64) GenerateMemDesc() *desc.SGuestMem { + return &desc.SGuestMem{ + Slots: LOONGARCH64_MEM_DEFAULT_SLOTS, + MaxMem: LOONGARCH64_MAX_MEM_MB, + } +} + +func (*LOONGARCH64) GenerateCpuDesc(cpus uint, cpuMax uint, s KVMGuestInstance) (*desc.SGuestCpu, error) { + var accel, cpuType string + if s.IsKvmSupport() { + accel = "kvm" + + // * under KVM, -cpu max is the same as -cpu host + // * under TCG, -cpu max means "emulate with as many features as possible" + cpuType = "max" + } else { + accel = "tcg" + cpuType = "max" + } + return &desc.SGuestCpu{ + Cpus: cpus, + Model: cpuType, + Accel: accel, + }, nil +} diff --git a/pkg/hostman/guestman/guestman.go b/pkg/hostman/guestman/guestman.go index 2a6e7f9c1d2..3cf47e2146b 100644 --- a/pkg/hostman/guestman/guestman.go +++ b/pkg/hostman/guestman/guestman.go @@ -137,7 +137,7 @@ func NewGuestManager(host hostutils.IHost, serversPath string, workerCnt int) (* func (m *SGuestManager) InitQemuMaxCpus(machineCaps []monitor.MachineInfo, kvmMaxCpus uint) { m.qemuMachineCpuMax[compute.VM_MACHINE_TYPE_PC] = arch.X86_MAX_CPUS m.qemuMachineCpuMax[compute.VM_MACHINE_TYPE_Q35] = arch.X86_MAX_CPUS - m.qemuMachineCpuMax[compute.VM_MACHINE_TYPE_ARM_VIRT] = arch.ARM_MAX_CPUS + m.qemuMachineCpuMax[compute.VM_MACHINE_TYPE_VIRT] = arch.ARM_MAX_CPUS if len(machineCaps) == 0 { return } diff --git a/pkg/hostman/guestman/qemu-kvm.go b/pkg/hostman/guestman/qemu-kvm.go index 513ff1328bb..b7ea4219121 100644 --- a/pkg/hostman/guestman/qemu-kvm.go +++ b/pkg/hostman/guestman/qemu-kvm.go @@ -127,6 +127,8 @@ func NewKVMGuestInstance(id string, manager *SGuestManager) *SKVMGuestInstance { qemuArch := arch.Arch_x86_64 if manager.host.IsAarch64() { qemuArch = arch.Arch_aarch64 + } else if manager.host.IsLoongarch64() { + qemuArch = arch.Arch_loongarch64 } return &SKVMGuestInstance{ SKVMInstanceRuntime: SKVMInstanceRuntime{ diff --git a/pkg/hostman/guestman/qemu-kvmhelper.go b/pkg/hostman/guestman/qemu-kvmhelper.go index b027622e235..2b3aae4b2c3 100644 --- a/pkg/hostman/guestman/qemu-kvmhelper.go +++ b/pkg/hostman/guestman/qemu-kvmhelper.go @@ -254,12 +254,12 @@ func (s *SKVMGuestInstance) isQ35() bool { } func (s *SKVMGuestInstance) isVirt() bool { - return s.getMachine() == api.VM_MACHINE_TYPE_ARM_VIRT + return s.getMachine() == api.VM_MACHINE_TYPE_VIRT } func (s *SKVMGuestInstance) isPcie() bool { return utils.IsInStringArray(s.getMachine(), - []string{api.VM_MACHINE_TYPE_Q35, api.VM_MACHINE_TYPE_ARM_VIRT}) + []string{api.VM_MACHINE_TYPE_Q35, api.VM_MACHINE_TYPE_VIRT}) } func (s *SKVMGuestInstance) GetVdiProtocol() string { @@ -378,6 +378,8 @@ func (s *SKVMGuestInstance) generateStartScript(data *jsonutils.JSONDict) (strin // inject qemu arch if s.manager.host.IsAarch64() { input.QemuArch = qemu.Arch_aarch64 + } else if s.manager.host.IsLoongarch64() { + input.QemuArch = qemu.Arch_loongarch64 } else { input.QemuArch = qemu.Arch_x86_64 } @@ -445,7 +447,7 @@ func (s *SKVMGuestInstance) generateStartScript(data *jsonutils.JSONDict) (strin * cmd += "fi\n" */ cmd += "QEMU_CMD=$DEFAULT_QEMU_CMD\n" - if s.IsKvmSupport() && !options.HostOptions.DisableKVM { + if s.IsKvmSupport() && !options.HostOptions.DisableKVM && !s.manager.host.IsLoongarch64() { cmd += "QEMU_CMD_KVM_ARG=-enable-kvm\n" } else if utils.IsInStringArray(s.manager.host.GetCpuArchitecture(), apis.ARCH_X86) { // -no-kvm仅x86适用,且将在qemu 5.2之后移除 @@ -503,7 +505,7 @@ function nic_mtu() { } // inject usb devices - if input.QemuArch == qemu.Arch_aarch64 { + if input.QemuArch == qemu.Arch_aarch64 || input.QemuArch == qemu.Arch_loongarch64 { input.Devices = append(input.Devices, fmt.Sprintf("usb-tablet,id=input0,bus=%s.0,port=1", s.Desc.Usb.Id), fmt.Sprintf("usb-kbd,id=input1,bus=%s.0,port=2", s.Desc.Usb.Id), @@ -1047,9 +1049,12 @@ func (s *SKVMGuestInstance) fixGuestMachineType() { if utils.IsInStringArray(s.Desc.Machine, []string{ "", api.VM_MACHINE_TYPE_PC, api.VM_MACHINE_TYPE_Q35, }) { - s.Desc.Machine = api.VM_MACHINE_TYPE_ARM_VIRT + s.Desc.Machine = api.VM_MACHINE_TYPE_VIRT } s.Desc.Bios = qemu.BIOS_UEFI + } else if s.manager.host.IsLoongarch64() { + s.Desc.Machine = api.VM_MACHINE_TYPE_VIRT + s.Desc.Bios = qemu.BIOS_UEFI } } @@ -1082,7 +1087,7 @@ func (s *SKVMGuestInstance) initIsaSerialDesc() { } func (s *SKVMGuestInstance) getVfioDeviceHotPlugPciControllerType() *desc.PCI_CONTROLLER_TYPE { - if s.Desc.Machine == api.VM_MACHINE_TYPE_Q35 || s.Desc.Machine == api.VM_MACHINE_TYPE_ARM_VIRT { + if s.Desc.Machine == api.VM_MACHINE_TYPE_Q35 || s.Desc.Machine == api.VM_MACHINE_TYPE_VIRT { _, _, found := s.findUnusedSlotForController(desc.CONTROLLER_TYPE_PCIE_ROOT_PORT, 0) if found { var contType desc.PCI_CONTROLLER_TYPE = desc.CONTROLLER_TYPE_PCIE_ROOT_PORT diff --git a/pkg/hostman/guestman/qemu/generate.go b/pkg/hostman/guestman/qemu/generate.go index 732da95e79d..d5c4c5d2781 100644 --- a/pkg/hostman/guestman/qemu/generate.go +++ b/pkg/hostman/guestman/qemu/generate.go @@ -201,6 +201,10 @@ func generateSMPOption(guestDesc *desc.SGuestDesc) string { if len(guestDesc.MemDesc.Mem.Mems) > 0 { startCpus = 1 } + if cpu.MaxCpus <= 0 { + return fmt.Sprintf("-smp cpus=%d", startCpus) + } + if cpu.MaxCpus%2 > 0 { return fmt.Sprintf( "-smp cpus=%d,maxcpus=%d", startCpus, cpu.MaxCpus, @@ -828,7 +832,7 @@ func GenerateStartOptions( opts = append(opts, nicOpts...) if !input.GuestDesc.LightMode { - if input.QemuArch == Arch_aarch64 { + if input.QemuArch == Arch_aarch64 || input.QemuArch == Arch_loongarch64 { if input.GuestDesc.Usb != nil { opts = append(opts, generatePCIDeviceOption(input.GuestDesc.Usb.PCIDevice)) for _, device := range input.Devices { diff --git a/pkg/hostman/guestman/qemu/qemu.go b/pkg/hostman/guestman/qemu/qemu.go index 306d3ac3cfb..5888e499843 100644 --- a/pkg/hostman/guestman/qemu/qemu.go +++ b/pkg/hostman/guestman/qemu/qemu.go @@ -39,8 +39,9 @@ const ( type Arch string const ( - Arch_x86_64 Arch = "x86_64" - Arch_aarch64 Arch = "aarch64" + Arch_x86_64 Arch = "x86_64" + Arch_aarch64 Arch = "aarch64" + Arch_loongarch64 Arch = "loongarch64" ) const ( diff --git a/pkg/hostman/guestman/qemu/v9_0_1.go b/pkg/hostman/guestman/qemu/v9_0_1.go index a5534685b7d..c5b5ff379d5 100644 --- a/pkg/hostman/guestman/qemu/v9_0_1.go +++ b/pkg/hostman/guestman/qemu/v9_0_1.go @@ -18,6 +18,7 @@ func init() { RegisterCmd( newCmd_9_0_1_x86_64(), newCmd_9_0_1_aarch64(), + newCmd_9_0_1_loongarch64(), ) } @@ -66,3 +67,33 @@ func newOpt_9_0_1_aarch64() QemuOptions { baseOptions_ge_310: newBaseOptionsGE310(), } } + +func newCmd_9_0_1_loongarch64() QemuCommand { + return newBaseCommand( + Version_9_0_1, + Arch_loongarch64, + newOpt_9_0_1_loongarch64(), + ) +} + +type opt_901_loongarch64 struct { + *baseOptions +} + +func newOpt_9_0_1_loongarch64() QemuOptions { + return &opt_901_loongarch64{ + baseOptions: newBaseOptions(Arch_loongarch64), + } +} + +func (o opt_901_loongarch64) Global() string { + return "" +} + +func (o opt_901_loongarch64) NoHpet() (bool, string) { + return false, "" +} + +func (o opt_901_loongarch64) Nodefconfig() string { + return "-no-user-config" +} diff --git a/pkg/hostman/hostinfo/hostinfo.go b/pkg/hostman/hostinfo/hostinfo.go index 9983214e28b..e31d7fe64c7 100644 --- a/pkg/hostman/hostinfo/hostinfo.go +++ b/pkg/hostman/hostinfo/hostinfo.go @@ -2483,6 +2483,10 @@ func (h *SHostInfo) IsX8664() bool { return h.GetCpuArchitecture() == apis.OS_ARCH_X86_64 } +func (h *SHostInfo) IsLoongarch64() bool { + return h.GetCpuArchitecture() == apis.OS_ARCH_LOONGARCH64 +} + func (h *SHostInfo) GetKubeletConfig() kubelet.KubeletConfig { return h.kubeletConfig } @@ -2519,6 +2523,8 @@ func NewHostInfo() (*SHostInfo, error) { if res.IsAarch64() { qemutils.UseAarch64() + } else if res.IsLoongarch64() { + qemutils.UseLoongarch64() } else if !res.IsX8664() { return nil, fmt.Errorf("unsupport cpu architecture %s", cpu.CpuArchitecture) } diff --git a/pkg/hostman/hostutils/hostutils.go b/pkg/hostman/hostutils/hostutils.go index 0173db5bbc9..4526a815c0c 100644 --- a/pkg/hostman/hostutils/hostutils.go +++ b/pkg/hostman/hostutils/hostutils.go @@ -51,6 +51,7 @@ type IHost interface { GetCpuArchitecture() string GetKernelVersion() string IsAarch64() bool + IsLoongarch64() bool IsX8664() bool GetHostTopology() *hostapi.HostTopology GetReservedCpusInfo() *cpuset.CPUSet diff --git a/pkg/scheduler/algorithm/predicates/guest/cpu_predicate.go b/pkg/scheduler/algorithm/predicates/guest/cpu_predicate.go index 069d57ae8c0..70c002037c2 100644 --- a/pkg/scheduler/algorithm/predicates/guest/cpu_predicate.go +++ b/pkg/scheduler/algorithm/predicates/guest/cpu_predicate.go @@ -58,18 +58,13 @@ func (f *CPUPredicate) Execute(ctx context.Context, u *core.Unit, c core.Candida getter := c.Getter() archMatch := true - isArmHost := getter.IsArmHost() - if apis.IsARM(d.OsArch) { - // process arm64 host - if !isArmHost { - archMatch = false - } - } else { - // process x86_64 host - if isArmHost { - archMatch = false - } + cpuArch := getter.CPUArch() + if apis.IsARM(cpuArch) && !apis.IsARM(d.OsArch) { + archMatch = false + } else if apis.IsLoongarch64(cpuArch) && !apis.IsLoongarch64(d.OsArch) { + archMatch = false } + if !archMatch { h.Exclude2(predicates.ErrHostCpuArchitectureNotMatch, getter.CPUArch(), d.OsArch) return h.GetResult() diff --git a/pkg/util/qemutils/qemutils.go b/pkg/util/qemutils/qemutils.go index 207193e07cc..3b91266d45c 100644 --- a/pkg/util/qemutils/qemutils.go +++ b/pkg/util/qemutils/qemutils.go @@ -39,6 +39,10 @@ func UseAarch64() { qemuSystemCmd = "qemu-system-aarch64" } +func UseLoongarch64() { + qemuSystemCmd = "qemu-system-loongarch64" +} + func GetQemu(version string) string { return getQemuCmd(qemuSystemCmd, version) } From 0bd587747d51110cafce4206ac46c4878dc4c504 Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Tue, 10 Dec 2024 14:16:25 +0800 Subject: [PATCH 2/2] fix(region): create server validate add loongarch64 os_type --- pkg/compute/models/guests.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 0d6868ee049..771e0c68e36 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -1657,8 +1657,11 @@ func (manager *SGuestManager) validateCreateData( } } - if arch := imgProperties["os_arch"]; strings.Contains(arch, "aarch") || strings.Contains(arch, "arm") { + arch := imgProperties["os_arch"] + if strings.Contains(arch, "aarch") || strings.Contains(arch, "arm") { input.OsArch = apis.OS_ARCH_AARCH64 + } else if arch == apis.OS_ARCH_LOONGARCH64 { + input.OsArch = apis.OS_ARCH_LOONGARCH64 } var imgSupportUEFI *bool @@ -1666,7 +1669,7 @@ func (manager *SGuestManager) validateCreateData( support := desc == "true" imgSupportUEFI = &support } - if input.OsArch == apis.OS_ARCH_AARCH64 { + if input.OsArch == apis.OS_ARCH_AARCH64 || input.OsArch == apis.OS_ARCH_LOONGARCH64 { // arm image supports UEFI by default support := true imgSupportUEFI = &support