Skip to content
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

Merged
merged 1 commit into from
Jul 8, 2022

Conversation

nalind
Copy link
Member

@nalind nalind commented Jul 5, 2022

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.

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]>
@nalind
Copy link
Member Author

nalind commented Jul 5, 2022

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 {
Copy link
Member

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?

Copy link
Member Author

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.

@rhatdan
Copy link
Member

rhatdan commented Jul 8, 2022

LGTM
@giuseppe @saschagrunert @vrothberg @flouthoc PTAL

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vrothberg vrothberg merged commit f048afd into containers:main Jul 8, 2022
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)

@nalind nalind deleted the create-quota-using-rename branch July 14, 2022 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants