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 : 2112 : ftl_base_device_type_get_desc(const char *name)
18 : : {
19 : : struct ftl_base_device_type *entry;
20 : :
21 [ - + # # : 2112 : TAILQ_FOREACH(entry, &g_devs, base_devs_entry) {
# # # # ]
22 [ # # # # : 0 : if (0 == strcmp(entry->name, name)) {
# # # # #
# ]
23 : 0 : return entry;
24 : : }
25 : 0 : }
26 : :
27 : 2112 : return NULL;
28 : 58 : }
29 : :
30 : : static bool
31 : 2112 : ftl_base_device_valid(const struct ftl_base_device_type *type)
32 : : {
33 [ + - + - : 2112 : return type && type->name && strlen(type->name);
+ - + - +
- + - +
- ]
34 : : }
35 : :
36 : : void
37 : 2112 : ftl_base_device_register(struct ftl_base_device_type *type)
38 : : {
39 [ + + ]: 2112 : if (!ftl_base_device_valid(type)) {
40 : 0 : SPDK_ERRLOG("[FTL] Base device type is invalid\n");
41 [ # # ]: 0 : ftl_abort();
42 : 0 : }
43 : :
44 [ + + ]: 2112 : pthread_mutex_lock(&g_devs_mutex);
45 [ + - + - : 2112 : if (!ftl_base_device_type_get_desc(type->name)) {
+ - ]
46 [ + - + - : 2112 : TAILQ_INSERT_TAIL(&g_devs, type, base_devs_entry);
+ - + - +
- + - + -
+ - + - +
- + - +
- ]
47 : :
48 [ + - + - ]: 2112 : SPDK_NOTICELOG("[FTL] Registered base device, name: %s\n", type->name);
49 : 58 : } else {
50 [ # # # # ]: 0 : SPDK_ERRLOG("[FTL] Cannot register base device, already exist, name: %s\n", type->name);
51 [ # # ]: 0 : ftl_abort();
52 : : }
53 : :
54 [ + + ]: 2112 : pthread_mutex_unlock(&g_devs_mutex);
55 : 2112 : }
56 : :
57 : : const struct ftl_base_device_type *
58 : 27 : 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 [ - + ]: 27 : pthread_mutex_lock(&g_devs_mutex);
63 : :
64 [ + - # # : 27 : TAILQ_FOREACH(type, &g_devs, base_devs_entry) {
# # # # ]
65 [ + - # # : 27 : if (type->ops.is_bdev_compatible) {
# # # # ]
66 [ + - # # : 27 : if (type->ops.is_bdev_compatible(dev, bdev)) {
# # # # #
# # # ]
67 : 27 : break;
68 : : }
69 : 0 : }
70 : 0 : }
71 : :
72 [ - + ]: 27 : pthread_mutex_unlock(&g_devs_mutex);
73 : :
74 : 27 : return type;
75 : : }
|