]> git.proxmox.com Git - pve-storage.git/commitdiff
new method volume_is_base() to check if volume is a base volume
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 31 Jan 2013 07:42:26 +0000 (08:42 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 31 Jan 2013 07:42:26 +0000 (08:42 +0100)
PVE/Storage.pm

index 78a14f90b98f8f5bebf4428f3e48dd26dafb8825..9bb8185251a976379e5cc86a3bd252840a0872e5 100755 (executable)
@@ -268,6 +268,27 @@ sub parse_volume_id {
     die "unable to parse volume ID '$volid'\n";
 }
 
+sub volume_is_base {
+    my ($cfg, $volid) = @_;
+
+    my ($sid, $volname) = parse_volume_id($volid, 1);
+    return 0 if !$sid;
+
+    if (my $scfg = $cfg->{ids}->{$sid}) {
+       my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+       my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) = 
+           $plugin->parse_volname($volname);
+       return $isBase ? 1 : 0;
+    } else {
+       # stale volid with undefined storage - so we can just guess
+       if ($volid =~ m/base-/) {
+           return 1;
+       }
+    }
+
+    return 0;
+}
+
 # try to map a filesystem path to a volume identifier
 sub path_to_volume_id {
     my ($cfg, $path) = @_;