Skip to content
This repository was archived by the owner on Mar 22, 2024. It is now read-only.

Commit 298161c

Browse files
committed
upgrade to newer version of the filesystem interface and implement the unmount call
1 parent 3970f67 commit 298161c

File tree

3 files changed

+722
-6
lines changed

3 files changed

+722
-6
lines changed

cvmfs/cvmfs.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"path/filepath"
88
"strings"
9+
"sync"
910
"syscall"
1011

1112
"github.com/containerd/containerd/log"
@@ -22,10 +23,10 @@ const (
2223
targetImageLayersLabel = "containerd.io/snapshot/cri.image-layers"
2324
)
2425

25-
2626
type filesystem struct {
27-
repository string
28-
mountedLayers map[string]string
27+
repository string
28+
mountedLayers map[string]string
29+
mountedLayersLock sync.Mutex
2930
}
3031

3132
type Config struct {
@@ -63,13 +64,17 @@ func (fs *filesystem) Mount(ctx context.Context, mountpoint string, labels map[s
6364
log.G(ctx).WithError(err).WithField("layer digest", digest).WithField("mountpoint", mountpoint).Debug("cvmfs: Error in bind mounting the layer.")
6465
return err
6566
}
67+
fs.mountedLayersLock.Lock()
68+
defer fs.mountedLayersLock.Unlock()
6669
fs.mountedLayers[mountpoint] = path
6770
return nil
6871
}
6972

70-
func (fs *filesystem) Check(ctx context.Context, mountpoint string) error {
73+
func (fs *filesystem) Check(ctx context.Context, mountpoint string, labels map[string]string) error {
7174
log.G(ctx).WithField("snapshotter", "cvmfs").WithField("mountpoint", mountpoint).Warning("checking layer")
75+
fs.mountedLayersLock.Lock()
7276
path, ok := fs.mountedLayers[mountpoint]
77+
fs.mountedLayersLock.Unlock()
7378
if !ok {
7479
err := fmt.Errorf("Mountpoint: %s was not mounted", mountpoint)
7580
log.G(ctx).WithError(err).WithField("mountpoint", mountpoint).Error("cvmfs: the requested mountpoint does not seem to be mounted")
@@ -92,3 +97,18 @@ func (fs *filesystem) Check(ctx context.Context, mountpoint string) error {
9297
}
9398
return statErr
9499
}
100+
101+
func (fs *filesystem) Unmount(ctx context.Context, mountpoint string) error {
102+
// maybe we lost track of something somehow, does not hurt to try to unmount the mountpoint anyway
103+
104+
fs.mountedLayersLock.Lock()
105+
_, ok := fs.mountedLayers[mountpoint]
106+
delete(fs.mountedLayers, mountpoint)
107+
fs.mountedLayersLock.Unlock()
108+
109+
if !ok {
110+
err := fmt.Errorf("Trying to unmount mountpoint that does not seems mounted: %s", mountpoint)
111+
log.G(ctx).WithError(err).Error("Layer does not seems mounted.")
112+
}
113+
return syscall.Unmount(mountpoint, syscall.MNT_FORCE)
114+
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ go 1.14
44

55
require (
66
github.com/BurntSushi/toml v0.3.1
7-
github.com/containerd/containerd v1.3.1-0.20200507183255-990076b731ec
8-
github.com/containerd/stargz-snapshotter v0.0.0-20200609024515-95c85650d51d
7+
github.com/containerd/containerd v1.4.0
8+
github.com/containerd/stargz-snapshotter v0.0.0-20201007053350-9827a0b90aaa
99
github.com/sirupsen/logrus v1.6.0
1010
google.golang.org/grpc v1.29.1
1111
)

0 commit comments

Comments
 (0)