]> git.proxmox.com Git - pve-storage.git/blame - PVE/Storage/LVMPlugin.pm
followup: get_disks: use own variable for frequent access
[pve-storage.git] / PVE / Storage / LVMPlugin.pm
CommitLineData
1dc01b9f
DM
1package PVE::Storage::LVMPlugin;
2
3use strict;
4use warnings;
074b2cb4 5
1dc01b9f 6use IO::File;
074b2cb4 7
1dc01b9f
DM
8use PVE::Tools qw(run_command trim);
9use PVE::Storage::Plugin;
10use PVE::JSONSchema qw(get_standard_option);
11
12use base qw(PVE::Storage::Plugin);
13
14# lvm helper functions
15
16sub lvm_pv_info {
17 my ($device) = @_;
18
19 die "no device specified" if !$device;
20
21 my $has_label = 0;
22
23 my $cmd = ['/usr/bin/file', '-L', '-s', $device];
24 run_command($cmd, outfunc => sub {
25 my $line = shift;
26 $has_label = 1 if $line =~ m/LVM2/;
27 });
28
29 return undef if !$has_label;
30
31 $cmd = ['/sbin/pvs', '--separator', ':', '--noheadings', '--units', 'k',
32 '--unbuffered', '--nosuffix', '--options',
33 'pv_name,pv_size,vg_name,pv_uuid', $device];
34
35 my $pvinfo;
36 run_command($cmd, outfunc => sub {
37 my $line = shift;
38
39 $line = trim($line);
40
41 my ($pvname, $size, $vgname, $uuid) = split(':', $line);
42
5c687bd9 43 die "found multiple pvs entries for device '$device'\n"
1dc01b9f
DM
44 if $pvinfo;
45
46 $pvinfo = {
47 pvname => $pvname,
a3f38a64 48 size => int($size),
1dc01b9f
DM
49 vgname => $vgname,
50 uuid => $uuid,
51 };
52 });
53
54 return $pvinfo;
55}
56
57sub clear_first_sector {
58 my ($dev) = shift;
59
60 if (my $fh = IO::File->new($dev, "w")) {
61 my $buf = 0 x 512;
62 syswrite $fh, $buf;
5c687bd9 63 $fh->close();
1dc01b9f
DM
64 }
65}
66
67sub lvm_create_volume_group {
68 my ($device, $vgname, $shared) = @_;
5c687bd9 69
1dc01b9f 70 my $res = lvm_pv_info($device);
5c687bd9 71
1dc01b9f
DM
72 if ($res->{vgname}) {
73 return if $res->{vgname} eq $vgname; # already created
74 die "device '$device' is already used by volume group '$res->{vgname}'\n";
75 }
76
77 clear_first_sector($device); # else pvcreate fails
78
79 # we use --metadatasize 250k, which reseults in "pe_start = 512"
80 # so pe_start is aligned on a 128k boundary (advantage for SSDs)
81 my $cmd = ['/sbin/pvcreate', '--metadatasize', '250k', $device];
82
83 run_command($cmd, errmsg => "pvcreate '$device' error");
84
85 $cmd = ['/sbin/vgcreate', $vgname, $device];
86 # push @$cmd, '-c', 'y' if $shared; # we do not use this yet
87
88 run_command($cmd, errmsg => "vgcreate $vgname $device error");
89}
90
91sub lvm_vgs {
8cccb344 92 my ($includepvs) = @_;
1dc01b9f
DM
93
94 my $cmd = ['/sbin/vgs', '--separator', ':', '--noheadings', '--units', 'b',
8cccb344
DC
95 '--unbuffered', '--nosuffix', '--options'];
96
97 my $cols = [qw(vg_name vg_size vg_free lv_count)];
98
99 if ($includepvs) {
100 push @$cols, qw(pv_name pv_size pv_free);
101 }
102
103 push @$cmd, join(',', @$cols);
1dc01b9f
DM
104
105 my $vgs = {};
106 eval {
107 run_command($cmd, outfunc => sub {
108 my $line = shift;
109
110 $line = trim($line);
111
8cccb344
DC
112 my ($name, $size, $free, $lvcount, $pvname, $pvsize, $pvfree) = split (':', $line);
113
114 $vgs->{$name} = { size => int ($size), free => int ($free), lvcount => int($lvcount) }
115 if !$vgs->{$name};
1dc01b9f 116
8cccb344
DC
117 if (defined($pvname) && defined($pvsize) && defined($pvfree)) {
118 push @{$vgs->{$name}->{pvs}}, {
119 name => $pvname,
120 size => int($pvsize),
121 free => int($pvfree),
122 };
123 }
1dc01b9f
DM
124 });
125 };
126 my $err = $@;
127
128 # just warn (vgs return error code 5 if clvmd does not run)
129 # but output is still OK (list without clustered VGs)
130 warn $err if $err;
131
132 return $vgs;
133}
134
3e44cd84 135sub lvm_list_volumes {
1dc01b9f
DM
136 my ($vgname) = @_;
137
138 my $cmd = ['/sbin/lvs', '--separator', ':', '--noheadings', '--units', 'b',
139 '--unbuffered', '--nosuffix', '--options',
2c2fd98b 140 'vg_name,lv_name,lv_size,lv_attr,pool_lv,data_percent,metadata_percent,snap_percent,uuid,tags,metadata_size'];
1dc01b9f
DM
141
142 push @$cmd, $vgname if $vgname;
143
144 my $lvs = {};
145 run_command($cmd, outfunc => sub {
146 my $line = shift;
147
148 $line = trim($line);
149
2c2fd98b 150 my ($vg_name, $lv_name, $lv_size, $lv_attr, $pool_lv, $data_percent, $meta_percent, $snap_percent, $uuid, $tags, $meta_size) = split(':', $line);
3e44cd84
DM
151 return if !$vg_name;
152 return if !$lv_name;
1dc01b9f 153
3e44cd84 154 my $lv_type = substr($lv_attr, 0, 1);
1dc01b9f 155
3e44cd84 156 my $d = {
a3f38a64 157 lv_size => int($lv_size),
3e44cd84
DM
158 lv_type => $lv_type,
159 };
160 $d->{pool_lv} = $pool_lv if $pool_lv;
7a9dd119 161 $d->{tags} = $tags if $tags;
3e44cd84
DM
162
163 if ($lv_type eq 't') {
164 $data_percent ||= 0;
165 $meta_percent ||= 0;
166 $snap_percent ||= 0;
2c2fd98b
DC
167 $d->{metadata_size} = int($meta_size);
168 $d->{metadata_used} = int(($meta_percent * $meta_size)/100);
faabe9e2 169 $d->{used} = int(($data_percent * $lv_size)/100);
1dc01b9f 170 }
3e44cd84 171 $lvs->{$vg_name}->{$lv_name} = $d;
1dc01b9f
DM
172 });
173
174 return $lvs;
175}
176
5c687bd9 177# Configuration
1dc01b9f 178
1dc01b9f
DM
179sub type {
180 return 'lvm';
181}
182
183sub plugindata {
184 return {
68b2c18a 185 content => [ {images => 1, rootdir => 1}, { images => 1 }],
1dc01b9f
DM
186 };
187}
188
189sub properties {
190 return {
191 vgname => {
192 description => "Volume group name.",
193 type => 'string', format => 'pve-storage-vgname',
194 },
195 base => {
196 description => "Base volume. This volume is automatically activated.",
197 type => 'string', format => 'pve-volume-id',
198 },
199 saferemove => {
200 description => "Zero-out data when removing LVs.",
201 type => 'boolean',
202 },
399ab2b6
PB
203 saferemove_throughput => {
204 description => "Wipe throughput (cstream -t parameter value).",
205 type => 'string',
206 },
7a9dd119
FG
207 tagged_only => {
208 description => "Only use logical volumes tagged with 'pve-vm-ID'.",
209 type => 'boolean',
210 }
1dc01b9f
DM
211 };
212}
213
214sub options {
215 return {
216 vgname => { fixed => 1 },
0423e8c6 217 nodes => { optional => 1 },
1dc01b9f
DM
218 shared => { optional => 1 },
219 disable => { optional => 1 },
0423e8c6
FG
220 saferemove => { optional => 1 },
221 saferemove_throughput => { optional => 1 },
1dc01b9f 222 content => { optional => 1 },
0423e8c6 223 base => { fixed => 1, optional => 1 },
7a9dd119 224 tagged_only => { optional => 1 },
9edb99a5 225 bwlimit => { optional => 1 },
1dc01b9f
DM
226 };
227}
228
229# Storage implementation
230
f9602323
TL
231sub on_add_hook {
232 my ($class, $storeid, $scfg, %param) = @_;
233
234 if (my $base = $scfg->{base}) {
235 my ($baseid, $volname) = PVE::Storage::parse_volume_id($base);
236
237 my $cfg = PVE::Storage::config();
238 my $basecfg = PVE::Storage::storage_config ($cfg, $baseid, 1);
239 die "base storage ID '$baseid' does not exist\n" if !$basecfg;
240
241 # we only support iscsi for now
242 die "unsupported base type '$basecfg->{type}'"
243 if $basecfg->{type} ne 'iscsi';
244
245 my $path = PVE::Storage::path($cfg, $base);
246
247 PVE::Storage::activate_storage($cfg, $baseid);
248
249 lvm_create_volume_group($path, $scfg->{vgname}, $scfg->{shared});
250 }
251}
252
1dc01b9f
DM
253sub parse_volname {
254 my ($class, $volname) = @_;
255
5dca5c7c 256 PVE::Storage::Plugin::parse_lvm_name($volname);
1dc01b9f
DM
257
258 if ($volname =~ m/^(vm-(\d+)-\S+)$/) {
7800e84d 259 return ('images', $1, $2, undef, undef, undef, 'raw');
1dc01b9f
DM
260 }
261
262 die "unable to parse lvm volume name '$volname'\n";
263}
264
452e3ee7 265sub filesystem_path {
e67069eb
DM
266 my ($class, $scfg, $volname, $snapname) = @_;
267
268 die "lvm snapshot is not implemented"if defined($snapname);
1dc01b9f
DM
269
270 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
271
272 my $vg = $scfg->{vgname};
5c687bd9 273
1dc01b9f
DM
274 my $path = "/dev/$vg/$name";
275
5521b580 276 return wantarray ? ($path, $vmid, $vtype) : $path;
1dc01b9f
DM
277}
278
5eab0272
DM
279sub create_base {
280 my ($class, $storeid, $scfg, $volname) = @_;
281
282 die "can't create base images in lvm storage\n";
283}
284
285sub clone_image {
f236eaf8 286 my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
5eab0272
DM
287
288 die "can't clone images in lvm storage\n";
289}
290
b1378461 291sub lvm_find_free_diskname {
c4a29df4 292 my ($lvs, $vg, $storeid, $vmid, $scfg) = @_;
b1378461 293
c4a29df4 294 my $disk_list = [ keys %{$lvs->{$vg}} ];
b1378461 295
c4a29df4 296 return PVE::Storage::Plugin::get_next_vm_diskname($disk_list, $storeid, $vmid, undef, $scfg);
b1378461
DM
297}
298
1dc01b9f
DM
299sub alloc_image {
300 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
301
302 die "unsupported format '$fmt'" if $fmt ne 'raw';
303
5c687bd9 304 die "illegal name '$name' - sould be 'vm-$vmid-*'\n"
1dc01b9f
DM
305 if $name && $name !~ m/^vm-$vmid-/;
306
307 my $vgs = lvm_vgs();
308
309 my $vg = $scfg->{vgname};
310
e8acaa3c 311 die "no such volume group '$vg'\n" if !defined ($vgs->{$vg});
1dc01b9f
DM
312
313 my $free = int($vgs->{$vg}->{free});
314
315 die "not enough free space ($free < $size)\n" if $free < $size;
316
c4a29df4 317 $name = lvm_find_free_diskname(lvm_list_volumes($vg), $vg, $storeid, $vmid, $scfg)
1dc01b9f
DM
318 if !$name;
319
320 my $cmd = ['/sbin/lvcreate', '-aly', '--addtag', "pve-vm-$vmid", '--size', "${size}k", '--name', $name, $vg];
321
322 run_command($cmd, errmsg => "lvcreate '$vg/pve-vm-$vmid' error");
323
324 return $name;
325}
326
327sub free_image {
32437ed2 328 my ($class, $storeid, $scfg, $volname, $isBase) = @_;
1dc01b9f
DM
329
330 my $vg = $scfg->{vgname};
399ab2b6 331
1dc01b9f
DM
332 # we need to zero out LVM data for security reasons
333 # and to allow thin provisioning
334
335 my $zero_out_worker = sub {
399ab2b6
PB
336 print "zero-out data on image $volname (/dev/$vg/del-$volname)\n";
337
338 # wipe throughput up to 10MB/s by default; may be overwritten with saferemove_throughput
339 my $throughput = '-10485760';
340 if ($scfg->{saferemove_throughput}) {
341 $throughput = $scfg->{saferemove_throughput};
342 }
343
344 my $cmd = [
345 '/usr/bin/cstream',
346 '-i', '/dev/zero',
347 '-o', "/dev/$vg/del-$volname",
348 '-T', '10',
349 '-v', '1',
350 '-b', '1048576',
351 '-t', "$throughput"
352 ];
353 eval { run_command($cmd, errmsg => "zero out finished (note: 'No space left on device' is ok here)"); };
1dc01b9f
DM
354 warn $@ if $@;
355
356 $class->cluster_lock_storage($storeid, $scfg->{shared}, undef, sub {
357 my $cmd = ['/sbin/lvremove', '-f', "$vg/del-$volname"];
358 run_command($cmd, errmsg => "lvremove '$vg/del-$volname' error");
359 });
399ab2b6 360 print "successfully removed volume $volname ($vg/del-$volname)\n";
1dc01b9f
DM
361 };
362
399ab2b6
PB
363 my $cmd = ['/sbin/lvchange', '-aly', "$vg/$volname"];
364 run_command($cmd, errmsg => "can't activate LV '$vg/$volname' to zero-out its data");
628a921a
SI
365 $cmd = ['/sbin/lvchange', '--refresh', "$vg/$volname"];
366 run_command($cmd, errmsg => "can't refresh LV '$vg/$volname' to zero-out its data");
399ab2b6 367
1dc01b9f
DM
368 if ($scfg->{saferemove}) {
369 # avoid long running task, so we only rename here
399ab2b6 370 $cmd = ['/sbin/lvrename', $vg, $volname, "del-$volname"];
1dc01b9f
DM
371 run_command($cmd, errmsg => "lvrename '$vg/$volname' error");
372 return $zero_out_worker;
373 } else {
374 my $tmpvg = $scfg->{vgname};
399ab2b6 375 $cmd = ['/sbin/lvremove', '-f', "$tmpvg/$volname"];
1dc01b9f
DM
376 run_command($cmd, errmsg => "lvremove '$tmpvg/$volname' error");
377 }
378
379 return undef;
380}
381
7a9dd119
FG
382my $check_tags = sub {
383 my ($tags) = @_;
384
385 return defined($tags) && $tags =~ /(^|,)pve-vm-\d+(,|$)/;
386};
387
1dc01b9f
DM
388sub list_images {
389 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
390
391 my $vgname = $scfg->{vgname};
392
3e44cd84 393 $cache->{lvs} = lvm_list_volumes() if !$cache->{lvs};
1dc01b9f
DM
394
395 my $res = [];
5c687bd9 396
1dc01b9f
DM
397 if (my $dat = $cache->{lvs}->{$vgname}) {
398
399 foreach my $volname (keys %$dat) {
400
3e44cd84
DM
401 next if $volname !~ m/^vm-(\d+)-/;
402 my $owner = $1;
403
404 my $info = $dat->{$volname};
405
7a9dd119
FG
406 next if $scfg->{tagged_only} && !&$check_tags($info->{tags});
407
3e44cd84 408 next if $info->{lv_type} ne '-';
1dc01b9f
DM
409
410 my $volid = "$storeid:$volname";
411
412 if ($vollist) {
413 my $found = grep { $_ eq $volid } @$vollist;
414 next if !$found;
415 } else {
3e44cd84 416 next if defined($vmid) && ($owner ne $vmid);
1dc01b9f
DM
417 }
418
3e44cd84
DM
419 push @$res, {
420 volid => $volid, format => 'raw', size => $info->{lv_size}, vmid => $owner,
421 };
1dc01b9f
DM
422 }
423 }
424
425 return $res;
426}
427
428sub status {
429 my ($class, $storeid, $scfg, $cache) = @_;
430
431 $cache->{vgs} = lvm_vgs() if !$cache->{vgs};
432
433 my $vgname = $scfg->{vgname};
434
097a2b2f
DM
435 if (my $info = $cache->{vgs}->{$vgname}) {
436 return ($info->{size}, $info->{free}, $info->{size} - $info->{free}, 1);
1dc01b9f
DM
437 }
438
439 return undef;
440}
441
442sub activate_storage {
443 my ($class, $storeid, $scfg, $cache) = @_;
444
445 $cache->{vgs} = lvm_vgs() if !$cache->{vgs};
446
447 # In LVM2, vgscans take place automatically;
448 # this is just to be sure
5c687bd9 449 if ($cache->{vgs} && !$cache->{vgscaned} &&
1dc01b9f
DM
450 !$cache->{vgs}->{$scfg->{vgname}}) {
451 $cache->{vgscaned} = 1;
452 my $cmd = ['/sbin/vgscan', '--ignorelockingfailure', '--mknodes'];
453 eval { run_command($cmd, outfunc => sub {}); };
454 warn $@ if $@;
455 }
456
457 # we do not acticate any volumes here ('vgchange -aly')
458 # instead, volumes are activate individually later
459}
460
461sub deactivate_storage {
462 my ($class, $storeid, $scfg, $cache) = @_;
463
464 my $cmd = ['/sbin/vgchange', '-aln', $scfg->{vgname}];
465 run_command($cmd, errmsg => "can't deactivate VG '$scfg->{vgname}'");
466}
467
468sub activate_volume {
02e797b8 469 my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
c8943a85 470 #fix me lvmchange is not provided on
02e797b8 471 my $path = $class->path($scfg, $volname, $snapname);
1dc01b9f 472
c8943a85 473 my $lvm_activate_mode = 'ey';
1dc01b9f
DM
474
475 my $cmd = ['/sbin/lvchange', "-a$lvm_activate_mode", $path];
476 run_command($cmd, errmsg => "can't activate LV '$path'");
628a921a
SI
477 $cmd = ['/sbin/lvchange', '--refresh', $path];
478 run_command($cmd, errmsg => "can't refresh LV '$path' for activation");
1dc01b9f
DM
479}
480
481sub deactivate_volume {
02e797b8 482 my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
1dc01b9f 483
02e797b8 484 my $path = $class->path($scfg, $volname, $snapname);
1dc01b9f
DM
485 return if ! -b $path;
486
487 my $cmd = ['/sbin/lvchange', '-aln', $path];
488 run_command($cmd, errmsg => "can't deactivate LV '$path'");
489}
490
530defb6
AD
491sub volume_resize {
492 my ($class, $scfg, $storeid, $volname, $size, $running) = @_;
493
494 $size = ($size/1024/1024) . "M";
495
496 my $path = $class->path($scfg, $volname);
497 my $cmd = ['/sbin/lvextend', '-L', $size, $path];
49cc7802
TL
498
499 $class->cluster_lock_storage($storeid, $scfg->{shared}, undef, sub {
500 run_command($cmd, errmsg => "error resizing volume '$path'");
501 });
530defb6
AD
502
503 return 1;
504}
505
955c1f2c
SI
506sub volume_size_info {
507 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
508 my $path = $class->filesystem_path($scfg, $volname);
509
510 my $cmd = ['/sbin/lvs', '--separator', ':', '--noheadings', '--units', 'b',
511 '--unbuffered', '--nosuffix', '--options', 'lv_size', $path];
512
513 my $size;
514 run_command($cmd, timeout => $timeout, errmsg => "can't get size of '$path'",
515 outfunc => sub {
516 $size = int(shift);
517 });
518 return wantarray ? ($size, 'raw', 0, undef) : $size;
519}
520
33818d16 521sub volume_snapshot {
f5640e7d 522 my ($class, $scfg, $storeid, $volname, $snap) = @_;
33818d16
AD
523
524 die "lvm snapshot is not implemented";
525}
526
051e85b8
AD
527sub volume_snapshot_rollback {
528 my ($class, $scfg, $storeid, $volname, $snap) = @_;
529
530 die "lvm snapshot rollback is not implemented";
531}
532
f57e796b
AD
533sub volume_snapshot_delete {
534 my ($class, $scfg, $storeid, $volname, $snap) = @_;
535
536 die "lvm snapshot delete is not implemented";
537}
538
f7d4064f
AD
539sub volume_has_feature {
540 my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running) = @_;
541
9bb4abf6
AD
542 my $features = {
543 copy => { base => 1, current => 1},
544 };
545
546 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =
547 $class->parse_volname($volname);
548
549 my $key = undef;
550 if($snapname){
2c5a7097 551 $key = 'snap';
9bb4abf6
AD
552 }else{
553 $key = $isBase ? 'base' : 'current';
554 }
555 return 1 if $features->{$feature}->{$key};
556
f7d4064f
AD
557 return undef;
558}
559
5cbbc78f
WB
560sub volume_export_formats {
561 my ($class, $scfg, $storeid, $volname, $snapshot, $base_snapshot, $with_snapshots) = @_;
562 return () if defined($snapshot); # lvm-thin only
563 return volume_import_formats($class, $scfg, $storeid, $volname, $base_snapshot, $with_snapshots);
564}
565
566sub volume_export {
567 my ($class, $scfg, $storeid, $fh, $volname, $format, $snapshot, $base_snapshot, $with_snapshots) = @_;
568 die "volume export format $format not available for $class\n"
569 if $format ne 'raw+size';
570 die "cannot export volumes together with their snapshots in $class\n"
571 if $with_snapshots;
572 die "cannot export a snapshot in $class\n" if defined($snapshot);
573 die "cannot export an incremental stream in $class\n" if defined($base_snapshot);
574 my $file = $class->path($scfg, $volname, $storeid);
575 my $size;
576 # should be faster than querying LVM, also checks for the device file's availability
577 run_command(['/sbin/blockdev', '--getsize64', $file], outfunc => sub {
578 my ($line) = @_;
579 die "unexpected output from /sbin/blockdev: $line\n" if $line !~ /^(\d+)$/;
580 $size = int($1);
581 });
582 PVE::Storage::Plugin::write_common_header($fh, $size);
583 run_command(['dd', "if=$file", "bs=64k"], output => '>&'.fileno($fh));
584}
585
586sub volume_import_formats {
587 my ($class, $scfg, $storeid, $volname, $base_snapshot, $with_snapshots) = @_;
588 return () if $with_snapshots; # not supported
589 return () if defined($base_snapshot); # not supported
590 return ('raw+size');
591}
592
593sub volume_import {
594 my ($class, $scfg, $storeid, $fh, $volname, $format, $base_snapshot, $with_snapshots) = @_;
595 die "volume import format $format not available for $class\n"
596 if $format ne 'raw+size';
597 die "cannot import volumes together with their snapshots in $class\n"
598 if $with_snapshots;
599 die "cannot import an incremental stream in $class\n" if defined($base_snapshot);
600
601 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $file_format) =
602 $class->parse_volname($volname);
603 die "cannot import format $format into a file of format $file_format\n"
604 if $file_format ne 'raw';
605
606 my $vg = $scfg->{vgname};
607 my $lvs = lvm_list_volumes($vg);
608 die "volume $vg/$volname already exists\n"
609 if $lvs->{$vg}->{$volname};
610
611 my ($size) = PVE::Storage::Plugin::read_common_header($fh);
612 $size = int($size/1024);
613
614 eval {
615 my $allocname = $class->alloc_image($storeid, $scfg, $vmid, 'raw', $name, $size);
616 if ($allocname ne $volname) {
617 my $oldname = $volname;
618 $volname = $allocname; # Let the cleanup code know what to free
619 die "internal error: unexpected allocated name: '$allocname' != '$oldname'\n";
620 }
621 my $file = $class->path($scfg, $volname, $storeid)
622 or die "internal error: failed to get path to newly allocated volume $volname\n";
4e8de9ad
SI
623
624 $class->volume_import_write($fh, $file);
5cbbc78f
WB
625 };
626 if (my $err = $@) {
627 eval { $class->free_image($storeid, $scfg, $volname, 0) };
628 warn $@ if $@;
629 die $err;
630 }
631}
632
4e8de9ad
SI
633sub volume_import_write {
634 my ($class, $input_fh, $output_file) = @_;
635 run_command(['dd', "of=$output_file", 'bs=64k'],
636 input => '<&'.fileno($input_fh));
637}
638
1dc01b9f 6391;