public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: Lukas Sichert <l.sichert@proxmox.com>, pve-devel@lists.proxmox.com
Subject: Re: [PATCH storage v8 1/5] lvm: saferemove: keep LVs where zero-out failed for manual zero-out
Date: Fri, 10 Jul 2026 11:26:29 +0200	[thread overview]
Message-ID: <34a010cd-1a88-4dc0-bb92-6e8377e99dbe@proxmox.com> (raw)
In-Reply-To: <20260707143252.101757-2-l.sichert@proxmox.com>

Am 07.07.26 um 4:32 PM schrieb Lukas Sichert:
> Currently even if 'zeroout' fails, the LV is removed and can't be zeroed
> out manually later.
> 
> Let zeroing errors propagate from the secure delete command, and rename
> failed removals to a 'failed-<N>-del-*' LV name instead of immediately
> removing them.
> 
> Signed-off-by: Lukas Sichert <l.sichert@proxmox.com>
> ---
>  src/PVE/Storage/LVMPlugin.pm | 70 +++++++++++++++++++++++++-----------
>  1 file changed, 50 insertions(+), 20 deletions(-)
> 
> diff --git a/src/PVE/Storage/LVMPlugin.pm b/src/PVE/Storage/LVMPlugin.pm
> index a313ecc..a0feb5c 100644
> --- a/src/PVE/Storage/LVMPlugin.pm
> +++ b/src/PVE/Storage/LVMPlugin.pm
> @@ -7,6 +7,7 @@ use Cwd qw(abs_path);
>  use File::Basename;
>  use IO::File;
>  use JSON;
> +use List::Util qw(max);
>  
>  use PVE::JSONSchema qw(get_standard_option);
>  use PVE::Tools qw(run_command file_read_firstline trim);
> @@ -327,13 +328,10 @@ my sub free_lvm_volumes_locked {
>                  '-t',
>                  "$throughput",
>              ];
> -            eval {
> -                run_command(
> -                    $cmd,
> -                    errmsg => "zero out finished (note: 'No space left on device' is ok here)",
> -                );
> -            };
> -            warn $@ if $@;
> +            run_command(
> +                $cmd,
> +                errmsg => "zero out finished (note: 'No space left on device' is ok here)",
> +            );

Removing the eval is not okay here. Otherwise a successful cleanup,
which is expected to fail with ENOSPC, will also be treated as a
failure. You would need to detect the kind of error (but it's not worth
it, since your following patches replace the 'dd' invocation anyways :)

>          } else {
>              # If the storage supports write_zeroes but stepsize is too big, reduce the stepsize to
>              # the maximum supported by the storage.
> @@ -345,8 +343,7 @@ my sub free_lvm_volumes_locked {
>              }
>  
>              my $cmd = ['blkdiscard', $lvmpath, '-v', '--zeroout', '--step', "${stepsize}"];
> -            eval { run_command($cmd); };
> -            warn $@ if $@;
> +            run_command($cmd);
>          }
>      };
>  
> @@ -368,18 +365,51 @@ my sub free_lvm_volumes_locked {
>                  errmsg => "can't refresh LV '$lvmpath' to zero-out its data",
>              );
>  
> -            $secure_delete_cmd->($lvmpath);
> +            eval { $secure_delete_cmd->($lvmpath); };
> +            if (my $cleanup_err = $@) {
> +                my $failed_name;
> +                $class->cluster_lock_storage(
> +                    $storeid,
> +                    $scfg->{shared},
> +                    undef,
> +                    sub {
> +                        my $lvs = lvm_list_volumes();
> +                        my $existing = $lvs->{$vg} // {};
> +
> +                        my $prefix = 'failed-';
> +                        my $suffix = "-del-$name";
> +
> +                        my $last_fail = max(
> +                            0,

Nit: we usually start counting with 0 for disk numbers, so this could
also be -1. But not really important, and both variants are fine by me.

> +                            map {
> +                                /^\Q$prefix\E(\d+)\Q$suffix\E$/ ? $1 : ()
> +                            } keys %$existing,
> +                        );
> +
> +                        $failed_name = 'failed-' . ($last_fail + 1) . $suffix;
> +
> +                        my $cmd = ['/sbin/lvrename', $vg, "del-$name", $failed_name];
> +                        run_command(
> +                            $cmd,
> +                            errmsg => "lvrename '$vg/del-$name' to '$vg/$failed_name' error",
> +                        );
> +                    },
> +                );

Maybe have a private helper function for the stuff in the if branch
here? It's not super long, but together with everything else (also from
the next patches) the free_lvm_volumes_locked() does become rather big.

>  
> -            $class->cluster_lock_storage(
> -                $storeid,
> -                $scfg->{shared},
> -                undef,
> -                sub {
> -                    my $cmd = ['/sbin/lvremove', '-f', "$vg/del-$name"];
> -                    run_command($cmd, errmsg => "lvremove '$vg/del-$name' error");
> -                },
> -            );
> -            print "successfully removed volume $name ($vg/del-$name)\n";
> +                die "cleanup failed for lv $name: $cleanup_err\n";
> +
> +            } else {
> +                $class->cluster_lock_storage(
> +                    $storeid,
> +                    $scfg->{shared},
> +                    undef,
> +                    sub {
> +                        my $cmd = ['/sbin/lvremove', '-f', "$vg/del-$name"];
> +                        run_command($cmd, errmsg => "lvremove '$vg/del-$name' error");
> +                    },
> +                );
> +                print "successfully removed volume $name ($vg/del-$name)\n";
> +            }
>          }
>      };
>  





  parent reply	other threads:[~2026-07-10  9:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07 14:32 [PATCH docs/manager/storage v8 0/5] fix #7339: lvmthick: add option to free storage for deleted VMs Lukas Sichert
2026-07-07 14:32 ` [PATCH storage v8 1/5] lvm: saferemove: keep LVs where zero-out failed for manual zero-out Lukas Sichert
2026-07-08 16:25   ` Michael Köppl
2026-07-10  9:26   ` Fiona Ebner [this message]
2026-07-07 14:32 ` [PATCH storage v8 2/5] lvm: saferemove: zero out volumes range by range Lukas Sichert
2026-07-08 16:26   ` Michael Köppl
2026-07-10 10:20   ` Fiona Ebner
2026-07-07 14:32 ` [PATCH storage v8 3/5] fix #7339: lvm: add discard action for removed volumes Lukas Sichert
2026-07-10 11:49   ` Fiona Ebner
2026-07-07 14:32 ` [PATCH manager v8 4/5] fix #7339: lvmthick: ui: add UI option to free storage Lukas Sichert
2026-07-07 14:32 ` [PATCH docs v8 5/5] fix #7339: lvm: document discard option Lukas Sichert
2026-07-08 16:35 ` [PATCH docs/manager/storage v8 0/5] fix #7339: lvmthick: add option to free storage for deleted VMs Michael Köppl

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=34a010cd-1a88-4dc0-bb92-6e8377e99dbe@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=l.sichert@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal