@@ -22,13 +22,13 @@ import (
22
22
"net"
23
23
"net/http"
24
24
"os"
25
+ "os/exec"
25
26
"runtime/debug"
26
27
"strconv"
27
28
"strings"
28
29
"sync"
29
- "time"
30
- "os/exec"
31
30
"syscall"
31
+ "time"
32
32
33
33
// disable gosec check for math/rand. We just need a random starting
34
34
// place to start looking for CIDs; no need for cryptographically
@@ -152,8 +152,8 @@ type service struct {
152
152
vsockPortMu sync.Mutex
153
153
154
154
// httpControlClient is to send pause/resume/snapshot commands to the microVM
155
- httpControlClient * http.Client
156
- firecrackerPid int
155
+ httpControlClient * http.Client
156
+ firecrackerPid int
157
157
taskDrivePathOnHost string
158
158
}
159
159
@@ -489,7 +489,7 @@ func (s *service) CreateVM(requestCtx context.Context, request *proto.CreateVMRe
489
489
s .logger .WithError (err ).Error ("failed to publish start VM event" )
490
490
}
491
491
492
- // Commented out because its execution cancels the shim, and
492
+ // Commented out because its execution cancels the shim, and
493
493
// it would get executed on Offload if we leave it, killing the shim,
494
494
// and making snapshots impossible.
495
495
//go s.monitorVMExit()
@@ -595,12 +595,14 @@ func (s *service) createVM(requestCtx context.Context, request *proto.CreateVMRe
595
595
596
596
s .createHTTPControlClient ()
597
597
598
- if pid , err := s .machine .PID (); err != nil {
598
+ pid , err := s .machine .PID ()
599
+ if err != nil {
599
600
s .logger .WithError (err ).Error ("Failed to get PID of firecracker process" )
600
601
return err
601
- } else {
602
- s .firecrackerPid = pid
603
602
}
603
+
604
+ s .firecrackerPid = pid
605
+
604
606
s .logger .Info ("successfully started the VM" )
605
607
606
608
return nil
@@ -782,7 +784,7 @@ func (s *service) ResumeVM(ctx context.Context, req *proto.ResumeVMRequest) (*em
782
784
783
785
// LoadSnapshot Loads a VM from a snapshot
784
786
func (s * service ) LoadSnapshot (ctx context.Context , req * proto.LoadSnapshotRequest ) (* empty.Empty , error ) {
785
- if err := s .startFirecrackerProcess () ; err != nil {
787
+ if err := s .startFirecrackerProcess (); err != nil {
786
788
s .logger .WithError (err ).Error ("startFirecrackerProcess returned an error" )
787
789
return nil , err
788
790
}
@@ -894,7 +896,7 @@ func (s *service) buildVMConfiguration(req *proto.CreateVMRequest) (*firecracker
894
896
s .logger .WithError (err ).Errorf ("Failed to delete %s" , logFilePath )
895
897
return nil , err
896
898
}
897
- if _ , err := os .OpenFile (logFilePath , os .O_RDONLY | os .O_CREATE , 0666 ); err != nil {
899
+ if _ , err := os .OpenFile (logFilePath , os .O_RDONLY | os .O_CREATE , 0600 ); err != nil {
898
900
s .logger .WithError (err ).Errorf ("Failed to create %s" , logFilePath )
899
901
return nil , err
900
902
}
@@ -906,10 +908,10 @@ func (s *service) buildVMConfiguration(req *proto.CreateVMRequest) (*firecracker
906
908
ID : "agent_api" ,
907
909
}},
908
910
// Put LogPath insteadof LogFifo here to comply with the new Firecracker logging
909
- LogPath : logFilePath ,
910
- MachineCfg : machineConfigurationFromProto (s .config , req .MachineCfg ),
911
- LogLevel : s .config .DebugHelper .GetFirecrackerLogLevel (),
912
- VMID : s .vmID ,
911
+ LogPath : logFilePath ,
912
+ MachineCfg : machineConfigurationFromProto (s .config , req .MachineCfg ),
913
+ LogLevel : s .config .DebugHelper .GetFirecrackerLogLevel (),
914
+ VMID : s .vmID ,
913
915
}
914
916
915
917
if req .JailerConfig != nil {
@@ -1518,6 +1520,8 @@ func (s *service) cleanup() error {
1518
1520
}
1519
1521
1520
1522
// monitorVMExit watches the VM and cleanup resources when it terminates.
1523
+ // Comment out because unused
1524
+ /*
1521
1525
func (s *service) monitorVMExit() {
1522
1526
// Block until the VM exits
1523
1527
if err := s.machine.Wait(s.shimCtx); err != nil && err != context.Canceled {
@@ -1528,6 +1532,7 @@ func (s *service) monitorVMExit() {
1528
1532
s.logger.WithError(err).Error("failed to clean up the VM")
1529
1533
}
1530
1534
}
1535
+ */
1531
1536
1532
1537
func (s * service ) createHTTPControlClient () {
1533
1538
u := & httpunix.Transport {
@@ -1642,20 +1647,20 @@ func formCreateSnapReq(snapshotPath, memPath string) (*http.Request, error) {
1642
1647
return req , nil
1643
1648
}
1644
1649
1645
- func formPatchDriveReq (drive_id , path_on_host string ) (* http.Request , error ) {
1650
+ func formPatchDriveReq (driveID , pathOnHost string ) (* http.Request , error ) {
1646
1651
var req * http.Request
1647
1652
1648
1653
data := map [string ]string {
1649
- "drive_id" : drive_id ,
1650
- "path_on_host" : path_on_host ,
1654
+ "drive_id" : driveID ,
1655
+ "path_on_host" : pathOnHost ,
1651
1656
}
1652
1657
json , err := json .Marshal (data )
1653
1658
if err != nil {
1654
1659
logrus .WithError (err ).Error ("Failed to marshal json data" )
1655
1660
return nil , err
1656
1661
}
1657
1662
1658
- req , err = http .NewRequest ("PATCH" , fmt .Sprintf ("http+unix://firecracker/drives/%s" , drive_id ), bytes .NewBuffer (json ))
1663
+ req , err = http .NewRequest ("PATCH" , fmt .Sprintf ("http+unix://firecracker/drives/%s" , driveID ), bytes .NewBuffer (json ))
1659
1664
if err != nil {
1660
1665
logrus .WithError (err ).Error ("Failed to create new HTTP request in formPauseReq" )
1661
1666
return nil , err
@@ -1674,14 +1679,13 @@ func (s *service) startFirecrackerProcess() error {
1674
1679
return err
1675
1680
}
1676
1681
1677
-
1678
1682
// TODO: Remove hardcoding and make a parameter
1679
1683
logFilePath := fmt .Sprintf ("/tmp/log_%s_after.logs" , s .vmID )
1680
1684
if err := os .RemoveAll (logFilePath ); err != nil {
1681
1685
s .logger .WithError (err ).Errorf ("Failed to delete %s" , logFilePath )
1682
1686
return err
1683
1687
}
1684
- if _ , err := os .OpenFile (logFilePath , os .O_RDONLY | os .O_CREATE , 0666 ); err != nil {
1688
+ if _ , err := os .OpenFile (logFilePath , os .O_RDONLY | os .O_CREATE , 0600 ); err != nil {
1685
1689
s .logger .WithError (err ).Errorf ("Failed to create %s" , logFilePath )
1686
1690
return err
1687
1691
}
@@ -1706,4 +1710,4 @@ func (s *service) startFirecrackerProcess() error {
1706
1710
s .firecrackerPid = firecrackerCmd .Process .Pid
1707
1711
1708
1712
return nil
1709
- }
1713
+ }
0 commit comments