Skip to content

Instantly share code, notes, and snippets.

@rootfs
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rootfs/5e976304b103c61f46b5 to your computer and use it in GitHub Desktop.
Save rootfs/5e976304b103c61f46b5 to your computer and use it in GitHub Desktop.
given FC wwn and lun number, find matching dev name
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