[pve-devel] [PATCH v2 common 01/11] Make get_host_arch return raw uname entry
Stefan Reiter
s.reiter at proxmox.com
Tue Oct 29 09:54:10 CET 2019
On 10/29/19 7:10 AM, Thomas Lamprecht wrote:
> On 10/28/19 12:59 PM, Stefan Reiter wrote:
>> The current version had only one user in LXC, so move the LXC-specific
>> code there to reuse this in QemuServer.
>>
>> Also cache, since the host's architecture can't change during runtime.
>>
>> Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
>> ---
>> src/PVE/Tools.pm | 17 +++++------------
>> 1 file changed, 5 insertions(+), 12 deletions(-)
>>
>> diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
>> index 550da09..c9d37ec 100644
>> --- a/src/PVE/Tools.pm
>> +++ b/src/PVE/Tools.pm
>> @@ -47,6 +47,7 @@ safe_print
>> trim
>> extract_param
>> file_copy
>> +get_host_arch
>> O_PATH
>> O_TMPFILE
>> );
>> @@ -1630,18 +1631,10 @@ sub readline_nointr {
>> return $line;
>> }
>>
>> -sub get_host_arch {
>> -
>> - my @uname = POSIX::uname();
>> - my $machine = $uname[4];
>> -
>> - if ($machine eq 'x86_64') {
>> - return 'amd64';
>> - } elsif ($machine eq 'aarch64') {
>> - return 'arm64';
>> - } else {
>> - die "unsupported host architecture '$machine'\n";
>> - }
>> +my $host_arch;
>> +sub get_host_arch() {
>
> was the perl prototype wanted or was it by mistake? ^^
>
> For you and/or others information, empty prototypes suggest perl to
> inline that method, as it's seen as constant method[0].
> But here, the explicit return renders that behavior void.
> Point is, perl prototypes are confusing for most people, and are mostly
> useful to use a submethod like an built-in method..
>
> [0]: https://perldoc.perl.org/perlsub.html#Constant-Functions
>
I used the method definition as it previously was in QemuServer.pm (see
Patch 3/11). I couldn't quite wrap my head around prototypes from just
the perldoc, so I left it alone, but I think I understand it now - thanks!
>> + $host_arch = (POSIX::uname())[4] if !$host_arch;
>> + return $host_arch;
>> }
>>
>> # Devices are: [ (12 bits minor) (12 bits major) (8 bits minor) ]
>>
>
More information about the pve-devel
mailing list