Skip to content

drivers/quota.makeBackingFsDev(): use mknod+rename#1280

Merged
vrothberg merged 1 commit intocontainers:mainfrom
nalind:create-quota-using-rename
Jul 8, 2022
Merged

drivers/quota.makeBackingFsDev(): use mknod+rename#1280
vrothberg merged 1 commit intocontainers:mainfrom
nalind:create-quota-using-rename

Conversation

@nalind
Copy link
Copy Markdown
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 <nalin@redhat.com>
@nalind
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

rhatdan commented Jul 8, 2022

LGTM
@giuseppe @saschagrunert @vrothberg @flouthoc PTAL

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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