diff --git a/internal/common.go b/internal/common.go index 9e7a78b48..cb8cfb7a9 100644 --- a/internal/common.go +++ b/internal/common.go @@ -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" diff --git a/internal/vm/dir.go b/internal/vm/dir.go index 228350a35..6c3fdece7 100644 --- a/internal/vm/dir.go +++ b/internal/vm/dir.go @@ -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 { diff --git a/runtime/service.go b/runtime/service.go index 48e6e9dd6..99eb0ed77 100644 --- a/runtime/service.go +++ b/runtime/service.go @@ -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 } @@ -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, @@ -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 diff --git a/runtime/service_test.go b/runtime/service_test.go index 80e690221..b10417dd3 100644 --- a/runtime/service_test.go +++ b/runtime/service_test.go @@ -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++ {