Index: /branches/eam_branches/neb-host-20250516/bin/neb-host
===================================================================
--- /branches/eam_branches/neb-host-20250516/bin/neb-host	(revision 42865)
+++ /branches/eam_branches/neb-host-20250516/bin/neb-host	(revision 42866)
@@ -16,5 +16,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($host, $state, $note, $db, $dbhost, $dbpass, $dbuser, $debug, $volume);
+my ($host, $state, $xattr, $note, $db, $dbhost, $dbpass, $dbuser, $debug, $volume);
 
 # $db     = $ENV{'NEB_DB'} unless $db;
@@ -43,4 +43,5 @@
     'host=s'         => \$host,
     'state=s'        => \$state,
+    'xattr=s'        => \$xattr,
     'note=s'         => \$note,
     'db=s'           => \$db,
@@ -52,6 +53,11 @@
 
 # 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))) {
+my $Narg = @ARGV;
+
+if (($Narg == 1) && (!defined($host)) && (!defined($state))) {
+    # neb-host (host) : return volume into for specified host
+    $host = shift(@ARGV);
+}
+if (($Narg == 2) && (!defined($host)) && (!defined($state))) {
     $host = shift(@ARGV);
     $state = shift(@ARGV);
@@ -75,4 +81,8 @@
 if (defined($host) && defined($state)) {
 
+    # strip dangerous characters
+    if (defined($note)) { $note =~ s/'/ /g; $note =~ s/;/ /g; $note =~ s/"/ /g; }
+    if (defined($host)) { $host =~ s/'/ /g; $host =~ s/;/ /g; $host =~ s/"/ /g; }
+
     if (($state ne 'up') && ($state ne 'down') && ($state ne 'repair')) { die "Unknown state '$state'"; }
     
@@ -103,15 +113,15 @@
     if ($state eq 'up')     { 
 	$selections = "allocate = 1, available = 1";
-	$constraint = "(name = '$host') AND (xattr != 3) AND (xattr != 5)";
+	$constraint = "$hostWhere AND (xattr != 3) AND (xattr != 5)";
     }
 
     if ($state eq 'repair')     { 
 	$selections = "allocate = 0, available = 1";
-	$constraint = "(name = '$host') AND (xattr != 5)";
+	$constraint = "$hostWhere AND (xattr != 5)";
     }
 
     if ($state eq 'down')     { 
 	$selections = "allocate = 0, available = 0";
-	$constraint = "(name = '$host')";
+	$constraint = "$hostWhere";
     }
 
@@ -121,13 +131,28 @@
     if ($state eq 'up')     { 
 	$selections = "allocate = 0, available = 1";
-	$constraint = "(name = '$host') AND (xattr = 3)";
+	$constraint = "$hostWhere AND (xattr = 3)";
 
 	&modify_hosts ($selections, $constraint, $note);
     }
+    exit 0;
 }
 
 my $sql = Nebulous::Server::SQL->new();
 my ($q, @bind);
-$q = $sql->get_volumes . " ORDER BY v.host, v.name";
+
+if (defined($host)) {
+    if (defined($xattr)) {
+	$q = $sql->get_volumes . " WHERE v.host = '$host' AND v.xattr = $xattr ORDER BY v.host, v.name";
+    } else {
+	$q = $sql->get_volumes . " WHERE v.host = '$host' ORDER BY v.host, v.name";
+    }
+} else {
+    if (defined($xattr)) {
+	$q = $sql->get_volumes . " WHERE v.xattr = $xattr ORDER BY v.host, v.name";
+    } else {
+	$q = $sql->get_volumes . " ORDER BY v.host, v.name";
+    }
+}
+
 warn "$q\n" if $debug;
 my $query = $dbh->prepare($q);
@@ -152,17 +177,22 @@
 
     my $note = $_[2];
+    # print "NOTE: $note\n";
 
     if (defined $note) { $selections = $selections . ", note = '$note'"; }
 
     {
-	my $sqlLine = "UPDATE volume SET ($selections) WHERE $constraint";
+	my $sqlLine = "UPDATE volume SET $selections WHERE $constraint";
+	# print "SQL: $sqlLine\n";
 	my $query = $dbh->prepare($sqlLine);
 	$query->execute() or die "error from Nebulous database\n";
+	$dbh->commit;
     }
     
     { 
-	my $sqlLine = "UPDATE mountedvol SET ($selections) WHERE $constraint";
+	my $sqlLine = "UPDATE mountedvol SET $selections WHERE $constraint";
+	# print "SQL: $sqlLine\n";
 	my $query = $dbh->prepare($sqlLine);
 	$query->execute() or die "error from Nebulous database\n";
+	$dbh->commit;
     }
 }
@@ -184,4 +214,5 @@
     [--note '<status note>']
     [--host <nebulous host>] [--state <up|down|repair>]
+    [--xattr N]
     [--volume]
     [--dbhost <database host>] [--db <database name>]
@@ -195,4 +226,6 @@
 given, the host and state are read directly from the command line.  If nothing
 is specified, prints out the table of currently mounted volumes in nebulous.
+If the state is not specified, but a host is supplied, the table of values is restricted 
+to the specified host.
 
 =head1 OPTIONS
@@ -215,4 +248,8 @@
     repair Allocate = 0, Available = 1
 
+=item * --xattr <N>
+
+Limit the listed volumes to the specified xattr value
+
 =item * --volume
 
