[pve-devel] r5628 - in qemu-server/pve2: . PVE

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Feb 25 11:29:44 CET 2011


Author: dietmar
Date: 2011-02-25 11:29:44 +0100 (Fri, 25 Feb 2011)
New Revision: 5628

Added:
   qemu-server/pve2/pve-bridge
Removed:
   qemu-server/pve2/bridge-vlan
Modified:
   qemu-server/pve2/ChangeLog
   qemu-server/pve2/Makefile
   qemu-server/pve2/PVE/QemuServer.pm
Log:
	* PVE/QemuServer.pm: changed network config systax. We now use
	-net[n] instead of -vlan[n]. This allows us to add more options.



Modified: qemu-server/pve2/ChangeLog
===================================================================
--- qemu-server/pve2/ChangeLog	2011-02-25 10:13:43 UTC (rev 5627)
+++ qemu-server/pve2/ChangeLog	2011-02-25 10:29:44 UTC (rev 5628)
@@ -1,3 +1,8 @@
+2011-02-25  Proxmox Support Team  <support at proxmox.com>
+
+	* PVE/QemuServer.pm: changed network config systax. We now use
+	-net[n] instead of -vlan[n]. This allows us to add more options.
+
 2011-02-11  Proxmox Support Team  <support at proxmox.com>
 
 	* PVE/API2/Qemu.pm: renamed Config.pm to Qemu.pm (whole API inside

Modified: qemu-server/pve2/Makefile
===================================================================
--- qemu-server/pve2/Makefile	2011-02-25 10:13:43 UTC (rev 5627)
+++ qemu-server/pve2/Makefile	2011-02-25 10:29:44 UTC (rev 5628)
@@ -63,7 +63,7 @@
 	install -m 0755 qmrestore ${DESTDIR}${SBINDIR}
 	install -D -m 0755 qmupdate ${DESTDIR}${VARLIBDIR}/qmupdate
 	install -D -m 0755 qemu.init.d ${DESTDIR}/etc/init.d/${PACKAGE}
-	install -m 0755 bridge-vlan ${DESTDIR}${VARLIBDIR}/bridge-vlan
+	install -m 0755 pve-bridge ${DESTDIR}${VARLIBDIR}/pve-bridge
 	install -s -m 0755 vmtar ${DESTDIR}${LIBDIR}
 	install -s -m 0755 sparsecp ${DESTDIR}${LIBDIR}
 #	pod2man -n qemu-server -s 1 -r "proxmox 1.0" -c "Proxmox Documentation" <qemu-server.pod | gzip -9 > ${DESTDIR}/usr/share/man/man1/qemu-server.1.gz

Modified: qemu-server/pve2/PVE/QemuServer.pm
===================================================================
--- qemu-server/pve2/PVE/QemuServer.pm	2011-02-25 10:13:43 UTC (rev 5627)
+++ qemu-server/pve2/PVE/QemuServer.pm	2011-02-25 10:29:44 UTC (rev 5628)
@@ -30,7 +30,7 @@
 
 # Note about locking: we use flock on the config file protect 
 # against concurent actions.
-# Adiitionaly, we have a 'lock' setting in the config file. This
+# Aditionaly, we have a 'lock' setting in the config file. This
 # can be set to 'migrate' or 'backup'. Most actions are not
 # allowed when such lock is set. But you can ignore this kind of
 # lock with the --skiplock flag.
@@ -268,13 +268,6 @@
 	type => 'boolean',
 	description => "Freeze CPU at startup (use 'c' monitor command to start execution).",
     },
-    vlanu => {
-	optional => 1,
-	type => 'string', format => 'pve-qm-vlan',
-	typetext => "MODEL=XX:XX:XX:XX:XX:XX { , MODEL=YY:YY:YY:YY:YY:YY  }",
-	description => "Same as vlan[n], but vlanu uses user mode network stack (NAT).
-Provides DHCP and DNS services. The following addresses are used:\n\n10.0.2.2   Gateway\n10.0.2.3   DNS Server\n10.0.2.4   SMB Server\n\nThe DHCP server assign addresses to the guest starting from 10.0.2.15.",
-    },
     vga => {
 	optional => 1,
 	type => 'string',
@@ -406,29 +399,42 @@
 my $MAX_IDE_DISKS = 4;
 my $MAX_SCSI_DISKS = 16;
 my $MAX_VIRTIO_DISKS = 16;
-my $MAX_VLANS = 4095;
+my $MAX_NETS = 4095;
 my $MAX_UNUSED_DISKS = 8;
 
 my $nic_model_list = ['rtl8139', 'ne2k_pci', 'e1000',  'pcnet',  'virtio',
 		      'ne2k_isa', 'i82551', 'i82557b', 'i82559er'];
 my $nic_model_list_txt = join (' ', sort @$nic_model_list);
 
-my $vlandesc = {
+# fixme:
+my $netdesc = {
     optional => 1,
-    type => 'string', format => 'pve-qm-vlan',
-    typetext => "MODEL=XX:XX:XX:XX:XX:XX { , MODEL=YY:YY:YY:YY:YY:YY }",
+    type => 'string', format => 'pve-qm-net',
+    typetext => "MODEL=XX:XX:XX:XX:XX:XX [,bridge=<dev>]",
     description => <<EODESCR,
-Specify network devices connected to vlan[n]. Currently, vlan[n] is connected to vmbr[n] (n is 0 to 4094).
+Specify network devices. 
 
 MODEL is one of: $nic_model_list_txt
 
-XX:XX:XX:XX:XX:XX should be an unique MAC address
+XX:XX:XX:XX:XX:XX should be an unique MAC address. This is 
+automatically generated if not specified.
+
+The bridge parameter can be used to automatically add the interface to a bridge device. The Proxmox VE standard bridge is called 'vmbr0'.
+
+If you specify no bridge, we create a kvm 'user' (NATed) network device, which provides DHCP and DNS services. The following addresses are used:
+
+10.0.2.2   Gateway
+10.0.2.3   DNS Server
+10.0.2.4   SMB Server
+
+The DHCP server assign addresses to the guest starting from 10.0.2.15.
+
 EODESCR
 };
-PVE::JSONSchema::register_standard_option("pve-qm-vlan", $vlandesc);
+PVE::JSONSchema::register_standard_option("pve-qm-net", $netdesc);
 
-for (my $i = 0; $i < $MAX_VLANS; $i++)  {
-    $confdesc->{"vlan$i"} = $vlandesc;
+for (my $i = 0; $i < $MAX_NETS; $i++)  {
+    $confdesc->{"net$i"} = $netdesc;
 }
 
 my $drivename_hash;
@@ -518,6 +524,8 @@
 
 }
 
+my $kernel_has_vhost_net = -c '/dev/vhost-net';
+
 sub disknames {
     # order is important - used to autoselect boot disk
     return ((map { "ide$_" } (0 .. ($MAX_IDE_DISKS - 1))),  
@@ -842,39 +850,39 @@
 
 }
 
-# vlanX: e1000=XX:XX:XX:XX:XX:XX,pcnet=XX:XX:XX:XX:XX:XX,...
-sub parse_vlan {
+# netX: e1000=XX:XX:XX:XX:XX:XX,bridge=vmbr0,
+sub parse_net {
     my ($data) = @_;
 
     my $res = {};
 
-    foreach my $nic (split (/,/, $data)) {
+    foreach my $kvp (split (/,/, $data)) {
 
-	if ($nic =~ m/^(ne2k_pci|e1000|rtl8139|pcnet|virtio|ne2k_isa|i82551|i82557b|i82559er)(=([0-9a-f]{2}(:[0-9a-f]{2}){5}))?$/i) {
+	if ($kvp =~ m/^(ne2k_pci|e1000|rtl8139|pcnet|virtio|ne2k_isa|i82551|i82557b|i82559er)(=([0-9a-f]{2}(:[0-9a-f]{2}){5}))?$/i) {
 	    my $model = lc ($1);
 	    my $mac = uc($3) || random_ether_addr ();
-	    push @{$res->{nics}}, { model => $model, macaddr => $mac } ;
+	    $res->{model} = $model;
+	    $res->{macaddr} = $mac;
+	} elsif ($kvp =~ m/^bridge=(\S+)$/) {
+	    $res->{bridge} = $1;
 	} else {
 	    return undef;
 	}
 	
     }
 
-    return undef if !$res->{nics};
+    return undef if !$res->{model};
 
     return $res;
 }
 
-sub print_vlan {
-    my $vlan = shift;
+sub print_net {
+    my $net = shift;
 
-    my $res = '';
-    foreach my $nic (@{$vlan->{nics}}) {
-	$res .= ',' if $res;
-	$res .= "$nic->{model}";
-	my $mac =  $nic->{macaddr};
-	$res .= "=$mac" if $mac;
-    }
+    my $res = "$net->{model}";
+    $res .= "=$net->{macaddr}" if $net->{macaddr};
+    $res .= ",bridge=$net->{bridge}" if $net->{bridge};
+
     return $res;
 }
 
@@ -882,10 +890,10 @@
     my ($settings) = @_;
 
     foreach my $opt (keys %$settings) {
-	next if $opt !~ m/^vlan(\d+|u)$/;
-	my $vlan = parse_vlan ($settings->{$opt});
-	next if !$vlan;
-	$settings->{$opt} = print_vlan ($vlan);
+	next if $opt !~ m/^net(\d+)$/;
+	my $net = parse_net($settings->{$opt});
+	next if !$net;
+	$settings->{$opt} = print_net($net);
     }
 }
 
@@ -920,15 +928,15 @@
     die "invalid boot disk '$value'\n";
 }
 
-PVE::JSONSchema::register_format('pve-qm-vlan', \&verify_vlan);
-sub verify_vlan {
+PVE::JSONSchema::register_format('pve-qm-net', \&verify_net);
+sub verify_net {
     my ($value, $noerr) = @_;
 
-    return $value if parse_vlan ($value);
+    return $value if parse_net($value);
 
     return undef if $noerr;
     
-    die "unable to parse vlan\n";
+    die "unable to parse network options\n";
 }
 
 PVE::JSONSchema::register_format('pve-qm-drive', \&verify_drive);
@@ -1860,38 +1868,39 @@
     my $foundnet = 0;
 
     foreach my $k (sort keys %$conf) {
-	next if $k !~ m/^vlan(\d+)$/;
+	next if $k !~ m/^net(\d+)$/;
 	my $i = int ($1);
 
-	die "got strange vlan id '$i'\n" if $i >= ${MAX_VLANS};
+	die "got strange net id '$i'\n" if $i >= ${MAX_NETS};
 
-	if ($conf->{"vlan$i"} && (my $vlan = parse_vlan ($conf->{"vlan$i"}))) {
+	if ($conf->{"net$i"} && (my $net = parse_net($conf->{"net$i"}))) {
 
 	    $foundnet = 1;
 
-	    my $ifname = "vmtab${vmid}i$i";
-	    push @$cmd, '-net', "tap,vlan=$i,ifname=$ifname,script=/var/lib/qemu-server/bridge-vlan";
+	    my $ifname = "tap${vmid}i$i";
 
-	    foreach my $nic (@{$vlan->{nics}}) {
-		$use_virtio = 1 if $nic->{model} eq 'virtio';
-		push @$cmd, '-net', "nic,vlan=$i,model=$nic->{model},macaddr=$nic->{macaddr}";
+	    # kvm uses TUNSETIFF ioctl, and that limits ifname length
+	    die "interface name '$ifname' is too long (max 15 character)\n" 
+		if length($ifname) >= 16;
+
+	    my $device = $net->{model};
+	    my $vhostparam = '';
+	    if ($net->{model} eq 'virtio') {
+		$use_virtio = 1;
+		$device = 'virtio-net-pci';
+		$vhostparam = ',vhost=on' if $kernel_has_vhost_net;
+	    };
+
+	    if ($net->{bridge}) {
+		push @$cmd, '-netdev', "type=tap,id=${k},ifname=${ifname},script=/var/lib/qemu-server/pve-bridge$vhostparam";
+	    } else {
+		push @$cmd, '-netdev', "type=user,id=${k},hostname=$vmname";
 	    }
 
+	    push @$cmd, '-device', "$device,mac=$net->{macaddr},netdev=${k}";
 	}
     } 
-
-    if ($conf->{"vlanu"} && (my $vlan = parse_vlan ($conf->{"vlanu"}))) {
-
-	$foundnet = 1;
-
-	push @$cmd, '-net', "user,vlan=${MAX_VLANS},hostname=$vmname";
-
-	foreach my $nic (@{$vlan->{nics}}) {
-	    $use_virtio = 1 if $nic->{model} eq 'virtio';
-	    push @$cmd, '-net', "nic,vlan=${MAX_VLANS},model=$nic->{model},macaddr=$nic->{macaddr}";
-	}
-    }
-    
+       
     push @$cmd, '-net', 'none' if !$foundnet;
 
     # hack: virtio with fairsched is unreliable, so we do not use fairsched

Deleted: qemu-server/pve2/bridge-vlan
===================================================================
--- qemu-server/pve2/bridge-vlan	2011-02-25 10:13:43 UTC (rev 5627)
+++ qemu-server/pve2/bridge-vlan	2011-02-25 10:29:44 UTC (rev 5628)
@@ -1,22 +0,0 @@
-#!/usr/bin/perl -w
-
-use strict;
-
-my $iface = shift;
-
-die "no interface specified\n" if !$iface;
-
-die "got strange interface name '$iface'\n" 
-    if $iface !~ m/^vmtab(\d+)i(\d+)$/;
-
-my $vmid = $1;
-my $vlan = $2;
-
-my $bridge = "vmbr$vlan";
-
-system ("/sbin/ifconfig $iface 0.0.0.0 promisc up") == 0 ||
-    die "interface activation failed\n";
-system ("/usr/sbin/brctl addif $bridge $iface") == 0 ||
-    die "can't add interface to bridge\n";
-
-exit 0;

Added: qemu-server/pve2/pve-bridge
===================================================================
--- qemu-server/pve2/pve-bridge	                        (rev 0)
+++ qemu-server/pve2/pve-bridge	2011-02-25 10:29:44 UTC (rev 5628)
@@ -0,0 +1,32 @@
+#!/usr/bin/perl -w
+
+use strict;
+use PVE::QemuServer;
+
+my $iface = shift;
+
+die "no interface specified\n" if !$iface;
+
+die "got strange interface name '$iface'\n" 
+    if $iface !~ m/^tap(\d+)i(\d+)$/;
+
+my $vmid = $1;
+my $netid = "net$2";
+
+my $conf = PVE::QemuServer::load_config ($vmid);
+
+die "unable to get network config '$netid'\n"
+    if !$conf->{$netid};
+
+my $net = PVE::QemuServer::parse_net($conf->{$netid});
+die "unable to parse network config '$netid'\n" if !$net;
+
+my $bridge = $net->{bridge};
+die "unable to get bridge setting\n" if !$bridge;
+
+system ("/sbin/ifconfig $iface 0.0.0.0 promisc up") == 0 ||
+    die "interface activation failed\n";
+system ("/usr/sbin/brctl addif $bridge $iface") == 0 ||
+    die "can't add interface to bridge\n";
+
+exit 0;


Property changes on: qemu-server/pve2/pve-bridge
___________________________________________________________________
Added: svn:executable
   + *




More information about the pve-devel mailing list