hvsupport.pl 11.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/usr/bin/perl

use strict;
use warnings;

use File::Find;

die "syntax: $0 SRCDIR\n" unless int(@ARGV) == 1;

my $srcdir = shift @ARGV;

my $symslibvirt = "$srcdir/libvirt_public.syms";
my $symsqemu = "$srcdir/libvirt_qemu.syms";
14
my $symslxc = "$srcdir/libvirt_lxc.syms";
15 16 17 18 19 20
my $drivertable = "$srcdir/driver.h";

my %groupheaders = (
    "virDriver" => "Hypervisor APIs",
    "virNetworkDriver" => "Virtual Network APIs",
    "virInterfaceDriver" => "Host Interface APIs",
21
    "virNodeDeviceDriver" => "Host Device APIs",
22 23 24 25 26 27 28 29 30
    "virStorageDriver" => "Storage Pool APIs",
    "virSecretDriver" => "Secret APIs",
    "virNWFilterDriver" => "Network Filter APIs",
    );


my @srcs;
find({
    wanted => sub {
31 32 33
        if (m!$srcdir/.*/\w+_(driver|tmpl|monitor|hal|udev)\.c$!) {
            push @srcs, $_ if $_ !~ /vbox_driver\.c/;
        }
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
    }, no_chdir => 1}, $srcdir);
my $line;

# Get the list of all public APIs and their corresponding version

my %apis;
open FILE, "<$symslibvirt"
    or die "cannot read $symslibvirt: $!";

my $vers;
my $prevvers;
while (defined($line = <FILE>)) {
    chomp $line;
    next if $line =~ /^\s*#/;
    next if $line =~ /^\s*$/;
    next if $line =~ /^\s*(global|local):/;
    if ($line =~ /^\s*LIBVIRT_(\d+\.\d+\.\d+)\s*{\s*$/) {
51 52 53 54
        if (defined $vers) {
            die "malformed syms file";
        }
        $vers = $1;
55
    } elsif ($line =~ /\s*}\s*;\s*$/) {
56 57 58 59 60
        if (defined $prevvers) {
            die "malformed syms file";
        }
        $prevvers = $vers;
        $vers = undef;
61
    } elsif ($line =~ /\s*}\s*LIBVIRT_(\d+\.\d+\.\d+)\s*;\s*$/) {
62 63 64 65 66
        if ($1 ne $prevvers) {
            die "malformed syms file $1 != $vers";
        }
        $prevvers = $vers;
        $vers = undef;
67
    } elsif ($line =~ /\s*(\w+)\s*;\s*$/) {
68
        $apis{$1} = $vers;
69
    } else {
70
        die "unexpected data $line\n";
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    }
}

close FILE;


# And the same for the QEMU specific APIs

open FILE, "<$symsqemu"
    or die "cannot read $symsqemu: $!";

$prevvers = undef;
$vers = undef;
while (defined($line = <FILE>)) {
    chomp $line;
    next if $line =~ /^\s*#/;
    next if $line =~ /^\s*$/;
    next if $line =~ /^\s*(global|local):/;
    if ($line =~ /^\s*LIBVIRT_QEMU_(\d+\.\d+\.\d+)\s*{\s*$/) {
90 91 92 93
        if (defined $vers) {
            die "malformed syms file";
        }
        $vers = $1;
94
    } elsif ($line =~ /\s*}\s*;\s*$/) {
95 96 97 98 99
        if (defined $prevvers) {
            die "malformed syms file";
        }
        $prevvers = $vers;
        $vers = undef;
100
    } elsif ($line =~ /\s*}\s*LIBVIRT_QEMU_(\d+\.\d+\.\d+)\s*;\s*$/) {
101 102 103 104 105
        if ($1 ne $prevvers) {
            die "malformed syms file $1 != $vers";
        }
        $prevvers = $vers;
        $vers = undef;
106
    } elsif ($line =~ /\s*(\w+)\s*;\s*$/) {
107
        $apis{$1} = $vers;
108
    } else {
109
        die "unexpected data $line\n";
110 111 112 113 114 115 116 117 118 119 120 121 122 123 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
    }
}

close FILE;


# And the same for the LXC specific APIs

open FILE, "<$symslxc"
    or die "cannot read $symslxc: $!";

$prevvers = undef;
$vers = undef;
while (defined($line = <FILE>)) {
    chomp $line;
    next if $line =~ /^\s*#/;
    next if $line =~ /^\s*$/;
    next if $line =~ /^\s*(global|local):/;
    if ($line =~ /^\s*LIBVIRT_LXC_(\d+\.\d+\.\d+)\s*{\s*$/) {
        if (defined $vers) {
            die "malformed syms file";
        }
        $vers = $1;
    } elsif ($line =~ /\s*}\s*;\s*$/) {
        if (defined $prevvers) {
            die "malformed syms file";
        }
        $prevvers = $vers;
        $vers = undef;
    } elsif ($line =~ /\s*}\s*LIBVIRT_LXC_(\d+\.\d+\.\d+)\s*;\s*$/) {
        if ($1 ne $prevvers) {
            die "malformed syms file $1 != $vers";
        }
        $prevvers = $vers;
        $vers = undef;
    } elsif ($line =~ /\s*(\w+)\s*;\s*$/) {
        $apis{$1} = $vers;
    } else {
        die "unexpected data $line\n";
149 150 151 152 153 154 155 156
    }
}

close FILE;


# Some special things which aren't public APIs,
# but we want to report
157
$apis{virConnectSupportsFeature} = "0.3.2";
158 159 160 161 162 163 164 165 166 167 168 169
$apis{virDomainMigratePrepare} = "0.3.2";
$apis{virDomainMigratePerform} = "0.3.2";
$apis{virDomainMigrateFinish} = "0.3.2";
$apis{virDomainMigratePrepare2} = "0.5.0";
$apis{virDomainMigrateFinish2} = "0.5.0";
$apis{virDomainMigratePrepareTunnel} = "0.7.2";

$apis{virDomainMigrateBegin3} = "0.9.2";
$apis{virDomainMigratePrepare3} = "0.9.2";
$apis{virDomainMigratePrepareTunnel3} = "0.9.2";
$apis{virDomainMigratePerform3} = "0.9.2";
$apis{virDomainMigrateFinish3} = "0.9.2";
170
$apis{virDomainMigrateConfirm3} = "0.9.2";
171 172 173 174 175 176 177 178 179 180 181 182 183 184



# Now we want to get the mapping between public APIs
# and driver struct fields. This lets us later match
# update the driver impls with the public APis.

open FILE, "<$drivertable"
    or die "cannot read $drivertable: $!";

# Group name -> hash of APIs { fields -> api name }
my %groups;
my $ingrp;
while (defined($line = <FILE>)) {
185
    if ($line =~ /struct _(vir\w*Driver)/) {
186 187 188 189 190 191
        my $grp = $1;
        if ($grp ne "virStateDriver" &&
            $grp ne "virStreamDriver") {
            $ingrp = $grp;
            $groups{$ingrp} = { apis => {}, drivers => {} };
        }
192
    } elsif ($ingrp) {
193
        if ($line =~ /^\s*vir(?:Drv)(\w+)\s+(\w+);\s*$/) {
194 195 196 197 198 199 200 201 202 203 204 205 206
            my $field = $2;
            my $name = $1;

            my $api;
            if (exists $apis{"vir$name"}) {
                $api = "vir$name";
            } else {
                die "driver $name does not have a public API";
            }
            $groups{$ingrp}->{apis}->{$field} = $api;
        } elsif ($line =~ /};/) {
            $ingrp = undef;
        }
207 208 209 210 211 212 213 214 215 216 217
    }
}

close FILE;


# Finally, we read all the primary driver files and extract
# the driver API tables from each one.

foreach my $src (@srcs) {
    open FILE, "<$src" or
218
        die "cannot read $src: $!";
219 220 221 222

    $ingrp = undef;
    my $impl;
    while (defined($line = <FILE>)) {
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 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
        if (!$ingrp) {
            foreach my $grp (keys %groups) {
                if ($line =~ /^\s*(?:static\s+)?$grp\s+(\w+)\s*=\s*{/ ||
                    $line =~ /^\s*(?:static\s+)?$grp\s+NAME\(\w+\)\s*=\s*{/) {
                    $ingrp = $grp;
                    $impl = $src;

                    if ($impl =~ m,.*/node_device_(\w+)\.c,) {
                        $impl = $1;
                    } else {
                        $impl =~ s,.*/(\w+?)_((\w+)_)?(\w+)\.c,$1,;
                    }

                    if ($groups{$ingrp}->{drivers}->{$impl}) {
                        die "Group $ingrp already contains $impl";
                    }

                    $groups{$ingrp}->{drivers}->{$impl} = {};
                }
            }

        } else {
            if ($line =~ m!\s*\.(\w+)\s*=\s*(\w+)\s*,?\s*(?:/\*\s*(\d+\.\d+\.\d+)\s*\*/\s*)?$!) {
                my $api = $1;
                my $meth = $2;
                my $vers = $3;

                next if $api eq "no" || $api eq "name";

                die "Method $meth in $src is missing version" unless defined $vers;

                die "Driver method for $api is NULL in $src" if $meth eq "NULL";

                if (!exists($groups{$ingrp}->{apis}->{$api})) {
                    die "Found unexpected method $api in $ingrp\n";
                }

                $groups{$ingrp}->{drivers}->{$impl}->{$api} = $vers;
                if ($api eq "domainMigratePrepare" ||
                    $api eq "domainMigratePrepare2" ||
                    $api eq "domainMigratePrepare3") {
                    $groups{$ingrp}->{drivers}->{$impl}->{"domainMigrate"} = $vers
                        unless $groups{$ingrp}->{drivers}->{$impl}->{"domainMigrate"};
                }

            } elsif ($line =~ /}/) {
                $ingrp = undef;
            }
        }
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
    }

    close FILE;
}


# The '.open' driver method is used for 3 public APIs, so we
# have a bit of manual fixup todo with the per-driver versioning
# and support matrix

$groups{virDriver}->{apis}->{"openAuth"} = "virConnectOpenAuth";
$groups{virDriver}->{apis}->{"openReadOnly"} = "virConnectOpenReadOnly";
$groups{virDriver}->{apis}->{"domainMigrate"} = "virDomainMigrate";

my $openAuthVers = (0 * 1000 * 1000) + (4 * 1000) + 0;

foreach my $drv (keys %{$groups{"virDriver"}->{drivers}}) {
289
    my $openVersStr = $groups{"virDriver"}->{drivers}->{$drv}->{"connectOpen"};
290 291
    my $openVers;
    if ($openVersStr =~ /(\d+)\.(\d+)\.(\d+)/) {
292
        $openVers = ($1 * 1000 * 1000) + ($2 * 1000) + $3;
293 294 295
    }

    # virConnectOpenReadOnly always matches virConnectOpen version
296 297
    $groups{"virDriver"}->{drivers}->{$drv}->{"connectOpenReadOnly"} =
        $groups{"virDriver"}->{drivers}->{$drv}->{"connectOpen"};
298 299 300 301 302

    # virConnectOpenAuth is always 0.4.0 if the driver existed
    # before this time, otherwise it matches the version of
    # the driver's virConnectOpen entry
    if ($openVersStr eq "Y" ||
303
        $openVers >= $openAuthVers) {
304
        $groups{"virDriver"}->{drivers}->{$drv}->{"connectOpenAuth"} = $openVersStr;
305
    } else {
306
        $groups{"virDriver"}->{drivers}->{$drv}->{"connectOpenAuth"} = "0.4.0";
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
    }
}


# Another special case for the virDomainCreateLinux which was replaced
# with virDomainCreateXML
$groups{virDriver}->{apis}->{"domainCreateLinux"} = "virDomainCreateLinux";

my $createAPIVers = (0 * 1000 * 1000) + (0 * 1000) + 3;

foreach my $drv (keys %{$groups{"virDriver"}->{drivers}}) {
    my $createVersStr = $groups{"virDriver"}->{drivers}->{$drv}->{"domainCreateXML"};
    next unless defined $createVersStr;
    my $createVers;
    if ($createVersStr =~ /(\d+)\.(\d+)\.(\d+)/) {
322
        $createVers = ($1 * 1000 * 1000) + ($2 * 1000) + $3;
323 324 325 326 327 328
    }

    # virCreateLinux is always 0.0.3 if the driver existed
    # before this time, otherwise it matches the version of
    # the driver's virCreateXML entry
    if ($createVersStr eq "Y" ||
329 330
        $createVers >= $createAPIVers) {
        $groups{"virDriver"}->{drivers}->{$drv}->{"domainCreateLinux"} = $createVersStr;
331
    } else {
332
        $groups{"virDriver"}->{drivers}->{$drv}->{"domainCreateLinux"} = "0.0.3";
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
    }
}


# Finally we generate the HTML file with the tables

print <<EOF;
<html>
<head>
<title>libvirt API support matrix</title>
</head>
<body>
<h1>libvirt API support matrix</h1>

<ul id="toc"></ul>

<p>
This page documents which <a href="html/">libvirt calls</a> work on
which libvirt drivers / hypervisors, and which version the API appeared
in.
</p>

EOF

foreach my $grp (sort { $a cmp $b } keys %groups) {
    print "<h2><a name=\"$grp\">", $groupheaders{$grp}, "</a></h2>\n";
    print <<EOF;
<table class="top_table">
<thead>
<tr>
<th>API</th>
<th>Version</th>
EOF

    foreach my $drv (sort { $a cmp $b } keys %{$groups{$grp}->{drivers}}) {
368
        print "  <th>$drv</th>\n";
369 370 371 372 373 374 375 376 377 378
    }

    print <<EOF;
</tr>
</thead>
<tbody>
EOF

    my $row = 0;
    foreach my $field (sort {
379 380 381 382 383 384 385
        $groups{$grp}->{apis}->{$a}
        cmp
        $groups{$grp}->{apis}->{$b}
        } keys %{$groups{$grp}->{apis}}) {
        my $api = $groups{$grp}->{apis}->{$field};
        my $vers = $apis{$api};
        print <<EOF;
386 387 388 389 390 391
<tr>
<td><a href=\"html/libvirt-libvirt.html#$api\">$api</a></td>
<td>$vers</td>
EOF

        foreach my $drv (sort {$a cmp $b } keys %{$groups{$grp}->{drivers}}) {
392 393 394 395 396
            if (exists $groups{$grp}->{drivers}->{$drv}->{$field}) {
                print "<td>", $groups{$grp}->{drivers}->{$drv}->{$field}, "</td>\n";
            } else {
                print "<td></td>\n";
            }
397 398
        }

399
        print <<EOF;
400 401 402 403 404 405 406 407 408 409 410 411
</tr>
EOF

        $row++;
        if (($row % 15) == 0) {
            print <<EOF;
<tr>
<th>API</th>
<th>Version</th>
EOF

            foreach my $drv (sort { $a cmp $b } keys %{$groups{$grp}->{drivers}}) {
412
                print "  <th>$drv</th>\n";
413 414 415 416 417
            }

        print <<EOF;
</tr>
EOF
418
        }
419 420 421 422 423 424 425 426 427 428 429 430 431

    }

    print <<EOF;
</tbody>
</table>
EOF
}

print <<EOF;
</body>
</html>
EOF