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 : 4268 : ftl_nv_cache_device_type_get_type(const char *name)
17 : : {
18 : : struct ftl_nv_cache_device_type *entry;
19 : :
20 [ + + - + : 6402 : TAILQ_FOREACH(entry, &g_devs, internal.entry) {
- + - + -
+ ]
21 [ + + + + : 2134 : if (0 == strcmp(entry->name, name)) {
+ + + - +
- ]
22 : 0 : return entry;
23 : : }
24 : 58 : }
25 : :
26 : 4268 : return NULL;
27 : 116 : }
28 : :
29 : : static bool
30 : 4268 : ftl_nv_cache_device_valid(const struct ftl_nv_cache_device_type *type)
31 : : {
32 [ + - + - : 4268 : return type && type->name && strlen(type->name) > 0;
+ - + - +
- + - +
- ]
33 : : }
34 : :
35 : : void
36 : 4268 : ftl_nv_cache_device_register(struct ftl_nv_cache_device_type *type)
37 : : {
38 [ + + ]: 4268 : if (!ftl_nv_cache_device_valid(type)) {
39 : 0 : SPDK_ERRLOG("NV cache device descriptor is invalid\n");
40 [ # # ]: 0 : ftl_abort();
41 : 0 : }
42 : :
43 [ + + ]: 4268 : pthread_mutex_lock(&g_devs_mutex);
44 [ + - + - : 4268 : if (!ftl_nv_cache_device_type_get_type(type->name)) {
+ - ]
45 [ + - + - : 4268 : TAILQ_INSERT_TAIL(&g_devs, type, internal.entry);
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- ]
46 [ + - + - ]: 4268 : SPDK_NOTICELOG("Registered NV cache device, name: %s\n", type->name);
47 : 116 : } else {
48 [ # # # # ]: 0 : SPDK_ERRLOG("Cannot register NV cache device, already exists, name: %s\n", type->name);
49 [ # # ]: 0 : ftl_abort();
50 : : }
51 : :
52 [ + + ]: 4268 : pthread_mutex_unlock(&g_devs_mutex);
53 : 4268 : }
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 : 0 : }
69 : 0 : }
70 [ - + ]: 27 : pthread_mutex_unlock(&g_devs_mutex);
71 : :
72 : 27 : return type;
73 : : }
|