libadminmfs.pm.in 19.8 KB
Newer Older
1 2
#!/usr/bin/perl -wT
#
3
# Copyright (c) 2005-2014 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#
# Admin MFS library.  Routines related to getting into and out of the
# admin MFS and executing programs within it.
#
# Note that none of these routines are graceful about errors.  If some/all
# nodes fail, their bootinfo states may be modified and not all the same;
# i.e., some nodes may be set to boot into the MFS (or may even have booted
# into the MFS) and others not.  These routines are used primarily at swap
# out time where all inconsistent state will get fixed up anyway, or by
# node_admin where the caller is assumed to be saavy.
#
package libadminmfs;

use strict;
use Exporter;
use vars qw(@ISA @EXPORT);

@ISA    = "Exporter";
41 42
@EXPORT = qw ( TBAdminMfsBoot TBAdminMfsSelect TBAdminMfsRunCmd
    	       TBAdminMfsCreate TBAdminMfsDestroy);
43 44 45

# Must come after package declaration!
use libdb;
46
use libtestbed;
47 48
use StateWait;

Kirk Webb's avatar
Kirk Webb committed
49 50 51 52 53 54
#
# Function prototypes
#
sub TBAdminMfsBoot($$@);
sub TBAdminMfsSelect($$@);
sub TBAdminMfsRunCmd($$@);
55 56
sub TBAdminMfsCreate($$@);
sub TBAdminMfsDestroy($$@);
Kirk Webb's avatar
Kirk Webb committed
57

58 59 60 61 62 63 64 65 66
# Configure variables
my $TB		= "@prefix@";
my $TESTMODE    = @TESTMODE@;
my $TBOPS       = "@TBOPSEMAIL@";
my $ELABINELAB  = @ELABINELAB@;

my $nodereboot	= "$TB/bin/node_reboot";
my $power	= "$TB/bin/power";
my $osselect    = "$TB/bin/os_select";
67
my $nfsmfssetup = "$TB/sbin/nfsmfs_setup";
68

69 70 71 72 73 74 75 76
#
# The number of nodes we will power on at a time and the time to wait
# between batches.  These values are NOT the same as in libreboot.pm.
# I had to reduce the batch count to prevent problems.
#
my $BATCHCOUNT  = 8;
my $BATCHSLEEP	= 5;

77 78 79 80
#
# Timeout for a node to reboot into (or out of) the admin MFS
# XXX we could calculate this from node_type and os_info reboot times
#
81
my $reboottimo  = (6 * 60);
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
my $commandtimo = (2 * 60);
my $sleepwait   = 10;

#
# TBAdminMfsBoot(\%args, \@failed, @nodes)
#
# Boot up (reboot or power on) a set of nodes (@nodes) and optionally wait
# for them to enter or exit the admin MFS.  It is assumed that the node
# has been setup to boot into or out of the admin MFS as appropriate
# (TBAdminMfsSelect). If not, you could be waiting a long time!
# Arguments passed in the $args hash:
#
#	'name'	 string identifying the caller for error messages
#	'on'	 1 to enter MFS, 0 to exit
#	'reboot' 1 to reboot into MFS, -1 to "power on", 0 to do nothing
97
#	'prepare' 1 to run prepare on the way down
98 99
#	'wait'	 1 to wait for all nodes to reach MFS before returning,
#		 0 to return after reboot/power-on
100 101
#	'retry'  1 if we should retry once on nodes that do not make it
#		 into the MFS.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
#
# Returns zero if all nodes successfully complete the reboot (wait==0)
# or reach the MFS (wait==1), and non-zero otherwise.  If the $failed ref
# is defined, it is an arrayref in which we return the list of nodes that
# failed.
#
# Note: NO PERMISSION CHECKING IS DONE.  It is assumed that the caller
# has performed all the necessary checks.
#
sub TBAdminMfsBoot($$@)
{
    my ($args, $failedref, @nodes) = @_;

    my $me = $args->{'name'};
    my $on = $args->{'on'};
    my $reboot = $args->{'reboot'};
    my $wait = $args->{'wait'};
119
    my $prepare = $args->{'prepare'};
120 121 122 123
    my $retry = $args->{'retry'};

    $retry = 0
        if (!defined($retry) || !$wait);
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152

    #
    # Reboot or power on nodes...
    #
   if ($wait) {
	$StateWait::debug = 0;
	
	#
	# Initialize the statewait library.
	#
	my @states   = ();

	#
	# Only wait for MFSSETUP when going into the MFS. When coming out
	# of MFS, just wait for generic ISUP.
	# 
	push(@states, TBDB_NODESTATE_MFSSETUP())
	    if ($on);
	push(@states, TBDB_NODESTATE_ISUP());
    
	if (initStateWait(\@states, @nodes)) {
	    print STDERR "*** $me:\n".
		"    Failed to initialize the statewait library!\n";
	    @$failedref = @nodes
		if (defined($failedref));
	    return 1;
	}
    }

153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
    if ($reboot) {
	#
	# Since the admin MFS is large, we do are own limiting of the number
	# of nodes rebooted in parallel.  This value is considerably lower than
	# that enforced in libreboot.pm.  Also note that we would need to
	# perform batching for the "power on" case anyway, as the power command
	# does not do any batching.
	#
	my @nodelist = @nodes;
	while (@nodelist) {
	    my $batch = "";
	    my $i = 0;
	    while ($i < $BATCHCOUNT && @nodelist > 0) {
		my $node = shift(@nodelist);
		$batch .= " $node";
		$i++;
	    }
	    if ($reboot > 0) {
171 172 173
		my $optarg = ($prepare ? "-p" : "");
		
		if (system("$nodereboot $optarg $batch")) {
174 175 176 177 178 179 180 181 182 183 184 185 186 187
		    print STDERR "*** $me:\n".
			"    WARNING: Could not reboot some of: $batch!\n";
		}
	    } elsif ($reboot < 0) {
		print STDOUT "Powering on nodes:\n";
		if (system("$power on $batch")) {
		    print STDERR "*** $me:\n".
			"    WARNING: Could not power on some of: $batch!\n";
		}
	    }
	    print STDOUT "  $batch ", @nodelist > 0 ? "...\n" : "\n";
	    if (@nodelist) {
		sleep($BATCHSLEEP);
	    }
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
	}
    }

    #
    # ...and wait for them to come back up.
    #
    if ($wait) {
	#
	# Initialize the statewait library.
	#
	my @finished = ();
	my @failed   = ();
	my $endtime = time() + $reboottimo;

	print STDOUT "Waiting for nodes to come up.\n";
	
	# Now we can statewait.
	if (waitForState(\@finished, \@failed, $reboottimo)) {
	    print STDERR "*** $me:\n".
		"    Failed in waitForState!\n";
	    @$failedref = @nodes
		if (defined($failedref));
	    return 1;
	}
	endStateWait();
	
	#
	# XXX gak! Our whole state wait system (actually event system)
	# doesn't distinguish timeouts.  A timeout is a failure in this
	# context since it means that some node did not get where it was
	# supposed to go, and that could be dangerous.  Fortunately, nodes
	# that do timeout, while not added to failed, are not added to
	# finished either (ditto for nodes that go through an improper
	# state transition sequence).  So if the sum of @finished + @failed
	# is not @nodes, then we know some nodes timed out.  So we can go
	# back and tease those out.
	#
	if (scalar(@nodes) > scalar(@finished) + scalar(@failed)) {
	    # there is probably a better way to do a set diff...
	    my %seen;
	    for my $n (@finished, @failed) {
		$seen{$n} = 1;
	    }
	    for my $n (@nodes) {
		push(@failed, $n)
		    if (!defined($seen{$n}));
	    }
	}

237 238 239
	if (@failed == 0) {
	    print STDOUT "All nodes are up.\n";
	    return 0;
240 241
	}

242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
	print STDERR "*** $me:\n".
	             "    Failed to boot " . ($on ? "MFS" : "regular OS") .
		     " on: @failed\n";

	#
	# Failures to boot after powering on may be due to issues with
	# power-on and not related to the nodes themselves.  So we will
	# retry once, trying a power cycle the second time around.
	# This addresses cases where I have seen power on leave a machine
	# (pc600) in a hung state that can be cured by cycling (I have no
	# idea why...).
	#
	if ($reboot < 0 && $retry) {
	    print STDERR "Retrying on failed nodes ...\n";
	    my @myfailed;
	    my %myargs;
	    $myargs{'name'} = $me;
	    $myargs{'on'} = $on;
	    $myargs{'reboot'} = 1;
	    $myargs{'wait'} = $wait;
	    $myargs{'prepare'} = $prepare;
	    $myargs{'retry'} = 0;
	    if (TBAdminMfsBoot(\%myargs, \@myfailed, @failed) == 0) {
		return 0;
	    }
	    @failed = @myfailed;
	}

	@$failedref = @failed
	    if (defined($failedref));
	return 1;
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
    }

    return 0;
}

#
# TBAdminMfsSelect(\%args, \@failed, @nodes)
#
# For the given list of nodes, set or clear the temp OSID field so that
# they will or will not boot into the admin MFS.
#
# Arguments passed via the $args hashref:
#
#	'name'	   string identifying the caller for error messages
#	'on'	   1 to set temp OSID to MFS, 0 to clear
#	'clearall' 1 to clear one-shot and partition boot OSIDs
#		   (if 'on' is set), 0 leaves them alone
#
# Returns zero if we successfully set the state for all nodes,
# and non-zero otherwise.  If the $failed ref is defined, it is an
# arrayref in which we return the list of nodes that failed.
#
# Note: NO PERMISSION CHECKING IS DONE.  It is assumed that the caller
# has performed all the necessary checks.
#
# Note: this call will clear any user-set startupcmd and status.  The
# caller is responsible for saving it if they care.
#
sub TBAdminMfsSelect($$@)
{
    my ($args, $failedref, @nodes) = @_;

    return 0
	if (@nodes == 0);

    my $me = $args->{'name'};
    my $on = $args->{'on'};
    my $only = $args->{'clearall'};
    my @good = ();
    my @bad = ();

    #
    # Set/clear the temp OSID for all nodes.
    #
    if ($on) {
	# clear one-shot boots
319
	if ($only && system("$osselect -c -1 @nodes")) {
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
	    print STDERR "*** $me:\n".
		"    Failed to clear one-shot boot for @nodes!\n";
	    @{$failedref} = @nodes
		if (defined($failedref));
	    return 1;
	}

	# determine the correct admin OSID for all nodes
	my %adminosid = ();
	for my $node (@nodes) {
	    my $osid = TBNodeAdminOSID($node);
	    push @{$adminosid{$osid}}, $node;
	}

	# and set it
	for my $osid (keys %adminosid) {
	    my @n = @{$adminosid{$osid}};
	    if (system("$osselect -t $osid @n")) {
		print STDERR "*** $me:\n".
		    "    Failed to set temp boot to $osid for @n!\n";
		push(@bad, @n);
	    } else {
		push(@good, @n);
	    }
	}

346 347 348 349 350 351 352 353 354
	my %cargs;
	$cargs{'name'} = $me;
	my @cfailed = ();
	if (TBAdminMfsCreate(\%cargs, \@cfailed, @good)) {
	    print STDERR "*** $me:\n".
		"    Failed to create NFS FS for @cfailed; ".
		"continuing, but those nodes won't boot!\n";
	}

355
	# clear partition boots for successful nodes
356
	if ($only && system("$osselect -c @good")) {
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
	    print STDERR "*** $me:\n".
		"    Failed to clear partition boot for @good!\n";
	    @{$failedref} = @nodes
		if (defined($failedref));
	    return 1;
	}
    } else {
	if (system("$osselect -c -t @nodes")) {
	    print STDERR "*** $me:\n".
		"    Failed to clear temp boot for @nodes!\n";
	    @{$failedref} = @nodes
		if (defined($failedref));
	    return 1;
	}
	@good = @nodes;
372 373 374 375 376 377 378 379 380 381 382 383 384 385

	#
	# XXX note that this is a "soft" destroy.
	# We will only rename the existing MFS so that if the node
	# is currently running on it, it will continue to function.
	#
	my %cargs;
	$cargs{'name'} = $me;
	my @cfailed = ();
	if (TBAdminMfsDestroy(\%cargs, \@cfailed, @good)) {
	    print STDERR "*** $me:\n".
		"    Failed to destroy NFS FS for @cfailed; ".
		"continuing, but these FSes will need to be cleaned up!\n";
	}
386 387 388 389 390 391 392
    }

    #
    # Make sure we don't execute any unintended command, either those
    # set by the user when we enter admin mode, or those set by us when
    # we leave admin mode.
    #
393 394 395 396
    if (@good > 0) {
	my $cond = "node_id in (" . join(",", map("'$_'", @good)) . ")";
	if (!DBQueryWarn("update nodes set startupcmd='', startstatus='none' ".
			 "where $cond")) {
397 398 399
	    print STDERR "*** $me:\n".
		"    Failed to clear startup state for @good!\n";
	    push(@bad, @good);
400
	}
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
    }

    @{$failedref} = @bad
	if (defined($failedref));

    return (@bad != 0);
}

#
# TBAdminMfsRunCmd(\%args, \@failed, @nodes)
#
# For the given list of nodes, boot each one into the admin MFS and run the
# indicated command.  Upon successful completion, all nodes are left in the
# MFS with admin mode enabled.  Arguments passed in the $args hash:
#
416 417 418 419 420 421 422 423 424 425 426 427 428 429
#	'name'	    string identifying the caller for error messages
#	'command'   command+args to run on the nodes
#	'timeout'   time in seconds to wait for command completion
#		    (starts when node has booted into MFS)
#	'poweron'   1 if nodes need to be powered on initially
#		    rather than rebooted
#	'pfunc'
#	'pinterval'
#	'pcookie'   Progress tracking.  'pfunc' will be called every
#		    'pinterval' seconds with argument 'pcookie' and a
#		    node-indexed status hash for all nodes.  If
#		    the function returns 0, we abort as we would with
#		    a timeout.
#	'timestamp' if timestamps after significant events are desired
430
#	'prepare'   1 if nodes should be rebooted with "prepare" flag
431 432
#	'retry'     1 if we should retry once on nodes that do not make it
#		    into the MFS.
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
#
# Returns zero if all nodes successfully run the command.
# If the $failed ref is defined, it is an arrayref in which we return the
# list of nodes that failed.
#
# Note: NO PERMISSION CHECKING IS DONE.  It is assumed that the caller
# has performed all the necessary checks.
#
# Note: this call will clear any user-set startupcmd and status.  The
# caller is responsible for saving it if they care.
#
sub TBAdminMfsRunCmd($$@)
{
    my ($args, $failedref, @nodes) = @_;

    my $me = $args->{'name'};
    my $cmd = $args->{'command'};
    my $timeout = $args->{'timeout'};
    my $poweron = $args->{'poweron'};
452 453 454 455
    my $timestamp = $args->{'timestamp'};
    my $pfunc = $args->{'pfunc'};
    my $pinterval = $args->{'pinterval'};
    my $pcookie = $args->{'pcookie'};
456
    my $prepare = $args->{'prepare'};
457
    my $retry = $args->{'retry'};
458 459 460 461 462 463

    # we always need a value
    $timeout = $commandtimo
	if (!defined($timeout));
    $poweron = 0
	if (!defined($poweron));
464 465 466 467
    if ($pfunc) {
	$pinterval = 10
	    if (!defined($pinterval));
    }
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499

    #
    # Arrange for the node to boot into the MFS, but don't boot it yet.
    #
    my %myargs;
    $myargs{'name'} = $me;
    $myargs{'on'} = 1;
    $myargs{'clearall'} = 0;
    if (TBAdminMfsSelect(\%myargs, undef, @nodes)) {
	@{$failedref} = @nodes
	    if (defined($failedref));
	return 1;
    }

    #
    # Record the startup command.  The status has already been set to
    # 'none' by Select above.
    #
    my $allcond = "node_id in (" . join(",", map("'$_'", @nodes)) . ")";
    if (!DBQueryWarn("update nodes set startupcmd='$cmd' where $allcond")) {
	print STDERR "*** $me:\n".
	    "    DB error updating node startupcmd info for @nodes!\n";
	@{$failedref} = @nodes
	    if (defined($failedref));
	return 1;
    }

    #
    # Now reboot into the admin MFS.  TBAdminMfsBoot will return when
    # the nodes report ISUP, which they will do before firing off the
    # startup command.
    #
500 501
    TBDebugTimeStamp("Booting nodes into admin MFS")
	if ($timestamp);
502 503 504 505
    %myargs = ();
    $myargs{'name'} = $me;
    $myargs{'on'} = 1;
    $myargs{'reboot'} = $poweron ? -1 : 1;
506
    $myargs{'retry'} = $retry;
507
    $myargs{'prepare'} = $prepare;
508 509 510 511
    $myargs{'wait'} = 1;
    my @failed = ();
    if (TBAdminMfsBoot(\%myargs, \@failed, @nodes)) {
	print STDERR "*** $me:\n".
512
	    "    failed admin MFS boot for @failed!\n";
513 514 515 516 517 518 519 520
	@{$failedref} = @nodes
	    if (defined($failedref));
	return 1;
    }

    #
    # Wait for the command completion status or til we time out
    #
521 522
    TBDebugTimeStamp("Nodes in admin MFS, running command")
	if ($timestamp);
523 524
    my @running = @nodes;
    my %status = ();
525 526 527
    foreach my $node (@nodes) {
	$status{$node} = "none";
    }
528
    my $endtime = time() + $timeout;
529
    my $interval = $pfunc ? $pinterval : $sleepwait;
530
    while (@running > 0 && time() < $endtime) {
531
	sleep($interval);
532 533 534 535 536 537 538 539 540 541 542 543 544

	my $cond = "node_id in (" . join(",", map("'$_'", @running)) . ")";
	my $query_result =
	    DBQueryWarn("select node_id,startstatus from nodes where $cond");

	if (!$query_result || $query_result->numrows < 1) {
	    print STDERR "*** $me:\n".
		"    DB error getting startstatus for @running!\n";
	    @running = ();
	    last;
	}
 
	while (my ($node, $result) = $query_result->fetchrow_array()) {
545
	    $status{$node} = $result;
546 547
	}

548 549 550 551 552 553 554 555 556 557 558 559 560 561
	#
	# Run the progress function with the updated status of all nodes.
	#
	if ($pfunc && &$pfunc($pcookie, \%status) == 0) {
	    last;
	}

	#
	# Recompute the set of running nodes after any progress function
	# has been called in case that function has updated a node's status.
	# We trust that the function will be well behaved and not add nodes
	# that don't belong!
	#
	@running = grep { $status{$_} eq "none" } keys(%status);
562 563 564 565 566 567
    }

    #
    # Everyone has reported or we timed out.
    # Find out who succeeded, who failed, and who timed out.
    #
568 569
    TBDebugTimeStamp("Node admin MFS commands completed/timedout")
	if ($timestamp);
570 571 572
    my @succeeded = ();
    my @timedout = ();
    for my $node (@nodes) {
573
	if ($status{$node} eq "none" || $status{$node} eq "timeout") {
574
	    push(@timedout, $node);
575
	} elsif (int($status{$node}) != 0) {
576 577 578 579 580 581 582 583 584
	    push(@failed, $node);
	} else {
	    push(@succeeded, $node);
	}
    }

    if (scalar(@nodes) != scalar(@succeeded)) {
	if (scalar(@failed) > 0) {
	    print STDERR "*** $me:\n".
585
		"    Command run failed on @failed\n";
586 587 588 589 590
	    push(@{$failedref}, @failed)
		if (defined($failedref));
	}
	if (scalar(@timedout) > 0) {
	    print STDERR "*** $me:\n".
591
		"    Timed-out while running command on @timedout\n";
592 593 594 595 596 597 598 599 600
	    push(@{$failedref}, @timedout)
		if (defined($failedref));
	}
	return 1;
    }

    print STDOUT "All nodes have completed their command.\n";
    return 0;
}
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716

#
# TBAdminMfsCreate(\%args, \@failed, @nodes)
#
# For the given list of nodes, find those that need their MFS created
# dynamically and do so.
#
# Arguments passed via the $args hashref:
#
#	'name'	   string identifying the caller for error messages
#	'force'    1 to force re-creation of the MFS if it already exists,
#		   0 will just reuse any existing MFS.
#
# Returns zero if we successfully created all MFSes and non-zero otherwise.
# If the $failed ref is defined, it is an arrayref in which we return the
# list of nodes that failed.
#
# Note: NO PERMISSION CHECKING IS DONE.  It is assumed that the caller
# has performed all the necessary checks.
#
sub TBAdminMfsCreate($$@)
{
    my ($args, $failedref, @nodes) = @_;

    return 0
	if (@nodes == 0);

    my $me = $args->{'name'};
    my $force = exists($args->{'force'}) ? $args->{'force'} : 0;

    #
    # Find all the nodes that require a dynamic MFS
    #
    my @nfsnodes = ();
    for my $node (@nodes) {
	require OSinfo;

	my $osobj = OSinfo->Lookup(TBNodeAdminOSID($node));
	if ($osobj && $osobj->IsNfsMfs()) {
	    push @nfsnodes, $node;
	}
    }

    #
    # If any nodes are using an NFS-based MFS, set them up.
    #
    if (@nfsnodes > 0) {
	my $args = $force ? "-f" : "";
	if (system("$nfsmfssetup $args @nfsnodes")) {
	    @$failedref = @nfsnodes
		if (defined($failedref));
	    return 1;
	}
    }

    return 0;
}

#
# TBAdminMfsDestroy(\%args, \@failed, @nodes)
#
# For the given list of nodes, find those that use a dynamic MFS
# and destroy it.
#
# Arguments passed via the $args hashref:
#
#	'name'	   string identifying the caller for error messages
#	'force'    1 to force actual destruction of the MFS, screwing
#		   the node if it is currently running on it.
#		   0 will just rename the existing MFS instead,
#		   with the old copy destroyed on next creation.
#
# Returns zero if we successfully destroyed all MFSes and non-zero otherwise.
# If the $failed ref is defined, it is an arrayref in which we return the
# list of nodes that failed.
#
# Note: NO PERMISSION CHECKING IS DONE.  It is assumed that the caller
# has performed all the necessary checks.
#
sub TBAdminMfsDestroy($$@)
{
    my ($args, $failedref, @nodes) = @_;

    return 0
	if (@nodes == 0);

    my $me = $args->{'name'};
    my $force = exists($args->{'force'}) ? $args->{'force'} : 0;

    #
    # Find all the nodes that require a dynamic MFS
    #
    my @nfsnodes = ();
    for my $node (@nodes) {
	require OSinfo;

	my $osobj = OSinfo->Lookup(TBNodeAdminOSID($node));
	if ($osobj && $osobj->IsNfsMfs()) {
	    push @nfsnodes, $node;
	}
    }

    #
    # If any nodes are using an NFS-based MFS, set them up.
    #
    if (@nfsnodes > 0) {
	my $args = $force ? "-f" : "";
	if (system("$nfsmfssetup -D $args @nfsnodes")) {
	    @$failedref = @nfsnodes
		if (defined($failedref));
	    return 1;
	}
    }

    return 0;
}