[pve-devel] [PATCH v7 storage] Optionally allow blockdev in abs_filesystem_path

Dominic Jäger d.jaeger at proxmox.com
Fri Mar 26 13:32:25 CET 2021


This is required to import from LVM storages, for example

Signed-off-by: Dominic Jäger <d.jaeger at proxmox.com>
---
v6->v7: Feedback Fabian G
 - Variables with _ instead of camelCase
 - single if instead of if/else

 PVE/Storage.pm | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index 18c03ec..38dffdb 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -609,22 +609,22 @@ sub path {
 }
 
 sub abs_filesystem_path {
-    my ($cfg, $volid) = @_;
+    my ($cfg, $volid, $allow_blockdev) = @_;
 
     my $path;
     if (parse_volume_id ($volid, 1)) {
 	activate_volumes($cfg, [ $volid ]);
 	$path = PVE::Storage::path($cfg, $volid);
     } else {
-	if (-f $volid) {
+	if (-f $volid || ($allow_blockdev && -b $volid)) {
 	    my $abspath = abs_path($volid);
 	    if ($abspath && $abspath =~ m|^(/.+)$|) {
 		$path = $1; # untaint any path
 	    }
 	}
     }
-
-    die "can't find file '$volid'\n" if !($path && -f $path);
+    die "can't find file '$volid'\n"
+	if !($path && (-f $path || ($allow_blockdev && -b $path)));
 
     return $path;
 }
-- 
2.20.1





More information about the pve-devel mailing list