5
0
mirror of git://git.proxmox.com/git/pve-storage.git synced 2025-01-11 05:18:01 +03:00

Diskmanage: introduce get_sysdir_size helper

to be used for partitions as well.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
This commit is contained in:
Fabian Ebner 2021-01-26 12:45:21 +01:00 committed by Thomas Lamprecht
parent 59c03cd970
commit 40be5c5cab
8 changed files with 30 additions and 6 deletions

View File

@ -368,6 +368,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) = @_;
@ -375,12 +386,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;

View File

@ -0,0 +1 @@
1000

View File

@ -0,0 +1 @@
2000

View File

@ -0,0 +1 @@
3000

View File

@ -0,0 +1 @@
3000

View File

@ -0,0 +1 @@
1000

View File

@ -0,0 +1 @@
2000

View File

@ -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; });