From 186e53c5bfd44df64a98c11bc60b918f80d07c21 Mon Sep 17 00:00:00 2001 From: mowangdk Date: Tue, 8 Aug 2023 16:58:26 +0800 Subject: [PATCH] bugfix: remove grep -v grep commands in mount output --- pkg/dbfs/utils.go | 2 +- pkg/disk/utils.go | 8 ++++---- pkg/ens/nodeserver.go | 2 +- pkg/ens/utils.go | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/dbfs/utils.go b/pkg/dbfs/utils.go index 76a31952c..8d4f52820 100644 --- a/pkg/dbfs/utils.go +++ b/pkg/dbfs/utils.go @@ -316,7 +316,7 @@ func describeDbfs(fsID string) (*dbfs.GetDbfsResponse, error) { func isPodMounted(pvName string) (bool, error) { mountFlag := filepath.Join("volumes/kubernetes.io~csi", pvName, "mount") - cmd := fmt.Sprintf("mount | grep -v grep | grep fuse.dbfs_server | grep %s | wc -l", mountFlag) + cmd := fmt.Sprintf("mount | grep fuse.dbfs_server | grep %s | wc -l", mountFlag) out, err := utils.Run(cmd) if err != nil { return false, err diff --git a/pkg/disk/utils.go b/pkg/disk/utils.go index 3e48a6049..ae6e3f43e 100644 --- a/pkg/disk/utils.go +++ b/pkg/disk/utils.go @@ -192,7 +192,7 @@ func GetMetaData(resource string) string { // GetDeviceByMntPoint return the device info from given mount point func GetDeviceByMntPoint(targetPath string) string { - deviceCmd := fmt.Sprintf("mount | grep \"on %s\" | grep -v grep | awk 'NR==1 {print $1}'", targetPath) + deviceCmd := fmt.Sprintf("mount | grep \"on %s\" | awk 'NR==1 {print $1}'", targetPath) deviceCmdOut, err := run(deviceCmd) if err != nil { return "" @@ -202,13 +202,13 @@ func GetDeviceByMntPoint(targetPath string) string { // GetDeviceMountNum get the device mount number func GetDeviceMountNum(targetPath string) int { - deviceCmd := fmt.Sprintf("mount | grep %s | grep -v grep | awk '{print $1}'", targetPath) + deviceCmd := fmt.Sprintf("mount | grep %s | awk '{print $1}'", targetPath) deviceCmdOut, err := run(deviceCmd) if err != nil { return 0 } deviceCmdOut = strings.TrimSuffix(deviceCmdOut, "\n") - deviceNumCmd := fmt.Sprintf("mount | grep \"%s \" | grep -v grep | wc -l", deviceCmdOut) + deviceNumCmd := fmt.Sprintf("mount | grep \"%s \" | wc -l", deviceCmdOut) deviceNumOut, err := run(deviceNumCmd) if err != nil { return 0 @@ -1098,7 +1098,7 @@ func checkDeviceAvailable(devicePath, volumeID, targetPath string) error { // block volume if devicePath == "devtmpfs" { - findmntCmd := fmt.Sprintf("findmnt %s | grep -v grep | awk '{if(NR>1)print $2}'", targetPath) + findmntCmd := fmt.Sprintf("findmnt %s | awk '{if(NR>1)print $2}'", targetPath) output, err := utils.Run(findmntCmd) if err != nil { return status.Error(codes.Internal, err.Error()) diff --git a/pkg/ens/nodeserver.go b/pkg/ens/nodeserver.go index 4501de422..f21082f58 100644 --- a/pkg/ens/nodeserver.go +++ b/pkg/ens/nodeserver.go @@ -548,7 +548,7 @@ func (ns *nodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoReque // GetDeviceByMntPoint return the device info from given mount point func GetDeviceByMntPoint(targetPath string) string { - deviceCmd := fmt.Sprintf("mount | grep \"on %s\" | grep -v grep | awk 'NR==1 {print $1}'", targetPath) + deviceCmd := fmt.Sprintf("mount | grep \"on %s\" | awk 'NR==1 {print $1}'", targetPath) deviceCmdOut, err := utils.Run(deviceCmd) if err != nil { return "" diff --git a/pkg/ens/utils.go b/pkg/ens/utils.go index 3716df2ad..7f058b1ef 100644 --- a/pkg/ens/utils.go +++ b/pkg/ens/utils.go @@ -712,7 +712,7 @@ func checkDeviceAvailable(devicePath, volumeID, targetPath string) error { // block volume if devicePath == "devtmpfs" { - findmntCmd := fmt.Sprintf("findmnt %s | grep -v grep | awk '{if(NR>1)print $2}'", targetPath) + findmntCmd := fmt.Sprintf("findmnt %s | awk '{if(NR>1)print $2}'", targetPath) output, err := utils.Run(findmntCmd) if err != nil { return err