2 * Copyright(c) 2012-2018 Intel Corporation
3 * SPDX-License-Identifier: BSD-3-Clause-Clear
6 #ifndef __UTILS_PARTITION_H__
7 #define __UTILS_PARTITION_H__
9 #include "../ocf_request.h"
10 #include "../engine/cache_engine.h"
11 #include "../metadata/metadata_partition.h"
13 int ocf_part_init(struct ocf_cache
*cache
);
15 static inline bool ocf_part_is_valid(struct ocf_user_part
*part
)
17 return !!part
->config
->flags
.valid
;
20 static inline void ocf_part_set_prio(struct ocf_cache
*cache
,
21 struct ocf_user_part
*part
, int16_t prio
)
23 if (part
->config
->priority
!= prio
)
24 part
->config
->priority
= prio
;
27 static inline int16_t ocf_part_get_prio(struct ocf_cache
*cache
,
28 ocf_part_id_t part_id
)
30 if (part_id
< OCF_IO_CLASS_MAX
)
31 return cache
->user_parts
[part_id
].config
->priority
;
33 return OCF_IO_CLASS_PRIO_LOWEST
;
36 void ocf_part_set_valid(struct ocf_cache
*cache
, ocf_part_id_t id
,
39 static inline bool ocf_part_is_added(struct ocf_user_part
*part
)
41 return !!part
->config
->flags
.added
;
44 static inline ocf_part_id_t
ocf_part_class2id(ocf_cache_t cache
, uint64_t class)
46 if (class < OCF_IO_CLASS_MAX
)
47 if (cache
->user_parts
[class].config
->flags
.valid
)
50 return PARTITION_DEFAULT
;
53 void ocf_part_move(struct ocf_request
*req
);
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)
59 static inline void ocf_part_sort(struct ocf_cache
*cache
)
61 ocf_lst_sort(&cache
->lst_part
);
64 static inline ocf_cache_mode_t
ocf_part_get_cache_mode(struct ocf_cache
*cache
,
65 ocf_part_id_t part_id
)
67 if (part_id
< OCF_IO_CLASS_MAX
)
68 return cache
->user_parts
[part_id
].config
->cache_mode
;
69 return ocf_cache_mode_none
;
72 static inline bool ocf_part_is_prio_valid(int64_t prio
)
75 case OCF_IO_CLASS_PRIO_HIGHEST
... OCF_IO_CLASS_PRIO_LOWEST
:
76 case OCF_IO_CLASS_PRIO_PINNED
:
85 * routine checks for validity of a partition name.
87 * Following condition is checked:
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).
94 * @return returns true if partition name is a valid name
96 static inline bool ocf_part_is_name_valid(const char *name
)
101 if (*name
< ' ' || *name
> '~')
104 if (',' == *name
|| '"' == *name
)
110 if (length
>= OCF_IO_CLASS_NAME_MAX
)
117 #endif /* __UTILS_PARTITION_H__ */