提交 89a3dcbb 编写于 作者: L LiFeng 提交者: lifeng68

storage: add init storage module

Signed-off-by: NLiFeng <lifeng68@huawei.com>
上级 d428449b
......@@ -601,10 +601,11 @@ static int image_store_load(image_store_t *image_store)
return load_helper(image_store);
}
int new_image_store(const char *dir)
int image_store_init(struct storage_module_init_options *opts)
{
int ret = 0;
image_store_t *store = NULL;
char *dir = NULL;// todo gipath := filepath.Join(s.graphRoot, driverPrefix+"images")
ret = util_mkdir_p(dir, IMAGE_STORE_PATH_MODE);
if (ret < 0) {
......
......@@ -18,7 +18,7 @@
#include <stdbool.h>
#include <string.h>
#include <pthread.h>
#include "storage_image.h"
#include "storage.h"
#include "types_def.h"
#include "map.h"
......@@ -27,7 +27,7 @@ extern "C" {
#endif
// Load the image in the dir folder
int new_image_store(const char *dir);
int image_store_init(struct storage_module_init_options *opts);
// Create an image that has a specified ID (or a random one) and optional names, using the specified layer as
// its topmost (hopefully read-only) layer. That layer can be referenced by multiple images.
......
......@@ -56,7 +56,7 @@ static void layer_map_kvfree(void *key, void *value)
layer_ref_dec((layer_t *)value);
}
int layer_store_init(const struct layer_store_config *conf)
int layer_store_init(const struct storage_module_init_options *conf)
{
int nret;
......@@ -176,20 +176,6 @@ void free_layer(struct layer *ptr)
free(ptr);
}
void free_layer_store_config(struct layer_store_config *ptr)
{
if (ptr == NULL) {
return;
}
free(ptr->driver_name);
ptr->driver_name = NULL;
free(ptr->driver_root);
ptr->driver_root = NULL;
//TODO: free mount options
free(ptr);
}
void free_layer_opts(struct layer_opts *ptr)
{
if (ptr == NULL) {
......
......@@ -17,6 +17,7 @@
#include <stdint.h>
#include "storage.h"
#include "console.h"
#ifdef __cplusplus
......@@ -29,25 +30,6 @@ struct layer_store_mount_opts {
size_t options_len;
};
struct layer_store_config {
/*configs for graph driver */
char *driver_name;
char *driver_root;
struct layer_store_mount_opts *opts;
};
struct layer {
char *id;
char *parent;
char *mount_point;
int mount_count;
char *compressed_digest;
int64_t compress_size;
char *uncompressed_digest;
int64_t uncompress_size;
};
struct layer_opts {
char *parent;
char **names;
......@@ -58,7 +40,7 @@ struct layer_opts {
struct layer_store_mount_opts *opts;
};
int layer_store_init(const struct layer_store_config *conf);
int layer_store_init(const struct storage_module_init_options *conf);
bool layer_store_check(const char *id);
int layer_store_create(const char *id, const struct layer_opts *opts, const struct io_read_wrapper *content,
......@@ -78,7 +60,6 @@ struct graphdriver_status* layer_store_status();
int layer_store_try_repair_lowers(const char *id);
void free_layer(struct layer *l);
void free_layer_store_config(struct layer_store_config *conf);
void free_layer_opts(struct layer_opts *opts);
#ifdef __cplusplus
......
......@@ -16,9 +16,13 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "console.h"
#include "utils.h"
#include "log.h"
#include "layer_store.h"
#include "image_store.h"
static ssize_t layer_archive_io_read(void *context, void *buf, size_t buf_len)
{
......@@ -268,3 +272,63 @@ out:
return ret;
}
static int check_module_init_opt(struct storage_module_init_options *opts)
{
if (opts == NULL || opts->driver_name == NULL || opts->storage_root == NULL || opts->storage_run_root == NULL) {
ERROR("Invalid input arguments");
return -1;
}
return 0;
}
static int make_storage_directory(struct storage_module_init_options *opts)
{
int ret = 0;
if (util_mkdir_p(opts->storage_root, IMAGE_STORE_PATH_MODE) != 0) {
SYSERROR("Failed to make %s", opts->storage_root);
ret = -1;
goto out;
}
if (util_mkdir_p(opts->storage_run_root, IMAGE_STORE_PATH_MODE) != 0) {
SYSERROR("Failed to make %s", opts->storage_run_root);
ret = -1;
goto out;
}
out:
return ret;
}
int storage_module_init(struct storage_module_init_options *opts)
{
int ret = 0;
if (check_module_init_opt(opts) != 0) {
ret = -1;
goto out;
}
if (make_storage_directory(opts) != 0) {
ret = -1;
goto out;
}
if (layer_store_init(opts) != 0) {
ERROR("Failed to init layer store");
ret = -1;
goto out;
}
if (image_store_init(opts) != 0) {
ERROR("Failed to init image store");
ret = -1;
goto out;
}
out:
return ret;
}
......@@ -19,18 +19,45 @@
#include <stdbool.h>
#include <stddef.h>
#include "types_def.h"
#include "layer_store.h"
#include "image_store.h"
#include "storage_image.h"
#ifdef __cplusplus
extern "C" {
#endif
struct layer {
char *id;
char *parent;
char *mount_point;
int mount_count;
char *compressed_digest;
int64_t compress_size;
char *uncompressed_digest;
int64_t uncompress_size;
};
struct storage_module_init_options {
// storage_run_root is the filesystem path under which we can store run-time info
// e.g. /var/run/isulad/storage
char *storage_run_root;
// storage_root is the filesystem path under which we will store the contents of layers, images, and containers
// e.g. /var/lib/isulad/storage
char *storage_root;
char *driver_name;
// driver_opts are driver-specific options.
char **driver_opts;
size_t driver_opts_len;
};
struct storage_img_create_options {
types_timestamp_t *create_time;
char *digest;
};
int storage_module_init(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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册