Skip to content

mount: setupLoop() doesn't work with with Autoclear#4991

Merged
dmcgowan merged 1 commit intocontainerd:masterfrom
kzys:no-auto-clear
Feb 4, 2021
Merged

mount: setupLoop() doesn't work with with Autoclear#4991
dmcgowan merged 1 commit intocontainerd:masterfrom
kzys:no-auto-clear

Conversation

@kzys
Copy link
Copy Markdown
Member

@kzys kzys commented Feb 2, 2021

setupLoop()'s Autoclear (LO_FLAGS_AUTOCLEAR) will destruct the
loopback device when all FDs are closed.

However since setupLoop() returns a file name, not a file handle,
the looppack device will be destructed at the end of the function all the time.

Signed-off-by: Kazuyoshi Kato [email protected]

@k8s-ci-robot
Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@kzys
Copy link
Copy Markdown
Member Author

kzys commented Feb 2, 2021

If my theory is right, we may need to fix setupLoop() rather than the callers.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Feb 2, 2021

Build succeeded.

@kzys kzys requested a review from mxpv February 2, 2021 23:13
@mxpv
Copy link
Copy Markdown
Member

mxpv commented Feb 2, 2021

However since setupLoop() returns a file name, not a file handle,
the looppack device will be destructed at the end of the function all the time.

Should we return a file handle from setupLoop then? I guess in the current form setupLoop with autoclear flag is broken?

@kzys
Copy link
Copy Markdown
Member Author

kzys commented Feb 2, 2021

It seems broken and I think we should return a file handle. Autoclear translated to LO_FLAGS_AUTOCLEAR, which destructs a loopback device on its last close.

https://man7.org/linux/man-pages/man4/loop.4.html

              LO_FLAGS_AUTOCLEAR (since Linux 2.6.25)
                     The loopback device will autodestruct on last
                     close.

However, since setupLoop() is returning a file name, the function should close all file handles at the end. Otherwise, a file descriptor will be leaked. But that means the loopback device will be destructed at the end of the function.

@kzys
Copy link
Copy Markdown
Member Author

kzys commented Feb 3, 2021

I've added a new commit. I would squash them together tomorrow PST if others don't mind.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Feb 3, 2021

Build succeeded.

@kzys kzys force-pushed the no-auto-clear branch 2 times, most recently from 483c234 to cd9e32f Compare February 3, 2021 17:40
@kzys kzys marked this pull request as ready for review February 3, 2021 17:42
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Feb 3, 2021

Build succeeded.

Copy link
Copy Markdown
Member

@estesp estesp left a comment

Choose a reason for hiding this comment

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

LGTM

Comment thread mount/losetup_linux.go Outdated
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.

Are the devmapper tests which use this still going to run into issues using the loop device?

Copy link
Copy Markdown
Member Author

@kzys kzys Feb 3, 2021

Choose a reason for hiding this comment

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

Since LoopParams doesn't have Autoclear here, closing the file won't destruct the loopback device.

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.

OK, I guess we can separate that some. I thought we were still seeing some related issues on devmapper. In this case, could/should it just return the file with autoclear to avoid detach? If there are no leaks there though that might not help the running out of loop devices issues there.

Comment thread mount/losetup_linux.go Outdated
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.

nit: typo (fo instead of for)

not a blocker, just in case other changes are needed before merge

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.

Ah right. Will fix.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Feb 3, 2021

Build succeeded.

setupLoop()'s Autoclear (LO_FLAGS_AUTOCLEAR) will destruct the
loopback device when all associated file descriptors are closed.

However this behavior didn't work before since setupLoop() was
returning a file name. The looppack device was destructed at
the end of the function when LoopParams had Autoclear = true.

Fixes containerd#4969.

Signed-off-by: Kazuyoshi Kato <[email protected]>
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Feb 4, 2021

Build succeeded.

@kzys
Copy link
Copy Markdown
Member Author

kzys commented Feb 4, 2021

Note that this change only affects Linux and the failing test is on Windows.

Copy link
Copy Markdown
Member

@dmcgowan dmcgowan left a comment

Choose a reason for hiding this comment

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

LGTM

@dmcgowan dmcgowan merged commit ccbeb55 into containerd:master Feb 4, 2021
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.

6 participants