提交 11711205 编写于 作者: L lifeng68

resources: support inspect memory-swap

Signed-off-by: Nlifeng68 <lifeng68@huawei.com>
上级 d943fc8e
......@@ -26,7 +26,7 @@ source ./helpers.bash
function do_test_t()
{
containername=test_update
containerid=`isula create -t --name $containername busybox`
containerid=`isula create -t --memory 50M --name $containername busybox`
fn_check_eq "$?" "0" "create failed"
testcontainer $containername inited
......@@ -117,6 +117,29 @@ function do_test_t()
return $TC_RET_T
}
function do_test_t1()
{
containername=test_update1
containerid=`isula run -itd --memory 500M --name $containername busybox`
fn_check_eq "$?" "0" "run failed"
isula inspect $containerid | grep "MemorySwap" | grep "1048576000"
fn_check_eq "$?" "0" "inspect memory swap failed"
isula update --memory 2G $containername > /tmp/test_update1.log 2>&1
fn_check_eq "$?" "1" "Success update memory with 2G, expect fail"
cat /tmp/test_update1.log | grep "Memory limit should be smaller than already set memoryswap limit, update the memoryswap at the same time."
fn_check_eq "$?" "0" "Failed to check error message"
rm -rf /tmp/test_update1.log
isula rm -f $containername
fn_check_eq "$?" "0" "rm failed"
return $TC_RET_T
}
ret=0
do_test_t
......@@ -124,4 +147,11 @@ if [ $? -ne 0 ];then
let "ret=$ret + 1"
fi
if [ -f "/sys/fs/cgroup/memory/memory.memsw.usage_in_bytes" ];then
do_test_t1
if [ $? -ne 0 ];then
let "ret=$ret + 1"
fi
fi
show_result $ret "basic update"
......@@ -45,6 +45,7 @@
#include "constants.h"
#include "namespace.h"
#include "collector.h"
#include "sysinfo.h"
static int runtime_check(const char *name, bool *runtime_res)
{
......@@ -837,6 +838,33 @@ static int preparate_runtime_environment(const container_create_request *request
return 0;
}
static int adapt_host_spec(host_config *host_spec)
{
int ret = 0;
sysinfo_t *sysinfo = NULL;
sysinfo = get_sys_info(true);
if (sysinfo == NULL) {
ERROR("Can not get system info");
ret = -1;
goto out;
}
if (host_spec->memory > 0 && host_spec->memory_swap == 0 && sysinfo->cgmeminfo.swap) {
if (host_spec->memory > (INT64_MAX / 2)) {
ERROR("Memory swap out of range!");
isulad_set_error_message("Memory swap out of range!");
ret = -1;
goto out;
}
host_spec->memory_swap = host_spec->memory * 2;
}
out:
free_sysinfo(sysinfo);
return ret;
}
static int get_basic_spec(const container_create_request *request, const char *id, const char *runtime_root,
host_config **host_spec, container_config **container_spec)
{
......@@ -845,6 +873,10 @@ static int get_basic_spec(const container_create_request *request, const char *i
return -1;
}
if (adapt_host_spec(*host_spec) != 0) {
return -1;
}
*container_spec = get_container_spec(id, runtime_root, request);
if (*container_spec == NULL) {
return -1;
......
......@@ -863,8 +863,9 @@ static int update_container_memory(const char *id, const host_config *hostconfig
hostconfig->memory_swap == 0) {
ERROR("Memory limit should be smaller than already set memoryswap limit,"
" update the memoryswap at the same time");
isulad_set_error_message("Cannot update container %s: Memory limit should be smaller than"
"already set memoryswap limit, update the memoryswap at the same time.", id);
isulad_set_error_message("Cannot update container %s: Memory limit should be smaller than "
"already set memoryswap limit, update the memoryswap at the same time.",
id);
ret = -1;
goto out;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册