]> git.proxmox.com Git - qemu-server.git/blob - PVE/VZDump/QemuServer.pm
vzdump: factor out _get_task_devlist
[qemu-server.git] / PVE / VZDump / QemuServer.pm
1 package PVE::VZDump::QemuServer;
2
3 use strict;
4 use warnings;
5
6 use File::Basename;
7 use File::Path;
8 use IO::File;
9 use IPC::Open3;
10
11 use PVE::Cluster qw(cfs_read_file);
12 use PVE::INotify;
13 use PVE::IPCC;
14 use PVE::JSONSchema;
15 use PVE::QMPClient;
16 use PVE::Storage::Plugin;
17 use PVE::Storage::PBSPlugin;
18 use PVE::Storage;
19 use PVE::Tools;
20 use PVE::VZDump;
21
22 use PVE::QemuServer;
23 use PVE::QemuServer::Machine;
24 use PVE::QemuServer::Monitor qw(mon_cmd);
25
26 use base qw (PVE::VZDump::Plugin);
27
28 sub new {
29 my ($class, $vzdump) = @_;
30
31 PVE::VZDump::check_bin('qm');
32
33 my $self = bless { vzdump => $vzdump }, $class;
34
35 $self->{vmlist} = PVE::QemuServer::vzlist();
36 $self->{storecfg} = PVE::Storage::config();
37
38 return $self;
39 };
40
41 sub type {
42 return 'qemu';
43 }
44
45 sub vmlist {
46 my ($self) = @_;
47 return [ keys %{$self->{vmlist}} ];
48 }
49
50 sub prepare {
51 my ($self, $task, $vmid, $mode) = @_;
52
53 $task->{disks} = [];
54
55 my $conf = $self->{vmlist}->{$vmid} = PVE::QemuConfig->load_config($vmid);
56
57 $self->loginfo("VM Name: $conf->{name}")
58 if defined($conf->{name});
59
60 $self->{vm_was_running} = 1;
61 if (!PVE::QemuServer::check_running($vmid)) {
62 $self->{vm_was_running} = 0;
63 }
64
65 $task->{hostname} = $conf->{name};
66
67 my $hostname = PVE::INotify::nodename();
68
69 my $vollist = [];
70 my $drivehash = {};
71 PVE::QemuServer::foreach_drive($conf, sub {
72 my ($ds, $drive) = @_;
73
74 return if PVE::QemuServer::drive_is_cdrom($drive);
75
76 my $volid = $drive->{file};
77
78 if (defined($drive->{backup}) && !$drive->{backup}) {
79 $self->loginfo("exclude disk '$ds' '$volid' (backup=no)");
80 return;
81 } elsif ($self->{vm_was_running} && $drive->{iothread}) {
82 if (!PVE::QemuServer::Machine::runs_at_least_qemu_version($vmid, 4, 0, 1)) {
83 die "disk '$ds' '$volid' (iothread=on) can't use backup feature with running QEMU " .
84 "version < 4.0.1! Either set backup=no for this drive or upgrade QEMU and restart VM\n";
85 }
86 } elsif ($ds =~ m/^efidisk/ && (!defined($conf->{bios}) || $conf->{bios} ne 'ovmf')) {
87 $self->loginfo("excluding '$ds' (efidisks can only be backed up when BIOS is set to 'ovmf')");
88 return;
89 } else {
90 my $log = "include disk '$ds' '$volid'";
91 if (defined $drive->{size}) {
92 my $readable_size = PVE::JSONSchema::format_size($drive->{size});
93 $log .= " $readable_size";
94 }
95 $self->loginfo($log);
96 }
97
98 my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
99 push @$vollist, $volid if $storeid;
100 $drivehash->{$ds} = $drive;
101 });
102
103 PVE::Storage::activate_volumes($self->{storecfg}, $vollist);
104
105 foreach my $ds (sort keys %$drivehash) {
106 my $drive = $drivehash->{$ds};
107
108 my $volid = $drive->{file};
109 my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
110
111 my $path = $volid;
112 if ($storeid) {
113 $path = PVE::Storage::path($self->{storecfg}, $volid);
114 }
115 next if !$path;
116
117 my ($size, $format) = eval { PVE::Storage::volume_size_info($self->{storecfg}, $volid, 5) };
118 die "no such volume '$volid'\n" if $@;
119
120 my $diskinfo = {
121 path => $path,
122 volid => $volid,
123 storeid => $storeid,
124 format => $format,
125 virtdev => $ds,
126 qmdevice => "drive-$ds",
127 };
128
129 if (-b $path) {
130 $diskinfo->{type} = 'block';
131 } else {
132 $diskinfo->{type} = 'file';
133 }
134
135 push @{$task->{disks}}, $diskinfo;
136 }
137 }
138
139 sub vm_status {
140 my ($self, $vmid) = @_;
141
142 my $running = PVE::QemuServer::check_running($vmid) ? 1 : 0;
143
144 return wantarray ? ($running, $running ? 'running' : 'stopped') : $running;
145 }
146
147 sub lock_vm {
148 my ($self, $vmid) = @_;
149
150 PVE::QemuConfig->set_lock($vmid, 'backup');
151 }
152
153 sub unlock_vm {
154 my ($self, $vmid) = @_;
155
156 PVE::QemuConfig->remove_lock($vmid, 'backup');
157 }
158
159 sub stop_vm {
160 my ($self, $task, $vmid) = @_;
161
162 my $opts = $self->{vzdump}->{opts};
163
164 my $wait = $opts->{stopwait} * 60;
165 # send shutdown and wait
166 $self->cmd ("qm shutdown $vmid --skiplock --keepActive --timeout $wait");
167 }
168
169 sub start_vm {
170 my ($self, $task, $vmid) = @_;
171
172 $self->cmd ("qm start $vmid --skiplock");
173 }
174
175 sub suspend_vm {
176 my ($self, $task, $vmid) = @_;
177
178 $self->cmd ("qm suspend $vmid --skiplock");
179 }
180
181 sub resume_vm {
182 my ($self, $task, $vmid) = @_;
183
184 $self->cmd ("qm resume $vmid --skiplock");
185 }
186
187 sub assemble {
188 my ($self, $task, $vmid) = @_;
189
190 my $conffile = PVE::QemuConfig->config_file($vmid);
191
192 my $outfile = "$task->{tmpdir}/qemu-server.conf";
193 my $firewall_src = "/etc/pve/firewall/$vmid.fw";
194 my $firewall_dest = "$task->{tmpdir}/qemu-server.fw";
195
196 my $outfd = IO::File->new (">$outfile") ||
197 die "unable to open '$outfile'";
198 my $conffd = IO::File->new ($conffile, 'r') ||
199 die "unable open '$conffile'";
200
201 my $found_snapshot;
202 my $found_pending;
203 while (defined (my $line = <$conffd>)) {
204 next if $line =~ m/^\#vzdump\#/; # just to be sure
205 next if $line =~ m/^\#qmdump\#/; # just to be sure
206 if ($line =~ m/^\[(.*)\]\s*$/) {
207 if ($1 =~ m/PENDING/i) {
208 $found_pending = 1;
209 } else {
210 $found_snapshot = 1;
211 }
212 next; # skip all snapshots and pending changes config data
213 }
214
215 if ($line =~ m/^unused\d+:\s*(\S+)\s*/) {
216 $self->loginfo("skip unused drive '$1' (not included into backup)");
217 next;
218 }
219 next if $line =~ m/^lock:/ || $line =~ m/^parent:/;
220
221 print $outfd $line;
222 }
223
224 foreach my $di (@{$task->{disks}}) {
225 if ($di->{type} eq 'block' || $di->{type} eq 'file') {
226 my $storeid = $di->{storeid} || '';
227 my $format = $di->{format} || '';
228 print $outfd "#qmdump#map:$di->{virtdev}:$di->{qmdevice}:$storeid:$format:\n";
229 } else {
230 die "internal error";
231 }
232 }
233
234 if ($found_snapshot) {
235 $self->loginfo("snapshots found (not included into backup)");
236 }
237 if ($found_pending) {
238 $self->loginfo("pending configuration changes found (not included into backup)");
239 }
240
241 PVE::Tools::file_copy($firewall_src, $firewall_dest) if -f $firewall_src;
242 }
243
244 sub archive {
245 my ($self, $task, $vmid, $filename, $comp) = @_;
246
247 my $opts = $self->{vzdump}->{opts};
248 my $scfg = $opts->{scfg};
249
250 if ($scfg->{type} eq 'pbs') {
251 $self->archive_pbs($task, $vmid);
252 } else {
253 $self->archive_vma($task, $vmid, $filename, $comp);
254 }
255 }
256
257 my $query_backup_status_loop = sub {
258 my ($self, $vmid, $job_uuid) = @_;
259
260 my $starttime = time ();
261 my $last_time = $starttime;
262 my ($last_percent, $last_total, $last_zero, $last_transferred) = (-1, 0, 0, 0);
263 my $transferred;
264
265 my $get_mbps = sub {
266 my ($mb, $delta) = @_;
267 return ($mb > 0) ? int(($mb / $delta) / (1000 * 1000)) : 0;
268 };
269
270 while(1) {
271 my $status = mon_cmd($vmid, 'query-backup');
272
273 my $total = $status->{total} || 0;
274 $transferred = $status->{transferred} || 0;
275 my $percent = $total ? int(($transferred * 100)/$total) : 0;
276 my $zero = $status->{'zero-bytes'} || 0;
277 my $zero_per = $total ? int(($zero * 100)/$total) : 0;
278
279 die "got unexpected uuid\n" if !$status->{uuid} || ($status->{uuid} ne $job_uuid);
280
281 my $ctime = time();
282 my $duration = $ctime - $starttime;
283
284 my $rbytes = $transferred - $last_transferred;
285 my $wbytes = $rbytes - ($zero - $last_zero);
286
287 my $timediff = ($ctime - $last_time) || 1; # fixme
288 my $mbps_read = $get_mbps->($rbytes, $timediff);
289 my $mbps_write = $get_mbps->($wbytes, $timediff);
290
291 my $statusline = "status: $percent% ($transferred/$total), sparse ${zero_per}% ($zero), duration $duration, read/write $mbps_read/$mbps_write MB/s";
292
293 my $res = $status->{status} || 'unknown';
294 if ($res ne 'active') {
295 $self->loginfo($statusline);
296 if ($res ne 'done') {
297 die (($status->{errmsg} || "unknown error") . "\n") if $res eq 'error';
298 die "got unexpected status '$res'\n";
299 } elsif ($total != $transferred) {
300 die "got wrong number of transfered bytes ($total != $transferred)\n";
301 }
302 last;
303 }
304 if ($percent != $last_percent && ($timediff > 2)) {
305 $self->loginfo($statusline);
306 $last_percent = $percent;
307 $last_total = $total if $total;
308 $last_zero = $zero if $zero;
309 $last_transferred = $transferred if $transferred;
310 $last_time = $ctime;
311 }
312 sleep(1);
313 }
314
315 my $duration = time() - $starttime;
316 if ($transferred && $duration) {
317 my $mb = int($transferred / (1000 * 1000));
318 my $mbps = $get_mbps->($transferred, $duration);
319 $self->loginfo("transferred $mb MB in $duration seconds ($mbps MB/s)");
320 }
321 };
322
323 sub archive_pbs {
324 my ($self, $task, $vmid) = @_;
325
326 my $conffile = "$task->{tmpdir}/qemu-server.conf";
327 my $firewall = "$task->{tmpdir}/qemu-server.fw";
328
329 my $opts = $self->{vzdump}->{opts};
330
331 my $scfg = $opts->{scfg};
332
333 my $starttime = time();
334
335 my $diskcount = scalar(@{$task->{disks}});
336
337 my $server = $scfg->{server};
338 my $datastore = $scfg->{datastore};
339 my $username = $scfg->{username} // 'root@pam';
340 my $fingerprint = $scfg->{fingerprint};
341
342 my $repo = "$username\@$server:$datastore";
343 my $password = PVE::Storage::PBSPlugin::pbs_get_password($scfg, $opts->{storage});
344
345 if (PVE::QemuConfig->is_template($self->{vmlist}->{$vmid}) || !$diskcount) {
346 my @pathlist;
347 foreach my $di (@{$task->{disks}}) {
348 if ($di->{type} eq 'block' || $di->{type} eq 'file') {
349 push @pathlist, "$di->{qmdevice}.img:$di->{path}";
350 } else {
351 die "implement me";
352 }
353 }
354
355 if (!$diskcount) {
356 $self->loginfo("backup contains no disks");
357 }
358
359 local $ENV{PBS_PASSWORD} = $password;
360 my $cmd = [
361 '/usr/bin/proxmox-backup-client',
362 'backup',
363 '--repository', $repo,
364 '--backup-type', 'vm',
365 '--backup-id', "$vmid",
366 '--backup-time', $task->{backup_time},
367 ];
368
369 push @$cmd, '--fingerprint', $fingerprint if defined($fingerprint);
370
371 push @$cmd, "qemu-server.conf:$conffile";
372 push @$cmd, "fw.conf:$firewall" if -e $firewall;
373 push @$cmd, @pathlist if scalar(@pathlist);
374
375 $self->loginfo("starting template backup");
376 $self->loginfo(join(' ', @$cmd));
377
378 $self->cmd($cmd);
379
380 return;
381 }
382
383 # get list early so we die on unkown drive types before doing anything
384 my $devlist = _get_task_devlist($task);
385
386 my $stop_after_backup;
387 my $resume_on_backup;
388
389 my $skiplock = 1;
390 my $vm_is_running = PVE::QemuServer::check_running($vmid);
391 if (!$vm_is_running) {
392 eval {
393 $self->loginfo("starting kvm to execute backup task");
394 PVE::QemuServer::vm_start($self->{storecfg}, $vmid, undef,
395 $skiplock, undef, 1);
396 if ($self->{vm_was_running}) {
397 $resume_on_backup = 1;
398 } else {
399 $stop_after_backup = 1;
400 }
401 };
402 if (my $err = $@) {
403 die $err;
404 }
405 }
406
407 my $backup_job_uuid;
408
409 my $interrupt_msg = "interrupted by signal\n";
410 eval {
411 $SIG{INT} = $SIG{TERM} = $SIG{QUIT} = $SIG{HUP} = $SIG{PIPE} = sub {
412 die $interrupt_msg;
413 };
414
415 my $agent_running = 0;
416
417 if ($self->{vmlist}->{$vmid}->{agent} && $vm_is_running) {
418 $agent_running = PVE::QemuServer::qga_check_running($vmid);
419 }
420
421 if ($agent_running){
422 eval { mon_cmd($vmid, "guest-fsfreeze-freeze"); };
423 if (my $err = $@) {
424 $self->logerr($err);
425 }
426 }
427
428 eval {
429
430 my $params = {
431 format => "pbs",
432 'backup-file' => $repo,
433 'backup-id' => "$vmid",
434 'backup-time' => $task->{backup_time},
435 password => $password,
436 devlist => $devlist,
437 'config-file' => $conffile,
438 };
439 $params->{fingerprint} = $fingerprint if defined($fingerprint);
440 $params->{'firewall-file'} = $firewall if -e $firewall;
441 my $res = mon_cmd($vmid, "backup", %$params);
442 $backup_job_uuid = $res->{UUID};
443 };
444
445 my $qmperr = $@;
446
447 if ($agent_running){
448 eval { mon_cmd($vmid, "guest-fsfreeze-thaw"); };
449 if (my $err = $@) {
450 $self->logerr($err);
451 }
452 }
453
454 die $qmperr if $qmperr;
455
456 die "got no uuid for backup task\n" if !defined($backup_job_uuid);
457
458 $self->loginfo("started backup task '$backup_job_uuid'");
459
460 if ($resume_on_backup) {
461 if (my $stoptime = $task->{vmstoptime}) {
462 my $delay = time() - $task->{vmstoptime};
463 $task->{vmstoptime} = undef; # avoid printing 'online after ..' twice
464 $self->loginfo("resuming VM again after $delay seconds");
465 } else {
466 $self->loginfo("resuming VM again");
467 }
468 mon_cmd($vmid, 'cont');
469 }
470
471 $query_backup_status_loop->($self, $vmid, $backup_job_uuid);
472 };
473 my $err = $@;
474
475 if ($err) {
476 $self->logerr($err);
477 if (defined($backup_job_uuid)) {
478 $self->loginfo("aborting backup job");
479 eval { mon_cmd($vmid, 'backup-cancel'); };
480 if (my $err1 = $@) {
481 $self->logerr($err1);
482 }
483 }
484 }
485
486 if ($stop_after_backup) {
487 # stop if not running
488 eval {
489 my $resp = mon_cmd($vmid, 'query-status');
490 my $status = $resp && $resp->{status} ? $resp->{status} : 'unknown';
491 if ($status eq 'prelaunch') {
492 $self->loginfo("stopping kvm after backup task");
493 PVE::QemuServer::vm_stop($self->{storecfg}, $vmid, $skiplock);
494 } else {
495 $self->loginfo("kvm status changed after backup ('$status')" .
496 " - keep VM running");
497 }
498 }
499 }
500
501 die $err if $err;
502 }
503
504 sub archive_vma {
505 my ($self, $task, $vmid, $filename, $comp) = @_;
506
507 my $conffile = "$task->{tmpdir}/qemu-server.conf";
508 my $firewall = "$task->{tmpdir}/qemu-server.fw";
509
510 my $opts = $self->{vzdump}->{opts};
511
512 my $starttime = time();
513
514 my $speed = 0;
515 if ($opts->{bwlimit}) {
516 $speed = $opts->{bwlimit}*1024;
517 }
518
519 my $diskcount = scalar(@{$task->{disks}});
520
521 if (PVE::QemuConfig->is_template($self->{vmlist}->{$vmid}) || !$diskcount) {
522 my @pathlist;
523 foreach my $di (@{$task->{disks}}) {
524 if ($di->{type} eq 'block' || $di->{type} eq 'file') {
525 push @pathlist, "$di->{qmdevice}=$di->{path}";
526 } else {
527 die "implement me";
528 }
529 }
530
531 if (!$diskcount) {
532 $self->loginfo("backup contains no disks");
533 }
534
535 my $outcmd;
536 if ($comp) {
537 $outcmd = "exec:$comp";
538 } else {
539 $outcmd = "exec:cat";
540 }
541
542 $outcmd .= " > $filename" if !$opts->{stdout};
543
544 my $cmd = ['/usr/bin/vma', 'create', '-v', '-c', $conffile];
545 push @$cmd, '-c', $firewall if -e $firewall;
546 push @$cmd, $outcmd, @pathlist;
547
548 $self->loginfo("starting template backup");
549 $self->loginfo(join(' ', @$cmd));
550
551 if ($opts->{stdout}) {
552 $self->cmd($cmd, output => ">&=" . fileno($opts->{stdout}));
553 } else {
554 $self->cmd($cmd);
555 }
556
557 return;
558 }
559
560 my $devlist = _get_task_devlist($task);
561
562 my $stop_after_backup;
563 my $resume_on_backup;
564
565 my $skiplock = 1;
566 my $vm_is_running = PVE::QemuServer::check_running($vmid);
567 if (!$vm_is_running) {
568 eval {
569 $self->loginfo("starting kvm to execute backup task");
570 PVE::QemuServer::vm_start($self->{storecfg}, $vmid, undef,
571 $skiplock, undef, 1);
572 if ($self->{vm_was_running}) {
573 $resume_on_backup = 1;
574 } else {
575 $stop_after_backup = 1;
576 }
577 };
578 if (my $err = $@) {
579 die $err;
580 }
581 }
582
583 my $cpid;
584 my $backup_job_uuid;
585
586 my $interrupt_msg = "interrupted by signal\n";
587 eval {
588 $SIG{INT} = $SIG{TERM} = $SIG{QUIT} = $SIG{HUP} = $SIG{PIPE} = sub {
589 die $interrupt_msg;
590 };
591
592 my $qmpclient = PVE::QMPClient->new();
593
594 my $backup_cb = sub {
595 my ($vmid, $resp) = @_;
596 $backup_job_uuid = $resp->{return}->{UUID};
597 };
598
599 my $outfh;
600 if ($opts->{stdout}) {
601 $outfh = $opts->{stdout};
602 } else {
603 $outfh = IO::File->new($filename, "w") ||
604 die "unable to open file '$filename' - $!\n";
605 }
606
607 my $outfileno;
608 if ($comp) {
609 my @pipefd = POSIX::pipe();
610 $cpid = fork();
611 die "unable to fork worker - $!" if !defined($cpid);
612 if ($cpid == 0) {
613 eval {
614 POSIX::close($pipefd[1]);
615 # redirect STDIN
616 my $fd = fileno(STDIN);
617 close STDIN;
618 POSIX::close(0) if $fd != 0;
619 die "unable to redirect STDIN - $!"
620 if !open(STDIN, "<&", $pipefd[0]);
621
622 # redirect STDOUT
623 $fd = fileno(STDOUT);
624 close STDOUT;
625 POSIX::close (1) if $fd != 1;
626
627 die "unable to redirect STDOUT - $!"
628 if !open(STDOUT, ">&", fileno($outfh));
629
630 exec($comp);
631 die "fork compressor '$comp' failed\n";
632 };
633 if (my $err = $@) {
634 $self->logerr($err);
635 POSIX::_exit(1);
636 }
637 POSIX::_exit(0);
638 kill(-9, $$);
639 } else {
640 POSIX::close($pipefd[0]);
641 $outfileno = $pipefd[1];
642 }
643 } else {
644 $outfileno = fileno($outfh);
645 }
646
647 my $add_fd_cb = sub {
648 my ($vmid, $resp) = @_;
649
650 my $params = {
651 'backup-file' => "/dev/fdname/backup",
652 speed => $speed,
653 'config-file' => $conffile,
654 devlist => $devlist
655 };
656
657 $params->{'firewall-file'} = $firewall if -e $firewall;
658 $qmpclient->queue_cmd($vmid, $backup_cb, 'backup', %$params);
659 };
660
661 $qmpclient->queue_cmd($vmid, $add_fd_cb, 'getfd',
662 fd => $outfileno, fdname => "backup");
663
664 my $agent_running = 0;
665
666 if ($self->{vmlist}->{$vmid}->{agent} && $vm_is_running) {
667 $agent_running = PVE::QemuServer::qga_check_running($vmid);
668 $self->loginfo("skipping guest-agent 'fs-freeze', agent configured but not running?")
669 if !$agent_running;
670 }
671
672 if ($agent_running){
673 $self->loginfo("issuing guest-agent 'fs-freeze' command");
674 eval { mon_cmd($vmid, "guest-fsfreeze-freeze"); };
675 if (my $err = $@) {
676 $self->logerr($err);
677 }
678 }
679
680 eval { $qmpclient->queue_execute(30) };
681 my $qmperr = $@;
682
683 if ($agent_running){
684 $self->loginfo("issuing guest-agent 'fs-thaw' command");
685 eval { mon_cmd($vmid, "guest-fsfreeze-thaw"); };
686 if (my $err = $@) {
687 $self->logerr($err);
688 }
689 }
690 die $qmperr if $qmperr;
691 die $qmpclient->{errors}->{$vmid} if $qmpclient->{errors}->{$vmid};
692
693 if ($cpid) {
694 POSIX::close($outfileno) == 0 ||
695 die "close output file handle failed\n";
696 }
697
698 die "got no uuid for backup task\n" if !defined($backup_job_uuid);
699
700 $self->loginfo("started backup task '$backup_job_uuid'");
701
702 if ($resume_on_backup) {
703 if (my $stoptime = $task->{vmstoptime}) {
704 my $delay = time() - $task->{vmstoptime};
705 $task->{vmstoptime} = undef; # avoid printing 'online after ..' twice
706 $self->loginfo("resuming VM again after $delay seconds");
707 } else {
708 $self->loginfo("resuming VM again");
709 }
710 mon_cmd($vmid, 'cont');
711 }
712
713 $query_backup_status_loop->($self, $vmid, $backup_job_uuid);
714 };
715 my $err = $@;
716
717 if ($err) {
718 $self->logerr($err);
719 if (defined($backup_job_uuid)) {
720 $self->loginfo("aborting backup job");
721 eval { mon_cmd($vmid, 'backup-cancel'); };
722 if (my $err1 = $@) {
723 $self->logerr($err1);
724 }
725 }
726 }
727
728 if ($stop_after_backup) {
729 # stop if not running
730 eval {
731 my $resp = mon_cmd($vmid, 'query-status');
732 my $status = $resp && $resp->{status} ? $resp->{status} : 'unknown';
733 if ($status eq 'prelaunch') {
734 $self->loginfo("stopping kvm after backup task");
735 PVE::QemuServer::vm_stop($self->{storecfg}, $vmid, $skiplock);
736 } else {
737 $self->loginfo("kvm status changed after backup ('$status')" .
738 " - keep VM running");
739 }
740 }
741 }
742
743 if ($err) {
744 if ($cpid) {
745 kill(9, $cpid);
746 waitpid($cpid, 0);
747 }
748 die $err;
749 }
750
751 if ($cpid && (waitpid($cpid, 0) > 0)) {
752 my $stat = $?;
753 my $ec = $stat >> 8;
754 my $signal = $stat & 127;
755 if ($ec || $signal) {
756 die "$comp failed - wrong exit status $ec" .
757 ($signal ? " (signal $signal)\n" : "\n");
758 }
759 }
760 }
761
762 sub _get_task_devlist {
763 my ($task) = @_;
764
765 my $devlist = '';
766 foreach my $di (@{$task->{disks}}) {
767 if ($di->{type} eq 'block' || $di->{type} eq 'file') {
768 $devlist .= ',' if $devlist;
769 $devlist .= $di->{qmdevice};
770 } else {
771 die "implement me (type '$di->{type}')";
772 }
773 }
774 return $devlist;
775 }
776
777 sub snapshot {
778 my ($self, $task, $vmid) = @_;
779
780 # nothing to do
781 }
782
783 sub cleanup {
784 my ($self, $task, $vmid) = @_;
785
786 # nothing to do ?
787 }
788
789 1;