my ($cfg, $storeid, $noerr) = @_;
die "no storage id specified\n" if !$storeid;
-
+
my $scfg = $cfg->{ids}->{$storeid};
die "storage '$storeid' does not exists\n" if (!$noerr && !$scfg);
if (my $scfg = $cfg->{ids}->{$sid}) {
my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
- my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =
+ my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =
$plugin->parse_volname($volname);
return $isBase ? 1 : 0;
} else {
return ('');
}
- # Note: abs_path() return undef if $path doesn not exist
+ # Note: abs_path() return undef if $path doesn not exist
# for example when nfs storage is not mounted
$path = abs_path($path) || $path;
}
} elsif ($path =~ m!^$isodir/([^/]+\.[Ii][Ss][Oo])$!) {
my $name = $1;
- return ('iso', "$sid:iso/$name");
+ return ('iso', "$sid:iso/$name");
} elsif ($path =~ m!^$tmpldir/([^/]+\.tar\.gz)$!) {
my $name = $1;
return ('vztmpl', "$sid:vztmpl/$name");
return ('rootdir', "$sid:rootdir/$vmid");
} elsif ($path =~ m!^$backupdir/([^/]+\.(tar|tar\.gz|tar\.lzo|tgz|vma|vma\.gz|vma\.lzo))$!) {
my $name = $1;
- return ('iso', "$sid:backup/$name");
+ return ('iso', "$sid:backup/$name");
}
}
my $dirname = dirname($dst);
if ($tcfg->{shared}) { # we can do a local copy
-
+
run_command(['/bin/mkdir', '-p', $dirname]);
run_command(['/bin/cp', $src, $dst]);
} else {
- run_command(['/usr/bin/ssh', "root\@${target_host}",
+ run_command(['/usr/bin/ssh', "root\@${target_host}",
'/bin/mkdir', '-p', $dirname]);
# we use rsync with --sparse, so we can't use --inplace,
# save space
my ($size, $format) = PVE::Storage::Plugin::file_size_info($src);
if ($format && ($format eq 'raw') && $size) {
- run_command(['/usr/bin/ssh', "root\@${target_host}",
+ run_command(['/usr/bin/ssh', "root\@${target_host}",
'rm', '-f', $dst],
outfunc => sub {});
}
- my $cmd = ['/usr/bin/rsync', '--progress', '--sparse', '--whole-file',
+ my $cmd = ['/usr/bin/rsync', '--progress', '--sparse', '--whole-file',
$src, "root\@${target_host}:$dst"];
my $percent = -1;
sub vdisk_clone {
my ($cfg, $volid, $vmid) = @_;
-
+
my ($storeid, $volname) = parse_volume_id($volid);
my $scfg = storage_config($cfg, $storeid);
my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
-
+
activate_storage($cfg, $storeid);
# lock shared storage
my $scfg = storage_config($cfg, $storeid);
my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
-
+
activate_storage($cfg, $storeid);
# lock shared storage
my $scfg = storage_config($cfg, $storeid);
my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
-
+
activate_storage($cfg, $storeid);
my $cleanup_worker;
# lock shared storage
$plugin->cluster_lock_storage($storeid, $scfg->{shared}, undef, sub {
- my ($vtype, $name, $vmid, undef, undef, $isBase) =
+ my ($vtype, $name, $vmid, undef, undef, $isBase) =
$plugin->parse_volname($volname);
if ($isBase) {
my $vollist = $plugin->list_images($storeid, $scfg);
my $basevmid = undef;
eval{
- (undef, undef, undef, $basename, $basevmid) =
+ (undef, undef, undef, $basename, $basevmid) =
$plugin->parse_volname($tmpvolname);
};
sub template_list {
my ($cfg, $storeid, $tt) = @_;
- die "unknown template type '$tt'\n"
- if !($tt eq 'iso' || $tt eq 'vztmpl' || $tt eq 'backup');
+ die "unknown template type '$tt'\n"
+ if !($tt eq 'iso' || $tt eq 'vztmpl' || $tt eq 'backup');
my $ids = $cfg->{ids};
} elsif ($tt eq 'backup') {
next if $fn !~ m!/([^/]+\.(tar|tar\.gz|tar\.lzo|tgz|vma|vma\.gz|vma\.lzo))$!;
-
+
$info = { volid => "$sid:backup/$1", format => $2 };
}
my $scfg = storage_config($cfg, $storeid);
my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
-
+
eval {
$plugin->deactivate_volume($storeid, $scfg, $volname, $cache);
};
if scalar(@errlist);
}
-sub storage_info {
+sub storage_info {
my ($cfg, $content) = @_;
my $ids = $cfg->{ids};
my $type = $ids->{$storeid}->{type};
- $info->{$storeid} = {
+ $info->{$storeid} = {
type => $type,
- total => 0,
- avail => 0,
- used => 0,
+ total => 0,
+ avail => 0,
+ used => 0,
shared => $ids->{$storeid}->{shared} ? 1 : 0,
content => PVE::Storage::Plugin::content_hash_to_string($ids->{$storeid}->{content}),
active => 0,
eval { ($total, $avail, $used, $active) = $plugin->status($storeid, $scfg, $cache); };
warn $@ if $@;
next if !$active;
- $info->{$storeid}->{total} = $total;
- $info->{$storeid}->{avail} = $avail;
- $info->{$storeid}->{used} = $used;
+ $info->{$storeid}->{total} = $total;
+ $info->{$storeid}->{avail} = $avail;
+ $info->{$storeid}->{used} = $used;
$info->{$storeid}->{active} = $active;
}
sub resolv_server {
my ($server) = @_;
-
+
my $packed_ip = gethostbyname($server);
if (defined $packed_ip) {
return inet_ntoa($packed_ip);
my $product = file_read_firstline("$devpath/product");
$d->{product} = $product if $product;
-
+
my $manu = file_read_firstline("$devpath/manufacturer");
$d->{manufacturer} = $manu if $manu;
# Glusterfs helper functions
sub read_proc_mounts {
-
+
local $/; # enable slurp mode
-
+
my $data = "";
if (my $fd = IO::File->new("/proc/mounts", "r")) {
$data = <$fd>;
if ($mountdata =~ m|^$source/?\s$mountpoint\sfuse.glusterfs|m) {
return $mountpoint;
- }
+ }
return undef;
}
{ images => 1 }],
format => [ { raw => 1, qcow2 => 1, vmdk => 1 } , 'raw' ],
};
-}
+}
sub properties {
return {
my $volume = $scfg->{volume};
- return undef if !glusterfs_is_mounted($server, $volume, $path, $cache->{mountdata});
+ return undef if !glusterfs_is_mounted($server, $volume, $path, $cache->{mountdata});
return $class->SUPER::status($storeid, $scfg, $cache);
}
my $server = $scfg->{server} ? $scfg->{server} : 'localhost';
my $volume = $scfg->{volume};
- if (!glusterfs_is_mounted($server, $volume, $path, $cache->{mountdata})) {
-
+ if (!glusterfs_is_mounted($server, $volume, $path, $cache->{mountdata})) {
+
mkpath $path;
die "unable to activate storage '$storeid' - " .
my $server = $scfg->{server} ? $scfg->{server} : 'localhost';
my $volume = $scfg->{volume};
- if (glusterfs_is_mounted($server, $volume, $path, $cache->{mountdata})) {
+ if (glusterfs_is_mounted($server, $volume, $path, $cache->{mountdata})) {
my $cmd = ['/bin/umount', $path];
- run_command($cmd, errmsg => 'umount error');
+ run_command($cmd, errmsg => 'umount error');
}
}
# this only works for file based storage types
die "storage definintion has no path\n" if !$scfg->{path};
- my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =
+ my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =
$class->parse_volname($volname);
die "create_base on wrong vtype '$vtype'\n" if $vtype ne 'images';
die "file '$newpath' already exists\n" if -f $newpath;
- rename($path, $newpath) ||
+ rename($path, $newpath) ||
die "rename '$path' to '$newpath' failed - $!\n";
# We try to protect base volume
# also try to set immutable flag
eval { run_command(['/usr/bin/chattr', '+i', $newpath]); };
warn $@ if $@;
-
+
return $newvolname;
}
my ($imgdir, $vmid, $fmt) = @_;
my $disk_ids = {};
- PVE::Tools::dir_glob_foreach($imgdir,
+ PVE::Tools::dir_glob_foreach($imgdir,
qr!(vm|base)-$vmid-disk-(\d+)\..*!,
sub {
- my ($fn, $type, $disk) = @_;
+ my ($fn, $type, $disk) = @_;
$disk_ids->{$disk} = 1;
});
# this only works for file based storage types
die "storage definintion has no path\n" if !$scfg->{path};
- my ($vtype, $basename, $basevmid, undef, undef, $isBase) =
+ my ($vtype, $basename, $basevmid, undef, undef, $isBase) =
$class->parse_volname($volname);
die "clone_image on wrong vtype '$vtype'\n" if $vtype ne 'images';
my $path = $class->path($scfg, $newvol);
- # Note: we use relative paths, so we need to call chdir before qemu-img
+ # Note: we use relative paths, so we need to call chdir before qemu-img
eval {
local $CWD = $imagedir;
- my $cmd = ['/usr/bin/qemu-img', 'create', '-b', "../$basevmid/$basename",
+ my $cmd = ['/usr/bin/qemu-img', 'create', '-b', "../$basevmid/$basename",
'-f', 'qcow2', $path];
-
+
run_command($cmd);
};
my $err = $@;
mkpath $imagedir;
$name = &$find_free_diskname($imagedir, $vmid, $fmt) if !$name;
-
+
my (undef, $tmpfmt) = parse_name_dir($name);
die "illegal name '$name' - wrong extension for format ('$tmpfmt != '$fmt')\n"
push @$res, {
volid => $volid, format => $format,
- size => $size, vmid => $owner, used => $used, parent => $parent
+ size => $size, vmid => $owner, used => $used, parent => $parent
};
}