From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH storage 2/3] btrfs: cleanup after qgroups when deleting subvolumes
Date: Thu, 24 Jun 2021 12:01:41 +0200 [thread overview]
Message-ID: <20210624100142.108334-2-w.bumiller@proxmox.com> (raw)
In-Reply-To: <20210624100142.108334-1-w.bumiller@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
---
They literally just get leaked...
PVE/Storage/BTRFSPlugin.pm | 34 +++++++++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 5 deletions(-)
diff --git a/PVE/Storage/BTRFSPlugin.pm b/PVE/Storage/BTRFSPlugin.pm
index 179186b..ccdf3c8 100644
--- a/PVE/Storage/BTRFSPlugin.pm
+++ b/PVE/Storage/BTRFSPlugin.pm
@@ -312,6 +312,30 @@ sub clone_image {
return $newvolname;
}
+# We need to cleanup after qgroups as they just get leaked...
+my sub subvolume_delete($$@) {
+ my ($class, $scfg, @subvols) = @_;
+
+ for my $path (@subvols) {
+ my $qid = undef;
+ if ($scfg->{quotas}) {
+ eval {
+ $qid = '0/' . $class->btrfs_get_subvol_id($path);
+ };
+ warn "failed to get qgroup id for subvolume: $@\n" if $@;
+ }
+
+ $class->btrfs_cmd(['subvolume', 'delete', '--', $path]);
+
+ if (defined($qid)) {
+ eval {
+ $class->btrfs_cmd(['qgroup', 'destroy', '--', $qid, $scfg->{path}]);
+ };
+ warn "failed to destroy qgroup: $@\n" if $@;
+ }
+ }
+}
+
sub alloc_image {
my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
@@ -372,7 +396,7 @@ sub alloc_image {
};
if (my $err = $@) {
- eval { $class->btrfs_cmd(['subvolume', 'delete', '--', $subvol]); };
+ eval { subvolume_delete($class, $scfg, $subvol); };
warn $@ if $@;
die $err;
}
@@ -428,7 +452,7 @@ sub free_image {
push @snapshot_vols, "$dir/$volume";
});
- $class->btrfs_cmd(['subvolume', 'delete', '--', @snapshot_vols, $subvol]);
+ subvolume_delete($class, $scfg, @snapshot_vols, $subvol);
# try to cleanup directory to not clutter storage with empty $vmid dirs if
# all images from a guest got deleted
rmdir($dir);
@@ -550,7 +574,7 @@ sub volume_snapshot_rollback {
# The paths are absolute, so pass -1 as file descriptors.
my $ok = PVE::Tools::renameat2(-1, $tmp_path, -1, $path, &PVE::Tools::RENAME_EXCHANGE);
- eval { $class->btrfs_cmd(['subvolume', 'delete', '--', $tmp_path]) };
+ eval { subvolume_delete($class, $scfg, $tmp_path) };
warn "failed to remove '$tmp_path' subvolume: $@" if $@;
if (!$ok) {
@@ -575,7 +599,7 @@ sub volume_snapshot_delete {
$path = raw_file_to_subvol($path);
}
- $class->btrfs_cmd(['subvolume', 'delete', '--', $path]);
+ subvolume_delete($class, $scfg, $path);
return undef;
}
@@ -910,7 +934,7 @@ sub volume_import {
$dh->rewind;
while (defined(my $entry = $dh->read)) {
next if $entry eq '.' || $entry eq '..';
- eval { $class->btrfs_cmd(['subvolume', 'delete', '--', "$tmppath/$entry"]) };
+ eval { subvolume_delete($class, $scfg, "$tmppath/$entry") };
warn $@ if $@;
}
$dh->close; undef $dh;
--
2.30.2
next prev parent reply other threads:[~2021-06-24 10:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-24 10:01 [pve-devel] [PATCH v3 storage 1/3] btrfs: support quota-based subvols optionally Wolfgang Bumiller
2021-06-24 10:01 ` Wolfgang Bumiller [this message]
2021-06-24 10:01 ` [pve-devel] [PATCH storage 3/3] btrfs: fix qgroup id and size in volume resize Wolfgang Bumiller
2021-06-24 10:18 ` [pve-devel] [PATCH v3 storage 1/3] btrfs: support quota-based subvols optionally Fabian Grünbichler
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=20210624100142.108334-2-w.bumiller@proxmox.com \
--to=w.bumiller@proxmox.com \
--cc=pve-devel@lists.proxmox.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.