Skip to content

Commit

Permalink
Merge pull request #1710 from TomSweeneyRedHat/dev/tsweeney/unlinkcherry
Browse files Browse the repository at this point in the history
[release-1.45] quota: unlink tmp file before creating it
  • Loading branch information
rhatdan authored Sep 14, 2023
2 parents 75e4c52 + a3b0bfa commit e52057c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.45.6-dev
1.45.7-dev
11 changes: 9 additions & 2 deletions drivers/quota/projectquota.go
Original file line number Diff line number Diff line change
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 e52057c

Please sign in to comment.