Add API function ocf_cache_wait_for_io_finish()

Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
Robert Baldyga 2019-02-20 11:16:06 +01:00
parent 435cc6209a
commit 44ed250d41
6 changed files with 35 additions and 30 deletions

View File

@ -172,6 +172,13 @@ bool ocf_cache_is_device_attached(ocf_cache_t cache);
*/
bool ocf_cache_is_running(ocf_cache_t cache);
/**
* @brief Wait for all IO to finish
*
* @param[in] cache Cache object
*/
void ocf_cache_wait_for_io_finish(ocf_cache_t cache);
/**
* @brief Get cache mode of given cache object
*

View File

@ -1559,7 +1559,7 @@ static int _ocf_mngt_cache_unplug(ocf_cache_t cache, bool stop)
cache->device = NULL;
env_atomic_set(&cache->attached, 0);
/* TODO: this should be removed from detach after 'attached' stats
/* TODO: this should be removed from detach after 'attached' stats
are better separated in statistics */
_ocf_mngt_init_attached_nonpersistent(cache);
@ -1579,7 +1579,7 @@ static int _ocf_mngt_cache_stop(ocf_cache_t cache)
env_bit_set(ocf_cache_state_stopping, &cache->cache_state);
env_bit_clear(ocf_cache_state_running, &cache->cache_state);
ocf_mngt_wait_for_io_finish(cache);
ocf_cache_wait_for_io_finish(cache);
/* All exported objects removed, cleaning up rest. */
for (i = 0, j = 0; j < no && i < OCF_CORE_MAX; i++) {
@ -1681,7 +1681,7 @@ int ocf_mngt_cache_stop(ocf_cache_t cache)
{
int result;
char cache_name[OCF_CACHE_NAME_SIZE];
ocf_ctx_t context;
ocf_ctx_t ctx;
OCF_CHECK_NULL(cache);
@ -1690,21 +1690,21 @@ int ocf_mngt_cache_stop(ocf_cache_t cache)
if (result)
return result;
context = ocf_cache_get_ctx(cache);
ctx = ocf_cache_get_ctx(cache);
ocf_cache_log(cache, log_info, "Stopping cache\n");
result = _ocf_mngt_cache_stop(cache);
if (result == -OCF_ERR_WRITE_CACHE) {
ocf_log(context, log_warn, "Stopped cache %s with "
"errors\n", cache_name);
ocf_log(ctx, log_warn, "Stopped cache %s with errors\n",
cache_name);
} else if (result) {
ocf_log(context, log_err, "Stopping cache %s "
"failed\n", cache_name);
ocf_log(ctx, log_err, "Stopping cache %s failed\n",
cache_name);
} else {
ocf_log(context, log_info, "Cache %s successfully "
"stopped\n", cache_name);
ocf_log(ctx, log_info, "Cache %s successfully stopped\n",
cache_name);
}
return result;

View File

@ -434,15 +434,3 @@ int ocf_mngt_cache_visit_reverse(ocf_ctx_t ocf_ctx,
return result;
}
void ocf_mngt_wait_for_io_finish(ocf_cache_t cache)
{
uint32_t req_active = 0;
do {
req_active = ocf_req_get_allocated(cache);
if (req_active)
env_msleep(500);
} while (req_active);
}

View File

@ -24,8 +24,6 @@ int cache_mng_thread_io_requests(void *data);
bool ocf_mngt_cache_is_dirty(ocf_cache_t cache);
void ocf_mngt_wait_for_io_finish(ocf_cache_t cache);
int ocf_mngt_add_partition_to_cache(struct ocf_cache *cache,
ocf_part_id_t part_id, const char *name, uint32_t min_size,
uint32_t max_size, uint8_t priority, bool valid);

View File

@ -7,6 +7,7 @@
#include "metadata/metadata.h"
#include "engine/cache_engine.h"
#include "utils/utils_cache_line.h"
#include "utils/utils_req.h"
#include "ocf_priv.h"
#include "ocf_cache_priv.h"
@ -51,6 +52,17 @@ bool ocf_cache_is_device_attached(ocf_cache_t cache)
return env_atomic_read(&(cache)->attached);
}
void ocf_cache_wait_for_io_finish(ocf_cache_t cache)
{
uint32_t req_active = 0;
do {
req_active = ocf_req_get_allocated(cache);
if (req_active)
env_msleep(500);
} while (req_active);
}
ocf_cache_mode_t ocf_cache_get_mode(ocf_cache_t cache)
{
OCF_CHECK_NULL(cache);

View File

@ -39,7 +39,7 @@ static void ocf_init_queue(struct ocf_queue *q)
INIT_LIST_HEAD(&q->io_list);
}
int ocf_start_queues(struct ocf_cache *cache)
int ocf_start_queues(ocf_cache_t cache)
{
int id, result = 0;
struct ocf_queue *q;
@ -63,17 +63,17 @@ int ocf_start_queues(struct ocf_cache *cache)
return result;
}
void ocf_stop_queues(struct ocf_cache *dev)
void ocf_stop_queues(ocf_cache_t cache)
{
int i;
struct ocf_queue *curr;
ocf_mngt_wait_for_io_finish(dev);
ocf_cache_wait_for_io_finish(cache);
/* Stop IO threads. */
for (i = 0 ; i < dev->io_queues_no; i++) {
curr = &dev->io_queues[i];
ctx_queue_stop(dev->owner, curr);
for (i = 0 ; i < cache->io_queues_no; i++) {
curr = &cache->io_queues[i];
ctx_queue_stop(cache->owner, curr);
}
}