pf-tools commit: r738 [parmelan-guest] - in /branches/0.33-stable: debian/changelog lib/PFTools/Net.pm tools/kvmlaunch
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Mon Apr 26 13:00:48 UTC 2010
Author: parmelan-guest
Date: Mon Apr 26 13:00:41 2010
New Revision: 738
URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=738
Log:
- force serial console when running in a KVM or QEMU virtual host.
* tools/kvmlaunch:
- correctly handle bonding / slaves / eth remapping.
Modified:
branches/0.33-stable/debian/changelog
branches/0.33-stable/lib/PFTools/Net.pm
branches/0.33-stable/tools/kvmlaunch
Modified: branches/0.33-stable/debian/changelog
URL: http://svn.debian.org/wsvn/pf-tools/branches/0.33-stable/debian/changelog?rev=738&op=diff
==============================================================================
--- branches/0.33-stable/debian/changelog (original)
+++ branches/0.33-stable/debian/changelog Mon Apr 26 13:00:41 2010
@@ -13,8 +13,11 @@
- detect if we are running in a KVM or QEMU virtual host.
- when remapping interfaces, do not reuse bonding slaves.
- uncomment the Warn for duplicated network definitions.
-
- -- Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org> Wed, 21 Apr 2010 17:27:26 +0200
+ - force serial console when running in a KVM or QEMU virtual host.
+ * tools/kvmlaunch:
+ - correctly handle bonding / slaves / eth remapping.
+
+ -- Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org> Mon, 26 Apr 2010 14:59:08 +0200
pf-tools (0.33.19-1) unstable; urgency=low
Modified: branches/0.33-stable/lib/PFTools/Net.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/0.33-stable/lib/PFTools/Net.pm?rev=738&op=diff
==============================================================================
--- branches/0.33-stable/lib/PFTools/Net.pm (original)
+++ branches/0.33-stable/lib/PFTools/Net.pm Mon Apr 26 13:00:41 2010
@@ -669,6 +669,14 @@
if ( !defined($M) ) {
return undef;
+ }
+
+ if ($PFTOOLS_VARS->{'QEMU'}) {
+ # Prepend the serial console configuration (unless there already is
+ # one) in order to use kvm's 'monitor' mode instead of the 'curses'
+ # mode (this mode has, let's say, an "interesting" keymap).
+ $M->{'cmdline'} =~ s{\A}{console=ttyS0,115200n8 }xms
+ unless $M->{'cmdline'} =~ m{console=ttyS};
}
return ( $M->{'cmdline'} );
Modified: branches/0.33-stable/tools/kvmlaunch
URL: http://svn.debian.org/wsvn/pf-tools/branches/0.33-stable/tools/kvmlaunch?rev=738&op=diff
==============================================================================
--- branches/0.33-stable/tools/kvmlaunch (original)
+++ branches/0.33-stable/tools/kvmlaunch Mon Apr 26 13:00:41 2010
@@ -41,7 +41,12 @@
use PFTools::Net;
use PFTools::Update;
-#$PFTools::Conf::PFTOOLS_VARS->{'UML'} = 1;
+# Trash VLAN, for all "fake" interfaces
+my $TRASH_VLAN_ID = 4242;
+
+# Remap interfaces, it just works
+# (as opposed to 802.1Q on the QEMU/KVM tap interfaces)
+$PFTools::Conf::PFTOOLS_VARS->{'UML'} = 1;
#if ( `which vconfig 2>/dev/null` eq ""
# || `which brctl 2>/dev/null` eq ""
@@ -155,7 +160,7 @@
}
my $vm_disk_file = "$vm_dir/$vm_hostname.qcow";
- unless (-f $vm_disk_file) {
+ if ($option->{'mode'} eq 'boot' and not -f $vm_disk_file) {
warn "INFO: no disk file, forcing install mode\n"
if $option->{'verbose'};
@@ -163,6 +168,7 @@
}
my @interfaces = __get_list_of_interfaces($Z, $vm_hostname);
+
my @net_args =
map { ('-net', $_) }
map { (
@@ -208,8 +214,8 @@
# url/checksum=%PRESEED_MD5% -- %CONSOLE% %CMDLINE%
# FIXME: 'amd64' hardcoded
- my $kernel = '/distrib/tftpboot/debian-installer/amd64/linux';
- my $initrd = '/distrib/tftpboot/debian-installer/amd64/initrd.gz';
+ my $kernel = '/distrib/tftpboot/debian-installer/lenny/amd64.20090123lenny6/linux';
+ my $initrd = '/distrib/tftpboot/debian-installer/lenny/amd64.20090123lenny6/initrd.gz';
# FIXME: this is a dirty hack to get the cmdline from the PXE config file.
my $vm_ip_in_hex = __get_host_ip_in_hex($Z, $vm_hostname);
@@ -332,17 +338,30 @@
my ($dhcpif, $dhcp_address) = Get_Dhcp_Infos( $Z, $host );
- my @interfaces = ();
-# #UMRemap_If( $Z, $host );
- my $umif = Get_UM_If( $Z, $host ); # FIXME Get_KVM_If ?
+ my $interfaces = {};
+ my $umif = Get_UM_If( $Z, $host );
my $hostclass = Host_class($host, $Z);
my $N = $Z->{'SERVERS'}->{'BY_NAME'}->{$hostclass};
my $M = $N->{'SRVLIST'}->{$host};
+ my $last_eth_used = -1;
+ my %eth;
+
+# my @tagged_vlans = ();
foreach my $ifname ( sort { cmpif( $a, $b ) } keys %{$umif} ) {
my $tag = $umif->{$ifname};
next unless defined $tag;
+
+# if ($ifname =~ m{\A (\D+\d+)\.(\d+) \z}xms) {
+# my ($real_ifname, $vlan_tag) = ($1, $2);
+# warn "DEBUG: iface $real_ifname 802.1Q VLAN tag $tag\n" if $option->{'debug'};
+# push @tagged_vlans, {
+# ifname => $real_ifname,
+# tag => $vlan_tag,
+# };
+# next;
+# }
my $slave_ifname;
if ($M->{'bonding'}->{$ifname}) {
@@ -350,11 +369,19 @@
if $option->{'debug'};
# Only use the first slave interface for kvm
# (this avoids having to compute non-conflicting MAC adresses for the other slaves)
- $slave_ifname = ${ $M->{'bonding'}->{$ifname} }[0];
+ $slave_ifname = shift @{ $M->{'bonding'}->{$ifname} };
+ # Register the other slaves (they will be faked later on)
+ foreach my $other_slave_ifname (@{ $M->{'bonding'}->{$ifname} }) {
+ $last_eth_used = __update_last_eth_used($last_eth_used, $other_slave_ifname);
+ }
}
- my $virtual_ifname = __get_virtual_ifname($host, $slave_ifname ? $slave_ifname : $ifname);
+ my $unmangled_ifname = $slave_ifname ? $slave_ifname : $ifname;
+ my $virtual_ifname = __get_virtual_ifname($host, $unmangled_ifname);
my $ip_address = __get_iface_ip($Z, $host, $ifname);
+
+ $last_eth_used = __update_last_eth_used($last_eth_used, $unmangled_ifname);
+ $eth{$unmangled_ifname} = 1;
warn "DEBUG: iface $ifname <-> tag $tag <-> vif $virtual_ifname <-> IP $ip_address",
($slave_ifname ? " (slave $slave_ifname)" : ''),
@@ -380,19 +407,58 @@
$mac_address = join ':', @mac_address;
}
- push @interfaces, {
+ $interfaces->{$unmangled_ifname} = {
bridge => $bridge_name,
ifname => $virtual_ifname,
+ #unmangled_ifname => $ifname,
+ unmangled_ifname => $unmangled_ifname,
ip => $ip_address,
mac => $mac_address,
vlan => $tag,
};
}
- # sort the interfaces again, because of the game we played with bond interfaces
+# # Fill the tagged vlans information
+# foreach my $vlan (@tagged_vlans) {
+# my $ifname = $vlan->{'ifname'};
+# my $tag = $vlan->{'tag' };
+#
+# push @{ $interfaces->{$ifname}->{'vlans'} }, $tag;
+# }
+
+ # Fill the holes if needed to keep the correct ethX naming in the VM
+ foreach my $i (0 .. $last_eth_used) {
+ my $ifname = "eth$i";
+ next if $eth{$ifname};
+ warn "DEBUG: Faking $ifname\n" if $option->{'debug'};
+ $interfaces->{$ifname} = {
+ bridge => 'brtrash',
+ ifname => __get_virtual_ifname($host, $ifname),
+ unmangled_ifname => $ifname,
+ ip => 0,
+ mac => '00:00:00:00:00:00',
+ vlan => $TRASH_VLAN_ID,
+ };
+ }
+
+ # sort the interfaces and return them as a list
return
- sort { __cmpif_kvm( $a->{'ifname'}, $b->{'ifname'} ) }
- @interfaces;
+ sort { __cmpif_kvm( $a->{'unmangled_ifname'}, $b->{'unmangled_ifname'} ) }
+ values %{$interfaces};
+}
+
+
+sub __update_last_eth_used {
+ my ($last_eth_used, $ifname) = @_;
+
+ if ( $ifname =~ m/^([^:.\d]+)(\d+)$/ ) {
+ my ($iftype, $ifnumber) = ($1, $2);
+ if ($iftype eq 'eth' and $last_eth_used < $ifnumber) {
+ $last_eth_used = $ifnumber;
+ }
+ }
+
+ return $last_eth_used;
}
@@ -408,20 +474,22 @@
# truncated to "abv1-ncdn-varni"!
#
# It is therefore necessary to discriminate these interfaces... a simple
-# solution is to use a digest function. We use the prefix "m-" (for "mangled")
-# and the hexadecimal representation of the CRC32 digest of the hostname. That
-# gives us short enough names, such as "m-8f6aac88.0" and "m-8f6aac88.1"
-# instead of "abv1-ncdn-varnish00.0" and "abv1-ncdn-varnish00.1".
+# solution is to use a digest function. We use the prefix "m" (for "mangled")
+# and the hexadecimal representation of the CRC32 digest of the hostname. The
+# dot also is suppressed. That gives us short enough names, such as
+# "m8f6aac880" and "m8f6aac881" instead of "abv1-ncdn-varnish00.0" and
+# "abv1-ncdn-varnish00.1".
#
sub __get_virtual_ifname { my ($host, $ifname) = @_;
my $IFNAMESIZ = 16; # <linux/if.h>
- my $MAX_HOSTNAME_SIZE = $IFNAMESIZ - 3; # '.' + digit + NULL
+# my $MAX_HOSTNAME_SIZE = $IFNAMESIZ - 3; # '.' + digit + NULL
my ($iface_number) = $ifname =~ m{\A \D+ (\d+) \z}xms;
- my $mangled_hostname = length($host) > $MAX_HOSTNAME_SIZE ? "m-" . crc32_hex($host) : $host;
-
- my $virtual_ifname = "$mangled_hostname.$iface_number";
+# my $mangled_hostname = length($host) > $MAX_HOSTNAME_SIZE ? "m-" . crc32_hex($host) : $host;
+# my $virtual_ifname = "$mangled_hostname.$iface_number";
+
+ my $virtual_ifname = "m" . crc32_hex($host) . $iface_number;
return $virtual_ifname;
}
@@ -435,6 +503,14 @@
# add it to the bridge hosting the corresponding VLAN
__brctl_addif($option, $iface->{'vlan'}, $iface->{'ifname'});
+
+# if ($iface->{'vlans'}) {
+# # add 802.1Q VLAN tags to the TUN/TAP device
+# foreach my $vlan (@{ $iface->{'vlans'} }) {
+# __vconfig_add($option, $iface->{'ifname'}, $vlan);
+# __brctl_addif($option, $vlan, "$iface->{'ifname'}.$vlan");
+# }
+# }
}
}
@@ -442,6 +518,13 @@
my ($option, @interfaces) = @_;
foreach my $iface (@interfaces) {
+# if ($iface->{'vlans'}) {
+# # add 802.1Q VLAN tags to the TUN/TAP device
+# foreach my $vlan (@{ $iface->{'vlans'} }) {
+# __brctl_delif($option, $vlan, "$iface->{'ifname'}.$vlan");
+# __vconfig_rem($option, $iface->{'ifname'}, $vlan);
+# }
+# }
__brctl_delif($option, $iface->{'vlan'}, $iface->{'ifname'});
__delete_tun_device($option, $iface->{'ifname'});
}
@@ -472,6 +555,8 @@
my $brname = "br$vlan_tag";
+ return if $vlan_tag == $TRASH_VLAN_ID;
+
warn "INFO: adding tun device $ifname to bridge $brname\n"
if $option->{'verbose'};
@@ -484,12 +569,36 @@
my $brname = "br$vlan_tag";
+ return if $vlan_tag == $TRASH_VLAN_ID;
+
warn "INFO: removing tun device $ifname from bridge $brname\n"
if $option->{'verbose'};
my $cmd = "brctl delif $brname $ifname";
__system_or_carp($cmd);
}
+
+#sub __vconfig_add {
+# my ($option, $iface, $vlan_tag) = @_;
+#
+# warn "INFO: adding 802.1Q VLAN ID $vlan_tag to interface $iface\n"
+# if $option->{'verbose'};
+#
+# my $cmd = "vconfig add $iface $vlan_tag";
+# __system_or_carp($cmd);
+# $cmd = "ip link set $iface.$vlan_tag up";
+# __system_or_carp($cmd);
+#}
+#
+#sub __vconfig_rem {
+# my ($option, $iface, $vlan_tag) = @_;
+#
+# warn "INFO: removing 802.1Q VLAN ID $vlan_tag from interface $iface\n"
+# if $option->{'verbose'};
+#
+# my $cmd = "vconfig rem $iface.$vlan_tag";
+# __system_or_carp($cmd);
+#}
sub __system_or_croak {
my @cmd = @_;
More information about the pf-tools-commits
mailing list