splitNetPath: Add support for windows paths including volumeNames e.g ip:C:\network\path

This commit is contained in:
awwalker
2016-08-15 14:33:48 -07:00
committed by Harshavardhana
parent 0bce3d6d63
commit 7c7eb1475d
6 changed files with 155 additions and 16 deletions
+12 -7
View File
@@ -56,18 +56,21 @@ func fsHouseKeeping(storageDisk StorageAPI) error {
// Check if a network path is local to this node.
func isLocalStorage(networkPath string) bool {
if idx := strings.LastIndex(networkPath, ":"); idx != -1 {
// e.g 10.0.0.1:9000:/mnt/networkPath
netAddr, _ := splitNetPath(networkPath)
var netHost string
var err error
netHost, _, err = net.SplitHostPort(netAddr)
// e.g 10.0.0.1:/mnt/networkPath
netAddr, _, err := splitNetPath(networkPath)
if err != nil {
netHost = netAddr
errorIf(err, "Splitting into ip and path failed")
return false
}
// netAddr will only be set if this is not a local path.
if netAddr == "" {
return true
}
// Resolve host to address to check if the IP is loopback.
// If address resolution fails, assume it's a non-local host.
addrs, err := net.LookupHost(netHost)
addrs, err := net.LookupHost(netAddr)
if err != nil {
errorIf(err, "Failed to lookup host")
return false
}
for _, addr := range addrs {
@@ -77,12 +80,14 @@ func isLocalStorage(networkPath string) bool {
}
iaddrs, err := net.InterfaceAddrs()
if err != nil {
errorIf(err, "Unable to list interface addresses")
return false
}
for _, addr := range addrs {
for _, iaddr := range iaddrs {
ip, _, err := net.ParseCIDR(iaddr.String())
if err != nil {
errorIf(err, "Unable to parse CIDR")
return false
}
if ip.String() == addr {