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