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 779556B4B4
 for <pve-devel@lists.proxmox.com>; Tue, 26 Jan 2021 12:46:14 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 5C1B715B16
 for <pve-devel@lists.proxmox.com>; Tue, 26 Jan 2021 12:45:43 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [212.186.127.180])
 (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 8D30E15995
 for <pve-devel@lists.proxmox.com>; Tue, 26 Jan 2021 12:45:36 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 342334611B
 for <pve-devel@lists.proxmox.com>; Tue, 26 Jan 2021 12:45:36 +0100 (CET)
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Tue, 26 Jan 2021 12:45:21 +0100
Message-Id: <20210126114530.8753-6-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20210126114530.8753-1-f.ebner@proxmox.com>
References: <20210126114530.8753-1-f.ebner@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.006 Adjusted score from AWL reputation of From: address
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_DNSWL_MED        -2.3 Sender listed at https://www.dnswl.org/,
 medium trust
 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]
Subject: [pve-devel] [PATCH storage 05/14] Diskmanage: introduce
 get_sysdir_size helper
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, 26 Jan 2021 11:46:14 -0000

to be used for partitions as well.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
 PVE/Diskmanage.pm                    | 18 ++++++++++++------
 test/disk_tests/usages/sdd/sdd1/size |  1 +
 test/disk_tests/usages/sdd/sdd2/size |  1 +
 test/disk_tests/usages/sde/sde1/size |  1 +
 test/disk_tests/usages/sdf/sdf1/size |  1 +
 test/disk_tests/usages/sdm/sdm1/size |  1 +
 test/disk_tests/usages/sdm/sdm9/size |  1 +
 test/disklist_test.pm                | 12 ++++++++++++
 8 files changed, 30 insertions(+), 6 deletions(-)
 create mode 100644 test/disk_tests/usages/sdd/sdd1/size
 create mode 100644 test/disk_tests/usages/sdd/sdd2/size
 create mode 100644 test/disk_tests/usages/sde/sde1/size
 create mode 100644 test/disk_tests/usages/sdf/sdf1/size
 create mode 100644 test/disk_tests/usages/sdm/sdm1/size
 create mode 100644 test/disk_tests/usages/sdm/sdm9/size

diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm
index 5672d0f..6d96e77 100644
--- a/PVE/Diskmanage.pm
+++ b/PVE/Diskmanage.pm
@@ -369,6 +369,17 @@ sub get_udev_info {
     return $data;
 }
 
+sub get_sysdir_size {
+    my ($sysdir) = @_;
+
+    my $size = file_read_firstline("$sysdir/size");
+    return if !$size;
+
+    # linux always considers sectors to be 512 bytes,
+    # independently of real block size
+    return $size * 512;
+}
+
 sub get_sysdir_info {
     my ($sysdir) = @_;
 
@@ -376,12 +387,7 @@ sub get_sysdir_info {
 
     my $data = {};
 
-    my $size = file_read_firstline("$sysdir/size");
-    return undef if !$size;
-
-    # linux always considers sectors to be 512 bytes,
-    # independently of real block size
-    $data->{size} = $size * 512;
+    $data->{size} = get_sysdir_size($sysdir) or return;
 
     # dir/queue/rotational should be 1 for hdd, 0 for ssd
     $data->{rotational} = file_read_firstline("$sysdir/queue/rotational") // -1;
diff --git a/test/disk_tests/usages/sdd/sdd1/size b/test/disk_tests/usages/sdd/sdd1/size
new file mode 100644
index 0000000..83b33d2
--- /dev/null
+++ b/test/disk_tests/usages/sdd/sdd1/size
@@ -0,0 +1 @@
+1000
diff --git a/test/disk_tests/usages/sdd/sdd2/size b/test/disk_tests/usages/sdd/sdd2/size
new file mode 100644
index 0000000..8bd1af1
--- /dev/null
+++ b/test/disk_tests/usages/sdd/sdd2/size
@@ -0,0 +1 @@
+2000
diff --git a/test/disk_tests/usages/sde/sde1/size b/test/disk_tests/usages/sde/sde1/size
new file mode 100644
index 0000000..13de30f
--- /dev/null
+++ b/test/disk_tests/usages/sde/sde1/size
@@ -0,0 +1 @@
+3000
diff --git a/test/disk_tests/usages/sdf/sdf1/size b/test/disk_tests/usages/sdf/sdf1/size
new file mode 100644
index 0000000..13de30f
--- /dev/null
+++ b/test/disk_tests/usages/sdf/sdf1/size
@@ -0,0 +1 @@
+3000
diff --git a/test/disk_tests/usages/sdm/sdm1/size b/test/disk_tests/usages/sdm/sdm1/size
new file mode 100644
index 0000000..83b33d2
--- /dev/null
+++ b/test/disk_tests/usages/sdm/sdm1/size
@@ -0,0 +1 @@
+1000
diff --git a/test/disk_tests/usages/sdm/sdm9/size b/test/disk_tests/usages/sdm/sdm9/size
new file mode 100644
index 0000000..8bd1af1
--- /dev/null
+++ b/test/disk_tests/usages/sdm/sdm9/size
@@ -0,0 +1 @@
+2000
diff --git a/test/disklist_test.pm b/test/disklist_test.pm
index 9cb6763..bfce1ea 100644
--- a/test/disklist_test.pm
+++ b/test/disklist_test.pm
@@ -87,6 +87,16 @@ sub mocked_get_sysdir_info {
     return &$originalsub($param);
 }
 
+sub mocked_get_sysdir_size {
+    my ($param) = @_;
+
+    my $originalsub = $diskmanage_module->original('get_sysdir_size');
+
+    $param =~ s|/sys/block|disk_tests/$testcasedir|;
+
+    return &$originalsub($param);
+}
+
 sub mocked_is_iscsi {
     return 0;
 }
@@ -219,6 +229,8 @@ $diskmanage_module->mock('dir_glob_foreach' => \&mocked_dir_glob_foreach);
 print("\tMocked dir_glob_foreach\n");
 $diskmanage_module->mock('get_sysdir_info' => \&mocked_get_sysdir_info);
 print("\tMocked get_sysdir_info\n");
+$diskmanage_module->mock('get_sysdir_size' => \&mocked_get_sysdir_size);
+print("\tMocked get_sysdir_size\n");
 $diskmanage_module->mock('is_iscsi' => \&mocked_is_iscsi);
 print("\tMocked is_iscsi\n");
 $diskmanage_module->mock('assert_blockdev' => sub { return 1; });
-- 
2.20.1