Skip to content

Commit

Permalink
Import Upstream version 0.0~git20180126.e307c2f
Browse files Browse the repository at this point in the history
  • Loading branch information
Héctor Orón Martínez committed Mar 7, 2018
1 parent 74722fd commit 0614cad
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright {yyyy} {name of copyright owner}
Copyright 2017,2018 Collabora Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
5 changes: 5 additions & 0 deletions cmd/fakemachine/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Options struct {
Volumes []string `short:"v" long:"volume" description:"volume to mount"`
Images []string `short:"i" long:"image" description:"image to add"`
Memory int `short:"m" long:"memory" description:"Amount of memory for the fakemachine"`
CPUs int `short:"c" long:"cpus" description:"Number of CPUs for the fakemachine"`
ScratchSize string `short:"s" long:"scratchsize" description:"On disk scratchspace size, if unset memory backed scratch space is used"`
}

Expand Down Expand Up @@ -93,6 +94,10 @@ func main() {
m.SetMemory(options.Memory)
}

if options.CPUs > 0 {
m.SetNumCPUs(options.CPUs)
}

command := "/bin/bash"
if len(args) > 0 {
command = strings.Join(args, " ")
Expand Down
13 changes: 11 additions & 2 deletions machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"path"
"runtime"
"strconv"
"strings"
"syscall"
Expand Down Expand Up @@ -39,6 +40,7 @@ type Machine struct {
count int
images []image
memory int
numcpus int

scratchsize int64
scratchpath string
Expand All @@ -48,7 +50,7 @@ type Machine struct {

// Create a new machine object
func NewMachine() (m *Machine) {
m = &Machine{memory: 2048}
m = &Machine{memory: 2048, numcpus: runtime.NumCPU()}
// usr is mounted by specific label via /init
m.addStaticVolume("/usr", "usr")

Expand Down Expand Up @@ -235,6 +237,12 @@ func (m *Machine) SetMemory(memory int) {
m.memory = memory
}

// SetNumCPUs sets the number of CPUs exposed to the fakemachine. Defaults to
// the number of available cores in the system.
func (m *Machine) SetNumCPUs(numcpus int) {
m.numcpus = numcpus
}

// SetScratch sets the size and location of on-disk scratch space to allocate
// (sparsely) for /scratch. If not set /scratch will be backed by memory. If
// Path is "" then the working directory is used as a default storage location
Expand Down Expand Up @@ -482,9 +490,10 @@ func (m *Machine) startup(command string, extracontent [][2]string) (int, error)
return -1, err
}
memory := fmt.Sprintf("%d", m.memory)
numcpus := fmt.Sprintf("%d", m.numcpus)
qemuargs := []string{"qemu-system-x86_64",
"-cpu", "host",
"-smp", "2",
"-smp", numcpus,
"-m", memory,
"-enable-kvm",
"-kernel", "/boot/vmlinuz-" + kernelRelease,
Expand Down

0 comments on commit 0614cad

Please sign in to comment.