Fix extra logs for NVMe drives

NVMe drives have FRUs. Because of this entity-manager
handles the add/remove messages. Make sure hsbp-manager
doesn't log for these, and that we rescan when they
change.

Tested: Extra logs went away, got add / remove messages
when status changed

Change-Id: Ie9b6d980be9cb557f44da1ffaed79ecc867c2d98
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/hsbp-manager/src/hsbp_manager.cpp b/hsbp-manager/src/hsbp_manager.cpp
index 56d0d24..e2ff857 100644
--- a/hsbp-manager/src/hsbp_manager.cpp
+++ b/hsbp-manager/src/hsbp_manager.cpp
@@ -76,6 +76,20 @@
     terminate = 0x3
 };
 
+static void rescanFruDeviceBus(size_t bus)
+{
+    conn->async_method_call(
+        [bus](const boost::system::error_code ec) {
+            if (ec)
+            {
+                std::cerr << "Error trigger rescan at bus " << bus << "\n";
+            }
+        },
+        "xyz.openbmc_project.FruDevice", "/xyz/openbmc_project/FruDevice",
+        "xyz.openbmc_project.FruDeviceManager", "ReScanBus",
+        static_cast<uint8_t>(bus));
+}
+
 struct Led : std::enable_shared_from_this<Led>
 {
     // led pattern addresses start at 0x10
@@ -259,10 +273,10 @@
         associations->set_property("Associations", std::vector<Association>{});
     }
 
-    void setPresent(bool set)
+    void setPresent(bool set, bool nvme)
     {
         // nvme drives get detected by their fru
-        if (isNvme || set == isPresent)
+        if (nvme || set == isPresent)
         {
             return;
         }
@@ -481,12 +495,21 @@
         for (auto it = drives.begin(); it != drives.end(); it++, ii++)
         {
             bool isNvme = nvme & (1 << ii);
+            bool wasNvme = it->isNvme || isNvme;
             bool isPresent = isNvme || (presence & (1 << ii));
             bool isFailed = !isPresent || (failed & (1 << ii));
             bool isRebuilding = isPresent && (rebuilding & (1 << ii));
 
+            if (isNvme != it->isNvme)
+            {
+                rescanFruDeviceBus(bus);
+            }
+
             it->isNvme = isNvme;
-            it->setPresent(isPresent);
+
+            // if it was nvme, treat it as nvme for presence
+            it->setPresent(isPresent, wasNvme);
+
             it->rebuildingIface->set_property("Rebuilding", isRebuilding);
             if (isFailed || isRebuilding)
             {