-
Notifications
You must be signed in to change notification settings - Fork 18.7k
bugfix: fetch the right device number which great than 255 #39212
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
Conversation
(reserved for my derek commands) |
@yyb196 congrats of your first PR to moby 🎂 I'm not familiar this this feature so just to verify that did you test that those unit tests would fail without this fix? |
ping @kolyshkin PTAL |
Looks fine, but since x/sys/unix already implemented these, it'll be better to use those. In other words: import "golang.org/x/sys/unix"
...
d.Major = unix.Major(stat.Rdev)
d.Minor = unix.Minor(stat.Rdev) @yyb196 can you please update this PR? |
Codecov Report
@@ Coverage Diff @@
## master #39212 +/- ##
=========================================
Coverage ? 37.06%
=========================================
Files ? 612
Lines ? 45494
Branches ? 0
=========================================
Hits ? 16862
Misses ? 26344
Partials ? 2288 |
@kolyshkin @olljanat I have change the code and test case according to your advices. PTALA, thanks a lot. Using the unix package's methods And now the unit test case that I add will fail without this fix. Because I don't know how to mock system call in go, my test case depends on that we can do |
daemon/daemon_unix_test.go
Outdated
@@ -376,3 +379,75 @@ func sysInfo(t *testing.T, opts ...func(*sysinfo.SysInfo)) sysinfo.SysInfo { | |||
} | |||
return si | |||
} | |||
|
|||
func TestGetBlkioWeightDevices(t *testing.T) { |
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.
mknod
requires root, so this test case should have something like
if os.Getuid() != 0 {
t.Skip("root required") // for mknod
}
at the very beginning (so if someone runs go test
as non-root, there won't be a fake failure).
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.
Also, make sense to use
t.Parallel()
daemon/daemon_unix_test.go
Outdated
|
||
// mock a file with major 0x1FD(509 in decimal) and minor 0x130(304) | ||
if err = unix.Mknod(tempFile, unix.S_IFCHR, 0x11FD30); err != nil { | ||
t.Fatalf("mknode error %s(%x): %v", tempFile, 0x11FD30, 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.
s/mknode/mknod/
daemon/daemon_unix_test.go
Outdated
defer os.RemoveAll(tempDir) | ||
|
||
// mock a file with major 0x1FD(509 in decimal) and minor 0x130(304) | ||
if err = unix.Mknod(tempFile, unix.S_IFCHR, 0x11FD30); 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.
You can use unix.Mkdev(major, minor)
(and define major
and minor
as constants to not have some "magic numbers" across the code.
daemon/daemon_unix_test.go
Outdated
weightDevs, err := getBlkioWeightDevices(mockResource) | ||
assert.NilError(t, err, "getBlkioWeightDevices") | ||
|
||
if len(weightDevs) != 1 { |
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.
assert.Check(t, is.Len(weightDevs, 1), "getBlkioWeightDevices")
(you can use assert
in other places in your code as well, it makes the code more compact and perhaps more readable)
daemon/daemon_unix_test.go
Outdated
@@ -376,3 +379,75 @@ func sysInfo(t *testing.T, opts ...func(*sysinfo.SysInfo)) sysinfo.SysInfo { | |||
} | |||
return si | |||
} | |||
|
|||
func TestGetBlkioWeightDevices(t *testing.T) { | |||
tempDir, err := ioutil.TempDir("", "tempDevDirForBlkioThrottleDevices") |
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.
s/"tempDevDirForBlkioThrottleDevices"/t.Name()/
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.
or, if you like it more, "tempDevDir"+t.Name()
daemon/daemon_unix_test.go
Outdated
} | ||
} | ||
|
||
func TestGetBlkioThrottleDevices(t *testing.T) { |
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.
This second test is the same as the first one, except for function called. Can you please combine the code so it won't repeat twice?
@yyb196 thanks so much for the update! I have left some comments |
Signed-off-by: frankyang <yyb196@gmail.com>
@kolyshkin thanks for your comments, I have updated. PTALA. |
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, thanks for good work!
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, thanks!
Signed-off-by: frankyang yyb196@gmail.com
- What I did
fix a bug which cause an error like :
write 4349:48 0 to blkio.throttle.read_bps_device: write /sys/fs/cgroup/blkio/xxx/cid/blkio.throttle.read_bps_device: no such device
the container has config
"BlkioDeviceReadBps":[{"Path":"/dev/vdt","Rate":0}]
and I foud
stat /dev/vdt
andls -l /dev/vdt
has different out of device number, which is correct:Someone in docker forum ran into the same problem: https://forums.docker.com/t/docker-run-device-read-bps-option-not-working/68044 in his case is the major number greater than 255.
- How I did it
I correct the way in which we get major and minor device number according to the method
new_encode_dev
in linux kernel.- How to verify it
I add two unit test cases.
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)