]> git.proxmox.com Git - pve-storage.git/commitdiff
Diskmanage: add append_partition sub
authorDominik Csapak <d.csapak@proxmox.com>
Tue, 4 Jun 2019 10:35:23 +0000 (12:35 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 4 Jun 2019 10:51:44 +0000 (12:51 +0200)
we will use this for adding a partition to a disk when using a device
for ceph osd db/wal which already has partitions on it

first we search for the highest partition number, then add the partition
and search for the resulting device (we cannot assume to simply
append the number, e.g. from /dev/nvme0n1 we get /dev/nvme0n1pX)

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
PVE/Diskmanage.pm

index 281b378e5fdac79d6a24f41f5446ad7ec7bf5092..5e337474954d23dc387211362ea472bb2e631866 100644 (file)
@@ -680,4 +680,37 @@ sub assert_disk_unused {
     return undef;
 }
 
+sub append_partition {
+    my ($dev, $size) = @_;
+
+    my $devname = $dev;
+    $devname =~ s|^/dev/||;
+
+    my $newpartid = 1;
+    dir_glob_foreach("/sys/block/$devname", qr/\Q$devname\E.*?(\d+)/, sub {
+       my ($part, $partid) = @_;
+
+       if ($partid >= $newpartid) {
+           $newpartid = $partid + 1;
+       }
+    });
+
+    $size = PVE::Tools::convert_size($size, 'b' => 'mb');
+
+    run_command([ $SGDISK, '-n', "$newpartid:0:+${size}M", $dev ],
+               errmsg => "error creating partition '$newpartid' on '$dev'");
+
+    my $partition;
+
+    # loop again to detect the real partiton device which does not always follow
+    # a strict $devname$partition scheme like /dev/nvme0n1 -> /dev/nvme0n1p1
+    dir_glob_foreach("/sys/block/$devname", qr/\Q$devname\E.*$newpartid/, sub {
+       my ($part) = @_;
+
+       $partition = "/dev/$part";
+    });
+
+    return $partition;
+}
+
 1;