Skip to content

Commit

Permalink
[release-1.45] quota: unlink tmp file before creating it
Browse files Browse the repository at this point in the history
Before creating the tmp file, we unlink it first to avoid an EEXIST
error.

Cherry Pick of befd147
Needed for Podman v4.4.1 backport.

Fixes: https://issues.redhat.com/browse/RHEL-3163

[NO NEW TESTS NEEDED]

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
  • Loading branch information
giuseppe authored and TomSweeneyRedHat committed Sep 12, 2023
1 parent 75e4c52 commit e7f5808
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions drivers/quota/projectquota.go
Expand Up @@ -424,8 +424,15 @@ func makeBackingFsDev(home string) (string, error) {
backingFsBlockDev := path.Join(home, "backingFsBlockDev")
backingFsBlockDevTmp := backingFsBlockDev + ".tmp"
// Re-create just in case someone copied the home directory over to a new device
if err := unix.Mknod(backingFsBlockDevTmp, unix.S_IFBLK|0600, int(stat.Dev)); err != nil {
return "", fmt.Errorf("failed to mknod %s: %w", backingFsBlockDevTmp, err)
if err := unix.Mknod(backingFsBlockDevTmp, unix.S_IFBLK|0o600, int(stat.Dev)); err != nil {
if !errors.Is(err, unix.EEXIST) {
return "", fmt.Errorf("failed to mknod %s: %w", backingFsBlockDevTmp, err)
}
// On EEXIST, try again after unlinking any potential leftover.
_ = unix.Unlink(backingFsBlockDevTmp)
if err := unix.Mknod(backingFsBlockDevTmp, unix.S_IFBLK|0o600, int(stat.Dev)); err != nil {
return "", fmt.Errorf("failed to mknod %s: %w", backingFsBlockDevTmp, err)
}
}
if err := unix.Rename(backingFsBlockDevTmp, backingFsBlockDev); err != nil {
return "", fmt.Errorf("failed to rename %s to %s: %w", backingFsBlockDevTmp, backingFsBlockDev, err)
Expand Down

0 comments on commit e7f5808

Please sign in to comment.