Last active
August 29, 2015 14:27
-
-
Save rootfs/5e976304b103c61f46b5 to your computer and use it in GitHub Desktop.
given FC wwn and lun number, find matching dev name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"os" | |
"path/filepath" | |
"strings" | |
) | |
func main() { | |
if len(os.Args) < 3 { | |
fmt.Fprintf(os.Stdout, "usage: %s wwn lun_number\n", os.Args[0]) | |
os.Exit(1) | |
} | |
wwn := os.Args[1] | |
lun := os.Args[2] | |
fc_path := "-fc-0x" + wwn + "-lun-" + lun | |
dev_path := "/dev/disk/by-path/" | |
if dirs, err := ioutil.ReadDir(dev_path); err == nil { | |
for _, f := range dirs { | |
name := f.Name() | |
if strings.Contains(name, fc_path) { | |
fmt.Fprintf(os.Stdout, "found %s\n", name) | |
if disk, err1 := filepath.EvalSymlinks(dev_path + name); err1 == nil { | |
fmt.Fprintf(os.Stderr, "found %s, disk is %s\n", name, disk) | |
} | |
return | |
} | |
} | |
fmt.Fprintf(os.Stderr, "cannot find %s\n", os.Args[1]) | |
} else { | |
fmt.Fprintf(os.Stderr, "failed to open: %v\n", err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment