From 6fffd1ef376ed1cbbb021c88e3fbf0b31c40ba89 Mon Sep 17 00:00:00 2001 From: Dominik Hassler Date: Fri, 27 Oct 2023 16:20:16 +0000 Subject: [PATCH] add support for cpu attribute for kvm brand --- cpanfile | 10 +- lib/Zadm/Privilege.pm | 2 + lib/Zadm/Schema/Bhyve.pm | 3 +- lib/Zadm/Schema/KVM.pm | 7 + lib/Zadm/Utils.pm | 2 + lib/Zadm/Validator.pm | 26 +++- test/lib/perl5/Sun/Solaris/Privilege.pm | 7 +- thirdparty/cpanfile-5.36.snapshot | 163 ++++++++++++------------ 8 files changed, 128 insertions(+), 92 deletions(-) diff --git a/cpanfile b/cpanfile index 2ffc6e9..003ef91 100644 --- a/cpanfile +++ b/cpanfile @@ -1,12 +1,12 @@ requires 'Bytes::Random::Secure::Tiny', '== 1.011'; -requires 'Cpanel::JSON::XS', '== 4.36'; +requires 'Cpanel::JSON::XS', '== 4.37'; requires 'Curses::UI', '== 0.9609'; requires 'Data::Processor', '== 1.0.9'; -requires 'Mojolicious', '== 9.32'; +requires 'Mojolicious', '== 9.34'; requires 'IO::Socket::SSL', '== 2.083'; -requires 'IO::Uncompress::UnXz', '== 2.204'; -requires 'IO::Uncompress::UnZstd', '== 2.204'; +requires 'IO::Uncompress::UnXz', '== 2.206'; +requires 'IO::Uncompress::UnZstd', '== 2.206'; requires 'Regexp::IPv4', '== 0.003'; requires 'Regexp::IPv6', '== 0.03'; -requires 'TOML::Tiny', '== 0.15'; +requires 'TOML::Tiny', '== 0.16'; requires 'YAML::XS', '== 0.88'; diff --git a/lib/Zadm/Privilege.pm b/lib/Zadm/Privilege.pm index c059989..33d570a 100644 --- a/lib/Zadm/Privilege.pm +++ b/lib/Zadm/Privilege.pm @@ -32,6 +32,8 @@ my $getPrivSet = sub { priv_addset($targprivs, PRIV_FILE_DAC_WRITE) if $set ne 'empty'; # We keep FILE_DAC_READ if the caller has it priv_addset($targprivs, PRIV_FILE_DAC_READ) if $set ne 'empty'; + # We keep FILE_OWNER if the caller has it + priv_addset($targprivs, PRIV_FILE_OWNER) if $set ne 'empty'; # get the current permitted privileges my $curprivs = getppriv(PRIV_PERMITTED); diff --git a/lib/Zadm/Schema/Bhyve.pm b/lib/Zadm/Schema/Bhyve.pm index 5c6ced1..5767c26 100644 --- a/lib/Zadm/Schema/Bhyve.pm +++ b/lib/Zadm/Schema/Bhyve.pm @@ -6,7 +6,8 @@ has schema => sub($self) { my $kvmschema = $self->SUPER::schema; # we need to drop these parent entries since merging would result in checking parent validators too; # the additional options from the bhyve brand would fail the check from the parent - delete $kvmschema->{$_} for qw(bootorder diskif netif vnc); + # also dropping attributes not supported by the bhyve brand (e.g. cpu) + delete $kvmschema->{$_} for qw(bootorder cpu diskif netif vnc); my $dp = Data::Processor->new($kvmschema); my $ec = $dp->merge_schema($self->$SCHEMA); diff --git a/lib/Zadm/Schema/KVM.pm b/lib/Zadm/Schema/KVM.pm index 05ae807..fcd8ecc 100644 --- a/lib/Zadm/Schema/KVM.pm +++ b/lib/Zadm/Schema/KVM.pm @@ -85,6 +85,13 @@ $SCHEMA = sub($self) { validator => $self->sv->regexp(qr/^.+$/, 'expected a string'), 'x-attr' => 1, }, + cpu => { + optional => 1, + description => 'emulated CPU and features', + example => '"cpu" : "qemu64,+aes,+sse4.2,+sse4.1,+ssse3"', + validator => $self->sv->qemuCPUtype, + 'x-attr' => 1, + }, disk => { optional => 1, array => 1, diff --git a/lib/Zadm/Utils.pm b/lib/Zadm/Utils.pm index 42244cf..a4f0b22 100644 --- a/lib/Zadm/Utils.pm +++ b/lib/Zadm/Utils.pm @@ -125,6 +125,8 @@ my %CMDS = ( dd => '/usr/bin/dd', uefivars => '/opt/ooce/bin/uefivars', bhyve_boot => '/usr/lib/brand/bhyve/boot', + qemu => '/usr/bin/qemu-system-x86_64', + isainfo => '/usr/bin/isainfo', ); my %ENVARGS = map { diff --git a/lib/Zadm/Validator.pm b/lib/Zadm/Validator.pm index 828ac3b..c6669f2 100644 --- a/lib/Zadm/Validator.pm +++ b/lib/Zadm/Validator.pm @@ -479,6 +479,30 @@ sub cloudinit($self) { } } +sub qemuCPUtype($self) { + return sub($cpuType, @) { + my $cpuTypes = $self->utils->readProc('qemu', [ qw(-cpu ?) ]); + s/^x86\s+\[?|\]$//g for @$cpuTypes; + + my $cpuFeatures = $self->utils->readProc('isainfo', [ qw(-x) ]); + my ($featStr) = map { /^amd64:\s+(.+)$/ } @$cpuFeatures; + my @features = map { "+$_" } split /\s+/, $featStr; + + my @cpuType = split /,/, $cpuType; + + my $typeInvalid = $self->elemOf(@$cpuTypes)->(shift @cpuType); + return $typeInvalid if length ($typeInvalid); + + for my $feature (@cpuType) { + my $featureInvalid = $self->elemOf(@features)->($feature); + + return $featureInvalid if length ($featureInvalid); + } + + return undef; + } +} + sub stringorfile($self) { return sub($arg, @) { return $self->file('<', 'No such file,')->($arg) if Mojo::File->new($arg)->is_abs; @@ -499,7 +523,7 @@ __END__ =head1 COPYRIGHT -Copyright 2022 OmniOS Community Edition (OmniOSce) Association. +Copyright 2023 OmniOS Community Edition (OmniOSce) Association. =head1 LICENSE diff --git a/test/lib/perl5/Sun/Solaris/Privilege.pm b/test/lib/perl5/Sun/Solaris/Privilege.pm index 9000bf8..534712f 100644 --- a/test/lib/perl5/Sun/Solaris/Privilege.pm +++ b/test/lib/perl5/Sun/Solaris/Privilege.pm @@ -8,6 +8,7 @@ use constant { PRIV_EFFECTIVE => 'Effective', PRIV_FILE_DAC_READ => 'file_dac_read', PRIV_FILE_DAC_WRITE => 'file_dac_write', + PRIV_FILE_OWNER => 'file_owner', PRIV_INHERITABLE => 'Inheritable', PRIV_LIMIT => 'Limit', PRIV_OFF => 1, @@ -21,8 +22,8 @@ use constant { }; my @constants = qw(PRIV_DEBUG PRIV_EFFECTIVE PRIV_FILE_DAC_READ PRIV_FILE_DAC_WRITE - PRIV_INHERITABLE PRIV_LIMIT PRIV_NET_ACCESS PRIV_OFF PRIV_ON PRIV_PERMITTED - PRIV_SET PRIV_STR_LIT PRIV_STR_PORT PRIV_SYS_DL_CONFIG PRIV_SYS_MOUNT); + PRIV_FILE_OWNER PRIV_INHERITABLE PRIV_LIMIT PRIV_NET_ACCESS PRIV_OFF PRIV_ON + PRIV_PERMITTED PRIV_SET PRIV_STR_LIT PRIV_STR_PORT PRIV_SYS_DL_CONFIG PRIV_SYS_MOUNT); our @EXPORT_OK = (@constants, qw(getppriv priv_addset priv_emptyset priv_fillset priv_intersect priv_set_to_str priv_str_to_set setpflags setppriv)); @@ -44,7 +45,7 @@ __END__ =head1 COPYRIGHT -Copyright 2022 OmniOS Community Edition (OmniOSce) Association. +Copyright 2023 OmniOS Community Edition (OmniOSce) Association. =head1 LICENSE diff --git a/thirdparty/cpanfile-5.36.snapshot b/thirdparty/cpanfile-5.36.snapshot index 7f8bfc4..0880c1f 100644 --- a/thirdparty/cpanfile-5.36.snapshot +++ b/thirdparty/cpanfile-5.36.snapshot @@ -11,22 +11,22 @@ DISTRIBUTIONS ExtUtils::MakeMaker 6.56 Test::More 0.98 perl 5.008000 - Compress-Raw-Bzip2-2.204 - pathname: P/PM/PMQS/Compress-Raw-Bzip2-2.204.tar.gz + Compress-Raw-Bzip2-2.206 + pathname: P/PM/PMQS/Compress-Raw-Bzip2-2.206.tar.gz provides: - Compress::Raw::Bzip2 2.204 + Compress::Raw::Bzip2 2.206 requirements: ExtUtils::MakeMaker 0 - Compress-Raw-Lzma-2.204 - pathname: P/PM/PMQS/Compress-Raw-Lzma-2.204.tar.gz + Compress-Raw-Lzma-2.206 + pathname: P/PM/PMQS/Compress-Raw-Lzma-2.206.tar.gz provides: - Compress::Raw::Lzma 2.204 + Compress::Raw::Lzma 2.206 requirements: ExtUtils::MakeMaker 0 - Compress-Raw-Zlib-2.204 - pathname: P/PM/PMQS/Compress-Raw-Zlib-2.204.tar.gz + Compress-Raw-Zlib-2.206 + pathname: P/PM/PMQS/Compress-Raw-Zlib-2.206.tar.gz provides: - Compress::Raw::Zlib 2.204 + Compress::Raw::Zlib 2.206 requirements: ExtUtils::MakeMaker 0 Compress-Stream-Zstd-0.206 @@ -45,10 +45,10 @@ DISTRIBUTIONS Module::Build 0.4005 parent 0 perl 5.008001 - Cpanel-JSON-XS-4.36 - pathname: R/RU/RURBAN/Cpanel-JSON-XS-4.36.tar.gz + Cpanel-JSON-XS-4.37 + pathname: R/RU/RURBAN/Cpanel-JSON-XS-4.37.tar.gz provides: - Cpanel::JSON::XS 4.36 + Cpanel::JSON::XS 4.37 Cpanel::JSON::XS::Type undef requirements: Carp 0 @@ -144,79 +144,79 @@ DISTRIBUTIONS requirements: ExtUtils::MakeMaker 0 perl 5.008005 - IO-Compress-2.204 - pathname: P/PM/PMQS/IO-Compress-2.204.tar.gz + IO-Compress-2.206 + pathname: P/PM/PMQS/IO-Compress-2.206.tar.gz provides: - Compress::Zlib 2.204 + Compress::Zlib 2.206 File::GlobMapper 1.001 IO::Compress undef - IO::Compress::Adapter::Bzip2 2.204 - IO::Compress::Adapter::Deflate 2.204 - IO::Compress::Adapter::Identity 2.204 - IO::Compress::Base 2.204 - IO::Compress::Base::Common 2.204 - IO::Compress::Bzip2 2.204 - IO::Compress::Deflate 2.204 - IO::Compress::Gzip 2.204 - IO::Compress::Gzip::Constants 2.204 - IO::Compress::RawDeflate 2.204 - IO::Compress::Zip 2.204 - IO::Compress::Zip::Constants 2.204 - IO::Compress::Zlib::Constants 2.204 - IO::Compress::Zlib::Extra 2.204 - IO::Uncompress::Adapter::Bunzip2 2.204 - IO::Uncompress::Adapter::Identity 2.204 - IO::Uncompress::Adapter::Inflate 2.204 - IO::Uncompress::AnyInflate 2.204 - IO::Uncompress::AnyUncompress 2.204 - IO::Uncompress::Base 2.204 - IO::Uncompress::Bunzip2 2.204 - IO::Uncompress::Gunzip 2.204 - IO::Uncompress::Inflate 2.204 - IO::Uncompress::RawInflate 2.204 - IO::Uncompress::Unzip 2.204 - U64 2.204 - Zlib::OldDeflate 2.204 - Zlib::OldInflate 2.204 + IO::Compress::Adapter::Bzip2 2.206 + IO::Compress::Adapter::Deflate 2.206 + IO::Compress::Adapter::Identity 2.206 + IO::Compress::Base 2.206 + IO::Compress::Base::Common 2.206 + IO::Compress::Bzip2 2.206 + IO::Compress::Deflate 2.206 + IO::Compress::Gzip 2.206 + IO::Compress::Gzip::Constants 2.206 + IO::Compress::RawDeflate 2.206 + IO::Compress::Zip 2.206 + IO::Compress::Zip::Constants 2.206 + IO::Compress::Zlib::Constants 2.206 + IO::Compress::Zlib::Extra 2.206 + IO::Uncompress::Adapter::Bunzip2 2.206 + IO::Uncompress::Adapter::Identity 2.206 + IO::Uncompress::Adapter::Inflate 2.206 + IO::Uncompress::AnyInflate 2.206 + IO::Uncompress::AnyUncompress 2.206 + IO::Uncompress::Base 2.206 + IO::Uncompress::Bunzip2 2.206 + IO::Uncompress::Gunzip 2.206 + IO::Uncompress::Inflate 2.206 + IO::Uncompress::RawInflate 2.206 + IO::Uncompress::Unzip 2.206 + U64 2.206 + Zlib::OldDeflate 2.206 + Zlib::OldInflate 2.206 requirements: - Compress::Raw::Bzip2 2.204 - Compress::Raw::Zlib 2.204 + Compress::Raw::Bzip2 2.206 + Compress::Raw::Zlib 2.206 Encode 0 ExtUtils::MakeMaker 0 Scalar::Util 0 Time::Local 0 - IO-Compress-Lzma-2.204 - pathname: P/PM/PMQS/IO-Compress-Lzma-2.204.tar.gz + IO-Compress-Lzma-2.206 + pathname: P/PM/PMQS/IO-Compress-Lzma-2.206.tar.gz provides: - IO::Compress::Adapter::Lzip 2.204 - IO::Compress::Adapter::Lzma 2.204 - IO::Compress::Adapter::Xz 2.204 - IO::Compress::Lzip 2.204 - IO::Compress::Lzma 2.204 - IO::Compress::Xz 2.204 - IO::Uncompress::Adapter::UnLzip 2.204 - IO::Uncompress::Adapter::UnLzma 2.204 - IO::Uncompress::Adapter::UnXz 2.204 - IO::Uncompress::UnLzip 2.204 - IO::Uncompress::UnLzma 2.204 - IO::Uncompress::UnXz 2.204 + IO::Compress::Adapter::Lzip 2.206 + IO::Compress::Adapter::Lzma 2.206 + IO::Compress::Adapter::Xz 2.206 + IO::Compress::Lzip 2.206 + IO::Compress::Lzma 2.206 + IO::Compress::Xz 2.206 + IO::Uncompress::Adapter::UnLzip 2.206 + IO::Uncompress::Adapter::UnLzma 2.206 + IO::Uncompress::Adapter::UnXz 2.206 + IO::Uncompress::UnLzip 2.206 + IO::Uncompress::UnLzma 2.206 + IO::Uncompress::UnXz 2.206 requirements: - Compress::Raw::Lzma 2.204 + Compress::Raw::Lzma 2.206 ExtUtils::MakeMaker 0 - IO::Compress::Base 2.204 - IO::Uncompress::Base 2.204 - IO-Compress-Zstd-2.204 - pathname: P/PM/PMQS/IO-Compress-Zstd-2.204.tar.gz + IO::Compress::Base 2.206 + IO::Uncompress::Base 2.206 + IO-Compress-Zstd-2.206 + pathname: P/PM/PMQS/IO-Compress-Zstd-2.206.tar.gz provides: - IO::Compress::Adapter::Zstd 2.204 - IO::Compress::Zstd 2.204 - IO::Uncompress::Adapter::UnZstd 2.204 - IO::Uncompress::UnZstd 2.204 + IO::Compress::Adapter::Zstd 2.206 + IO::Compress::Zstd 2.206 + IO::Uncompress::Adapter::UnZstd 2.206 + IO::Uncompress::UnZstd 2.206 requirements: Compress::Stream::Zstd 0 ExtUtils::MakeMaker 0 - IO::Compress::Base 2.204 - IO::Uncompress::Base 2.204 + IO::Compress::Base 2.206 + IO::Uncompress::Base 2.206 IO-Socket-SSL-2.083 pathname: S/SU/SULLR/IO-Socket-SSL-2.083.tar.gz provides: @@ -280,8 +280,8 @@ DISTRIBUTIONS Text::ParseWords 0 perl 5.006001 version 0.87 - Mojolicious-9.32 - pathname: S/SR/SRI/Mojolicious-9.32.tar.gz + Mojolicious-9.34 + pathname: S/SR/SRI/Mojolicious-9.34.tar.gz provides: Mojo undef Mojo::Asset undef @@ -349,7 +349,7 @@ DISTRIBUTIONS Mojo::UserAgent::Transactor undef Mojo::Util undef Mojo::WebSocket undef - Mojolicious 9.32 + Mojolicious 9.34 Mojolicious::Command undef Mojolicious::Command::Author::cpanify undef Mojolicious::Command::Author::generate undef @@ -372,7 +372,6 @@ DISTRIBUTIONS Mojolicious::Lite undef Mojolicious::Plugin undef Mojolicious::Plugin::Config undef - Mojolicious::Plugin::Config::Sandbox undef Mojolicious::Plugin::DefaultHelpers undef Mojolicious::Plugin::EPLRenderer undef Mojolicious::Plugin::EPRenderer undef @@ -434,15 +433,15 @@ DISTRIBUTIONS Regexp::IPv6 0.03 requirements: ExtUtils::MakeMaker 0 - TOML-Tiny-0.15 - pathname: J/JE/JEFFOBER/TOML-Tiny-0.15.tar.gz + TOML-Tiny-0.16 + pathname: O/OA/OALDERS/TOML-Tiny-0.16.tar.gz provides: - TOML::Tiny 0.15 - TOML::Tiny::Grammar 0.15 - TOML::Tiny::Parser 0.15 - TOML::Tiny::Tokenizer 0.15 - TOML::Tiny::Util 0.15 - TOML::Tiny::Writer 0.15 + TOML::Tiny 0.16 + TOML::Tiny::Grammar 0.16 + TOML::Tiny::Parser 0.16 + TOML::Tiny::Tokenizer 0.16 + TOML::Tiny::Util 0.16 + TOML::Tiny::Writer 0.16 requirements: Carp 0 Data::Dumper 0