summaryrefslogtreecommitdiff
path: root/tests/bcachefs/subvol.ktest
blob: 1b84160698d809945a3f48e77ce4fd2f7ca33e26 (plain)
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
#!/bin/bash

. $(dirname $(readlink -e "${BASH_SOURCE[0]}"))/bcachefs-test-libs.sh

config-scratch-devs 4G
config-scratch-devs 4G

test_snapshots_simple()
{
    NR_SNAPS=1

    bcachefs_antagonist

    run_quiet "" bcachefs format -f --errors=panic /dev/sdb
    mount -t bcachefs /dev/sdb /mnt

    pushd /mnt
    for i in `seq 0 $NR_SNAPS`; do
	dd if=/dev/zero of=/mnt/foo bs=1M count=1 oflag=direct
	bcachefs subvolume snapshot snap-$i
    done
    popd

    umount /mnt
    sleep 0.2
    bcachefs fsck -n /dev/sdb
    exit

    for i in `seq 0 $NR_SNAPS|sort -r`; do
	umount /mnt
	sleep 0.2
	bcachefs fsck -n /dev/sdb
	mount -t bcachefs /dev/sdb /mnt

	echo "deleting snap-$i"
	bcachefs subvolume delete /mnt/snap-$i
	df -h /mnt
    done

    umount /mnt
    sleep 0.2
    mount -t bcachefs -o fsck /dev/sdb /mnt
    umount /mnt
}

test_files_many()
{
    #bcachefs_antagonist

    run_quiet "" bcachefs format -f --errors=panic /dev/sdb
    mount -t bcachefs /dev/sdb /mnt

    for i in $(seq 0 1000001); do
       	echo $i > /mnt/$i 
    done

    umount /mnt
    sleep 0.2
    time mount -t bcachefs -o fsck /dev/sdb /mnt
    umount /mnt
}

d_test_snapshots_many()
{
    #bcachefs_antagonist

    run_quiet "" bcachefs format -f --errors=panic /dev/sdb
    mount -t bcachefs /dev/sdb /mnt

    cd /mnt

    for i in $(seq 0 1000001); do
	bcachefs subvolume snapshot "snap_$(date -u +%F-%H%M%_S%N)"
       	echo $i > snap_number
    done

    umount /mnt
    sleep 0.2
    mount -t bcachefs -o fsck /dev/sdb /mnt
    umount /mnt
}

test_dbench()
{
    # so wait doesn't hang
    [[ $(jobs -p) != "" ]] && kill $(jobs -p)

    NR_SNAPS=10

    run_quiet "" bcachefs format -f --errors=panic /dev/sdb
    mount -t bcachefs /dev/sdb /mnt

    (
	cd /mnt

	for i in `seq 0 $NR_SNAPS`; do
	    sleep 1
	    bcachefs subvolume snapshot snap-$i
	done
    ) &

    dbench -S -t $NR_SNAPS 1 -D /mnt/
    wait
    df -h /mnt

    for i in `seq 0 $NR_SNAPS|sort -r`; do
	echo "deleting snap-$i"
	bcachefs subvolume delete /mnt/snap-$i
	df -h /mnt
    done

    umount /mnt
    sleep 0.2
    #bcachefs fsck -n /dev/sdb
    mount -t bcachefs -o fsck /dev/sdb /mnt
    df -h /mnt
    umount /mnt
}

test_reflink()
{
    run_quiet "" bcachefs format -f --errors=panic /dev/sdb
    mount -t bcachefs /dev/sdb /mnt

    pushd /mnt
    cp -a /usr .
    bcachefs subvolume snapshot snap-$i
    cp -r --reflink usr usr2
    popd

    umount /mnt
}

d_test_finsert()
{
    run_quiet "" bcachefs format -f --errors=panic /dev/sdb
    mount -t bcachefs /dev/sdb /mnt

    pushd /mnt
    dd if=/dev/zero of=foo bs=1M count=8 oflag=direct
    bcachefs subvolume snapshot snap-$i
    xfs_io -c "finsert 1024 1024" foo
    popd

    umount /mnt
}

d_test_snapshots_fio()
{
    # so wait doesn't hang
    [[ $(jobs -p) != "" ]] && kill $(jobs -p)

    run_quiet "" bcachefs format -f --errors=panic /dev/sdb
    mount -t bcachefs /dev/sdb /mnt

    fallocate -l500M /mnt/fiotest

    (
	cd /mnt

	for i in `seq 0 10`; do
	    sleep 2
	    bcachefs subvolume snapshot snap-$i
	done
    ) &

    fio --eta=always				\
	--eta-interval=1s			\
	--exitall_on_error=1			\
	--randrepeat=0				\
	--ioengine=libaio			\
	--iodepth=64				\
	--iodepth_batch=16			\
	--direct=1				\
	--numjobs=1				\
	--verify=crc32c				\
	--verify_fatal=1			\
	--verify_async=1			\
	--filename=/mnt/fiotest		    	\
	--filesize=1G				\
	--io_size=12G				\
	--fallocate=none			\
	--name=randwrite			\
	--rw=randwrite				\
	--bsrange=4k-32k || true
    wait
    df -h /mnt

    for i in `seq 0 10`; do
	fio --eta=always			\
	    --eta-interval=1s			\
	    --exitall_on_error=1		\
	    --randrepeat=0			\
	    --ioengine=libaio			\
	    --iodepth=64			\
	    --iodepth_batch=16			\
	    --direct=1				\
	    --numjobs=1				\
	    --verify=crc32c			\
	    --verify_only=1			\
	    --filename=/mnt/snap-$i/fiotest	\
	    --filesize=1G			\
	    --io_size=12G			\
	    --fallocate=none			\
	    --name=randwrite			\
	    --rw=randwrite			\
	    --bsrange=4k-32k || true
    done

    for i in `seq 0 10|sort -r`; do
	umount /mnt
	sleep 0.1
	mount -t bcachefs -o fsck /dev/sdb /mnt

	echo "deleting snap-$i"
	cd /mnt
	bcachefs subvolume delete snap-$i
	df -h /mnt
	cd /
    done

    umount /mnt

    sleep 0.1
    mount -t bcachefs -o fsck /dev/sdb /mnt
    df -h /mnt
    umount /mnt
}

test_subvol_create()
{
    run_quiet "" bcachefs format -f --errors=panic /dev/sdb
    mount -t bcachefs /dev/sdb /mnt
    bcachefs subvolume create /mnt/subvolume_1

    touch /mnt/foo
    mv /mnt/foo /mnt/subvolume_1

    umount /mnt

    bcachefs fsck -n /dev/sdb
}

test_subvol_delete()
{
    run_quiet "" bcachefs format -f --errors=panic /dev/sdb
    mount -t bcachefs /dev/sdb /mnt
    bcachefs subvolume create /mnt/subvolume_1
    rm -rf /mnt/subvolume_1

    umount /mnt

    bcachefs fsck -n /dev/sdb
}

test_subvol_snapshot_create()
{
    run_quiet "" bcachefs format -f --errors=panic /dev/sdb
    mount -t bcachefs /dev/sdb /mnt
    bcachefs subvolume create /mnt/subvolume_1
    bcachefs subvolume snapshot /mnt/subvolume_1 /mnt/snapshot_1

    umount /mnt

    bcachefs fsck -n /dev/sdb
}

test_subvol_snapshot_create_ro()
{
    run_quiet "" bcachefs format -f --errors=panic /dev/sdb
    mount -t bcachefs /dev/sdb /mnt
    bcachefs subvolume create /mnt/subvolume_1
    bcachefs subvolume snapshot -r /mnt/subvolume_1 /mnt/snapshot_1

    ! touch /mnt/snapshot_1/foo

    umount /mnt

    bcachefs fsck -n /dev/sdb
}

test_subvol_snapshot_delete()
{
    run_quiet "" bcachefs format -f --errors=panic /dev/sdb
    mount -t bcachefs /dev/sdb /mnt
    bcachefs subvolume create /mnt/subvolume_1
    bcachefs subvolume snapshot /mnt/subvolume_1 /mnt/snapshot_1
    bcachefs subvolume delete /mnt/snapshot_1

    umount /mnt

    bcachefs fsck -n /dev/sdb
}

test_subvol_snapshot_delete_create()
{
    run_quiet "" bcachefs format -f --errors=panic /dev/sdb
    mount -t bcachefs /dev/sdb /mnt
    bcachefs subvolume create /mnt/subvolume_1
    bcachefs subvolume snapshot /mnt/subvolume_1 /mnt/snapshot_1
    bcachefs subvolume delete /mnt/snapshot_1
    bcachefs subvolume snapshot /mnt/subvolume_1 /mnt/snapshot_1

    umount /mnt

    bcachefs fsck -n /dev/sdb
}

d_test_subvol_snapshot_rm()
{
    run_quiet "" bcachefs format -f --errors=panic /dev/sdb
    mount -t bcachefs /dev/sdb /mnt
    bcachefs subvolume create /mnt/subvolume_1
    bcachefs subvolume snapshot /mnt/subvolume_1 /mnt/snapshot_1
    rm -r /mnt/snapshot_1

    umount /mnt

    bcachefs fsck -n /dev/sdb
}

# Create a subvolume, then snapshot the parent subvolume, then move the child
# subvolume:
test_mkdir_mv_snapshot()
{
    run_quiet "" bcachefs format -f --errors=panic /dev/sdb
    mount -t bcachefs /dev/sdb /mnt
    mkdir /mnt/dir1
    bcachefs subvolume snapshot /mnt/ /mnt/snap1
    mv /mnt/dir1 /mnt/dir2
    umount /mnt

    bcachefs fsck -n /dev/sdb
}

test_subvol_mv_snapshot()
{
    run_quiet "" bcachefs format -f --errors=panic /dev/sdb
    mount -t bcachefs /dev/sdb /mnt
    bcachefs subvolume create /mnt/sub1
    bcachefs subvolume snapshot /mnt/ /mnt/snap1
    mv /mnt/sub1 /mnt/sub2
    umount /mnt

    bcachefs fsck -n /dev/sdb
}

# Test moving a subvol to another subvol
test_subvol_mv_subvol()
{
    run_quiet "" bcachefs format -f --errors=panic /dev/sdb
    mount -t bcachefs /dev/sdb /mnt
    bcachefs subvolume create /mnt/sub1
    bcachefs subvolume create /mnt/sub2
    mv /mnt/sub1 /mnt/sub2
    umount /mnt

    bcachefs fsck -n /dev/sdb
}

test_subvol_snapshot_reuse_snapshot_name()
{
    run_quiet "" bcachefs format -f --errors=panic /dev/sdb
    mount -t bcachefs /dev/sdb /mnt
    bcachefs subvolume create /mnt/subvolume_1
    bcachefs subvolume snapshot /mnt/subvolume_1 /mnt/snapshot_1
    bcachefs subvolume delete /mnt/snapshot_1
    bcachefs subvolume snapshot /mnt/subvolume_1 /mnt/snapshot_1

    umount /mnt

    bcachefs fsck -n /dev/sdb
}

test_subvol_delete_snapshot_of_deleted_subvol()
{
    run_quiet "" bcachefs format -f --errors=panic /dev/sdb
    mount -t bcachefs /dev/sdb /mnt
    bcachefs subvolume create /mnt/subvolume_1
    bcachefs subvolume snapshot /mnt/subvolume_1 /mnt/snapshot_1
    rm -rf /mnt/subvolume_1
    bcachefs subvolume delete /mnt/snapshot_1

    umount /mnt

    bcachefs fsck -n /dev/sdb
}

test_subvol_snapshot_delete_repeat()
{
    run_quiet "" bcachefs format -f --errors=panic /dev/sdb
    mount -t bcachefs /dev/sdb /mnt
    for i in $(seq 1 64); do
        bcachefs subvolume snapshot /mnt/$i
        bcachefs subvolume delete /mnt/$i
    done
    umount /mnt

    bcachefs fsck -n /dev/sdb
}

test_subvol_snapshot_delete_fio()
{
    run_quiet "" bcachefs format -f --errors=panic /dev/sdb
    mount -t bcachefs /dev/sdb /mnt

    for i in $(seq 1 10); do
	#run_fio_randrw --filesize=500M --bs=4k
	dd if=/dev/zero of=/mnt/test bs=4k count=1024 oflag=direct
        bcachefs subvolume snapshot /mnt/$i
    done

    for i in $(seq 1 10); do
	umount /mnt
	bcachefs fsck -n /dev/sdb
	mount -t bcachefs -o fsck /dev/sdb /mnt
    done

    umount /mnt
    bcachefs fsck -n /dev/sdb
}

test_snapshot_copygc()
{
    run_quiet "" bcachefs format -f --errors=panic /dev/sdb
    mount -t bcachefs /dev/sdb /mnt

    for i in $(seq 1 4); do
	run_fio_randrw --filesize=1000M --loops=4 --bs=4k
        bcachefs subvolume snapshot /mnt/$i
    done

    bcachefs fs usage -h /mnt
    umount /mnt
}

main "$@"