Skip to content

Commit 544730b

Browse files
committed
vc: Drop Sandbox#Pause and Sandbox#Resume
Fixes kata-containers#2276 Signed-off-by: Ted Yu <[email protected]>
1 parent d054556 commit 544730b

File tree

8 files changed

+0
-275
lines changed

8 files changed

+0
-275
lines changed

virtcontainers/api.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -659,24 +659,6 @@ func KillContainer(ctx context.Context, sandboxID, containerID string, signal sy
659659
return s.KillContainer(containerID, signal, all)
660660
}
661661

662-
// PauseSandbox is the virtcontainers pausing entry point which pauses an
663-
// already running sandbox.
664-
func PauseSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
665-
span, ctx := trace(ctx, "PauseSandbox")
666-
defer span.Finish()
667-
668-
return togglePauseSandbox(ctx, sandboxID, true)
669-
}
670-
671-
// ResumeSandbox is the virtcontainers resuming entry point which resumes
672-
// (or unpauses) and already paused sandbox.
673-
func ResumeSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
674-
span, ctx := trace(ctx, "ResumeSandbox")
675-
defer span.Finish()
676-
677-
return togglePauseSandbox(ctx, sandboxID, false)
678-
}
679-
680662
// ProcessListContainer is the virtcontainers entry point to list
681663
// processes running inside a container
682664
func ProcessListContainer(ctx context.Context, sandboxID, containerID string, options ProcessListOptions) (ProcessList, error) {

virtcontainers/api_test.go

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -354,64 +354,6 @@ func TestStopSandboxNoopAgentSuccessful(t *testing.T) {
354354
assert.NotNil(vp)
355355
}
356356

357-
func TestPauseThenResumeSandboxNoopAgentSuccessful(t *testing.T) {
358-
defer cleanUp()
359-
assert := assert.New(t)
360-
361-
config := newTestSandboxConfigNoop()
362-
363-
ctx := context.Background()
364-
365-
p, _, err := createAndStartSandbox(ctx, config)
366-
assert.NoError(err)
367-
assert.NotNil(p)
368-
369-
contID := "100"
370-
contConfig := newTestContainerConfigNoop(contID)
371-
372-
_, c, err := CreateContainer(ctx, p.ID(), contConfig)
373-
assert.NoError(err)
374-
assert.NotNil(c)
375-
376-
p, err = PauseSandbox(ctx, p.ID())
377-
assert.NoError(err)
378-
assert.NotNil(p)
379-
380-
pImpl, ok := p.(*Sandbox)
381-
assert.True(ok)
382-
383-
expectedState := types.StatePaused
384-
385-
assert.Equal(pImpl.state.State, expectedState, "unexpected paused sandbox state")
386-
387-
for i, c := range p.GetAllContainers() {
388-
cImpl, ok := c.(*Container)
389-
assert.True(ok)
390-
391-
assert.Equal(expectedState, cImpl.state.State,
392-
fmt.Sprintf("paused container %d has unexpected state", i))
393-
}
394-
395-
p, err = ResumeSandbox(ctx, p.ID())
396-
assert.NoError(err)
397-
assert.NotNil(p)
398-
399-
pImpl, ok = p.(*Sandbox)
400-
assert.True(ok)
401-
402-
expectedState = types.StateRunning
403-
404-
assert.Equal(pImpl.state.State, expectedState, "unexpected resumed sandbox state")
405-
406-
for i, c := range p.GetAllContainers() {
407-
cImpl, ok := c.(*Container)
408-
assert.True(ok)
409-
410-
assert.Equal(cImpl.state.State, expectedState,
411-
fmt.Sprintf("resumed container %d has unexpected state", i))
412-
}
413-
}
414-
415357
func TestStopSandboxKataAgentSuccessful(t *testing.T) {
416358
assert := assert.New(t)
417359
if tc.NotValid(ktu.NeedRoot()) {

virtcontainers/implementation.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,6 @@ func (impl *VCImpl) StatusSandbox(ctx context.Context, sandboxID string) (Sandbo
7777
return StatusSandbox(ctx, sandboxID)
7878
}
7979

80-
// PauseSandbox implements the VC function of the same name.
81-
func (impl *VCImpl) PauseSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
82-
return PauseSandbox(ctx, sandboxID)
83-
}
84-
85-
// ResumeSandbox implements the VC function of the same name.
86-
func (impl *VCImpl) ResumeSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
87-
return ResumeSandbox(ctx, sandboxID)
88-
}
89-
9080
// CreateContainer implements the VC function of the same name.
9181
func (impl *VCImpl) CreateContainer(ctx context.Context, sandboxID string, containerConfig ContainerConfig) (VCSandbox, VCContainer, error) {
9282
return CreateContainer(ctx, sandboxID, containerConfig)

virtcontainers/interfaces.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ type VC interface {
2727
DeleteSandbox(ctx context.Context, sandboxID string) (VCSandbox, error)
2828
FetchSandbox(ctx context.Context, sandboxID string) (VCSandbox, error)
2929
ListSandbox(ctx context.Context) ([]SandboxStatus, error)
30-
PauseSandbox(ctx context.Context, sandboxID string) (VCSandbox, error)
31-
ResumeSandbox(ctx context.Context, sandboxID string) (VCSandbox, error)
3230
RunSandbox(ctx context.Context, sandboxConfig SandboxConfig) (VCSandbox, error)
3331
StartSandbox(ctx context.Context, sandboxID string) (VCSandbox, error)
3432
StatusSandbox(ctx context.Context, sandboxID string) (SandboxStatus, error)
@@ -72,8 +70,6 @@ type VCSandbox interface {
7270

7371
Start() error
7472
Stop(force bool) error
75-
Pause() error
76-
Resume() error
7773
Release() error
7874
Monitor() (chan error, error)
7975
Delete() error

virtcontainers/pkg/vcmock/mock.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -119,24 +119,6 @@ func (m *VCMock) StatusSandbox(ctx context.Context, sandboxID string) (vc.Sandbo
119119
return vc.SandboxStatus{}, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
120120
}
121121

122-
// PauseSandbox implements the VC function of the same name.
123-
func (m *VCMock) PauseSandbox(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
124-
if m.PauseSandboxFunc != nil {
125-
return m.PauseSandboxFunc(ctx, sandboxID)
126-
}
127-
128-
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
129-
}
130-
131-
// ResumeSandbox implements the VC function of the same name.
132-
func (m *VCMock) ResumeSandbox(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
133-
if m.ResumeSandboxFunc != nil {
134-
return m.ResumeSandboxFunc(ctx, sandboxID)
135-
}
136-
137-
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
138-
}
139-
140122
// CreateContainer implements the VC function of the same name.
141123
func (m *VCMock) CreateContainer(ctx context.Context, sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error) {
142124
if m.CreateContainerFunc != nil {

virtcontainers/pkg/vcmock/mock_test.go

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -197,60 +197,6 @@ func TestVCMockListSandbox(t *testing.T) {
197197
assert.True(IsMockError(err))
198198
}
199199

200-
func TestVCMockPauseSandbox(t *testing.T) {
201-
assert := assert.New(t)
202-
203-
m := &VCMock{}
204-
assert.Nil(m.PauseSandboxFunc)
205-
206-
ctx := context.Background()
207-
_, err := m.PauseSandbox(ctx, testSandboxID)
208-
assert.Error(err)
209-
assert.True(IsMockError(err))
210-
211-
m.PauseSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
212-
return &Sandbox{}, nil
213-
}
214-
215-
sandbox, err := m.PauseSandbox(ctx, testSandboxID)
216-
assert.NoError(err)
217-
assert.Equal(sandbox, &Sandbox{})
218-
219-
// reset
220-
m.PauseSandboxFunc = nil
221-
222-
_, err = m.PauseSandbox(ctx, testSandboxID)
223-
assert.Error(err)
224-
assert.True(IsMockError(err))
225-
}
226-
227-
func TestVCMockResumeSandbox(t *testing.T) {
228-
assert := assert.New(t)
229-
230-
m := &VCMock{}
231-
assert.Nil(m.ResumeSandboxFunc)
232-
233-
ctx := context.Background()
234-
_, err := m.ResumeSandbox(ctx, testSandboxID)
235-
assert.Error(err)
236-
assert.True(IsMockError(err))
237-
238-
m.ResumeSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
239-
return &Sandbox{}, nil
240-
}
241-
242-
sandbox, err := m.ResumeSandbox(ctx, testSandboxID)
243-
assert.NoError(err)
244-
assert.Equal(sandbox, &Sandbox{})
245-
246-
// reset
247-
m.ResumeSandboxFunc = nil
248-
249-
_, err = m.ResumeSandbox(ctx, testSandboxID)
250-
assert.Error(err)
251-
assert.True(IsMockError(err))
252-
}
253-
254200
func TestVCMockRunSandbox(t *testing.T) {
255201
assert := assert.New(t)
256202

virtcontainers/pkg/vcmock/types.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ type VCMock struct {
4848
DeleteSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
4949
ListSandboxFunc func(ctx context.Context) ([]vc.SandboxStatus, error)
5050
FetchSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
51-
PauseSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
52-
ResumeSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
5351
RunSandboxFunc func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error)
5452
StartSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
5553
StatusSandboxFunc func(ctx context.Context, sandboxID string) (vc.SandboxStatus, error)

virtcontainers/sandbox.go

Lines changed: 0 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,48 +1599,6 @@ func (s *Sandbox) Stop(force bool) error {
15991599
return nil
16001600
}
16011601

1602-
// Pause pauses the sandbox
1603-
func (s *Sandbox) Pause() error {
1604-
if err := s.hypervisor.pauseSandbox(); err != nil {
1605-
return err
1606-
}
1607-
1608-
//After the sandbox is paused, it's needed to stop its monitor,
1609-
//Otherwise, its monitors will receive timeout errors if it is
1610-
//paused for a long time, thus its monitor will not tell it's a
1611-
//crash caused timeout or just a paused timeout.
1612-
if s.monitor != nil {
1613-
s.monitor.stop()
1614-
}
1615-
1616-
if err := s.pauseSetStates(); err != nil {
1617-
return err
1618-
}
1619-
1620-
if err := s.storeSandbox(); err != nil {
1621-
return err
1622-
}
1623-
1624-
return nil
1625-
}
1626-
1627-
// Resume resumes the sandbox
1628-
func (s *Sandbox) Resume() error {
1629-
if err := s.hypervisor.resumeSandbox(); err != nil {
1630-
return err
1631-
}
1632-
1633-
if err := s.resumeSetStates(); err != nil {
1634-
return err
1635-
}
1636-
1637-
if err := s.storeSandbox(); err != nil {
1638-
return err
1639-
}
1640-
1641-
return nil
1642-
}
1643-
16441602
// list lists all sandbox running on the host.
16451603
func (s *Sandbox) list() ([]Sandbox, error) {
16461604
return nil, nil
@@ -1668,26 +1626,6 @@ func (s *Sandbox) setSandboxState(state types.StateString) error {
16681626
return nil
16691627
}
16701628

1671-
func (s *Sandbox) pauseSetStates() error {
1672-
// XXX: When a sandbox is paused, all its containers are forcibly
1673-
// paused too.
1674-
if err := s.setContainersState(types.StatePaused); err != nil {
1675-
return err
1676-
}
1677-
1678-
return s.setSandboxState(types.StatePaused)
1679-
}
1680-
1681-
func (s *Sandbox) resumeSetStates() error {
1682-
// XXX: Resuming a paused sandbox puts all containers back into the
1683-
// running state.
1684-
if err := s.setContainersState(types.StateRunning); err != nil {
1685-
return err
1686-
}
1687-
1688-
return s.setSandboxState(types.StateRunning)
1689-
}
1690-
16911629
// getAndSetSandboxBlockIndex retrieves sandbox block index and increments it for
16921630
// subsequent accesses. This index is used to maintain the index at which a
16931631
// block device is assigned to a container in the sandbox.
@@ -1737,55 +1675,6 @@ func (s *Sandbox) decrementSandboxBlockIndex() error {
17371675
return nil
17381676
}
17391677

1740-
func (s *Sandbox) setContainersState(state types.StateString) error {
1741-
if state == "" {
1742-
return vcTypes.ErrNeedState
1743-
}
1744-
1745-
for _, c := range s.containers {
1746-
if err := c.setContainerState(state); err != nil {
1747-
return err
1748-
}
1749-
}
1750-
1751-
return nil
1752-
}
1753-
1754-
// togglePauseSandbox pauses a sandbox if pause is set to true, else it resumes it.
1755-
func togglePauseSandbox(ctx context.Context, sandboxID string, pause bool) (*Sandbox, error) {
1756-
span, ctx := trace(ctx, "togglePauseSandbox")
1757-
defer span.Finish()
1758-
1759-
if sandboxID == "" {
1760-
return nil, vcTypes.ErrNeedSandbox
1761-
}
1762-
1763-
lockFile, err := rwLockSandbox(ctx, sandboxID)
1764-
if err != nil {
1765-
return nil, err
1766-
}
1767-
defer unlockSandbox(ctx, sandboxID, lockFile)
1768-
1769-
// Fetch the sandbox from storage and create it.
1770-
s, err := fetchSandbox(ctx, sandboxID)
1771-
if err != nil {
1772-
return nil, err
1773-
}
1774-
defer s.releaseStatelessSandbox()
1775-
1776-
if pause {
1777-
err = s.Pause()
1778-
} else {
1779-
err = s.Resume()
1780-
}
1781-
1782-
if err != nil {
1783-
return nil, err
1784-
}
1785-
1786-
return s, nil
1787-
}
1788-
17891678
// HotplugAddDevice is used for add a device to sandbox
17901679
// Sandbox implement DeviceReceiver interface from device/api/interface.go
17911680
func (s *Sandbox) HotplugAddDevice(device api.Device, devType config.DeviceType) error {

0 commit comments

Comments
 (0)