@@ -40,8 +40,7 @@ type mountConfig struct {
4040// mountEntry contains mount data specific to a mount point.
4141type mountEntry struct {
4242 * configs.Mount
43- srcFD * int
44- idmapFD int
43+ srcFD * int
4544}
4645
4746func (m * mountEntry ) src () string {
@@ -86,20 +85,19 @@ func prepareRootfs(pipe io.ReadWriter, iConfig *initConfig, mountFds mountFds) (
8685 cgroupns : config .Namespaces .Contains (configs .NEWCGROUP ),
8786 }
8887 for i , m := range config .Mounts {
89- entry := mountEntry {Mount : m , idmapFD : - 1 }
90- // Just before the loop we checked that if not empty, len(mountFds) == len(config.Mounts).
91- // Therefore, we can access mountFds[i] without any concerns.
88+ entry := mountEntry {Mount : m }
89+ // Just before the loop we checked that if not empty, len(mountFds.sourceFds ) == len(config.Mounts).
90+ // Therefore, we can access mountFds.sourceFds [i] without any concerns.
9291 if mountFds .sourceFds != nil && mountFds .sourceFds [i ] != - 1 {
9392 entry .srcFD = & mountFds .sourceFds [i ]
9493 }
9594
96- // We validated before we can access idmapFds[i].
95+ // We validated before we can access mountFds. idmapFds[i].
9796 if mountFds .idmapFds != nil && mountFds .idmapFds [i ] != - 1 {
98- entry .idmapFD = mountFds .idmapFds [i ]
99- }
100-
101- if entry .idmapFD != - 1 && entry .srcFD != nil {
102- return fmt .Errorf ("malformed mountFds and idmapFds slice, entry: %v has fds in both slices" , i )
97+ if entry .srcFD != nil {
98+ return fmt .Errorf ("malformed mountFds and idmapFds slice, entry: %v has fds in both slices" , i )
99+ }
100+ entry .srcFD = & mountFds .idmapFds [i ]
103101 }
104102
105103 if err := mountToRootfs (mountConfig , entry ); err != nil {
@@ -482,10 +480,10 @@ func mountToRootfs(c *mountConfig, m mountEntry) error {
482480 }
483481
484482 if m .IsBind () && m .IsIDMapped () {
485- if m .idmapFD == - 1 {
483+ if m .srcFD == nil {
486484 return fmt .Errorf ("error creating mount %+v: idmapFD is invalid, should point to a valid fd" , m )
487485 }
488- if err := unix .MoveMount (m . idmapFD , "" , - 1 , dest , unix .MOVE_MOUNT_F_EMPTY_PATH ); err != nil {
486+ if err := unix .MoveMount (* m . srcFD , "" , - 1 , dest , unix .MOVE_MOUNT_F_EMPTY_PATH ); err != nil {
489487 return fmt .Errorf ("error on unix.MoveMount %+v: %w" , m , err )
490488 }
491489
0 commit comments