@@ -5,28 +5,43 @@ import (
5
5
6
6
"github.com/golang/glog"
7
7
"github.com/hyperhq/hyper/engine"
8
+ "github.com/hyperhq/runv/hypervisor/types"
8
9
)
9
10
10
- func (daemon * Daemon ) CmdPause (job * engine.Job ) ( err error ) {
11
+ func (daemon * Daemon ) CmdPause (job * engine.Job ) error {
11
12
if len (job .Args ) == 0 {
12
13
return fmt .Errorf ("Can not execute 'pause' command without pod id!" )
13
14
}
14
15
15
16
podId := job .Args [0 ]
16
-
17
17
glog .V (1 ).Infof ("Get pod id is %s" , podId )
18
18
19
- vmId , err := daemon .GetVmByPodId (podId )
20
- if err != nil {
21
- return err
19
+ daemon .PodList .RLock ()
20
+ glog .V (2 ).Infof ("lock read of PodList" )
21
+ pod , ok := daemon .PodList .Get (podId )
22
+ if ! ok {
23
+ glog .V (2 ).Infof ("unlock read of PodList" )
24
+ daemon .PodList .RUnlock ()
25
+ return fmt .Errorf ("Can not get Pod info with pod ID(%s)" , podId )
22
26
}
27
+ vmId := pod .status .Vm
28
+ glog .V (2 ).Infof ("unlock read of PodList" )
29
+ daemon .PodList .RUnlock ()
23
30
24
31
vm , ok := daemon .VmList [vmId ]
25
32
if ! ok {
26
33
return fmt .Errorf ("Can not find VM whose Id is %s!" , vmId )
27
34
}
28
35
29
- return vm .Pause (true )
36
+ if err := vm .Pause (true ); err != nil {
37
+ return err
38
+ }
39
+
40
+ pod .status .SetContainerStatus (types .S_POD_PAUSED )
41
+ pod .status .Status = types .S_POD_PAUSED
42
+ vm .Status = types .S_VM_PAUSED
43
+
44
+ return nil
30
45
}
31
46
32
47
func (daemon Daemon ) PauseContainer (container string ) error {
@@ -56,17 +71,36 @@ func (daemon *Daemon) CmdUnpause(job *engine.Job) error {
56
71
57
72
podId := job .Args [0 ]
58
73
59
- vmId , err := daemon .GetVmByPodId (podId )
60
- if err != nil {
61
- return err
74
+ daemon .PodList .RLock ()
75
+ glog .V (2 ).Infof ("lock read of PodList" )
76
+ pod , ok := daemon .PodList .Get (podId )
77
+ if ! ok {
78
+ glog .V (2 ).Infof ("unlock read of PodList" )
79
+ daemon .PodList .RUnlock ()
80
+ return fmt .Errorf ("Can not get Pod info with pod ID(%s)" , podId )
81
+ }
82
+ vmId := pod .status .Vm
83
+ glog .V (2 ).Infof ("unlock read of PodList" )
84
+ daemon .PodList .RUnlock ()
85
+
86
+ if pod .status .Status != types .S_POD_PAUSED {
87
+ return fmt .Errorf ("pod is not paused" )
62
88
}
63
89
64
90
vm , ok := daemon .VmList [vmId ]
65
91
if ! ok {
66
92
return fmt .Errorf ("Can not find VM whose Id is %s!" , vmId )
67
93
}
68
94
69
- return vm .Pause (false )
95
+ if err := vm .Pause (false ); err != nil {
96
+ return err
97
+ }
98
+
99
+ pod .status .SetContainerStatus (types .S_POD_RUNNING )
100
+ pod .status .Status = types .S_POD_RUNNING
101
+ vm .Status = types .S_VM_ASSOCIATED
102
+
103
+ return nil
70
104
}
71
105
72
106
func (daemon * Daemon ) UnpauseContainer (container string ) error {
0 commit comments