diff --git a/CI/test_cases/container_cases/grow_fs.bash b/CI/test_cases/container_cases/grow_fs.bash new file mode 100755 index 0000000000000000000000000000000000000000..d3641a2bf1de6bbc03c444ed83e181ed03f2442f --- /dev/null +++ b/CI/test_cases/container_cases/grow_fs.bash @@ -0,0 +1,85 @@ +#!/bin/bash +# +# attributes: isulad inheritance restart +# concurrent: YES +# spend time: 1 + +####################################################################### +##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved. +# - iSulad licensed under the Mulan PSL v2. +# - You can use this software according to the terms and conditions of the Mulan PSL v2. +# - You may obtain a copy of Mulan PSL v2 at: +# - http://license.coscl.org.cn/MulanPSL2 +# - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# - IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# - PURPOSE. +# - See the Mulan PSL v2 for more details. +##- @Description:CI +##- @Author: gaohuatao +##- @Create: 2020-07-1 +####################################################################### + +curr_path=$(dirname $(readlink -f "$0")) +data_path=$(realpath $curr_path/../data) +source ../helpers.bash + +function do_pre() +{ + local ret=0 + + cp -f /etc/isulad/daemon.json /etc/isulad/daemon.bak + # delete next line + sed -i '/ \"dm\.fs\=ext4\"\,/{n;d}' /etc/isulad/daemon.json + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - fail to modify daemon.json" && ((ret++)) + sed -i '/ \"dm\.fs\=ext4\"\,/a\ \"dm\.min\_free\_space\=10\%\"\,\n \"dm\.basesize\=11G\"' /etc/isulad/daemon.json + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - fail to modify daemon.json" && ((ret++)) + + return $ret +} + +function test_grow_fs() +{ + local ret=0 + + local test="restart isulad specify dm.basesize test => (${FUNCNAME[@]})" + msg_info "${test} starting..." + + id=`isula run -tid busybox` + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - run container failed" && ((ret++)) + + check_valgrind_log + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stop isulad failed" && ((ret++)) + + start_isulad_with_valgrind + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - start isulad failed" && ((ret++)) + + isula rm -f $id + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - rm container id:$id failed" && ((ret++)) + + msg_info "${test} finished with return ${ret}..." + return ${ret} +} + +function do_post() +{ + local ret=0 + + check_valgrind_log + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stop isulad failed" && ((ret++)) + + start_isulad_with_valgrind + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - start isulad failed" && ((ret++)) + + return ${ret} +} + +declare -i ans=0 + +driver_name=$(isula info | grep "Storage Driver" | cut -d " " -f3) +if [[ "x$driver_name" == "xdevicemapper" ]]; then + do_pre || ((ans++)) + test_grow_fs || ((ans++)) + do_post || ((ans++)) +fi + +show_result ${ans} "${curr_path}/${0}" diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/devices_constants.h b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/devices_constants.h index 73ec33058d02d3b40ec0d9fcfa2316158e3b2d4d..a6eec7560e00b8210d5436a54d0d3079d50f4f3e 100644 --- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/devices_constants.h +++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/devices_constants.h @@ -27,7 +27,6 @@ #define DEVMAPPER_DECICE_DIRECTORY "/dev/mapper/" #define DEFAULT_THIN_BLOCK_SIZE 128 #define DEFAULT_METADATA_LOOPBACK_SIZE (2 * 1024 * 1024 * 1024) -// #define DEFAULT_BASE_FS_SIZE (10 * 1024 * 1024 * 1024) #define DEFAULT_UDEV_SYNC_OVERRIDE false #define MAX_DEVICE_ID (0xffffff) // 24 bit, pool limit diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c index b32e5614d208e2cbdeaa0d4c183eec6dab9496f8..fa5967d3cb2c7a09975c2775a0f88aafbe1c1412 100644 --- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c +++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c @@ -36,9 +36,6 @@ #define DM_LOG_FATAL 2 #define DM_LOG_DEBUG 7 -// static int64_t default_udev_wait_timeout = 185; -static uint64_t default_base_fs_size = 10L * 1024L * 1024L * 1204L; - static char *util_trim_prefice_string(char *str, const char *prefix) { if (str == NULL || !util_has_prefix(str, prefix)) { @@ -1756,7 +1753,6 @@ static int save_base_device_uuid(struct device_set *devset, image_devmapper_devi int ret = 0; char *base_dev_uuid = NULL; char *dev_fname = NULL; - char *dm_name = NULL; if (activate_device_if_needed(devset, info, false) != 0) { ret = -1; @@ -1764,14 +1760,13 @@ static int save_base_device_uuid(struct device_set *devset, image_devmapper_devi goto free_out; } - dm_name = get_dm_name(devset, info->hash); - if (dm_name == NULL) { + dev_fname = dev_name(devset, info); + if (dev_fname == NULL) { ret = -1; ERROR("devmapper: get dm name failed"); goto free_out; } - dev_fname = get_dev_name(dm_name); base_dev_uuid = get_device_uuid(dev_fname); if (base_dev_uuid == NULL) { ret = -1; @@ -1788,7 +1783,6 @@ static int save_base_device_uuid(struct device_set *devset, image_devmapper_devi free_out: deactivate_device(devset, info); - free(dm_name); free(dev_fname); free(base_dev_uuid); return ret; @@ -1950,7 +1944,6 @@ out: static int verify_base_device_uuidfs(struct device_set *devset, image_devmapper_device_info *base_info) { int ret = 0; - char *dm_name = NULL; char *dev_fname = NULL; char *uuid = NULL; char *fs_type = NULL; @@ -1960,13 +1953,12 @@ static int verify_base_device_uuidfs(struct device_set *devset, image_devmapper_ return -1; } - dm_name = get_dm_name(devset, base_info->hash); - if (dm_name == NULL) { + dev_fname = dev_name(devset, base_info); + if (dev_fname == NULL) { ret = -1; ERROR("devmapper: get dm name failed"); goto out; } - dev_fname = get_dev_name(dm_name); uuid = get_device_uuid(dev_fname); if (uuid == NULL) { @@ -2007,7 +1999,6 @@ static int verify_base_device_uuidfs(struct device_set *devset, image_devmapper_ out: deactivate_device(devset, base_info); - free(dm_name); free(dev_fname); free(uuid); free(fs_type); @@ -2084,7 +2075,6 @@ static int grow_fs(struct device_set *devset, image_devmapper_device_info *info) int ret = 0; bool is_remove = false; char *mount_opt = NULL; - char *pool_name = NULL; char *dev_fname = NULL; if (activate_device_if_needed(devset, info, false) != 0) { @@ -2103,11 +2093,10 @@ static int grow_fs(struct device_set *devset, image_devmapper_device_info *info) append_mount_options(&mount_opt, devset->mount_options); - pool_name = get_pool_name(devset); - dev_fname = get_dev_name(pool_name); + dev_fname = dev_name(devset, info); if (dev_fname == NULL) { ret = -1; - ERROR("devmapper: pool device name is NULL"); + ERROR("devmapper: get device:%s full name failed", info->hash); goto out; } @@ -2136,7 +2125,6 @@ out: if (is_remove && util_path_remove(FS_MOUNT_POINT) != 0) { ERROR("devmapper: remove path:%s failed", FS_MOUNT_POINT); } - free(pool_name); free(dev_fname); free(mount_opt); return ret; @@ -2152,7 +2140,7 @@ static int check_grow_base_device_fs(struct device_set *devset, image_devmapper_ base_dev_size = get_base_device_size(devset); if (devset->base_fs_size < base_dev_size) { - ERROR("devmapper: Base fs size cannot be smaller than %ld", base_dev_size); + ERROR("devmapper: Base fs size:%lu cannot be smaller than %lu",devset->base_fs_size, base_dev_size); return -1; } @@ -2622,7 +2610,8 @@ static int devmapper_init_devset(const char *driver_home, const char **options, devset->driver_deferred_removal_support = false; devset->enable_deferred_removal = false; devset->enable_deferred_deletion = false; - devset->base_fs_size = default_base_fs_size; + devset->base_fs_size = 10 * SIZE_GB; + ERROR("BASE fs size is %lu", devset->base_fs_size); devset->override_udev_sync_check = DEFAULT_UDEV_SYNC_OVERRIDE; devset->do_blk_discard = false; devset->thinp_block_size = DEFAULT_THIN_BLOCK_SIZE;