提交 cd503ba4 编写于 作者: W wujing 提交者: lifeng68

rootfs store interface implement

Signed-off-by: Nwujing <wujing50@huawei.com>
上级 4537c008
......@@ -290,3 +290,72 @@ char *oci_strip_dockerio_prefix(const char *name)
return util_strdup_s(name);
}
static bool should_use_origin_name(const char *name)
{
size_t i;
for (i = 0; i < strlen(name); i++) {
char ch = name[i];
if (ch != '.' && !(ch >= '0' && ch <= '9') && !(ch >= 'a' && ch <= 'z')) {
return false;
}
}
return true;
}
// Convert a BigData key name into an acceptable file name.
char *make_big_data_base_name(const char *key)
{
int ret = 0;
int nret = 0;
char *b64_encode_name = NULL;
size_t b64_encode_name_len = 0;
char *base_name = NULL;
size_t name_size;
if (should_use_origin_name(key)) {
return util_strdup_s(key);
}
b64_encode_name_len = util_base64_encode_len(strlen(key));
b64_encode_name = util_common_calloc_s(b64_encode_name_len + 1);
if (b64_encode_name == NULL) {
ERROR("Out of memory");
ret = -1;
goto out;
}
nret = util_base64_encode((unsigned char *)key, strlen(key), b64_encode_name, b64_encode_name_len);
if (nret < 0) {
ret = -1;
ERROR("Encode auth to base64 failed");
goto out;
}
name_size = 1 + strlen(b64_encode_name) + 1; // '=' + encode string + '\0'
base_name = (char *)util_common_calloc_s(name_size * sizeof(char));
if (base_name == NULL) {
ERROR("Out of memory");
ret = -1;
goto out;
}
nret = snprintf(base_name, name_size, "=%s", b64_encode_name);
if (nret < 0 || (size_t)nret >= name_size) {
ERROR("Out of memory");
ret = -1;
goto out;
}
DEBUG("big data file name : %s", base_name);
out:
if (ret != 0) {
free(base_name);
base_name = NULL;
}
free(b64_encode_name);
return base_name;
}
......@@ -39,6 +39,7 @@ char *oci_normalize_image_name(const char *name);
int oci_split_image_name(const char *image_name, char **host, char **name, char **tag);
char *oci_full_image_name(const char *host, const char *name, const char *tag);
char *oci_strip_dockerio_prefix(const char *name);
char *make_big_data_base_name(const char *key);
#ifdef __cplusplus
}
......
......@@ -15,6 +15,8 @@
#ifndef __IMAGE_REGISTRY_H
#define __IMAGE_REGISTRY_H
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
......
......@@ -23,7 +23,6 @@
#include <unistd.h>
#include <string.h>
#include <stddef.h>
#include <libwebsockets.h>
#include <sha256.h>
#include "utils.h"
#include "log.h"
......@@ -1296,75 +1295,6 @@ out:
return ret;
}
static bool should_use_origin_name(const char *name)
{
size_t i;
for (i = 0; i < strlen(name); i++) {
char ch = name[i];
if (ch != '.' && !(ch >= '0' && ch <= '9') && !(ch >= 'a' && ch <= 'z')) {
return false;
}
}
return true;
}
// Convert a BigData key name into an acceptable file name.
static char *make_big_data_base_name(const char *key)
{
int ret = 0;
int nret = 0;
char *b64_encode_name = NULL;
size_t b64_encode_name_len = 0;
char *base_name = NULL;
size_t name_size;
if (should_use_origin_name(key)) {
return util_strdup_s(key);
}
b64_encode_name_len = util_base64_encode_len(strlen(key));
b64_encode_name = util_common_calloc_s(b64_encode_name_len + 1);
if (b64_encode_name == NULL) {
ERROR("Out of memory");
ret = -1;
goto out;
}
nret = util_base64_encode((unsigned char *)key, strlen(key), b64_encode_name, b64_encode_name_len);
if (nret < 0) {
ret = -1;
ERROR("Encode auth to base64 failed");
goto out;
}
name_size = 1 + strlen(b64_encode_name) + 1; // '=' + encode string + '\0'
base_name = (char *)util_common_calloc_s(name_size * sizeof(char));
if (base_name == NULL) {
ERROR("Out of memory");
ret = -1;
goto out;
}
nret = snprintf(base_name, name_size, "=%s", b64_encode_name);
if (nret < 0 || (size_t)nret >= name_size) {
ERROR("Out of memory");
ret = -1;
goto out;
}
DEBUG("big data file name : %s", base_name);
out:
if (ret != 0) {
free(base_name);
base_name = NULL;
}
free(b64_encode_name);
return base_name;
}
static int get_data_path(const char *id, const char *key, char *path, size_t len)
{
int ret = 0;
......@@ -1779,7 +1709,7 @@ int image_store_set_names(const char *id, const char **names, size_t names_len)
}
if (!image_store_lock(EXCLUSIVE)) {
ERROR("Failed to lock image store with exclusive lock, not allowed to change image name assignments");
ERROR("Failed to lock image store with exclusive lock, not allowed to change image names assignments");
return -1;
}
......@@ -1914,7 +1844,11 @@ int image_store_set_metadata(const char *id, const char *metadata)
free(img->simage->metadata);
img->simage->metadata = util_strdup_s(metadata);
save_image(img);
if (save_image(img) != 0) {
ERROR("Failed to save image");
ret = -1;
goto out;
}
out:
image_ref_dec(img);
......@@ -2357,7 +2291,11 @@ int image_store_set_image_size(const char *id, uint64_t size)
}
img->simage->size = size;
save_image(img);
if (save_image(img) != 0) {
ERROR("Failed to save image");
ret = -1;
goto out;
}
out:
image_ref_dec(img);
......
......@@ -51,7 +51,7 @@ cntrootfs_t *new_rootfs(storage_rootfs *scntr)
return NULL;
}
c->scontainer = scntr;
c->srootfs = scntr;
return c;
......@@ -86,8 +86,8 @@ void free_rootfs_t(cntrootfs_t *ptr)
if (ptr == NULL) {
return;
}
free_storage_rootfs(ptr->scontainer);
ptr->scontainer = NULL;
free_storage_rootfs(ptr->srootfs);
ptr->srootfs = NULL;
free(ptr);
}
......
......@@ -26,7 +26,7 @@ extern "C" {
#endif
typedef struct _cntrootfs_t {
storage_rootfs *scontainer;
storage_rootfs *srootfs;
uint64_t refcnt;
} cntrootfs_t;
......
......@@ -20,6 +20,7 @@
#include <stddef.h>
#include "types_def.h"
#include "storage_image.h"
#include "storage_rootfs.h"
#include "imagetool_images_list.h"
#include "imagetool_fs_info.h"
......@@ -46,7 +47,7 @@ struct layer_list {
};
struct rootfs_list {
struct storage_rootfs **rootfs;
storage_rootfs **rootfs;
size_t rootfs_len;
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册