From e53e402f823a38e494862dfb4890d205f6949faa Mon Sep 17 00:00:00 2001
From: David Johnson <johnsond@flux.utah.edu>
Date: Mon, 18 Dec 2006 23:35:20 +0000
Subject: [PATCH] Bugfix for plab nodes.  This problem was tripped by Kevin. 
 What was happening was that when Kevin swapmod'd to get rid of failed nodes,
 he just took the bad ones out.  This forced a change in the vname<->vnode
 mapping, and the failed node got put in a state (RES_INIT_CLEAN) that
 vnode_setup couldn't handle for plab nodes. Basically, the problem is that
 vnode_setup was assuming that the RES_INIT_CLEAN meant that the plab vnode
 needed to be allocated -- but it was already allocated in the previous swap.

---
 tbsetup/vnode_setup.in | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/tbsetup/vnode_setup.in b/tbsetup/vnode_setup.in
index 8629b1935d..4905794f1f 100644
--- a/tbsetup/vnode_setup.in
+++ b/tbsetup/vnode_setup.in
@@ -295,6 +295,29 @@ foreach my $node (@nodes) {
 		    # this would move up into os_setup.
 		    $mode = "reboot";
 		}
+		elsif ($plab && $allocstate eq TBDB_ALLOCSTATE_RES_INIT_CLEAN()) {
+		    # This is a special case.  If we reuse one of the plab 
+		    # nodes, but use a different vname in the topo, there will
+		    # be an entry in the database and a slice will be reserved
+		    # because it's never torn down.  However, we need to 
+		    # skip plabnode alloc and go straight to vnodesetup.
+		    #
+		    # BUT, we only can do this if the sliver entry is already
+		    # in the database!
+		    # Also note that this could eventually cause problems
+		    # if there is a mistaken sliver entry in the DB.
+
+		    $res = DBQueryFatal(
+			"select slicename,node_id from plab_slice_nodes" . 
+			" where pid='$pid' and eid='$eid' " . 
+                        "   and node_id='$node'");
+		    if ($res->numrows == 1) {
+			# node exists; change mode to resetup
+			$mode = "resetup";
+			print "Doing a resetup on '$node'\n";
+		    }
+		    
+		}
 	    }
 	}
     }
@@ -395,7 +418,7 @@ while (1) {
 		$args   .= ($jailed   ? "-j " : " ");
 		$args   .= ($plab     ? "-p " : " ");
 		$args   .= "$vnode ";
-                
+		
 		$exval = TBForkCmd("$ssh -host $vnode ".
                                  "$CLIENT_BIN/vnodesetup $args",1);
             }
-- 
GitLab