]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Diskmanage.pm
buildsys: no need to include arch detection for arch-independent package
[pve-storage.git] / PVE / Diskmanage.pm
index e1db2ae67c803af87a031d92bb64810f8000706c..de3e60e02146fc841826a491353127e3e088e29d 100644 (file)
@@ -79,8 +79,11 @@ sub get_smart_data {
 
     my $returncode = 0;
 
-    $disk =~ s/n\d+$//
-        if $disk =~ m!^/dev/nvme\d+n\d+$!;
+    if ($disk =~ m!^/dev/(nvme\d+n\d+)$!) {
+       my $info = get_sysdir_info("/sys/block/$1");
+       $disk = "/dev/".($info->{device}
+           or die "failed to get nvme controller device for $disk\n");
+    }
 
     my $cmd = [$SMARTCTL, '-H'];
     push @$cmd, '-A', '-f', 'brief' if !$healthonly;
@@ -149,6 +152,8 @@ sub get_smart_data {
 sub get_zfs_devices {
     my $list = {};
 
+    return {} if ! -x $ZPOOL;
+
     # use zpool and parttype uuid,
     # because log and cache do not have
     # zfs type uuid
@@ -306,6 +311,11 @@ sub get_sysdir_info {
     $data->{vendor} = file_read_firstline("$sysdir/device/vendor") || 'unknown';
     $data->{model} = file_read_firstline("$sysdir/device/model") || 'unknown';
 
+    if (defined(my $device = readlink("$sysdir/device"))) {
+       # strip directory and untaint:
+       ($data->{device}) = $device =~ m!([^/]+)$!;
+    }
+
     return $data;
 }
 
@@ -363,6 +373,16 @@ sub dir_is_empty {
     return 1;
 }
 
+sub is_iscsi {
+    my ($sysdir) = @_;
+
+    if (-l $sysdir && readlink($sysdir) =~ m|host[^/]*/session[^/]*|) {
+       return 1;
+    }
+
+    return 0;
+}
+
 sub get_disks {
     my ($disk, $nosmart) = @_;
     my $disklist = {};
@@ -413,7 +433,7 @@ sub get_disks {
        my $sysdir = "/sys/block/$dev";
 
        # we do not want iscsi devices
-       return if -l $sysdir && readlink($sysdir) =~ m|host[^/]*/session[^/]*|;
+       return if is_iscsi($sysdir);
 
        my $sysdata = get_sysdir_info($sysdir);
        return if !defined($sysdata);
@@ -456,6 +476,14 @@ sub get_disks {
 
        $used = 'ZFS' if $zfslist->{$devpath};
 
+       # we replaced cciss/ with cciss! above
+       # but in the result we need cciss/ again
+       # because the caller might want to check the
+       # result again with the original parameter
+       if ($dev =~ m|^cciss!|) {
+           $dev =~ s|^cciss!|cciss/|;
+       }
+
        $disklist->{$dev} = {
            vendor => $sysdata->{vendor},
            model => $data->{model} || $sysdata->{model},
@@ -550,8 +578,8 @@ sub get_partnum {
     my ($mode, $rdev) = (stat($part_path))[2,6];
 
     next if !$mode || !S_ISBLK($mode) || !$rdev;
-    my $major = int($rdev / 0x100);
-    my $minor = $rdev % 0x100;
+    my $major = PVE::Tools::dev_t_major($rdev);
+    my $minor = PVE::Tools::dev_t_minor($rdev);
     my $partnum_path = "/sys/dev/block/$major:$minor/";
 
     my $partnum;
@@ -587,4 +615,19 @@ sub get_blockdev {
     return $block_dev;
 }
 
+sub locked_disk_action {
+    my ($sub) = @_;
+    my $res = PVE::Tools::lock_file('/run/lock/pve-diskmanage.lck', undef, $sub);
+    die $@ if $@;
+    return $res;
+}
+
+sub assert_disk_unused {
+    my ($dev) = @_;
+
+    die "device '$dev' is already in use\n" if disk_is_used($dev);
+
+    return undef;
+}
+
 1;