Skip to content

Commit 257b378

Browse files
Merge pull request cri-o#4148 from kolyshkin/pinns-debug
Fix pinns error diagnostics, cleanup, and return
2 parents da77921 + 7b1e835 commit 257b378

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

internal/lib/sandbox/namespaces_linux.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func pinNamespaces(nsTypes []NSType, cfg *config.Config, idMappings *idtools.IDM
9595
return nil, errors.Errorf("Invalid namespace type: %s", nsType)
9696
}
9797
pinnsArgs = append(pinnsArgs, arg)
98-
pinPath := filepath.Join(cfg.NamespacesDir, fmt.Sprintf("%sns", string(nsType)), pinnedNamespace)
98+
pinPath := filepath.Join(cfg.NamespacesDir, string(nsType)+"ns", pinnedNamespace)
9999
mountedNamespaces = append(mountedNamespaces, namespaceInfo{
100100
path: pinPath,
101101
nsType: nsType,
@@ -122,28 +122,21 @@ func pinNamespaces(nsTypes []NSType, cfg *config.Config, idMappings *idtools.IDM
122122
fmt.Sprintf("--gid-mapping=%s", getMappingsForPinns(idMappings.GIDs())))
123123
}
124124

125-
pinns := cfg.PinnsPath
126-
127125
logrus.Debugf("calling pinns with %v", pinnsArgs)
128-
output, err := exec.Command(pinns, pinnsArgs...).Output()
129-
if len(output) != 0 {
130-
logrus.Debugf("pinns output: %s", string(output))
131-
}
126+
output, err := exec.Command(cfg.PinnsPath, pinnsArgs...).CombinedOutput()
132127
if err != nil {
133-
// cleanup after ourselves
134-
failedUmounts := make([]string, 0)
128+
logrus.Warnf("pinns %v failed: %s (%v)", pinnsArgs, string(output), err)
129+
// cleanup the mounts
135130
for _, info := range mountedNamespaces {
136-
if unmountErr := unix.Unmount(info.path, unix.MNT_DETACH); unmountErr != nil {
137-
failedUmounts = append(failedUmounts, info.path)
131+
if mErr := unix.Unmount(info.path, unix.MNT_DETACH); mErr != nil && mErr != unix.EINVAL {
132+
logrus.Warnf("failed to unmount %s: %v", info.path, mErr)
138133
}
139134
}
140-
if len(failedUmounts) != 0 {
141-
return nil, fmt.Errorf("failed to cleanup %v after pinns failure %s %v", failedUmounts, output, err)
142-
}
135+
143136
return nil, fmt.Errorf("failed to pin namespaces %v: %s %v", nsTypes, output, err)
144137
}
145138

146-
returnedNamespaces := make([]NamespaceIface, 0)
139+
returnedNamespaces := make([]NamespaceIface, 0, len(nsTypes))
147140
for _, info := range mountedNamespaces {
148141
ret, err := nspkg.GetNS(info.path)
149142
if err != nil {

0 commit comments

Comments
 (0)