blkioTestDevice finds a usable block device on the host by examining the device backing the root filesystem. The returned path (e.g. "/dev/sda") and the decimal major:minor string are suitable for docker update flags and cgroup file lookups respectively.
(t *testing.T)
| 223 | // and the decimal major:minor string are suitable for docker update flags and |
| 224 | // cgroup file lookups respectively. |
| 225 | func blkioTestDevice(t *testing.T) (devPath, majMin string) { |
| 226 | t.Helper() |
| 227 | |
| 228 | var st unix.Stat_t |
| 229 | assert.NilError(t, unix.Stat("/", &st), "stat /") |
| 230 | |
| 231 | major := unix.Major(st.Dev) |
| 232 | minor := unix.Minor(st.Dev) |
| 233 | |
| 234 | // Resolve the device name via sysfs so we get a real /dev/… path. |
| 235 | uevent, err := os.ReadFile(fmt.Sprintf("/sys/dev/block/%d:%d/uevent", major, minor)) |
| 236 | if err != nil { |
| 237 | t.Skipf("cannot resolve block device for / from sysfs: %v", err) |
| 238 | } |
| 239 | var name string |
| 240 | for _, line := range strings.Split(string(uevent), "\n") { |
| 241 | if after, ok := strings.CutPrefix(line, "DEVNAME="); ok { |
| 242 | name = strings.TrimSpace(after) |
| 243 | break |
| 244 | } |
| 245 | } |
| 246 | if name == "" { |
| 247 | t.Skip("DEVNAME not found in sysfs uevent for / block device") |
| 248 | } |
| 249 | return "/dev/" + name, fmt.Sprintf("%d:%d", major, minor) |
| 250 | } |
| 251 | |
| 252 | // parseIOMax returns the value of field (rbps/wbps/riops/wiops) for the given |
| 253 | // major:minor device from a cgroup v2 io.max file content. |
no test coverage detected
searching dependent graphs…