Skip to content

Commit 9f20578

Browse files
authored
Merge pull request #17 from ustiugov/kill_shim_snapshots
Move firecracker logs to shimDir
2 parents 7a8cf27 + 28d7396 commit 9f20578

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

internal/common.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ const (
5050
// ShimLogFifoName is the name of the FIFO created by containerd for a shim to write its logs to
5151
ShimLogFifoName = "log"
5252

53+
// LogPathNameStart is the name of the FIFO created by containerd for a shim to write its logs to
54+
LogPathNameStart = "log_start"
55+
56+
// LogPathNameLoad is the name of the FIFO created by containerd for a shim to write its logs to
57+
LogPathNameLoad = "log_load"
58+
5359
// OCIConfigName is the name of the OCI bundle's config field
5460
OCIConfigName = "config.json"
5561

internal/vm/dir.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,19 @@ func (d Dir) OpenLogFifo(requestCtx context.Context) (io.ReadWriteCloser, error)
8383
return fifo.OpenFifo(requestCtx, d.LogFifoPath(), unix.O_WRONLY|unix.O_NONBLOCK, 0200)
8484
}
8585

86+
// LogStartPath returns the path to the file for storing
87+
// firecracker logs after the microVM is started and until
88+
// it is Offloaded
89+
func (d Dir) LogStartPath() string {
90+
return filepath.Join(d.RootPath(), internal.LogPathNameStart)
91+
}
92+
93+
// LogLoadPath returns the path to the file for storing
94+
// firecracker logs after the microVM is loaded from a snapshot
95+
func (d Dir) LogLoadPath() string {
96+
return filepath.Join(d.RootPath(), internal.LogPathNameLoad)
97+
}
98+
8699
// FirecrackerSockPath returns the path to the unix socket at which the firecracker VMM
87100
// services its API
88101
func (d Dir) FirecrackerSockPath() string {

runtime/service.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -875,13 +875,8 @@ func (s *service) buildVMConfiguration(req *proto.CreateVMRequest) (*firecracker
875875
}
876876

877877
// TODO: Remove hardcoding and make a parameter
878-
logFilePath := fmt.Sprintf("/tmp/log_%s_start.logs", s.vmID)
879-
if err := os.RemoveAll(logFilePath); err != nil {
880-
s.logger.WithError(err).Errorf("Failed to delete %s", logFilePath)
881-
return nil, err
882-
}
883-
if _, err := os.OpenFile(logFilePath, os.O_RDONLY|os.O_CREATE, 0600); err != nil {
884-
s.logger.WithError(err).Errorf("Failed to create %s", logFilePath)
878+
if _, err := os.OpenFile(s.shimDir.LogStartPath(), os.O_RDONLY|os.O_CREATE, 0600); err != nil {
879+
s.logger.WithError(err).Errorf("Failed to create %s", s.shimDir.LogStartPath())
885880
return nil, err
886881
}
887882

@@ -892,7 +887,7 @@ func (s *service) buildVMConfiguration(req *proto.CreateVMRequest) (*firecracker
892887
ID: "agent_api",
893888
}},
894889
// Put LogPath insteadof LogFifo here to comply with the new Firecracker logging
895-
LogPath: logFilePath,
890+
LogPath: s.shimDir.LogStartPath(),
896891
MachineCfg: machineConfigurationFromProto(s.config, req.MachineCfg),
897892
LogLevel: s.config.DebugHelper.GetFirecrackerLogLevel(),
898893
VMID: s.vmID,
@@ -1629,8 +1624,7 @@ func (s *service) startFirecrackerProcess() error {
16291624
return err
16301625
}
16311626

1632-
// TODO: Remove hardcoding and make a parameter
1633-
logFilePath := fmt.Sprintf("/tmp/log_%s_after.logs", s.vmID)
1627+
logFilePath := s.shimDir.LogLoadPath()
16341628
if err := os.RemoveAll(logFilePath); err != nil {
16351629
s.logger.WithError(err).Errorf("Failed to delete %s", logFilePath)
16361630
return err

runtime/service_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ func TestBuildVMConfiguration(t *testing.T) {
260260
// TODO: FIX TEST WHEN LogPath is no longer hardcoded
261261
//tc.expectedCfg.LogFifo = svc.shimDir.FirecrackerLogFifoPath()
262262
//tc.expectedCfg.MetricsFifo = svc.shimDir.FirecrackerMetricsFifoPath()
263-
tc.expectedCfg.LogPath = "/tmp/log__start.logs"
263+
tc.expectedCfg.LogPath = svc.shimDir.LogStartPath()
264264

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

0 commit comments

Comments
 (0)