diff --git a/env/posix/ocf_env.h b/env/posix/ocf_env.h index c0784ba..62d6e23 100644 --- a/env/posix/ocf_env.h +++ b/env/posix/ocf_env.h @@ -201,6 +201,16 @@ static inline void env_mutex_unlock(env_mutex *mutex) ENV_BUG_ON(pthread_mutex_unlock(&mutex->m)); } +static inline int env_mutex_destroy(env_mutex *mutex) +{ + if(pthread_mutex_destroy(&mutex->m)) + return 1; + + return 0; +} + +/* *** RECURSIVE MUTEX *** */ + typedef env_mutex env_rmutex; static inline int env_rmutex_init(env_rmutex *rmutex) @@ -229,6 +239,14 @@ static inline void env_rmutex_unlock(env_rmutex *rmutex) env_mutex_unlock(rmutex); } +static inline int env_rmutex_destroy(env_rmutex *rmutex) +{ + if(pthread_mutex_destroy(&rmutex->m)) + return 1; + + return 0; +} + /* *** RW SEMAPHORE *** */ typedef struct { pthread_rwlock_t lock; @@ -269,6 +287,11 @@ static inline int env_rwsem_down_write_trylock(env_rwsem *s) return pthread_rwlock_trywrlock(&s->lock) ? -OCF_ERR_NO_LOCK : 0; } +static inline int env_rwsem_destroy(env_rwsem *s) +{ + return pthread_rwlock_destroy(&s->lock); +} + /* *** COMPLETION *** */ struct completion { sem_t sem; @@ -291,6 +314,11 @@ static inline void env_completion_complete(env_completion *completion) sem_post(&completion->sem); } +static inline void env_completion_destroy(env_completion *completion) +{ + sem_destroy(&completion->sem); +} + /* *** ATOMIC VARIABLES *** */ typedef struct { @@ -445,6 +473,11 @@ static inline void env_spinlock_unlock(env_spinlock *l) (void)flags; \ env_spinlock_unlock(l) +static inline void env_spinlock_destroy(env_spinlock *l) +{ + ENV_BUG_ON(pthread_spin_destroy(&l->lock)); +} + /* *** RW LOCKS *** */ typedef struct { @@ -476,6 +509,11 @@ static inline void env_rwlock_write_unlock(env_rwlock *l) ENV_BUG_ON(pthread_rwlock_unlock(&l->lock)); } +static inline void env_rwlock_destroy(env_rwlock *l) +{ + ENV_BUG_ON(pthread_rwlock_destroy(&l->lock)); +} + /* *** WAITQUEUE *** */ typedef struct { @@ -490,6 +528,11 @@ typedef struct { __ret = __ret; \ }) +static inline void env_waitqueue_destroy(env_waitqueue *w) +{ + sem_destroy(&w->sem); +} + /* *** BIT OPERATIONS *** */ static inline void env_bit_set(int nr, volatile void *addr) diff --git a/src/cleaning/acp.c b/src/cleaning/acp.c index 956e5b0..533f4e6 100644 --- a/src/cleaning/acp.c +++ b/src/cleaning/acp.c @@ -233,8 +233,13 @@ void cleaning_policy_acp_init_cache_block(struct ocf_cache *cache, void cleaning_policy_acp_deinitialize(struct ocf_cache *cache) { + struct acp_context *acp; + _acp_remove_cores(cache); + acp = cache->cleaner.cleaning_policy_context; + env_rwsem_destroy(&acp->chunks_lock); + env_vfree(cache->cleaner.cleaning_policy_context); cache->cleaner.cleaning_policy_context = NULL; } diff --git a/src/concurrency/ocf_cache_line_concurrency.c b/src/concurrency/ocf_cache_line_concurrency.c index 432904c..ddbb626 100644 --- a/src/concurrency/ocf_cache_line_concurrency.c +++ b/src/concurrency/ocf_cache_line_concurrency.c @@ -134,6 +134,7 @@ ocf_cache_line_concurrency_init: */ void ocf_cache_line_concurrency_deinit(struct ocf_cache *cache) { + int i; struct ocf_cache_line_concurrency *concurrency; if (!cache->device->concurrency.cache_line) @@ -143,6 +144,11 @@ void ocf_cache_line_concurrency_deinit(struct ocf_cache *cache) concurrency = cache->device->concurrency.cache_line; + env_rwlock_destroy(&concurrency->lock); + + for (i = 0; i < _WAITERS_LIST_ENTRIES; i++) + env_spinlock_destroy(&concurrency->waiters_lsts[i].lock); + if (concurrency->access) OCF_REALLOC_DEINIT(&concurrency->access, &concurrency->access_limit); diff --git a/src/concurrency/ocf_metadata_concurrency.c b/src/concurrency/ocf_metadata_concurrency.c index a262cc3..5304780 100644 --- a/src/concurrency/ocf_metadata_concurrency.c +++ b/src/concurrency/ocf_metadata_concurrency.c @@ -12,6 +12,13 @@ void ocf_metadata_concurrency_init(struct ocf_cache *cache) env_rwsem_init(&cache->metadata.lock.collision); } +void ocf_metadata_concurrency_deinit(struct ocf_cache *cache) +{ + env_spinlock_destroy(&cache->metadata.lock.eviction); + env_rwlock_destroy(&cache->metadata.lock.status); + env_rwsem_destroy(&cache->metadata.lock.collision); +} + int ocf_metadata_concurrency_attached_init(struct ocf_cache *cache) { return 0; diff --git a/src/concurrency/ocf_metadata_concurrency.h b/src/concurrency/ocf_metadata_concurrency.h index e0be9c2..85b0c10 100644 --- a/src/concurrency/ocf_metadata_concurrency.h +++ b/src/concurrency/ocf_metadata_concurrency.h @@ -12,6 +12,8 @@ void ocf_metadata_concurrency_init(struct ocf_cache *cache); +void ocf_metadata_concurrency_deinit(struct ocf_cache *cache); + int ocf_metadata_concurrency_attached_init(struct ocf_cache *cache); static inline void ocf_metadata_eviction_lock(struct ocf_cache *cache) diff --git a/src/metadata/metadata.c b/src/metadata/metadata.c index 611ffc9..3f9ae8f 100644 --- a/src/metadata/metadata.c +++ b/src/metadata/metadata.c @@ -73,6 +73,8 @@ void ocf_metadata_deinit(struct ocf_cache *cache) cache->metadata.iface.deinit(cache); } + ocf_metadata_concurrency_deinit(cache); + ocf_metadata_io_deinit(cache); } diff --git a/src/metadata/metadata_raw_dynamic.c b/src/metadata/metadata_raw_dynamic.c index 230dbfe..e45ade1 100644 --- a/src/metadata/metadata_raw_dynamic.c +++ b/src/metadata/metadata_raw_dynamic.c @@ -129,6 +129,8 @@ int raw_dynamic_deinit(ocf_cache_t cache, for (i = 0; i < raw->ssd_pages; i++) env_secure_free(ctrl->pages[i], PAGE_SIZE); + env_mutex_destroy(&ctrl->lock); + env_vfree(ctrl); raw->priv = NULL; diff --git a/src/metadata/metadata_updater.c b/src/metadata/metadata_updater.c index 4c24475..f3bb357 100644 --- a/src/metadata/metadata_updater.c +++ b/src/metadata/metadata_updater.c @@ -33,6 +33,7 @@ void ocf_metadata_updater_kick(ocf_cache_t cache) void ocf_metadata_updater_stop(ocf_cache_t cache) { ctx_metadata_updater_stop(cache->owner, &cache->metadata_updater); + env_mutex_destroy(&cache->metadata_updater.syncher.lock); } void ocf_metadata_updater_set_priv(ocf_metadata_updater_t mu, void *priv) diff --git a/src/mngt/ocf_mngt_common.c b/src/mngt/ocf_mngt_common.c index 8e2a07f..bc21cd0 100644 --- a/src/mngt/ocf_mngt_common.c +++ b/src/mngt/ocf_mngt_common.c @@ -135,6 +135,7 @@ void ocf_mngt_cache_put(ocf_cache_t cache) ctx = cache->owner; ocf_metadata_deinit(cache); ocf_mngt_cache_lock_deinit(cache); + env_mutex_destroy(&cache->flush_mutex); env_vfree(cache); ocf_ctx_put(ctx); } diff --git a/src/ocf_ctx.c b/src/ocf_ctx.c index 16c123c..cab484d 100644 --- a/src/ocf_ctx.c +++ b/src/ocf_ctx.c @@ -233,6 +233,8 @@ void ocf_ctx_put(ocf_ctx_t ctx) ocf_mngt_core_pool_deinit(ctx); ocf_ctx_unregister_volume_types(ctx); + env_rmutex_destroy(&ctx->lock); + ocf_req_allocator_deinit(ctx); ocf_logger_close(&ctx->logger); env_free(ctx); diff --git a/src/ocf_queue.c b/src/ocf_queue.c index ffd034f..7657eee 100644 --- a/src/ocf_queue.c +++ b/src/ocf_queue.c @@ -60,6 +60,7 @@ void ocf_queue_put(ocf_queue_t queue) list_del(&queue->list); queue->ops->stop(queue); ocf_mngt_cache_put(queue->cache); + env_spinlock_destroy(&queue->io_list_lock); env_free(queue); } } diff --git a/src/ocf_volume.c b/src/ocf_volume.c index 7793b33..ebb1759 100644 --- a/src/ocf_volume.c +++ b/src/ocf_volume.c @@ -308,6 +308,7 @@ static void ocf_volume_close_end(void *ctx) env_completion *cmpl = ctx; env_completion_complete(cmpl); + env_completion_destroy(cmpl); } void ocf_volume_close(ocf_volume_t volume) diff --git a/src/utils/utils_async_lock.c b/src/utils/utils_async_lock.c index d730060..748260f 100644 --- a/src/utils/utils_async_lock.c +++ b/src/utils/utils_async_lock.c @@ -72,6 +72,8 @@ void ocf_async_lock_deinit(struct ocf_async_lock *lock) list_for_each_entry_safe(iter, temp, &lock->waiters, list) list_move_tail(&iter->list, &waiters); env_mutex_unlock(&lock->mutex); + + env_mutex_destroy(&lock->mutex); _ocf_async_lock_run_waiters(lock, &waiters, -OCF_ERR_NO_LOCK); }