Skip to content

Commit

Permalink
Test gcs-sidecar outside uvm
Browse files Browse the repository at this point in the history
Signed-off-by: Kirtana Ashok <[email protected]>
  • Loading branch information
kiashok committed Dec 6, 2024
1 parent 044046a commit 4216874
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 36 deletions.
83 changes: 50 additions & 33 deletions cmd/gcs-sidecar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,58 +190,60 @@ func runService(name string, isDebug bool) error {
}

func main() {
// Ignore the following log when running sidecar outside the uvm.
// Logs will be at C:\\gcs-sidecar-logs-redirect.log.
// See internal/uvm/start.go#252 for more details.
f, err := os.OpenFile("C:\\gcs-sidecar-logs.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
fmt.Printf("error opening file: %v", err)
log.Fatalf("error opening file: %v", err)
}
defer f.Close()

log.SetOutput(f)

type srvResp struct {
err error
}
/*
type srvResp struct {
err error
}
chsrv := make(chan error)
go func() {
defer close(chsrv)
chsrv := make(chan error)
go func() {
defer close(chsrv)
if err := runService("gcs-sidecar", false); err != nil {
log.Fatalf("error starting gcs-sidecar service: %v", err)
}
if err := runService("gcs-sidecar", false); err != nil {
log.Fatalf("error starting gcs-sidecar service: %v", err)
}
chsrv <- err
}()
chsrv <- err
}()
select {
// case <-ctx.Done():
// return ctx.Err()
case r := <-chsrv:
if r != nil {
log.Fatal(r)
select {
// case <-ctx.Done():
// return ctx.Err()
case r := <-chsrv:
if r != nil {
log.Fatal(r)
}
}
}
*/

ctx := context.Background()
// 1. Setup connection with hcsshim external gcs connection
hvsockAddr := &winio.HvsockAddr{
VMID: gcs.HV_GUID_PARENT,
ServiceID: gcs.WindowsSidecarGcsHvsockServiceID,
// take in the uvm id as args
if len(os.Args) != 2 {
log.Printf("unexpected num of args: %v", len(os.Args))
fmt.Printf("unexpected num of args: %v", len(os.Args))
return
}
fmt.Printf("Dialing to hcsshim external bridge at address %v", hvsockAddr)
log.Printf("Dialing to hcsshim external bridge at address %v", hvsockAddr)

shimCon, err := winio.Dial(ctx, hvsockAddr)
uvmID, err := guid.FromString(os.Args[1])
if err != nil {
fmt.Printf("Error dialing hcsshim external bridge at address %v", hvsockAddr)
log.Printf("Error dialing hcsshim external bridge at address %v", hvsockAddr)
log.Printf("error getting guid from string %v", os.Args[1])
fmt.Printf("error getting guid from string %v", os.Args[1])
return
}

// 2. Start external server to connect with inbox GCS
ctx := context.Background()
// 1. Start external server to connect with inbox GCS
listener, err := winio.ListenHvsock(&winio.HvsockAddr{
VMID: gcs.HV_GUID_LOOPBACK,
VMID: uvmID,
//HV_GUID_PARENT,
ServiceID: gcs.WindowsGcsHvsockServiceID,
})
Expand All @@ -256,8 +258,23 @@ func main() {

gcsCon, err := acceptAndClose(ctx, gcsListener)
if err != nil {
fmt.Printf("Err accepting inbox GCS connection %v", err)
log.Printf("Err accepting inbox GCS connection %v", err)
fmt.Printf("Err accepting inbox GCS connection %v", err)
return
}

// 2. Setup connection with hcsshim external gcs connection
hvsockAddr := &winio.HvsockAddr{
VMID: gcs.HV_GUID_LOOPBACK,
ServiceID: gcs.WindowsSidecarGcsHvsockServiceID,
}
log.Printf("Dialing to hcsshim external bridge at address %v", hvsockAddr)
fmt.Printf("Dialing to hcsshim external bridge at address %v", hvsockAddr)

shimCon, err := winio.Dial(ctx, hvsockAddr)
if err != nil {
log.Printf("Error dialing hcsshim external bridge at address %v", hvsockAddr)
fmt.Printf("Error dialing hcsshim external bridge at address %v", hvsockAddr)
return
}

Expand Down
6 changes: 3 additions & 3 deletions internal/uvm/create_wcow.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ func (uvm *UtilityVM) startExternalGcsListener(ctx context.Context) error {
log.G(ctx).WithField("vmID", uvm.runtimeID).Debug("Using external GCS bridge")

l, err := winio.ListenHvsock(&winio.HvsockAddr{
VMID: uvm.runtimeID,
// gcs.HV_GUID_PARENT,
VMID: gcs.HV_GUID_LOOPBACK,
// uvm.runtimeID,
ServiceID: gcs.WindowsSidecarGcsHvsockServiceID,
//gcs.WindowsGcsHvsockServiceID,
// gcs.WindowsGcsHvsockServiceID,
})
if err != nil {
return err
Expand Down
30 changes: 30 additions & 0 deletions internal/uvm/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (
"fmt"
"io"
"net"
"os"
"os/exec"
"syscall"
"time"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -246,6 +249,33 @@ func (uvm *UtilityVM) Start(ctx context.Context) (err error) {
}

if uvm.gcListener != nil {
// Temp: Hack to just kick off the gcs sidecar process as
// a simple process on the host to fasten debugging and
// development. After dev work, it can be easily tested
// by minor tweaks to hvsockAddress to run inside the uvm
// + inbox gcs to listen on HV_SOCK_LOOPBACK.
sidecarPath := "C:\\gcs-sidecar.exe"
//sidecarCmd := fmt.Sprintf("%s %s", sidecarPath, uvm.runtimeID)
cmd := exec.Command(sidecarPath, uvm.runtimeID.String())

// Set the Pdeathsig field to 0 to prevent the subprocess from being terminated
// when the parent process exits
cmd.SysProcAttr = &syscall.SysProcAttr{
ParentProcess: 0,
}
// Redirect stdout to a file
outfile, err := os.Create("C:\\gcs-sidecar-logs-redirect.log")
if err != nil {
return fmt.Errorf("error create sidecar log file")
}
// defer outfile.Close()
cmd.Stdout = outfile

err = cmd.Start()
if err != nil {
return fmt.Errorf("failed to do start gcs-sidecar: %w", err)
}

// Accept the GCS connection.
conn, err := uvm.acceptAndClose(ctx, uvm.gcListener)
uvm.gcListener = nil
Expand Down

0 comments on commit 4216874

Please sign in to comment.