From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 9F8551FF0E6 for ; Fri, 07 Aug 2026 11:54:57 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 2087F21561; Fri, 07 Aug 2026 11:54:57 +0200 (CEST) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 07 Aug 2026 11:54:49 +0200 Message-Id: Subject: Re: [PATCH qemu-server v2 2/3] add new classify_drive_file utility From: "Thomas Ellmenreich" To: "Max R. Carrara" , X-Mailer: aerc 0.20.0 References: <20260805082122.43184-1-t.ellmenreich@proxmox.com> <20260805082122.43184-3-t.ellmenreich@proxmox.com> In-Reply-To: X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1786096473502 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.864 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: DGIWLYT7OUFE775S7ZNGAC7G62VY4BEG X-Message-ID-Hash: DGIWLYT7OUFE775S7ZNGAC7G62VY4BEG X-MailFrom: t.ellmenreich@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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) =3D @_; >> + >> + if ($volid eq 'none') { >> + return 'none'; >> + } elsif ($volid eq 'cdrom') { >> + return 'cdrom'; >> + } elsif ($volid =3D~ 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=3Dpve-storage.git;a=3Dblob;f=3Dsrc/PVE/St= orage/Plugin.pm;h=3D4f69f9b5db69674335eb3024d61d4a3430bca1ec;hb=3Drefs/head= s/master#l799 > [1]: https://lore.proxmox.com/pve-devel/20260422111322.257380-23-m.carrar= a@proxmox.com/#Z31src:PVE:Storage:Plugin.pm > [2]: https://lore.proxmox.com/pve-devel/20260422111322.257380-30-m.carrar= a@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]