Skip to content

Commit

Permalink
Merge pull request #17 from ustiugov/kill_shim_snapshots
Browse files Browse the repository at this point in the history
Move firecracker logs to shimDir
  • Loading branch information
ustiugov authored Sep 22, 2020
2 parents 7a8cf27 + 28d7396 commit 9f20578
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
6 changes: 6 additions & 0 deletions internal/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ const (
// ShimLogFifoName is the name of the FIFO created by containerd for a shim to write its logs to
ShimLogFifoName = "log"

// LogPathNameStart is the name of the FIFO created by containerd for a shim to write its logs to
LogPathNameStart = "log_start"

// LogPathNameLoad is the name of the FIFO created by containerd for a shim to write its logs to
LogPathNameLoad = "log_load"

// OCIConfigName is the name of the OCI bundle's config field
OCIConfigName = "config.json"

Expand Down
13 changes: 13 additions & 0 deletions internal/vm/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ func (d Dir) OpenLogFifo(requestCtx context.Context) (io.ReadWriteCloser, error)
return fifo.OpenFifo(requestCtx, d.LogFifoPath(), unix.O_WRONLY|unix.O_NONBLOCK, 0200)
}

// LogStartPath returns the path to the file for storing
// firecracker logs after the microVM is started and until
// it is Offloaded
func (d Dir) LogStartPath() string {
return filepath.Join(d.RootPath(), internal.LogPathNameStart)
}

// LogLoadPath returns the path to the file for storing
// firecracker logs after the microVM is loaded from a snapshot
func (d Dir) LogLoadPath() string {
return filepath.Join(d.RootPath(), internal.LogPathNameLoad)
}

// FirecrackerSockPath returns the path to the unix socket at which the firecracker VMM
// services its API
func (d Dir) FirecrackerSockPath() string {
Expand Down
14 changes: 4 additions & 10 deletions runtime/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,13 +875,8 @@ func (s *service) buildVMConfiguration(req *proto.CreateVMRequest) (*firecracker
}

// TODO: Remove hardcoding and make a parameter
logFilePath := fmt.Sprintf("/tmp/log_%s_start.logs", s.vmID)
if err := os.RemoveAll(logFilePath); err != nil {
s.logger.WithError(err).Errorf("Failed to delete %s", logFilePath)
return nil, err
}
if _, err := os.OpenFile(logFilePath, os.O_RDONLY|os.O_CREATE, 0600); err != nil {
s.logger.WithError(err).Errorf("Failed to create %s", logFilePath)
if _, err := os.OpenFile(s.shimDir.LogStartPath(), os.O_RDONLY|os.O_CREATE, 0600); err != nil {
s.logger.WithError(err).Errorf("Failed to create %s", s.shimDir.LogStartPath())
return nil, err
}

Expand All @@ -892,7 +887,7 @@ func (s *service) buildVMConfiguration(req *proto.CreateVMRequest) (*firecracker
ID: "agent_api",
}},
// Put LogPath insteadof LogFifo here to comply with the new Firecracker logging
LogPath: logFilePath,
LogPath: s.shimDir.LogStartPath(),
MachineCfg: machineConfigurationFromProto(s.config, req.MachineCfg),
LogLevel: s.config.DebugHelper.GetFirecrackerLogLevel(),
VMID: s.vmID,
Expand Down Expand Up @@ -1629,8 +1624,7 @@ func (s *service) startFirecrackerProcess() error {
return err
}

// TODO: Remove hardcoding and make a parameter
logFilePath := fmt.Sprintf("/tmp/log_%s_after.logs", s.vmID)
logFilePath := s.shimDir.LogLoadPath()
if err := os.RemoveAll(logFilePath); err != nil {
s.logger.WithError(err).Errorf("Failed to delete %s", logFilePath)
return err
Expand Down
2 changes: 1 addition & 1 deletion runtime/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func TestBuildVMConfiguration(t *testing.T) {
// TODO: FIX TEST WHEN LogPath is no longer hardcoded
//tc.expectedCfg.LogFifo = svc.shimDir.FirecrackerLogFifoPath()
//tc.expectedCfg.MetricsFifo = svc.shimDir.FirecrackerMetricsFifoPath()
tc.expectedCfg.LogPath = "/tmp/log__start.logs"
tc.expectedCfg.LogPath = svc.shimDir.LogStartPath()

drives := make([]models.Drive, tc.expectedStubDriveCount)
for i := 0; i < tc.expectedStubDriveCount; i++ {
Expand Down

0 comments on commit 9f20578

Please sign in to comment.