diff --git a/Makefile.am b/Makefile.am index 14429e85..0fe4b2de 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,10 @@ export GO15VENDOREXPERIMENT=1 +if WITH_9P +9P_BUILD_TAG=with_9p +else +9P_BUILD_TAG= +endif + if WITH_XEN XEN_BUILD_TAG=with_xen else @@ -13,7 +19,7 @@ endif COMMIT=`git describe --dirty --always --tags 2> /dev/null || true` GOLDFLAGS="-X main.gitCommit=${COMMIT} -X main.version=${VERSION}" -HYPER_BULD_TAGS=$(XEN_BUILD_TAG) $(LIBVIRT_BUILD_TAG) +HYPER_BULD_TAGS=$(XEN_BUILD_TAG) $(LIBVIRT_BUILD_TAG) $(9P_BUILD_TAG) all-local: build-runv clean-local: diff --git a/cli/sandbox.go b/cli/sandbox.go index 312d4ff0..5bcc4b04 100644 --- a/cli/sandbox.go +++ b/cli/sandbox.go @@ -74,6 +74,7 @@ func setupFactory(context *cli.Context, spec *specs.Spec) (factory.Factory, erro Bios: bios, Cbfs: cbfs, EnableVsock: vsock, + ContainerRootFs: spec.Root.Path, } return singlefactory.Dummy(bootConfig), nil } @@ -153,6 +154,7 @@ func destroySandbox(vm *hypervisor.Vm, lockFile *os.File) { glog.Errorf("StopPod timeout") } vm.Kill() + os.RemoveAll("/tmp/"+vm.Id) // cli refactor todo: kill the proxy if vm.Shutdown() failed. diff --git a/configure.ac b/configure.ac index 4df07fdc..53468606 100644 --- a/configure.ac +++ b/configure.ac @@ -31,6 +31,12 @@ esac # Checks for libraries. +AC_ARG_WITH([9p], + [AS_HELP_STRING([--without-9p], + [run runv with 9p])], + [with_9p=no],[with_9p=yes]) + + LIBVIRT_REQUIRED="1.2.2" AC_ARG_WITH([libvirt], @@ -76,6 +82,8 @@ fi AM_CONDITIONAL([WITH_XEN], [test "x$with_xen" == "xyes"]) +AM_CONDITIONAL([WITH_9P], [test "x$with_9p" == "xyes"]) + AC_CONFIG_FILES([Makefile]) AC_OUTPUT @@ -90,4 +98,6 @@ AC_MSG_RESULT([ with xen: ${with_xen} with libvirt: ${with_libvirt} + + with 9p: ${with_9p} ]) diff --git a/hyperstart/api/json/spec.go b/hyperstart/api/json/spec.go index 3d334b21..46d868eb 100644 --- a/hyperstart/api/json/spec.go +++ b/hyperstart/api/json/spec.go @@ -108,7 +108,7 @@ type Pod struct { DnsOptions []string `json:"dnsOptions,omitempty"` DnsSearch []string `json:"dnsSearch,omitempty"` DeprecatedRoutes []Route `json:"routes,omitempty"` - ShareDir string `json:"shareDir"` + ShareDir string `json:"shareDir,omitempty"` PortmappingWhiteLists *PortmappingWhiteList `json:"portmappingWhiteLists,omitempty"` } diff --git a/hyperstart/proxy/proxy.go b/hyperstart/proxy/proxy.go index c25633ac..5129dc9c 100644 --- a/hyperstart/proxy/proxy.go +++ b/hyperstart/proxy/proxy.go @@ -14,6 +14,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/health" "google.golang.org/grpc/health/grpc_health_v1" + "github.com/hyperhq/runv/hypervisor" ) type jsonProxy struct { @@ -108,10 +109,16 @@ func (proxy *jsonProxy) TtyWinResize(ctx context.Context, req *hyperstartgrpc.Tt } func (proxy *jsonProxy) StartSandbox(ctx context.Context, req *hyperstartgrpc.StartSandboxRequest) (*google_protobuf.Empty, error) { + var sharedDir string + if hypervisor.Is9pfsSupported(){ + sharedDir = "share_dir" + } else { + sharedDir = "" + } pod := &hyperstartjson.Pod{ Hostname: req.Hostname, Dns: req.Dns, - ShareDir: "share_dir", + ShareDir: sharedDir, } err := proxy.json.StartSandbox(pod) return pbEmpty(err), err diff --git a/hypervisor/driver.go b/hypervisor/driver.go index 428b5883..30d27851 100644 --- a/hypervisor/driver.go +++ b/hypervisor/driver.go @@ -22,6 +22,7 @@ type BootConfig struct { Initrd string Bios string Cbfs string + ContainerRootFs string // For network QoS (kilobytes/s) InboundAverage string diff --git a/hypervisor/qemu/qemu_amd64.go b/hypervisor/qemu/qemu_amd64.go index efbc29cf..a2eb7e44 100644 --- a/hypervisor/qemu/qemu_amd64.go +++ b/hypervisor/qemu/qemu_amd64.go @@ -56,6 +56,17 @@ func (qc *QemuContext) arguments(ctx *hypervisor.VmContext) []string { "-kernel", boot.Kernel, "-initrd", boot.Initrd, "-append", cmdline) } + if !hypervisor.Is9pfsSupported(){ + params = append(params, "-device", "virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x6") + params = append(params, "-drive", "file=/tmp/"+ctx.Id+"/rootfs.img,format=qcow2,if=none,id=drive-scsi0-1-0-0") + params = append(params, "-device", "scsi-hd,bus=scsi0.0,channel=0,scsi-id=1,lun=0,drive=drive-scsi0-1-0-0,id=scsi0-1-0-0") + params = append(params,"-device", "virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x2", "-device", "virtio-scsi-pci,id=scsi1,bus=pci.0,addr=0x3") + } else { + params = append(params,"-device", "virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x2", "-device", "virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x3") + params = append(params,"-fsdev", fmt.Sprintf("local,id=virtio9p,path=%s,security_model=none", ctx.ShareDir)) + params = append(params,"-device", fmt.Sprintf("virtio-9p-pci,fsdev=virtio9p,mount_tag=%s", hypervisor.ShareDirTag)) + } + params = append(params, "-realtime", "mlock=off", "-no-user-config", "-nodefaults", "-no-hpet", "-rtc", "base=utc,clock=vm,driftfix=slew", "-no-reboot", "-display", "none", "-boot", "strict=on", @@ -82,12 +93,9 @@ func (qc *QemuContext) arguments(ctx *hypervisor.VmContext) []string { } return append(params, "-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), ) } diff --git a/hypervisor/vm.go b/hypervisor/vm.go index eb09d91f..1480866c 100644 --- a/hypervisor/vm.go +++ b/hypervisor/vm.go @@ -7,6 +7,7 @@ import ( "fmt" "io/ioutil" "os" + "os/exec" "path/filepath" "strings" "syscall" @@ -771,6 +772,18 @@ func GetVm(vmId string, b *BootConfig, waitStarted bool) (*Vm, error) { } } + if !Is9pfsSupported() { + _, err := exec.LookPath("virt-make-fs") + if err != nil { + return nil, err + } else { + err = createRootFSDisk(id, b.ContainerRootFs) + if err != nil { + return nil, err + } + } + } + vm := newVm(id, b.CPU, b.Memory) if err := vm.launch(b); err != nil { return nil, err @@ -788,3 +801,30 @@ func GetVm(vmId string, b *BootConfig, waitStarted bool) (*Vm, error) { vm.Log(TRACE, "GetVm succeeded") return vm, nil } + +func createRootFSDisk(containerID string, rootfsPath string) error { + + //Container RootFS spec.Root.Path + //Create RootFS raw image at runqQemuRoot + "/vm_image" + vmdata.ContainerID + cmd := exec.Command("/bin/mkdir", "-p","/tmp/" + containerID) + err := cmd.Run() + if err != nil { + return fmt.Errorf("runq error: mkdir failed: %v", err) + } + //Create rootfs.img + cmd = exec.Command("/usr/bin/virt-make-fs", "--label=rootfs", "-F","qcow2", "-s", "+512M", "-t","ext4", rootfsPath, + "/tmp/" + containerID + "/rootfs.img") + var out bytes.Buffer + var stderr bytes.Buffer + cmd.Stdout = &out + cmd.Stderr = &stderr + err = cmd.Run() + if err != nil { + fmt.Printf("Stderr %s", cmd.Stderr) + fmt.Printf("Stdout %s", cmd.Stdout) + return fmt.Errorf("runq error: virt-make-fs failed: %v", err) + } + + return nil + +} diff --git a/hypervisor/with_9pfs.go b/hypervisor/with_9pfs.go new file mode 100644 index 00000000..79f6ee5a --- /dev/null +++ b/hypervisor/with_9pfs.go @@ -0,0 +1,7 @@ +// +build linux,amd64,with_9p + +package hypervisor + +func Is9pfsSupported() bool { + return true +} diff --git a/hypervisor/without_9pfs.go b/hypervisor/without_9pfs.go new file mode 100644 index 00000000..a3592b51 --- /dev/null +++ b/hypervisor/without_9pfs.go @@ -0,0 +1,9 @@ +// +build linux,amd64,!with_9p + + +package hypervisor + +func Is9pfsSupported() bool { + return false +} +