Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PWX-35452: Fix mount/unmount race by using MountsInProgress to track … #2392

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions pkg/mount/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import (
"syscall"
"time"

"github.com/moby/sys/mountinfo"
"github.com/libopenstorage/openstorage/pkg/chattr"
"github.com/libopenstorage/openstorage/pkg/keylock"
"github.com/libopenstorage/openstorage/pkg/options"
"github.com/libopenstorage/openstorage/pkg/sched"
"github.com/libopenstorage/openstorage/volume"
"github.com/moby/sys/mountinfo"
"github.com/pborman/uuid"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -134,10 +134,13 @@ type PathInfo struct {
// Info per device
type Info struct {
sync.Mutex
Device string
Minor int
Device string
Minor int
// Guarded using the above lock.
Mountpoint []*PathInfo
Fs string
// Guarded using Mounter.Lock()
MountsInProgress int
}

// Mounter implements Ops and keeps track of active mounts for volume drivers.
Expand Down Expand Up @@ -323,8 +326,8 @@ func (m *Mounter) maybeRemoveDevice(device string) {
m.Lock()
defer m.Unlock()
if info, ok := m.mounts[device]; ok {
// If the device has no more mountpoints, remove it from the map
if len(info.Mountpoint) == 0 {
// If the device has no more mountpoints and no mounts in progress, remove it from the map
if len(info.Mountpoint) == 0 && info.MountsInProgress == 0 {
delete(m.mounts, device)
}
}
Expand Down Expand Up @@ -478,10 +481,18 @@ func (m *Mounter) Mount(
Fs: fs,
}
}
// This variable in Info Structure is guarded using m.Lock()
info.MountsInProgress++
m.mounts[device] = info
m.Unlock()
info.Lock()
defer info.Unlock()
defer func() {
info.Unlock()
m.Lock()
// Info is not destroyed, even when we don't hold the lock.
info.MountsInProgress--
m.Unlock()
}()

// Validate input params
// FS check is not needed if it is a bind mount
Expand Down
Loading