LCOV - code coverage report
Current view: top level - spdk/lib/ftl/base - ftl_base_dev.c (source / functions) Hit Total Coverage
Test: Combined Lines: 21 27 77.8 %
Date: 2024-07-11 05:51:35 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_core.h"
      10                 :            : #include "ftl_base_dev.h"
      11                 :            : #include "utils/ftl_defs.h"
      12                 :            : 
      13                 :            : static TAILQ_HEAD(, ftl_base_device_type) g_devs = TAILQ_HEAD_INITIALIZER(g_devs);
      14                 :            : static pthread_mutex_t g_devs_mutex = PTHREAD_MUTEX_INITIALIZER;
      15                 :            : 
      16                 :            : static const struct ftl_base_device_type *
      17                 :       2045 : ftl_base_device_type_get_desc(const char *name)
      18                 :            : {
      19                 :            :         struct ftl_base_device_type *entry;
      20                 :            : 
      21         [ -  + ]:       2045 :         TAILQ_FOREACH(entry, &g_devs, base_devs_entry) {
      22   [ #  #  #  #  :          0 :                 if (0 == strcmp(entry->name, name)) {
                   #  # ]
      23                 :          0 :                         return entry;
      24                 :            :                 }
      25                 :            :         }
      26                 :            : 
      27                 :       2045 :         return NULL;
      28                 :            : }
      29                 :            : 
      30                 :            : static bool
      31                 :       2045 : ftl_base_device_valid(const struct ftl_base_device_type *type)
      32                 :            : {
      33   [ +  -  +  -  :       2045 :         return type && type->name && strlen(type->name);
                   +  - ]
      34                 :            : }
      35                 :            : 
      36                 :            : void
      37                 :       2045 : ftl_base_device_register(struct ftl_base_device_type *type)
      38                 :            : {
      39         [ -  + ]:       2045 :         if (!ftl_base_device_valid(type)) {
      40                 :          0 :                 SPDK_ERRLOG("[FTL] Base device type is invalid\n");
      41                 :          0 :                 ftl_abort();
      42                 :            :         }
      43                 :            : 
      44         [ -  + ]:       2045 :         pthread_mutex_lock(&g_devs_mutex);
      45         [ +  - ]:       2045 :         if (!ftl_base_device_type_get_desc(type->name)) {
      46                 :       2045 :                 TAILQ_INSERT_TAIL(&g_devs, type, base_devs_entry);
      47                 :            : 
      48                 :       2045 :                 SPDK_NOTICELOG("[FTL] Registered base device, name: %s\n", type->name);
      49                 :            :         } else {
      50                 :          0 :                 SPDK_ERRLOG("[FTL] Cannot register base device, already exist, name: %s\n", type->name);
      51                 :          0 :                 ftl_abort();
      52                 :            :         }
      53                 :            : 
      54         [ -  + ]:       2045 :         pthread_mutex_unlock(&g_devs_mutex);
      55                 :       2045 : }
      56                 :            : 
      57                 :            : const struct ftl_base_device_type *
      58                 :         22 : ftl_base_device_get_type_by_bdev(struct spdk_ftl_dev *dev, struct spdk_bdev *bdev)
      59                 :            : {
      60                 :            :         struct ftl_base_device_type *type;
      61                 :            : 
      62         [ -  + ]:         22 :         pthread_mutex_lock(&g_devs_mutex);
      63                 :            : 
      64         [ +  - ]:         22 :         TAILQ_FOREACH(type, &g_devs, base_devs_entry) {
      65         [ +  - ]:         22 :                 if (type->ops.is_bdev_compatible) {
      66         [ +  - ]:         22 :                         if (type->ops.is_bdev_compatible(dev, bdev)) {
      67                 :         22 :                                 break;
      68                 :            :                         }
      69                 :            :                 }
      70                 :            :         }
      71                 :            : 
      72         [ -  + ]:         22 :         pthread_mutex_unlock(&g_devs_mutex);
      73                 :            : 
      74                 :         22 :         return type;
      75                 :            : }

Generated by: LCOV version 1.14