Merge pull request #168 from robertbaldyga/config-helpers
Introduce helpers for setting config structures to defaults
This commit is contained in:
commit
7d493ae995
@ -104,16 +104,13 @@ int initialize_cache(ocf_ctx_t ctx, ocf_cache_t *cache)
|
||||
context.error = &ret;
|
||||
|
||||
/* Cache configuration */
|
||||
cache_cfg.backfill.max_queue_size = 65536;
|
||||
cache_cfg.backfill.queue_unblock_size = 60000;
|
||||
cache_cfg.cache_line_size = ocf_cache_line_size_4;
|
||||
cache_cfg.cache_mode = ocf_cache_mode_wt;
|
||||
ocf_mngt_cache_config_set_default(&cache_cfg);
|
||||
cache_cfg.metadata_volatile = true;
|
||||
cache_cfg.name = "cache1";
|
||||
|
||||
/* Cache deivce (volume) configuration */
|
||||
ocf_mngt_cache_device_config_set_default(&device_cfg);
|
||||
device_cfg.volume_type = VOL_TYPE;
|
||||
device_cfg.cache_line_size = ocf_cache_line_size_4;
|
||||
ret = ocf_uuid_set_str(&device_cfg.uuid, "cache");
|
||||
if (ret)
|
||||
return ret;
|
||||
@ -210,8 +207,9 @@ int initialize_core(ocf_cache_t cache, ocf_core_t *core)
|
||||
context.error = &ret;
|
||||
|
||||
/* Core configuration */
|
||||
core_cfg.volume_type = VOL_TYPE;
|
||||
ocf_mngt_core_config_set_default(&core_cfg);
|
||||
core_cfg.name = "core1";
|
||||
core_cfg.volume_type = VOL_TYPE;
|
||||
ret = ocf_uuid_set_str(&core_cfg.uuid, "core");
|
||||
if (ret)
|
||||
return ret;
|
||||
|
@ -234,6 +234,9 @@ typedef enum {
|
||||
* OCF supported cache line sizes in bytes
|
||||
*/
|
||||
typedef enum {
|
||||
ocf_cache_line_size_none = 0,
|
||||
/*!< None */
|
||||
|
||||
ocf_cache_line_size_4 = 4 * KiB,
|
||||
/*!< 4 kiB */
|
||||
|
||||
|
147
inc/ocf_mngt.h
147
inc/ocf_mngt.h
@ -40,11 +40,6 @@ struct ocf_mngt_core_config {
|
||||
*/
|
||||
const char *name;
|
||||
|
||||
/**
|
||||
* @brief OCF cache ID number
|
||||
*/
|
||||
ocf_cache_id_t cache_id;
|
||||
|
||||
/**
|
||||
* @brief Add core to pool if cache isn't present or add core to
|
||||
* earlier loaded cache
|
||||
@ -60,6 +55,25 @@ struct ocf_mngt_core_config {
|
||||
} user_metadata;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Initialize core config to default values
|
||||
*
|
||||
* @note This function doesn't initiialize uuid and volume_type fields
|
||||
* which have no default values and are required to be set by user.
|
||||
*
|
||||
* @param[in] cfg Core config stucture
|
||||
*/
|
||||
static inline void ocf_mngt_core_config_set_default(
|
||||
struct ocf_mngt_core_config *cfg)
|
||||
{
|
||||
cfg->core_id = OCF_CORE_ID_INVALID;
|
||||
cfg->name = NULL;
|
||||
cfg->try_add = false;
|
||||
cfg->seq_cutoff_threshold = 1024;
|
||||
cfg->user_metadata.data = NULL;
|
||||
cfg->user_metadata.size = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get number of OCF caches
|
||||
*
|
||||
@ -74,8 +88,8 @@ uint32_t ocf_mngt_cache_get_count(ocf_ctx_t ctx);
|
||||
/**
|
||||
* @brief Get OCF cache
|
||||
*
|
||||
* @note This function on success also increasing reference counter in given
|
||||
* cache
|
||||
* @note This function on success also increasing reference counter
|
||||
* in given cache
|
||||
*
|
||||
* @param[in] ctx OCF context
|
||||
* @param[in] id OCF cache ID
|
||||
@ -282,6 +296,72 @@ struct ocf_mngt_cache_config {
|
||||
bool use_submit_io_fast;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Initialize core config to default values
|
||||
*
|
||||
* @param[in] cfg Cache config stucture
|
||||
*/
|
||||
static inline void ocf_mngt_cache_config_set_default(
|
||||
struct ocf_mngt_cache_config *cfg)
|
||||
{
|
||||
cfg->id = OCF_CACHE_ID_INVALID;
|
||||
cfg->name = NULL;
|
||||
cfg->cache_mode = ocf_cache_mode_default;
|
||||
cfg->eviction_policy = ocf_eviction_default;
|
||||
cfg->cache_line_size = ocf_cache_line_size_4;
|
||||
cfg->metadata_layout = ocf_metadata_layout_default;
|
||||
cfg->metadata_volatile = false;
|
||||
cfg->backfill.max_queue_size = 65536;
|
||||
cfg->backfill.queue_unblock_size = 60000;
|
||||
cfg->locked = false;
|
||||
cfg->pt_unaligned_io = false;
|
||||
cfg->use_submit_io_fast = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Start cache instance
|
||||
*
|
||||
* @param[in] ctx OCF context
|
||||
* @param[out] cache Cache handle
|
||||
* @param[in] cfg Starting cache configuration
|
||||
*
|
||||
* @retval 0 Cache started successfully
|
||||
* @retval Non-zero Error occurred and starting cache failed
|
||||
*/
|
||||
int ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache,
|
||||
struct ocf_mngt_cache_config *cfg);
|
||||
|
||||
/**
|
||||
* @brief Set queue to be used during management operations
|
||||
*
|
||||
* @param[in] cache Cache object
|
||||
* @param[in] queue Queue object
|
||||
*
|
||||
* @retval 0 Success
|
||||
* @retval Non-zero Error occurred
|
||||
*/
|
||||
int ocf_mngt_cache_set_mngt_queue(ocf_cache_t cache, ocf_queue_t queue);
|
||||
|
||||
/**
|
||||
* @brief Completion callback of cache stop operation
|
||||
*
|
||||
* @param[in] cache Cache handle
|
||||
* @param[in] priv Callback context
|
||||
* @param[in] error Error code (zero on success)
|
||||
*/
|
||||
typedef void (*ocf_mngt_cache_stop_end_t)(ocf_cache_t cache,
|
||||
void *priv, int error);
|
||||
|
||||
/**
|
||||
* @brief Stop cache instance
|
||||
*
|
||||
* @param[in] cache Cache handle
|
||||
* @param[in] cmpl Completion callback
|
||||
* @param[in] priv Completion callback context
|
||||
*/
|
||||
void ocf_mngt_cache_stop(ocf_cache_t cache,
|
||||
ocf_mngt_cache_stop_end_t cmpl, void *priv);
|
||||
|
||||
/**
|
||||
* @brief Cache attach configuration
|
||||
*/
|
||||
@ -342,48 +422,23 @@ struct ocf_mngt_cache_device_config {
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Start cache instance
|
||||
* @brief Initialize core config to default values
|
||||
*
|
||||
* @param[in] ctx OCF context
|
||||
* @param[out] cache Cache handle
|
||||
* @param[in] cfg Starting cache configuration
|
||||
* @note This function doesn't initiialize uuid and volume_type fields
|
||||
* which have no default values and are required to be set by user.
|
||||
*
|
||||
* @retval 0 Cache started successfully
|
||||
* @retval Non-zero Error occurred and starting cache failed
|
||||
* @param[in] cfg Cache device config stucture
|
||||
*/
|
||||
int ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache,
|
||||
struct ocf_mngt_cache_config *cfg);
|
||||
|
||||
/**
|
||||
* @brief Set queue to be used during management operations
|
||||
*
|
||||
* @param[in] cache Cache object
|
||||
* @param[in] queue Queue object
|
||||
*
|
||||
* @retval 0 Success
|
||||
* @retval Non-zero Error occurred
|
||||
*/
|
||||
int ocf_mngt_cache_set_mngt_queue(ocf_cache_t cache, ocf_queue_t queue);
|
||||
|
||||
/**
|
||||
* @brief Completion callback of cache stop operation
|
||||
*
|
||||
* @param[in] cache Cache handle
|
||||
* @param[in] priv Callback context
|
||||
* @param[in] error Error code (zero on success)
|
||||
*/
|
||||
typedef void (*ocf_mngt_cache_stop_end_t)(ocf_cache_t cache,
|
||||
void *priv, int error);
|
||||
|
||||
/**
|
||||
* @brief Stop cache instance
|
||||
*
|
||||
* @param[in] cache Cache handle
|
||||
* @param[in] cmpl Completion callback
|
||||
* @param[in] priv Completion callback context
|
||||
*/
|
||||
void ocf_mngt_cache_stop(ocf_cache_t cache,
|
||||
ocf_mngt_cache_stop_end_t cmpl, void *priv);
|
||||
static inline void ocf_mngt_cache_device_config_set_default(
|
||||
struct ocf_mngt_cache_device_config *cfg)
|
||||
{
|
||||
cfg->cache_line_size = ocf_cache_line_size_none;
|
||||
cfg->open_cores = true;
|
||||
cfg->force = false;
|
||||
cfg->perform_test = true;
|
||||
cfg->discard_on_start = true;
|
||||
cfg->volume_params = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get amount of free RAM needed to attach cache volume
|
||||
|
@ -1594,7 +1594,7 @@ static int _ocf_mngt_cache_validate_device_cfg(
|
||||
if (device_cfg->uuid.size > OCF_VOLUME_UUID_MAX_SIZE)
|
||||
return -OCF_ERR_INVAL;
|
||||
|
||||
if (device_cfg->cache_line_size &&
|
||||
if (device_cfg->cache_line_size != ocf_cache_line_size_none &&
|
||||
!ocf_cache_line_size_is_valid(device_cfg->cache_line_size))
|
||||
return -OCF_ERR_INVALID_CACHE_LINE_SIZE;
|
||||
|
||||
|
@ -358,11 +358,11 @@ static inline void ocf_set_clean_map_info(struct ocf_request *req)
|
||||
static inline bool ocf_cache_line_size_is_valid(uint64_t size)
|
||||
{
|
||||
switch (size) {
|
||||
case 4 * KiB:
|
||||
case 8 * KiB:
|
||||
case 16 * KiB:
|
||||
case 32 * KiB:
|
||||
case 64 * KiB:
|
||||
case ocf_cache_line_size_4:
|
||||
case ocf_cache_line_size_8:
|
||||
case ocf_cache_line_size_16:
|
||||
case ocf_cache_line_size_32:
|
||||
case ocf_cache_line_size_64:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user