Index: /branches/eam_branches/neb-host-20250516/bin/neb-host
===================================================================
--- /branches/eam_branches/neb-host-20250516/bin/neb-host	(revision 42864)
+++ /branches/eam_branches/neb-host-20250516/bin/neb-host	(revision 42865)
@@ -16,7 +16,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($host, $state, $note,
-    $db, $dbhost, $dbpass, $dbuser,
-    $allocate, $available, $debug,$volume);
+my ($host, $state, $note, $db, $dbhost, $dbpass, $dbuser, $debug, $volume);
 
 # $db     = $ENV{'NEB_DB'} unless $db;
@@ -25,28 +23,19 @@
 # $dbpass = $ENV{'NEB_PASS'} unless $dbpass;
 
-# my $conffile = "/data/ippc64.1/ippitc/ippconfig/nebulous.config";
 # my $conffile = "/home/panstarrs/ipp/ippconfig/nebulous.config";
 my $conffile = "/home/panstarrs/ippps1/ippconfig/nebulous.config";
 
 if (-e $conffile) {
-#    printf STDERR "found config\n";
+    # printf STDERR "found config\n";
     open(IN,$conffile);
     while(<IN>) {
 	chomp;
-	if ($_ =~ /NEB_DB\s+/) {
-	    $db = (split /\s+/,$_)[2];
-	}
-	elsif ($_ =~ /NEB_DBHOST/) {
-	    $dbhost = (split /\s+/,$_)[2];
-	}
-	elsif ($_ =~ /NEB_USER/) {
-	    $dbuser = (split /\s+/,$_)[2];
-	}
-	elsif ($_ =~ /NEB_PASS/) {
-	    $dbpass = (split /\s+/,$_)[2];
-	}
+	if ($_ =~ /NEB_DB\s+/)  { $db     = (split /\s+/,$_)[2]; next; }
+	if ($_ =~ /NEB_DBHOST/) { $dbhost = (split /\s+/,$_)[2]; next; }
+	if ($_ =~ /NEB_USER/)   { $dbuser = (split /\s+/,$_)[2]; next; }
+	if ($_ =~ /NEB_PASS/)   { $dbpass = (split /\s+/,$_)[2]; next; }
     }
     close(IN);
-#    print STDERR  "$db $dbhost $dbuser $dbpass\n";
+    # print STDERR  "$db $dbhost $dbuser $dbpass\n";
 }
 
@@ -60,8 +49,9 @@
     'dbpass=s'       => \$dbpass,
     'volume'         => \$volume,
-    
     ) || pod2usage( 2 );
 
-if (($#ARGV == 1)&&(!defined($host))&&(!defined($state))) {
+# if --host and --state are not supplied, look for positional arguments
+# XXX this is wrong, it should say $#ARGV == 3 -- but it seems to work?
+if (($#ARGV == 1) && (!defined($host)) && (!defined($state))) {
     $host = shift(@ARGV);
     $state = shift(@ARGV);
@@ -83,54 +73,55 @@
     );
 
-if ((defined($host))&&(defined($state))) {
-    if ($state eq 'up') {
-	$allocate = 1;
-	$available = 1;
-    }
-    elsif ($state eq 'down') {
-	$allocate = 0;
-	$available = 0;
-    }
-    elsif ($state eq 'repair') {
-	$allocate = 0;
-	$available = 1;
-    }
-    else {
-	die "Unknown state '$state'";
-    }
+if (defined($host) && defined($state)) {
+
+    if (($state ne 'up') && ($state ne 'down') && ($state ne 'repair')) { die "Unknown state '$state'"; }
     
-    my %constraint;
+    # for 'up', we want to exclude set volumes with xattr = 3, and possible issue an equivalent of 'repair' for xattr = 3
+    # for 'up' and 'repair', we should exclude volumes with xattr = 5
+    # for 'down', all volumes are ok
+    
+    # up:
+    # UPDATE volume SET (allocate = 1, available = 1, note = '$note') WHERE (name = '$host') AND (xattr != 3) AND (xattr != 5)
+    # UPDATE volume SET (allocate = 0, available = 1, note = '$note') WHERE (name = '$host') AND (xattr = 3)
+
+    # repair:
+    # UPDATE volume SET (allocate = 0, available = 1, note = '$note') WHERE (name = '$host') AND (xattr != 5)
+
+    # down:
+    # UPDATE volume SET (allocate = 0, available = 0, note = '$note') WHERE (name = '$host')
+
+    # $volume is a boolean which means 'use' the supplied host as the 'name' field
+    my $hostWhere;
     if (defined($volume)) {
-	$constraint{'v.name'} = $host;
-    }
-    else {
-	$constraint{'v.host'} = $host;
-    }
-    my %set;
-    $set{'v.allocate'} = $allocate if defined $allocate;
-    $set{'v.available'} = $available if defined $available;
-    $set{'v.note'} = $note if defined $note;
-
-    eval {
-	my ($q, @bind) = sql_interp("UPDATE volume AS v SET", \%set, "WHERE", \%constraint);
-	warn "$q\n" if $debug;
-	my $query = $dbh->prepare($q);
-	$query->execute(@bind);
-	$dbh->commit;
-    };
-    if ($@) {
-	$dbh->rollback;
-	die $@;
-    }
-    eval {
-	my ($q, @bind) = sql_interp("UPDATE mountedvol AS v SET", \%set, "WHERE", \%constraint);
-	warn "$q\n" if $debug;
-	my $query = $dbh->prepare($q);
-	$query->execute(@bind);
-	$dbh->commit;
-    };
-    if ($@) {
-	$dbh->rollback;
-	die $@;
+	$hostWhere = "(name = '$host')";
+    } else {
+	$hostWhere = "(host = '$host')";
+    }
+
+    my ($selections, $constraint);
+
+    if ($state eq 'up')     { 
+	$selections = "allocate = 1, available = 1";
+	$constraint = "(name = '$host') AND (xattr != 3) AND (xattr != 5)";
+    }
+
+    if ($state eq 'repair')     { 
+	$selections = "allocate = 0, available = 1";
+	$constraint = "(name = '$host') AND (xattr != 5)";
+    }
+
+    if ($state eq 'down')     { 
+	$selections = "allocate = 0, available = 0";
+	$constraint = "(name = '$host')";
+    }
+
+    &modify_hosts ($selections, $constraint, $note);
+
+    ## for 'up', make a second call to set hosts with (xattr = 3) to 'repair':
+    if ($state eq 'up')     { 
+	$selections = "allocate = 0, available = 1";
+	$constraint = "(name = '$host') AND (xattr = 3)";
+
+	&modify_hosts ($selections, $constraint, $note);
     }
 }
@@ -152,9 +143,33 @@
 	$$row{ 'note' } = '-';
     }
-
     printf($format, @$row{@columns});
 }
 
+sub modify_hosts {
+
+    my $selections = $_[0];
+    my $constraint = $_[1];
+
+    my $note = $_[2];
+
+    if (defined $note) { $selections = $selections . ", note = '$note'"; }
+
+    {
+	my $sqlLine = "UPDATE volume SET ($selections) WHERE $constraint";
+	my $query = $dbh->prepare($sqlLine);
+	$query->execute() or die "error from Nebulous database\n";
+    }
+    
+    { 
+	my $sqlLine = "UPDATE mountedvol SET ($selections) WHERE $constraint";
+	my $query = $dbh->prepare($sqlLine);
+	$query->execute() or die "error from Nebulous database\n";
+    }
+}
+
+
 __END__
+
+
 
 =pod
