From 9bec1bff0ebc7e34ee34aff0957a6551fc2b55ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Tue, 1 Sep 2026 16:13:05 -0300 Subject: [PATCH] refactor(netboot): centralize volatile kernel arguments --- perl-xCAT/xCAT/BootUtils.pm | 18 ++++++++++++++++++ xCAT-server/lib/xcat/plugins/pxe.pm | 12 ++---------- xCAT-server/lib/xcat/plugins/xnba.pm | 12 ++---------- 3 files changed, 22 insertions(+), 20 deletions(-) create mode 100644 perl-xCAT/xCAT/BootUtils.pm diff --git a/perl-xCAT/xCAT/BootUtils.pm b/perl-xCAT/xCAT/BootUtils.pm new file mode 100644 index 000000000..ee7c4add4 --- /dev/null +++ b/perl-xCAT/xCAT/BootUtils.pm @@ -0,0 +1,18 @@ +# IBM(c) 2026 EPL license http://www.eclipse.org/legal/epl-v10.html +package xCAT::BootUtils; + +use strict; +use warnings; + +use xCAT::Utils; + +sub volatile_addkcmdline { + my ($kcmdline) = @_; + + return $kcmdline unless $kcmdline; + + my $cmdhashref = xCAT::Utils->splitkcmdline($kcmdline); + return $cmdhashref->{volatile} // ''; +} + +1; diff --git a/xCAT-server/lib/xcat/plugins/pxe.pm b/xCAT-server/lib/xcat/plugins/pxe.pm index 4b586f984..51913d854 100644 --- a/xCAT-server/lib/xcat/plugins/pxe.pm +++ b/xCAT-server/lib/xcat/plugins/pxe.pm @@ -9,6 +9,7 @@ use File::Copy; use File::Path; use Getopt::Long; require xCAT::Utils; +require xCAT::BootUtils; require xCAT::TableUtils; use xCAT::ServiceNodeUtils; my $dhcpconf = "/etc/dhcpd.conf"; @@ -114,16 +115,7 @@ sub setstate { my $kcmdlinehack = ($imgaddkcmdline) ? $kern->{addkcmdline} . " " . $imgaddkcmdline : $kern->{addkcmdline}; - my $cmdhashref; - if ($kcmdlinehack) { - $cmdhashref = xCAT::Utils->splitkcmdline($kcmdlinehack); - } - - if ($cmdhashref) { - # Use only volatile options for netboot; persistent (R::) options - # are handled separately for the installed OS via PERSKCMDLINE - $kcmdlinehack = $cmdhashref->{volatile} // ""; - } + $kcmdlinehack = xCAT::BootUtils::volatile_addkcmdline($kcmdlinehack); while ($kcmdlinehack =~ /#NODEATTRIB:([^:#]+):([^:#]+)#/) { diff --git a/xCAT-server/lib/xcat/plugins/xnba.pm b/xCAT-server/lib/xcat/plugins/xnba.pm index 2e314e02f..bbcf09be0 100644 --- a/xCAT-server/lib/xcat/plugins/xnba.pm +++ b/xCAT-server/lib/xcat/plugins/xnba.pm @@ -9,6 +9,7 @@ use xCAT::Scope; use xCAT::MsgUtils; use Getopt::Long; use xCAT::Utils; +require xCAT::BootUtils; use xCAT::TableUtils; use xCAT::ServiceNodeUtils; use xCAT::Usage; @@ -190,16 +191,7 @@ sub setstate { my $kcmdlinehack = ($imgaddkcmdline) ? $kern->{addkcmdline} . " " . $imgaddkcmdline : $kern->{addkcmdline}; - my $cmdhashref; - if ($kcmdlinehack) { - $cmdhashref = xCAT::Utils->splitkcmdline($kcmdlinehack); - } - - if ($cmdhashref) { - # Use only volatile options for netboot; persistent (R::) options - # are handled separately for the installed OS via PERSKCMDLINE - $kcmdlinehack = $cmdhashref->{volatile} // ""; - } + $kcmdlinehack = xCAT::BootUtils::volatile_addkcmdline($kcmdlinehack); while ($kcmdlinehack =~ /#NODEATTRIB:([^:#]+):([^:#]+)#/) {