Debian Codegraph @

examples/vol-upload-all.pl

raw
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Sys::Virt;
7
8
9 my $c = Sys::Virt->new(uri => "qemu:///session");
10
11 my $st = $c->new_stream();
12
13 die "syntax: $0 VOL-PATH INPUT-FILE" unless int(@ARGV) == 2;
14
15 my $volpath = shift @ARGV;
16 my $f = shift @ARGV;
17
18 my $vol = $c->get_storage_volume_by_path($volpath);
19
20 open FILE, "<$f" or die "cannot open $f: $!";
21
22 sub foo {
23 my $st = $_[0];
24 my $nbytes = $_[2];
25 return sysread FILE, $_[1], $nbytes;
26 };
27
28 eval {
29 $vol->upload($st, 0, 0);
30 $st->send_all(\&foo);
31
32 $st->finish();
33 };
34 if ($@) {
35 close FILE;
36 die $@;
37 }
38 close FILE or die "cannot save $f: $!";
39