From 933bf632d65e1e6a4990da0a562c797c055a184b Mon Sep 17 00:00:00 2001 From: Konrad Sztyber Date: Wed, 6 Nov 2019 10:06:14 +0100 Subject: [PATCH] event/vmd: write_config_json support This patch adds support for saving VMD subsystem's configuration to a JSON formatted file. It allows saving and then loading configuration with VMD enabled without having to send the `enable_vmd` RPC. Change-Id: I59b380ec1e1f25f60f45d2363724ed7ac78c365c Signed-off-by: Konrad Sztyber Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/473405 Community-CI: Broadcom SPDK FC-NVMe CI Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Ben Walker --- module/event/subsystems/vmd/vmd.c | 26 +++++++++++++++++++++++--- test/json_config/clear_config.py | 4 ++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/module/event/subsystems/vmd/vmd.c b/module/event/subsystems/vmd/vmd.c index cf49960bf..49e3f4a7a 100644 --- a/module/event/subsystems/vmd/vmd.c +++ b/module/event/subsystems/vmd/vmd.c @@ -42,6 +42,7 @@ #include "event_vmd.h" static struct spdk_poller *g_hotplug_poller; +static bool g_enabled; static int vmd_hotplug_monitor(void *ctx) @@ -54,8 +55,7 @@ vmd_subsystem_init(void) { int rc; - /* If the poller is registered, the initialization already took place */ - if (g_hotplug_poller != NULL) { + if (g_enabled) { SPDK_ERRLOG("The initialization has already been performed\n"); return -EBUSY; } @@ -66,12 +66,16 @@ vmd_subsystem_init(void) return rc; } + assert(g_hotplug_poller == NULL); + g_hotplug_poller = spdk_poller_register(vmd_hotplug_monitor, NULL, 1000000ULL); if (g_hotplug_poller == NULL) { SPDK_ERRLOG("Failed to register hotplug monitor poller\n"); return -ENOMEM; } + g_enabled = true; + return 0; } @@ -99,12 +103,28 @@ spdk_vmd_subsystem_fini(void) spdk_subsystem_fini_next(); } +static void +spdk_vmd_write_config_json(struct spdk_json_write_ctx *w) +{ + spdk_json_write_array_begin(w); + + if (g_enabled) { + spdk_json_write_object_begin(w); + spdk_json_write_named_string(w, "method", "enable_vmd"); + spdk_json_write_named_object_begin(w, "params"); + spdk_json_write_object_end(w); + spdk_json_write_object_end(w); + } + + spdk_json_write_array_end(w); +} + static struct spdk_subsystem g_spdk_subsystem_vmd = { .name = "vmd", .init = spdk_vmd_subsystem_init, .fini = spdk_vmd_subsystem_fini, .config = NULL, - .write_config_json = NULL, + .write_config_json = spdk_vmd_write_config_json, }; SPDK_SUBSYSTEM_REGISTER(g_spdk_subsystem_vmd); diff --git a/test/json_config/clear_config.py b/test/json_config/clear_config.py index 5328e6dc1..c40151e75 100755 --- a/test/json_config/clear_config.py +++ b/test/json_config/clear_config.py @@ -153,6 +153,10 @@ def clear_vhost_subsystem(args, vhost_config): args.client.call("vhost_delete_controller", {'ctrlr': vhost['params']['ctrlr']}) +def clear_vmd_subsystem(args, vmd_config): + pass + + def call_test_cmd(func): def rpc_test_cmd(*args, **kwargs): try: