func (qc *QemuContext) arguments(ctx *hypervisor.VmContext) []string { if ctx.Boot == nil { ctx.Boot = &hypervisor.BootConfig{ CPU: 1, Memory: 128, Kernel: hypervisor.DefaultKernel, Initrd: hypervisor.DefaultInitrd, } } boot := ctx.Boot qc.cpus = boot.CPU var machineClass, memParams, cpuParams string if ctx.Boot.HotAddCpuMem { machineClass = "pc-i440fx-2.1" memParams = fmt.Sprintf("size=%d,slots=1,maxmem=%s", ctx.Boot.Memory, hypervisor.DefaultMaxMem) // TODO set maxmem to the total memory of the system cpuParams = fmt.Sprintf("cpus=%d,maxcpus=%d", ctx.Boot.CPU, hypervisor.DefaultMaxCpus) // TODO set it to the cpus of the system } else { machineClass = "pc-i440fx-2.0" memParams = strconv.Itoa(ctx.Boot.Memory) cpuParams = strconv.Itoa(ctx.Boot.CPU) } params := []string{ "-machine", machineClass + ",accel=kvm,usb=off", "-global", "kvm-pit.lost_tick_policy=discard", "-cpu", "host"} if _, err := os.Stat("/dev/kvm"); os.IsNotExist(err) { glog.V(1).Info("kvm not exist change to no kvm mode") params = []string{"-machine", machineClass + ",usb=off", "-cpu", "core2duo"} } if boot.Bios != "" && boot.Cbfs != "" { params = append(params, "-drive", fmt.Sprintf("if=pflash,file=%s,readonly=on", boot.Bios), "-drive", fmt.Sprintf("if=pflash,file=%s,readonly=on", boot.Cbfs)) } else if boot.Bios != "" { params = append(params, "-bios", boot.Bios, "-kernel", boot.Kernel, "-initrd", boot.Initrd, "-append", "\"console=ttyS0 panic=1 no_timer_check\"") } else if boot.Cbfs != "" { params = append(params, "-drive", fmt.Sprintf("if=pflash,file=%s,readonly=on", boot.Cbfs)) } else { params = append(params, "-kernel", boot.Kernel, "-initrd", boot.Initrd, "-append", "\"console=ttyS0 panic=1 no_timer_check\"") } return append(params, "-realtime", "mlock=off", "-no-user-config", "-nodefaults", "-no-hpet", "-rtc", "base=utc,driftfix=slew", "-no-reboot", "-display", "none", "-boot", "strict=on", "-m", memParams, "-smp", cpuParams, "-qmp", fmt.Sprintf("unix:%s,server,nowait", qc.qmpSockName), "-serial", fmt.Sprintf("unix:%s,server,nowait", ctx.ConsoleSockName), "-device", "virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x2", "-device", "virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x3", "-chardev", fmt.Sprintf("socket,id=charch0,path=%s,server,nowait", ctx.HyperSockName), "-device", "virtserialport,bus=virtio-serial0.0,nr=1,chardev=charch0,id=channel0,name=sh.hyper.channel.0", "-chardev", fmt.Sprintf("socket,id=charch1,path=%s,server,nowait", ctx.TtySockName), "-device", "virtserialport,bus=virtio-serial0.0,nr=2,chardev=charch1,id=channel1,name=sh.hyper.channel.1", "-fsdev", fmt.Sprintf("local,id=virtio9p,path=%s,security_model=none", ctx.ShareDir), "-device", fmt.Sprintf("virtio-9p-pci,fsdev=virtio9p,mount_tag=%s", hypervisor.ShareDirTag), ) }
func (qc *QemuContext) arguments(ctx *hypervisor.VmContext) []string { if ctx.Boot == nil { ctx.Boot = &hypervisor.BootConfig{ CPU: 1, Memory: VM_MIN_MEMORY_SIZE, Kernel: hypervisor.DefaultKernel, Initrd: hypervisor.DefaultInitrd, } } boot := ctx.Boot qc.cpus = boot.CPU // Currently the default memory size is fixed to 128 MiB. // TODO: Check with PPC team for a better solution if boot.Memory < VM_MIN_MEMORY_SIZE { boot.Memory = VM_MIN_MEMORY_SIZE } var memParams, cpuParams string if boot.HotAddCpuMem { memParams = fmt.Sprintf("size=%d,slots=1,maxmem=%dM", boot.Memory, hypervisor.DefaultMaxMem) // TODO set maxmem to the total memory of the system cpuParams = fmt.Sprintf("cpus=%d,maxcpus=%d", boot.CPU, hypervisor.DefaultMaxCpus) // TODO set it to the cpus of the system } else { memParams = strconv.Itoa(boot.Memory) cpuParams = strconv.Itoa(boot.CPU) } return []string{ "-machine", "pseries,accel=kvm,usb=off", "-global", "kvm-pit.lost_tick_policy=discard", "-cpu", "host", "-kernel", boot.Kernel, "-initrd", boot.Initrd, "-machine", "pseries,accel=kvm,usb=off", "-cpu", "host", "-realtime", "mlock=off", "-no-user-config", "-nodefaults", "-rtc", "base=utc,driftfix=slew", "-no-reboot", "-display", "none", "-boot", "strict=on", "-m", memParams, "-smp", cpuParams, "-qmp", fmt.Sprintf("unix:%s,server,nowait", qc.qmpSockName), "-serial", fmt.Sprintf("unix:%s,server,nowait", ctx.ConsoleSockName), "-device", "virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x2", "-device", "virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x3", "-chardev", fmt.Sprintf("socket,id=charch0,path=%s,server,nowait", ctx.HyperSockName), "-device", "virtserialport,bus=virtio-serial0.0,nr=1,chardev=charch0,id=channel0,name=sh.hyper.channel.0", "-chardev", fmt.Sprintf("socket,id=charch1,path=%s,server,nowait", ctx.TtySockName), "-device", "virtserialport,bus=virtio-serial0.0,nr=2,chardev=charch1,id=channel1,name=sh.hyper.channel.1", "-fsdev", fmt.Sprintf("local,id=virtio9p,path=%s,security_model=none", ctx.ShareDir), "-device", fmt.Sprintf("virtio-9p-pci,fsdev=virtio9p,mount_tag=%s", hypervisor.ShareDirTag), } }
func (qc *QemuContext) arguments(ctx *hypervisor.VmContext) []string { if ctx.Boot == nil { ctx.Boot = &hypervisor.BootConfig{ CPU: 1, Memory: 128, Kernel: hypervisor.DefaultKernel, Initrd: hypervisor.DefaultInitrd, } } boot := ctx.Boot qc.cpus = boot.CPU var memParams, cpuParams string if boot.HotAddCpuMem { memParams = fmt.Sprintf("size=%d,slots=1,maxmem=%dM", boot.Memory, hypervisor.DefaultMaxMem) // TODO set maxmem to the total memory of the system cpuParams = fmt.Sprintf("cpus=%d,maxcpus=%d", boot.CPU, hypervisor.DefaultMaxCpus) // TODO set it to the cpus of the system } else { memParams = strconv.Itoa(boot.Memory) cpuParams = strconv.Itoa(boot.CPU) } return []string{ "-machine", "s390-ccw-virtio,accel=kvm,usb=off", "-cpu", "host", "-kernel", boot.Kernel, "-initrd", boot.Initrd, "-append", "\"console=ttyS1 panic=1 no_timer_check\"", "-realtime", "mlock=off", "-no-user-config", "-nodefaults", "-enable-kvm", "-rtc", "base=utc,driftfix=slew", "-no-reboot", "-display", "none", "-boot", "strict=on", "-m", memParams, "-smp", cpuParams, "-qmp", fmt.Sprintf("unix:%s,server,nowait", qc.qmpSockName), "-chardev", fmt.Sprintf("socket,id=charconsole0,path=%s,server,nowait", ctx.ConsoleSockName), "-device", "sclpconsole,chardev=charconsole0", "-device", "virtio-serial-ccw,id=virtio-serial0", "-device", "virtio-scsi-ccw,id=scsi0", "-chardev", fmt.Sprintf("socket,id=charch0,path=%s,server,nowait", ctx.HyperSockName), "-device", "virtserialport,bus=virtio-serial0.0,nr=1,chardev=charch0,id=channel0,name=sh.hyper.channel.0", "-chardev", fmt.Sprintf("socket,id=charch1,path=%s,server,nowait", ctx.TtySockName), "-device", "virtserialport,bus=virtio-serial0.0,nr=2,chardev=charch1,id=channel1,name=sh.hyper.channel.1", "-fsdev", fmt.Sprintf("local,id=virtio9p,path=%s,security_model=none", ctx.ShareDir), "-device", fmt.Sprintf("virtio-9p-ccw,fsdev=virtio9p,mount_tag=%s", hypervisor.ShareDirTag), } }
func (lc *LibvirtContext) domainXml(ctx *hypervisor.VmContext) (string, error) { if ctx.Boot == nil { ctx.Boot = &hypervisor.BootConfig{ CPU: 1, Memory: 128, Kernel: hypervisor.DefaultKernel, Initrd: hypervisor.DefaultInitrd, } } boot := ctx.Boot dom := &domain{ Type: "kvm", Name: ctx.Id, } dom.Memory.Unit = "MiB" dom.Memory.Content = ctx.Boot.Memory dom.VCpu.Placement = "static" dom.VCpu.Current = strconv.Itoa(ctx.Boot.CPU) dom.VCpu.Content = ctx.Boot.CPU dom.OS.Supported = "yes" dom.OS.Type.Arch = "x86_64" dom.OS.Type.Machine = "pc-i440fx-2.0" dom.OS.Type.Content = "hvm" dom.SecLabel.Type = "none" dom.CPU.Mode = "host-passthrough" if _, err := os.Stat("/dev/kvm"); os.IsNotExist(err) { dom.Type = "qemu" dom.CPU.Mode = "host-model" dom.CPU.Match = "exact" dom.CPU.Model = &cpumodel{ Fallback: "allow", Content: "core2duo", } } if ctx.Boot.HotAddCpuMem { dom.OS.Type.Machine = "pc-i440fx-2.1" dom.VCpu.Content = hypervisor.DefaultMaxCpus dom.MaxMem = &maxmem{Unit: "MiB", Slots: "1", Content: hypervisor.DefaultMaxMem} cells := make([]cell, 1) cells[0].Id = "0" cells[0].Cpus = fmt.Sprintf("0-%d", hypervisor.DefaultMaxCpus-1) cells[0].Memory = strconv.Itoa(ctx.Boot.Memory * 1024) // older libvirt always considers unit='KiB' cells[0].Unit = "KiB" dom.CPU.Numa = &numa{Cell: cells} } cmd, err := exec.LookPath("qemu-system-x86_64") if err != nil { return "", fmt.Errorf("cannot find qemu-system-x86_64 binary") } dom.Devices.Emulator = cmd qemuTemplateWrapper := filepath.Join(filepath.Dir(boot.MemoryPath), "libvirt-qemu-template-wrapper.sh") if boot.BootToBeTemplate { err := CreateTemplateQemuWrapper(qemuTemplateWrapper, cmd, boot) if err != nil { return "", err } dom.Devices.Emulator = qemuTemplateWrapper } else if boot.BootFromTemplate { // the wrapper was created when the template was created dom.Devices.Emulator = qemuTemplateWrapper } dom.OnPowerOff = "destroy" dom.OnReboot = "destroy" dom.OnCrash = "destroy" pcicontroller := controller{ Type: "pci", Index: "0", Model: "pci-root", } dom.Devices.Controllers = append(dom.Devices.Controllers, pcicontroller) serialcontroller := controller{ Type: "virtio-serial", Index: "0", Address: &address{ Type: "pci", Domain: "0x0000", Bus: "0x00", Slot: "0x02", Function: "0x00", }, } dom.Devices.Controllers = append(dom.Devices.Controllers, serialcontroller) scsicontroller := controller{ Type: "scsi", Index: "0", Model: "virtio-scsi", Address: &address{ Type: "pci", Domain: "0x0000", Bus: "0x00", Slot: "0x03", Function: "0x00", }, } dom.Devices.Controllers = append(dom.Devices.Controllers, scsicontroller) usbcontroller := controller{ Type: "usb", Model: "none", } dom.Devices.Controllers = append(dom.Devices.Controllers, usbcontroller) sharedfs := filesystem{ Type: "mount", Accessmode: "squash", Driver: fsdriver{ Type: "path", }, Source: fspath{ Dir: ctx.ShareDir, }, Target: fspath{ Dir: hypervisor.ShareDirTag, }, Address: &address{ Type: "pci", Domain: "0x0000", Bus: "0x00", Slot: "0x04", Function: "0x00", }, } dom.Devices.Filesystems = append(dom.Devices.Filesystems, sharedfs) hyperchannel := channel{ Type: "unix", Source: channsrc{ Mode: "bind", Path: ctx.HyperSockName, }, Target: channtgt{ Type: "virtio", Name: "sh.hyper.channel.0", }, } dom.Devices.Channels = append(dom.Devices.Channels, hyperchannel) ttychannel := channel{ Type: "unix", Source: channsrc{ Mode: "bind", Path: ctx.TtySockName, }, Target: channtgt{ Type: "virtio", Name: "sh.hyper.channel.1", }, } dom.Devices.Channels = append(dom.Devices.Channels, ttychannel) dom.Devices.Console = console{ Type: "unix", Source: channsrc{ Mode: "bind", Path: ctx.ConsoleSockName, }, Target: constgt{ Type: "serial", Port: "0", }, } dom.Devices.Memballoon = memballoon{ Model: "virtio", Address: &address{ Type: "pci", Domain: "0x0000", Bus: "0x00", Slot: "0x05", Function: "0x00", }, } if boot.Bios != "" && boot.Cbfs != "" { dom.OS.Loader = &osloader{ ReadOnly: "yes", Type: "pflash", Content: boot.Bios, } dom.OS.Nvram = boot.Cbfs } else { dom.OS.Kernel = boot.Kernel dom.OS.Initrd = boot.Initrd dom.OS.Cmdline = "console=ttyS0 panic=1 no_timer_check" } data, err := xml.Marshal(dom) if err != nil { return "", err } return string(data), nil }
func (lc *LibvirtContext) domainXml(ctx *hypervisor.VmContext) (string, error) { if ctx.Boot == nil { ctx.Boot = &hypervisor.BootConfig{ CPU: 1, Memory: 128, Kernel: hypervisor.DefaultKernel, Initrd: hypervisor.DefaultInitrd, } } boot := ctx.Boot dom := &domain{ Type: "kvm", Name: ctx.Id, } dom.Memory.Unit = "MB" dom.Memory.Content = ctx.Boot.Memory dom.VCpu.Placement = "static" dom.VCpu.Content = ctx.Boot.CPU dom.OS.Supported = "yes" dom.OS.Type.Arch = "x86_64" dom.OS.Type.Machine = "pc-i440fx-2.0" dom.OS.Type.Content = "hvm" dom.SecLabel.Type = "none" dom.CPU.Mode = "host-passthrough" if _, err := os.Stat("/dev/kvm"); os.IsNotExist(err) { dom.Type = "qemu" dom.CPU.Mode = "host-model" dom.CPU.Match = "exact" dom.CPU.Model = &cpumodel{ Fallback: "allow", Content: "core2duo", } } cmd, err := exec.LookPath("qemu-system-x86_64") if err != nil { return "", fmt.Errorf("cannot find qemu-system-x86_64 binary") } dom.Devices.Emulator = cmd pcicontroller := controller{ Type: "pci", Index: "0", Model: "pci-root", } dom.Devices.Controllers = append(dom.Devices.Controllers, pcicontroller) serialcontroller := controller{ Type: "virtio-serial", Index: "0", Address: &address{ Type: "pci", Domain: "0x0000", Bus: "0x00", Slot: "0x02", Function: "0x00", }, } dom.Devices.Controllers = append(dom.Devices.Controllers, serialcontroller) scsicontroller := controller{ Type: "scsi", Index: "0", Model: "virtio-scsi", Address: &address{ Type: "pci", Domain: "0x0000", Bus: "0x00", Slot: "0x03", Function: "0x00", }, } dom.Devices.Controllers = append(dom.Devices.Controllers, scsicontroller) usbcontroller := controller{ Type: "usb", Model: "none", } dom.Devices.Controllers = append(dom.Devices.Controllers, usbcontroller) sharedfs := filesystem{ Type: "mount", Accessmode: "squash", Driver: fsdriver{ Type: "path", }, Source: fspath{ Dir: ctx.ShareDir, }, Target: fspath{ Dir: hypervisor.ShareDirTag, }, Address: &address{ Type: "pci", Domain: "0x0000", Bus: "0x00", Slot: "0x04", Function: "0x00", }, } dom.Devices.Filesystems = append(dom.Devices.Filesystems, sharedfs) hyperchannel := channel{ Type: "unix", Source: channsrc{ Mode: "bind", Path: ctx.HyperSockName, }, Target: channtgt{ Type: "virtio", Name: "sh.hyper.channel.0", }, } dom.Devices.Channels = append(dom.Devices.Channels, hyperchannel) ttychannel := channel{ Type: "unix", Source: channsrc{ Mode: "bind", Path: ctx.TtySockName, }, Target: channtgt{ Type: "virtio", Name: "sh.hyper.channel.1", }, } dom.Devices.Channels = append(dom.Devices.Channels, ttychannel) dom.Devices.Console = console{ Type: "unix", Source: channsrc{ Mode: "bind", Path: ctx.ConsoleSockName, }, Target: constgt{ Type: "serial", Port: "0", }, } dom.Devices.Memballoon = memballoon{ Model: "virtio", Address: &address{ Type: "pci", Domain: "0x0000", Bus: "0x00", Slot: "0x05", Function: "0x00", }, } if boot.Bios != "" && boot.Cbfs != "" { dom.OS.Loader = &osloader{ ReadOnly: "yes", Type: "pflash", Content: boot.Bios, } dom.OS.Nvram = boot.Cbfs } else { dom.OS.Kernel = boot.Kernel dom.OS.Initrd = boot.Initrd dom.OS.Cmdline = "console=ttyS0 panic=1 no_timer_check" } data, err := xml.Marshal(dom) if err != nil { return "", err } return string(data), nil }