nvmed: Add metric-store feature flag to disable nvme cache
Default value is disabled. If disabled then the metric store will be
empty but the dbus interface will still be there. Also none of the
vendor metrics will be loaded.
The other possible values are statis and dynamic which will act same for
now and act as enabled feature. Future CL will cover the dynamic part.
Tested: https://paste.googleplex.com/6081669870256128?raw
Google-Bug-Id: 447223936
Change-Id: I8dfe8fbe7f44f40053daee4052e888fbb942d3c6
Signed-off-by: Munawar Hussain <munawarhussain@google.com>
diff --git a/meson_options.txt b/meson_options.txt
index 7dd57ae..4f2e000 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -14,3 +14,4 @@
option('insecure-sensor-override', type : 'feature', value : 'disabled', description : 'Enables Sensor override feature without any check.',)
option('build-type', type: 'combo', choices: ['ci', 'bitbake'], value: 'ci', yield: false)
option('single-worker', type : 'feature', value: 'disabled', description : 'Enable single worker per i2c bus')
+option('metric-store', type : 'combo', choices : ['disabled', 'static', 'dynamic'], value : 'disabled', description : 'Metric store options. If disabled, then no metrics will be loaded; if static, then will load all metrics but will not dynamically decide which to load; if dynamic then metric store will load specific metrics dynamically based on conditions.')
\ No newline at end of file
diff --git a/src/NVMeController.cpp b/src/NVMeController.cpp
index 7f69ef5..427b484 100644
--- a/src/NVMeController.cpp
+++ b/src/NVMeController.cpp
@@ -1,5 +1,7 @@
#include "NVMeController.hpp"
+#include "dbus-sensor_config.h"
+
#include "AsioHelper.hpp"
#include "NVMeCacheImpl.hpp"
#include "NVMeError.hpp"
@@ -191,11 +193,15 @@
void NVMeControllerEnabled::initializeMetricStore()
{
- // only to test compilation. need to remove.
- this->metricStore.emplace(this->NVMeController::io,
- this->NVMeController::conn,
- this->NVMeController::path);
-
+ // if metric store feature is disabled then create empty metric store
+ // the dbus interface will be there but with no metrics
+ if (metricStoreFeature == MetricStoreFeature::Disabled)
+ {
+ this->metricStore.emplace(this->NVMeController::io,
+ this->NVMeController::conn,
+ this->NVMeController::path);
+ return;
+ }
auto scheduler = Scheduler<SchedulerClockType>::getScheduler(path);
using IdentifyMetric =
diff --git a/src/NVMePlugin.cpp b/src/NVMePlugin.cpp
index 51ac4e0..e450017 100644
--- a/src/NVMePlugin.cpp
+++ b/src/NVMePlugin.cpp
@@ -1,5 +1,7 @@
#include "NVMePlugin.hpp"
+#include "dbus-sensor_config.h"
+
#include "NVMeIntf.hpp"
#include "NVMeMetricStore.hpp"
#include "NVMeSubsys.hpp"
@@ -125,6 +127,13 @@
std::vector<std::shared_ptr<MetricBase<>>>
MetricStore::getVendorMatrics(const std::string& path)
{
+ // if metric store feature is disabled then no vendor metrics should be
+ // loaded
+ if (metricStoreFeature == MetricStoreFeature::Disabled)
+ {
+ return {};
+ }
+
auto itr = std::find_if(
pluginMetricFunctions.begin(), pluginMetricFunctions.end(),
[&path](const std::pair<
diff --git a/src/NVMeVolume.cpp b/src/NVMeVolume.cpp
index 4cf675b..91fef79 100644
--- a/src/NVMeVolume.cpp
+++ b/src/NVMeVolume.cpp
@@ -1,5 +1,7 @@
#include "NVMeVolume.hpp"
+#include "dbus-sensor_config.h"
+
#include "NVMeCacheImpl.hpp"
using SchedulerClockType = std::chrono::steady_clock;
@@ -26,7 +28,14 @@
void NVMeVolume::initializeMetricStore()
{
- /* create the MetricStore interface */
+ // if metric store feature is disabled then create empty metric store
+ // the dbus interface will be there but with no metrics
+ if (metricStoreFeature == MetricStoreFeature::Disabled)
+ {
+ metricStore.emplace(conn->get_io_context(), conn, path);
+ return;
+ }
+
auto scheduler = Scheduler<SchedulerClockType>::getScheduler(path);
using IdentifyMetric =
diff --git a/src/dbus-sensor_config.h.in b/src/dbus-sensor_config.h.in
index 668f186..d6bdc06 100644
--- a/src/dbus-sensor_config.h.in
+++ b/src/dbus-sensor_config.h.in
@@ -2,10 +2,19 @@
#include <cstdint>
+enum class MetricStoreFeature : uint8_t
+{
+ Disabled = 0,
+ Static = 1,
+ Dynamic = 2
+};
+
// clang-format off
constexpr const int validateUnsecureFeature = @VALIDATION_UNSECURE_FEATURE@;
constexpr const int insecureSensorOverride = @INSECURE_UNRESTRICTED_SENSOR_OVERRIDE@;
constexpr const bool singleWorkerFeature = @NVMED_ENABLE_SINGLE_WOKER@;
+
+constexpr MetricStoreFeature metricStoreFeature = static_cast<MetricStoreFeature>(@METRIC_STORE_FEATURE@);
// clang-format on
diff --git a/src/meson.build b/src/meson.build
index 50e1500..291ac62 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -2,6 +2,15 @@
conf_data.set10('VALIDATION_UNSECURE_FEATURE', get_option('validate-unsecure-feature').enabled())
conf_data.set10('INSECURE_UNRESTRICTED_SENSOR_OVERRIDE', get_option('insecure-sensor-override').enabled())
conf_data.set10('NVMED_ENABLE_SINGLE_WOKER', get_option('single-worker').enabled())
+
+metric_store_feature_map = {
+ 'disabled': 0,
+ 'static': 1,
+ 'dynamic': 2
+}
+metric_store_feature = metric_store_feature_map.get(get_option('metric-store'))
+conf_data.set('METRIC_STORE_FEATURE', metric_store_feature)
+
conf_hdr = configure_file(input: 'dbus-sensor_config.h.in',
output: 'dbus-sensor_config.h',
configuration: conf_data)