@@ -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 {
@@ -1511,6 +1513,8 @@ func (s *service) cleanup() error {
1511
1513
}
1512
1514
1513
1515
// monitorVMExit watches the VM and cleanup resources when it terminates.
1516
+ // Comment out because unused
1517
+ /*
1514
1518
func (s *service) monitorVMExit() {
1515
1519
// Block until the VM exits
1516
1520
if err := s.machine.Wait(s.shimCtx); err != nil && err != context.Canceled {
@@ -1521,6 +1525,7 @@ func (s *service) monitorVMExit() {
1521
1525
s.logger.WithError(err).Error("failed to clean up the VM")
1522
1526
}
1523
1527
}
1528
+ */
1524
1529
1525
1530
func (s * service ) createHTTPControlClient () {
1526
1531
u := & httpunix.Transport {
@@ -1635,20 +1640,20 @@ func formCreateSnapReq(snapshotPath, memPath string) (*http.Request, error) {
1635
1640
return req , nil
1636
1641
}
1637
1642
1638
- func formPatchDriveReq (drive_id , path_on_host string ) (* http.Request , error ) {
1643
+ func formPatchDriveReq (driveID , pathOnHost string ) (* http.Request , error ) {
1639
1644
var req * http.Request
1640
1645
1641
1646
data := map [string ]string {
1642
- "drive_id" : drive_id ,
1643
- "path_on_host" : path_on_host ,
1647
+ "drive_id" : driveID ,
1648
+ "path_on_host" : pathOnHost ,
1644
1649
}
1645
1650
json , err := json .Marshal (data )
1646
1651
if err != nil {
1647
1652
logrus .WithError (err ).Error ("Failed to marshal json data" )
1648
1653
return nil , err
1649
1654
}
1650
1655
1651
- req , err = http .NewRequest ("PATCH" , fmt .Sprintf ("http+unix://firecracker/drives/%s" , drive_id ), bytes .NewBuffer (json ))
1656
+ req , err = http .NewRequest ("PATCH" , fmt .Sprintf ("http+unix://firecracker/drives/%s" , driveID ), bytes .NewBuffer (json ))
1652
1657
if err != nil {
1653
1658
logrus .WithError (err ).Error ("Failed to create new HTTP request in formPauseReq" )
1654
1659
return nil , err
@@ -1667,14 +1672,13 @@ func (s *service) startFirecrackerProcess() error {
1667
1672
return err
1668
1673
}
1669
1674
1670
-
1671
1675
// TODO: Remove hardcoding and make a parameter
1672
1676
logFilePath := fmt .Sprintf ("/tmp/log_%s_after.logs" , s .vmID )
1673
1677
if err := os .RemoveAll (logFilePath ); err != nil {
1674
1678
s .logger .WithError (err ).Errorf ("Failed to delete %s" , logFilePath )
1675
1679
return err
1676
1680
}
1677
- if _ , err := os .OpenFile (logFilePath , os .O_RDONLY | os .O_CREATE , 0666 ); err != nil {
1681
+ if _ , err := os .OpenFile (logFilePath , os .O_RDONLY | os .O_CREATE , 0600 ); err != nil {
1678
1682
s .logger .WithError (err ).Errorf ("Failed to create %s" , logFilePath )
1679
1683
return err
1680
1684
}
@@ -1699,4 +1703,4 @@ func (s *service) startFirecrackerProcess() error {
1699
1703
s .firecrackerPid = firecrackerCmd .Process .Pid
1700
1704
1701
1705
return nil
1702
- }
1706
+ }
0 commit comments