@@ -1895,3 +1895,133 @@ func (s *service) dialFirecrackerSocket() error {
1895
1895
1896
1896
return nil
1897
1897
}
1898
+
1899
+ // PauseVM Pauses a VM
1900
+ func (s * service ) PauseVM (ctx context.Context , req * proto.PauseVMRequest ) (* empty.Empty , error ) {
1901
+ pauseReq , err := formPauseReq ()
1902
+ if err != nil {
1903
+ s .logger .WithError (err ).Error ("Failed to create pause vm request" )
1904
+ return nil , err
1905
+ }
1906
+
1907
+ err = s .waitVMReady ()
1908
+ if err != nil {
1909
+ return nil , err
1910
+ }
1911
+
1912
+ resp , err := s .httpControlClient .Do (pauseReq )
1913
+ if err != nil {
1914
+ s .logger .WithError (err ).Error ("Failed to send pause VM request" )
1915
+ return nil , err
1916
+ }
1917
+ if ! strings .Contains (resp .Status , "204" ) {
1918
+ s .logger .WithError (err ).Error ("Failed to pause VM" )
1919
+ return nil , err
1920
+ }
1921
+
1922
+ return & empty.Empty {}, nil
1923
+ }
1924
+
1925
+ // ResumeVM Resumes a VM
1926
+ func (s * service ) ResumeVM (ctx context.Context , req * proto.ResumeVMRequest ) (* empty.Empty , error ) {
1927
+ resumeReq , err := formResumeReq ()
1928
+ if err != nil {
1929
+ s .logger .WithError (err ).Error ("Failed to create resume vm request" )
1930
+ return nil , err
1931
+ }
1932
+
1933
+ resp , err := s .httpControlClient .Do (resumeReq )
1934
+ if err != nil {
1935
+ s .logger .WithError (err ).Error ("Failed to send resume VM request" )
1936
+ return nil , err
1937
+ }
1938
+ if ! strings .Contains (resp .Status , "204" ) {
1939
+ s .logger .WithError (err ).Error ("Failed to resume VM" )
1940
+ return nil , err
1941
+ }
1942
+ return & empty.Empty {}, nil
1943
+ }
1944
+
1945
+ // LoadSnapshot Loads a VM from a snapshot
1946
+ func (s * service ) LoadSnapshot (ctx context.Context , req * proto.LoadSnapshotRequest ) (* proto.LoadResponse , error ) {
1947
+ if err := s .startFirecrackerProcess (); err != nil {
1948
+ s .logger .WithError (err ).Error ("startFirecrackerProcess returned an error" )
1949
+ return nil , err
1950
+ }
1951
+
1952
+ if err := s .dialFirecrackerSocket (); err != nil {
1953
+ s .logger .WithError (err ).Error ("Failed to wait for firecracker socket" )
1954
+ }
1955
+ s .createHTTPControlClient ()
1956
+
1957
+ sendSockAddr := s .shimDir .FirecrackerUPFSockPath ()
1958
+ if ! req .EnableUserPF {
1959
+ sendSockAddr = "dummy"
1960
+ }
1961
+
1962
+ loadSnapReq , err := formLoadSnapReq (req .SnapshotFilePath , req .MemFilePath , sendSockAddr , req .EnableUserPF )
1963
+ if err != nil {
1964
+ s .logger .WithError (err ).Error ("Failed to create load snapshot request" )
1965
+ return nil , err
1966
+ }
1967
+
1968
+ resp , err := s .httpControlClient .Do (loadSnapReq )
1969
+ if err != nil {
1970
+ s .logger .WithError (err ).Error ("Failed to send load snapshot request" )
1971
+ return nil , err
1972
+ }
1973
+ if ! strings .Contains (resp .Status , "204" ) {
1974
+ s .logger .WithError (err ).Error ("Failed to load VM from snapshot" )
1975
+ s .logger .WithError (err ).Errorf ("Status of request: %s" , resp .Status )
1976
+ return nil , err
1977
+ }
1978
+
1979
+ return & proto.LoadResponse {FirecrackerPID : strconv .Itoa (s .firecrackerPid )}, nil
1980
+ }
1981
+
1982
+ // CreateSnapshot Creates a snapshot of a VM
1983
+ func (s * service ) CreateSnapshot (ctx context.Context , req * proto.CreateSnapshotRequest ) (* empty.Empty , error ) {
1984
+ createSnapReq , err := formCreateSnapReq (req .SnapshotFilePath , req .MemFilePath )
1985
+ if err != nil {
1986
+ s .logger .WithError (err ).Error ("Failed to create make snapshot request" )
1987
+ return nil , err
1988
+ }
1989
+
1990
+ resp , err := s .httpControlClient .Do (createSnapReq )
1991
+ if err != nil {
1992
+ s .logger .WithError (err ).Error ("Failed to send make snapshot request" )
1993
+ return nil , err
1994
+ }
1995
+ if ! strings .Contains (resp .Status , "204" ) {
1996
+ s .logger .WithError (err ).Error ("Failed to make snapshot of VM" )
1997
+ return nil , err
1998
+ }
1999
+
2000
+ return & empty.Empty {}, nil
2001
+ }
2002
+
2003
+ // Offload Shuts down a VM and deletes the corresponding firecracker socket
2004
+ // and vsock. All of the other resources will persist
2005
+ func (s * service ) Offload (ctx context.Context , req * proto.OffloadRequest ) (* empty.Empty , error ) {
2006
+ if err := syscall .Kill (s .firecrackerPid , 9 ); err != nil {
2007
+ s .logger .WithError (err ).Error ("Failed to kill firecracker process" )
2008
+ return nil , err
2009
+ }
2010
+
2011
+ if err := os .RemoveAll (s .shimDir .FirecrackerSockPath ()); err != nil {
2012
+ s .logger .WithError (err ).Error ("Failed to delete firecracker socket" )
2013
+ return nil , err
2014
+ }
2015
+
2016
+ if err := os .RemoveAll (s .shimDir .FirecrackerVSockPath ()); err != nil {
2017
+ s .logger .WithError (err ).Error ("Failed to delete firecracker vsock" )
2018
+ return nil , err
2019
+ }
2020
+
2021
+ if err := os .RemoveAll (s .shimDir .FirecrackerUPFSockPath ()); err != nil {
2022
+ s .logger .WithError (err ).Error ("Failed to delete firecracker UPF socket" )
2023
+ return nil , err
2024
+ }
2025
+
2026
+ return & empty.Empty {}, nil
2027
+ }
0 commit comments