LCOV - code coverage report
Current view: top level - lib/ftl/nvc - ftl_nvc_dev.c (source / functions) Hit Total Coverage
Test: ut_cov_unit.info Lines: 0 29 0.0 %
Date: 2024-07-15 12:43:16 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /*   SPDX-License-Identifier: BSD-3-Clause
       2             :  *   Copyright 2023 Solidigm All Rights Reserved
       3             :  */
       4             : 
       5             : #include "spdk/stdinc.h"
       6             : #include "spdk/queue.h"
       7             : #include "spdk/log.h"
       8             : 
       9             : #include "ftl_nvc_dev.h"
      10             : #include "utils/ftl_defs.h"
      11             : 
      12             : static TAILQ_HEAD(, ftl_nv_cache_device_type) g_devs = TAILQ_HEAD_INITIALIZER(g_devs);
      13             : static pthread_mutex_t g_devs_mutex = PTHREAD_MUTEX_INITIALIZER;
      14             : 
      15             : static const struct ftl_nv_cache_device_type *
      16           0 : ftl_nv_cache_device_type_get_type(const char *name)
      17             : {
      18             :         struct ftl_nv_cache_device_type *entry;
      19             : 
      20           0 :         TAILQ_FOREACH(entry, &g_devs, internal.entry) {
      21           0 :                 if (0 == strcmp(entry->name, name)) {
      22           0 :                         return entry;
      23             :                 }
      24             :         }
      25             : 
      26           0 :         return NULL;
      27             : }
      28             : 
      29             : static bool
      30           0 : ftl_nv_cache_device_valid(const struct ftl_nv_cache_device_type *type)
      31             : {
      32           0 :         return type && type->name && strlen(type->name) > 0;
      33             : }
      34             : 
      35             : void
      36           0 : ftl_nv_cache_device_register(struct ftl_nv_cache_device_type *type)
      37             : {
      38           0 :         if (!ftl_nv_cache_device_valid(type)) {
      39           0 :                 SPDK_ERRLOG("NV cache device descriptor is invalid\n");
      40           0 :                 ftl_abort();
      41             :         }
      42             : 
      43           0 :         pthread_mutex_lock(&g_devs_mutex);
      44           0 :         if (!ftl_nv_cache_device_type_get_type(type->name)) {
      45           0 :                 TAILQ_INSERT_TAIL(&g_devs, type, internal.entry);
      46           0 :                 SPDK_NOTICELOG("Registered NV cache device, name: %s\n", type->name);
      47             :         } else {
      48           0 :                 SPDK_ERRLOG("Cannot register NV cache device, already exists, name: %s\n", type->name);
      49           0 :                 ftl_abort();
      50             :         }
      51             : 
      52           0 :         pthread_mutex_unlock(&g_devs_mutex);
      53           0 : }
      54             : 
      55             : const struct ftl_nv_cache_device_type *
      56           0 : ftl_nv_cache_device_get_type_by_bdev(struct spdk_ftl_dev *dev, struct spdk_bdev *bdev)
      57             : {
      58             :         struct ftl_nv_cache_device_type *entry;
      59           0 :         const struct ftl_nv_cache_device_type *type = NULL;
      60             : 
      61           0 :         pthread_mutex_lock(&g_devs_mutex);
      62           0 :         TAILQ_FOREACH(entry, &g_devs, internal.entry) {
      63           0 :                 if (entry->ops.is_bdev_compatible) {
      64           0 :                         if (entry->ops.is_bdev_compatible(dev, bdev)) {
      65           0 :                                 type = entry;
      66           0 :                                 break;
      67             :                         }
      68             :                 }
      69             :         }
      70           0 :         pthread_mutex_unlock(&g_devs_mutex);
      71             : 
      72           0 :         return type;
      73             : }

Generated by: LCOV version 1.15