Skip to content

Commit

Permalink
firecracker: record VM process ID
Browse files Browse the repository at this point in the history
After the VM is started, it's sometimes necessary to interact with the
`firecracker` process directly, which requires knowing its PID.

Record the `firecracker` process ID when it starts and bubble it up to
the peer.
  • Loading branch information
lgfa29 authored and pojntfx committed Jul 29, 2024
1 parent 4b91624 commit e450e22
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/firecracker/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const (

type FirecrackerServer struct {
VMPath string
VMPid int
Wait func() error
Close func() error
}
Expand Down Expand Up @@ -136,6 +137,7 @@ func StartFirecrackerServer(
if err := cmd.Start(); err != nil {
panic(errors.Join(ErrCouldNotStartFirecrackerServer, err))
}
server.VMPid = cmd.Process.Pid

var closeLock sync.Mutex
closed := false
Expand Down
2 changes: 2 additions & 0 deletions pkg/roles/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ type peerStage5 struct {

type Peer struct {
VMPath string
VMPid int

Wait func() error
Close func() error
Expand Down Expand Up @@ -299,6 +300,7 @@ func StartPeer(
}

peer.VMPath = runner.VMPath
peer.VMPid = runner.VMPid

// We don't track this because we return the wait function
handleGoroutinePanics(false, func() {
Expand Down
2 changes: 2 additions & 0 deletions pkg/roles/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type SnapshotLoadConfiguration struct {

type Runner struct {
VMPath string
VMPid int

Wait func() error
Close func() error
Expand Down Expand Up @@ -173,6 +174,7 @@ func StartRunner(
}

runner.VMPath = server.VMPath
runner.VMPid = server.VMPid

// We intentionally don't call `wg.Add` and `wg.Done` here since we return the process's wait method
// We still need to `defer handleGoroutinePanic()()` here however so that we catch any errors during this call
Expand Down

0 comments on commit e450e22

Please sign in to comment.