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

Commit 04bb5fd

Browse files
authored
Merge pull request #4 from cvmfs/unmountall_when_exiting
unmount on main defer
2 parents cf6d051 + 94dfaaa commit 04bb5fd

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

cvmfs/cvmfs.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,18 @@ func (fs *Filesystem) Unmount(ctx context.Context, mountpoint string) error {
124124
return syscall.Unmount(mountpoint, syscall.MNT_FORCE)
125125
}
126126

127-
func (fs *Filesystem) UnmountAll() {
127+
func (fs *Filesystem) UnmountAll(ctx context.Context) {
128+
log.G(ctx).Info("Unmounting all the layers")
128129
m := make([]string, 0)
129130
fs.mountedLayersLock.Lock()
130131
for mountpoint := range fs.mountedLayers {
131132
m = append(m, mountpoint)
132133
delete(fs.mountedLayers, mountpoint)
133134
}
134135
fs.mountedLayersLock.Unlock()
136+
log.G(ctx).WithField("layers", m).Info("Unmounting the layers")
135137
for _, mountpoint := range m {
138+
log.G(ctx).WithField("layer", mountpoint).Info("Unmounting the layer")
136139
if err := syscall.Unmount(mountpoint, syscall.MNT_FORCE); err != nil {
137140
log.G(context.TODO()).WithError(err).WithField("mountpoint", mountpoint).Error("Error in unmounting before to exit")
138141
}

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func main() {
7272

7373
// Configure filesystem and snapshotter
7474
fs, err := cvmfs.NewFilesystem(ctx, filepath.Join(*rootDir, "cvmfs"), config)
75+
defer fs.(*cvmfs.Filesystem).UnmountAll(ctx)
7576
if err != nil {
7677
log.G(ctx).WithError(err).Fatalf("failed to configure filesystem")
7778
}
@@ -120,13 +121,12 @@ func main() {
120121
log.G(ctx).WithError(err).Fatalf("error on serving via socket %q", *address)
121122
}
122123
}()
123-
waitForSIGINT(fs.(*cvmfs.Filesystem))
124+
waitForSIGINT()
124125
log.G(ctx).Info("Got SIGINT")
125126
}
126127

127-
func waitForSIGINT(fs *cvmfs.Filesystem) {
128+
func waitForSIGINT() {
128129
c := make(chan os.Signal, 1)
129130
signal.Notify(c, os.Interrupt)
130131
<-c
131-
fs.UnmountAll()
132132
}

0 commit comments

Comments
 (0)