@@ -40,13 +40,13 @@ type mountConfig struct {
4040// mountEntry contains mount data specific to a mount point.
4141type mountEntry struct {
4242 * configs.Mount
43- srcFD string
43+ srcFD * int
4444 idmapFD int
4545}
4646
4747func (m * mountEntry ) src () string {
48- if m .srcFD != "" {
49- return m .srcFD
48+ if m .srcFD != nil {
49+ return "/proc/self/fd/" + strconv . Itoa ( * m .srcFD )
5050 }
5151 return m .Source
5252}
@@ -90,15 +90,15 @@ func prepareRootfs(pipe io.ReadWriter, iConfig *initConfig, mountFds mountFds) (
9090 // Just before the loop we checked that if not empty, len(mountFds) == len(config.Mounts).
9191 // Therefore, we can access mountFds[i] without any concerns.
9292 if mountFds .sourceFds != nil && mountFds .sourceFds [i ] != - 1 {
93- entry .srcFD = "/proc/self/fd/" + strconv . Itoa ( mountFds .sourceFds [i ])
93+ entry .srcFD = & mountFds .sourceFds [i ]
9494 }
9595
9696 // We validated before we can access idmapFds[i].
9797 if mountFds .idmapFds != nil && mountFds .idmapFds [i ] != - 1 {
9898 entry .idmapFD = mountFds .idmapFds [i ]
9999 }
100100
101- if entry .idmapFD != - 1 && entry .srcFD != "" {
101+ if entry .idmapFD != - 1 && entry .srcFD != nil {
102102 return fmt .Errorf ("malformed mountFds and idmapFds slice, entry: %v has fds in both slices" , i )
103103 }
104104
@@ -297,7 +297,7 @@ func mountCgroupV1(m *configs.Mount, c *mountConfig) error {
297297 data = cgroups .CgroupNamePrefix + data
298298 source = "systemd"
299299 }
300- return mountViaFDs (source , "" , b .Destination , dstFD , "cgroup" , uintptr (flags ), data )
300+ return mountViaFDs (source , nil , b .Destination , dstFD , "cgroup" , uintptr (flags ), data )
301301 }); err != nil {
302302 return err
303303 }
@@ -329,7 +329,7 @@ func mountCgroupV2(m *configs.Mount, c *mountConfig) error {
329329 return err
330330 }
331331 err = utils .WithProcfd (c .root , m .Destination , func (dstFD string ) error {
332- return mountViaFDs (m .Source , "" , m .Destination , dstFD , "cgroup2" , uintptr (m .Flags ), m .Data )
332+ return mountViaFDs (m .Source , nil , m .Destination , dstFD , "cgroup2" , uintptr (m .Flags ), m .Data )
333333 })
334334 if err == nil || ! (errors .Is (err , unix .EPERM ) || errors .Is (err , unix .EBUSY )) {
335335 return err
@@ -403,7 +403,7 @@ func doTmpfsCopyUp(m mountEntry, rootfs, mountLabel string) (Err error) {
403403 return fmt .Errorf ("tmpcopyup: failed to copy %s to %s (%s): %w" , m .Destination , dstFD , tmpDir , err )
404404 }
405405 // Now move the mount into the container.
406- if err := mountViaFDs (tmpDir , "" , m .Destination , dstFD , "" , unix .MS_MOVE , "" ); err != nil {
406+ if err := mountViaFDs (tmpDir , nil , m .Destination , dstFD , "" , unix .MS_MOVE , "" ); err != nil {
407407 return fmt .Errorf ("tmpcopyup: failed to move mount: %w" , err )
408408 }
409409 return nil
@@ -497,7 +497,7 @@ func mountToRootfs(c *mountConfig, m mountEntry) error {
497497 // system type and data arguments are ignored:
498498 // https://man7.org/linux/man-pages/man2/mount.2.html
499499 // We also ignore procfd because we want to act on dest.
500- if err := mountViaFDs ("" , "" , dest , dstFD , "" , uintptr (pflag ), "" ); err != nil {
500+ if err := mountViaFDs ("" , nil , dest , dstFD , "" , uintptr (pflag ), "" ); err != nil {
501501 return err
502502 }
503503 }
@@ -733,7 +733,7 @@ func bindMountDeviceNode(rootfs, dest string, node *devices.Device) error {
733733 _ = f .Close ()
734734 }
735735 return utils .WithProcfd (rootfs , dest , func (dstFD string ) error {
736- return mountViaFDs (node .Path , "" , dest , dstFD , "bind" , unix .MS_BIND , "" )
736+ return mountViaFDs (node .Path , nil , dest , dstFD , "bind" , unix .MS_BIND , "" )
737737 })
738738}
739739
@@ -1154,7 +1154,7 @@ func mountPropagate(m mountEntry, rootfs string, mountLabel string) error {
11541154 // target needs to be re-opened.
11551155 if err := utils .WithProcfd (rootfs , m .Destination , func (dstFD string ) error {
11561156 for _ , pflag := range m .PropagationFlags {
1157- if err := mountViaFDs ("" , "" , m .Destination , dstFD , "" , uintptr (pflag ), "" ); err != nil {
1157+ if err := mountViaFDs ("" , nil , m .Destination , dstFD , "" , uintptr (pflag ), "" ); err != nil {
11581158 return err
11591159 }
11601160 }
0 commit comments