Merge pull request #296 from micrakow/sec_rev_fixes

Env fixes & more
This commit is contained in:
Adam Rutkowski 2019-09-30 17:42:40 +02:00 committed by GitHub
commit 944d70288e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 100 additions and 34 deletions

4
env/posix/ocf_env.h vendored
View File

@ -450,9 +450,9 @@ typedef struct {
pthread_spinlock_t lock; pthread_spinlock_t lock;
} env_spinlock; } env_spinlock;
static inline void env_spinlock_init(env_spinlock *l) static inline int env_spinlock_init(env_spinlock *l)
{ {
ENV_BUG_ON(pthread_spin_init(&l->lock, 0)); return pthread_spin_init(&l->lock, 0);
} }
static inline int env_spinlock_trylock(env_spinlock *l) static inline int env_spinlock_trylock(env_spinlock *l)

View File

@ -302,11 +302,16 @@ int cleaning_policy_acp_initialize(struct ocf_cache *cache,
ocf_cache_log(cache, log_err, "acp context allocation error\n"); ocf_cache_log(cache, log_err, "acp context allocation error\n");
return -OCF_ERR_NO_MEM; return -OCF_ERR_NO_MEM;
} }
err = env_rwsem_init(&acp->chunks_lock);
if (err) {
env_vfree(acp);
return err;
}
cache->cleaner.cleaning_policy_context = acp; cache->cleaner.cleaning_policy_context = acp;
acp->cache = cache; acp->cache = cache;
env_rwsem_init(&acp->chunks_lock);
for (i = 0; i < ACP_MAX_BUCKETS; i++) { for (i = 0; i < ACP_MAX_BUCKETS; i++) {
INIT_LIST_HEAD(&acp->bucket_info[i].chunk_list); INIT_LIST_HEAD(&acp->bucket_info[i].chunk_list);
acp->bucket_info[i].threshold = acp->bucket_info[i].threshold =

View File

@ -467,6 +467,7 @@ int cleaning_policy_alru_initialize(ocf_cache_t cache, int init_metadata)
struct ocf_user_part *part; struct ocf_user_part *part;
ocf_part_id_t part_id; ocf_part_id_t part_id;
struct alru_context *alru; struct alru_context *alru;
int error = 0;
unsigned i; unsigned i;
alru = env_vzalloc(sizeof(*alru)); alru = env_vzalloc(sizeof(*alru));
@ -475,8 +476,19 @@ int cleaning_policy_alru_initialize(ocf_cache_t cache, int init_metadata)
return -OCF_ERR_NO_MEM; return -OCF_ERR_NO_MEM;
} }
for (i = 0; i < OCF_IO_CLASS_MAX; i++) for (i = 0; i < OCF_IO_CLASS_MAX; i++) {
env_spinlock_init(&alru->list_lock[i]); error = env_spinlock_init(&alru->list_lock[i]);
if (error)
break;
}
if (error) {
while (i--)
env_spinlock_destroy(&alru->list_lock[i]);
env_vfree(alru);
return error;
}
cache->cleaner.cleaning_policy_context = alru; cache->cleaner.cleaning_policy_context = alru;

View File

@ -110,13 +110,17 @@ int ocf_cache_line_concurrency_init(struct ocf_cache *cache)
/* Init concurrency control table */ /* Init concurrency control table */
for (i = 0; i < _WAITERS_LIST_ENTRIES; i++) { for (i = 0; i < _WAITERS_LIST_ENTRIES; i++) {
INIT_LIST_HEAD(&c->waiters_lsts[i].head); INIT_LIST_HEAD(&c->waiters_lsts[i].head);
env_spinlock_init(&c->waiters_lsts[i].lock); error = env_spinlock_init(&c->waiters_lsts[i].lock);
if (error)
goto spinlock_err;
} }
return 0; return 0;
spinlock_err:
while (i--)
env_spinlock_destroy(&c->waiters_lsts[i].lock);
ocf_cache_line_concurrency_init: ocf_cache_line_concurrency_init:
ocf_cache_log(cache, log_err, "Cannot initialize cache concurrency, " ocf_cache_log(cache, log_err, "Cannot initialize cache concurrency, "
"ERROR %d", error); "ERROR %d", error);

View File

@ -6,17 +6,35 @@
#include "ocf_metadata_concurrency.h" #include "ocf_metadata_concurrency.h"
#include "../metadata/metadata_misc.h" #include "../metadata/metadata_misc.h"
void ocf_metadata_concurrency_init(struct ocf_metadata_lock *metadata_lock) int ocf_metadata_concurrency_init(struct ocf_metadata_lock *metadata_lock)
{ {
int err = 0;
unsigned i; unsigned i;
env_spinlock_init(&metadata_lock->eviction); err = env_spinlock_init(&metadata_lock->eviction);
if (err)
return err;
env_rwlock_init(&metadata_lock->status); env_rwlock_init(&metadata_lock->status);
env_rwsem_init(&metadata_lock->global); err = env_rwsem_init(&metadata_lock->global);
if (err)
goto rwsem_err;
for (i = 0; i < OCF_IO_CLASS_MAX; i++) { for (i = 0; i < OCF_IO_CLASS_MAX; i++) {
env_spinlock_init(&metadata_lock->partition[i]); err = env_spinlock_init(&metadata_lock->partition[i]);
if (err)
goto spinlocks_err;
} }
return err;
spinlocks_err:
while (i--)
env_spinlock_destroy(&metadata_lock->partition[i]);
rwsem_err:
env_rwlock_destroy(&metadata_lock->status);
env_spinlock_destroy(&metadata_lock->eviction);
return err;
} }
void ocf_metadata_concurrency_deinit(struct ocf_metadata_lock *metadata_lock) void ocf_metadata_concurrency_deinit(struct ocf_metadata_lock *metadata_lock)

View File

@ -10,7 +10,7 @@
#define OCF_METADATA_RD 0 #define OCF_METADATA_RD 0
#define OCF_METADATA_WR 1 #define OCF_METADATA_WR 1
void ocf_metadata_concurrency_init(struct ocf_metadata_lock *metadata_lock); int ocf_metadata_concurrency_init(struct ocf_metadata_lock *metadata_lock);
void ocf_metadata_concurrency_deinit(struct ocf_metadata_lock *metadata_lock); void ocf_metadata_concurrency_deinit(struct ocf_metadata_lock *metadata_lock);

View File

@ -77,7 +77,7 @@ static int _ocf_discard_core(struct ocf_request *req)
ocf_io_set_cmpl(io, req, NULL, _ocf_discard_core_complete); ocf_io_set_cmpl(io, req, NULL, _ocf_discard_core_complete);
err = ocf_io_set_data(io, req->data, 0); err = ocf_io_set_data(io, req->data, 0);
if (err) { if (err) {
_ocf_discard_complete_req(req, err); _ocf_discard_core_complete(io, err);
return err; return err;
} }

View File

@ -39,7 +39,14 @@ int ocf_metadata_init(struct ocf_cache *cache,
return ret; return ret;
} }
ocf_metadata_concurrency_init(&cache->metadata.lock); ret = ocf_metadata_concurrency_init(&cache->metadata.lock);
if (ret) {
if (cache->metadata.iface.deinit)
cache->metadata.iface.deinit(cache);
ocf_metadata_io_deinit(cache);
return ret;
}
return 0; return 0;
} }

View File

@ -6,7 +6,6 @@
#ifndef __METADATA_SUPERBLOCK_H__ #ifndef __METADATA_SUPERBLOCK_H__
#define __METADATA_SUPERBLOCK_H__ #define __METADATA_SUPERBLOCK_H__
#include <ocf/ocf_def.h>
#include <ocf/ocf_def.h> #include <ocf/ocf_def.h>
#define CACHE_MAGIC_NUMBER 0x187E1CA6 #define CACHE_MAGIC_NUMBER 0x187E1CA6

View File

@ -568,10 +568,7 @@ static int _ocf_mngt_init_new_cache(struct ocf_cache_mngt_init_params *params)
goto lock_err; goto lock_err;
} }
if (!ocf_refcnt_inc(&cache->refcnt.cache)){ ENV_BUG_ON(!ocf_refcnt_inc(&cache->refcnt.cache));
result = -OCF_ERR_START_CACHE_FAIL;
goto flush_mutex_err;
}
/* start with freezed metadata ref counter to indicate detached device*/ /* start with freezed metadata ref counter to indicate detached device*/
ocf_refcnt_freeze(&cache->refcnt.metadata); ocf_refcnt_freeze(&cache->refcnt.metadata);
@ -586,8 +583,6 @@ static int _ocf_mngt_init_new_cache(struct ocf_cache_mngt_init_params *params)
return 0; return 0;
flush_mutex_err:
env_mutex_destroy(&cache->flush_mutex);
lock_err: lock_err:
ocf_mngt_cache_lock_deinit(cache); ocf_mngt_cache_lock_deinit(cache);
alloc_err: alloc_err:

View File

@ -385,21 +385,28 @@ ocf_freelist_t ocf_freelist_init(struct ocf_cache *cache)
freelist->lock = env_vzalloc(sizeof(freelist->lock[0]) * num); freelist->lock = env_vzalloc(sizeof(freelist->lock[0]) * num);
freelist->part = env_vzalloc(sizeof(freelist->part[0]) * num); freelist->part = env_vzalloc(sizeof(freelist->part[0]) * num);
if (!freelist->lock || !freelist->part) { if (!freelist->lock || !freelist->part)
env_vfree(freelist->lock); goto free_allocs;
env_vfree(freelist->part);
env_vfree(freelist);
return NULL;
}
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
env_spinlock_init(&freelist->lock[i]); if (env_spinlock_init(&freelist->lock[i]))
goto spinlock_err;
freelist->part[i].head = line_entries; freelist->part[i].head = line_entries;
freelist->part[i].tail = line_entries; freelist->part[i].tail = line_entries;
env_atomic64_set(&freelist->part[i].curr_size, 0); env_atomic64_set(&freelist->part[i].curr_size, 0);
} }
return freelist; return freelist;
spinlock_err:
while (i--)
env_spinlock_destroy(&freelist->lock[i]);
free_allocs:
env_vfree(freelist->lock);
env_vfree(freelist->part);
env_vfree(freelist);
return NULL;
} }
void ocf_freelist_deinit(ocf_freelist_t freelist) void ocf_freelist_deinit(ocf_freelist_t freelist)

View File

@ -32,7 +32,13 @@ int ocf_queue_create(ocf_cache_t cache, ocf_queue_t *queue,
} }
env_atomic_set(&tmp_queue->io_no, 0); env_atomic_set(&tmp_queue->io_no, 0);
env_spinlock_init(&tmp_queue->io_list_lock); result = env_spinlock_init(&tmp_queue->io_list_lock);
if (result) {
ocf_mngt_cache_put(cache);
free(tmp_queue);
return result;
}
INIT_LIST_HEAD(&tmp_queue->io_list); INIT_LIST_HEAD(&tmp_queue->io_list);
env_atomic_set(&tmp_queue->ref_count, 1); env_atomic_set(&tmp_queue->ref_count, 1);
tmp_queue->cache = cache; tmp_queue->cache = cache;

View File

@ -266,6 +266,9 @@ int ocf_stats_collect_part_core(ocf_core_t core, ocf_part_id_t part_id,
OCF_CHECK_NULL(core); OCF_CHECK_NULL(core);
if (part_id > OCF_IO_CLASS_ID_MAX)
return -OCF_ERR_INVAL;
cache = ocf_core_get_cache(core); cache = ocf_core_get_cache(core);
_ocf_stats_zero(usage); _ocf_stats_zero(usage);
@ -291,6 +294,9 @@ int ocf_stats_collect_part_cache(ocf_cache_t cache, ocf_part_id_t part_id,
OCF_CHECK_NULL(cache); OCF_CHECK_NULL(cache);
if (part_id > OCF_IO_CLASS_ID_MAX)
return -OCF_ERR_INVAL;
_ocf_stats_zero(usage); _ocf_stats_zero(usage);
_ocf_stats_zero(req); _ocf_stats_zero(req);
_ocf_stats_zero(blocks); _ocf_stats_zero(blocks);

View File

@ -146,7 +146,6 @@ ocf_error_t nhit_hash_init(uint64_t hash_size, nhit_hash_t *ctx)
for (i_locks = 0; i_locks < new_ctx->hash_entries; i_locks++) { for (i_locks = 0; i_locks < new_ctx->hash_entries; i_locks++) {
if (env_rwsem_init(&new_ctx->hash_locks[i_locks])) { if (env_rwsem_init(&new_ctx->hash_locks[i_locks])) {
result = -OCF_ERR_UNKNOWN; result = -OCF_ERR_UNKNOWN;
i_locks--;
goto dealloc_locks; goto dealloc_locks;
} }
} }
@ -163,14 +162,17 @@ ocf_error_t nhit_hash_init(uint64_t hash_size, nhit_hash_t *ctx)
env_atomic_set(&new_ctx->ring_buffer[i].counter, 0); env_atomic_set(&new_ctx->ring_buffer[i].counter, 0);
} }
env_spinlock_init(&new_ctx->rb_pointer_lock); result = env_spinlock_init(&new_ctx->rb_pointer_lock);
if (result)
goto dealloc_locks;
new_ctx->rb_pointer = 0; new_ctx->rb_pointer = 0;
*ctx = new_ctx; *ctx = new_ctx;
return 0; return 0;
dealloc_locks: dealloc_locks:
for (; i_locks >= 0; i_locks--) while (i_locks--)
ENV_BUG_ON(env_rwsem_destroy(&new_ctx->hash_locks[i_locks])); ENV_BUG_ON(env_rwsem_destroy(&new_ctx->hash_locks[i_locks]));
env_vfree(new_ctx->hash_locks); env_vfree(new_ctx->hash_locks);
dealloc_hash: dealloc_hash:

View File

@ -47,7 +47,12 @@ void _ocf_async_lock_run_waiters(struct ocf_async_lock *lock,
int ocf_async_lock_init(struct ocf_async_lock *lock, uint32_t waiter_priv_size) int ocf_async_lock_init(struct ocf_async_lock *lock, uint32_t waiter_priv_size)
{ {
env_spinlock_init(&lock->waiters_lock); int err = 0;
err = env_spinlock_init(&lock->waiters_lock);
if (err)
return err;
INIT_LIST_HEAD(&lock->waiters); INIT_LIST_HEAD(&lock->waiters);
lock->rd = 0; lock->rd = 0;
lock->wr = 0; lock->wr = 0;