| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # This file is part of StorageDisplay | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # This software is copyright (c) 2014-2023 by Vincent Danjean. | ||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||
| 7 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 8 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # PODNAME: storage-merge-dots | ||||||||||||||||||||||||||||
| 12 | # ABSTRACT: merge dot files created by storage2dot, adding inter links if possible | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | our $VERSION = '2.06'; # VERSION | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use StorageDisplay; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use StorageDisplay::Collect; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub collect_from_remote { | ||||||||||||||||||||||||||
|
Subroutine
collect_from_remote: not called CC=16 SCAR=52.1
| |||||||||||||||||||||||||||||
| 25 | 0 | my $remote = shift; | |||||||||||||||||||||||||||
| 26 | 0 | my $content=''; | |||||||||||||||||||||||||||
| 27 | 2 | ▶ | use Net::OpenSSH; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 2 | ▶ | use Term::ReadKey; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 2 | ▶ | END { | ||||||||||||||||||||||||||
|
Subroutine
END: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 2 | ReadMode('normal'); | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | 0 | my $ssh = Net::OpenSSH->new($remote); | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | $ssh->error and | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | die "Couldn't establish SSH connection: ". $ssh->error; | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | my ($in, $out, $pid) = $ssh->open2( | |||||||||||||||||||||||||||
| 37 | #'cat', | ||||||||||||||||||||||||||||
| 38 | 'perl', '--', '-', | ||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | my $fdperlmod; | |||||||||||||||||||||||||||
| 42 | open($fdperlmod, '<', $INC{'StorageDisplay/Collect.pm'}) | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | or die "Cannot open ".INC{'StorageDisplay/Collect.pm'}.": $!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | #use Sys::Syscall; | ||||||||||||||||||||||||||||
| 45 | #Sys::Syscall::sendfile($in, $fdperlmod); | ||||||||||||||||||||||||||||
| 46 | { | ||||||||||||||||||||||||||||
| 47 | 0 | ▶ | while(defined(my $line=<$fdperlmod>)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | last if $line =~ m/^__END__\s*$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | print $in $line; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 0 | close $fdperlmod; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | #print $in "StorageDisplay::Collect::dump_collect;\n"; | ||||||||||||||||||||||||||||
| 54 | 0 | my @args = (@_, 'LocalBySSH'); | |||||||||||||||||||||||||||
| 55 | 0 | my $cmd = "StorageDisplay::Collect::dump_collect('".join("','", @args)."');\n"; | |||||||||||||||||||||||||||
| 56 | 0 | print STDERR 'Running through SSH: ',$cmd; | |||||||||||||||||||||||||||
| 57 | 0 | print $in $cmd; | |||||||||||||||||||||||||||
| 58 | 0 | print $in "__END__\n"; | |||||||||||||||||||||||||||
| 59 | 0 | flush $in; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 2 | ▶ | use IO::Select; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 62 | 2 | ▶ | use POSIX ":sys_wait_h"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 63 | 0 | my $sel = IO::Select->new(\*STDIN, $out); | |||||||||||||||||||||||||||
| 64 | 0 | my $timeout = 1; | |||||||||||||||||||||||||||
| 65 | 0 | ReadMode('noecho'); | |||||||||||||||||||||||||||
| 66 | 0 | my ($in_closed,$out_closed) = (0,0); | |||||||||||||||||||||||||||
| 67 | 0 | while(1) { | |||||||||||||||||||||||||||
| 68 | 0 | $!=0; | |||||||||||||||||||||||||||
| 69 | 0 | my @ready = $sel->can_read($timeout); | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ($!) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | die "Error with select: $!\n"; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if (scalar(@ready)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 0 | foreach my $fd (@ready) { | |||||||||||||||||||||||||||
| 75 | 0 | ▶ | if ($fd == $out) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | my $line=<$out>; | |||||||||||||||||||||||||||
| 77 | 0 | ▶ | if (defined($line)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | $content .= $line; | |||||||||||||||||||||||||||
| 79 | } else { | ||||||||||||||||||||||||||||
| 80 | 0 | $sel->remove($out); | |||||||||||||||||||||||||||
| 81 | 0 | close $out; | |||||||||||||||||||||||||||
| 82 | 0 | $out_closed=1; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } else { | ||||||||||||||||||||||||||||
| 85 | 0 | my $line=<STDIN>; | |||||||||||||||||||||||||||
| 86 | 0 | ▶ | if (print $in $line) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | flush $in; | |||||||||||||||||||||||||||
| 88 | } else { | ||||||||||||||||||||||||||||
| 89 | 0 | $sel->remove(\*STDIN); | |||||||||||||||||||||||||||
| 90 | 0 | close $in; | |||||||||||||||||||||||||||
| 91 | 0 | $in_closed=1; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | } else { | ||||||||||||||||||||||||||||
| 96 | 0 | my $res = waitpid($pid, WNOHANG); | |||||||||||||||||||||||||||
| 97 | 0 | ▶ | if ($res==-1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | die "Some error occurred ".($? >> 8).": $!\n"; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if ($res) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if (!$in_closed) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | $sel->remove(\*STDIN); | |||||||||||||||||||||||||||
| 103 | 0 | close $in; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 0 | ReadMode('normal'); | |||||||||||||||||||||||||||
| 106 | 0 | last; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | #print STDERR "timeout for $pid\n"; | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if (!$out_closed) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | while (defined(my $line=<$out>)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | $content .= $out; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 0 | $sel->remove($out); | |||||||||||||||||||||||||||
| 116 | 0 | close $out; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | 0 | return $content; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 2 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 122 | 2 | ▶ | use Pod::Usage; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 123 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 124 | 2 | $Data::Dumper::Sortkeys = 1; | |||||||||||||||||||||||||||
| 125 | 2 | $Data::Dumper::Purity = 1; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 2 | my $help; | |||||||||||||||||||||||||||
| 128 | my $man; | ||||||||||||||||||||||||||||
| 129 | 2 | my $verbose; | |||||||||||||||||||||||||||
| 130 | 2 | my $vmnames={}; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 2 | ▶ | GetOptions ("v|verbose+" => \$verbose, # flag | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | "h|help" => \$help, # flag | ||||||||||||||||||||||||||||
| 134 | "man" => \$man, # flag | ||||||||||||||||||||||||||||
| 135 | "vm=s" => $vmnames, | ||||||||||||||||||||||||||||
| 136 | ) or pod2usage(2); | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 2 | my $dotfiles; | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 2 | my $print_level=0; | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | sub print_info { | ||||||||||||||||||||||||||
|
Subroutine
print_info: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if ($verbose) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 0 | foreach my $l (@_) { | |||||||||||||||||||||||||||
| 145 | 0 | print STDERR "I: ".(' 'x$print_level).$l."\n"; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | ▶ | sub print_warn { | ||||||||||||||||||||||||||
|
Subroutine
print_warn: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 151 | 0 | foreach my $l (@_) { | |||||||||||||||||||||||||||
| 152 | 0 | print STDERR "W: ".(' 'x$print_level).$l."\n"; | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 2 | my $slinks={}; | |||||||||||||||||||||||||||
| 157 | 2 | my $tlinks={}; | |||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 0 | ▶ | sub add_link { | ||||||||||||||||||||||||||
|
Subroutine
add_link: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 160 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 161 | 0 | my $name = shift; | |||||||||||||||||||||||||||
| 162 | 0 | my $link = shift; | |||||||||||||||||||||||||||
| 163 | 0 | ▶ | if ($link !~ m,([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s*$,) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 0 | return; | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | 0 | my ($vm, $size, $disk, $sl) = ($1, $2, $3, $4); | |||||||||||||||||||||||||||
| 168 | 0 | my $realdisk = 1; | |||||||||||||||||||||||||||
| 169 | 0 | ▶ | if ($disk =~ m,^[(](.*)[)]$,) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | 0 | $disk = $1; | |||||||||||||||||||||||||||
| 171 | 0 | $realdisk = 0; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | 0 | ▶ | if (exists($self->{$vm}->{$disk})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 0 | print_warn "Ignoring duplicate $name link: $link"; | |||||||||||||||||||||||||||
| 175 | } else { | ||||||||||||||||||||||||||||
| 176 | 0 | $self->{$vm}->{$disk} = { | |||||||||||||||||||||||||||
| 177 | 'link' => $sl, | ||||||||||||||||||||||||||||
| 178 | 'size' => $size, | ||||||||||||||||||||||||||||
| 179 | 'realdisk' => $realdisk, | ||||||||||||||||||||||||||||
| 180 | 'name' => $disk, | ||||||||||||||||||||||||||||
| 181 | }; | ||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 0 | ▶ | sub add_slink { | ||||||||||||||||||||||||||
|
Subroutine
add_slink: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 186 | 0 | my $link = shift; | |||||||||||||||||||||||||||
| 187 | 0 | add_link($slinks, "source", $link); | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 0 | ▶ | sub add_tlink { | ||||||||||||||||||||||||||
|
Subroutine
add_tlink: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 191 | 0 | my $link = shift; | |||||||||||||||||||||||||||
| 192 | 0 | add_link($tlinks, "target", $link); | |||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 0 | ▶ | sub check_disks { | ||||||||||||||||||||||||||
|
Subroutine
check_disks: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 196 | 0 | my $hostdisk = shift; | |||||||||||||||||||||||||||
| 197 | 0 | my $vmdisk = shift; | |||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 0 | ▶ | return 0 if not exists($vmdisk->{name}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | 0 | ▶ | return 0 if $hostdisk->{matched}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | 0 | ▶ | return 0 if $vmdisk->{matched}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 0 | ▶ | if ($hostdisk->{size} != $vmdisk->{size}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | 0 | print_info "Rejecting $hostdisk->{name} to $vmdisk->{name}: different size"; | |||||||||||||||||||||||||||
| 205 | 0 | return 0; | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | 0 | return 1; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 0 | ▶ | sub match_links { | ||||||||||||||||||||||||||
|
Subroutine
match_links: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||
| 211 | 0 | my $host = shift; | |||||||||||||||||||||||||||
| 212 | 0 | my $vm = shift; | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 0 | my @matching; | |||||||||||||||||||||||||||
| 215 | 0 | foreach my $hostdname (sort keys %$host) { | |||||||||||||||||||||||||||
| 216 | 0 | my $hostdisk = $host->{$hostdname}; | |||||||||||||||||||||||||||
| 217 | 0 | ▶ | next if $hostdisk->{matched}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | 0 | my $vmdname = $hostdname; | |||||||||||||||||||||||||||
| 219 | 0 | ▶ | my $vmdisk = $vm->{$vmdname} // {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$vm->{$vmdname} // {}
MC/DC0%0/1
$vm->{$vmdname} // {}
$vm->{$vmdname}
Truth table0%0/2
A
A= $vm->{$vmdname}
| |||||||||||||||||||||||||||||
| 220 | 0 | ▶ | if ($hostdisk->{realdisk} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$hostdisk->{"realdisk"} and check_disks($hostdisk, $vmdisk)
MC/DC0%0/2
$hostdisk->{"realdisk"} and check_disks($hostdisk, $vmdisk)
$hostdisk->{"realdisk"}
check_disks($hostdisk, $vmdisk)
Truth table0%0/3
A and B
A= $hostdisk->{"realdisk"}B= check_disks($hostdisk, $vmdisk)
| |||||||||||||||||||||||||||||
| 221 | && check_disks($hostdisk, $vmdisk)) { | ||||||||||||||||||||||||||||
| 222 | # fast path with real diskname (qemu agent was available) | ||||||||||||||||||||||||||||
| 223 | 0 | push @matching, [$hostdisk, $vmdisk]; | |||||||||||||||||||||||||||
| 224 | 0 | $hostdisk->{matched} = 1; | |||||||||||||||||||||||||||
| 225 | 0 | $vmdisk->{matched} = 1; | |||||||||||||||||||||||||||
| 226 | 0 | next; | |||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | # slow path: qemu-agent not available or device renamed after reboot | ||||||||||||||||||||||||||||
| 229 | # trying to check with disksize | ||||||||||||||||||||||||||||
| 230 | 0 | $vmdisk = undef; | |||||||||||||||||||||||||||
| 231 | 0 | foreach my $vmdisk_try (values %$vm) { | |||||||||||||||||||||||||||
| 232 | 0 | ▶ | if (check_disks($hostdisk, $vmdisk_try)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 233 | 0 | ▶ | if (defined($vmdisk)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | 0 | print_warn "Multiple disks matching, ignoring it"; | |||||||||||||||||||||||||||
| 235 | 0 | $vmdisk = undef; | |||||||||||||||||||||||||||
| 236 | 0 | last; | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | 0 | $vmdisk = $vmdisk_try; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | 0 | ▶ | if (defined($vmdisk)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 242 | 0 | push @matching, [$hostdisk, $vmdisk]; | |||||||||||||||||||||||||||
| 243 | 0 | $hostdisk->{matched} = 1; | |||||||||||||||||||||||||||
| 244 | 0 | $vmdisk->{matched} = 1; | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | 0 | return @matching; | |||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 2 | my $one_handled; | |||||||||||||||||||||||||||
| 251 | 0 | ▶ | sub handle_dotfile { | ||||||||||||||||||||||||||
|
Subroutine
handle_dotfile: not called CC=21 SCAR=61.4
| |||||||||||||||||||||||||||||
| 252 | 0 | my $filename = shift; | |||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 0 | my $state = 0; | |||||||||||||||||||||||||||
| 255 | 0 | ▶ | open(my $h, '<', $filename) or die "Cannot read $filename\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | 0 | ▶ | my $print = $one_handled ? 0 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 257 | 0 | my $header_size = 0; | |||||||||||||||||||||||||||
| 258 | 0 | my $footer_size = 0; | |||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 0 | ▶ | while(defined(my $line = <$h>)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 261 | 0 | chomp($line); | |||||||||||||||||||||||||||
| 262 | 0 | ▶ | if ($state == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | 0 | $state = 1; | |||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | 0 | ▶ | if ($line =~ m,//\s*HEADER: MACHINE\s*$,) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 266 | 0 | ▶ | if ($state == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 267 | 0 | ▶ | print $line, "\n" if not $one_handled; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 268 | 0 | $header_size++; | |||||||||||||||||||||||||||
| 269 | } else { | ||||||||||||||||||||||||||||
| 270 | 0 | print_warn "Ignoring header line after data: $line"; | |||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||
| 272 | } elsif ($line =~ m,//\s*FOOTER: MACHINE\s*$,) { | ||||||||||||||||||||||||||||
| 273 | 0 | ▶ | if ($state < 2) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 274 | 0 | print_warn "Ignoring footer line before data: $line"; | |||||||||||||||||||||||||||
| 275 | } elsif ($state == 2) { | ||||||||||||||||||||||||||||
| 276 | 0 | $state = 3; | |||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | 0 | ▶ | if ($state == 3) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 279 | 0 | ▶ | if ($line !~ m,^\s*}\s*//\s*FOOTER: MACHINE\s*$,) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 280 | 0 | print_warn "Strange footer line $line"; | |||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | 0 | $footer_size++; | |||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | } else { | ||||||||||||||||||||||||||||
| 285 | 0 | ▶ | if ($state < 1) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 286 | 0 | print_warn "Data before header"; | |||||||||||||||||||||||||||
| 287 | } elsif ($state == 1) { | ||||||||||||||||||||||||||||
| 288 | 0 | $state = 2; | |||||||||||||||||||||||||||
| 289 | 0 | $one_handled++; | |||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||
| 291 | 0 | ▶ | if ($state == 2) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 292 | 0 | print $line, "\n"; | |||||||||||||||||||||||||||
| 293 | 0 | ▶ | if ($line =~ m,//\s*SOURCE\s+LINK\s*:\s*(.*)$,) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 294 | 0 | my $link = $1; | |||||||||||||||||||||||||||
| 295 | 0 | add_slink($link); | |||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | 0 | ▶ | if ($line =~ m,//\s*TARGET\s+LINK\s*:\s*(.*)$,) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 298 | 0 | my $link = $1; | |||||||||||||||||||||||||||
| 299 | 0 | add_tlink($link); | |||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | } elsif ($state == 3) { | ||||||||||||||||||||||||||||
| 302 | 0 | print_warn "Ignoring data after footer line: $line"; | |||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||
| 307 | 0 | ▶ | if ($header_size != 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 308 | 0 | print_warn "Strange header with $header_size lines"; | |||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||
| 310 | 0 | ▶ | if ($footer_size != 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | 0 | print_warn "Strange footer with $header_size lines"; | |||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | 2 | ▶ | sub main() { | ||||||||||||||||||||||||||
|
Subroutine
main: called CC=9 SCAR=41.2
| |||||||||||||||||||||||||||||
| 316 | 2 | ▶ | pod2usage(-exitval => 0, -verbose => 1) if $help; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 317 | 1 | ▶ | pod2usage(-exitval => 0, -verbose => 2) if $man; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | 0 | foreach my $dotfilename (@ARGV) { | |||||||||||||||||||||||||||
| 320 | 0 | print_info "handling $dotfilename"; | |||||||||||||||||||||||||||
| 321 | 0 | $print_level++; | |||||||||||||||||||||||||||
| 322 | 0 | handle_dotfile($dotfilename); | |||||||||||||||||||||||||||
| 323 | 0 | $print_level--; | |||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||
| 325 | #use Data::Dumper; | ||||||||||||||||||||||||||||
| 326 | #print STDERR Dumper($slinks), "\n"; | ||||||||||||||||||||||||||||
| 327 | #print STDERR Dumper($tlinks), "\n"; | ||||||||||||||||||||||||||||
| 328 | 0 | print_info "handling interlinks"; | |||||||||||||||||||||||||||
| 329 | 0 | $print_level++; | |||||||||||||||||||||||||||
| 330 | 0 | foreach my $vm (sort keys %{$slinks}) { | |||||||||||||||||||||||||||
| 331 | 0 | ▶ | my $hostname = $vmnames->{$vm} // $vm; | ||||||||||||||||||||||||||
|
Condition0%0/3
$vmnames->{$vm} // $vm
MC/DC0%0/2
$vmnames->{$vm} // $vm
$vmnames->{$vm}
$vm
Truth table0%0/3
A // B
A= $vmnames->{$vm}B= $vm
| |||||||||||||||||||||||||||||
| 332 | 0 | print_info "Looking for $vm ($hostname) VM"; | |||||||||||||||||||||||||||
| 333 | 0 | ▶ | if (exists($tlinks->{$hostname})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 334 | 0 | $print_level++; | |||||||||||||||||||||||||||
| 335 | 0 | print_info "Found target"; | |||||||||||||||||||||||||||
| 336 | 0 | my @matches = match_links($slinks->{$vm}, $tlinks->{$hostname}); | |||||||||||||||||||||||||||
| 337 | 0 | foreach (@matches) { | |||||||||||||||||||||||||||
| 338 | 0 | my ($hd, $vmd) = @{$_}; | |||||||||||||||||||||||||||
| 339 | 0 | print_info "Linking $hd->{name}\@$vm to $vmd->{name}\@$hostname"; | |||||||||||||||||||||||||||
| 340 | 0 | print $hd->{link}, " -> ", $vmd->{link}, "\n"; | |||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||
| 342 | 0 | $print_level--; | |||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||
| 345 | 0 | $print_level--; | |||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 0 | ▶ | if ($one_handled) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 348 | 0 | print "} // FOOTER: MACHINE\n"; | |||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 2 | main | |||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | __END__ | ||||||||||||||||||||||||||||