[pve-devel] [PATCH qemu-server 1/4] add qemu firmware cfg

Alexandre Derumier aderumier at odiso.com
Fri Oct 6 16:49:11 CEST 2017


This add support for qemu_fw_cfg feature, enable it by default for qemu 2.9
(fw_cfg already exist, it's just a new firmware, so it don't break live migration)

the vmid.conf content will be passed to guest vm with

-fw_cfg name=opt/Proxmox,file=/etc/pve/nodes/<nodename>/qemu-server/<vmid>.conf

qemu guest can read content through sysfs:

/sys/firmware/qemu_fw_cfg/by_name/opt/Proxmox/raw
(need qemu_fw_cfg module from kernel 4.6)
---
 PVE/QemuServer.pm | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 2b6fda9..2455e20 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -1759,6 +1759,15 @@ sub print_cpu_device {
     return "$cpu-x86_64-cpu,id=cpu$id,socket-id=$current_socket,core-id=$current_core,thread-id=0";
 }
 
+sub print_firmware_cfg {
+    my ($vmid, $migratedfrom) = @_;
+
+    my $nodename = $migratedfrom ? $migratedfrom : PVE::INotify::nodename();
+    my $path = "/etc/pve/nodes/$nodename/qemu-server/$vmid.conf";
+
+    return "name=opt/Proxmox,file=$path";
+}
+
 sub drive_is_cdrom {
     my ($drive) = @_;
 
@@ -2824,7 +2833,7 @@ sub vga_conf_has_spice {
 }
 
 sub config_to_command {
-    my ($storecfg, $vmid, $conf, $defaults, $forcemachine) = @_;
+    my ($storecfg, $vmid, $conf, $defaults, $forcemachine, $migratedfrom) = @_;
 
     my $cmd = [];
     my $globalFlags = [];
@@ -3332,6 +3341,11 @@ sub config_to_command {
     push @$cmd, '-global', join(',', @$globalFlags)
 	if scalar(@$globalFlags);
 
+    if (qemu_machine_feature_enabled ($machine_type, $kvmver, 2, 9)) {
+	my $fwcfgstr = print_firmware_cfg($vmid, $migratedfrom);
+	push @$cmd, '-fw_cfg', $fwcfgstr;
+    }
+
     return wantarray ? ($cmd, $vollist, $spice_port) : $cmd;
 }
 
@@ -4560,7 +4574,7 @@ sub vm_start {
 	    }
 	}
 
-	my ($cmd, $vollist, $spice_port) = config_to_command($storecfg, $vmid, $conf, $defaults, $forcemachine);
+	my ($cmd, $vollist, $spice_port) = config_to_command($storecfg, $vmid, $conf, $defaults, $forcemachine, $migratedfrom);
 
 	my $migrate_port = 0;
 	my $migrate_uri;
-- 
2.11.0



More information about the pve-devel mailing list