]>
git.proxmox.com Git - qemu-server.git/blob - PVE/QemuServer/Helpers.pm
1 package PVE
::QemuServer
::Helpers
;
16 my $nodename = PVE
::INotify
::nodename
();
18 # Paths and directories
20 our $var_run_tmpdir = "/var/run/qemu-server";
21 mkdir $var_run_tmpdir;
24 my ($vmid, $qga) = @_;
25 my $sockettype = $qga ?
'qga' : 'qmp';
26 return "${var_run_tmpdir}/$vmid.$sockettype";
31 return "${var_run_tmpdir}/$vmid.pid";
36 return "${var_run_tmpdir}/$vmid.vnc";
39 # Parse the cmdline of a running kvm/qemu process and return arguments as hash
43 my $fh = IO
::File-
>new("/proc/$pid/cmdline", "r");
47 return undef if !$line;
48 my @param = split(/\0/, $line);
51 return if !$cmd || ($cmd !~ m
|kvm
$| && $cmd !~ m
@(?
:^|/)qemu-system-[^/]+$@);
55 for (my $i = 0; $i < scalar (@param); $i++) {
59 if ($p =~ m/^--?(.*)$/) {
61 $phash->{$pending_cmd} = {};
64 } elsif ($pending_cmd) {
65 $phash->{$pending_cmd} = { value
=> $p };
75 sub vm_running_locally
{
78 my $pidfile = pidfile_name
($vmid);
80 if (my $fd = IO
::File-
>new("<$pidfile")) {
85 my $mtime = $st->mtime;
86 if ($mtime > time()) {
87 warn "file '$pidfile' modified in future\n";
90 if ($line =~ m/^(\d+)$/) {
92 my $cmdline = parse_cmdline
($pid);
93 if ($cmdline && defined($cmdline->{pidfile
}) && $cmdline->{pidfile
}->{value
}
94 && $cmdline->{pidfile
}->{value
} eq $pidfile) {
95 if (my $pinfo = PVE
::ProcFSTools
::check_process_running
($pid)) {
106 my ($verstr, $major, $minor, $pve) = @_;
108 if ($verstr =~ m/^(\d+)\.(\d+)(?:\.(\d+))?(?:\+pve(\d+))?/) {
109 return 1 if version_cmp
($1, $major, $2, $minor, $4, $pve) >= 0;
113 die "internal error: cannot check version of invalid string '$verstr'";
116 # gets in pairs the versions you want to compares, i.e.:
117 # ($a-major, $b-major, $a-minor, $b-minor, $a-extra, $b-extra, ...)
118 # returns 0 if same, -1 if $a is older than $b, +1 if $a is newer than $b
122 my $size = scalar(@versions);
124 return 0 if $size == 0;
127 my (undef, $fn, $line) = caller(0);
128 die "cannot compare odd count of versions, called from $fn:$line\n";
131 for (my $i = 0; $i < $size; $i += 2) {
132 my ($a, $b) = splice(@versions, 0, 2);
137 return -1 if $a < $b;