nfstrace.in 3.17 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/perl -wT

#
# EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group.
# All rights reserved.
#

use English;
use IPC::Open2;

#
# Configure variables
#
my $TB		= "@prefix@";
my $TBOPS       = "@TBOPSEMAIL@";
my $TESTMODE    = @TESTMODE@;
my $FSNODE      = "@FSNODE@";

20
21
22
23
24
my $FSDIR_GROUPS = "@FSDIR_GROUPS@";
my $FSDIR_PROJ = "@FSDIR_PROJ@";
my $FSDIR_USERS = "@FSDIR_USERS@";
my $FSDIR_SHARE = "@FSDIR_SHARE@";

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Note no -n option. We redirect stdin from the new exports file below.
my $SSH		= "$TB/bin/sshtb -l root -host $FSNODE";
my $DBPROG	= "$TB/sbin/nfsdump2db";
my $PROG	= "$TB/sbin/nfstrace.proxy";
my $TMPFILE     = "/var/nfstrace/temp";
my $dbg		= 1;
my @row;

#
# Handle command-line arguments
#
sub usage() {
    warn "Usage: $0 <gc|get|stats> pid eid\n";
    return 1;
}

my $cmd = shift @ARGV;
if (!$cmd) {
    exit usage();
}

# Check the operation type
if ($cmd !~ /^(gc|get|stats)$/) {
    exit usage();
} else {
    # Untaint operation
    $cmd = $1;
}

my $pid;
my $eid;

if (@ARGV == 2) {
    $pid = $ARGV[0];
    $eid = $ARGV[1];

    #
    # Untaint args.
    #
    if ($pid =~ /^([-\@\w]+)$/) {
	$pid = $1;
    }
    else {
	die_noretry("Bad data in pid: $pid.");
    }
    if ($eid =~ /^([-\@\w]+)$/) {
	$eid = $1;
    }
    else {
	die_noretry("Bad data in eid: $eid.");
    }
}
elsif ($cmd ne "stats") {
    print "Project ID and Experiment ID missing.";
    exit usage();
}

#
# We don't want to run this script unless its the real version.
#
if ($EUID != 0) {
    die("*** $0:\n".
	"    Must be root! Maybe its a development version?\n");
}

# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/sbin:/usr/local/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

#
# Turn off line buffering on output
#
$| = 1;

#
# Testbed Support libraries
# 
use lib "@prefix@/lib";
use libdb;
use libtestbed;

$UID = 0;

108
109
110
111
112
113
114
115
116
117
118
my $cmdline = "$SSH $PROG $cmd";

if ($cmd eq "get") {
    $cmdline .= " -m $FSDIR_GROUPS:/groups";
    $cmdline .= " -m $FSDIR_PROJ:/proj";
    $cmdline .= " -m $FSDIR_USERS:/users";
    $cmdline .= " -m $FSDIR_SHARE:/share";
    $cmdline .= " $pid $eid";
}
elsif ($cmd eq "gc") {
    $cmdline = "$SSH xargs -n 100 $PROG $cmd -e $pid/$eid";
119
120
121
}

local (*NT_READER, *NT_WRITER);
122
$ntpid = open2(\*NT_READER, \*NT_WRITER, $cmdline);
123

124
if ($cmd eq "gc" && defined($pid)) {
125
126
127
128
129
130
131
132
    #
    # First gather up all the nodes that are reserved and the required info.
    # Order by pid,gid first so that they're all grouped together and we avoid
    # extra db queries.
    #
    # VIRTNODE HACK: Virtual nodes are special, so do not export. (isvirtnode).
    #
    $nodes_result =
133
	DBQueryFatal("select r.vname from reserved as r ".
134
135
136
137
138
		     "left join nodes on r.node_id=nodes.node_id ".
		     "left join node_types on node_types.type=nodes.type ".
		     " where nodes.role='testnode' ".
		     "       and node_types.isvirtnode=0 ".
		     "       and node_types.isremotenode=0 ".
139
		     "       and node_types.control_net is not null ".
140
141
		     "       and pid='$pid' and eid='$eid'");
    
142
143
    while (my ($vname) = $nodes_result->fetchrow_array) {
	print NT_WRITER "$vname\n";
144
145
146
147
148
149
150
151
152
153
154
155
156
    }
}

close(NT_WRITER);

while (<NT_READER>) {
    print "$_";
}

close(NT_READER);
waitpid($ntpid, 0);

exit(0);