~ubuntu-virt/ubuntu/maverick/eucalyptus/2.0

444.26.12 by Neil
node fixes for iscsi.
1
#!/usr/bin/perl
2
3
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
4
$ENV{'PATH'}='/bin:/usr/bin:/sbin:/usr/sbin/';
5
6
$DELIMITER = ",";
7
$ISCSIADM = untaint(`which iscsiadm`);
8
9
# check binaries
10
if (!-x $ISCSIADM) {
11
    print STDERR "Unable to find iscsiadm\n";
12
    do_exit(1);
13
}
14
15
# check input params
16
$dev_string = untaint(shift @ARGV);
17
444.72.45 by wenye
Fix get_iscsitarget.pl.
18
($euca_home, $ip, $store, $passwd) = parse_devstring($dev_string);
444.26.12 by Neil
node fixes for iscsi.
19
20
print get_device_name($store);
21
22
sub parse_devstring {
23
    my ($dev_string) = @_;
24
    return split($DELIMITER, $dev_string);
25
}
26
27
sub get_device_name {
28
    my ($store) = @_;
29
30
    if(!open GETSESSION, "iscsiadm -m session -P 3 |") {
31
	print "Could not get iscsi session information";
32
	do_exit(1)
33
    }
34
    
35
    $found_target = 0;    
36
    while (<GETSESSION>) {
37
        if($_ =~ /Target: (.*)\n/) {
38
	    $found_target = 1 if $1 == $store;
39
	} elsif($_ =~ /.*Attached scsi disk ([a-zA-Z0-9]+).*\n/) {
40
	    if($found_target == 1) {
41
		return "/dev/", $1;
42
	    }
43
	}
44
    } 
45
    close GETSESSION; 
46
}
47
48
sub do_exit() {
49
    $e = shift;
50
51
    if ($mounted && ($tmpfile ne "")) {
52
	system("$mounter umount $tmpfile");
53
    }
54
    if ($attached && ($loopdev ne "")) {
55
	system("$LOSETUP -d $loopdev");
56
    }
57
    if ($tmpfile ne "") {
58
	system("$RMDIR $tmpfile");
59
    }
60
    exit($e);
61
}
62
63
sub untaint() {
64
    $str = shift;
65
    if ($str =~ /^([ &:#-\@\w.]+)$/) {
66
	$str = $1; #data is now untainted
67
    } else {
68
	$str = "";
69
    }
70
    return($str);
71
}