Skip to content

Commit

Permalink
Merge pull request #141 from hadfl/cpu
Browse files Browse the repository at this point in the history
add support for cpu attribute for kvm brand
  • Loading branch information
oetiker authored Oct 29, 2023
2 parents 2224214 + 6fffd1e commit cf03730
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 92 deletions.
10 changes: 5 additions & 5 deletions cpanfile
Original file line number Diff line number Diff line change
@@ -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';
2 changes: 2 additions & 0 deletions lib/Zadm/Privilege.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion lib/Zadm/Schema/Bhyve.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions lib/Zadm/Schema/KVM.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions lib/Zadm/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
26 changes: 25 additions & 1 deletion lib/Zadm/Validator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -499,7 +523,7 @@ __END__
=head1 COPYRIGHT
Copyright 2022 OmniOS Community Edition (OmniOSce) Association.
Copyright 2023 OmniOS Community Edition (OmniOSce) Association.
=head1 LICENSE
Expand Down
7 changes: 4 additions & 3 deletions test/lib/perl5/Sun/Solaris/Privilege.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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));
Expand All @@ -44,7 +45,7 @@ __END__
=head1 COPYRIGHT
Copyright 2022 OmniOS Community Edition (OmniOSce) Association.
Copyright 2023 OmniOS Community Edition (OmniOSce) Association.
=head1 LICENSE
Expand Down
163 changes: 81 additions & 82 deletions thirdparty/cpanfile-5.36.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cf03730

Please sign in to comment.