提交 1a7c652d 编写于 作者: L LiFeng 提交者: lifeng68

driver: fix init quota and add rel mount

Signed-off-by: NLiFeng <lifeng68@huawei.com>
上级 ea1e8337
......@@ -39,9 +39,7 @@ struct service_arguments {
// struct service_arguments *server_conf;
isulad_daemon_configs *json_confs;
#ifdef ENABLE_OCI_IMAGE
struct graphdriver *driver;
#endif
/* parsed configs */
oci_runtime_spec_hooks *hooks;
......
......@@ -1112,10 +1112,9 @@ static int isulad_server_init_common()
}
#ifdef ENABLE_OCI_IMAGE
args->driver = graphdriver_init(args->json_confs->storage_driver, args->json_confs->graph,
args->json_confs->storage_opts,
args->json_confs->storage_opts_len);
if (args->driver == NULL) {
if (graphdriver_init(args->json_confs->storage_driver, args->json_confs->graph,
args->json_confs->storage_opts,
args->json_confs->storage_opts_len) != 0) {
goto out;
}
#endif
......
......@@ -451,49 +451,6 @@ out:
}
#ifdef ENABLE_OCI_IMAGE
/* conf get graph driver */
char *conf_get_isulad_storage_driver()
{
char *driver = NULL;
struct service_arguments *conf = NULL;
if (isulad_server_conf_rdlock() != 0) {
return NULL;
}
conf = conf_get_server_conf();
if (conf == NULL || conf->driver->name == NULL) {
goto out;
}
driver = util_strdup_s(conf->driver->name);
out:
(void)isulad_server_conf_unlock();
return driver;
}
/* conf get graph driver */
char *conf_get_isulad_storage_driver_backing_fs()
{
char *fs = NULL;
struct service_arguments *conf = NULL;
if (isulad_server_conf_rdlock() != 0) {
return NULL;
}
conf = conf_get_server_conf();
if (conf == NULL || conf->driver->backing_fs == NULL) {
goto out;
}
fs = util_strdup_s(conf->driver->backing_fs);
out:
(void)isulad_server_conf_unlock();
return fs;
}
/* conf get graph driver opts */
char **conf_get_storage_opts()
......
......@@ -76,10 +76,6 @@ char *conf_get_graph_rootpath();
char *conf_get_graph_run_path();
char *conf_get_isulad_storage_driver();
char *conf_get_isulad_storage_driver_backing_fs();
char **conf_get_storage_opts();
char **conf_get_insecure_registry_list();
......
......@@ -456,7 +456,7 @@ int util_mount(const char *src, const char *dst, const char *mtype, const char *
if ((mntflags & MS_REMOUNT) != MS_REMOUNT) {
if (util_detect_mounted(dst)) {
DEBUG("mount dst %s had been mounted, skip mount", dst);
ERROR("mount dst %s had been mounted, skip mount", dst);
ret = 0;
goto out;
}
......@@ -491,4 +491,72 @@ int util_ensure_mounted_as(const char *dst, const char *mntopts)
out:
return ret;
}
static int util_mount_from_handler(const char *src, const char *dst, const char *mtype, const char *mntopts)
{
int ret = 0;
unsigned long mntflags = 0L;
char *mntdata = NULL;
ret = util_parse_mntopts(mntopts, &mntflags, &mntdata);
if (ret != 0) {
ERROR("Failed to parse mount options:%s", mntopts);
ret = -1;
goto out;
}
ret = mount(src, dst, mtype, mntflags, mntdata);
if (ret < 0) {
ERROR("Failed to mount from %s to %s:%s", src, dst, strerror(errno));
goto out;
}
out:
return ret;
}
int util_mount_from(const char *base, const char *src, const char *dst, const char *mtype, const char *mntopts)
{
int ret = 0;
pid_t pid = -1;
int keepfds[] = {-1};
pid = fork();
if (pid == (pid_t) - 1) {
ERROR("Failed to fork: %s", strerror(errno));
goto cleanup;
}
if (pid == (pid_t)0) {
keepfds[0] = log_get_log_fd();
ret = util_check_inherited_exclude_fds(true, keepfds, 1);
if (ret != 0) {
ERROR("Failed to close fds.");
ret = -1;
goto child_out;
}
if (chdir(base) != 0) {
SYSERROR("Failed to chroot to %s", base);
ret = -1;
goto child_out;
}
ret = util_mount_from_handler(src, dst, mtype, mntopts);
child_out:
if (ret != 0) {
exit(EXIT_FAILURE);
} else {
exit(EXIT_SUCCESS);
}
}
ret = wait_for_pid(pid);
if (ret != 0) {
ERROR("Wait util_mount_from failed");
}
cleanup:
return ret;
}
\ No newline at end of file
......@@ -35,6 +35,7 @@ int util_mount(const char *src, const char *dst, const char *mtype, const char *
int util_force_mount(const char *src, const char *dst, const char *mtype, const char *mntopts);
bool util_detect_mounted(const char *path);
int util_ensure_mounted_as(const char *dst, const char *mntopts);
int util_mount_from(const char *base, const char *src, const char *dst, const char *mtype, const char *mntopts);
#ifdef __cplusplus
}
#endif
......
......@@ -80,7 +80,7 @@ static const struct bim_ops g_embedded_ops = {
#ifdef ENABLE_OCI_IMAGE
static const struct bim_ops g_isula_ops = {
.init = isula_init,
.clean_resource = isula_exit,
.clean_resource = NULL,
.detect = oci_detect,
.prepare_rf = isula_prepare_rf,
......
......@@ -24,48 +24,7 @@
static int pack_global_graph_driver(const char * const *options, bool ignore_storage_opt_size, char *params[],
size_t *count)
{
int ret = -1;
char *graph_driver = NULL;
char **graph_opts = NULL;
char **p = NULL;
size_t i = 0;
i = *count;
graph_driver = conf_get_isulad_storage_driver();
if (graph_driver == NULL) {
COMMAND_ERROR("Failed to get graph driver");
goto out;
}
if (strcmp(graph_driver, "overlay2") == 0) {
// Treating overlay2 as overlay cause image was downloaded always
// in '/var/lib/isulad/storage/overlay' directory.
// See iSulad-img/vendor/github.com/containers/storage/drivers/overlay/overlay.go,
// Driver is inited by name "overlay".
graph_driver[strlen(graph_driver) - 1] = '\0';
}
add_array_kv(params, PARAM_NUM, &i, options[GB_OPTION_DRIVER_NAME], graph_driver);
graph_opts = conf_get_storage_opts();
// since iSulad-img will set quota when pull image, which is differ from docker,
// and we may get some error if setted, ignore it if neccessary.
for (p = graph_opts; (p != NULL) && (*p != NULL); p++) {
add_array_kv(params, PARAM_NUM, &i, options[GB_OPTION_DRIVER_OPTIONS], *p);
}
if (strcmp(graph_driver, "devicemapper") == 0) {
// option "test=false" is used when devicemapper thinpool is created automatically by iSulad-kit.
// Make "test" always be true to avoid config check as we always create thinpool manually.
add_array_kv(params, PARAM_NUM, &i, options[GB_OPTION_DRIVER_OPTIONS], "test=true");
}
ret = 0;
*count = i;
out:
free(graph_driver);
util_free_array(graph_opts);
return ret;
return 0;
}
#endif
......
......@@ -60,25 +60,29 @@ static struct graphdriver g_drivers[] = {
static const size_t g_numdrivers = sizeof(g_drivers) / sizeof(struct graphdriver);
struct graphdriver *graphdriver_init(const char *name, const char *isulad_root, char **storage_opts,
size_t storage_opts_len)
int graphdriver_init(const char *name, const char *isulad_root, char **storage_opts,
size_t storage_opts_len)
{
int ret = 0;
size_t i = 0;
char driver_home[PATH_MAX] = { 0 };
if (name == NULL || storage_opts == NULL || isulad_root == NULL) {
return NULL;
ret = -1;
goto out;
}
int nret = snprintf(driver_home, PATH_MAX, "%s/%s/%s", isulad_root, "storage", name);
if (nret < 0 || (size_t)nret >= PATH_MAX) {
ERROR("Sprintf graph driver path failed");
return NULL;
ret = -1;
goto out;
}
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) {
ret = -1;
goto out;
}
g_graphdriver = &g_drivers[i];
......@@ -86,15 +90,26 @@ struct graphdriver *graphdriver_init(const char *name, const char *isulad_root,
}
}
out:
return g_graphdriver;
}
if (i == g_numdrivers) {
ERROR("unsupported driver %s", name);
ret = -1;
goto out;
}
struct graphdriver *graphdriver_get()
{
return g_graphdriver;
}
//just for test
struct driver_create_opts test_create_opts = { 0 };
struct driver_mount_opts test_mount_opts = { 0 };
graphdriver_create_ro("1", "", &test_create_opts);
graphdriver_create_ro("2", "1", &test_create_opts);
graphdriver_create_ro("3", "2", &test_create_opts);
graphdriver_create_ro("4", "3", &test_create_opts);
graphdriver_create_rw("5", "4", &test_create_opts);
ERROR("mount: %s", graphdriver_mount_layer("5", &test_mount_opts));
//end test
out:
return ret;
}
int graphdriver_create_rw(const char *id, const char *parent, struct driver_create_opts *create_opts)
{
......@@ -251,8 +266,12 @@ void free_graphdriver_status(struct graphdriver_status *status)
if (status == NULL) {
return;
}
free(status->driver_name);
status->driver_name = NULL;
free(status->backing_fs);
status->backing_fs = NULL;
free(status->status);
status->status = NULL;
free(status);
}
......
......@@ -41,6 +41,7 @@ struct driver_mount_opts {
};
struct graphdriver_status {
char *driver_name;
char *backing_fs;
char *status;
};
......@@ -88,10 +89,8 @@ struct graphdriver {
struct overlay_options *overlay_opts;
};
struct graphdriver *graphdriver_init(const char *name, const char *isulad_root, char **storage_opts,
size_t storage_opts_len);
struct graphdriver *graphdriver_get(void);
int graphdriver_init(const char *name, const char *isulad_root, char **storage_opts,
size_t storage_opts_len);
int graphdriver_create_rw(const char *id, const char *parent, struct driver_create_opts *create_opts);
......
......@@ -30,9 +30,18 @@
#include "util_archive.h"
#include "project_quota.h"
#define OVERLAY_LINK_DIR "l"
#define QUOTA_SIZE_OPTION "overlay2.size"
#define QUOTA_BASESIZE_OPTIONS "overlay2.basesize"
#define OVERLAY_LINK_DIR "l"
#define OVERLAY_LAYER_DIFF "diff"
#define OVERLAY_LAYER_MERGED "merged"
#define OVERLAY_LAYER_WORK "work"
#define OVERLAY_LAYER_LOWER "lower"
#define OVERLAY_LAYER_LINK "link"
#define OVERLAY_LAYER_EMPTY "empty"
#define OVERLAY_LAYER_MAX_DEPTH 128
#define QUOTA_SIZE_OPTION "overlay2.size"
#define QUOTA_BASESIZE_OPTIONS "overlay2.basesize"
// MAX_LAYER_ID_LENGTH represents the number of random characters which can be used to create the unique link identifer
// for every layer. If this value is too long then the page size limit for the mount command may be exceeded.
// The idLength should be selected such that following equation is true (512 is a buffer for label metadata).
......@@ -222,6 +231,29 @@ static bool check_bk_fs_support_quota(const char *backing_fs)
return strcmp(backing_fs, "xfs") == 0 || strcmp(backing_fs, "extfs") == 0;
}
static int driver_init_quota(struct graphdriver *driver)
{
int ret = 0;
if (check_bk_fs_support_quota(driver->backing_fs)) {
driver->quota_ctrl = project_quota_control_init(driver->home, driver->backing_fs);
if (driver->quota_ctrl != NULL) {
driver->support_quota = true;
} else if (driver->overlay_opts->default_quota != 0) {
ERROR("Storage option overlay.size not supported. Filesystem does not support Project Quota");
ret = -1;
goto out;
}
} else if (driver->overlay_opts->default_quota != 0) {
ERROR("Storage option overlay.size only supported for backingFS XFS or ext4.");
ret = -1;
goto out;
}
out:
return ret;
}
int overlay2_init(struct graphdriver *driver, const char *drvier_home, const char **options, size_t len)
{
int ret = 0;
......@@ -281,21 +313,15 @@ int overlay2_init(struct graphdriver *driver, const char *drvier_home, const cha
driver->support_dtype = true;
if (!driver->overlay_opts->skip_mount_home) {
ret = util_ensure_mounted_as(drvier_home, "private");
if (ret != 0) {
if (util_ensure_mounted_as(drvier_home, "private") != 0) {
ret = -1;
goto out;
}
}
if (check_bk_fs_support_quota(driver->backing_fs)) {
driver->quota_ctrl = project_quota_control_init(driver->home, driver->backing_fs);
if (driver->quota_ctrl == NULL) {
ERROR("Failed to init quota ctrl");
ret = -1;
goto out;
}
driver->support_quota = true;
if (driver_init_quota(driver) != 0) {
ret = -1;
goto out;
}
out:
......@@ -336,7 +362,7 @@ static int mk_diff_directory(const char *layer_dir)
int ret = 0;
char *diff_dir = NULL;
diff_dir = util_path_join(layer_dir, "diff");
diff_dir = util_path_join(layer_dir, OVERLAY_LAYER_DIFF);
if (diff_dir == NULL) {
ERROR("Failed to join layer diff dir:%s", layer_dir);
ret = -1;
......@@ -413,7 +439,7 @@ static int mk_diff_symlink(const char *id, const char *layer_dir, const char *dr
goto out;
}
link_file = util_path_join(layer_dir, "link");
link_file = util_path_join(layer_dir, OVERLAY_LAYER_LINK);
if (link_file == NULL) {
ERROR("Failed to get layer link file %s", layer_dir);
ret = -1;
......@@ -437,7 +463,7 @@ static int mk_work_directory(const char *layer_dir)
int ret = 0;
char *work_dir = NULL;
work_dir = util_path_join(layer_dir, "work");
work_dir = util_path_join(layer_dir, OVERLAY_LAYER_WORK);
if (work_dir == NULL) {
ERROR("Failed to join layer work dir:%s", layer_dir);
ret = -1;
......@@ -460,7 +486,7 @@ static int mk_merged_directory(const char *layer_dir)
int ret = 0;
char *merged_dir = NULL;
merged_dir = util_path_join(layer_dir, "merged");
merged_dir = util_path_join(layer_dir, OVERLAY_LAYER_MERGED);
if (merged_dir == NULL) {
ERROR("Failed to join layer merged dir:%s", layer_dir);
ret = -1;
......@@ -483,7 +509,7 @@ static int mk_empty_directory(const char *layer_dir)
int ret = 0;
char *empty_dir = NULL;
empty_dir = util_path_join(layer_dir, "empty");
empty_dir = util_path_join(layer_dir, OVERLAY_LAYER_EMPTY);
if (empty_dir == NULL) {
ERROR("Failed to join layer empty dir:%s", empty_dir);
ret = -1;
......@@ -501,6 +527,26 @@ out:
return ret;
}
const static int check_lower_depth(const char *lowers_str)
{
int ret = 0;
char **lowers_arr = NULL;
size_t lowers_size = 0;
lowers_arr = util_string_split(lowers_str, ':');
lowers_size = util_array_len((const char **)lowers_arr);
if (lowers_size > OVERLAY_LAYER_MAX_DEPTH) {
ERROR("Max depth exceeded %s", lowers_str);
ret = -1;
goto out;
}
out:
util_free_array(lowers_arr);
return ret;
}
static char *get_lower(const char *parent, const char *driver_home)
{
int nret = 0;
......@@ -518,7 +564,7 @@ static char *get_lower(const char *parent, const char *driver_home)
goto out;
}
parent_link_file = util_path_join(parent_dir, "link");
parent_link_file = util_path_join(parent_dir, OVERLAY_LAYER_LINK);
if (parent_link_file == NULL) {
ERROR("Failed to get parent link %s", parent_dir);
goto out;
......@@ -537,7 +583,7 @@ static char *get_lower(const char *parent, const char *driver_home)
lower_len = strlen(OVERLAY_LINK_DIR) + 1 + strlen(parent_link) + 1;
parent_lower_file = util_path_join(parent_dir, "lower");
parent_lower_file = util_path_join(parent_dir, OVERLAY_LAYER_LOWER);
if (parent_lower_file == NULL) {
ERROR("Failed to get parent lower %s", parent_dir);
goto out;
......@@ -563,6 +609,10 @@ static char *get_lower(const char *parent, const char *driver_home)
goto err_out;
}
if (check_lower_depth(lower) != 0) {
goto err_out;
}
goto out;
err_out:
......@@ -583,7 +633,7 @@ static int write_lowers(const char *layer_dir, const char *lowers)
int ret = 0;
char *lowers_file = NULL;
lowers_file = util_path_join(layer_dir, "lower");
lowers_file = util_path_join(layer_dir, OVERLAY_LAYER_LOWER);
if (lowers_file == NULL) {
ERROR("Failed to get layer lower file %s", layer_dir);
ret = -1;
......@@ -648,7 +698,7 @@ out:
return ret;
}
static int set_dir_quota(const char *dir, const json_map_string_string *opts, const struct graphdriver *driver)
static int set_layer_quota(const char *dir, const json_map_string_string *opts, const struct graphdriver *driver)
{
int ret = 0;
size_t i = 0;
......@@ -703,7 +753,7 @@ static int do_create(const char *id, const char *parent, const struct graphdrive
}
if (create_opts->storage_opt != NULL && create_opts->storage_opt->len != 0) {
if (set_dir_quota(layer_dir, create_opts->storage_opt, driver) != 0) {
if (set_layer_quota(layer_dir, create_opts->storage_opt, driver) != 0) {
ERROR("Unable to set layer quota %s", layer_dir);
ret = -1;
goto out;
......@@ -782,7 +832,7 @@ int overlay2_create_rw(const char *id, const char *parent, const struct graphdri
goto out;
}
if (apply_quota_opts(create_opts, driver->overlay_opts->default_quota) != 0) {
if (driver->support_quota && apply_quota_opts(create_opts, driver->overlay_opts->default_quota) != 0) {
ret = -1;
goto out;
}
......@@ -819,7 +869,7 @@ static char *read_layer_link_file(const char *layer_dir)
char *link_file = NULL;
char *link = NULL;
link_file = util_path_join(layer_dir, "link");
link_file = util_path_join(layer_dir, OVERLAY_LAYER_LINK);
if (link_file == NULL) {
ERROR("Failed to get link %s", layer_dir);
goto out;
......@@ -836,7 +886,7 @@ static char *read_layer_lower_file(const char *layer_dir)
char *lower_file = NULL;
char *lower = NULL;
lower_file = util_path_join(layer_dir, "lower");
lower_file = util_path_join(layer_dir, OVERLAY_LAYER_LOWER);
if (lower_file == NULL) {
ERROR("Failed to get lower %s", layer_dir);
goto out;
......@@ -927,7 +977,7 @@ static int append_abs_empty_path(const char *layer_dir, char ***abs_lowers)
int ret = 0;
char *abs_path = NULL;
abs_path = util_path_join(layer_dir, "empty");
abs_path = util_path_join(layer_dir, OVERLAY_LAYER_EMPTY);
if (!util_dir_exists(abs_path)) {
SYSERROR("Can't stat absolute layer:%s", abs_path);
ret = -1;
......@@ -1102,13 +1152,13 @@ static char *get_abs_mount_opt_data(const char *layer_dir, const char *abs_lower
char *work_dir = NULL;
char *tmp = NULL;
upper_dir = util_path_join(layer_dir, "diff");
upper_dir = util_path_join(layer_dir, OVERLAY_LAYER_DIFF);
if (upper_dir == NULL) {
ERROR("Failed to join layer diff dir:%s", layer_dir);
goto error_out;
}
work_dir = util_path_join(layer_dir, "work");
work_dir = util_path_join(layer_dir, OVERLAY_LAYER_WORK);
if (work_dir == NULL) {
ERROR("Failed to join layer work dir:%s", layer_dir);
goto error_out;
......@@ -1174,7 +1224,7 @@ static char *get_rel_mount_opt_data(const char *id, const char *rel_lower_dir, c
goto error_out;
}
work_dir = util_path_join("/work", id);
work_dir = util_string_append("/work", id);
if (work_dir == NULL) {
ERROR("Failed to join layer work dir:%s", id);
goto error_out;
......@@ -1225,7 +1275,7 @@ out:
}
static char *generate_mount_opt_data(const char *id, const char *layer_dir, const struct graphdriver *driver,
const struct driver_mount_opts *mount_opts)
const struct driver_mount_opts *mount_opts, bool *use_rel_mount)
{
int ret = 0;
char *mount_data = NULL;
......@@ -1246,11 +1296,18 @@ static char *generate_mount_opt_data(const char *id, const char *layer_dir, cons
}
if (strlen(mount_data) > page_size) {
free(mount_data);
*use_rel_mount = true;
mount_data = get_rel_mount_opt_data(id, rel_lower_dir, driver, mount_opts);
if (mount_data == NULL) {
ERROR("Failed to get abs mount opt data");
goto out;
}
if (strlen(mount_data) > page_size) {
ERROR("cannot mount layer, mount label too large %s", mount_data);
free(mount_data);
mount_data = NULL;
goto out;
}
}
out:
......@@ -1259,29 +1316,73 @@ out:
return mount_data;
}
static int abs_mount(const char *layer_dir, const char *merged_dir, const char *mount_data)
{
int ret = 0;
ret = util_mount("overlay", merged_dir, "overlay", mount_data);
if (ret != 0) {
ERROR("Failed to mount %s with option \"%s\"", merged_dir, mount_data);
goto out;
}
out:
return ret;
}
static int rel_mount(const char *driver_home, const char *id, const char *mount_data)
{
int ret = 0;
char *mount_target = NULL;
mount_target = util_string_append("/merged", id);
if (mount_target == NULL) {
ERROR("Failed to join layer merged dir:%s", id);
ret = -1;
goto out;
}
ret = util_mount_from(driver_home, "overlay", mount_target, "overlay", mount_data);
if (ret != 0) {
ERROR("Failed to mount %s with option \"%s\"", mount_target, mount_data);
ret = -1;
goto out;
}
out:
free(mount_target);
return ret;
}
static char *do_mount_layer(const char *id, const char *layer_dir, const struct graphdriver *driver,
const struct driver_mount_opts *mount_opts)
{
int nret = 0;
char *merged_dir = NULL;
char *mount_data = NULL;
bool use_rel_mount = false;
mount_data = generate_mount_opt_data(id, layer_dir, driver, mount_opts);
mount_data = generate_mount_opt_data(id, layer_dir, driver, mount_opts, &use_rel_mount);
if (mount_data == NULL) {
ERROR("Failed to get mount data");
goto error_out;
}
merged_dir = util_path_join(layer_dir, "merged");
merged_dir = util_path_join(layer_dir, OVERLAY_LAYER_MERGED);
if (merged_dir == NULL) {
ERROR("Failed to join layer merged dir:%s", layer_dir);
goto error_out;
}
nret = util_mount("overlay", merged_dir, "overlay", mount_data);
if (nret != 0) {
ERROR("Failed to mount %s with option \"%s\"", merged_dir, mount_data);
goto error_out;
if (!use_rel_mount) {
if (abs_mount(layer_dir, merged_dir, mount_data) != 0) {
ERROR("Failed to mount %s with option \"%s\"", merged_dir, mount_data);
goto error_out;
}
} else {
if (rel_mount(driver->home, id, mount_data) != 0) {
ERROR("Failed to mount %s from %s with option \"%s\"", id, driver->home, mount_data);
goto error_out;
}
}
goto out;
......@@ -1349,7 +1450,7 @@ int overlay2_umount_layer(const char *id, const struct graphdriver *driver)
goto out;
}
merged_dir = util_path_join(layer_dir, "merged");
merged_dir = util_path_join(layer_dir, OVERLAY_LAYER_MERGED);
if (merged_dir == NULL) {
ERROR("Failed to join layer merged dir:%s", layer_dir);
ret = -1;
......@@ -1473,7 +1574,7 @@ int overlay2_apply_diff(const char *id, const struct graphdriver *driver, const
goto out;
}
layer_diff = util_path_join(layer_dir, "diff");
layer_diff = util_path_join(layer_dir, OVERLAY_LAYER_DIFF);
if (layer_diff == NULL) {
ERROR("Failed to join layer diff dir:%s", id);
ret = -1;
......@@ -1557,7 +1658,7 @@ int overlay2_get_layer_metadata(const char *id, const struct graphdriver *driver
goto out;
}
work_dir = util_path_join(layer_dir, "work");
work_dir = util_path_join(layer_dir, OVERLAY_LAYER_WORK);
if (work_dir == NULL) {
ERROR("Failed to join layer work dir:%s", layer_dir);
ret = -1;
......@@ -1569,7 +1670,7 @@ int overlay2_get_layer_metadata(const char *id, const struct graphdriver *driver
goto out;
}
merged_dir = util_path_join(layer_dir, "merged");
merged_dir = util_path_join(layer_dir, OVERLAY_LAYER_MERGED);
if (merged_dir == NULL) {
ERROR("Failed to join layer merged dir:%s", layer_dir);
ret = -1;
......@@ -1581,7 +1682,7 @@ int overlay2_get_layer_metadata(const char *id, const struct graphdriver *driver
goto out;
}
upper_dir = util_path_join(layer_dir, "diff");
upper_dir = util_path_join(layer_dir, OVERLAY_LAYER_DIFF);
if (upper_dir == NULL) {
ERROR("Failed to join layer upper_dir dir:%s", layer_dir);
ret = -1;
......@@ -1626,6 +1727,8 @@ int overlay2_get_driver_status(const struct graphdriver *driver, struct graphdri
return -1;
}
status->driver_name = util_strdup_s(driver->name);
status->backing_fs = util_strdup_s(driver->backing_fs);
nret = snprintf(tmp, MAX_INFO_LENGTH, "%s: %s\n", BACK_FS, driver->backing_fs);
......
......@@ -232,13 +232,6 @@ static int isulad_info_cb(const host_info_request *request, host_info_response *
}
#ifdef ENABLE_OCI_IMAGE
im_request->type = util_strdup_s(IMAGE_TYPE_OCI);
graph_driver = conf_get_isulad_storage_driver();
if (graph_driver == NULL) {
ERROR("Failed to get graph driver name info!");
goto pack_response;
}
driver_status = graphdriver_get_status();
if (driver_status == NULL) {
ERROR("Failed to get graph driver status info!");
......@@ -326,7 +319,7 @@ static int isulad_info_cb(const host_info_request *request, host_info_response *
(*response)->https_proxy = util_strdup_s(https_proxy);
(*response)->no_proxy = util_strdup_s(no_proxy);
#ifdef ENABLE_OCI_IMAGE
(*response)->driver_name = util_strdup_s(graph_driver);
(*response)->driver_name = util_strdup_s(driver_status->driver_name);
(*response)->driver_status = util_strdup_s(driver_status->status);
#endif
......
......@@ -831,35 +831,28 @@ static bool is_storage_opts_valid(const json_map_string_string *storage_opts)
static int verify_storage_opts(const host_config *hc)
{
int ret = 0;
char *driver = NULL;
json_map_string_string *storage_opts = NULL;
struct graphdriver_status *driver_status = NULL;
if (hc != NULL) {
storage_opts = hc->storage_opt;
}
driver = conf_get_isulad_storage_driver();
if (driver == NULL) {
ERROR("Failed to get storage driver");
return -1;
driver_status = graphdriver_get_status();
if (driver_status == NULL) {
ERROR("Failed to get graph driver status info!");
ret = -1;
goto cleanup;
}
if (storage_opts == NULL || storage_opts->len == 0 || strcmp(driver, "overlay2") != 0) {
if (storage_opts == NULL || storage_opts->len == 0 || strcmp(driver_status->driver_name, "overlay2") != 0) {
goto cleanup;
}
if (storage_opts->len > 0) {
char *backing_fs = NULL;
backing_fs = conf_get_isulad_storage_driver_backing_fs();
if (backing_fs == NULL) {
ERROR("No backing fs detected");
ret = -1;
goto cleanup;
}
if (strcmp(backing_fs, "xfs") == 0) {
if (strcmp(driver_status->backing_fs, "xfs") == 0) {
WARN("Filesystem quota for overlay2 over xfs is not totally support");
}
free(backing_fs);
}
if (!is_storage_opts_valid(storage_opts)) {
......@@ -868,7 +861,7 @@ static int verify_storage_opts(const host_config *hc)
}
cleanup:
free(driver);
free_graphdriver_status(driver_status);
return ret;
}
#endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册