From 2777aabd2efc988bee068cff4bd10c4b96fd5b66 Mon Sep 17 00:00:00 2001 From: Akshay Saini <109056238+AkshaySainiDell@users.noreply.github.com> Date: Wed, 23 Aug 2023 13:14:58 +0530 Subject: [PATCH 1/4] Fix index out of range error for lsblk mountpoint --- gofsutil_mount_linux.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gofsutil_mount_linux.go b/gofsutil_mount_linux.go index c30ae47..3a9e954 100644 --- a/gofsutil_mount_linux.go +++ b/gofsutil_mount_linux.go @@ -459,12 +459,18 @@ func (fs *FS) getMountInfoFromDevice( deviceTypeRegx := regexp.MustCompile(`TYPE=\"mpath"`) deviceNameRegx := regexp.MustCompile(`NAME=\"\S+\"`) mountPoint := mountRegx.FindString(output) + if(len(mountPoint) == 0){ + mountsRegx := regexp.MustCompile(`MOUNTPOINTS=\"\S+\"`) + mountPoint = mountsRegx.FindString(output) + } devices := sdDeviceRegx.FindAllString(output, 99999) nvmeDevices := nvmeDeviceRegx.FindAllString(output, 99999) mpath := mpathDeviceRegx.FindString(output) ppath := ppathDeviceRegx.FindString(output) mountInfo := new(DeviceMountInfo) - mountInfo.MountPoint = strings.Split(mountPoint, "\"")[1] + if(len(mountPoint) == 0){ + mountInfo.MountPoint = strings.Split(mountPoint, "\"")[1] + } for _, device := range devices { mountInfo.DeviceNames = append(mountInfo.DeviceNames, strings.Split(device, "\"")[1]) } From 5d91385366c79569393b37159ffa51ad753220df Mon Sep 17 00:00:00 2001 From: Akshay Saini <109056238+AkshaySainiDell@users.noreply.github.com> Date: Wed, 23 Aug 2023 17:36:10 +0530 Subject: [PATCH 2/4] Fix condition check --- gofsutil_mount_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gofsutil_mount_linux.go b/gofsutil_mount_linux.go index 3a9e954..863847d 100644 --- a/gofsutil_mount_linux.go +++ b/gofsutil_mount_linux.go @@ -468,7 +468,7 @@ func (fs *FS) getMountInfoFromDevice( mpath := mpathDeviceRegx.FindString(output) ppath := ppathDeviceRegx.FindString(output) mountInfo := new(DeviceMountInfo) - if(len(mountPoint) == 0){ + if(len(mountPoint) != 0){ mountInfo.MountPoint = strings.Split(mountPoint, "\"")[1] } for _, device := range devices { From e8df293f6847e9e1f03814ed67618178290c2fce Mon Sep 17 00:00:00 2001 From: Akshay Saini <109056238+AkshaySainiDell@users.noreply.github.com> Date: Thu, 24 Aug 2023 15:53:05 +0530 Subject: [PATCH 3/4] Fix MOUNTPOINT not present in lsblk output --- gofsutil_mount_linux.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/gofsutil_mount_linux.go b/gofsutil_mount_linux.go index 863847d..0ea428d 100644 --- a/gofsutil_mount_linux.go +++ b/gofsutil_mount_linux.go @@ -430,7 +430,7 @@ func (fs *FS) getMountInfoFromDevice( log.Debugf("multipath exec command output is : %+v", output) if output != "" { if lsblkNew { - cmd = "lsblk -Px MODE | awk '/" + devID + "/{if (a && a !~ /" + devID + "/) print a; print} {a=$0}'" + cmd = "lsblk --pairs --sort MODE --output NAME,MAJ:MIN,RM,SIZE,RO,TYPE,MOUNTPOINT | awk '/" + devID + "/{if (a && a !~ /" + devID + "/) print a; print} {a=$0}'" } else { cmd = "lsblk -P | awk '/" + devID + "/{if (a && a !~ /" + devID + "/) print a; print} {a=$0}'" } @@ -459,18 +459,12 @@ func (fs *FS) getMountInfoFromDevice( deviceTypeRegx := regexp.MustCompile(`TYPE=\"mpath"`) deviceNameRegx := regexp.MustCompile(`NAME=\"\S+\"`) mountPoint := mountRegx.FindString(output) - if(len(mountPoint) == 0){ - mountsRegx := regexp.MustCompile(`MOUNTPOINTS=\"\S+\"`) - mountPoint = mountsRegx.FindString(output) - } devices := sdDeviceRegx.FindAllString(output, 99999) nvmeDevices := nvmeDeviceRegx.FindAllString(output, 99999) mpath := mpathDeviceRegx.FindString(output) ppath := ppathDeviceRegx.FindString(output) mountInfo := new(DeviceMountInfo) - if(len(mountPoint) != 0){ - mountInfo.MountPoint = strings.Split(mountPoint, "\"")[1] - } + mountInfo.MountPoint = strings.Split(mountPoint, "\"")[1] for _, device := range devices { mountInfo.DeviceNames = append(mountInfo.DeviceNames, strings.Split(device, "\"")[1]) } From f415b11a8bb64fd20aff75e6571cdff79022a189 Mon Sep 17 00:00:00 2001 From: Akshay Saini <109056238+AkshaySainiDell@users.noreply.github.com> Date: Fri, 25 Aug 2023 09:22:53 +0530 Subject: [PATCH 4/4] Fix lsblk output in getMountInfoFromDevice --- gofsutil_mount_linux.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gofsutil_mount_linux.go b/gofsutil_mount_linux.go index 0ea428d..9c6f9fe 100644 --- a/gofsutil_mount_linux.go +++ b/gofsutil_mount_linux.go @@ -406,7 +406,7 @@ func (fs *FS) getMountInfoFromDevice( } //check if devID has powerpath devices /* #nosec G204 */ - checkCmd := "lsblk -P | awk '/emcpower.+" + devID + "/ {print $0}'" + checkCmd := "lsblk --pairs --output NAME,MAJ:MIN,RM,SIZE,RO,TYPE,MOUNTPOINT | awk '/emcpower.+" + devID + "/ {print $0}'" log.Debugf("ppath checkcommand values is %s", checkCmd) /* #nosec G204 */ buf, err := exec.Command("bash", "-c", checkCmd).Output() @@ -418,7 +418,7 @@ func (fs *FS) getMountInfoFromDevice( // output is nil, powerpath device not found, continuing for multipath or single device log.Info("powerpath command output is nil, continuing for multipath or single device") /* #nosec G204 */ - checkCmd = "lsblk -P | awk '/mpath.+" + devID + "/ {print $0}'" + checkCmd = "lsblk --pairs --output NAME,MAJ:MIN,RM,SIZE,RO,TYPE,MOUNTPOINT | awk '/mpath.+" + devID + "/ {print $0}'" log.Debugf("mpath checkcommand values is %s", checkCmd) /* #nosec G204 */ @@ -432,12 +432,12 @@ func (fs *FS) getMountInfoFromDevice( if lsblkNew { cmd = "lsblk --pairs --sort MODE --output NAME,MAJ:MIN,RM,SIZE,RO,TYPE,MOUNTPOINT | awk '/" + devID + "/{if (a && a !~ /" + devID + "/) print a; print} {a=$0}'" } else { - cmd = "lsblk -P | awk '/" + devID + "/{if (a && a !~ /" + devID + "/) print a; print} {a=$0}'" + cmd = "lsblk --pairs --output NAME,MAJ:MIN,RM,SIZE,RO,TYPE,MOUNTPOINT | awk '/" + devID + "/{if (a && a !~ /" + devID + "/) print a; print} {a=$0}'" } } else { // multipath device not found, continue as single device /* #nosec G204 */ - cmd = "lsblk -P | awk '/" + devID + "/ {print $0}'" + cmd = "lsblk --pairs --output NAME,MAJ:MIN,RM,SIZE,RO,TYPE,MOUNTPOINT | awk '/" + devID + "/ {print $0}'" } log.Debugf("command value is %s", cmd) /* #nosec G204 */