Skip to content

Commit a89250d

Browse files
committed
Add ipc docs
Signed-off-by: Min Uk Lee <[email protected]>
1 parent efb8a67 commit a89250d

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

docs/command-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ Logging flags:
351351

352352
Shared memory flags:
353353

354-
- :whale: `--ipc`: IPC namespace to use
354+
- :whale: `--ipc=(host|private|shareable|container:<container>)`: IPC namespace to use and mount `/dev/shm`. Default: "private". Only implemented on Linux.
355355
- :whale: `--shm-size`: Size of `/dev/shm`
356356

357357
GPU flags:

pkg/cmd/container/run_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func generateNamespaceOpts(
163163
func generateIPCOpts(ctx context.Context, client *containerd.Client, ipcFlag string, shmSize string, stateDir string) ([]oci.SpecOpts, string, error) {
164164
ipcFlag = strings.ToLower(ipcFlag)
165165

166-
ipc, err := ipcutil.Detect(ctx, client, stateDir, ipcFlag, shmSize)
166+
ipc, err := ipcutil.DetectFlags(ctx, client, stateDir, ipcFlag, shmSize)
167167
if err != nil {
168168
return nil, "", err
169169
}

pkg/ipcutil/ipcutil.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ type IPC struct {
4444
// HostShmPath is only used when mode is shareable
4545
HostShmPath *string `json:"host_shm_path,omitempty"`
4646

47+
// ShmSize is only used when mode is private or shareable
48+
// Devshm size in bytes
4749
ShmSize string `json:"shm_size,omitempty"`
4850
}
4951

@@ -54,7 +56,9 @@ const (
5456
Container IPCMode = "container"
5557
)
5658

57-
func Detect(ctx context.Context, client *containerd.Client, stateDir string, ipc string, shmSize string) (IPC, error) {
59+
// DetectFlags detects IPC mode from the given ipc string and shmSize string.
60+
// If ipc is empty, it returns IPC{Mode: Private}.
61+
func DetectFlags(ctx context.Context, client *containerd.Client, stateDir string, ipc string, shmSize string) (IPC, error) {
5862
var res IPC
5963
res.ShmSize = shmSize
6064
switch ipc {
@@ -98,6 +102,7 @@ func Detect(ctx context.Context, client *containerd.Client, stateDir string, ipc
98102
return res, nil
99103
}
100104

105+
// EncodeIPCLabel encodes IPC spec into a label.
101106
func EncodeIPCLabel(ipc IPC) (string, error) {
102107
if ipc.Mode == "" {
103108
return "", nil
@@ -109,6 +114,8 @@ func EncodeIPCLabel(ipc IPC) (string, error) {
109114
return string(b), nil
110115
}
111116

117+
// DecodeIPCLabel decodes IPC spec from a label.
118+
// For backward compatibility, if ipcLabel is empty, it returns IPC{Mode: Private}.
112119
func DecodeIPCLabel(ipcLabel string) (IPC, error) {
113120
if ipcLabel == "" {
114121
return IPC{
@@ -123,6 +130,7 @@ func DecodeIPCLabel(ipcLabel string) (IPC, error) {
123130
return ipc, nil
124131
}
125132

133+
// GenerateIPCOpts generates IPC spec opts from the given IPC.
126134
func GenerateIPCOpts(ctx context.Context, ipc IPC, client *containerd.Client) ([]oci.SpecOpts, error) {
127135
opts := make([]oci.SpecOpts, 0)
128136

@@ -199,6 +207,7 @@ func GenerateIPCOpts(ctx context.Context, ipc IPC, client *containerd.Client) ([
199207
return opts, nil
200208
}
201209

210+
// WithBindMountHostOtherSourceIPC replaces /dev/shm mount with rbind by the given path on host
202211
func withBindMountHostOtherSourceIPC(source string) oci.SpecOpts {
203212
return func(_ context.Context, _ oci.Client, _ *containers.Container, s *oci.Spec) error {
204213
for i, m := range s.Mounts {

0 commit comments

Comments
 (0)