From 42a878e6c1a17b2e5f9e69bc0c7f61fe48c10256 Mon Sep 17 00:00:00 2001 From: yaoyinnan Date: Sat, 12 Feb 2022 11:10:10 +0800 Subject: [PATCH] runtime: The index variable is initialized multiple times in for Change the variables `mountTypeFieldIdx := 8`, `mntDestIdx := 4` and `netNsMountType := "nsfs"` to const. And unify the variable naming style, modify `mntDestIdx` to `mountDestIdx`. Fixes: #3646 Signed-off-by: yaoyinnan --- src/runtime/pkg/katautils/network.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/runtime/pkg/katautils/network.go b/src/runtime/pkg/katautils/network.go index d0cb4d66f4..fd37c66056 100644 --- a/src/runtime/pkg/katautils/network.go +++ b/src/runtime/pkg/katautils/network.go @@ -94,10 +94,14 @@ func SetupNetworkNamespace(config *vc.NetworkConfig) error { return nil } +const ( + netNsMountType = "nsfs" + mountTypeFieldIdx = 8 + mountDestIdx = 4 +) + // getNetNsFromBindMount returns the network namespace for the bind-mounted path func getNetNsFromBindMount(nsPath string, procMountFile string) (string, error) { - netNsMountType := "nsfs" - // Resolve all symlinks in the path as the mountinfo file contains // resolved paths. nsPath, err := filepath.EvalSymlinks(nsPath) @@ -129,14 +133,12 @@ func getNetNsFromBindMount(nsPath string, procMountFile string) (string, error) } // We check here if the mount type is a network namespace mount type, namely "nsfs" - mountTypeFieldIdx := 8 if fields[mountTypeFieldIdx] != netNsMountType { continue } // This is the mount point/destination for the mount - mntDestIdx := 4 - if fields[mntDestIdx] != nsPath { + if fields[mountDestIdx] != nsPath { continue }