]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/ocf/src/utils/utils_part.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / ocf / src / utils / utils_part.h
1 /*
2 * Copyright(c) 2012-2018 Intel Corporation
3 * SPDX-License-Identifier: BSD-3-Clause-Clear
4 */
5
6 #ifndef __UTILS_PARTITION_H__
7 #define __UTILS_PARTITION_H__
8
9 #include "../ocf_request.h"
10 #include "../engine/cache_engine.h"
11 #include "../metadata/metadata_partition.h"
12
13 int ocf_part_init(struct ocf_cache *cache);
14
15 static inline bool ocf_part_is_valid(struct ocf_user_part *part)
16 {
17 return !!part->config->flags.valid;
18 }
19
20 static inline void ocf_part_set_prio(struct ocf_cache *cache,
21 struct ocf_user_part *part, int16_t prio)
22 {
23 if (part->config->priority != prio)
24 part->config->priority = prio;
25 }
26
27 static inline int16_t ocf_part_get_prio(struct ocf_cache *cache,
28 ocf_part_id_t part_id)
29 {
30 if (part_id < OCF_IO_CLASS_MAX)
31 return cache->user_parts[part_id].config->priority;
32
33 return OCF_IO_CLASS_PRIO_LOWEST;
34 }
35
36 void ocf_part_set_valid(struct ocf_cache *cache, ocf_part_id_t id,
37 bool valid);
38
39 static inline bool ocf_part_is_added(struct ocf_user_part *part)
40 {
41 return !!part->config->flags.added;
42 }
43
44 static inline ocf_part_id_t ocf_part_class2id(ocf_cache_t cache, uint64_t class)
45 {
46 if (class < OCF_IO_CLASS_MAX)
47 if (cache->user_parts[class].config->flags.valid)
48 return class;
49
50 return PARTITION_DEFAULT;
51 }
52
53 void ocf_part_move(struct ocf_request *req);
54
55 #define for_each_part(cache, part, id) \
56 for_each_lst_entry(&cache->lst_part, part, id, \
57 struct ocf_user_part, lst_valid)
58
59 static inline void ocf_part_sort(struct ocf_cache *cache)
60 {
61 ocf_lst_sort(&cache->lst_part);
62 }
63
64 static inline ocf_cache_mode_t ocf_part_get_cache_mode(struct ocf_cache *cache,
65 ocf_part_id_t part_id)
66 {
67 if (part_id < OCF_IO_CLASS_MAX)
68 return cache->user_parts[part_id].config->cache_mode;
69 return ocf_cache_mode_none;
70 }
71
72 static inline bool ocf_part_is_prio_valid(int64_t prio)
73 {
74 switch (prio) {
75 case OCF_IO_CLASS_PRIO_HIGHEST ... OCF_IO_CLASS_PRIO_LOWEST:
76 case OCF_IO_CLASS_PRIO_PINNED:
77 return true;
78
79 default:
80 return false;
81 }
82 }
83
84 /**
85 * routine checks for validity of a partition name.
86 *
87 * Following condition is checked:
88 * - string too long
89 * - string containing invalid characters (outside of low ascii)
90 * Following condition is NOT cheched:
91 * - empty string. (empty string is NOT a valid partition name, but
92 * this function returns true on empty string nevertheless).
93 *
94 * @return returns true if partition name is a valid name
95 */
96 static inline bool ocf_part_is_name_valid(const char *name)
97 {
98 uint32_t length = 0;
99
100 while (*name) {
101 if (*name < ' ' || *name > '~')
102 return false;
103
104 if (',' == *name || '"' == *name)
105 return false;
106
107 name++;
108 length++;
109
110 if (length >= OCF_IO_CLASS_NAME_MAX)
111 return false;
112 }
113
114 return true;
115 }
116
117 #endif /* __UTILS_PARTITION_H__ */