bmc: ItemUpdater: Erase tmp folder in erase()
When bmcweb's `redfish-updateservice-use-dbus` is enabled and
`software-update-dbus-interface` option is enabled for this repo,
firmware update to bios_active target via Redfish will be handled by
bmc/ItemUpdater class. During the verification to create new software
objects in `ItemUpdater::verifyAndCreateObjects()`,
`ItemUpdater::erase()` is registered as the erasing callback when
`.Delete` method is called for the software object.
However, in `ItemUpdater::erase()`, in terms of image data, it only
erases RO partition and persist data for BMC image. For BIOS image, it
leaves off the temporary image folder of the software entry under
`$IMG_UPLOAD_DIR` (aka `/tmp/images/`), which can lead to memory leak
issue if BIOS firmware update is performed multiple times without BMC
reboot.
This commit handles removing the temporary image folder in
`ItemUpdater::erase()` for non-BMC firmware image when
`useUpdateDBusInterface` is true, which means this ItemUpdater object is
created when `software-update-dbus-interface` option is enabled.
Tested:
1. Execute BIOS firmware upgrade via Redfish
token=`curl -k -H "Content-Type: application/json" -X POST \
https://${BMC_IP}/login -d '{"username" : "root", "password" : \
"0penBmc"}' | grep token | awk '{print $2;}' | tr -d '"'`
uri=$(curl -k -H "X-Auth-Token: $token" \
https://${BMC_IP}/redfish/v1/UpdateService | jq -r ' \
.MultipartHttpPushUri')
curl -k -H "X-Auth-Token: $token" \
-H "Content-Type:multipart/form-data" -X POST \
-F UpdateParameters="{\"Targets\":[\
"/redfish/v1/UpdateService/FirmwareInventory/bios_active\"], \
"@Redfish.OperationApplyTime\":\"OnReset\"};type=application/json"\
-F "UpdateFile=@${IMG_PATH}" https://${BMC_IP}${uri}
Expected that upon upgrade completion, the newly added BIOS software
entry is removed from D-Bus, and the image folder with the software
entry name under `/tmp/images/` is removed too.
Change-Id: I7208cf2381af7db75bfd3cec99b0b891efa91cc8
Signed-off-by: Chau Ly <chaul@amperecomputing.com>
diff --git a/bmc/item_updater.cpp b/bmc/item_updater.cpp
index 02c20c7..41ae150 100644
--- a/bmc/item_updater.cpp
+++ b/bmc/item_updater.cpp
@@ -536,6 +536,15 @@
removePersistDataDirectory(flashId);
helper.clearEntry(flashId);
}
+ else if (useUpdateDBusInterface)
+ {
+ fs::path imageDirPath = flashId;
+ if (fs::exists(imageDirPath))
+ {
+ info("Erasing image temporary folder {ID}", "ID", flashId);
+ fs::remove_all(imageDirPath);
+ }
+ }
// Removing entry in versions map
this->versions.erase(entryId);