Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 6f43c6c

Browse files
author
Harshal Patil
committed
build tags for no 9pfs support
Signed-off-by: Harshal Patil <[email protected]>
1 parent 0235ecf commit 6f43c6c

File tree

10 files changed

+96
-6
lines changed

10 files changed

+96
-6
lines changed

Diff for: Makefile.am

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
export GO15VENDOREXPERIMENT=1
2+
if WITH_9P
3+
9P_BUILD_TAG=with_9p
4+
else
5+
9P_BUILD_TAG=
6+
endif
7+
28
if WITH_XEN
39
XEN_BUILD_TAG=with_xen
410
else
@@ -13,7 +19,7 @@ endif
1319

1420
COMMIT=`git describe --dirty --always --tags 2> /dev/null || true`
1521
GOLDFLAGS="-X main.gitCommit=${COMMIT} -X main.version=${VERSION}"
16-
HYPER_BULD_TAGS=$(XEN_BUILD_TAG) $(LIBVIRT_BUILD_TAG)
22+
HYPER_BULD_TAGS=$(XEN_BUILD_TAG) $(LIBVIRT_BUILD_TAG) $(9P_BUILD_TAG)
1723

1824
all-local: build-runv
1925
clean-local:

Diff for: cli/sandbox.go

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func setupFactory(context *cli.Context, spec *specs.Spec) (factory.Factory, erro
7474
Bios: bios,
7575
Cbfs: cbfs,
7676
EnableVsock: vsock,
77+
ContainerRootFs: spec.Root.Path,
7778
}
7879
return singlefactory.Dummy(bootConfig), nil
7980
}
@@ -153,6 +154,7 @@ func destroySandbox(vm *hypervisor.Vm, lockFile *os.File) {
153154
glog.Errorf("StopPod timeout")
154155
}
155156
vm.Kill()
157+
os.RemoveAll("/tmp/"+vm.Id)
156158

157159
// cli refactor todo: kill the proxy if vm.Shutdown() failed.
158160

Diff for: configure.ac

+10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ esac
3131

3232
# Checks for libraries.
3333

34+
AC_ARG_WITH([9p],
35+
[AS_HELP_STRING([--without-9p],
36+
[run runv with 9p])],
37+
[with_9p=no],[with_9p=yes])
38+
39+
3440
LIBVIRT_REQUIRED="1.2.2"
3541

3642
AC_ARG_WITH([libvirt],
@@ -76,6 +82,8 @@ fi
7682

7783
AM_CONDITIONAL([WITH_XEN], [test "x$with_xen" == "xyes"])
7884

85+
AM_CONDITIONAL([WITH_9P], [test "x$with_9p" == "xyes"])
86+
7987
AC_CONFIG_FILES([Makefile])
8088

8189
AC_OUTPUT
@@ -90,4 +98,6 @@ AC_MSG_RESULT([
9098
with xen: ${with_xen}
9199
92100
with libvirt: ${with_libvirt}
101+
102+
with 9p: ${with_9p}
93103
])

Diff for: hyperstart/api/json/spec.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ type Pod struct {
108108
DnsOptions []string `json:"dnsOptions,omitempty"`
109109
DnsSearch []string `json:"dnsSearch,omitempty"`
110110
DeprecatedRoutes []Route `json:"routes,omitempty"`
111-
ShareDir string `json:"shareDir"`
111+
ShareDir string `json:"shareDir,omitempty"`
112112
PortmappingWhiteLists *PortmappingWhiteList `json:"portmappingWhiteLists,omitempty"`
113113
}
114114

Diff for: hyperstart/proxy/proxy.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"google.golang.org/grpc"
1515
"google.golang.org/grpc/health"
1616
"google.golang.org/grpc/health/grpc_health_v1"
17+
"github.com/hyperhq/runv/hypervisor"
1718
)
1819

1920
type jsonProxy struct {
@@ -108,10 +109,16 @@ func (proxy *jsonProxy) TtyWinResize(ctx context.Context, req *hyperstartgrpc.Tt
108109
}
109110

110111
func (proxy *jsonProxy) StartSandbox(ctx context.Context, req *hyperstartgrpc.StartSandboxRequest) (*google_protobuf.Empty, error) {
112+
var sharedDir string
113+
if hypervisor.Is9pfsSupported(){
114+
sharedDir = "share_dir"
115+
} else {
116+
sharedDir = ""
117+
}
111118
pod := &hyperstartjson.Pod{
112119
Hostname: req.Hostname,
113120
Dns: req.Dns,
114-
ShareDir: "share_dir",
121+
ShareDir: sharedDir,
115122
}
116123
err := proxy.json.StartSandbox(pod)
117124
return pbEmpty(err), err

Diff for: hypervisor/driver.go

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type BootConfig struct {
2222
Initrd string
2323
Bios string
2424
Cbfs string
25+
ContainerRootFs string
2526

2627
// For network QoS (kilobytes/s)
2728
InboundAverage string

Diff for: hypervisor/qemu/qemu_amd64.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ func (qc *QemuContext) arguments(ctx *hypervisor.VmContext) []string {
5656
"-kernel", boot.Kernel, "-initrd", boot.Initrd, "-append", cmdline)
5757
}
5858

59+
if !hypervisor.Is9pfsSupported(){
60+
params = append(params, "-device", "virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x6")
61+
params = append(params, "-drive", "file=/tmp/"+ctx.Id+"/rootfs.img,format=qcow2,if=none,id=drive-scsi0-1-0-0")
62+
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")
63+
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")
64+
} else {
65+
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")
66+
params = append(params,"-fsdev", fmt.Sprintf("local,id=virtio9p,path=%s,security_model=none", ctx.ShareDir))
67+
params = append(params,"-device", fmt.Sprintf("virtio-9p-pci,fsdev=virtio9p,mount_tag=%s", hypervisor.ShareDirTag))
68+
}
69+
5970
params = append(params,
6071
"-realtime", "mlock=off", "-no-user-config", "-nodefaults", "-no-hpet",
6172
"-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 {
8293
}
8394

8495
return append(params, "-qmp", fmt.Sprintf("unix:%s,server,nowait", qc.qmpSockName), "-serial", fmt.Sprintf("unix:%s,server,nowait", ctx.ConsoleSockName),
85-
"-device", "virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x2", "-device", "virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x3",
8696
"-chardev", fmt.Sprintf("socket,id=charch0,path=%s,server,nowait", ctx.HyperSockName),
8797
"-device", "virtserialport,bus=virtio-serial0.0,nr=1,chardev=charch0,id=channel0,name=sh.hyper.channel.0",
8898
"-chardev", fmt.Sprintf("socket,id=charch1,path=%s,server,nowait", ctx.TtySockName),
8999
"-device", "virtserialport,bus=virtio-serial0.0,nr=2,chardev=charch1,id=channel1,name=sh.hyper.channel.1",
90-
"-fsdev", fmt.Sprintf("local,id=virtio9p,path=%s,security_model=none", ctx.ShareDir),
91-
"-device", fmt.Sprintf("virtio-9p-pci,fsdev=virtio9p,mount_tag=%s", hypervisor.ShareDirTag),
92100
)
93101
}

Diff for: hypervisor/vm.go

+40
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"io/ioutil"
99
"os"
10+
"os/exec"
1011
"path/filepath"
1112
"strings"
1213
"syscall"
@@ -771,6 +772,18 @@ func GetVm(vmId string, b *BootConfig, waitStarted bool) (*Vm, error) {
771772
}
772773
}
773774

775+
if !Is9pfsSupported() {
776+
_, err := exec.LookPath("virt-make-fs")
777+
if err != nil {
778+
return nil, err
779+
} else {
780+
err = createRootFSDisk(id, b.ContainerRootFs)
781+
if err != nil {
782+
return nil, err
783+
}
784+
}
785+
}
786+
774787
vm := newVm(id, b.CPU, b.Memory)
775788
if err := vm.launch(b); err != nil {
776789
return nil, err
@@ -788,3 +801,30 @@ func GetVm(vmId string, b *BootConfig, waitStarted bool) (*Vm, error) {
788801
vm.Log(TRACE, "GetVm succeeded")
789802
return vm, nil
790803
}
804+
805+
func createRootFSDisk(containerID string, rootfsPath string) error {
806+
807+
//Container RootFS spec.Root.Path
808+
//Create RootFS raw image at runqQemuRoot + "/vm_image" + vmdata.ContainerID
809+
cmd := exec.Command("/bin/mkdir", "-p","/tmp/" + containerID)
810+
err := cmd.Run()
811+
if err != nil {
812+
return fmt.Errorf("runq error: mkdir failed: %v", err)
813+
}
814+
//Create rootfs.img
815+
cmd = exec.Command("/usr/bin/virt-make-fs", "--label=rootfs", "-F","qcow2", "-s", "+512M", "-t","ext4", rootfsPath,
816+
"/tmp/" + containerID + "/rootfs.img")
817+
var out bytes.Buffer
818+
var stderr bytes.Buffer
819+
cmd.Stdout = &out
820+
cmd.Stderr = &stderr
821+
err = cmd.Run()
822+
if err != nil {
823+
fmt.Printf("Stderr %s", cmd.Stderr)
824+
fmt.Printf("Stdout %s", cmd.Stdout)
825+
return fmt.Errorf("runq error: virt-make-fs failed: %v", err)
826+
}
827+
828+
return nil
829+
830+
}

Diff for: hypervisor/with_9pfs.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// +build linux,amd64,with_9p
2+
3+
package hypervisor
4+
5+
func Is9pfsSupported() bool {
6+
return true
7+
}

Diff for: hypervisor/without_9pfs.go

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// +build linux,amd64,!with_9p
2+
3+
4+
package hypervisor
5+
6+
func Is9pfsSupported() bool {
7+
return false
8+
}
9+

0 commit comments

Comments
 (0)