Skip to content

Commit f6b91d7

Browse files
committed
inspect: Ignore character devices for IO limits
Cgroup block I/O limits cannot be applied to character devices. Ignore character devices in the inspect output. Update the API tests to use the null block device `/dev/nullb0` (if available) instead of `/dev/zero` for testing I/O limits. Signed-off-by: Giuseppe Scrivano <[email protected]>
1 parent 4e3226c commit f6b91d7

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

libpod/container_inspect.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ func (c *Container) GetDevices(priv bool, ctrSpec spec.Spec, deviceNodes map[str
653653
for _, dev := range ctrSpec.Linux.Devices {
654654
key := fmt.Sprintf("%d:%d", dev.Major, dev.Minor)
655655
if deviceNodes == nil {
656-
nodes, err := util.FindDeviceNodes()
656+
nodes, err := util.FindDeviceNodes(false)
657657
if err != nil {
658658
return nil, err
659659
}
@@ -678,7 +678,7 @@ func blkioDeviceThrottle(deviceNodes map[string]string, devs []spec.LinuxThrottl
678678
for _, dev := range devs {
679679
key := fmt.Sprintf("%d:%d", dev.Major, dev.Minor)
680680
if deviceNodes == nil {
681-
nodes, err := util.FindDeviceNodes()
681+
nodes, err := util.FindDeviceNodes(true)
682682
if err != nil {
683683
return nil, err
684684
}

libpod/container_inspect_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (c *Container) platformInspectContainerHostConfig(ctrSpec *spec.Spec, hostC
8989
continue
9090
}
9191
if deviceNodes == nil {
92-
nodes, err := util.FindDeviceNodes()
92+
nodes, err := util.FindDeviceNodes(true)
9393
if err != nil {
9494
return err
9595
}

pkg/util/utils_linux.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ func GetContainerPidInformationDescriptors() ([]string, error) {
3333
// [major:minor] is the device's major and minor numbers formatted as, for
3434
// example, 2:0 and path is the path to the device node.
3535
// Symlinks to nodes are ignored.
36-
func FindDeviceNodes() (map[string]string, error) {
36+
// If onlyBlockDevices is specified, character devices are ignored.
37+
func FindDeviceNodes(onlyBlockDevices bool) (map[string]string, error) {
3738
nodes := make(map[string]string)
3839
err := filepath.WalkDir("/dev", func(path string, d fs.DirEntry, err error) error {
3940
if err != nil {
@@ -44,7 +45,13 @@ func FindDeviceNodes() (map[string]string, error) {
4445
}
4546

4647
// If we aren't a device node, do nothing.
47-
if d.Type()&(os.ModeDevice|os.ModeCharDevice) == 0 {
48+
if d.Type()&os.ModeDevice == 0 {
49+
return nil
50+
}
51+
52+
// Ignore character devices, because it is not possible to set limits on them.
53+
// os.ModeCharDevice is usable only when os.ModeDevice is set.
54+
if onlyBlockDevices && d.Type()&os.ModeCharDevice != 0 {
4855
return nil
4956
}
5057

pkg/util/utils_unsupported.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ package util
55
import "errors"
66

77
// FindDeviceNodes is not implemented anywhere except Linux.
8-
func FindDeviceNodes() (map[string]string, error) {
8+
func FindDeviceNodes(onlyBlockDevices bool) (map[string]string, error) {
99
return nil, errors.New("not supported on non-Linux OSes")
1010
}

test/apiv2/20-containers.at

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -710,15 +710,15 @@ t GET libpod/containers/$cname/json 200 \
710710
.ImageName=$IMAGE \
711711
.Name=$cname
712712

713-
if root; then
713+
if root && test -e /dev/nullb0; then
714714
podman run -dt --name=updateCtr alpine
715715
echo '{
716716
"Memory":{"Limit":500000},
717717
"CPU":{"Shares":123},
718-
"DeviceReadBPs": [{ "Path": "/dev/zero", "Rate": 10485760 }],
719-
"DeviceWriteBPs": [{ "Path": "/dev/zero", "Rate": 31457280 }],
720-
"DeviceReadIOPs": [{ "Path": "/dev/zero", "Rate": 2000 }],
721-
"DeviceWriteIOPs": [{ "Path": "/dev/zero", "Rate": 4000 }]
718+
"DeviceReadBPs": [{ "Path": "/dev/nullb0", "Rate": 10485760 }],
719+
"DeviceWriteBPs": [{ "Path": "/dev/nullb0", "Rate": 31457280 }],
720+
"DeviceReadIOPs": [{ "Path": "/dev/nullb0", "Rate": 2000 }],
721+
"DeviceWriteIOPs": [{ "Path": "/dev/nullb0", "Rate": 4000 }]
722722
}' >${TMPD}/update.json
723723
t POST libpod/containers/updateCtr/update ${TMPD}/update.json 201
724724

@@ -734,25 +734,25 @@ if root; then
734734

735735
BlkioDeviceReadBps_expected='[
736736
{
737-
"Path": "/dev/zero",
737+
"Path": "/dev/nullb0",
738738
"Rate": 10485760
739739
}
740740
]'
741741
BlkioDeviceWriteBPs_expected='[
742742
{
743-
"Path": "/dev/zero",
743+
"Path": "/dev/nullb0",
744744
"Rate": 31457280
745745
}
746746
]'
747747
BlkioDeviceReadIOPs_expected='[
748748
{
749-
"Path": "/dev/zero",
749+
"Path": "/dev/nullb0",
750750
"Rate": 2000
751751
}
752752
]'
753753
BlkioDeviceWriteIOPs_expected='[
754754
{
755-
"Path": "/dev/zero",
755+
"Path": "/dev/nullb0",
756756
"Rate": 4000
757757
}
758758
]'

0 commit comments

Comments
 (0)