Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions driverloader/driverloader_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hyperhq/runv/hypervisor/libvirt"
"github.com/hyperhq/runv/hypervisor/qemu"
"github.com/hyperhq/runv/hypervisor/xen"
"github.com/hyperhq/runv/hypervisor/xenpv"
"github.com/hyperhq/runv/lib/vsock"
)

Expand Down Expand Up @@ -38,6 +39,12 @@ func Probe(driver string) (hd hypervisor.HypervisorDriver, err error) {
glog.V(1).Infof("Driver %q loaded", driver)
return qd, nil
}
case "xenpv":
xpd := xenpv.InitDriver()
if xpd != nil {
glog.V(1).Infof("Driver xenpv loaded")
return xpd, nil
}
case "xen", "":
xd := xen.InitDriver()
if xd != nil {
Expand Down
1 change: 1 addition & 0 deletions hyperstart/api/json/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ const HYPER_VSOCK_CTL_PORT = 2718
const HYPER_VSOCK_MSG_PORT = 2719

const HYPER_USE_SERIAL = "hyper_use_serial"
const HYPER_P9_USE_XEN = "hyper_p9_xen"
46 changes: 24 additions & 22 deletions hypervisor/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type VmContext struct {

cancelWatchHyperstart chan struct{}

sockConnected chan bool

logPrefix string

lock sync.RWMutex //protect update of context
Expand Down Expand Up @@ -115,28 +117,28 @@ func InitContext(id string, hub chan VmEvent, client chan *types.VmResponse, dc
}

ctx = &VmContext{
Id: id,
Boot: boot,
PauseState: PauseStateUnpaused,
pciAddr: PciAddrFrom,
scsiId: 0,
GuestCid: cid,
Hub: hub,
client: client,
DCtx: dc,
HomeDir: homeDir,
HyperSockName: hyperSockName,
TtySockName: ttySockName,
ConsoleSockName: consoleSockName,
ShareDir: shareDir,
timer: nil,
handler: stateRunning,
current: StateRunning,
volumes: make(map[string]*DiskContext),
containers: make(map[string]*ContainerContext),
networks: NewNetworkContext(),
logPrefix: fmt.Sprintf("SB[%s] ", id),

Id: id,
Boot: boot,
PauseState: PauseStateUnpaused,
pciAddr: PciAddrFrom,
scsiId: 0,
GuestCid: cid,
Hub: hub,
client: client,
DCtx: dc,
HomeDir: homeDir,
HyperSockName: hyperSockName,
TtySockName: ttySockName,
ConsoleSockName: consoleSockName,
ShareDir: shareDir,
timer: nil,
handler: stateRunning,
current: StateRunning,
volumes: make(map[string]*DiskContext),
containers: make(map[string]*ContainerContext),
networks: NewNetworkContext(),
logPrefix: fmt.Sprintf("SB[%s] ", id),
sockConnected: make(chan bool),
cancelWatchHyperstart: make(chan struct{}),
}
ctx.networks.sandbox = ctx
Expand Down
6 changes: 6 additions & 0 deletions hypervisor/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ type DriverContext interface {
Close()
}

type ConsoleDriverContext interface {
DriverContext

ConnectConsole(console chan<- string) error
}

type LazyDriverContext interface {
DriverContext

Expand Down
6 changes: 5 additions & 1 deletion hypervisor/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ loop:
timeout.Stop()
}

func (ctx *VmContext) WaitSockConnected() {
<-ctx.sockConnected
}

func (ctx *VmContext) Launch() {
var err error

Expand All @@ -84,7 +88,7 @@ func (ctx *VmContext) Launch() {
if ctx.LogLevel(DEBUG) {
go watchVmConsole(ctx)
}

close(ctx.sockConnected)
go ctx.loop()
}

Expand Down
54 changes: 38 additions & 16 deletions hypervisor/kvmtool/lkvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type KvmtoolDriver struct {
//implement the hypervisor.DriverContext interface
type KvmtoolContext struct {
driver *KvmtoolDriver
conPty string
}

func InitDriver() *KvmtoolDriver {
Expand Down Expand Up @@ -221,11 +222,6 @@ func (kc *KvmtoolContext) Launch(ctx *hypervisor.VmContext) {
conPty, ctlPty, ttyPty := lookupPtys(output[:len])
ctx.Log(hypervisor.INFO, "find %v %v %v", conPty, ctlPty, ttyPty)
if conPty != "" && ctlPty != "" && ttyPty != "" {
conSock, err = net.Listen("unix", ctx.ConsoleSockName)
if err != nil {
return
}

ctlSock, err = net.Listen("unix", ctx.HyperSockName)
if err != nil {
return
Expand All @@ -235,9 +231,9 @@ func (kc *KvmtoolContext) Launch(ctx *hypervisor.VmContext) {
return
}

go sock2pty(conSock, conPty, false)
go sock2pty(ctlSock, ctlPty, true)
go sock2pty(ttySock, ttyPty, true)
kc.conPty = conPty
go sock2pty(ctlSock, ctlPty)
go sock2pty(ttySock, ttyPty)

go func() {
// without this, guest burst output will crash kvmtool, why?
Expand All @@ -264,7 +260,7 @@ func (kc *KvmtoolContext) Launch(ctx *hypervisor.VmContext) {
err = fmt.Errorf("cannot find pts devices used by lkvm")
}

func sock2pty(ls net.Listener, ptypath string, input bool) {
func sock2pty(ls net.Listener, ptypath string) {
defer ls.Close()

conn, err := ls.Accept()
Expand Down Expand Up @@ -299,13 +295,11 @@ func sock2pty(ls net.Listener, ptypath string, input bool) {
var newbuf []byte = nil
nr, er := src.Read(buf)
if nr > 0 {
newbuf = buf
if input {
newbuf = bytes.Replace(buf[:nr], []byte{1}, []byte{1, 1}, -1)
nr = len(newbuf)
} else {
newbuf = buf
}

nw, ew := dst.Write(newbuf[:nr])
if ew != nil {
glog.Infof("write failed: %v", ew)
Expand Down Expand Up @@ -334,10 +328,8 @@ func sock2pty(ls net.Listener, ptypath string, input bool) {
wg.Add(1)
go copy(conn, pty, false)

if input {
wg.Add(1)
go copy(pty, conn, true)
}
wg.Add(1)
go copy(pty, conn, true)

wg.Wait()
}
Expand Down Expand Up @@ -454,3 +446,33 @@ func (kc *KvmtoolContext) AddMem(ctx *hypervisor.VmContext, slot, size int) erro
func (kc *KvmtoolContext) Save(ctx *hypervisor.VmContext, path string) error {
return fmt.Errorf("Save is unsupported on kvmtool driver")
}

func (kc *KvmtoolContext) ConnectConsole(console chan<- string) error {
pty, err := os.OpenFile(kc.conPty, os.O_RDWR|syscall.O_NOCTTY, 0600)
if err != nil {
glog.Errorf("fail to open %v, %v", kc.conPty, err)
return err
}

_, err = term.SetRawTerminal(pty.Fd())
if err != nil {
glog.Errorf("fail to setrowmode for %v: %v", kc.conPty, err)
return err
}

go func() {
data := make([]byte, 128)
for {
nr, err := pty.Read(data)
if err != nil {
glog.Errorf("fail to read console: %v", err)
break
}
console <- string(data[:nr])
}
pty.Close()
}()

return nil

}
32 changes: 18 additions & 14 deletions hypervisor/vm_console.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,28 @@ func watchVmConsole(ctx *VmContext) {
return
}

conn, err := utils.UnixSocketConnect(ctx.ConsoleSockName)
if err != nil {
ctx.Log(ERROR, "failed to connected to %s: %v", ctx.ConsoleSockName, err)
return
}
cout := make(chan string, 128)
if dctx, ok := ctx.DCtx.(ConsoleDriverContext); ok {
dctx.ConnectConsole(cout)
} else {

ctx.Log(TRACE, "connected to %s", ctx.ConsoleSockName)
conn, err := utils.UnixSocketConnect(ctx.ConsoleSockName)
if err != nil {
ctx.Log(ERROR, "failed to connected to %s: %v", ctx.ConsoleSockName, err)
return
}

tc, err := telnet.NewConn(conn)
if err != nil {
ctx.Log(ERROR, "fail to init telnet connection to %s: %v", ctx.ConsoleSockName, err)
return
}
ctx.Log(TRACE, "connected %s as telnet mode.", ctx.ConsoleSockName)
ctx.Log(TRACE, "connected to %s", ctx.ConsoleSockName)

cout := make(chan string, 128)
go TtyLiner(tc, cout)
tc, err := telnet.NewConn(conn)
if err != nil {
ctx.Log(ERROR, "fail to init telnet connection to %s: %v", ctx.ConsoleSockName, err)
return
}
ctx.Log(TRACE, "connected %s as telnet mode.", ctx.ConsoleSockName)

go TtyLiner(tc, cout)
}
const ignoreLines = 128
for consoleLines := 0; consoleLines < ignoreLines; consoleLines++ {
line, ok := <-cout
Expand Down
Loading