storage plugin and lvmplugin

This commit is contained in:
Tiago Sousa 2025-10-10 12:28:31 +01:00
parent 24bb59b858
commit dc575e9585
3 changed files with 55 additions and 23 deletions

View file

@ -462,6 +462,24 @@ sub volume_size_info {
}
}
sub volume_resize {
my ($cfg, $volid, $size, $running) = @_;
my $padding = (1024 - $size % 1024) % 1024;
$size = $size + $padding;
my ($storeid, $volname) = parse_volume_id($volid, 1);
if ($storeid) {
my $scfg = storage_config($cfg, $storeid);
my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
return $plugin->volume_resize($scfg, $storeid, $volname, $size, $running);
} elsif ($volid =~ m|^(/.+)$| && -e $volid) {
die "resize file/device '$volid' is not possible\n";
} else {
die "unable to parse volume ID '$volid'\n";
}
}
sub volume_underlay_size_info {
my ($cfg, $volid, $timeout) = @_;
@ -475,17 +493,14 @@ sub volume_underlay_size_info {
}
}
sub volume_resize {
my ($cfg, $volid, $size, $running) = @_;
my $padding = (1024 - $size % 1024) % 1024;
$size = $size + $padding;
sub volume_underlay_resize {
my ($cfg, $volid, $size, $running, $backing_snap) = @_;
my ($storeid, $volname) = parse_volume_id($volid, 1);
if ($storeid) {
my $scfg = storage_config($cfg, $storeid);
my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
return $plugin->volume_resize($scfg, $storeid, $volname, $size, $running);
return $plugin->volume_underlay_resize($scfg, $storeid, $volname, $size, $running, $backing_snap);
} elsif ($volid =~ m|^(/.+)$| && -e $volid) {
die "resize file/device '$volid' is not possible\n";
} else {

View file

@ -11,6 +11,7 @@ use PVE::Storage::Plugin;
use PVE::JSONSchema qw(get_standard_option);
use PVE::Storage::Common;
use PVE::SafeSyslog;
use JSON;
@ -583,7 +584,7 @@ my sub lvm_qcow2_format {
my $options = {
preallocation => PVE::Storage::Plugin::preallocation_cmd_opt($scfg, $fmt),
};
if ($thin) {
if ($backing_snap) {
my $backing_volname = get_snap_name($class, $name, $backing_snap);
# TODO: make this variable a check box when taking a snapshot
PVE::Storage::Common::qemu_img_create_qcow2_backed(
@ -648,8 +649,8 @@ my sub alloc_lvm_image {
return if $fmt ne 'qcow2';
my $thin = $backing_snap ? 1 : 0;
#format the lvm volume with qcow2 format
my $thin = 1;
eval { lvm_qcow2_format($class, $storeid, $scfg, $name, $fmt, $backing_snap, $size, $thin) };
if ($@) {
my $err = $@;
@ -948,27 +949,36 @@ sub volume_resize {
}
sub volume_underlay_resize {
my ($class, $scfg, $storeid, $volname) = @_;
my ($class, $scfg, $storeid, $volname, $backing_snap) = @_;
my ($format) = ($class->parse_volname($volname))[6];
# extend underlay lv
# need to check if next size is going to surpass the qemu img
# need to check if next size is going to surpass the qcow2 virtual size
# if so need to calculate the final size with calculate_lvm_size
# by using qemu_img_info
my $path = $class->filesystem_path($scfg, $volname);
my $json = PVE::Storage::Common::qemu_img_info($path, undef, 10, 0);
my $virtual_size = int($json->{'virtual-size'});
my $json_decode = eval { decode_json($json) };
if ($@) {
die "Can't decode qemu snapshot list. Invalid JSON: $@\n";
}
my $virtual_size = int($json_decode->{'virtual-size'} / 1024);
syslog("info", "current qcow2 virtual size $virtual_size B\n");
my $underlay_size = lv_size($path, 10);
# FIX: 1GiB increment needs to change to a configurable var $scfg->{block_size}
my $updated_underlay_size = $underlay_size + (1024 * 1024 * 1024);
$updated_underlay_size = calculate_lvm_size($virtual_size / 1024, $format, $backing_snap)
syslog("info", "current underlay size $underlay_size B\n ");
# FIX: 1GiB increment needs to change to a configurable var $scfg->{chunk_size}
my $updated_underlay_size = ($underlay_size + (1024 * 1024 * 1024)) / 1024;
syslog("info", "current updated underlay size $updated_underlay_size KiB\n");
$updated_underlay_size = calculate_lvm_size($virtual_size, $format, $backing_snap)
if $updated_underlay_size >= $virtual_size;
syslog("info", "current updated underlay size $updated_underlay_size KiB\n");
my $lvmsize = "${updated_underlay_size}k";
lv_extend($class,$scfg,$storeid,$lvmsize,$path);
lv_extend($class, $scfg, $storeid, $lvmsize, $path);
return 1;
return $updated_underlay_size;
}
sub lv_extend {

View file

@ -1267,13 +1267,6 @@ sub volume_size_info {
return file_size_info($path, $timeout, $format);
}
sub volume_underlay_size_info {
my ($class, $scfg, $storeid, $volname, $timeout) = @_;
# Only supported by LVM for now
die "volume underlay is not supported for storage type '$scfg->{type}'\n"
}
sub volume_resize {
my ($class, $scfg, $storeid, $volname, $size, $running) = @_;
@ -1291,6 +1284,20 @@ sub volume_resize {
return undef;
}
sub volume_underlay_size_info {
my ($class, $scfg, $storeid, $volname, $timeout) = @_;
# Only supported by LVM for now
die "volume underlay is not supported for storage type '$scfg->{type}'\n";
}
sub volume_underlay_resize {
my ($class, $scfg, $storeid, $volname, $backing_snap) = @_;
# Only supported by LVM for now
die "volume underlay is not supported for storage type '$scfg->{type}'\n";
}
sub volume_snapshot {
my ($class, $scfg, $storeid, $volname, $snap) = @_;