Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions inc/ocf_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,17 @@ const struct ocf_volume_uuid *ocf_cache_get_uuid(ocf_cache_t cache);
*/
ocf_ctx_t ocf_cache_get_ctx(ocf_cache_t cache);

/**
* @brief Get OCF cleaner of given cache object
*
* @param[in] cache Cache object
*
* @retval OCF cleaner, NULL if cache is in standby mode,
* cache device is not attached (cleaner not initialized)
* or cleaner is disabled
*/
ocf_cleaner_t ocf_cache_get_cleaner(ocf_cache_t cache);

/**
* @brief Get volume type id of given cache object
*
Expand Down
4 changes: 3 additions & 1 deletion inc/ocf_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@
* for invalid OCF_CORE_ID_INVALID.
*/
#define OCF_CORE_NUM OCF_CONFIG_MAX_CORES
_Static_assert(OCF_CORE_NUM < OCF_MAX_T(uint32_t, OCF_CORE_ID_BITS));
_Static_assert(OCF_MAX_T(uint32_t, OCF_CORE_ID_BITS) > OCF_CORE_NUM,
"Not enough core ID bits (OCF_CORE_ID_BITS) to "
"store maximum number of cores (OCF_CORE_NUM)");
/**
* Minimum value of a valid core ID
*/
Expand Down
2 changes: 1 addition & 1 deletion src/cleaning/cleaning.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct ocf_request;

struct cleaning_policy_config {
uint8_t data[CLEANING_POLICY_CONFIG_BYTES];
};
} __attribute__((aligned(4)));

struct cleaning_policy {
union {
Expand Down
3 changes: 2 additions & 1 deletion src/metadata/metadata_collision.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ struct ocf_metadata_list_info {
} __attribute__((packed));

/* Keep the struct ocf_metadata_list_info size of 8 bytes */
_Static_assert(sizeof(struct ocf_metadata_list_info) == sizeof(uint64_t));
_Static_assert(sizeof(struct ocf_metadata_list_info) == sizeof(uint64_t),
"Size of struct ocf_metadata_list_info is not equal to 8 bytes");

struct ocf_hash_entry {
union {
Expand Down
16 changes: 16 additions & 0 deletions src/ocf_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,22 @@ ocf_ctx_t ocf_cache_get_ctx(ocf_cache_t cache)
return cache->owner;
}

ocf_cleaner_t ocf_cache_get_cleaner(ocf_cache_t cache)
{
OCF_CHECK_NULL(cache);

if (ocf_cache_is_standby(cache))
return NULL;

if (!ocf_cache_is_device_attached(cache))
return NULL;

if (cache->conf_meta->cleaner_disabled)
return NULL;

return &cache->cleaner;
}

void ocf_cache_set_priv(ocf_cache_t cache, void *priv)
{
OCF_CHECK_NULL(cache);
Expand Down
5 changes: 4 additions & 1 deletion src/ocf_lru.c
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,7 @@ static int ocf_lru_populate_handle(ocf_parallelize_t parallelize,
uint32_t partial_chunk_lines = 0;
uint32_t num_chunks, chunk_idx, chunk_lines;
uint32_t ci, j;
int result;

/* Check if this shard has a partial last chunk */
if (remainder > (uint32_t)shard_id * OCF_LRU_CHUNK_SIZE) {
Expand All @@ -1044,7 +1045,9 @@ static int ocf_lru_populate_handle(ocf_parallelize_t parallelize,
if (num_chunks == 0)
return 0;

ocf_generator_bisect_init(&generator, num_chunks, 0);
result = ocf_generator_bisect_init(&generator, num_chunks, 0);
if (result)
return result;

list = ocf_lru_get_list(&cache->free, shard_id, true);

Expand Down
2 changes: 1 addition & 1 deletion src/promotion/promotion.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

struct promotion_policy_config {
uint8_t data[PROMOTION_POLICY_CONFIG_BYTES];
};
} __attribute__((aligned(4)));

typedef struct ocf_promotion_policy *ocf_promotion_policy_t;

Expand Down
24 changes: 20 additions & 4 deletions src/utils/utils_generator.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright(c) 2022 Intel Corporation
* Copyright(c) 2026 Unvertical
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand Down Expand Up @@ -29,20 +30,32 @@ static inline uint32_t bitreverse32(register uint32_t x)
* returned by the generator is limit - 1)
* @param[in] offset Offset at which generator should start
*
* @return Reversed value
* @return Zero when success, otherwise an error
*/
void ocf_generator_bisect_init(
int ocf_generator_bisect_init(
struct ocf_generator_bisect_state *generator,
uint32_t limit, uint32_t offset)
{
unsigned clz;
uint32_t maplen;

clz = __builtin_clz(limit - 1);
maplen = 1 << (32 - clz);
if (limit == 0)
return -OCF_ERR_INVAL;

if (offset >= limit)
return -OCF_ERR_INVAL;

if (limit > 1) {
clz = __builtin_clz(limit - 1);
maplen = 1 << (32 - clz);
} else {
maplen = 1;
}

generator->curr = (uint64_t)offset * maplen / limit;
generator->limit = limit;

return 0;
}

/**
Expand Down Expand Up @@ -180,6 +193,9 @@ uint32_t ocf_generator_bisect_next(
uint32_t maplen;
uint32_t value;

if (generator->limit == 1)
return 0;

clz = __builtin_clz(generator->limit - 1);
maplen = 1 << (32 - clz);

Expand Down
3 changes: 2 additions & 1 deletion src/utils/utils_generator.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright(c) 2022 Intel Corporation
* Copyright(c) 2026 Unvertical
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand All @@ -13,7 +14,7 @@ struct ocf_generator_bisect_state {
uint32_t limit;
};

void ocf_generator_bisect_init(
int ocf_generator_bisect_init(
struct ocf_generator_bisect_state *generator,
uint32_t limit, uint32_t offset);

Expand Down
Loading