From mboxrd@z Thu Jan 1 00:00:00 1970
Return-Path: <f.ebner@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits))
(No client certificate requested)
by lists.proxmox.com (Postfix) with ESMTPS id 12E8A6D786
for <pve-devel@lists.proxmox.com>; Tue, 28 Sep 2021 13:40:50 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
by firstgate.proxmox.com (Proxmox) with ESMTP id CC867DE71
for <pve-devel@lists.proxmox.com>; Tue, 28 Sep 2021 13:40:12 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
[94.136.29.106])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits))
(No client certificate requested)
by firstgate.proxmox.com (Proxmox) with ESMTPS id 4C350DCB1
for <pve-devel@lists.proxmox.com>; Tue, 28 Sep 2021 13:40:06 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 18B6344B2D
for <pve-devel@lists.proxmox.com>; Tue, 28 Sep 2021 13:40:06 +0200 (CEST)
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Tue, 28 Sep 2021 13:39:49 +0200
Message-Id: <20210928114001.164081-10-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20210928114001.164081-1-f.ebner@proxmox.com>
References: <20210928114001.164081-1-f.ebner@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results: 0
AWL 0.308 Adjusted score from AWL reputation of From: address
BAYES_00 -1.9 Bayes spam probability is 0 to 1%
KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record
SPF_PASS -0.001 SPF: sender matches SPF record
URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
information. [diskmanage.pm, directory.pm, zfs.pm]
Subject: [pve-devel] [PATCH storage 09/10] partially fix #2285: api: disks:
allow partitions for creation paths
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>,
<mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>,
<mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Tue, 28 Sep 2021 11:40:50 -0000
The calls for directory and ZFS need slight adaptations. Except for
those, the only thing that needs to be done is support partitions in
the disk_is_used helper.
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
PVE/API2/Disks/Directory.pm | 28 ++++++++++++++++------------
PVE/API2/Disks/ZFS.pm | 11 ++++++++++-
PVE/Diskmanage.pm | 2 +-
3 files changed, 27 insertions(+), 14 deletions(-)
diff --git a/PVE/API2/Disks/Directory.pm b/PVE/API2/Disks/Directory.pm
index 1285274..52f0c86 100644
--- a/PVE/API2/Disks/Directory.pm
+++ b/PVE/API2/Disks/Directory.pm
@@ -214,20 +214,24 @@ __PACKAGE__->register_method ({
PVE::Diskmanage::locked_disk_action(sub {
PVE::Diskmanage::assert_disk_unused($dev);
- # create partition
- my $cmd = [$SGDISK, '-n1', '-t1:8300', $dev];
- print "# ", join(' ', @$cmd), "\n";
- run_command($cmd);
-
- my ($devname) = $dev =~ m|^/dev/(.*)$|;
- my $part = "/dev/";
- dir_glob_foreach("/sys/block/$devname", qr/\Q$devname\E.+/, sub {
- my ($partition) = @_;
- $part .= $partition;
- });
+ my $part = $dev;
+
+ if (!PVE::Diskmanage::is_partition($dev)) {
+ # create partition
+ my $cmd = [$SGDISK, '-n1', '-t1:8300', $dev];
+ print "# ", join(' ', @$cmd), "\n";
+ run_command($cmd);
+
+ my ($devname) = $dev =~ m|^/dev/(.*)$|;
+ $part = "/dev/";
+ dir_glob_foreach("/sys/block/$devname", qr/\Q$devname\E.+/, sub {
+ my ($partition) = @_;
+ $part .= $partition;
+ });
+ }
# create filesystem
- $cmd = [$MKFS, '-t', $type, $part];
+ my $cmd = [$MKFS, '-t', $type, $part];
print "# ", join(' ', @$cmd), "\n";
run_command($cmd);
diff --git a/PVE/API2/Disks/ZFS.pm b/PVE/API2/Disks/ZFS.pm
index 1534631..6486404 100644
--- a/PVE/API2/Disks/ZFS.pm
+++ b/PVE/API2/Disks/ZFS.pm
@@ -373,7 +373,16 @@ __PACKAGE__->register_method ({
PVE::Diskmanage::locked_disk_action(sub {
for my $dev (@$devs) {
PVE::Diskmanage::assert_disk_unused($dev);
- my $sysfsdev = $dev =~ s!^/dev/!/sys/block/!r;
+
+ my $is_partition = PVE::Diskmanage::is_partition($dev);
+ my $sysfsdev = $is_partition ? PVE::Diskmanage::get_blockdev($dev) : $dev;
+
+ $sysfsdev =~ s!^/dev/!/sys/block/!;
+ if ($is_partition) {
+ my $part = $dev =~ s!^/dev/!!r;
+ $sysfsdev .= "/${part}";
+ }
+
my $udevinfo = PVE::Diskmanage::get_udev_info($sysfsdev);
$dev = $udevinfo->{by_id_link} if defined($udevinfo->{by_id_link});
}
diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm
index f0e14dc..18459f9 100644
--- a/PVE/Diskmanage.pm
+++ b/PVE/Diskmanage.pm
@@ -78,7 +78,7 @@ sub disk_is_used {
my $dev = $disk;
$dev =~ s|^/dev/||;
- my $disklist = get_disks($dev, 1);
+ my $disklist = get_disks($dev, 1, 1);
die "'$disk' is not a valid local disk\n" if !defined($disklist->{$dev});
return 1 if $disklist->{$dev}->{used};
--
2.30.2