Files created on live partition after snapshot is taken appear in snapshot
bug
### Distribution
Ubunto 22.04.1
### Architecture
amd64
### Kernel version
6.8.0-1034-azure (Hyper-V VM running on Windows 11)
### Blksnap version
13.0.0.772 including kernel module
### Bug description
I made minor modifications to the manual.sh test which primarily included mounting the snapshot with:
```
kpartx -av /dev/vbsnap-8-0
mount /dev/mapper/vbsnap-8-0p1 ${MNTPOINT}
```
I also sprinkled `touch testfile_x` statements throughout the code to verify the moment when the snapshot is taken, and surrounded `blksnap_snapshot_take` with `fsfreeze -f /` and `fsfreeze -u /` to ensure that the test files I touched before the snapshot is taken are included in the snapshot.
Initially, it worked exactly as expected, but I found that when I introduced a delay following `fsfreeze -u /`, then files created after that delay appeared in the snapshot. It's repeatable, but not 100% repeatable, and the exact results depend on the delay, so there seems to be some kind of race condition. But it's the opposite kind of race condition that I'd expect. Adding delay after the snapshot is taken causes the issue instead of preventing it.
### Steps to reproduce
Run this test script: [manual1.sh](https://github.com/user-attachments/files/22396896/manual1.sh)
It currently has `sleep 5` as the delay.
Replacing that with e.g. `systemctl restart mysql` makes the problem worse, on my system.
Removing all delay there causes the snapshot to behave as expected.
### Expected behavior
### Case 1: No delay added.
9 test files were created. As expected, only the first two, created before `blksnap_snapshot_take`, appear in the snapshot
```
-rw-r--r-- 1 root root 0 2025-09-17 17:59:28.544102215 -0700 /tmp/blksnap_test/t0
-rw-r--r-- 1 root root 0 2025-09-17 17:59:28.546102228 -0700 /tmp/blksnap_test/t1
-rw-r--r-- 1 root root 0 2025-09-17 17:59:28.603102617 -0700 /tmp/blksnap_test/t2a_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:59:28.603102617 -0700 /tmp/blksnap_test/t2b_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:59:28.604102624 -0700 /tmp/blksnap_test/t2c_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:59:28.605102631 -0700 /tmp/blksnap_test/t2d_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:59:28.606102638 -0700 /tmp/blksnap_test/t2e_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:59:28.607102644 -0700 /tmp/blksnap_test/t3_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:59:28.774103782 -0700 /tmp/blksnap_test/t4_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:59:28.544102215 -0700 /mnt/blksnap/tmp/blksnap_test/t0
-rw-r--r-- 1 root root 0 2025-09-17 17:59:28.546102228 -0700 /mnt/blksnap/tmp/blksnap_test/t1
```
### Additional information
Here are two examples showing how delay inserted after `blksnap_snapshot_take` causes unexpected behavior.
### Case 2: `sleep 5` delay.
File `t2a_not_expected` incorrectly appears in the snapshot.
```
-rw-r--r-- 1 root root 0 2025-09-17 17:58:35.819736710 -0700 /tmp/blksnap_test/t0
-rw-r--r-- 1 root root 0 2025-09-17 17:58:35.822736731 -0700 /tmp/blksnap_test/t1
-rw-r--r-- 1 root root 0 2025-09-17 17:58:40.900772517 -0700 /tmp/blksnap_test/t2a_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:58:40.904772546 -0700 /tmp/blksnap_test/t2b_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:58:40.906772560 -0700 /tmp/blksnap_test/t2c_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:58:40.908772574 -0700 /tmp/blksnap_test/t2d_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:58:40.909772581 -0700 /tmp/blksnap_test/t2e_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:58:40.912772602 -0700 /tmp/blksnap_test/t3_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:58:41.081773791 -0700 /tmp/blksnap_test/t4_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:58:35.819736710 -0700 /mnt/blksnap/tmp/blksnap_test/t0
-rw-r--r-- 1 root root 0 2025-09-17 17:58:35.822736731 -0700 /mnt/blksnap/tmp/blksnap_test/t1
-rw-r--r-- 1 root root 0 2025-09-17 17:58:40.900772517 -0700 /mnt/blksnap/tmp/blksnap_test/t2a_not_expected
```
### Case 3: `systemctl restart mysql` delay.
6 files (t2*,t3) incorrectly appears in the snapshot. File t4_not_expected does not appear, showing the snapshot seems to have started working within the 190mS between the creation of files t3 and t4.
```
-rw-r--r-- 1 root root 0 2025-09-17 17:59:12.480992248 -0700 /tmp/blksnap_test/t0
-rw-r--r-- 1 root root 0 2025-09-17 17:59:12.483992268 -0700 /tmp/blksnap_test/t1
-rw-r--r-- 1 root root 0 2025-09-17 17:59:13.939002278 -0700 /tmp/blksnap_test/t2a_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:59:13.939002278 -0700 /tmp/blksnap_test/t2b_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:59:13.939002278 -0700 /tmp/blksnap_test/t2c_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:59:13.939002278 -0700 /tmp/blksnap_test/t2d_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:59:13.940002285 -0700 /tmp/blksnap_test/t2e_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:59:13.941002292 -0700 /tmp/blksnap_test/t3_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:59:14.127003571 -0700 /tmp/blksnap_test/t4_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:59:12.480992248 -0700 /mnt/blksnap/tmp/blksnap_test/t0
-rw-r--r-- 1 root root 0 2025-09-17 17:59:12.483992268 -0700 /mnt/blksnap/tmp/blksnap_test/t1
-rw-r--r-- 1 root root 0 2025-09-17 17:59:13.939002278 -0700 /mnt/blksnap/tmp/blksnap_test/t2a_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:59:13.939002278 -0700 /mnt/blksnap/tmp/blksnap_test/t2b_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:59:13.939002278 -0700 /mnt/blksnap/tmp/blksnap_test/t2c_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:59:13.939002278 -0700 /mnt/blksnap/tmp/blksnap_test/t2d_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:59:13.940002285 -0700 /mnt/blksnap/tmp/blksnap_test/t2e_not_expected
-rw-r--r-- 1 root root 0 2025-09-17 17:59:13.941002292 -0700 /mnt/blksnap/tmp/blksnap_test/t3_not_expected
```
关闭于 2025-09-18 3 条评论