Skip to content

Commit dd476f0

Browse files
committed
Implement Mount Fix
Signed-off-by: Antonio <[email protected]>
1 parent a36276f commit dd476f0

File tree

10 files changed

+48
-16
lines changed

10 files changed

+48
-16
lines changed

libpod/common_test.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,16 @@ func getTestContainer(id, name string, manager lock.Manager) (*Container, error)
2727
RootfsImageID: id,
2828
RootfsImageName: "testimg",
2929
StaticDir: "/does/not/exist/",
30-
Mounts: []string{"/does/not/exist"},
30+
Mounts: []define.InspectMount{
31+
{
32+
Type: "bind",
33+
Source: "/dummy/source",
34+
Destination: "/dummy/destination",
35+
Mode: "",
36+
RW: true,
37+
Propagation: "rprivate",
38+
},
39+
},
3140
},
3241
ContainerMiscConfig: ContainerMiscConfig{
3342
LogPath: "/does/not/exist/",

libpod/container.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,10 @@ func (c *Container) Spec() *spec.Spec {
379379
return returnSpec
380380
}
381381

382-
// specFromState returns the unmarshalled json config of the container. If the
382+
// SpecFromState returns the unmarshalled json config of the container. If the
383383
// config does not exist (e.g., because the container was never started) return
384384
// the spec from the config.
385-
func (c *Container) specFromState() (*spec.Spec, error) {
385+
func (c *Container) SpecFromState() (*spec.Spec, error) {
386386
returnSpec := c.config.Spec
387387

388388
if f, err := os.Open(c.state.ConfigPath); err == nil {

libpod/container_config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ type ContainerRootFSConfig struct {
147147
// Mounts contains all additional mounts into the container rootfs.
148148
// It is presently only used for the container's SHM directory.
149149
// These must be unmounted before the container's rootfs is unmounted.
150-
Mounts []string `json:"mounts,omitempty"`
150+
Mounts []define.InspectMount `json:"mounts,omitempty"`
151151
// NamedVolumes lists the Libpod named volumes to mount into the
152152
// container. Each named volume is guaranteed to exist so long as this
153153
// container exists.

libpod/container_inspect.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (c *Container) Inspect(size bool) (*define.InspectContainerData, error) {
5050
}
5151

5252
func (c *Container) volumesFrom() ([]string, error) {
53-
ctrSpec, err := c.specFromState()
53+
ctrSpec, err := c.SpecFromState()
5454
if err != nil {
5555
return nil, err
5656
}
@@ -63,7 +63,7 @@ func (c *Container) volumesFrom() ([]string, error) {
6363
func (c *Container) getContainerInspectData(size bool, driverData *define.DriverData) (*define.InspectContainerData, error) {
6464
config := c.config
6565
runtimeInfo := c.state
66-
ctrSpec, err := c.specFromState()
66+
ctrSpec, err := c.SpecFromState()
6767
if err != nil {
6868
return nil, err
6969
}
@@ -664,7 +664,7 @@ func (c *Container) inHostPidNS() (bool, error) {
664664
if c.config.PIDNsCtr != "" {
665665
return false, nil
666666
}
667-
ctrSpec, err := c.specFromState()
667+
ctrSpec, err := c.SpecFromState()
668668
if err != nil {
669669
return false, err
670670
}

libpod/container_internal.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ func (c *Container) processLabel(processLabel string) (string, error) {
575575
if !c.Systemd() && !c.ociRuntime.SupportsKVM() {
576576
return processLabel, nil
577577
}
578-
ctrSpec, err := c.specFromState()
578+
ctrSpec, err := c.SpecFromState()
579579
if err != nil {
580580
return "", err
581581
}
@@ -2068,7 +2068,7 @@ func (c *Container) cleanupStorage() error {
20682068
}
20692069

20702070
for _, containerMount := range c.config.Mounts {
2071-
if err := c.unmountSHM(containerMount); err != nil {
2071+
if err := c.unmountSHM(containerMount.Destination); err != nil {
20722072
reportErrorf("unmounting container %s: %w", c.ID(), err)
20732073
}
20742074
}
@@ -2870,7 +2870,7 @@ func (c *Container) update(updateOptions *entities.ContainerUpdateOptions) error
28702870
(updateOptions.Resources != nil || updateOptions.Env != nil || updateOptions.UnsetEnv != nil) {
28712871
// So `podman inspect` on running containers sources its OCI spec from disk.
28722872
// To keep inspect accurate we need to update the on-disk OCI spec.
2873-
onDiskSpec, err := c.specFromState()
2873+
onDiskSpec, err := c.SpecFromState()
28742874
if err != nil {
28752875
return fmt.Errorf("retrieving on-disk OCI spec to update: %w", err)
28762876
}

libpod/oci_conmon_exec_linux.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func (c *Container) setProcessCapabilitiesExec(options *ExecOptions, user string, execUser *user.ExecUser, pspec *spec.Process) error {
12-
ctrSpec, err := c.specFromState()
12+
ctrSpec, err := c.SpecFromState()
1313
if err != nil {
1414
return err
1515
}

libpod/runtime_ctr.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,13 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Contai
557557
return nil, fmt.Errorf("unable to create shm dir: %w", err)
558558
}
559559
}
560-
ctr.config.Mounts = append(ctr.config.Mounts, ctr.config.ShmDir)
560+
ctr.config.Mounts = append(ctr.config.Mounts, define.InspectMount{ // HERE I ADDED SOME DEFAULT VALUES. MUST THEY BE CHANGED? If yes, where should I take those values?
561+
Type: "bind", // default mount type
562+
Source: "/opt", // assuming source is same as destination, or set appropriately
563+
Destination: ctr.config.ShmDir, // the destination in the container
564+
RW: true, // default read/write setting
565+
Propagation: "rprivate", // default propagation
566+
})
561567
}
562568

563569
// Add the container to the state
@@ -1167,7 +1173,7 @@ func (r *Runtime) evictContainer(ctx context.Context, idOrName string, removeVol
11671173

11681174
// Unmount container mount points
11691175
for _, mount := range c.config.Mounts {
1170-
Unmount(mount)
1176+
Unmount(mount.Destination)
11711177
}
11721178

11731179
// Remove container from c/storage

pkg/domain/entities/types/container_ps.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"time"
55

66
netTypes "github.com/containers/common/libnetwork/types"
7+
pod_define "github.com/containers/podman/v5/libpod/define"
78
define "github.com/containers/podman/v5/pkg/ps/define"
89
)
910

@@ -41,7 +42,7 @@ type ListContainer struct {
4142
// Labels for container
4243
Labels map[string]string
4344
// User volume mounts
44-
Mounts []string
45+
Mounts []pod_define.InspectMount
4546
// The names assigned to the container
4647
Names []string
4748
// Namespaces the container belongs to. Requires the

pkg/ps/ps.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
psdefine "github.com/containers/podman/v5/pkg/ps/define"
2222
"github.com/containers/storage"
2323
"github.com/containers/storage/types"
24+
spec "github.com/opencontainers/runtime-spec/specs-go"
2425
"github.com/sirupsen/logrus"
2526
)
2627

@@ -153,6 +154,10 @@ func ListContainerBatch(rt *libpod.Runtime, ctr *libpod.Container, opts entities
153154
healthStatus string
154155
restartCount uint
155156
podName string
157+
ctrSpec *spec.Spec
158+
namedVolumes []*libpod.ContainerNamedVolume
159+
mounts []spec.Mount
160+
inspectMounts []define.InspectMount
156161
)
157162

158163
batchErr := ctr.Batch(func(c *libpod.Container) error {
@@ -206,6 +211,17 @@ func ListContainerBatch(rt *libpod.Runtime, ctr *libpod.Container, opts entities
206211
return err
207212
}
208213

214+
ctrSpec, err = c.SpecFromState()
215+
if err != nil {
216+
return err
217+
}
218+
219+
namedVolumes, mounts = c.SortUserVolumes(ctrSpec)
220+
inspectMounts, err = c.GetMounts(namedVolumes, conConfig.ImageVolumes, mounts)
221+
if err != nil {
222+
return err
223+
}
224+
209225
if opts.Namespace {
210226
ctrPID := strconv.Itoa(pid)
211227
cgroup, _ = getNamespaceInfo(filepath.Join("/proc", ctrPID, "ns", "cgroup"))
@@ -260,7 +276,7 @@ func ListContainerBatch(rt *libpod.Runtime, ctr *libpod.Container, opts entities
260276
ImageID: conConfig.RootfsImageID,
261277
IsInfra: conConfig.IsInfra,
262278
Labels: conConfig.Labels,
263-
Mounts: ctr.UserVolumes(),
279+
Mounts: inspectMounts,
264280
Names: []string{conConfig.Name},
265281
Networks: networks,
266282
Pid: pid,

pkg/specgen/generate/container.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ func ConfigToSpec(rt *libpod.Runtime, specg *specgen.SpecGenerator, containerID
333333
tmpMounts := conf.Mounts
334334

335335
conf.Systemd = nil
336-
conf.Mounts = []string{}
336+
conf.Mounts = []define.InspectMount{}
337337

338338
if specg == nil {
339339
specg = &specgen.SpecGenerator{}

0 commit comments

Comments
 (0)