Skip to content

Conversation

@ZhangShuaiyi
Copy link
Contributor

@ZhangShuaiyi ZhangShuaiyi commented Oct 30, 2023

After run TestRwLoop, there will leave a /dev/loopX not removed.

	file, err := setupLoop(backingFile, LoopParams{Autoclear: false})

Autoclear is false in TestRwLoop, so /dev/loopX will not be cleared automatically.

[root@containerddev containerd]# losetup
[root@containerddev containerd]# go test -v github.com/containerd/containerd/mount -test.root -run TestRwLoop
=== RUN   TestRwLoop
--- PASS: TestRwLoop (0.02s)
PASS
ok      github.com/containerd/containerd/mount  0.026s
[root@containerddev containerd]# losetup
NAME       SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE                        DIO LOG-SEC
/dev/loop0         0      0         0  0 /tmp/losetup1667762043 (deleted)   0     512
[root@containerddev containerd]# go test -v github.com/containerd/containerd/mount -test.root -run TestRwLoop
=== RUN   TestRwLoop
--- PASS: TestRwLoop (0.00s)
PASS
ok      github.com/containerd/containerd/mount  0.012s
[root@containerddev containerd]# losetup
NAME       SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE                        DIO LOG-SEC
/dev/loop1         0      0         0  0 /tmp/losetup473965374 (deleted)    0     512
/dev/loop0         0      0         0  0 /tmp/losetup1667762043 (deleted)   0     512
[root@containerddev containerd]# losetup -d /dev/loop0
[root@containerddev containerd]# losetup -d /dev/loop1
[root@containerddev containerd]# losetup
[root@containerddev containerd]#

Defer call removeLoop to remove loop device at end.

[root@containerddev containerd]# go test -v github.com/containerd/containerd/mount -test.root -run TestRwLoop
=== RUN   TestRwLoop
--- PASS: TestRwLoop (0.00s)
PASS
ok      github.com/containerd/containerd/mount  0.013s
[root@containerddev containerd]# losetup
[root@containerddev containerd]#

@k8s-ci-robot
Copy link

Hi @ZhangShuaiyi. Thanks for your PR.

I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@estesp
Copy link
Member

estesp commented Oct 30, 2023

This looks like a good cleanup; can you please sign your commit according to our guidance here: https://github.com/containerd/project/blob/main/CONTRIBUTING.md#sign-your-work

Copy link
Member

@austinvazquez austinvazquez left a comment

Choose a reason for hiding this comment

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

Comment on lines 89 to 95
defer func() {
dev := file.Name()
file.Close()
if err := removeLoop(dev); err != nil {
t.Fatal(err)
}
}()
Copy link
Member

Choose a reason for hiding this comment

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

Alternatively, for conciseness should the solution be to just use Autoclear: true similar toTestRoLoop?

Copy link
Contributor Author

@ZhangShuaiyi ZhangShuaiyi Oct 30, 2023

Choose a reason for hiding this comment

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

@austinvazquez How about using Autoclear: ture in TestRwLoop, and add a new test case for Autoclear: false?

Copy link
Member

Choose a reason for hiding this comment

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

+1, yeah it was not clear before that TestRwLoop was intended to test Autoclear: false. The tests you have added are much more intentional. Thanks.

@ZhangShuaiyi
Copy link
Contributor Author

ZhangShuaiyi commented Oct 30, 2023

@estesp Thanks, I will add a DCO later

@ZhangShuaiyi ZhangShuaiyi force-pushed the fix/TestRwLoop branch 3 times, most recently from a3a25cb to f111733 Compare October 30, 2023 16:24
@henry118
Copy link
Member

/ok-to-test

@k8s-ci-robot
Copy link

@henry118: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/ok-to-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link
Contributor Author

@ZhangShuaiyi ZhangShuaiyi left a comment

Choose a reason for hiding this comment

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

Run 10 times TestAutoclearTrueLoop in a 1C4G vm. TestAutoclearTrueLoop not always pass.

root@ubuntu2004:~/containerd# uname -a
Linux ubuntu2004 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
root@ubuntu2004:~/containerd# nproc
1
root@ubuntu2004:~/containerd# go test -count 10 github.com/containerd/containerd/mount -test.root -run TestAutoclearTrueLoop
--- FAIL: TestAutoclearTrueLoop (0.01s)
    losetup_linux_test.go:136: removeLoop should fail if Autoclear is true
--- FAIL: TestAutoclearTrueLoop (0.03s)
    losetup_linux_test.go:136: removeLoop should fail if Autoclear is true
--- FAIL: TestAutoclearTrueLoop (0.01s)
    losetup_linux_test.go:136: removeLoop should fail if Autoclear is true
--- FAIL: TestAutoclearTrueLoop (0.02s)
    losetup_linux_test.go:136: removeLoop should fail if Autoclear is true
FAIL
FAIL    github.com/containerd/containerd/mount  0.254s
FAIL

@ZhangShuaiyi
Copy link
Contributor Author

Loop deivce's autoclear is asynchronous. __loop_clr_fd was called in lo_release when Autoclear: true.
After add a 100ms sleep in TestAutoclearTrueLoop to wait loop device autoclear, the TestAutoclearTrueLoop can always be passed.

root@ubuntu2004:~/containerd# go test -count 100 github.com/containerd/containerd/mount -test.root -run TestAutoclearTrueLoop
ok      github.com/containerd/containerd/mount  11.218s

@ZhangShuaiyi ZhangShuaiyi force-pushed the fix/TestRwLoop branch 2 times, most recently from 21a4d44 to c4a447b Compare October 31, 2023 04:52
@henry118
Copy link
Member

@ZhangShuaiyi mind squashing your commits? the changes lgtm

@ZhangShuaiyi
Copy link
Contributor Author

@henry118 Squashed, thanks!

@ZhangShuaiyi
Copy link
Contributor Author

/retest

@estesp estesp added this pull request to the merge queue Nov 1, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 1, 2023
@estesp estesp added this pull request to the merge queue Nov 1, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 1, 2023
@estesp estesp added this pull request to the merge queue Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants