From 6b5a0a345ae767cc245d1008377b8489acf2c0c7 Mon Sep 17 00:00:00 2001 From: zhongtao Date: Sat, 8 Apr 2023 14:50:20 +0800 Subject: [PATCH 39/46] add files_limit to oci spec Signed-off-by: zhongtao --- src/daemon/modules/spec/specs.c | 49 +++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/daemon/modules/spec/specs.c b/src/daemon/modules/spec/specs.c index f32ff911..ad6d01d2 100644 --- a/src/daemon/modules/spec/specs.c +++ b/src/daemon/modules/spec/specs.c @@ -890,6 +890,27 @@ static int make_sure_oci_spec_linux_resources_pids(oci_runtime_spec *oci_spec) return 0; } +static int make_sure_oci_spec_linux_resources_files(oci_runtime_spec *oci_spec) +{ + int ret = 0; + + ret = make_sure_oci_spec_linux_resources(oci_spec); + if (ret < 0) { + return -1; + } + + if (oci_spec->linux->resources->files != NULL) { + return 0; + } + + oci_spec->linux->resources->files = util_common_calloc_s(sizeof(defs_resources_files)); + if (oci_spec->linux->resources->files == NULL) { + ERROR("Out of memory"); + return -1; + } + return 0; +} + static int merge_pids_limit(oci_runtime_spec *oci_spec, int64_t pids_limit) { int ret = 0; @@ -905,6 +926,20 @@ out: return ret; } +static int merge_files_limit(oci_runtime_spec *oci_spec, int64_t files_limit) +{ + int ret = 0; + + ret = make_sure_oci_spec_linux_resources_files(oci_spec); + if (ret < 0) { + ERROR("Failed to merge files limit"); + return ret; + } + + oci_spec->linux->resources->files->limit = files_limit; + return ret; +} + static int merge_hostname(oci_runtime_spec *oci_spec, const host_config *host_spec, container_config *container_spec) { free(oci_spec->hostname); @@ -1251,6 +1286,15 @@ out: return ret; } +static int merge_conf_files_limit(oci_runtime_spec *oci_spec, const host_config *host_spec) +{ + if (host_spec->files_limit == 0) { + return 0; + } + + return merge_files_limit(oci_spec, host_spec->files_limit); +} + int merge_conf_cgroup(oci_runtime_spec *oci_spec, const host_config *host_spec) { int ret = 0; @@ -1290,6 +1334,11 @@ int merge_conf_cgroup(oci_runtime_spec *oci_spec, const host_config *host_spec) goto out; } + ret = merge_conf_files_limit(oci_spec, host_spec); + if (ret != 0) { + goto out; + } + out: return ret; } -- 2.25.1