Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
persist: replace sandbox lock with newstore.Lock
Browse files Browse the repository at this point in the history
Replace rLockSandbox and rwLockSandbox with new store lock functions.

Signed-off-by: Wei Zhang <[email protected]>
  • Loading branch information
WeiZhang555 committed Nov 27, 2019
1 parent 1874ec4 commit 4c92e3e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 84 deletions.
108 changes: 50 additions & 58 deletions virtcontainers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ func DeleteSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
return nil, vcTypes.ErrNeedSandboxID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
unlock, err := rwLockSandbox(sandboxID)
if err != nil {
return nil, err
}
defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

// Fetch the sandbox from storage and create it.
s, err := fetchSandbox(ctx, sandboxID)
Expand Down Expand Up @@ -176,11 +176,11 @@ func FetchSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
return nil, vcTypes.ErrNeedSandboxID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
unlock, err := rwLockSandbox(sandboxID)
if err != nil {
return nil, err
}
defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

// Fetch the sandbox from storage and create it.
s, err := fetchSandbox(ctx, sandboxID)
Expand Down Expand Up @@ -213,11 +213,11 @@ func StartSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
return nil, vcTypes.ErrNeedSandboxID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
unlock, err := rwLockSandbox(sandboxID)
if err != nil {
return nil, err
}
defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

// Fetch the sandbox from storage and create it.
s, err := fetchSandbox(ctx, sandboxID)
Expand Down Expand Up @@ -249,11 +249,11 @@ func StopSandbox(ctx context.Context, sandboxID string, force bool) (VCSandbox,
return nil, vcTypes.ErrNeedSandbox
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
unlock, err := rwLockSandbox(sandboxID)
if err != nil {
return nil, err
}
defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

// Fetch the sandbox from storage and create it.
s, err := fetchSandbox(ctx, sandboxID)
Expand Down Expand Up @@ -288,11 +288,11 @@ func RunSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factor
}
defer s.releaseStatelessSandbox()

lockFile, err := rwLockSandbox(ctx, s.id)
unlock, err := rwLockSandbox(s.id)
if err != nil {
return nil, err
}
defer unlockSandbox(ctx, s.id, lockFile)
defer unlock()

// Start the sandbox
err = s.Start()
Expand All @@ -308,12 +308,7 @@ func ListSandbox(ctx context.Context) ([]SandboxStatus, error) {
span, ctx := trace(ctx, "ListSandbox")
defer span.Finish()

var sbsdir string
if supportNewStore(ctx) {
sbsdir = fs.RunStoragePath()
} else {
sbsdir = store.RunStoragePath()
}
sbsdir := fs.RunStoragePath()

dir, err := os.Open(sbsdir)
if err != nil {
Expand Down Expand Up @@ -354,15 +349,14 @@ func StatusSandbox(ctx context.Context, sandboxID string) (SandboxStatus, error)
return SandboxStatus{}, vcTypes.ErrNeedSandboxID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
unlock, err := rwLockSandbox(sandboxID)
if err != nil {
return SandboxStatus{}, err
}
defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

s, err := fetchSandbox(ctx, sandboxID)
if err != nil {
unlockSandbox(ctx, sandboxID, lockFile)
return SandboxStatus{}, err
}
defer s.releaseStatelessSandbox()
Expand Down Expand Up @@ -400,11 +394,11 @@ func CreateContainer(ctx context.Context, sandboxID string, containerConfig Cont
return nil, nil, vcTypes.ErrNeedSandboxID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
unlock, err := rwLockSandbox(sandboxID)
if err != nil {
return nil, nil, err
}
defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

s, err := fetchSandbox(ctx, sandboxID)
if err != nil {
Expand Down Expand Up @@ -439,11 +433,11 @@ func DeleteContainer(ctx context.Context, sandboxID, containerID string) (VCCont
return nil, vcTypes.ErrNeedContainerID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
unlock, err := rwLockSandbox(sandboxID)
if err != nil {
return nil, err
}
defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

s, err := fetchSandbox(ctx, sandboxID)
if err != nil {
Expand All @@ -468,11 +462,11 @@ func StartContainer(ctx context.Context, sandboxID, containerID string) (VCConta
return nil, vcTypes.ErrNeedContainerID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
unlock, err := rwLockSandbox(sandboxID)
if err != nil {
return nil, err
}
defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

s, err := fetchSandbox(ctx, sandboxID)
if err != nil {
Expand All @@ -497,11 +491,11 @@ func StopContainer(ctx context.Context, sandboxID, containerID string) (VCContai
return nil, vcTypes.ErrNeedContainerID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
unlock, err := rwLockSandbox(sandboxID)
if err != nil {
return nil, err
}
defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

s, err := fetchSandbox(ctx, sandboxID)
if err != nil {
Expand All @@ -526,11 +520,11 @@ func EnterContainer(ctx context.Context, sandboxID, containerID string, cmd type
return nil, nil, nil, vcTypes.ErrNeedContainerID
}

lockFile, err := rLockSandbox(ctx, sandboxID)
unlock, err := rLockSandbox(sandboxID)
if err != nil {
return nil, nil, nil, err
}
defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

s, err := fetchSandbox(ctx, sandboxID)
if err != nil {
Expand Down Expand Up @@ -560,15 +554,14 @@ func StatusContainer(ctx context.Context, sandboxID, containerID string) (Contai
return ContainerStatus{}, vcTypes.ErrNeedContainerID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
unlock, err := rwLockSandbox(sandboxID)
if err != nil {
return ContainerStatus{}, err
}
defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

s, err := fetchSandbox(ctx, sandboxID)
if err != nil {
unlockSandbox(ctx, sandboxID, lockFile)
return ContainerStatus{}, err
}
defer s.releaseStatelessSandbox()
Expand Down Expand Up @@ -644,11 +637,11 @@ func KillContainer(ctx context.Context, sandboxID, containerID string, signal sy
return vcTypes.ErrNeedContainerID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
unlock, err := rwLockSandbox(sandboxID)
if err != nil {
return err
}
defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

s, err := fetchSandbox(ctx, sandboxID)
if err != nil {
Expand Down Expand Up @@ -691,11 +684,11 @@ func ProcessListContainer(ctx context.Context, sandboxID, containerID string, op
return nil, vcTypes.ErrNeedContainerID
}

lockFile, err := rLockSandbox(ctx, sandboxID)
unlock, err := rLockSandbox(sandboxID)
if err != nil {
return nil, err
}
defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

s, err := fetchSandbox(ctx, sandboxID)
if err != nil {
Expand All @@ -720,11 +713,11 @@ func UpdateContainer(ctx context.Context, sandboxID, containerID string, resourc
return vcTypes.ErrNeedContainerID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
unlock, err := rwLockSandbox(sandboxID)
if err != nil {
return err
}
defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

s, err := fetchSandbox(ctx, sandboxID)
if err != nil {
Expand All @@ -748,12 +741,12 @@ func StatsContainer(ctx context.Context, sandboxID, containerID string) (Contain
if containerID == "" {
return ContainerStats{}, vcTypes.ErrNeedContainerID
}
lockFile, err := rLockSandbox(ctx, sandboxID)

unlock, err := rLockSandbox(sandboxID)
if err != nil {
return ContainerStats{}, err
}

defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

s, err := fetchSandbox(ctx, sandboxID)
if err != nil {
Expand All @@ -774,12 +767,11 @@ func StatsSandbox(ctx context.Context, sandboxID string) (SandboxStats, []Contai
return SandboxStats{}, []ContainerStats{}, vcTypes.ErrNeedSandboxID
}

lockFile, err := rLockSandbox(ctx, sandboxID)
unlock, err := rLockSandbox(sandboxID)
if err != nil {
return SandboxStats{}, []ContainerStats{}, err
}

defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

s, err := fetchSandbox(ctx, sandboxID)
if err != nil {
Expand Down Expand Up @@ -813,11 +805,11 @@ func togglePauseContainer(ctx context.Context, sandboxID, containerID string, pa
return vcTypes.ErrNeedContainerID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
unlock, err := rwLockSandbox(sandboxID)
if err != nil {
return err
}
defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

s, err := fetchSandbox(ctx, sandboxID)
if err != nil {
Expand Down Expand Up @@ -857,11 +849,11 @@ func AddDevice(ctx context.Context, sandboxID string, info deviceConfig.DeviceIn
return nil, vcTypes.ErrNeedSandboxID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
unlock, err := rwLockSandbox(sandboxID)
if err != nil {
return nil, err
}
defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

s, err := fetchSandbox(ctx, sandboxID)
if err != nil {
Expand All @@ -877,11 +869,11 @@ func toggleInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interfa
return nil, vcTypes.ErrNeedSandboxID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
unlock, err := rwLockSandbox(sandboxID)
if err != nil {
return nil, err
}
defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

s, err := fetchSandbox(ctx, sandboxID)
if err != nil {
Expand Down Expand Up @@ -921,11 +913,11 @@ func ListInterfaces(ctx context.Context, sandboxID string) ([]*vcTypes.Interface
return nil, vcTypes.ErrNeedSandboxID
}

lockFile, err := rLockSandbox(ctx, sandboxID)
unlock, err := rLockSandbox(sandboxID)
if err != nil {
return nil, err
}
defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

s, err := fetchSandbox(ctx, sandboxID)
if err != nil {
Expand All @@ -945,11 +937,11 @@ func UpdateRoutes(ctx context.Context, sandboxID string, routes []*vcTypes.Route
return nil, vcTypes.ErrNeedSandboxID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
unlock, err := rwLockSandbox(sandboxID)
if err != nil {
return nil, err
}
defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

s, err := fetchSandbox(ctx, sandboxID)
if err != nil {
Expand All @@ -969,11 +961,11 @@ func ListRoutes(ctx context.Context, sandboxID string) ([]*vcTypes.Route, error)
return nil, vcTypes.ErrNeedSandboxID
}

lockFile, err := rLockSandbox(ctx, sandboxID)
unlock, err := rLockSandbox(sandboxID)
if err != nil {
return nil, err
}
defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

s, err := fetchSandbox(ctx, sandboxID)
if err != nil {
Expand All @@ -999,11 +991,11 @@ func CleanupContainer(ctx context.Context, sandboxID, containerID string, force
return vcTypes.ErrNeedContainerID
}

lockFile, err := rwLockSandbox(ctx, sandboxID)
unlock, err := rwLockSandbox(sandboxID)
if err != nil {
return err
}
defer unlockSandbox(ctx, sandboxID, lockFile)
defer unlock()

s, err := fetchSandbox(ctx, sandboxID)
if err != nil {
Expand Down
Loading

0 comments on commit 4c92e3e

Please sign in to comment.