提交 c92ab5d6 编写于 作者: L lifeng68

rename storage container to rootfs

Signed-off-by: Nlifeng68 <lifeng68@huawei.com>
上级 8408ba1c
......@@ -54,7 +54,7 @@
#define IMAGE_STORE_PATH_MODE 0700
#define CONTAINER_STORE_PATH_MODE 0700
#define ROOTFS_STORE_PATH_MODE 0700
#define ISULAD_CONFIG "/etc/isulad"
......
......@@ -2,13 +2,13 @@
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} local_storage_srcs)
add_subdirectory(image_store)
add_subdirectory(layer_store)
add_subdirectory(container_store)
add_subdirectory(rootfs_store)
set(STORAGE_SRCS
${local_storage_srcs}
${IMAGE_STORE_SRCS}
${LAYER_STORE_SRCS}
${CONTAINER_STORE_SRCS}
${ROOTFS_STORE_SRCS}
PARENT_SCOPE
)
......@@ -16,6 +16,6 @@ set(STORAGE_INCS
${CMAKE_CURRENT_SOURCE_DIR}
${IMAGE_STORE_INCS}
${LAYER_STORE_INCS}
${CONTAINER_STORE_INCS}
${ROOTFS_STORE_INCS}
PARENT_SCOPE
)
# get current directory sources files
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} local_container_store_srcs)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} local_rootfs_store_srcs)
set(CONTAINER_STORE_SRCS
${local_container_store_srcs}
set(ROOTFS_STORE_SRCS
${local_rootfs_store_srcs}
PARENT_SCOPE
)
set(CONTAINER_STORE_INCS
set(ROOTFS_STORE_INCS
${CMAKE_CURRENT_SOURCE_DIR}
PARENT_SCOPE
)
......@@ -12,18 +12,18 @@
* Create: 2020-05-12
* Description: provide container function definition
******************************************************************************/
#include "container.h"
#include "storage_container.h"
#include "rootfs.h"
#include "storage_rootfs.h"
#include "constants.h"
#include "util_atomic.h"
#include "utils.h"
#include "log.h"
static cntr_t *create_empty_cntr()
static cntrootfs_t *create_empty_cntr()
{
cntr_t *result = NULL;
cntrootfs_t *result = NULL;
result = (cntr_t *)util_smart_calloc_s(sizeof(cntr_t), 1);
result = (cntrootfs_t *)util_smart_calloc_s(sizeof(cntrootfs_t), 1);
if (result == NULL) {
ERROR("Out of memory");
goto err_out;
......@@ -33,13 +33,13 @@ static cntr_t *create_empty_cntr()
return result;
err_out:
free_container_t(result);
free_rootfs_t(result);
return NULL;
}
cntr_t *new_container(storage_container *scntr)
cntrootfs_t *new_rootfs(storage_rootfs *scntr)
{
cntr_t *c = NULL;
cntrootfs_t *c = NULL;
if (scntr == NULL) {
ERROR("Empty storage cntr");
......@@ -57,7 +57,7 @@ cntr_t *new_container(storage_container *scntr)
}
void container_ref_inc(cntr_t *c)
void rootfs_ref_inc(cntrootfs_t *c)
{
if (c == NULL) {
return;
......@@ -65,7 +65,7 @@ void container_ref_inc(cntr_t *c)
atomic_int_inc(&c->refcnt);
}
void container_ref_dec(cntr_t *c)
void rootfs_ref_dec(cntrootfs_t *c)
{
bool is_zero = false;
......@@ -78,15 +78,15 @@ void container_ref_dec(cntr_t *c)
return;
}
free_container_t(c);
free_rootfs_t(c);
}
void free_container_t(cntr_t *ptr)
void free_rootfs_t(cntrootfs_t *ptr)
{
if (ptr == NULL) {
return;
}
free_storage_container(ptr->scontainer);
free_storage_rootfs(ptr->scontainer);
ptr->scontainer = NULL;
free(ptr);
......
......@@ -12,31 +12,31 @@
* Create: 2020-05-12
* Description: provide containers function definition
******************************************************************************/
#ifndef __OCI_STORAGE_CONTAINER_H
#define __OCI_STORAGE_CONTAINER_H
#ifndef __OCI_STORAGE_ROOTFS_H
#define __OCI_STORAGE_ROOTFS_H
#include <stdbool.h>
#include <stdint.h>
#include <pthread.h>
#include "storage_container.h"
#include "storage_rootfs.h"
#include "log.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _cntr_t_ {
storage_container *scontainer;
typedef struct _cntrootfs_t {
storage_rootfs *scontainer;
uint64_t refcnt;
} cntr_t;
} cntrootfs_t;
cntr_t *new_container(storage_container *scntr);
void container_ref_inc(cntr_t *cntr);
void container_ref_dec(cntr_t *cntr);
void free_container_t(cntr_t *ptr);
cntrootfs_t *new_rootfs(storage_rootfs *scntr);
void rootfs_ref_inc(cntrootfs_t *cntr);
void rootfs_ref_dec(cntrootfs_t *cntr);
void free_rootfs_t(cntrootfs_t *ptr);
#ifdef __cplusplus
}
#endif
#endif // __OCI_STORAGE_CONTAINER_H
#endif // __OCI_STORAGE_ROOTFS_H
......@@ -13,7 +13,7 @@
* Description: provide image store functions
******************************************************************************/
#define _GNU_SOURCE
#include "container_store.h"
#include "rootfs_store.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <linux/limits.h>
......@@ -31,32 +31,32 @@
#include "defs.h"
#include "map.h"
#include "linked_list.h"
#include "container.h"
#include "rootfs.h"
#define CONTAINER_JSON "container.json"
typedef struct container_store {
typedef struct rootfs_store {
pthread_rwlock_t rwlock;
char *dir;
struct linked_list containers_list;
size_t containers_list_len;
struct linked_list rootfs_list;
size_t rootfs_list_len;
map_t *byid;
map_t *bylayer;
map_t *byname;
bool loaded;
} container_store_t;
} rootfs_store_t;
container_store_t *g_container_store = NULL;
rootfs_store_t *g_rootfs_store = NULL;
static inline bool container_store_lock(bool writable)
static inline bool rootfs_store_lock(bool writable)
{
int nret = 0;
if (writable) {
nret = pthread_rwlock_wrlock(&g_container_store->rwlock);
nret = pthread_rwlock_wrlock(&g_rootfs_store->rwlock);
} else {
nret = pthread_rwlock_rdlock(&g_container_store->rwlock);
nret = pthread_rwlock_rdlock(&g_rootfs_store->rwlock);
}
if (nret != 0) {
ERROR("Lock memory store failed: %s", strerror(nret));
......@@ -66,17 +66,17 @@ static inline bool container_store_lock(bool writable)
return true;
}
static inline void container_store_unlock()
static inline void rootfs_store_unlock()
{
int nret = 0;
nret = pthread_rwlock_unlock(&g_container_store->rwlock);
nret = pthread_rwlock_unlock(&g_rootfs_store->rwlock);
if (nret != 0) {
FATAL("Unlock memory store failed: %s", strerror(nret));
}
}
static void free_container_store(container_store_t *store)
static void free_rootfs_store(rootfs_store_t *store)
{
struct linked_list *item = NULL;
struct linked_list *next = NULL;
......@@ -97,36 +97,36 @@ static void free_container_store(container_store_t *store)
(void)map_free(store->byname);
store->byname = NULL;
linked_list_for_each_safe(item, &(store->containers_list), next) {
linked_list_for_each_safe(item, &(store->rootfs_list), next) {
linked_list_del(item);
container_ref_dec((cntr_t *)item->elem);
rootfs_ref_dec((cntrootfs_t *)item->elem);
free(item);
item = NULL;
}
store->containers_list_len = 0;
store->rootfs_list_len = 0;
free(store);
}
void container_store_free()
void rootfs_store_free()
{
free_container_store(g_container_store);
g_container_store = NULL;
free_rootfs_store(g_rootfs_store);
g_rootfs_store = NULL;
}
static void container_store_field_kvfree(void *key, void *value)
static void rootfs_store_field_kvfree(void *key, void *value)
{
(void)value;
free(key);
}
static int do_append_container(storage_container *c)
static int do_append_container(storage_rootfs *c)
{
cntr_t *cntr = NULL;
cntrootfs_t *cntr = NULL;
struct linked_list *item = NULL;
cntr = new_container(c);
cntr = new_rootfs(c);
if (cntr == NULL) {
ERROR("Out of memory");
return -1;
......@@ -135,13 +135,13 @@ static int do_append_container(storage_container *c)
item = util_smart_calloc_s(sizeof(struct linked_list), 1);
if (item == NULL) {
ERROR("Out of memory");
free_container_t(cntr);
free_rootfs_t(cntr);
return -1;
}
linked_list_add_elem(item, cntr);
linked_list_add_tail(&g_container_store->containers_list, item);
g_container_store->containers_list_len++;
linked_list_add_tail(&g_rootfs_store->rootfs_list, item);
g_rootfs_store->rootfs_list_len++;
return 0;
}
......@@ -151,7 +151,7 @@ static int append_container_by_directory(const char *container_dir)
int ret = 0;
int nret;
char container_path[PATH_MAX] = { 0x00 };
storage_container *c = NULL;
storage_rootfs *c = NULL;
parser_error err = NULL;
nret = snprintf(container_path, sizeof(container_path), "%s/%s", container_dir, CONTAINER_JSON);
......@@ -160,7 +160,7 @@ static int append_container_by_directory(const char *container_dir)
return -1;
}
c = storage_container_parse_file(container_path, NULL, &err);
c = storage_rootfs_parse_file(container_path, NULL, &err);
if (c == NULL) {
ERROR("Failed to parse container path: %s", err);
return -1;
......@@ -175,7 +175,7 @@ static int append_container_by_directory(const char *container_dir)
c = NULL;
out:
free_storage_container(c);
free_storage_rootfs(c);
free(err);
return ret;
}
......@@ -190,12 +190,12 @@ static int get_containers_from_json()
char *id_patten = "^[a-f0-9]{64}$";
char container_path[PATH_MAX] = { 0x00 };
if (!container_store_lock(true)) {
if (!rootfs_store_lock(true)) {
ERROR("Failed to lock container store");
return -1;
}
ret = util_list_all_subdir(g_container_store->dir, &container_dirs);
ret = util_list_all_subdir(g_rootfs_store->dir, &container_dirs);
if (ret != 0) {
ERROR("Failed to get container directorys");
goto out;
......@@ -210,7 +210,7 @@ static int get_containers_from_json()
}
DEBUG("Restore the containers:%s", container_dirs[i]);
nret = snprintf(container_path, sizeof(container_path), "%s/%s", g_container_store->dir, container_dirs[i]);
nret = snprintf(container_path, sizeof(container_path), "%s/%s", g_rootfs_store->dir, container_dirs[i]);
if (nret < 0 || (size_t)nret >= sizeof(container_path)) {
ERROR("Failed to get container path");
ret = -1;
......@@ -226,11 +226,11 @@ static int get_containers_from_json()
out:
util_free_array(container_dirs);
container_store_unlock();
rootfs_store_unlock();
return ret;
}
static int remove_name(cntr_t *cntr, const char *name)
static int remove_name(cntrootfs_t *cntr, const char *name)
{
size_t i;
size_t new_size;
......@@ -273,12 +273,12 @@ static int remove_name(cntr_t *cntr, const char *name)
static int get_container_path(const char *id, char *path, size_t len)
{
int nret = snprintf(path, len, "%s/%s/%s", g_container_store->dir, id, CONTAINER_JSON);
int nret = snprintf(path, len, "%s/%s/%s", g_rootfs_store->dir, id, CONTAINER_JSON);
return (nret < 0 || (size_t)nret >= len) ? -1 : 0;
}
static int save_container(cntr_t *cntr)
static int save_rootfs(cntrootfs_t *cntr)
{
int ret = 0;
char container_path[PATH_MAX] = { 0x00 };
......@@ -292,13 +292,13 @@ static int save_container(cntr_t *cntr)
}
strcpy(container_dir, container_path);
ret = util_mkdir_p(dirname(container_dir), CONTAINER_STORE_PATH_MODE);
ret = util_mkdir_p(dirname(container_dir), ROOTFS_STORE_PATH_MODE);
if (ret < 0) {
ERROR("Failed to create container directory %s.", container_path);
return -1;
}
json_data = storage_container_generate_json(cntr->scontainer, NULL, &err);
json_data = storage_rootfs_generate_json(cntr->scontainer, NULL, &err);
if (json_data == NULL) {
ERROR("Failed to generate container json path string:%s", err ? err : " ");
ret = -1;
......@@ -318,24 +318,24 @@ out:
return ret;
}
static int load_container_to_store_field(cntr_t *cntr)
static int load_container_to_store_field(cntrootfs_t *cntr)
{
int ret = 0;
bool should_save = false;
size_t i;
if (!map_replace(g_container_store->byid, (void *)cntr->scontainer->id, (void *)cntr)) {
if (!map_replace(g_rootfs_store->byid, (void *)cntr->scontainer->id, (void *)cntr)) {
ERROR("Failed to insert container to id index");
return -1;
}
if (!map_replace(g_container_store->bylayer, (void *)cntr->scontainer->layer, (void *)cntr)) {
if (!map_replace(g_rootfs_store->bylayer, (void *)cntr->scontainer->layer, (void *)cntr)) {
ERROR("Failed to insert container to layer index");
return -1;
}
for (i = 0; i < cntr->scontainer->names_len; i++) {
cntr_t *conflict_container = (cntr_t *)map_search(g_container_store->byname, (void *)cntr->scontainer->names[i]);
cntrootfs_t *conflict_container = (cntrootfs_t *)map_search(g_rootfs_store->byname, (void *)cntr->scontainer->names[i]);
if (conflict_container != NULL) {
if (remove_name(conflict_container, cntr->scontainer->names[i]) != 0) {
ERROR("Failed to remove name from conflict container");
......@@ -344,14 +344,14 @@ static int load_container_to_store_field(cntr_t *cntr)
}
should_save = true;
}
if (!map_replace(g_container_store->byname, (void *)cntr->scontainer->names[i], (void *)cntr)) {
if (!map_replace(g_rootfs_store->byname, (void *)cntr->scontainer->names[i], (void *)cntr)) {
ERROR("Failed to insert containes to name index");
ret = -1;
goto out;
}
}
if (should_save && save_container(cntr) != 0) {
if (should_save && save_rootfs(cntr) != 0) {
ERROR("Failed to save container");
ret = -1;
goto out;
......@@ -361,12 +361,12 @@ out:
return ret;
}
static int container_store_load()
static int rootfs_store_load()
{
struct linked_list *item = NULL;
struct linked_list *next = NULL;
if (g_container_store->loaded) {
if (g_rootfs_store->loaded) {
DEBUG("Do not need reload if daemon");
return 0;
}
......@@ -376,19 +376,19 @@ static int container_store_load()
return -1;
}
linked_list_for_each_safe(item, &(g_container_store->containers_list), next) {
if (load_container_to_store_field((cntr_t *)item->elem) != 0) {
linked_list_for_each_safe(item, &(g_rootfs_store->rootfs_list), next) {
if (load_container_to_store_field((cntrootfs_t *)item->elem) != 0) {
ERROR("Failed to load container to container store");
return -1;
}
}
g_container_store->loaded = true;
g_rootfs_store->loaded = true;
return 0;
}
static char *get_container_store_root_path(const struct storage_module_init_options *opts)
static char *get_rootfs_store_root_path(const struct storage_module_init_options *opts)
{
int nret = 0;
char *root_dir = NULL;
......@@ -412,70 +412,70 @@ static char *get_container_store_root_path(const struct storage_module_init_opti
return root_dir;
}
int container_store_init(struct storage_module_init_options *opts)
int rootfs_store_init(struct storage_module_init_options *opts)
{
int ret = 0;
char *root_dir = NULL;
if (g_container_store != NULL) {
if (g_rootfs_store != NULL) {
ERROR("Container store has already been initialized");
return -1;
}
root_dir = get_container_store_root_path(opts);
root_dir = get_rootfs_store_root_path(opts);
if (root_dir == NULL) {
return ret;
}
ret = util_mkdir_p(root_dir, CONTAINER_STORE_PATH_MODE);
ret = util_mkdir_p(root_dir, ROOTFS_STORE_PATH_MODE);
if (ret < 0) {
ERROR("Unable to create container store directory %s.", root_dir);
ret = -1;
goto out;
}
g_container_store = (container_store_t *)util_common_calloc_s(sizeof(container_store_t));
if (g_container_store == NULL) {
g_rootfs_store = (rootfs_store_t *)util_common_calloc_s(sizeof(rootfs_store_t));
if (g_rootfs_store == NULL) {
ERROR("Out of memory");
ret = -1;
goto out;
}
ret = pthread_rwlock_init(&(g_container_store->rwlock), NULL);
ret = pthread_rwlock_init(&(g_rootfs_store->rwlock), NULL);
if (ret != 0) {
ERROR("Failed to init container store rwlock");
ret = -1;
goto out;
}
g_container_store->dir = root_dir;
g_rootfs_store->dir = root_dir;
root_dir = NULL;
g_container_store->containers_list_len = 0;
linked_list_init(&g_container_store->containers_list);
g_rootfs_store->rootfs_list_len = 0;
linked_list_init(&g_rootfs_store->rootfs_list);
g_container_store->byid = map_new(MAP_STR_PTR, MAP_DEFAULT_CMP_FUNC, container_store_field_kvfree);
if (g_container_store->byid == NULL) {
g_rootfs_store->byid = map_new(MAP_STR_PTR, MAP_DEFAULT_CMP_FUNC, rootfs_store_field_kvfree);
if (g_rootfs_store->byid == NULL) {
ERROR("Out of memory");
ret = -1;
goto out;
}
g_container_store->bylayer = map_new(MAP_STR_PTR, MAP_DEFAULT_CMP_FUNC, container_store_field_kvfree);
if (g_container_store->bylayer == NULL) {
g_rootfs_store->bylayer = map_new(MAP_STR_PTR, MAP_DEFAULT_CMP_FUNC, rootfs_store_field_kvfree);
if (g_rootfs_store->bylayer == NULL) {
ERROR("Out of memory");
ret = -1;
goto out;
}
g_container_store->byname = map_new(MAP_STR_PTR, MAP_DEFAULT_CMP_FUNC, container_store_field_kvfree);
if (g_container_store->byname == NULL) {
g_rootfs_store->byname = map_new(MAP_STR_PTR, MAP_DEFAULT_CMP_FUNC, rootfs_store_field_kvfree);
if (g_rootfs_store->byname == NULL) {
ERROR("Out of memory");
ret = -1;
goto out;
}
ret = container_store_load();
ret = rootfs_store_load();
if (ret != 0) {
ERROR("Failed to load container store");
ret = -1;
......@@ -484,8 +484,8 @@ int container_store_init(struct storage_module_init_options *opts)
out:
if (ret != 0) {
free_container_store(g_container_store);
g_container_store = NULL;
free_rootfs_store(g_rootfs_store);
g_rootfs_store = NULL;
}
free(root_dir);
return ret;
......@@ -509,7 +509,7 @@ static char *generate_random_container_id()
ERROR("Generate random str failed");
goto err_out;
}
cntr_t *cntr = map_search(g_container_store->byid, (void *)id);
cntrootfs_t *cntr = map_search(g_rootfs_store->byid, (void *)id);
if (cntr == NULL) {
break;
}
......@@ -526,69 +526,69 @@ err_out:
return NULL;
}
static int copy_id_map(storage_container *c, const struct storage_container_options *container_opts)
static int copy_id_map(storage_rootfs *c, const struct storage_rootfs_options *rootfs_opts)
{
int ret = 0;
size_t i;
storage_container_uidmap_element **uid_map = NULL;
storage_rootfs_uidmap_element **uid_map = NULL;
size_t uid_map_len = 0;
storage_container_gidmap_element **gid_map = NULL;
storage_rootfs_gidmap_element **gid_map = NULL;
size_t gid_map_len = 0;
if (container_opts == NULL) {
if (rootfs_opts == NULL) {
return 0;
}
if (container_opts->id_mapping_opts.uid_map_len != 0) {
if (container_opts->id_mapping_opts.uid_map_len >= SIZE_MAX / sizeof(storage_container_uidmap_element *)) {
if (rootfs_opts->id_mapping_opts.uid_map_len != 0) {
if (rootfs_opts->id_mapping_opts.uid_map_len >= SIZE_MAX / sizeof(storage_rootfs_uidmap_element *)) {
ERROR("Too many id map");
return -1;
}
uid_map = (storage_container_uidmap_element **)util_common_calloc_s(
sizeof(storage_container_uidmap_element *) * container_opts->id_mapping_opts.uid_map_len);
uid_map = (storage_rootfs_uidmap_element **)util_common_calloc_s(
sizeof(storage_rootfs_uidmap_element *) * rootfs_opts->id_mapping_opts.uid_map_len);
if (uid_map == NULL) {
ERROR("Out of memory");
return -1;
}
for (i = 0; i < container_opts->id_mapping_opts.uid_map_len; i++) {
uid_map[i] = (storage_container_uidmap_element *)util_common_calloc_s(
sizeof(storage_container_uidmap_element));
for (i = 0; i < rootfs_opts->id_mapping_opts.uid_map_len; i++) {
uid_map[i] = (storage_rootfs_uidmap_element *)util_common_calloc_s(
sizeof(storage_rootfs_uidmap_element));
if (uid_map[i] == NULL) {
ERROR("Out of memory");
ret = -1;
goto out;
}
uid_map[i]->container_id = container_opts->id_mapping_opts.uid_map->container_id;
uid_map[i]->host_id = container_opts->id_mapping_opts.uid_map->host_id;
uid_map[i]->size = container_opts->id_mapping_opts.uid_map->size;
uid_map[i]->container_id = rootfs_opts->id_mapping_opts.uid_map->container_id;
uid_map[i]->host_id = rootfs_opts->id_mapping_opts.uid_map->host_id;
uid_map[i]->size = rootfs_opts->id_mapping_opts.uid_map->size;
uid_map_len++;
}
}
if (container_opts->id_mapping_opts.gid_map_len != 0) {
if (container_opts->id_mapping_opts.gid_map_len >= SIZE_MAX / sizeof(storage_container_gidmap_element *)) {
if (rootfs_opts->id_mapping_opts.gid_map_len != 0) {
if (rootfs_opts->id_mapping_opts.gid_map_len >= SIZE_MAX / sizeof(storage_rootfs_gidmap_element *)) {
ERROR("Too many id map");
return -1;
}
gid_map = (storage_container_gidmap_element **)util_common_calloc_s(
sizeof(storage_container_gidmap_element *) * container_opts->id_mapping_opts.gid_map_len);
gid_map = (storage_rootfs_gidmap_element **)util_common_calloc_s(
sizeof(storage_rootfs_gidmap_element *) * rootfs_opts->id_mapping_opts.gid_map_len);
if (gid_map == NULL) {
ERROR("Out of memory");
return -1;
}
for (i = 0; i < container_opts->id_mapping_opts.gid_map_len; i++) {
gid_map[i] = (storage_container_gidmap_element *)util_common_calloc_s(
sizeof(storage_container_gidmap_element));
for (i = 0; i < rootfs_opts->id_mapping_opts.gid_map_len; i++) {
gid_map[i] = (storage_rootfs_gidmap_element *)util_common_calloc_s(
sizeof(storage_rootfs_gidmap_element));
if (gid_map[i] == NULL) {
ERROR("Out of memory");
ret = -1;
goto out;
}
gid_map[i]->container_id = container_opts->id_mapping_opts.gid_map->container_id;
gid_map[i]->host_id = container_opts->id_mapping_opts.gid_map->host_id;
gid_map[i]->size = container_opts->id_mapping_opts.gid_map->size;
gid_map[i]->container_id = rootfs_opts->id_mapping_opts.gid_map->container_id;
gid_map[i]->host_id = rootfs_opts->id_mapping_opts.gid_map->host_id;
gid_map[i]->size = rootfs_opts->id_mapping_opts.gid_map->size;
gid_map_len++;
}
}
......@@ -619,15 +619,15 @@ out:
return ret;
}
static storage_container *new_storage_container(const char *id, const char *image,
char **unique_names, size_t unique_names_len, const char *layer,
const char *metadata, struct storage_container_options *container_opts)
static storage_rootfs *new_storage_rootfs(const char *id, const char *image,
char **unique_names, size_t unique_names_len, const char *layer,
const char *metadata, struct storage_rootfs_options *rootfs_opts)
{
int ret = 0;
char timebuffer[TIME_STR_SIZE] = { 0x00 };
storage_container *c = NULL;
storage_rootfs *c = NULL;
c = (storage_container *)util_common_calloc_s(sizeof(storage_container));
c = (storage_rootfs *)util_common_calloc_s(sizeof(storage_rootfs));
if (c == NULL) {
ERROR("Out of memory");
return NULL;
......@@ -649,7 +649,7 @@ static storage_container *new_storage_container(const char *id, const char *imag
}
c->created = util_strdup_s(timebuffer);
if (copy_id_map(c, container_opts) != 0) {
if (copy_id_map(c, rootfs_opts) != 0) {
ERROR("Failed to copy UID&GID map");
ret = -1;
goto out;
......@@ -657,14 +657,14 @@ static storage_container *new_storage_container(const char *id, const char *imag
out:
if (ret != 0) {
free_storage_container(c);
free_storage_rootfs(c);
c = NULL;
}
return c;
}
static int container_store_append_container(const char *id, const char *layer, const char **unique_names,
size_t unique_names_len, cntr_t *cntr)
static int rootfs_store_append_container_rootfs(const char *id, const char *layer, const char **unique_names,
size_t unique_names_len, cntrootfs_t *cntr)
{
int ret = 0;
size_t i = 0;
......@@ -676,29 +676,29 @@ static int container_store_append_container(const char *id, const char *layer, c
return -1;
}
linked_list_add_elem(item, cntr);
linked_list_add_tail(&g_container_store->containers_list, item);
g_container_store->containers_list_len++;
linked_list_add_tail(&g_rootfs_store->rootfs_list, item);
g_rootfs_store->rootfs_list_len++;
if (!map_insert(g_container_store->byid, (void *)id, (void *)cntr)) {
if (!map_insert(g_rootfs_store->byid, (void *)id, (void *)cntr)) {
ERROR("Failed to insert container to container store");
ret = -1;
goto out;
}
if (!map_insert(g_container_store->bylayer, (void *)layer, (void *)cntr)) {
if (!map_insert(g_rootfs_store->bylayer, (void *)layer, (void *)cntr)) {
ERROR("Failed to insert container to container store");
ret = -1;
goto out;
}
for (i = 0; i < unique_names_len; i++) {
if (!map_insert(g_container_store->byname, (void *)unique_names[i], (void *)cntr)) {
if (!map_insert(g_rootfs_store->byname, (void *)unique_names[i], (void *)cntr)) {
ERROR("Failed to insert container to container store's name index");
ret = -1;
goto out;
}
}
container_ref_inc(cntr);
rootfs_ref_inc(cntr);
out:
if (ret != 0) {
......@@ -708,22 +708,22 @@ out:
return ret;
}
char *container_store_create(const char *id, const char **names, size_t names_len, const char *image, const char *layer,
const char *metadata, struct storage_container_options *container_opts)
char *rootfs_store_create(const char *id, const char **names, size_t names_len, const char *image, const char *layer,
const char *metadata, struct storage_rootfs_options *rootfs_opts)
{
int ret = 0;
char *dst_id = NULL;
char **unique_names = NULL;
size_t unique_names_len = 0;
cntr_t *cntr = NULL;
storage_container *c = NULL;
cntrootfs_t *cntr = NULL;
storage_rootfs *c = NULL;
if (g_container_store == NULL) {
if (g_rootfs_store == NULL) {
ERROR("Container store is not ready");
return NULL;
}
if (!container_store_lock(true)) {
if (!rootfs_store_lock(true)) {
ERROR("Failed to lock container store, not allowed to create new containers");
return NULL;
}
......@@ -734,7 +734,7 @@ char *container_store_create(const char *id, const char **names, size_t names_le
dst_id = util_strdup_s(id);
}
if (map_search(g_container_store->byid, (void *)dst_id) != NULL) {
if (map_search(g_rootfs_store->byid, (void *)dst_id) != NULL) {
ERROR("ID is already in use: %s", id);
ret = -1;
goto out;
......@@ -746,27 +746,27 @@ char *container_store_create(const char *id, const char **names, size_t names_le
goto out;
}
c = new_storage_container(id, image, unique_names, unique_names_len, layer, metadata, container_opts);
c = new_storage_rootfs(id, image, unique_names, unique_names_len, layer, metadata, rootfs_opts);
if (c == NULL) {
ERROR("Failed to generate new storage container");
ret = -1;
goto out;
}
cntr = new_container(c);
cntr = new_rootfs(c);
if (cntr == NULL) {
ERROR("Out of memory");
ret = -1;
goto out;
}
if (container_store_append_container(id, layer, (const char **)unique_names, unique_names_len, cntr) != 0) {
if (rootfs_store_append_container_rootfs(id, layer, (const char **)unique_names, unique_names_len, cntr) != 0) {
ERROR("Failed to append container to container store");
ret = -1;
goto out;
}
if (save_container(cntr) != 0) {
if (save_rootfs(cntr) != 0) {
ERROR("Failed to save container");
ret = -1;
goto out;
......@@ -776,23 +776,23 @@ out:
if (ret != 0) {
free(dst_id);
dst_id = NULL;
free_storage_container(c);
free_storage_rootfs(c);
c = NULL;
free_container_t(cntr);
free_rootfs_t(cntr);
cntr = NULL;
}
container_store_unlock();
rootfs_store_unlock();
return dst_id;
}
static cntr_t *get_container_for_store_by_prefix(const char *id)
static cntrootfs_t *get_rootfs_for_store_by_prefix(const char *id)
{
bool ret = true;
cntr_t *value = NULL;
cntrootfs_t *value = NULL;
map_itor *itor = NULL;
const char *key = NULL;
itor = map_itor_new(g_container_store->byid);
itor = map_itor_new(g_rootfs_store->byid);
if (itor == NULL) {
ERROR("Failed to get byid's iterator from container store");
return NULL;
......@@ -825,26 +825,26 @@ out:
return value;
}
static cntr_t *lookup(const char *id)
static cntrootfs_t *lookup(const char *id)
{
cntr_t *value = NULL;
cntrootfs_t *value = NULL;
if (id == NULL) {
ERROR("Invalid input parameter, id is NULL");
return NULL;
}
value = map_search(g_container_store->byid, (void *)id);
value = map_search(g_rootfs_store->byid, (void *)id);
if (value != NULL) {
goto found;
}
value = map_search(g_container_store->bylayer, (void *)id);
value = map_search(g_rootfs_store->bylayer, (void *)id);
if (value != NULL) {
goto found;
}
value = get_container_for_store_by_prefix(id);
value = get_rootfs_for_store_by_prefix(id);
if (value != NULL) {
goto found;
}
......@@ -852,34 +852,34 @@ static cntr_t *lookup(const char *id)
return NULL;
found:
container_ref_inc(value);
rootfs_ref_inc(value);
return value;
}
static inline cntr_t *lookup_with_lock(const char *id)
static inline cntrootfs_t *lookup_with_lock(const char *id)
{
cntr_t *cntr = NULL;
cntrootfs_t *cntr = NULL;
if (!container_store_lock(false)) {
if (!rootfs_store_lock(false)) {
return NULL;
}
cntr = lookup(id);
container_store_unlock();
rootfs_store_unlock();
return cntr;
}
char *container_store_lookup(const char *id)
char *rootfs_store_lookup(const char *id)
{
char *container_id = NULL;
cntr_t *cntr = NULL;
cntrootfs_t *cntr = NULL;
if (id == NULL) {
ERROR("Invalid input parameter, id is NULL");
return NULL;
}
if (g_container_store == NULL) {
if (g_rootfs_store == NULL) {
ERROR("Container store is not ready");
return NULL;
}
......@@ -891,77 +891,77 @@ char *container_store_lookup(const char *id)
}
container_id = util_strdup_s(cntr->scontainer->id);
container_ref_dec(cntr);
rootfs_ref_dec(cntr);
return container_id;
}
int container_store_delete(const char *id)
int rootfs_store_delete(const char *id)
{
return 0;
}
int container_store_wipe()
int rootfs_store_wipe()
{
return 0;
}
int container_store_set_big_data(const char *id, const char *key, const char *data)
int rootfs_store_set_big_data(const char *id, const char *key, const char *data)
{
return 0;
}
int container_store_set_names(const char *id, const char **names, size_t names_len)
int rootfs_store_set_names(const char *id, const char **names, size_t names_len)
{
return 0;
}
int container_store_set_metadata(const char *id, const char *metadata)
int rootfs_store_set_metadata(const char *id, const char *metadata)
{
return 0;
}
int container_store_save(cntr_t *c)
int rootfs_store_save(cntrootfs_t *c)
{
return 0;
}
bool container_store_exists(const char *id)
bool rootfs_store_exists(const char *id)
{
return false;
}
cntr_t *container_store_get_container(const char *id)
cntrootfs_t *rootfs_store_get_rootfs(const char *id)
{
return NULL;
}
char *container_store_big_data(const char *id, const char *key)
char *rootfs_store_big_data(const char *id, const char *key)
{
return NULL;
}
int64_t container_store_big_data_size(const char *id, const char *key)
int64_t rootfs_store_big_data_size(const char *id, const char *key)
{
return -1;
}
char *container_store_big_data_digest(const char *id, const char *key)
char *rootfs_store_big_data_digest(const char *id, const char *key)
{
return NULL;
}
int container_store_big_data_names(const char *id, char ***names, size_t *names_len)
int rootfs_store_big_data_names(const char *id, char ***names, size_t *names_len)
{
return 0;
}
char *container_store_metadata(const char *id)
char *rootfs_store_metadata(const char *id)
{
return NULL;
}
int container_store_get_all_containers(cntr_t *containers, size_t *len)
int rootfs_store_get_all_rootfs(cntrootfs_t *containers, size_t *len)
{
return 0;
}
......
......@@ -12,78 +12,78 @@
* Create: 2020-05-12
* Description: provide containers module interface definition
******************************************************************************/
#ifndef __OCI_STORAGE_CONTAINER_STORE_H
#define __OCI_STORAGE_CONTAINER_STORE_H
#ifndef __OCI_STORAGE_ROOTFS_STORE_H
#define __OCI_STORAGE_ROOTFS_STORE_H
#include <stdbool.h>
#include <string.h>
#include <pthread.h>
#include "storage.h"
#include "container.h"
#include "rootfs.h"
#ifdef __cplusplus
extern "C" {
#endif
// Load the containers in the folder(${driver}-containers)
int container_store_init(struct storage_module_init_options *opts);
int rootfs_store_init(struct storage_module_init_options *opts);
// Creates a container that has a specified ID (or generates a random one if an empty value is supplied)
// and optional names, based on the specified image, using the specified layer as its read-write layer.
// return a new id, or NULL if failed.
char *container_store_create(const char *id, const char **names, size_t names_len, const char *image, const char *layer,
const char *metadata, struct storage_container_options *container_opts);
char *rootfs_store_create(const char *id, const char **names, size_t names_len, const char *image, const char *layer,
const char *metadata, struct storage_rootfs_options *rootfs_opts);
// Attempt to translate a name to an ID. Most methods do this implicitly.
char *container_store_lookup(const char *id);
char *rootfs_store_lookup(const char *id);
// Remove the record of the container.
int container_store_delete(const char *id);
int rootfs_store_delete(const char *id);
// Remove records of all containers
int container_store_wipe();
int rootfs_store_wipe();
// Stores a (potentially large) piece of data associated with this ID.
int container_store_set_big_data(const char *id, const char *key, const char *data);
int rootfs_store_set_big_data(const char *id, const char *key, const char *data);
// Replace the list of names associated with a container with the supplied values.
int container_store_set_names(const char *id, const char **names, size_t names_len);
int rootfs_store_set_names(const char *id, const char **names, size_t names_len);
// Updates the metadata associated with the item with the specified ID.
int container_store_set_metadata(const char *id, const char *metadata);
int rootfs_store_set_metadata(const char *id, const char *metadata);
// Saves the contents of the store to disk.
int container_store_save(cntr_t *c);
int rootfs_store_save(cntrootfs_t *c);
// Check if there is a container with the given ID or name.
bool container_store_exists(const char *id);
bool rootfs_store_exists(const char *id);
// Retrieve information about a container given an ID or name.
cntr_t *container_store_get_container(const char *id);
cntrootfs_t *rootfs_store_get_rootfs(const char *id);
// Retrieves a (potentially large) piece of data associated with this ID, if it has previously been set.
char *container_store_big_data(const char *id, const char *key);
char *rootfs_store_big_data(const char *id, const char *key);
// Retrieves the size of a (potentially large) piece of data associated with this ID, if it has previously been set.
int64_t container_store_big_data_size(const char *id, const char *key);
int64_t rootfs_store_big_data_size(const char *id, const char *key);
// Retrieves the digest of a (potentially large) piece of data associated with this ID, if it has previously been set.
char *container_store_big_data_digest(const char *id, const char *key);
char *rootfs_store_big_data_digest(const char *id, const char *key);
// Returns a list of the names of previously-stored pieces of data.
int container_store_big_data_names(const char *id, char ***names, size_t *names_len);
int rootfs_store_big_data_names(const char *id, char ***names, size_t *names_len);
// Reads metadata associated with an item with the specified ID.
char *container_store_metadata(const char *id);
char *rootfs_store_metadata(const char *id);
// Return a slice enumerating the known containers.
int container_store_get_all_containers(cntr_t *containers, size_t *len);
int rootfs_store_get_all_rootfs(cntrootfs_t *containers, size_t *len);
// Free memory of container store, but will not delete the persisted files
void container_store_free();
void rootfs_store_free();
#ifdef __cplusplus
}
#endif
#endif /* __OCI_STORAGE_CONTAINER_STORE_H */
#endif /* __OCI_STORAGE_ROOTFS_STORE_H */
......@@ -82,7 +82,7 @@ struct id_mapping_options {
size_t gid_map_len;
};
struct storage_container_options {
struct storage_rootfs_options {
struct id_mapping_options id_mapping_opts;
char **label_opts;
size_t label_opts_len;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册