]>
git.proxmox.com Git - qemu-server.git/blob - PVE/QemuServer/Helpers.pm
1 package PVE
::QemuServer
::Helpers
;
17 my $nodename = PVE
::INotify
::nodename
();
19 # Paths and directories
21 our $var_run_tmpdir = "/var/run/qemu-server";
22 mkdir $var_run_tmpdir;
25 my ($vmid, $qga) = @_;
26 my $sockettype = $qga ?
'qga' : 'qmp';
27 return "${var_run_tmpdir}/$vmid.$sockettype";
32 return "${var_run_tmpdir}/$vmid.pid";
37 return "${var_run_tmpdir}/$vmid.vnc";
40 # Parse the cmdline of a running kvm/qemu process and return arguments as hash
44 my $fh = IO
::File-
>new("/proc/$pid/cmdline", "r");
48 return undef if !$line;
49 my @param = split(/\0/, $line);
52 return if !$cmd || ($cmd !~ m
|kvm
$| && $cmd !~ m
@(?
:^|/)qemu-system-[^/]+$@);
56 for (my $i = 0; $i < scalar (@param); $i++) {
60 if ($p =~ m/^--?(.*)$/) {
62 $phash->{$pending_cmd} = {};
65 } elsif ($pending_cmd) {
66 $phash->{$pending_cmd} = { value
=> $p };
76 sub vm_running_locally
{
79 my $pidfile = pidfile_name
($vmid);
81 if (my $fd = IO
::File-
>new("<$pidfile")) {
86 my $mtime = $st->mtime;
87 if ($mtime > time()) {
88 warn "file '$pidfile' modified in future\n";
91 if ($line =~ m/^(\d+)$/) {
93 my $cmdline = parse_cmdline
($pid);
94 if ($cmdline && defined($cmdline->{pidfile
}) && $cmdline->{pidfile
}->{value
}
95 && $cmdline->{pidfile
}->{value
} eq $pidfile) {
96 if (my $pinfo = PVE
::ProcFSTools
::check_process_running
($pid)) {
107 my ($verstr, $major, $minor, $pve) = @_;
109 if ($verstr =~ m/^(\d+)\.(\d+)(?:\.(\d+))?(?:\+pve(\d+))?/) {
110 return 1 if version_cmp
($1, $major, $2, $minor, $4, $pve) >= 0;
114 die "internal error: cannot check version of invalid string '$verstr'";
117 # gets in pairs the versions you want to compares, i.e.:
118 # ($a-major, $b-major, $a-minor, $b-minor, $a-extra, $b-extra, ...)
119 # returns 0 if same, -1 if $a is older than $b, +1 if $a is newer than $b
123 my $size = scalar(@versions);
125 return 0 if $size == 0;
128 my (undef, $fn, $line) = caller(0);
129 die "cannot compare odd count of versions, called from $fn:$line\n";
132 for (my $i = 0; $i < $size; $i += 2) {
133 my ($a, $b) = splice(@versions, 0, 2);
138 return -1 if $a < $b;
143 sub config_aware_timeout
{
144 my ($config, $is_suspended) = @_;
145 my $memory = $config->{memory
};
148 # Based on user reported startup time for vm with 512GiB @ 4-5 minutes
149 if (defined($memory) && $memory > 30720) {
150 $timeout = int($memory/1024);
153 if ($is_suspended && $timeout < 300) {
157 if ($config->{hugepages
} && $timeout < 150) {