-
Notifications
You must be signed in to change notification settings - Fork 0
/
stuck_at_100.sh
executable file
·119 lines (96 loc) · 2.64 KB
/
stuck_at_100.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
# mode
SLEEP=0
# configurations
SETTING="protection_period"
PROTECTION_PERIOD="10"
# constants
CONFIG_FILE="/etc/nilfs_cleanerd.conf"
MOUNT_POINT="/mnt/test-nilfs2"
DEVICE="/dev/ram0"
DEVSZKB=1028
BLK_PER_SEG=16
FILE_PREFIX="testfile"
DIR_PREFIX="testdir"
FILE_SIZE=4
NUM_FILES_TO_CREATE=100
update_setting() {
local setting=$1
local value=$2
SETTING_MODIFIED=${setting}
echo "setting: ${setting}, value: ${value}"
}
create_files() {
local num_files=0
for i in $(seq 1 $NUM_FILES_TO_CREATE); do
FILE="${FILE_PREFIX}_${i}"
dd if=/dev/zero of="${MOUNT_POINT}/${FILE}" bs=1K count=${FILE_SIZE} status=none
if [ $? -ne 0 ]; then
echo "Failed to create file ${MOUNT_POINT}/${FILE}. Stopping."
break
fi
num_files=$((num_files + 1))
done
echo -e "\nCreated ${num_files} files"
}
delete_files() {
local num_files=$(find ${MOUNT_POINT} -maxdepth 1 -type f | wc -l)
for i in $(seq 1 "$num_files"); do
FILE="${MOUNT_POINT}/${FILE_PREFIX}_${i}"
rm -f "$FILE"
done
echo -e "\nDeleted ${num_files} files"
}
create_and_delete() {
echo -e "\n\nCreating files until the system is full."
create_files
sleep 15
echo -e "\n\nDisk usage after filling:"
df "${MOUNT_POINT}"
df -h "${MOUNT_POINT}"
df -i "${MOUNT_POINT}"
lssu -a -l "${DEVICE}"
echo -e "\n\nDeleting all files created"
delete_files
sleep 60
echo -e "\nDisk usage after deleting:"
df "${MOUNT_POINT}"
df -h "${MOUNT_POINT}"
df -i "${MOUNT_POINT}"
lssu -a -l "${DEVICE}"
}
## Initial setup
# Update protection_period based on PROTECTION_PERIOD
if grep -q "^${SETTING}[[:space:]]*" "$CONFIG_FILE"; then
sed -i "s|^\(${SETTING}[[:space:]]*\).*|\1${PROTECTION_PERIOD}|" "$CONFIG_FILE"
else
echo "Did not find the setting ${SETTING}"
fi
umount "${MOUNT_POINT}"
rm -rf "${MOUNT_POINT}"
rmmod brd
mkdir "${MOUNT_POINT}"
modprobe brd rd_nr=1 rd_size=$DEVSZKB
mkfs.nilfs2 -B $BLK_PER_SEG -f "${DEVICE}"
mount -t nilfs2 -o nogc "${DEVICE}" "${MOUNT_POINT}"
## Disk usage after initialization
echo -e "\nInitial disk usage:"
df "${MOUNT_POINT}"
df -h "${MOUNT_POINT}"
df -i "${MOUNT_POINT}"
lssu -a -l "${DEVICE}"
## Create files from an empty disk
create_and_delete
create_and_delete
create_and_delete
create_and_delete
create_and_delete
## Manually run cleanerd
## Don't manually start cleanerd unless the mount specifies nogc
nilfs_cleanerd -p 1 "${DEVICE}" "${MOUNT_POINT}"
sleep 60
echo "Disk usage after manually running cleanerd"
df "${MOUNT_POINT}"
df -h "${MOUNT_POINT}"
df -i "${MOUNT_POINT}"
lssu -a -l "${DEVICE}"