@@ -45,13 +45,15 @@ func updateSandboxMounts(sbid string, spec *oci.Spec) error {
4545 var sandboxSource string
4646 // if using `sandbox-tmp://` prefix, we mount a tmpfs in sandboxTmpfsMountsDir
4747 if strings .HasPrefix (m .Source , guestpath .SandboxTmpfsMountPrefix ) {
48- sandboxSource = specGuest .SandboxTmpfsMountSource (sbid , m .Source )
48+ // Use virtual pod aware mount source
49+ sandboxSource = specGuest .VirtualPodAwareSandboxTmpfsMountSource (sbid , virtualSandboxID , m .Source )
50+ expectedMountsDir := specGuest .VirtualPodAwareSandboxTmpfsMountsDir (sbid , virtualSandboxID )
51+
4952 // filepath.Join cleans the resulting path before returning, so it would resolve the relative path if one was given.
5053 // Hence, we need to ensure that the resolved path is still under the correct directory
51- if ! strings .HasPrefix (sandboxSource , specGuest . SandboxTmpfsMountsDir ( sbid ) ) {
52- return errors .Errorf ("mount path %v for mount %v is not within sandboxTmpfsMountsDir " , sandboxSource , m .Source )
54+ if ! strings .HasPrefix (sandboxSource , expectedMountsDir ) {
55+ return errors .Errorf ("mount path %v for mount %v is not within sandbox's tmpfs mounts dir " , sandboxSource , m .Source )
5356 }
54-
5557 } else {
5658 // Use virtual pod aware mount source
5759 sandboxSource = specGuest .VirtualPodAwareSandboxMountSource (sbid , virtualSandboxID , m .Source )
@@ -81,29 +83,31 @@ func updateHugePageMounts(sbid string, spec *oci.Spec) error {
8183 virtualSandboxID := spec .Annotations [annotations .VirtualPodID ]
8284
8385 for i , m := range spec .Mounts {
84- if strings .HasPrefix (m .Source , guestpath .HugePagesMountPrefix ) {
85- // Use virtual pod aware hugepages directory
86- mountsDir := specGuest .VirtualPodAwareHugePagesMountsDir (sbid , virtualSandboxID )
87- subPath := strings .TrimPrefix (m .Source , guestpath .HugePagesMountPrefix )
88- pageSize := strings .Split (subPath , string (os .PathSeparator ))[0 ]
89- hugePageMountSource := filepath .Join (mountsDir , subPath )
90-
91- // filepath.Join cleans the resulting path before returning so it would resolve the relative path if one was given.
92- // Hence, we need to ensure that the resolved path is still under the correct directory
93- if ! strings .HasPrefix (hugePageMountSource , mountsDir ) {
94- return errors .Errorf ("mount path %v for mount %v is not within hugepages's mounts dir" , hugePageMountSource , m .Source )
95- }
86+ if ! strings .HasPrefix (m .Source , guestpath .HugePagesMountPrefix ) {
87+ continue
88+ }
89+
90+ // Use virtual pod aware hugepages directory
91+ mountsDir := specGuest .VirtualPodAwareHugePagesMountsDir (sbid , virtualSandboxID )
92+ subPath := strings .TrimPrefix (m .Source , guestpath .HugePagesMountPrefix )
93+ pageSize := strings .Split (subPath , string (os .PathSeparator ))[0 ]
94+ hugePageMountSource := filepath .Join (mountsDir , subPath )
95+
96+ // filepath.Join cleans the resulting path before returning so it would resolve the relative path if one was given.
97+ // Hence, we need to ensure that the resolved path is still under the correct directory
98+ if ! strings .HasPrefix (hugePageMountSource , mountsDir ) {
99+ return errors .Errorf ("mount path %v for mount %v is not within hugepages's mounts dir" , hugePageMountSource , m .Source )
100+ }
96101
97- spec .Mounts [i ].Source = hugePageMountSource
102+ spec .Mounts [i ].Source = hugePageMountSource
98103
99- _ , err := os .Stat (hugePageMountSource )
100- if os .IsNotExist (err ) {
101- if err := mkdirAllModePerm (hugePageMountSource ); err != nil {
102- return err
103- }
104- if err := unix .Mount ("none" , hugePageMountSource , "hugetlbfs" , 0 , "pagesize=" + pageSize ); err != nil {
105- return errors .Errorf ("mount operation failed for %v failed with error %v" , hugePageMountSource , err )
106- }
104+ _ , err := os .Stat (hugePageMountSource )
105+ if os .IsNotExist (err ) {
106+ if err := mkdirAllModePerm (hugePageMountSource ); err != nil {
107+ return err
108+ }
109+ if err := unix .Mount ("none" , hugePageMountSource , "hugetlbfs" , 0 , "pagesize=" + pageSize ); err != nil {
110+ return errors .Errorf ("mount operation failed for %v failed with error %v" , hugePageMountSource , err )
107111 }
108112 }
109113 }
0 commit comments