bugfix: fetch the right device number which great than 255#39212
bugfix: fetch the right device number which great than 255#39212cpuguy83 merged 1 commit intomoby:masterfrom
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
There was a problem hiding this comment.
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.
Also, make sense to use
t.Parallel()
daemon/daemon_unix_test.go
Outdated
daemon/daemon_unix_test.go
Outdated
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
s/"tempDevDirForBlkioThrottleDevices"/t.Name()/
There was a problem hiding this comment.
or, if you like it more, "tempDevDir"+t.Name()
daemon/daemon_unix_test.go
Outdated
There was a problem hiding this comment.
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. |
kolyshkin
left a comment
There was a problem hiding this comment.
LGTM, thanks for good work!
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 devicethe container has config
"BlkioDeviceReadBps":[{"Path":"/dev/vdt","Rate":0}]and I foud
stat /dev/vdtandls -l /dev/vdthas 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_devin 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)