LCOV - code coverage report
Current view: top level - module/event/subsystems/vmd - vmd.c (source / functions) Hit Total Coverage
Test: ut_cov_unit.info Lines: 0 40 0.0 %
Date: 2024-12-15 03:48:28 Functions: 0 7 0.0 %

          Line data    Source code
       1             : /*   SPDX-License-Identifier: BSD-3-Clause
       2             :  *   Copyright (C) 2019 Intel Corporation.
       3             :  *   All rights reserved.
       4             :  */
       5             : 
       6             : #include "spdk/stdinc.h"
       7             : 
       8             : #include "spdk/json.h"
       9             : #include "spdk/thread.h"
      10             : #include "spdk/likely.h"
      11             : #include "spdk/log.h"
      12             : 
      13             : #include "spdk/vmd.h"
      14             : 
      15             : #include "spdk_internal/init.h"
      16             : #include "event_vmd.h"
      17             : 
      18             : static struct spdk_poller *g_hotplug_poller;
      19             : static bool g_enabled;
      20             : 
      21             : void
      22           0 : vmd_subsystem_enable(void)
      23             : {
      24           0 :         g_enabled = true;
      25           0 : }
      26             : 
      27             : bool
      28           0 : vmd_subsystem_is_enabled(void)
      29             : {
      30           0 :         return g_enabled;
      31             : }
      32             : 
      33             : static int
      34           0 : vmd_hotplug_monitor(void *ctx)
      35             : {
      36           0 :         return spdk_vmd_hotplug_monitor();
      37             : }
      38             : 
      39             : static void
      40           0 : vmd_subsystem_init(void)
      41             : {
      42           0 :         int rc = 0;
      43             : 
      44           0 :         if (!g_enabled) {
      45           0 :                 goto out;
      46             :         }
      47             : 
      48           0 :         rc = spdk_vmd_init();
      49           0 :         if (spdk_likely(rc != 0)) {
      50           0 :                 SPDK_ERRLOG("Failed to initialize the VMD library\n");
      51           0 :                 goto out;
      52             :         }
      53             : 
      54           0 :         assert(g_hotplug_poller == NULL);
      55             : 
      56           0 :         g_hotplug_poller = SPDK_POLLER_REGISTER(vmd_hotplug_monitor, NULL, 1000000ULL);
      57           0 :         if (g_hotplug_poller == NULL) {
      58           0 :                 SPDK_ERRLOG("Failed to register hotplug monitor poller\n");
      59           0 :                 rc = -ENOMEM;
      60           0 :                 goto out;
      61             :         }
      62           0 : out:
      63           0 :         spdk_subsystem_init_next(rc);
      64           0 : }
      65             : 
      66             : static void
      67           0 : vmd_subsystem_fini(void)
      68             : {
      69           0 :         spdk_poller_unregister(&g_hotplug_poller);
      70             : 
      71           0 :         spdk_vmd_fini();
      72             : 
      73           0 :         spdk_subsystem_fini_next();
      74           0 : }
      75             : 
      76             : static void
      77           0 : vmd_write_config_json(struct spdk_json_write_ctx *w)
      78             : {
      79           0 :         spdk_json_write_array_begin(w);
      80             : 
      81           0 :         if (g_enabled) {
      82           0 :                 spdk_json_write_object_begin(w);
      83           0 :                 spdk_json_write_named_string(w, "method", "vmd_enable");
      84           0 :                 spdk_json_write_named_object_begin(w, "params");
      85           0 :                 spdk_json_write_object_end(w);
      86           0 :                 spdk_json_write_object_end(w);
      87             :         }
      88             : 
      89           0 :         spdk_json_write_array_end(w);
      90           0 : }
      91             : 
      92             : static struct spdk_subsystem g_spdk_subsystem_vmd = {
      93             :         .name = "vmd",
      94             :         .init = vmd_subsystem_init,
      95             :         .fini = vmd_subsystem_fini,
      96             :         .write_config_json = vmd_write_config_json,
      97             : };
      98             : 
      99           0 : SPDK_SUBSYSTEM_REGISTER(g_spdk_subsystem_vmd);

Generated by: LCOV version 1.15