From b40deecb6eca9083f66cad86f79187a95389889d Mon Sep 17 00:00:00 2001 From: deeplethe Date: Thu, 14 May 2026 11:16:48 +0800 Subject: [PATCH] cubelet: make cmdTimeout configurable via storage plugin config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements proposal (1) from #235. Adds an optional `cmd_timeout` field to the storage plugin's TOML config. When unset, the existing 3 s default is preserved — no behavior change. Multi-GiB ext4 ops on the live-create slow path can need longer than 3 s under concurrent load; this knob lets operators raise it without recompiling. Example: [plugins."io.cubelet.internal.v1.storage"] cmd_timeout = "30s" Signed-off-by: Wayland Yang --- Cubelet/storage/local.go | 1 + Cubelet/storage/plugin.go | 16 ++++++++++++++++ Cubelet/storage/shell.go | 9 ++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Cubelet/storage/local.go b/Cubelet/storage/local.go index 73b74ada..a9c6e435 100644 --- a/Cubelet/storage/local.go +++ b/Cubelet/storage/local.go @@ -75,6 +75,7 @@ var ( defaultPoolTriggerIntervalInMs = 1000 defaultWarningPercent = 100 defaultFormatSize = "1Gi" + defaultCmdTimeout = 3 * time.Second unifiedStorageSize = resource.MustParse(defaultFormatSize) otherFormatSize = "othersv2" diff --git a/Cubelet/storage/plugin.go b/Cubelet/storage/plugin.go index 211674ca..1b17c4ab 100644 --- a/Cubelet/storage/plugin.go +++ b/Cubelet/storage/plugin.go @@ -50,6 +50,14 @@ type Config struct { FreeInodesThreshold int32 `toml:"free_inodes_threshold"` ReconcileInterval tomlext.Duration `toml:"reconcile_interval"` + + // CmdTimeout overrides the per-command timeout for utils.ExecV + // invocations in shell.go (cp / truncate / e2fsck / resize2fs / + // mkfs.ext4). Defaults to defaultCmdTimeout when zero. The slow + // ext4-create path on multi-GiB images can need noticeably more + // than the 3s default; this knob lets operators bump it without + // recompiling. + CmdTimeout tomlext.Duration `toml:"cmd_timeout"` } func init() { @@ -76,6 +84,14 @@ func init() { if localStorage.config.PoolType == "" { localStorage.config.PoolType = cp_type } + if localStorage.config.CmdTimeout == 0 { + localStorage.config.CmdTimeout = tomlext.FromStdTime(defaultCmdTimeout) + } + if tomlext.ToStdTime(localStorage.config.CmdTimeout) < 0 { + return nil, fmt.Errorf("cmd_timeout must be non-negative, got %v", + tomlext.ToStdTime(localStorage.config.CmdTimeout)) + } + cmdTimeout = tomlext.ToStdTime(localStorage.config.CmdTimeout) checkPoolType(localStorage.config) cubeboxAPIObj, err := ic.GetByID(constants.CubeStorePlugin, constants.CubeboxID.ID()) diff --git a/Cubelet/storage/shell.go b/Cubelet/storage/shell.go index 7775af26..51b7a460 100644 --- a/Cubelet/storage/shell.go +++ b/Cubelet/storage/shell.go @@ -13,7 +13,14 @@ import ( "github.com/tencentcloud/CubeSandbox/Cubelet/pkg/utils" ) -const cmdTimeout = time.Second * 3 +// cmdTimeout is the per-command timeout for utils.ExecV calls in this +// package (cp, truncate, e2fsck, resize2fs, mkfs.ext4, ...). The +// default of 3s is fine for the small pre-formatted images on the +// pool fast path; the live `mkfs + reflink-copy + e2fsck + resize2fs` +// slow path on multi-GiB images can need longer. Override via the +// storage plugin config `cmd_timeout` (see Config.CmdTimeout); set +// during plugin initialization. +var cmdTimeout = 3 * time.Second const diskSizeOverheadInBytes = 1024 * 1024 * 100