Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 101b917

Browse files
committed
Reuse nqn if previously configured
1 parent e555d42 commit 101b917

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

bb/scripts/bbactivate.pl

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,23 @@ sub makeProxyConfigFile
466466
delete $json->{"bb"}{"server0"} if(!$CFG{"bbServer"});
467467
}
468468

469+
sub cacheRandomName
470+
{
471+
my($nqn) = @_;
472+
($key) = $nqn =~ /(.*)#/;
473+
$OLDSTATE{$key} = $nqn;
474+
}
475+
469476
sub genRandomName
470477
{
478+
my($name) = @_;
479+
return $OLDSTATE{$name} if(exists $OLDSTATE{$name});
480+
471481
my $string;
472482
my @chars = ("a".."z", 0..9);
473483
$string .= $chars[rand @chars] for 1..16;
474-
return $string;
484+
485+
return $name . "#" . $string;
475486
}
476487

477488
sub configureNVMeTarget
@@ -518,6 +529,15 @@ sub configureNVMeTarget
518529
return;
519530
}
520531
output("NVMe over Fabrics target has already been configured. Clearing potentially stale NVMe over Fabrics target configuration");
532+
533+
my $cleanup = 1;
534+
$cleanup = 0 if($CFG{"skip"} =~ /cleanup/);
535+
my ($fh, $tmpname) = tempfile(SUFFIX => ".nvmet.json", UNLINK => $cleanup);
536+
safe_cmd("nvmetcli save $tmpname");
537+
my $oldnvmetjson = cat($tmpname);
538+
$oldjson = decode_json($oldnvmetjson);
539+
cacheRandomName($oldjson->{"hosts"}[0]{"nqn"});
540+
cacheRandomName($oldjson->{"hosts"}[1]{"nqn"});
521541
cmd("nvmetcli clear", 1);
522542
}
523543

@@ -539,11 +559,11 @@ sub configureNVMeTarget
539559
$state = "enabled" if($CFG{"useOffload"});
540560
output("NVMe over Fabrics target offload is $state");
541561

542-
$json->{"hosts"}[0]{"nqn"} = $cfgfile->{"bb"}{"proxy"}{"servercfg"} . "#" . &genRandomName();
562+
$json->{"hosts"}[0]{"nqn"} = &genRandomName($cfgfile->{"bb"}{"proxy"}{"servercfg"});
543563
$json->{"subsystems"}[0]{"allowed_hosts"}[0] = $json->{"hosts"}[0]{"nqn"};
544564
if($cfgfile->{"bb"}{"proxy"}{"backupcfg"} ne "")
545565
{
546-
$json->{"hosts"}[1]{"nqn"} = $cfgfile->{"bb"}{"proxy"}{"backupcfg"} . "#" . &genRandomName();
566+
$json->{"hosts"}[1]{"nqn"} = &genRandomName($cfgfile->{"bb"}{"proxy"}{"backupcfg"});
547567
$json->{"subsystems"}[0]{"allowed_hosts"}[1] = $json->{"hosts"}[1]{"nqn"};
548568
}
549569
$json->{"ports"}[0]{"addr"}{"traddr"} = $myip;

0 commit comments

Comments
 (0)