Skip to content

Commit 1b3bb5d

Browse files
committed
Recursively set project ID for quota driver
We have previously relied on the PROJINHERIT flag for XFS quotas, which causes the ID of the parent directory to be recursively applied to subdirectories under the volume's parent directory. However, PROJINHERIT only applies to directories created after the project ID was first set. Pre-existing directories do not get the project ID if we only set it on the parent. This means that quota enforcement is not complete unless we recurse to subdirectories and apply the project ID to those as well. Fixes containers/podman#25368 Signed-off-by: Matt Heon <[email protected]>
1 parent 3a013da commit 1b3bb5d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

drivers/quota/projectquota_supported.go

+14
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,20 @@ func setProjectID(targetPath string, projectID uint32) error {
370370
return fmt.Errorf("failed to set projid for %s: %w", targetPath, errno)
371371
}
372372

373+
// While we are setting the PROJINHERIT flag, it only applies to files
374+
// and directories created after the fact.
375+
// Any pre-existing subdirectories will still need to have the project
376+
// ID set manually, so recurse onto them.
377+
if dents, err := os.Readdir(targetPath); err == nil {
378+
for _, dent := range dents {
379+
if dent.IsDir() {
380+
if err := setProjectID(filepath.Join(targetPath, dent.Name()), projectID); err != nil {
381+
return fmt.Errorf("recursively setting project ID on subdirectories of %s: %w", targetPath, err)
382+
}
383+
}
384+
}
385+
}
386+
373387
return nil
374388
}
375389

0 commit comments

Comments
 (0)