-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drivers/quota.makeBackingFsDev(): use mknod+rename #1280
Conversation
Use mknod() followed by rename() to create the "backingFsBlockDev" device, instead of unlink() followed by mknod(), to remove the window where the node won't exist if we're just going to end up replacing it with an identical device node. Signed-off-by: Nalin Dahyabhai <[email protected]>
May be applicable to https://bugzilla.redhat.com/show_bug.cgi?id=2091214, but without knowing what removed /var/lib/containers/storage/overlay/backingFsBlockDev, we can't be sure. |
if err := unix.Mknod(backingFsBlockDevTmp, unix.S_IFBLK|0600, int(stat.Dev)); err != nil { | ||
return "", fmt.Errorf("Failed to mknod %s: %v", backingFsBlockDevTmp, err) | ||
} | ||
if err := unix.Rename(backingFsBlockDevTmp, backingFsBlockDev); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename is allowed over an existing device?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per rename(2), yes. We'll get EEXIST back if we're using renameat2() and with a RENAME_NOREPLACE flag.
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
if err := unix.Mknod(backingFsBlockDev, unix.S_IFBLK|0600, int(stat.Dev)); err != nil { | ||
return "", fmt.Errorf("Failed to mknod %s: %v", backingFsBlockDev, err) | ||
if err := unix.Mknod(backingFsBlockDevTmp, unix.S_IFBLK|0600, int(stat.Dev)); err != nil { | ||
return "", fmt.Errorf("Failed to mknod %s: %v", backingFsBlockDevTmp, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return "", fmt.Errorf("Failed to mknod %s: %v", backingFsBlockDevTmp, err) | |
return "", fmt.Errorf("failed to mknod %s: %w", backingFsBlockDevTmp, err) |
return "", fmt.Errorf("Failed to mknod %s: %v", backingFsBlockDevTmp, err) | ||
} | ||
if err := unix.Rename(backingFsBlockDevTmp, backingFsBlockDev); err != nil { | ||
return "", fmt.Errorf("Failed to rename %s to %s: %v", backingFsBlockDevTmp, backingFsBlockDev, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return "", fmt.Errorf("Failed to rename %s to %s: %v", backingFsBlockDevTmp, backingFsBlockDev, err) | |
return "", fmt.Errorf("failed to rename %s to %s: %w", backingFsBlockDevTmp, backingFsBlockDev, err) |
Use mknod() followed by rename() to create the "backingFsBlockDev" device, instead of unlink() followed by mknod(), to remove the window where the node won't exist if we're just going to end up replacing it with an identical device node.