2022-06-03 19:15:11 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2016-05-04 21:39:50 +00:00
|
|
|
* Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
|
2022-11-01 20:26:26 +00:00
|
|
|
* Copyright (C) 2016 Intel Corporation.
|
2016-05-04 21:39:50 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Configuration file parser
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SPDK_CONF_H
|
|
|
|
#define SPDK_CONF_H
|
|
|
|
|
2017-05-01 20:22:48 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2016-05-04 21:39:50 +00:00
|
|
|
|
2017-12-07 20:25:19 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2016-11-15 22:31:34 +00:00
|
|
|
struct spdk_conf_value;
|
|
|
|
struct spdk_conf_item;
|
|
|
|
struct spdk_conf_section;
|
|
|
|
struct spdk_conf;
|
2016-05-04 21:39:50 +00:00
|
|
|
|
2017-12-22 02:47:30 +00:00
|
|
|
/**
|
|
|
|
* Allocate a configuration struct used for the initialization of SPDK app.
|
|
|
|
*
|
|
|
|
* \return a pointer to the allocated configuration struct.
|
|
|
|
*/
|
2016-05-04 21:39:50 +00:00
|
|
|
struct spdk_conf *spdk_conf_allocate(void);
|
2017-12-22 02:47:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Free the configuration struct.
|
|
|
|
*
|
|
|
|
* \param cp Configuration struct to free.
|
|
|
|
*/
|
2016-05-04 21:39:50 +00:00
|
|
|
void spdk_conf_free(struct spdk_conf *cp);
|
2017-12-22 02:47:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Read configuration file for spdk_conf struct.
|
|
|
|
*
|
|
|
|
* \param cp Configuration struct used for the initialization of SPDK app.
|
|
|
|
* \param file File to read that is created by user to configure SPDK app.
|
|
|
|
*
|
|
|
|
* \return 0 on success, -1 on failure.
|
|
|
|
*/
|
2016-05-04 21:39:50 +00:00
|
|
|
int spdk_conf_read(struct spdk_conf *cp, const char *file);
|
2017-12-22 02:47:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the specified section of the configuration.
|
|
|
|
*
|
|
|
|
* \param cp Configuration struct used for the initialization of SPDK app.
|
|
|
|
* \param name Name of section to find.
|
|
|
|
*
|
|
|
|
* \return a pointer to the requested section on success or NULL otherwise.
|
|
|
|
*/
|
2016-05-04 21:39:50 +00:00
|
|
|
struct spdk_conf_section *spdk_conf_find_section(struct spdk_conf *cp, const char *name);
|
|
|
|
|
2017-12-22 02:47:30 +00:00
|
|
|
/**
|
|
|
|
* Get the first section of the configuration.
|
|
|
|
*
|
|
|
|
* \param cp Configuration struct used for the initialization of SPDK app.
|
|
|
|
*
|
|
|
|
* \return a pointer to the requested section on success or NULL otherwise.
|
|
|
|
*/
|
2016-05-12 22:38:22 +00:00
|
|
|
struct spdk_conf_section *spdk_conf_first_section(struct spdk_conf *cp);
|
2017-12-22 02:47:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the next section of the configuration.
|
|
|
|
*
|
|
|
|
* \param sp The current section of the configuration.
|
|
|
|
*
|
|
|
|
* \return a pointer to the requested section on success or NULL otherwise.
|
|
|
|
*/
|
2016-05-12 22:38:22 +00:00
|
|
|
struct spdk_conf_section *spdk_conf_next_section(struct spdk_conf_section *sp);
|
|
|
|
|
2017-12-22 02:47:30 +00:00
|
|
|
/**
|
|
|
|
* Match prefix of the name of section.
|
|
|
|
*
|
|
|
|
* \param sp The section of the configuration.
|
|
|
|
* \param name_prefix Prefix name to match.
|
|
|
|
*
|
|
|
|
* \return ture on success, false on failure.
|
|
|
|
*/
|
2016-05-04 21:39:50 +00:00
|
|
|
bool spdk_conf_section_match_prefix(const struct spdk_conf_section *sp, const char *name_prefix);
|
2017-12-22 02:47:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the name of the section.
|
|
|
|
*
|
|
|
|
* \param sp The section of the configuration.
|
|
|
|
*
|
|
|
|
* \return the name of the section.
|
|
|
|
*/
|
2016-11-15 22:02:56 +00:00
|
|
|
const char *spdk_conf_section_get_name(const struct spdk_conf_section *sp);
|
2017-12-22 02:47:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the number of the section.
|
|
|
|
*
|
|
|
|
* \param sp The section of the configuration.
|
|
|
|
*
|
|
|
|
* \return the number of the section.
|
|
|
|
*/
|
2016-11-15 22:02:56 +00:00
|
|
|
int spdk_conf_section_get_num(const struct spdk_conf_section *sp);
|
2017-12-22 02:47:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the value of the item with name 'key' in the section.
|
|
|
|
*
|
|
|
|
* If key appears multiple times, idx1 will control which version to retrieve.
|
|
|
|
* Indices will start from the top of the configuration file at 0 and increment
|
2021-11-25 01:40:58 +00:00
|
|
|
* by one for each new appearance. If the configuration key contains multiple
|
2017-12-22 02:47:30 +00:00
|
|
|
* whitespace delimited values, idx2 controls which value is returned. The index
|
|
|
|
* begins at 0.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* \param sp The section of the configuration.
|
|
|
|
* \param key Name of item.
|
|
|
|
* \param idx1 The index into the item list for the key.
|
|
|
|
* \param idx2 The index into the value list for the item.
|
|
|
|
*
|
|
|
|
* \return the requested value on success or NULL otherwise.
|
|
|
|
*/
|
2016-05-04 21:39:50 +00:00
|
|
|
char *spdk_conf_section_get_nmval(struct spdk_conf_section *sp, const char *key,
|
|
|
|
int idx1, int idx2);
|
2017-12-22 02:47:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the first value of the item with name 'key' in the section.
|
|
|
|
*
|
|
|
|
* \param sp The section of the configuration.
|
|
|
|
* \param key Name of item.
|
|
|
|
* \param idx The index into the value list for the item.
|
|
|
|
*
|
|
|
|
* \return the requested value on success or NULL otherwise.
|
|
|
|
*/
|
2016-05-04 21:39:50 +00:00
|
|
|
char *spdk_conf_section_get_nval(struct spdk_conf_section *sp, const char *key, int idx);
|
2017-12-22 02:47:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the first value of the first item with name 'key' in the section.
|
|
|
|
*
|
|
|
|
* \param sp The section of the configuration.
|
|
|
|
* \param key Name of item.
|
|
|
|
*
|
|
|
|
* \return the requested value on success or NULL otherwise.
|
|
|
|
*/
|
2016-05-04 21:39:50 +00:00
|
|
|
char *spdk_conf_section_get_val(struct spdk_conf_section *sp, const char *key);
|
2017-12-22 02:47:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the first value of the first item with name 'key' in the section.
|
|
|
|
*
|
|
|
|
* \param sp The section of the configuration.
|
|
|
|
* \param key Name of item.
|
|
|
|
*
|
|
|
|
* \return the requested value on success or NULL otherwise.
|
|
|
|
*/
|
2016-05-04 21:39:50 +00:00
|
|
|
int spdk_conf_section_get_intval(struct spdk_conf_section *sp, const char *key);
|
2017-12-22 02:47:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the bool value of the item with name 'key' in the section.
|
|
|
|
*
|
|
|
|
* This is used to check whether the service is enabled.
|
|
|
|
*
|
|
|
|
* \param sp The section of the configuration.
|
|
|
|
* \param key Name of item.
|
|
|
|
* \param default_val Default value.
|
|
|
|
*
|
|
|
|
* \return true if matching 'Yes/Y/True', false if matching 'No/N/False', default value otherwise.
|
|
|
|
*/
|
2017-03-30 18:08:32 +00:00
|
|
|
bool spdk_conf_section_get_boolval(struct spdk_conf_section *sp, const char *key, bool default_val);
|
2016-05-04 21:39:50 +00:00
|
|
|
|
2017-12-22 02:47:30 +00:00
|
|
|
/**
|
|
|
|
* Set the configuration as the default.
|
|
|
|
*
|
|
|
|
* \param cp Configuration to set.
|
|
|
|
*/
|
2016-05-04 21:39:50 +00:00
|
|
|
void spdk_conf_set_as_default(struct spdk_conf *cp);
|
|
|
|
|
2020-07-17 10:46:14 +00:00
|
|
|
/**
|
|
|
|
* Disable sections merging during 'spdk_conf_read()'
|
|
|
|
*
|
|
|
|
* \param cp Configuration to be read
|
|
|
|
*/
|
|
|
|
void spdk_conf_disable_sections_merge(struct spdk_conf *cp);
|
|
|
|
|
2017-12-07 20:25:19 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-05-04 21:39:50 +00:00
|
|
|
#endif
|