From: Alexandre Derumier via pve-devel <pve-devel@lists.proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Alexandre Derumier <alexandre.derumier@groupe-cyllene.com>
Subject: [pve-devel] [PATCH pve-storage 1/5] add lvmqcow2 plugin
Date: Mon, 26 Aug 2024 13:00:19 +0200 [thread overview]
Message-ID: <mailman.400.1724670042.302.pve-devel@lists.proxmox.com> (raw)
In-Reply-To: <20240826110030.1744732-1-alexandre.derumier@groupe-cyllene.com>
[-- Attachment #1: Type: message/rfc822, Size: 10132 bytes --]
From: Alexandre Derumier <alexandre.derumier@groupe-cyllene.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-storage 1/5] add lvmqcow2 plugin
Date: Mon, 26 Aug 2024 13:00:19 +0200
Message-ID: <20240826110030.1744732-2-alexandre.derumier@groupe-cyllene.com>
Signed-off-by: Alexandre Derumier <alexandre.derumier@groupe-cyllene.com>
---
src/PVE/Storage.pm | 2 +
src/PVE/Storage/LVMQcow2Plugin.pm | 218 ++++++++++++++++++++++++++++++
src/PVE/Storage/Makefile | 3 +-
3 files changed, 222 insertions(+), 1 deletion(-)
create mode 100644 src/PVE/Storage/LVMQcow2Plugin.pm
diff --git a/src/PVE/Storage.pm b/src/PVE/Storage.pm
index 57b2038..97e77c8 100755
--- a/src/PVE/Storage.pm
+++ b/src/PVE/Storage.pm
@@ -40,6 +40,7 @@ use PVE::Storage::ZFSPlugin;
use PVE::Storage::PBSPlugin;
use PVE::Storage::BTRFSPlugin;
use PVE::Storage::ESXiPlugin;
+use PVE::Storage::LVMQcow2Plugin;
# Storage API version. Increment it on changes in storage API interface.
use constant APIVER => 10;
@@ -66,6 +67,7 @@ PVE::Storage::ZFSPlugin->register();
PVE::Storage::PBSPlugin->register();
PVE::Storage::BTRFSPlugin->register();
PVE::Storage::ESXiPlugin->register();
+PVE::Storage::LVMQcow2Plugin->register();
# load third-party plugins
if ( -d '/usr/share/perl5/PVE/Storage/Custom' ) {
diff --git a/src/PVE/Storage/LVMQcow2Plugin.pm b/src/PVE/Storage/LVMQcow2Plugin.pm
new file mode 100644
index 0000000..bdb21cc
--- /dev/null
+++ b/src/PVE/Storage/LVMQcow2Plugin.pm
@@ -0,0 +1,218 @@
+package PVE::Storage::LVMQcow2Plugin;
+
+use strict;
+use warnings;
+
+use IO::File;
+
+use PVE::Tools qw(run_command trim);
+use PVE::Storage::Plugin;
+use PVE::Storage::LVMPlugin;
+use PVE::JSONSchema qw(get_standard_option);
+
+use base qw(PVE::Storage::LVMPlugin);
+
+sub type {
+ return 'lvmqcow2';
+}
+
+sub plugindata {
+ return {
+ content => [ {images => 1, rootdir => 1}, { images => 1, rootdir => 1}],
+ };
+}
+
+sub properties {
+
+ return {
+ chunksize => {
+ description => "Size of extension chunk in Gigabytes. (default 1GB)",
+ type => 'integer',
+ default => 1,
+ minimum => 1,
+ optional => 1,
+ },
+ chunk_pct_extension => {
+ description => "Percentage usage of the last chunk before trigger extent. (default 50%)",
+ type => 'integer',
+ default => 50,
+ minimum => 1,
+ optional => 1,
+ }
+
+ };
+}
+
+sub options {
+ return {
+ vgname => { fixed => 1 },
+ nodes => { optional => 1 },
+ disable => { optional => 1 },
+ content => { optional => 1 },
+ bwlimit => { optional => 1 },
+ preallocation => { optional => 1 },
+ shared => { optional => 1 },
+ chunksize => { optional => 1 },
+ sparse => { optional => 1 },
+ };
+}
+
+
+sub default_format {
+ my ($scfg) = @_;
+
+ return 'qcow2';
+}
+
+sub find_free_diskname {
+ my ($class, $storeid, $scfg, $vmid, $fmt, $add_fmt_suffix) = @_;
+
+ my $vg = $scfg->{vgname};
+
+ my $lvs = PVE::Storage::LVMPlugin::lvm_list_volumes($vg);
+
+ my $disk_list = [ keys %{$lvs->{$vg}} ];
+
+ return PVE::Storage::Plugin::get_next_vm_diskname($disk_list, $storeid, $vmid, 'qcow2', $scfg, 1);
+}
+
+sub alloc_image {
+ my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
+
+ my $sparse = $scfg->{sparse};
+
+ my $chunksize = $scfg->{chunksize} // 1;
+ $chunksize *= 1024000;
+
+ #set minimum size to chunksize
+ my $lv_size = $chunksize;
+
+ #if no provisioning, $lv_size = $size + a extra chunk for metadatas overhead
+ $lv_size = $size + $chunksize if !$sparse;
+
+ die "illegal name '$name' - should be 'vm-$vmid-*'\n"
+ if $name && $name !~ m/^vm-$vmid-/;
+
+ my $vgs = PVE::Storage::LVMPlugin::lvm_vgs();
+
+ my $vg = $scfg->{vgname};
+
+ die "no such volume group '$vg'\n" if !defined ($vgs->{$vg});
+
+ my $free = int($vgs->{$vg}->{free});
+
+ die "not enough free space ($free < $lv_size)\n" if $free < $lv_size;
+
+ $name = $class->find_free_diskname($storeid, $scfg, $vmid)
+ if !$name;
+
+ PVE::Storage::LVMPlugin::lvcreate($vg, $name, $lv_size, ["pve-vm-$vmid"]);
+
+ #activate
+ $class->activate_volume($storeid, $scfg, $name, undef, {});
+
+ #format the lv with qcow2 with virtualsize (we can't preallocate for sparse image)
+ my $path = $class->path($scfg, $name);
+ my $cmd = ['/usr/bin/qemu-img', 'create'];
+
+ my $options = "extended_l2=on,cluster_size=128k";
+ #only metadata can be preallocated qcow2 on block device
+ $options .= ",preallocation=metadata" if !$sparse;
+
+ push @$cmd, '-o', $options;
+
+ push @$cmd, '-f', 'qcow2', $path, "${size}K";
+ run_command($cmd, errmsg => "unable to format image");
+
+ #desactivate
+ $class->deactivate_volume($storeid, $scfg, $name, undef, {});
+
+ return $name;
+}
+
+sub volume_size_info {
+ my ($class, $scfg, $storeid, $volname, $timeout) = @_;
+
+ my $path = $class->filesystem_path($scfg, $volname);
+
+ my $json = eval {
+ my $json = '';
+ run_command(['/usr/bin/qemu-img', 'measure', $path, '-O', 'qcow2', '--output=json'],
+ timeout => 5,
+ outfunc => sub { $json .= $_[0]; },
+ errfunc => sub { warn "$_[0]\n"; }
+ );
+ from_json($json)
+ };
+ die $@ if $@;
+
+ my $used = $json->{required};
+ my $size = $json->{'fully-allocated'};
+
+ return wantarray ? ($size, 'raw', $used, undef) : $size;
+}
+
+sub volume_resize {
+ my ($class, $scfg, $storeid, $volname, $size, $running) = @_;
+
+ return PVE::Storage::Plugin::volume_resize($class, $scfg, $storeid, $volname, $size, $running);
+}
+
+sub clone_image {
+ my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
+
+ die "not implemented";
+}
+
+sub create_base {
+ my ($class, $storeid, $scfg, $volname) = @_;
+
+ die "not implemented";
+}
+
+sub volume_snapshot {
+ my ($class, $scfg, $storeid, $volname, $snap) = @_;
+
+ return PVE::Storage::Plugin::volume_snapshot($class, $scfg, $storeid, $volname, $snap);
+}
+
+sub volume_snapshot_rollback {
+ my ($class, $scfg, $storeid, $volname, $snap) = @_;
+
+ return PVE::Storage::Plugin::volume_snapshot_rollback($class, $scfg, $storeid, $volname, $snap);
+}
+
+sub volume_snapshot_delete {
+ my ($class, $scfg, $storeid, $volname, $snap, $running) = @_;
+
+ return PVE::Storage::Plugin::volume_snapshot_delete($class, $scfg, $storeid, $volname, $snap, $running);
+}
+
+sub volume_has_feature {
+ my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running) = @_;
+
+ my $features = {
+ snapshot => { current => 1 },
+ clone => { base => 1, snap => 1},
+ template => { current => 1},
+ copy => { base => 1, current => 1, snap => 1},
+ sparseinit => { base => 1, current => 1},
+ rename => {current => 1},
+ };
+
+ my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =
+ $class->parse_volname($volname);
+
+ my $key = undef;
+ if($snapname){
+ $key = 'snap';
+ }else{
+ $key = $isBase ? 'base' : 'current';
+ }
+ return 1 if $features->{$feature}->{$key};
+
+ return undef;
+}
+
+1;
+
diff --git a/src/PVE/Storage/Makefile b/src/PVE/Storage/Makefile
index d5cc942..f5d40bf 100644
--- a/src/PVE/Storage/Makefile
+++ b/src/PVE/Storage/Makefile
@@ -14,7 +14,8 @@ SOURCES= \
PBSPlugin.pm \
BTRFSPlugin.pm \
LvmThinPlugin.pm \
- ESXiPlugin.pm
+ ESXiPlugin.pm \
+ LVMQcow2Plugin.pm
.PHONY: install
install:
--
2.39.2
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next parent reply other threads:[~2024-08-26 11:00 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20240826110030.1744732-1-alexandre.derumier@groupe-cyllene.com>
2024-08-26 11:00 ` Alexandre Derumier via pve-devel [this message]
2024-08-26 11:00 ` [pve-devel] [PATCH qemu-server 1/6] lvmqcow2: set disk write threshold Alexandre Derumier via pve-devel
2024-08-26 11:00 ` [pve-devel] [PATCH pve-manager 1/1] pvestatd: lvmqcow2 : extend disk on io-error Alexandre Derumier via pve-devel
2024-08-26 11:00 ` [pve-devel] [PATCH qemu-server 2/6] qm cli: add blockextend Alexandre Derumier via pve-devel
2024-08-26 11:00 ` [pve-devel] [PATCH pve-storage 2/5] vdisk_alloc: add underlay_size option Alexandre Derumier via pve-devel
2024-08-26 11:00 ` [pve-devel] [PATCH pve-storage 3/5] add volume_underlay_resize Alexandre Derumier via pve-devel
2024-08-26 11:00 ` [pve-devel] [PATCH qemu-server 3/6] qmevent: call qm disk blockextend when write_threshold event is received Alexandre Derumier via pve-devel
2024-08-26 11:00 ` [pve-devel] [PATCH pve-storage 4/5] add refresh volume Alexandre Derumier via pve-devel
2024-08-26 11:00 ` [pve-devel] [PATCH qemu-server 4/6] migration: refresh remote disk size before resume Alexandre Derumier via pve-devel
2024-08-26 11:00 ` [pve-devel] [PATCH pve-storage 5/5] add volume_underlay_shrink Alexandre Derumier via pve-devel
2024-08-26 11:00 ` [pve-devel] [PATCH qemu-server 5/6] qemu_img_format: lvmqcow2 is a path_storage Alexandre Derumier via pve-devel
2024-08-26 11:00 ` [pve-devel] [PATCH qemu-server 6/6] clone: allocate && shrink lvmcow2 underlay Alexandre Derumier via pve-devel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=mailman.400.1724670042.302.pve-devel@lists.proxmox.com \
--to=pve-devel@lists.proxmox.com \
--cc=alexandre.derumier@groupe-cyllene.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox