Merge pull request #168 from robertbaldyga/config-helpers

Introduce helpers for setting config structures to defaults
This commit is contained in:
Adam Rutkowski 2019-05-24 04:31:28 -04:00 committed by GitHub
commit 7d493ae995
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 114 additions and 58 deletions

View File

@ -104,16 +104,13 @@ int initialize_cache(ocf_ctx_t ctx, ocf_cache_t *cache)
context.error = &ret; context.error = &ret;
/* Cache configuration */ /* Cache configuration */
cache_cfg.backfill.max_queue_size = 65536; ocf_mngt_cache_config_set_default(&cache_cfg);
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;
cache_cfg.metadata_volatile = true; cache_cfg.metadata_volatile = true;
cache_cfg.name = "cache1"; cache_cfg.name = "cache1";
/* Cache deivce (volume) configuration */ /* Cache deivce (volume) configuration */
ocf_mngt_cache_device_config_set_default(&device_cfg);
device_cfg.volume_type = VOL_TYPE; 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"); ret = ocf_uuid_set_str(&device_cfg.uuid, "cache");
if (ret) if (ret)
return ret; return ret;
@ -210,8 +207,9 @@ int initialize_core(ocf_cache_t cache, ocf_core_t *core)
context.error = &ret; context.error = &ret;
/* Core configuration */ /* Core configuration */
core_cfg.volume_type = VOL_TYPE; ocf_mngt_core_config_set_default(&core_cfg);
core_cfg.name = "core1"; core_cfg.name = "core1";
core_cfg.volume_type = VOL_TYPE;
ret = ocf_uuid_set_str(&core_cfg.uuid, "core"); ret = ocf_uuid_set_str(&core_cfg.uuid, "core");
if (ret) if (ret)
return ret; return ret;

View File

@ -234,6 +234,9 @@ typedef enum {
* OCF supported cache line sizes in bytes * OCF supported cache line sizes in bytes
*/ */
typedef enum { typedef enum {
ocf_cache_line_size_none = 0,
/*!< None */
ocf_cache_line_size_4 = 4 * KiB, ocf_cache_line_size_4 = 4 * KiB,
/*!< 4 kiB */ /*!< 4 kiB */

View File

@ -40,11 +40,6 @@ struct ocf_mngt_core_config {
*/ */
const char *name; 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 * @brief Add core to pool if cache isn't present or add core to
* earlier loaded cache * earlier loaded cache
@ -60,6 +55,25 @@ struct ocf_mngt_core_config {
} user_metadata; } 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 * @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 * @brief Get OCF cache
* *
* @note This function on success also increasing reference counter in given * @note This function on success also increasing reference counter
* cache * in given cache
* *
* @param[in] ctx OCF context * @param[in] ctx OCF context
* @param[in] id OCF cache ID * @param[in] id OCF cache ID
@ -282,6 +296,72 @@ struct ocf_mngt_cache_config {
bool use_submit_io_fast; 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 * @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 * @note This function doesn't initiialize uuid and volume_type fields
* @param[out] cache Cache handle * which have no default values and are required to be set by user.
* @param[in] cfg Starting cache configuration
* *
* @retval 0 Cache started successfully * @param[in] cfg Cache device config stucture
* @retval Non-zero Error occurred and starting cache failed
*/ */
int ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache, static inline void ocf_mngt_cache_device_config_set_default(
struct ocf_mngt_cache_config *cfg); struct ocf_mngt_cache_device_config *cfg)
{
/** cfg->cache_line_size = ocf_cache_line_size_none;
* @brief Set queue to be used during management operations cfg->open_cores = true;
* cfg->force = false;
* @param[in] cache Cache object cfg->perform_test = true;
* @param[in] queue Queue object cfg->discard_on_start = true;
* cfg->volume_params = NULL;
* @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 Get amount of free RAM needed to attach cache volume * @brief Get amount of free RAM needed to attach cache volume

View File

@ -1594,7 +1594,7 @@ static int _ocf_mngt_cache_validate_device_cfg(
if (device_cfg->uuid.size > OCF_VOLUME_UUID_MAX_SIZE) if (device_cfg->uuid.size > OCF_VOLUME_UUID_MAX_SIZE)
return -OCF_ERR_INVAL; 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)) !ocf_cache_line_size_is_valid(device_cfg->cache_line_size))
return -OCF_ERR_INVALID_CACHE_LINE_SIZE; return -OCF_ERR_INVALID_CACHE_LINE_SIZE;

View File

@ -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) static inline bool ocf_cache_line_size_is_valid(uint64_t size)
{ {
switch (size) { switch (size) {
case 4 * KiB: case ocf_cache_line_size_4:
case 8 * KiB: case ocf_cache_line_size_8:
case 16 * KiB: case ocf_cache_line_size_16:
case 32 * KiB: case ocf_cache_line_size_32:
case 64 * KiB: case ocf_cache_line_size_64:
return true; return true;
default: default:
return false; return false;