Skip to content

Commit

Permalink
Merge pull request #821 from mowangdk/bugfix/remove_grep_mountpoints
Browse files Browse the repository at this point in the history
bugfix: remove grep -v grep commands in mount output
  • Loading branch information
mowangdk committed Aug 8, 2023
2 parents 6e6002a + 186e53c commit e7e52e9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/dbfs/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/disk/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,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 ""
Expand All @@ -201,13 +201,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
Expand Down Expand Up @@ -1097,7 +1097,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())
Expand Down
2 changes: 1 addition & 1 deletion pkg/ens/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
2 changes: 1 addition & 1 deletion pkg/ens/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e7e52e9

Please sign in to comment.