@@ -446,7 +446,7 @@ func (c *Container) setContainerState(state types.StateString) error {
446446 return nil
447447}
448448
449- func (c * Container ) shareFiles (m Mount , idx int , hostSharedDir , guestSharedDir string ) (string , bool , error ) {
449+ func (c * Container ) shareFiles (m Mount , idx int , hostSharedDir , hostMountDir , guestSharedDir string ) (string , bool , error ) {
450450 randBytes , err := utils .GenerateRandomBytes (8 )
451451 if err != nil {
452452 return "" , false , err
@@ -480,12 +480,19 @@ func (c *Container) shareFiles(m Mount, idx int, hostSharedDir, guestSharedDir s
480480 }
481481 } else {
482482 // These mounts are created in the shared dir
483- mountDest := filepath .Join (hostSharedDir , filename )
484- if err := bindMount (c .ctx , m .Source , mountDest , false , "private" ); err != nil {
483+ mountDest := filepath .Join (hostMountDir , filename )
484+ if err := bindMount (c .ctx , m .Source , mountDest , m . ReadOnly , "private" ); err != nil {
485485 return "" , false , err
486486 }
487487 // Save HostPath mount value into the mount list of the container.
488488 c .mounts [idx ].HostPath = mountDest
489+ // bindmount remount event is not propagated to mount subtrees, so we have to remount the shared dir mountpoint directly.
490+ if m .ReadOnly {
491+ mountDest = filepath .Join (hostSharedDir , filename )
492+ if err := remountRo (c .ctx , mountDest ); err != nil {
493+ return "" , false , err
494+ }
495+ }
489496 }
490497
491498 return guestDest , false , nil
@@ -496,7 +503,7 @@ func (c *Container) shareFiles(m Mount, idx int, hostSharedDir, guestSharedDir s
496503// It also updates the container mount list with the HostPath info, and store
497504// container mounts to the storage. This way, we will have the HostPath info
498505// available when we will need to unmount those mounts.
499- func (c * Container ) mountSharedDirMounts (hostSharedDir , guestSharedDir string ) (sharedDirMounts map [string ]Mount , ignoredMounts map [string ]Mount , err error ) {
506+ func (c * Container ) mountSharedDirMounts (hostSharedDir , hostMountDir , guestSharedDir string ) (sharedDirMounts map [string ]Mount , ignoredMounts map [string ]Mount , err error ) {
500507 sharedDirMounts = make (map [string ]Mount )
501508 ignoredMounts = make (map [string ]Mount )
502509 var devicesToDetach []string
@@ -546,7 +553,7 @@ func (c *Container) mountSharedDirMounts(hostSharedDir, guestSharedDir string) (
546553
547554 var ignore bool
548555 var guestDest string
549- guestDest , ignore , err = c .shareFiles (m , idx , hostSharedDir , guestSharedDir )
556+ guestDest , ignore , err = c .shareFiles (m , idx , hostSharedDir , hostMountDir , guestSharedDir )
550557 if err != nil {
551558 return nil , nil , err
552559 }
@@ -557,22 +564,12 @@ func (c *Container) mountSharedDirMounts(hostSharedDir, guestSharedDir string) (
557564 continue
558565 }
559566
560- // Check if mount is readonly, let the agent handle the readonly mount
561- // within the VM.
562- readonly := false
563- for _ , flag := range m .Options {
564- if flag == "ro" {
565- readonly = true
566- break
567- }
568- }
569-
570567 sharedDirMount := Mount {
571568 Source : guestDest ,
572569 Destination : m .Destination ,
573570 Type : m .Type ,
574571 Options : m .Options ,
575- ReadOnly : readonly ,
572+ ReadOnly : m . ReadOnly ,
576573 }
577574
578575 sharedDirMounts [sharedDirMount .Destination ] = sharedDirMount
0 commit comments