Skip to content

Commit

Permalink
Add Additional logging in Mount/Unmount/Load/Reload (libopenstorage#2427
Browse files Browse the repository at this point in the history
)

* PWX-36522 Add Additional logging in Mount/Unmount/Load/Reload

Signed-off-by: pnookala-px <[email protected]>

* Add Additional logging in Mount/Unmount/Load/Reload

Signed-off-by: pnookala-px <[email protected]>

---------

Signed-off-by: pnookala-px <[email protected]>
  • Loading branch information
pnookala-px authored Mar 19, 2024
1 parent 5aaf214 commit 736f732
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions pkg/mount/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ func (m *Mounter) maybeRemoveDevice(device string) {
if info, ok := m.mounts[device]; ok {
// 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 {
logrus.Infof("No more mount entries for device [%s]. Removing device from MountTable", device)
delete(m.mounts, device)
}
}
Expand All @@ -343,13 +344,15 @@ func (m *Mounter) reload(device string, newM *Info) error {

// New mountable has no mounts, delete old mounts.
if newM == nil {
logrus.Infof("Removing Entry for device [%v] from MountTable", device)
delete(m.mounts, device)
return nil
}

// Old mountable had no mounts, copy over new mounts.
oldM, ok := m.mounts[device]
if !ok {
logrus.Infof("Reload: Adding the tuple to device path[%v:%v]", device, newM.Fs)
m.mounts[device] = newM
return nil
}
Expand All @@ -365,6 +368,7 @@ func (m *Mounter) reload(device string, newM *Info) error {
}

// Purge old mounts.
logrus.Infof("Reload: Adding the device tuple {%v:%v] to mount table", device, newM.Fs)
m.mounts[device] = newM
return nil
}
Expand Down Expand Up @@ -409,6 +413,7 @@ func (m *Mounter) load(prefixes []*regexp.Regexp, fmp findMountPoint) error {
Mountpoint: make([]*PathInfo, 0),
}
m.mounts[mountSourcePath] = mount
logrus.Infof("load: Adding the device[%v:%v] to mount table", deviceSourcePath, v.FSType)
}
// Allow Load to be called multiple times.
for _, p := range mount.Mountpoint {
Expand All @@ -423,6 +428,7 @@ func (m *Mounter) load(prefixes []*regexp.Regexp, fmp findMountPoint) error {
Path: normalizeMountPath(v.Mountpoint),
}
mount.Mountpoint = append(mount.Mountpoint, pi)
logrus.Infof("load: Adding path to [%v:%v] to MountTable Entry for device [%v:%v]", v.Root, v.Mountpoint, deviceSourcePath, v.FSType)
if updatePaths {
m.paths[v.Mountpoint] = mountSourcePath
}
Expand Down Expand Up @@ -450,6 +456,7 @@ func (m *Mounter) Mount(
) error {
// device gets overwritten if opts specifies fuse mount with
// options.OptionsDeviceFuseMount.
logrus.Infof("Attempting to Mount device[%v] onto path [%s]. FsType[%s]", devPath, path, fs)
device := devPath
if value, ok := opts[options.OptionsDeviceFuseMount]; ok {
// fuse mounts show-up with this key as device.
Expand Down Expand Up @@ -483,6 +490,7 @@ func (m *Mounter) Mount(
Minor: minor,
Fs: fs,
}
logrus.Infof("Mount: Adding device[%v:%v] to mountable", device, fs)
}
// This variable in Info Structure is guarded using m.Lock()
info.MountsInProgress++
Expand All @@ -502,6 +510,7 @@ func (m *Mounter) Mount(
if !strings.HasPrefix(info.Fs, fs) && (flags&syscall.MS_BIND) != syscall.MS_BIND {
logrus.Warnf("%s Existing mountpoint has fs %q cannot change to %q",
device, info.Fs, fs)
m.printMountTable()
return ErrEinval
}

Expand Down Expand Up @@ -601,6 +610,20 @@ func (m *Mounter) cleanupBindMount(path, bindMountPath string, err error) error
return nil
}

func (m * Mounter) printMountTable() {
logrus.Infof("Found %v mounts in mounter's cache: ", len(m.mounts))
logrus.Infof("Mounter has the following mountpoints: ")
for dev, info := range m.mounts {
logrus.Infof("For Device %v: Info: %v", dev, info)
if info == nil {
continue
}
for _, path := range info.Mountpoint {
logrus.Infof("\t Mountpath: %v Rootpath: %v", path.Path, path.Root)
}
}
}

// Unmount device at mountpoint and from the matrix.
// ErrEnoent is returned if the device or mountpoint for the device is not found.
func (m *Mounter) Unmount(
Expand All @@ -613,6 +636,7 @@ func (m *Mounter) Unmount(
m.Lock()
// device gets overwritten if opts specifies fuse mount with
// options.OptionsDeviceFuseMount.
logrus.Infof("Unmount devPath[%s] from path[%s]", devPath, path)
device := devPath
path = normalizeMountPath(path)
if value, ok := opts[options.OptionsDeviceFuseMount]; ok {
Expand All @@ -623,17 +647,7 @@ func (m *Mounter) Unmount(
if !ok {
logrus.Warnf("Unable to unmount device %q path %q: %v",
devPath, path, ErrEnoent.Error())
logrus.Infof("Found %v mounts in mounter's cache: ", len(m.mounts))
logrus.Infof("Mounter has the following mountpoints: ")
for dev, info := range m.mounts {
logrus.Infof("For Device %v: Info: %v", dev, info)
if info == nil {
continue
}
for _, path := range info.Mountpoint {
logrus.Infof("\t Mountpath: %v Rootpath: %v", path.Path, path.Root)
}
}
m.printMountTable()
m.Unlock()
return ErrEnoent
}
Expand Down

0 comments on commit 736f732

Please sign in to comment.