From: "Thomas Ellmenreich" <t.ellmenreich@proxmox.com>
To: "Max R. Carrara" <m.carrara@proxmox.com>, <pve-devel@lists.proxmox.com>
Subject: Re: [PATCH qemu-server v2 2/3] add new classify_drive_file utility
Date: Fri, 07 Aug 2026 11:54:49 +0200 [thread overview]
Message-ID: <DKIMD3QNYHQQ.RSP13C9J12CL@proxmox.com> (raw)
In-Reply-To: <DKILUOJ6LFZ7.1X2WY1PSWHQYG@proxmox.com>
On Fri Aug 7, 2026 at 11:30 AM CEST, Max R. Carrara wrote:
[snip]
>> +# Tries to classify the drive file as either 'none', 'cdrom', 'absolute'
>> +# or 'volume'. In all other cases it will return undef.
>> +sub classify_drive_file {
>> + my ($volid) = @_;
>> +
>> + if ($volid eq 'none') {
>> + return 'none';
>> + } elsif ($volid eq 'cdrom') {
>> + return 'cdrom';
>> + } elsif ($volid =~ m|^/|) {
>> + return 'absolute';
>> + } elsif (PVE::Storage::parse_volume_id($volid, 1)) {
>> + return 'volume';
>> + }
>> +
>> + return 'unknown';
>> +}
>
> Small note regarding style: While the above is completely fine (and you
> shouldn't change it!) I do wanna note that for more complex subroutines,
> I would personally prefer avoiding if-elsif chains, mainly because..
>
> 1. they tend to become a little too "packed" when it comes to reading the
> code
>
> 2. they *may* inadvertently make future changes harder if a little more
> complex logic is involved
>
> To give you an example, have a look at some of our older code in
> `pve-storage` [0] that I'm trying to refactor at the moment.
>
> Eventually I replace each branch one-by-one in my series [1], until I
> finally condense the refactored logic in (yet) another patch [2].
>
> Again, the code above is completely fine! Please don't feel like you
> have to refresh your series. I just wanted to mention it for future
> cases where the chains might be longer and the conditions are nastier :P
>
> [0]: https://git.proxmox.com/?p=pve-storage.git;a=blob;f=src/PVE/Storage/Plugin.pm;h=4f69f9b5db69674335eb3024d61d4a3430bca1ec;hb=refs/heads/master#l799
> [1]: https://lore.proxmox.com/pve-devel/20260422111322.257380-23-m.carrara@proxmox.com/#Z31src:PVE:Storage:Plugin.pm
> [2]: https://lore.proxmox.com/pve-devel/20260422111322.257380-30-m.carrara@proxmox.com/#Z31src:PVE:Storage:Plugin.pm
I totally agree, I also found the style a bit too dense for my liking, but
was not sure what the better option would be. In the future, I will try to
avoid it and go for a less "chainy" method.
Also regarding the other mail about the imperative subject, it's also a
thing I have to properly get used to. (the fullstop was a typo)
Thanks for pointing these things out. ;)
[snip]
next prev parent reply other threads:[~2026-08-07 9:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 8:21 [PATCH qemu-server v2 0/3] refactor of volume_id classification Thomas Ellmenreich
2026-08-05 8:21 ` [PATCH qemu-server v2 1/3] move verify_volume_id_or_* format registrations into Drive submodule Thomas Ellmenreich
2026-08-05 8:21 ` [PATCH qemu-server v2 2/3] add new classify_drive_file utility Thomas Ellmenreich
2026-08-07 9:30 ` Max R. Carrara
2026-08-07 9:54 ` Thomas Ellmenreich [this message]
2026-08-10 8:51 ` Elias Huhsovitz
2026-08-05 8:21 ` [PATCH qemu-server v2 3/3] removed some unnecessary undef checks Thomas Ellmenreich
2026-08-07 9:33 ` Max R. Carrara
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=DKIMD3QNYHQQ.RSP13C9J12CL@proxmox.com \
--to=t.ellmenreich@proxmox.com \
--cc=m.carrara@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.