LCOV - code coverage report
Current view: top level - spdk/lib/ftl/nvc - ftl_nvc_dev.c (source / functions) Hit Total Coverage
Test: Combined Lines: 23 29 79.3 %
Date: 2024-07-15 13:34:03 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 13 32 40.6 %

           Branch data     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                 :       2315 : ftl_nv_cache_device_type_get_type(const char *name)
      17                 :            : {
      18                 :            :         struct ftl_nv_cache_device_type *entry;
      19                 :            : 
      20         [ -  + ]:       2315 :         TAILQ_FOREACH(entry, &g_devs, internal.entry) {
      21   [ #  #  #  #  :          0 :                 if (0 == strcmp(entry->name, name)) {
                   #  # ]
      22                 :          0 :                         return entry;
      23                 :            :                 }
      24                 :            :         }
      25                 :            : 
      26                 :       2315 :         return NULL;
      27                 :            : }
      28                 :            : 
      29                 :            : static bool
      30                 :       2315 : ftl_nv_cache_device_valid(const struct ftl_nv_cache_device_type *type)
      31                 :            : {
      32   [ +  -  +  -  :       2315 :         return type && type->name && strlen(type->name) > 0;
                   +  - ]
      33                 :            : }
      34                 :            : 
      35                 :            : void
      36                 :       2315 : ftl_nv_cache_device_register(struct ftl_nv_cache_device_type *type)
      37                 :            : {
      38         [ -  + ]:       2315 :         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         [ -  + ]:       2315 :         pthread_mutex_lock(&g_devs_mutex);
      44         [ +  - ]:       2315 :         if (!ftl_nv_cache_device_type_get_type(type->name)) {
      45                 :       2315 :                 TAILQ_INSERT_TAIL(&g_devs, type, internal.entry);
      46                 :       2315 :                 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         [ -  + ]:       2315 :         pthread_mutex_unlock(&g_devs_mutex);
      53                 :       2315 : }
      54                 :            : 
      55                 :            : const struct ftl_nv_cache_device_type *
      56                 :         22 : 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                 :         22 :         const struct ftl_nv_cache_device_type *type = NULL;
      60                 :            : 
      61         [ -  + ]:         22 :         pthread_mutex_lock(&g_devs_mutex);
      62         [ +  - ]:         22 :         TAILQ_FOREACH(entry, &g_devs, internal.entry) {
      63         [ +  - ]:         22 :                 if (entry->ops.is_bdev_compatible) {
      64         [ +  - ]:         22 :                         if (entry->ops.is_bdev_compatible(dev, bdev)) {
      65                 :         22 :                                 type = entry;
      66                 :         22 :                                 break;
      67                 :            :                         }
      68                 :            :                 }
      69                 :            :         }
      70         [ -  + ]:         22 :         pthread_mutex_unlock(&g_devs_mutex);
      71                 :            : 
      72                 :         22 :         return type;
      73                 :            : }

Generated by: LCOV version 1.14