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

Commit 78f3912

Browse files
committed
XPod: add snapVolumes as snapshot of volumes
It handles the issue that XPod.updatePodInfo works without XPod.resourceLock but access XPod.volumes. Signed-off-by: Hui Zhu <teawater@hyper.sh>
1 parent 56de23a commit 78f3912

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

daemon/pod/persist.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ func LoadXPod(factory *PodFactory, layout *types.PersistPodLayout) (*XPod, error
128128
for _, v := range p.volumes {
129129
v.status = S_VOLUME_INSERTED
130130
}
131+
p.statusLock.Lock()
132+
for index := range p.snapVolumes {
133+
p.snapVolumes[index] = p.volumes[index].Info()
134+
}
135+
p.statusLock.Unlock()
131136
}
132137

133138
err = p.loadPodMeta()
@@ -403,6 +408,9 @@ func (p *XPod) loadVolume(id string) error {
403408
v.descript = vx.Descript
404409
v.status = S_VOLUME_CREATED
405410
p.volumes[v.spec.Name] = v
411+
p.statusLock.Lock()
412+
p.snapVolumes[v.spec.Name] = p.volumes[v.spec.Name].Info()
413+
p.statusLock.Unlock()
406414
return nil
407415
}
408416

daemon/pod/pod.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ type XPod struct {
7878
// on it too.
7979
stoppedChan chan bool
8080
initCond *sync.Cond
81+
82+
//Protected by statusLock
83+
snapVolumes map[string]*apitypes.PodVolume
8184
}
8285

8386
// The Log infrastructure, to add pod name as prefix of the log message.
@@ -339,14 +342,14 @@ func (p *XPod) updatePodInfo() error {
339342

340343
var (
341344
containers = make([]*apitypes.Container, 0, len(p.containers))
342-
volumes = make([]*apitypes.PodVolume, 0, len(p.volumes))
345+
volumes = make([]*apitypes.PodVolume, 0, len(p.snapVolumes))
343346
containerStatus = make([]*apitypes.ContainerStatus, 0, len(p.containers))
344347
)
345348

346349
p.info.Spec.Labels = p.labels
347350

348-
for _, v := range p.volumes {
349-
volumes = append(volumes, v.Info())
351+
for _, v := range p.snapVolumes {
352+
volumes = append(volumes, v)
350353
}
351354
p.info.Spec.Volumes = volumes
352355

daemon/pod/provision.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func newXPod(factory *PodFactory, spec *apitypes.UserPod) (*XPod, error) {
101101
statusLock: &sync.RWMutex{},
102102
stoppedChan: make(chan bool, 1),
103103
factory: factory,
104+
snapVolumes: make(map[string]*apitypes.PodVolume),
104105
}
105106
p.initCond = sync.NewCond(p.statusLock.RLocker())
106107
return p, nil
@@ -152,6 +153,9 @@ func (p *XPod) doContainerCreate(c *apitypes.UserContainer) (string, error) {
152153
continue
153154
}
154155
p.volumes[vol.Name] = newVolume(p, vol)
156+
p.statusLock.Lock()
157+
p.snapVolumes[vol.Name] = p.volumes[vol.Name].Info()
158+
p.statusLock.Unlock()
155159
nvs = append(nvs, vol.Name)
156160
}
157161
pc.Log(TRACE, "volumes to be added: %v", nvs)
@@ -373,6 +377,9 @@ func (p *XPod) initResources(spec *apitypes.UserPod, allowCreate bool) error {
373377
continue
374378
}
375379
p.volumes[vol.Name] = newVolume(p, vol)
380+
p.statusLock.Lock()
381+
p.snapVolumes[vol.Name] = p.volumes[vol.Name].Info()
382+
p.statusLock.Unlock()
376383
}
377384
}
378385

0 commit comments

Comments
 (0)