Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 21b4047

Browse files
committed
show pause status
Signed-off-by: Gao feng <[email protected]>
1 parent 5871f3d commit 21b4047

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

daemon/list.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ func showVM(v *hypervisor.Vm) string {
151151
case types.S_VM_IDLE:
152152
status = "idle"
153153
break
154+
case types.S_VM_PAUSED:
155+
status = "pasued"
156+
break
154157
default:
155158
status = ""
156159
break
@@ -176,6 +179,8 @@ func showPod(pod *hypervisor.PodStatus) string {
176179
if pod.Type == "kubernetes" {
177180
status = "failed(kubernetes)"
178181
}
182+
case types.S_POD_PAUSED:
183+
status = "paused"
179184
case types.S_POD_SUCCEEDED:
180185
status = "succeeded"
181186
if pod.Type == "kubernetes" {

daemon/pause.go

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,43 @@ import (
55

66
"github.com/golang/glog"
77
"github.com/hyperhq/hyper/engine"
8+
"github.com/hyperhq/runv/hypervisor/types"
89
)
910

10-
func (daemon *Daemon) CmdPause(job *engine.Job) (err error) {
11+
func (daemon *Daemon) CmdPause(job *engine.Job) error {
1112
if len(job.Args) == 0 {
1213
return fmt.Errorf("Can not execute 'pause' command without pod id!")
1314
}
1415

1516
podId := job.Args[0]
16-
1717
glog.V(1).Infof("Get pod id is %s", podId)
1818

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)
2226
}
27+
vmId := pod.status.Vm
28+
glog.V(2).Infof("unlock read of PodList")
29+
daemon.PodList.RUnlock()
2330

2431
vm, ok := daemon.VmList[vmId]
2532
if !ok {
2633
return fmt.Errorf("Can not find VM whose Id is %s!", vmId)
2734
}
2835

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
3045
}
3146

3247
func (daemon Daemon) PauseContainer(container string) error {
@@ -56,17 +71,36 @@ func (daemon *Daemon) CmdUnpause(job *engine.Job) error {
5671

5772
podId := job.Args[0]
5873

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")
6288
}
6389

6490
vm, ok := daemon.VmList[vmId]
6591
if !ok {
6692
return fmt.Errorf("Can not find VM whose Id is %s!", vmId)
6793
}
6894

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
70104
}
71105

72106
func (daemon *Daemon) UnpauseContainer(container string) error {

0 commit comments

Comments
 (0)