提交 f75abd02 编写于 作者: L LiFeng 提交者: lifeng68

driver: refact init progress

Signed-off-by: NLiFeng <lifeng68@huawei.com>
上级 89a3dcbb
......@@ -45,6 +45,7 @@
#include "engine.h"
#include "utils.h"
#include "isulad_config.h"
#include "storage.h"
#include "image.h"
#include "sysinfo.h"
#include "verify.h"
......@@ -1090,6 +1091,51 @@ out:
return ret;
}
static int storage_module_init_helper(const struct service_arguments *args)
{
int ret = 0;
struct storage_module_init_options *storage_opts = NULL;
storage_opts = util_common_calloc_s(sizeof(struct storage_module_init_options));
if (storage_opts == NULL) {
ERROR("Memory out");
ret = -1;
goto out;
}
storage_opts->driver_name = util_strdup_s(args->json_confs->storage_driver);
storage_opts->storage_root = util_path_join(args->json_confs->graph, GRAPH_ROOTPATH_NAME);
if (storage_opts->storage_root == NULL) {
ERROR("Failed to get storage root dir");
ret = -1;
goto out;
}
storage_opts->storage_run_root = util_path_join(args->json_confs->state, GRAPH_ROOTPATH_NAME);
if (storage_opts->storage_run_root == NULL) {
ERROR("Failed to get storage run root dir");
ret = -1;
goto out;
}
if (dup_array_of_strings((const char **)args->json_confs->storage_opts,
args->json_confs->storage_opts_len, &storage_opts->driver_opts, &storage_opts->driver_opts_len) != 0) {
ERROR("Failed to get storage storage opts");
ret = -1;
goto out;
}
if (storage_module_init(storage_opts) != 0) {
ERROR("Failed to init storage module");
ret = -1;
goto out;
}
out:
free_storage_module_init_options(storage_opts);
return ret;
}
static int isulad_server_init_common()
{
int ret = -1;
......@@ -1112,9 +1158,7 @@ static int isulad_server_init_common()
}
#ifdef ENABLE_OCI_IMAGE
if (graphdriver_init(args->json_confs->storage_driver, args->json_confs->graph,
args->json_confs->storage_opts,
args->json_confs->storage_opts_len) != 0) {
if (storage_module_init_helper(args) != 0) {
goto out;
}
#endif
......
......@@ -30,9 +30,9 @@
#include "isulad_config.h"
#include "sysinfo.h"
#include "libisulad.h"
#include "storage.h"
#define ENGINE_ROOTPATH_NAME "engines"
#define GRAPH_ROOTPATH_NAME "storage"
#define GRAPH_ROOTPATH_CHECKED_FLAG "NEED_CHECK"
#define INCREMENT_INTREVAL 2
......@@ -215,45 +215,6 @@ free_out:
return epath;
}
/* conf get graph rootpath */
char *conf_get_graph_rootpath()
{
char *epath = NULL;
char *rootpath = NULL;
size_t len;
rootpath = conf_get_isulad_rootdir();
if (rootpath == NULL) {
ERROR("Get rootpath failed");
return epath;
}
if (strlen(rootpath) > (SIZE_MAX - strlen(GRAPH_ROOTPATH_NAME)) - 2) {
ERROR("Root path is too long");
goto free_out;
}
len = strlen(rootpath) + 1 + strlen(GRAPH_ROOTPATH_NAME) + 1;
if (len > PATH_MAX) {
ERROR("The size of path exceeds the limit");
goto free_out;
}
epath = util_common_calloc_s(len);
if (epath == NULL) {
ERROR("Out of memory");
goto free_out;
}
int nret = snprintf(epath, len, "%s/%s", rootpath, GRAPH_ROOTPATH_NAME);
if (nret < 0 || (size_t)nret >= len) {
ERROR("Sprintf graph path failed");
free(epath);
epath = NULL;
}
free_out:
free(rootpath);
return epath;
}
/* conf get graph checked flag file path */
char *conf_get_graph_check_flag_file()
{
......@@ -293,45 +254,6 @@ free_out:
return epath;
}
/* conf get graph run path */
char *conf_get_graph_run_path()
{
char *epath = NULL;
char *rootpath = NULL;
size_t len;
rootpath = conf_get_isulad_statedir();
if (rootpath == NULL) {
ERROR("Get rootpath failed");
return epath;
}
if (strlen(rootpath) > (SIZE_MAX - strlen(GRAPH_ROOTPATH_NAME)) - 2) {
ERROR("Root path is too long");
goto free_out;
}
len = strlen(rootpath) + 1 + strlen(GRAPH_ROOTPATH_NAME) + 1;
if (len > PATH_MAX) {
ERROR("The size of path exceeds the limit");
goto free_out;
}
epath = util_common_calloc_s(len);
if (epath == NULL) {
ERROR("Out of memory");
goto free_out;
}
int nret = snprintf(epath, len, "%s/%s", rootpath, GRAPH_ROOTPATH_NAME);
if (nret < 0 || (size_t)nret >= len) {
ERROR("Sprintf graph run path failed");
free(epath);
epath = NULL;
}
free_out:
free(rootpath);
return epath;
}
/* conf get routine rootdir */
char *conf_get_routine_rootdir(const char *runtime)
{
......
......@@ -72,10 +72,6 @@ unsigned int conf_get_start_timeout();
int init_cgroups_path(const char *path, int recursive_depth);
char *conf_get_graph_rootpath();
char *conf_get_graph_run_path();
char **conf_get_storage_opts();
char **conf_get_insecure_registry_list();
......
......@@ -28,50 +28,6 @@ static int pack_global_graph_driver(const char * const *options, bool ignore_sto
}
#endif
static int pack_global_graph_root(const char * const *options, char *params[], size_t *count)
{
int ret = -1;
char *graph_root = NULL;
size_t i = 0;
i = *count;
graph_root = conf_get_graph_rootpath();
if (graph_root == NULL) {
COMMAND_ERROR("Failed to get graph root directory");
goto out;
}
add_array_kv(params, PARAM_NUM, &i, options[GB_OPTION_GRAPH_ROOT], graph_root);
ret = 0;
*count = i;
out:
free(graph_root);
return ret;
}
static int pack_global_graph_run(const char * const *options, char *params[], size_t *count)
{
int ret = -1;
char *graph_run = NULL;
size_t i = 0;
i = *count;
graph_run = conf_get_graph_run_path();
if (graph_run == NULL) {
COMMAND_ERROR("Failed to get graph run directory");
goto out;
}
add_array_kv(params, PARAM_NUM, &i, options[GB_OPTION_RUN_ROOT], graph_run);
ret = 0;
*count = i;
out:
free(graph_run);
return ret;
}
static char *adapt_log_level()
{
#define LOG_LEVEL_MAX 5
......@@ -193,14 +149,6 @@ int pack_global_options(const char * const *options, char *params[], size_t *cou
i = *count;
if (pack_global_graph_root(options, params, &i) != 0) {
goto out;
}
if (pack_global_graph_run(options, params, &i) != 0) {
goto out;
}
#ifdef ENABLE_OCI_IMAGE
if (pack_global_graph_driver(options, ignore_storage_opt_size, params, &i) != 0) {
goto out;
......
......@@ -324,7 +324,8 @@ static void remove_graph_root()
int ret = 0;
char *graph_root = NULL;
graph_root = conf_get_graph_rootpath();
//TODO replce funtion with storge module uninstall
//graph_root = conf_get_graph_rootpath();
if (graph_root == NULL) {
ERROR("Failed to get image graph root path");
return;
......
......@@ -60,19 +60,18 @@ static struct graphdriver g_drivers[] = {
static const size_t g_numdrivers = sizeof(g_drivers) / sizeof(struct graphdriver);
int graphdriver_init(const char *name, const char *isulad_root, char **storage_opts,
size_t storage_opts_len)
int graphdriver_init(struct storage_module_init_options *opts)
{
int ret = 0;
size_t i = 0;
char driver_home[PATH_MAX] = { 0 };
if (name == NULL || storage_opts == NULL || isulad_root == NULL) {
if (opts == NULL || opts->storage_root == NULL || opts->driver_name == NULL) {
ret = -1;
goto out;
}
int nret = snprintf(driver_home, PATH_MAX, "%s/%s/%s", isulad_root, "storage", name);
int nret = snprintf(driver_home, PATH_MAX, "%s/%s", opts->storage_root, opts->driver_name);
if (nret < 0 || (size_t)nret >= PATH_MAX) {
ERROR("Sprintf graph driver path failed");
ret = -1;
......@@ -80,8 +79,8 @@ int graphdriver_init(const char *name, const char *isulad_root, char **storage_o
}
for (i = 0; i < g_numdrivers; i++) {
if (strcmp(name, g_drivers[i].name) == 0) {
if (g_drivers[i].ops->init(&g_drivers[i], driver_home, (const char **)storage_opts, storage_opts_len) != 0) {
if (strcmp(opts->driver_name, g_drivers[i].name) == 0) {
if (g_drivers[i].ops->init(&g_drivers[i], driver_home, (const char **)opts->driver_opts, opts->driver_opts_len) != 0) {
ret = -1;
goto out;
}
......@@ -91,7 +90,7 @@ int graphdriver_init(const char *name, const char *isulad_root, char **storage_o
}
if (i == g_numdrivers) {
ERROR("unsupported driver %s", name);
ERROR("unsupported driver %s", opts->driver_name);
ret = -1;
goto out;
}
......
......@@ -22,6 +22,7 @@
#include "json_common.h"
#include "console.h"
#include "driver_overlay2_types.h"
#include "storage.h"
#ifdef __cplusplus
extern "C" {
......@@ -89,8 +90,7 @@ struct graphdriver {
struct overlay_options *overlay_opts;
};
int graphdriver_init(const char *name, const char *isulad_root, char **storage_opts,
size_t storage_opts_len);
int graphdriver_init(struct storage_module_init_options *opts);
int graphdriver_create_rw(const char *id, const char *parent, struct driver_create_opts *create_opts);
......
......@@ -332,3 +332,24 @@ out:
return ret;
}
void free_storage_module_init_options(struct storage_module_init_options *opts)
{
if (opts == NULL) {
return;
}
free(opts->driver_name);
opts->driver_name = NULL;
free(opts->storage_root);
opts->storage_root = NULL;
free(opts->storage_run_root);
opts->storage_run_root = NULL;
util_free_array_by_len(opts->driver_opts, opts->driver_opts_len);
opts->driver_opts = NULL;
opts->driver_opts_len = 0;
free(opts);
}
\ No newline at end of file
......@@ -25,6 +25,8 @@
extern "C" {
#endif
#define GRAPH_ROOTPATH_NAME "storage"
struct layer {
char *id;
char *parent;
......@@ -59,6 +61,8 @@ struct storage_img_create_options {
int storage_module_init(struct storage_module_init_options *opts);
void free_storage_module_init_options(struct storage_module_init_options *opts);
int storage_layer_create(const char *layer_id, const char *parent_id, bool writeable, const char *layer_data_path);
struct layer *storage_layer_get(const char *id);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册