[pve-devel] r6573 - qemu-server/trunk

svn-commits at proxmox.com svn-commits at proxmox.com
Tue Dec 6 08:22:28 CET 2011


Author: dietmar
Date: 2011-12-06 08:22:28 +0100 (Tue, 06 Dec 2011)
New Revision: 6573

Modified:
   qemu-server/trunk/Makefile
   qemu-server/trunk/QemuServer.pm
   qemu-server/trunk/changelog.Debian
Log:
use device syntax and set bootindex property


Modified: qemu-server/trunk/Makefile
===================================================================
--- qemu-server/trunk/Makefile	2011-12-05 09:47:30 UTC (rev 6572)
+++ qemu-server/trunk/Makefile	2011-12-06 07:22:28 UTC (rev 6573)
@@ -1,4 +1,4 @@
-RELEASE=1.8
+RELEASE=1.9
 
 VERSION=1.1
 PACKAGE=qemu-server

Modified: qemu-server/trunk/QemuServer.pm
===================================================================
--- qemu-server/trunk/QemuServer.pm	2011-12-05 09:47:30 UTC (rev 6572)
+++ qemu-server/trunk/QemuServer.pm	2011-12-06 07:22:28 UTC (rev 6573)
@@ -569,11 +569,38 @@
     return "$drive->{file}$opts";
 }
 
+sub print_drivedevice_full {
+    my ($self, $vmid, $drive) = @_;
+
+    my $device = '';
+
+    if ($drive->{interface} eq 'virtio') {
+	$device = "virtio-blk-pci,drive=drive-$drive->{interface}$drive->{index},id=$drive->{interface}$drive->{index}";
+    } elsif ($drive->{interface} eq 'scsi') {
+	my $maxdev = 7;
+	my $controller = int($drive->{index} / $maxdev);
+	my $unit = $drive->{index} % $maxdev;
+	$device = "scsi-disk,bus=scsi$controller.0,scsi-id=$unit,drive=drive-$drive->{interface}$drive->{index},id=device-$drive->{interface}$drive->{index}";
+    } elsif ($drive->{interface} eq 'ide'){
+	my $maxdev = 2;
+	my $controller = int($drive->{index} / $maxdev);
+	my $unit = $drive->{index} % $maxdev;
+	$device = "ide-drive,bus=ide.$controller,unit=$unit,drive=drive-$drive->{interface}$drive->{index},id=device-$drive->{interface}$drive->{index}";
+    } else {
+	die "unknown drive type";
+    }
+
+    $device .= ",bootindex=$drive->{bootindex}" if $drive->{bootindex};
+
+    return $device;
+}
+
 sub print_drive_full {
     my ($self, $vmid, $drive) = @_;
 
     my $opts = '';
     foreach my $o (@qemu_drive_options) {
+	next if $o eq 'bootindex';
 	$opts .= ",$o=$drive->{$o}" if $drive->{$o};
     }
  
@@ -594,7 +621,7 @@
 
     my $pathinfo = $path ? "file=$path," : '';
 
-    return "${pathinfo}if=$drive->{interface},index=$drive->{index}$opts";
+    return "${pathinfo}if=none,id=drive-$drive->{interface}$drive->{index}$opts";
 }
 
 
@@ -1247,6 +1274,8 @@
 	die "unable to parse kvm version '$kvmver'\n";
     }
 
+    die "kvm version is too old\n" if $vernum < 15000;
+
     my $have_ovz = -f '/proc/vz/vestat';
 
     push @$cmd, '/usr/bin/kvm';
@@ -1274,11 +1303,7 @@
 	my @dl = split (/,/, $pcidl);
 	foreach my $dev (@dl) {
 	    next if !$dev;
-	    if ($vernum < 13000) {
-		push @$cmd, '-pcidevice', "host=$dev";
-	    } else {
-		push @$cmd, '-device', "pci-assign,host=$dev";
-	    }
+	    push @$cmd, '-device', "pci-assign,host=$dev";
 	}
     }
     # host usb devices
@@ -1323,24 +1348,26 @@
 
     my $boot_opt;
 
-    if ($vernum < 11000) { # 0.9.X and 0.10.X
+    push @$cmd, '-smp', "sockets=$sockets,cores=$cores";
 
-	push @$cmd, '-smp', $sockets*$cores;
+    my $bootindex_hash = {
+	c => 1,
+	a => 2,
+	d => 3,
+    };
 
-	$boot_opt = $conf->{boot};
-    } else {
+    $boot_opt = "menu=on";
+    if ($conf->{boot}) {
+	$bootindex_hash = {};
+	my $i = 1;
+	foreach my $o (split(//, $conf->{boot})) {
+	    $bootindex_hash->{$o} = $i;
+	    $i++;
+	} 
+    }
 
-	push @$cmd, '-smp', "sockets=$sockets,cores=$cores";
+    push @$cmd, '-nodefaults';
 
-	$boot_opt = "menu=on";
-	if ($conf->{boot}) {
-	    $boot_opt .= ",order=$conf->{boot}";
-	}
-
-	push @$cmd, '-nodefaults' if $vernum >= 12003;
-
-    }
-
     push @$cmd, '-boot', $boot_opt if $boot_opt;
 
     push @$cmd, '-no-acpi' if defined ($conf->{acpi}) && $conf->{acpi} == 0;
@@ -1391,13 +1418,25 @@
     #push @$cmd, '-soundhw', 'es1370';
     #push @$cmd, '-soundhw', $soundhw if $soundhw;
 
+    my $scsicontroller = {};
     my $di = $conf->{diskinfo};
     foreach my $ds (sort keys %$di) {
+	my $drive = $di->{$ds};
 	$use_virtio = 1 if $ds =~ m/^virtio/;
-	my $drive = $self->print_drive_full ($vmid, $di->{$ds});
-	$drive .= ",bootindex=1" if $conf->{bootdisk} && ($conf->{bootdisk} eq $ds);
-	push @$cmd, '-drive', $drive;
-    }
+	if (drive_is_cdrom ($drive)) {
+	    $drive->{bootindex} = $bootindex_hash->{d};
+	} else {
+	    $drive->{bootindex} = $bootindex_hash->{c} if $conf->{bootdisk} && ($conf->{bootdisk} eq $ds);
+	}
+        if ($drive->{interface} eq 'scsi') {
+           my $maxdev = 7;
+           my $controller = int($drive->{index} / $maxdev);
+	   push @$cmd, '-device', "lsi,id=scsi$controller" if !$scsicontroller->{$controller};
+           $scsicontroller->{$controller}=1;
+        }
+	push @$cmd, '-drive', $self->print_drive_full ($vmid, $di->{$ds});
+	push @$cmd, '-device', $self->print_drivedevice_full ($vmid, $di->{$ds});
+   }
 
     if ($conf->{memory}) {
 	push @$cmd, '-m', $conf->{memory};
@@ -1405,8 +1444,39 @@
 	push @$cmd, '-m', $defaults->{memory} || $default_memory;
     }
 
+
     my $foundnet = 0;
 
+    my $create_network_device = sub {
+	my ($type, $nic, $id, $ifname) = @_;
+
+	$foundnet = 1;
+
+	my $device = $nic->{model};
+	my $vhostparam = '';
+	if ($nic->{model} eq 'virtio') {
+	    $use_virtio = 1;
+	    $device = 'virtio-net-pci';
+	    $vhostparam = ',vhost=on' if $kernel_has_vhost_net;
+	};
+
+	if ($type eq 'tap') {
+	    push @$cmd, '-netdev', "type=tap,id=${id},ifname=${ifname},script=/var/lib/qemu-server/bridge-vlan$vhostparam";
+	} else {
+	    push @$cmd, '-netdev', "type=user,id=${id},hostname=$vmname";
+	}
+
+	# qemu 0.15 always try to boot from network - we disable that by
+	# not loading the pxe rom file
+	my $extra = ((!$conf->{boot} || ($conf->{boot} !~ m/n/))) ?
+	    "romfile=," : '';
+	my $tmpstr =  "$device,${extra}mac=$nic->{macaddr},netdev=${id}";
+	my $bootindex = $bootindex_hash->{n};
+	$tmpstr .= ",bootindex=$bootindex" if $bootindex;
+	push @$cmd, '-device', $tmpstr;
+    };
+
+
     foreach my $k (sort keys %$conf) {
 	next if $k !~ m/^vlan(\d+)$/;
 	my $i = int ($1);
@@ -1414,56 +1484,25 @@
 	die "got strange vlan id '$i'\n" if $i >= ${MAX_VLANS};
 
 	if ($conf->{"vlan$i"} && (my $vlan = parse_vlan ($conf->{"vlan$i"}))) {
-
-	    $foundnet = 1;
-
 	    my $baseifname = "tap${vmid}i$i";
-
-	    if ($vernum < 13000) {
-		push @$cmd, '-net', "tap,vlan=$i,ifname=$baseifname,script=/var/lib/qemu-server/bridge-vlan";
-	    }
-
 	    my $j = 0;
 	    foreach my $nic (@{$vlan->{nics}}) {
 		my $ifname = $baseifname;
-		my $device = $nic->{model};
-		my $vhostparam = '';
-		if ($nic->{model} eq 'virtio') {
-		    $use_virtio = 1;
-		    $device = 'virtio-net-pci';
-		    $vhostparam = ',vhost=on' if $kernel_has_vhost_net;
-		};
-		if ($vernum < 13000) {
-		    push @$cmd, '-net', "nic,vlan=$i,model=$nic->{model},macaddr=$nic->{macaddr}";
-		} else {
-		    $ifname = "${ifname}d$j";
-		    push @$cmd, '-netdev', "type=tap,id=${k}d$j,ifname=${ifname},script=/var/lib/qemu-server/bridge-vlan$vhostparam";
-		    # qemu 0.15 always try to boot from network - we disable that by
-		    # not loading the pxe rom file
-		    my $extra = (($vernum >= 15000) && (!$conf->{boot} || ($conf->{boot} !~ m/n/))) ?
-			"romfile=," : '';
-		    push @$cmd, '-device', "$device,${extra}mac=$nic->{macaddr},netdev=${k}d$j";
-		}
-
+		$ifname = "${ifname}d$j";
 		# kvm uses TUNSETIFF ioctl, and that limits ifname length
 		die "interface name '$ifname' is too long (max 15 character)\n" 
 		    if length($ifname) >= 16;
-
+		&$create_network_device('tap', $nic, "${k}d$j", $ifname);
 		$j = $j + 1;
 	    }
-
 	}
     } 
 
     if ($conf->{"vlanu"} && (my $vlan = parse_vlan ($conf->{"vlanu"}))) {
-
-	$foundnet = 1;
-
-	push @$cmd, '-net', "user,vlan=${MAX_VLANS},hostname=$vmname";
-
+	my $j = 0;
 	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}";
+	    &$create_network_device('user', $nic, "vlanu$j");
+	    $j = $j + 1;
 	}
     }
     

Modified: qemu-server/trunk/changelog.Debian
===================================================================
--- qemu-server/trunk/changelog.Debian	2011-12-05 09:47:30 UTC (rev 6572)
+++ qemu-server/trunk/changelog.Debian	2011-12-06 07:22:28 UTC (rev 6573)
@@ -1,6 +1,10 @@
 qemu-server (1.1-33) unstable; urgency=low
 
   * fixes for qemu-kvm 1.0
+  
+  * use new device syntax for all net/block devices
+  
+  * set bootindex property
 
  -- Proxmox Support Team <support at proxmox.com>  Mon, 05 Dec 2011 10:46:16 +0100
 




More information about the pve-devel mailing list