• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3set -e
4
5MAX_TIMEOUT_SECONDS=300
6
7usage() {
8    echo "$0 <mount point> <timeout seconds>"
9    exit 1
10}
11
12# Get the size of the filesystem mounted at $1, in bytes.
13get_mount_size_bytes() {
14    local mount_point="$1"
15
16    # Filesystem              1024-blocks  Used Available Capacity Mounted on
17    # /dev/mapper/encstateful      290968 47492    243476      17% /var
18    #
19    # awk uses double-representation internally; we'll hit problems if
20    # the filesystem has more than 2^53 bytes (8 petabytes).
21    df -P "$mount_point" |
22    awk '($6 == "'"$mount_point"'") { printf "%.0f", $2*1024; exit }'
23}
24
25if [ $# -ne 2 ]; then
26    usage
27fi
28
29mount_point="$1"
30timeout_seconds="$2"
31
32if [ "$timeout_seconds" -gt $MAX_TIMEOUT_SECONDS ]; then
33    echo "max timeout is "$MAX_TIMEOUT_SECONDS" seconds";
34    exit 1
35fi
36
37mount_size_bytes=$(get_mount_size_bytes /var)
38temp_file=$(mktemp --tmpdir="$mount_point" hog_disk.XXXXXXXXXX)
39trap 'rm -f "$temp_file"' EXIT
40trap 'exit' HUP INT QUIT TERM
41
42for i in $(seq 1 $(( timeout_seconds * 10 ))); do
43    fallocate --length "$mount_size_bytes" "$temp_file" 2>/dev/null || true
44    sleep 0.1
45done
46