From bae179aa1cbaded3013d2b65cc2cd713241a6d5e Mon Sep 17 00:00:00 2001 From: Derumier Alexandre Date: Sun, 11 Sep 2011 09:00:00 +0200 Subject: [PATCH] serial : new qemu syntax V2 Signed-off-by: Derumier Alexandre --- PVE/QemuServer.pm | 71 +++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 5f995e9f..e6a34446 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -287,18 +287,6 @@ EODESC typetext => '[[model=]i6300esb|ib700] [,[action=]reset|shutdown|poweroff|pause|debug|none]', description => "Create a virtual hardware watchdog device. Once enabled (by a guest action), the watchdog must be periodically polled by an agent inside the guest or else the guest will be restarted (or execute the action specified)", }, - serial => { - optional => 1, - type => 'string', format => 'pve-qm-serial', - typetext => "SERIALDEVICE { , SERIALDEVICE }", - description => < { optional => 1, type => 'string', format => 'pve-qm-parallel', @@ -391,6 +379,7 @@ my $MAX_USB_DEVICES = 5; my $MAX_NETS = 6; my $MAX_UNUSED_DISKS = 8; my $MAX_HOSTPCI_DEVICES = 2; +my $MAX_SERIAL_PORTS = 4; my $nic_model_list = ['rtl8139', 'ne2k_pci', 'e1000', 'pcnet', 'virtio', 'ne2k_isa', 'i82551', 'i82557b', 'i82559er']; @@ -492,6 +481,24 @@ EODESCR }; PVE::JSONSchema::register_standard_option("pve-qm-hostpci", $hostpcidesc); +my $serialdesc = { + optional => 1, + type => 'string', format => 'pve-qm-serial', + typetext => "SERIALDEVICE", + description => <{"serial$i"} = $serialdesc; +} + for (my $i = 0; $i < $MAX_HOSTPCI_DEVICES; $i++) { $confdesc->{"hostpci$i"} = $hostpcidesc; } @@ -1146,14 +1153,27 @@ PVE::JSONSchema::register_format('pve-qm-serial', \&verify_serial); sub verify_serial { my ($value, $noerr) = @_; - my @dl = split (/,/, $value); - foreach my $v (@dl) { - if ($v !~ m|^/dev/ttyS\d+$|) { - return undef if $noerr; - die "invalid device name\n"; - } + return $value if parse_serial($value); + + return undef if $noerr; + + die "invalid device name\n"; + +} + +sub parse_serial { + my ($value) = @_; + + return undef if !$value; + + my $res = {}; + if ($value =~ m|^/dev/ttyS\d+$|) { + $res->{dev} = $value; + } else { + return undef; } - return $value; + + return $res; } # add JSON properties for create and set function @@ -2013,14 +2033,11 @@ sub config_to_command { } # serial devices - if (my $serdl = $conf->{serial}) { - my @dl = split (/,/, $serdl); - foreach my $dev (@dl) { - next if !$dev; - if (-c $dev) { - push @$cmd, '-serial', "$dev"; - } - } + for (my $i = 0; $i < $MAX_SERIAL_PORTS; $i++) { + my $d = parse_serial($conf->{"serial$i"}); + next if !$d; + push @$cmd, '-chardev', "tty,id=serial$i,path=$d->{dev}"; + push @$cmd, '-device', "isa-serial,chardev=serial$i"; } # parallel devices