namespace: Change glob to list everything at a mount point, i.e., the mount point itself
and root of any server below it.   Therefore, for something like

mountMT("/s1/a", "/s2/b")
mountMT("/s2/b", "/s3/c")
mount("/s3/c", "/s4")

glob of /s1/a will show 3 entries for /s1/a

/s1/a -> /s2/b
/s1/a -> /s3/c
/s1/a -> /s4

Change-Id: I37775fb39fe80c46de4bc70e79a61208d42d4cf8
diff --git a/runtimes/google/naming/namespace/all_test.go b/runtimes/google/naming/namespace/all_test.go
index bbac581..5d707c5 100644
--- a/runtimes/google/naming/namespace/all_test.go
+++ b/runtimes/google/naming/namespace/all_test.go
@@ -1,10 +1,8 @@
 package namespace_test
 
 import (
-	"reflect"
 	"runtime"
 	"runtime/debug"
-	"sort"
 	"sync"
 	"testing"
 	"time"
@@ -29,13 +27,24 @@
 	t.Fatal(string(debug.Stack()))
 }
 
-func compare(t *testing.T, caller, name string, got, want []string) {
-	if len(got) != len(want) {
-		boom(t, "%s: %q returned wrong # servers: got %v, want %v, servers: got %v, want %v", caller, name, len(got), len(want), got, want)
+// N squared but who cares, this is a little test.
+// Ignores dups.
+func contains(container, contained []string) bool {
+L:
+	for _, d := range contained {
+		for _, r := range container {
+			if r == d {
+				continue L
+			}
+		}
+		return false
 	}
-	sort.Strings(got)
-	sort.Strings(want)
-	if !reflect.DeepEqual(got, want) {
+	return true
+}
+
+func compare(t *testing.T, caller, name string, got, want []string) {
+	// Compare ignoring dups.
+	if !contains(got, want) || !contains(want, got) {
 		boom(t, "%s: %q: got %v, want %v", caller, name, got, want)
 	}
 }
@@ -421,9 +430,7 @@
 		expected []string
 	}{
 		{"*", tln},
-		// TODO(cnicolaou): the glob that doesn't match a name should fail.
-		//
-		{"x", []string{"x"}},
+		{"x", []string{}},
 		{"m*", []string{"mt1", "mt2", "mt3", "mt4", "mt5"}},
 		{"mt[2,3]", []string{"mt2", "mt3"}},
 		{"*z", []string{"baz"}},
diff --git a/runtimes/google/naming/namespace/glob.go b/runtimes/google/naming/namespace/glob.go
index b251c63..4b3d296 100644
--- a/runtimes/google/naming/namespace/glob.go
+++ b/runtimes/google/naming/namespace/glob.go
@@ -26,11 +26,9 @@
 //   pelems    the pattern to match relative to the mounted subtree.
 //   l         the list to add results to.
 //   recursive true to continue below the matched pattern
-// We return a bool foundRoot which indicates whether the empty name "" was found on a target server.
-func (ns *namespace) globAtServer(ctx context.T, qe *queuedEntry, pattern *glob.Glob, l *list.List) (bool, error) {
+func (ns *namespace) globAtServer(ctx context.T, qe *queuedEntry, pattern *glob.Glob, l *list.List) error {
 	server := qe.me
 	pstr := pattern.String()
-	foundRoot := false
 	vlog.VI(2).Infof("globAtServer(%v, %v)", *server, pstr)
 
 	var lastErr error
@@ -43,68 +41,60 @@
 		if pattern.Finished() {
 			_, n := naming.SplitAddressName(s.Server)
 			if strings.HasPrefix(n, "//") {
-				return false, nil
+				return nil
 			}
 		}
 
-		mtServers, err := ns.ResolveToMountTable(ctx, s.Server)
+		// Don't further resolve s.Server.
+		s := naming.MakeTerminal(s.Server)
+		callCtx, _ := ctx.WithTimeout(callTimeout)
+		client := ns.rt.Client()
+		call, err := client.StartCall(callCtx, s, "Glob", []interface{}{pstr})
 		if err != nil {
 			lastErr = err
-			continue
+			continue // try another instance
 		}
 
-		for _, s := range mtServers {
-			callCtx, _ := ctx.WithTimeout(callTimeout)
-			client := ns.rt.Client()
-			call, err := client.StartCall(callCtx, s, "Glob", []interface{}{pstr})
+		// At this point we're commited to a server since it answered tha call.
+		for {
+			var e mountEntry
+			err := call.Recv(&e)
+			if err == io.EOF {
+				return nil
+			}
 			if err != nil {
-				lastErr = err
-				continue // try another instance
-			}
-			// At this point we have a server that can handle the RPC.
-			for {
-				var e mountEntry
-				err := call.Recv(&e)
-				if err == io.EOF {
-					return foundRoot, nil
-				}
-				if err != nil {
-					return foundRoot, err
-				}
-				if e.Name == "" {
-					foundRoot = true
-				}
-
-				// Prefix the results with the path of the mount point.
-				e.Name = naming.Join(server.Name, e.Name)
-
-				// Convert to the ever so slightly different name.MountTable version of a MountEntry
-				// and add it to the list.
-				x := &queuedEntry{
-					me: &naming.MountEntry{
-						Name:    e.Name,
-						Servers: convertServers(e.Servers),
-					},
-					depth: qe.depth,
-				}
-				// x.depth is the number of severs we've walked through since we've gone
-				// recursive (i.e. with pattern length of 0).
-				if pattern.Len() == 0 {
-					if x.depth++; x.depth > ns.maxRecursiveGlobDepth {
-						continue
-					}
-				}
-				l.PushBack(x)
+				return err
 			}
 
-			if err := call.Finish(); err != nil {
-				return foundRoot, err
+			// Prefix the results with the path of the mount point.
+			e.Name = naming.Join(server.Name, e.Name)
+
+			// Convert to the ever so slightly different name.MountTable version of a MountEntry
+			// and add it to the list.
+			x := &queuedEntry{
+				me: &naming.MountEntry{
+					Name:    e.Name,
+					Servers: convertServers(e.Servers),
+				},
+				depth: qe.depth,
 			}
-			return foundRoot, nil
+			// x.depth is the number of severs we've walked through since we've gone
+			// recursive (i.e. with pattern length of 0).
+			if pattern.Len() == 0 {
+				if x.depth++; x.depth > ns.maxRecursiveGlobDepth {
+					continue
+				}
+			}
+			l.PushBack(x)
 		}
+
+		if err := call.Finish(); err != nil {
+			return err
+		}
+		return nil
 	}
 
-	return foundRoot, lastErr
+	return lastErr
 }
 
 // Glob implements naming.MountTable.Glob.
@@ -118,9 +108,10 @@
 
 	// Add constant components of pattern to the servers' addresses and
 	// to the prefix.
-	var prefixElements []string
-	prefixElements, g = g.SplitFixedPrefix()
-	prefix := strings.Join(prefixElements, "/")
+	//var prefixElements []string
+	//prefixElements, g = g.SplitFixedPrefix()
+	//prefix := strings.Join(prefixElements, "/")
+	prefix := ""
 	if len(root) != 0 {
 		prefix = naming.JoinAddressName(root, prefix)
 	}
@@ -171,6 +162,7 @@
 	// tables to be traversed to the list 'l'.
 	l := list.New()
 	l.PushBack(&queuedEntry{me: &naming.MountEntry{Name: "", Servers: convertStringsToServers(servers)}})
+	atRoot := true
 
 	// Perform a breadth first search of the name graph.
 	for le := l.Front(); le != nil; le = l.Front() {
@@ -181,7 +173,7 @@
 		suffix := pattern.Split(depth(e.me.Name))
 
 		// Perform a glob at the server.
-		foundRoot, err := ns.globAtServer(ctx, e, suffix, l)
+		err := ns.globAtServer(ctx, e, suffix, l)
 
 		// We want to output this entry if:
 		// 1. There was a real error, we return whatever name gave us the error.
@@ -194,10 +186,11 @@
 
 		// 2. The current name fullfills the pattern and further servers did not respond
 		//    with "".  That is, we want to prefer foo/ over foo.
-		if suffix.Len() == 0 && !foundRoot {
+		if suffix.Len() == 0 && !atRoot {
 			x := *e.me
 			x.Name = naming.Join(prefix, x.Name)
 			reply <- x
 		}
+		atRoot = false
 	}
 }
diff --git a/tools/naming/simulator/ambiguity.scr b/tools/naming/simulator/ambiguity.scr
index 1df3410..f20b97b 100644
--- a/tools/naming/simulator/ambiguity.scr
+++ b/tools/naming/simulator/ambiguity.scr
@@ -2,7 +2,7 @@
 #
 # mountMT("/s1/a", "/s2/b")
 # mountMT("/s2/b", "/s3/c")
-# mount("/s3/c", "/s4/d")
+# mount("/s3/c", "/s4")
 #
 # Bogdan points out that: 'we will actually have d == "" in the echo example
 # below (since Serve only mounts endpoints without suffixes)'
@@ -17,8 +17,7 @@
 #
 # "s1/a", ["/s2/b"(mountpoint)]
 # "s1/a", ["/s3/c"(mountpoint)]
-# "s1/a", ["/s4/d"(mountpoint)]
-# "s1/a", []
+# "s1/a", ["/s4//"(mountpoint)]
 
 root
 eval $_
@@ -33,16 +32,26 @@
 set s3=$MT_NAME
 
 mount $s1/a $s2/b 1h
+wait $_
 
 mount $s2/b $s3/c 1h
+wait $_
 
 echoServer "Echo" $s3/c
 set es_h=$_
 
+# Returns the root and three mounts at s1/a.
 ls $s1/...
-wait $_
+set l=$_
+eval $l
+assert $RN 4
+wait $l
 
+# Returns three mounts at s1/a.
 ls $s1/a
-wait $_
+set l=$_
+eval $l
+assert $RN 3
+wait $l
 
 stop $es_h
diff --git a/tools/naming/simulator/mt_complex.scr b/tools/naming/simulator/mt_complex.scr
index 3a23946..6fb3532 100644
--- a/tools/naming/simulator/mt_complex.scr
+++ b/tools/naming/simulator/mt_complex.scr
@@ -40,11 +40,11 @@
 assert $RN 3
 wait $l
 
-# ls /... does not.. - it just finds itself... seems a little weird.
+# ls /... is meaningless, finds nothing
 ls /...
 set l=$_
 eval $l
-assert $RN 1
+assert $RN 0
 wait $l
 
 # a rooted glob finds all of the mount points, include an entry for the root
diff --git a/tools/naming/simulator/mt_simple.scr b/tools/naming/simulator/mt_simple.scr
index c09e1eb..1dfb805 100644
--- a/tools/naming/simulator/mt_simple.scr
+++ b/tools/naming/simulator/mt_simple.scr
@@ -31,7 +31,7 @@
 ls $root/...
 set l=$_
 eval $l
-assert $RN 5
+assert $RN 7
 
 ls -l $root/...
 wait $_