Skip to content

Commit 3c4bde4

Browse files
Create symbolic link after device tree is set
The commit creates API to set sym link to system config JSON once device tree is set. This is required because in existing code if VPD_SYMLIMK_PATH is not found and fitconfig value is also not correctly set at the same time, then symlink is created first and then code flow goes to set fitconfig and reboot. It never goes into the flow to set asset tag with factory reset flag set. Hence asset tag never gets updated. Test: Clear sym link path, set fitconfig to some default value clear asset tag data from system inventory path reboot the system. Introspect the system inventory path. Asset tag interface and data should be visible. xyz.openbmc_project.Inventory.Decorator.AssetTag interface - - - .AssetTag property s "Server-9043-MRX-13E8D2X" emits-change writable Signed-off-by: Sunny Srivastava <[email protected]>
1 parent 9f1a13a commit 3c4bde4

File tree

2 files changed

+48
-56
lines changed

2 files changed

+48
-56
lines changed

vpd-manager/include/worker.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,16 @@ class Worker
486486
*/
487487
void primeSystemBlueprint();
488488

489+
/**
490+
* @brief API to set symbolic link for system config JSON.
491+
*
492+
* Once correct device tree is set, symbolic link to the correct sytsem
493+
* config JSON is set to be used in subsequent BMC boot.
494+
*
495+
* @param[in] i_systemJson - system config JSON.
496+
*/
497+
void setJsonSymbolicLink(const std::string& i_systemJson);
498+
489499
// Parsed JSON file.
490500
nlohmann::json m_parsedJson{};
491501

vpd-manager/src/worker.cpp

Lines changed: 38 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -423,34 +423,49 @@ static void setEnvAndReboot(const std::string& key, const std::string& value)
423423
bus.call_noreply(method);
424424
}
425425

426-
void Worker::setDeviceTreeAndJson()
426+
void Worker::setJsonSymbolicLink(const std::string& i_systemJson)
427427
{
428-
std::error_code ec;
429-
ec.clear();
430-
if (!std::filesystem::exists(VPD_SYMLIMK_PATH, ec))
428+
std::error_code l_ec;
429+
l_ec.clear();
430+
if (!std::filesystem::exists(VPD_SYMLIMK_PATH, l_ec))
431431
{
432-
if (ec)
432+
if (l_ec)
433433
{
434434
throw std::runtime_error(
435435
"File system call to exist failed with error = " +
436-
ec.message());
436+
l_ec.message());
437437
}
438438

439439
// implies it is a fresh boot/factory reset.
440440
// Create the directory for hosting the symlink
441-
if (!std::filesystem::create_directories(VPD_SYMLIMK_PATH, ec))
441+
if (!std::filesystem::create_directories(VPD_SYMLIMK_PATH, l_ec))
442442
{
443-
if (ec)
443+
if (l_ec)
444444
{
445445
throw std::runtime_error(
446446
"File system call to create directory failed with error = " +
447-
ec.message());
447+
l_ec.message());
448448
}
449449
}
450+
}
450451

451-
m_isFactoryResetDone = true;
452+
// create a new symlink based on the system
453+
std::filesystem::create_symlink(i_systemJson, INVENTORY_JSON_SYM_LINK,
454+
l_ec);
455+
456+
if (l_ec)
457+
{
458+
throw std::runtime_error(
459+
"create_symlink system call failed with error: " + l_ec.message());
452460
}
453461

462+
// If the flow is at this point implies the symlink was not present there.
463+
// Considering this as factory reset.
464+
m_isFactoryResetDone = true;
465+
}
466+
467+
void Worker::setDeviceTreeAndJson()
468+
{
454469
// JSON is madatory for processing of this API.
455470
if (m_parsedJson.empty())
456471
{
@@ -460,14 +475,16 @@ void Worker::setDeviceTreeAndJson()
460475
types::VPDMapVariant parsedVpdMap;
461476
fillVPDMap(SYSTEM_VPD_FILE_PATH, parsedVpdMap);
462477

463-
// ToDo: Need to check is INVENTORY_JSON_SYM_LINK pointing to correct system
464-
// JSON or not, if the sym link exists already.
478+
// Implies it is default JSON.
479+
std::string systemJson{JSON_ABSOLUTE_PATH_PREFIX};
480+
481+
// ToDo: Need to check if INVENTORY_JSON_SYM_LINK pointing to correct system
482+
// This is required to support movement from rainier to Blue Ridge on the
483+
// fly.
465484

466485
// Do we have the entry for device tree in parsed JSON?
467486
if (m_parsedJson.find("devTree") == m_parsedJson.end())
468487
{
469-
// Implies it is default JSON.
470-
std::string systemJson{JSON_ABSOLUTE_PATH_PREFIX};
471488
getSystemJson(systemJson, parsedVpdMap);
472489

473490
if (!systemJson.compare(JSON_ABSOLUTE_PATH_PREFIX))
@@ -476,51 +493,10 @@ void Worker::setDeviceTreeAndJson()
476493
throw DataException("Error in getting system JSON.");
477494
}
478495

479-
// create a new symlink based on the system
480-
std::filesystem::create_symlink(systemJson, INVENTORY_JSON_SYM_LINK,
481-
ec);
482-
if (ec)
483-
{
484-
if (ec.value() == EEXIST)
485-
{
486-
ec.clear();
487-
logging::logMessage(
488-
"Sym link already exists, file [" +
489-
std::string(INVENTORY_JSON_SYM_LINK) +
490-
"] deleting and creating sym link again, target file: " +
491-
systemJson);
492-
493-
if (std::filesystem::remove(INVENTORY_JSON_SYM_LINK, ec))
494-
{
495-
std::filesystem::create_symlink(
496-
systemJson, INVENTORY_JSON_SYM_LINK, ec);
497-
if (ec)
498-
{
499-
throw std::runtime_error(
500-
"create_symlink system call failed when deleting existing link and recreating it again, error: " +
501-
ec.message());
502-
}
503-
}
504-
else
505-
{
506-
logging::logMessage(
507-
"remove system call failed for file[" +
508-
std::string(INVENTORY_JSON_SYM_LINK) + "], error[" +
509-
ec.message() + "], continuing with existing sym link.");
510-
}
511-
}
512-
else
513-
{
514-
throw std::runtime_error(
515-
"create_symlink system call failed with error: " +
516-
ec.message());
517-
}
518-
}
519-
520496
// re-parse the JSON once appropriate JSON has been selected.
521497
try
522498
{
523-
m_parsedJson = jsonUtility::getParsedJson(INVENTORY_JSON_SYM_LINK);
499+
m_parsedJson = jsonUtility::getParsedJson(systemJson);
524500
}
525501
catch (const nlohmann::json::parse_error& ex)
526502
{
@@ -549,6 +525,12 @@ void Worker::setDeviceTreeAndJson()
549525
{ // Skipping setting device tree as either devtree info is missing from
550526
// Json or it is rightly set.
551527

528+
// avoid setting symlink on every reboot.
529+
if (!m_isSymlinkPresent)
530+
{
531+
setJsonSymbolicLink(systemJson);
532+
}
533+
552534
if (isSystemVPDOnDBus() &&
553535
jsonUtility::isBackupAndRestoreRequired(m_parsedJson))
554536
{

0 commit comments

Comments
 (0)