github.com/containers/podman/v5@v5.1.0-rc1/test/system/180-blkio.bats (about)

     1  #!/usr/bin/env bats   -*- bats -*-
     2  #
     3  # podman blkio-related tests
     4  #
     5  # bats file_tags=distro-integration
     6  #
     7  
     8  load helpers
     9  
    10  function teardown() {
    11      lofile=${PODMAN_TMPDIR}/disk.img
    12      if [ -f ${lofile} ]; then
    13          run_podman '?' rm -t 0 --all --force --ignore
    14  
    15          while read path dev; do
    16              if [[ "$path" == "$lofile" ]]; then
    17                  losetup -d $dev
    18              fi
    19          done < <(losetup -l --noheadings --output BACK-FILE,NAME)
    20  
    21          rm ${lofile}
    22      fi
    23      basic_teardown
    24  }
    25  
    26  @test "podman run --blkio-weight-device" {
    27      skip_if_rootless "cannot create devices in rootless mode"
    28  
    29      # create loopback device
    30      lofile=${PODMAN_TMPDIR}/disk.img
    31      fallocate -l 1k  ${lofile}
    32      losetup -f ${lofile}
    33  
    34      run losetup -l --noheadings --output BACK-FILE,NAME,MAJ:MIN
    35      assert "$status" -eq 0 "losetup: status"
    36      assert "$output" != "" "losetup: output"
    37  
    38      lodevice=$(awk "\$1 == \"$lofile\" { print \$2 }" <<<"$output")
    39      lomajmin=$(awk "\$1 == \"$lofile\" { print \$3 }" <<<"$output")
    40  
    41      is "$lodevice" ".\+" "Could not determine device for $lofile"
    42      is "$lomajmin" ".\+" "Could not determine major/minor for $lofile"
    43  
    44      # use bfq io scheduler
    45      run grep -w bfq /sys/block/$(basename ${lodevice})/queue/scheduler
    46      if [ $status -ne 0 ]; then
    47          skip "BFQ scheduler is not supported on the system"
    48      fi
    49      echo bfq > /sys/block/$(basename ${lodevice})/queue/scheduler
    50  
    51      # run podman
    52      if is_cgroupsv2; then
    53          if [ ! -f /sys/fs/cgroup/system.slice/io.bfq.weight ]; then
    54              skip "Kernel does not support BFQ IO scheduler"
    55          fi
    56          run_podman run --device ${lodevice}:${lodevice} --blkio-weight-device ${lodevice}:123 --rm $IMAGE \
    57              /bin/sh -c "cat /sys/fs/cgroup/\$(sed -e 's/0:://' < /proc/self/cgroup)/io.bfq.weight"
    58          is "${lines[1]}" "${lomajmin}\s\+123"
    59      else
    60          if [ ! -f /sys/fs/cgroup/blkio/system.slice/blkio.bfq.weight_device ]; then
    61              skip "Kernel does not support BFQ IO scheduler"
    62          fi
    63          if [ $(podman_runtime) = "crun" ]; then
    64              # As of crun 1.2, crun doesn't support blkio.bfq.weight_device
    65              skip "crun doesn't support blkio.bfq.weight_device"
    66          fi
    67          run_podman run --device ${lodevice}:${lodevice} --blkio-weight-device ${lodevice}:123 --rm $IMAGE \
    68              /bin/sh -c "cat /sys/fs/cgroup/blkio/blkio.bfq.weight_device"
    69          is "${lines[1]}" "${lomajmin}\s\+123"
    70      fi
    71  }