Commit 0b3f407
btrfs: send: fix wrong file path when there is an inode with a pending rmdir
When doing an incremental send, if we have a new inode that happens to
have the same number that an old directory inode had in the base snapshot
and that old directory has a pending rmdir operation, we end up computing
a wrong path for the new inode, causing the receiver to fail.
Example reproducer:
$ cat test-send-rmdir.sh
#!/bin/bash
DEV=/dev/sdi
MNT=/mnt/sdi
mkfs.btrfs -f $DEV >/dev/null
mount $DEV $MNT
mkdir $MNT/dir
touch $MNT/dir/file1
touch $MNT/dir/file2
touch $MNT/dir/file3
# Filesystem looks like:
#
# . (ino 256)
# |----- dir/ (ino 257)
# |----- file1 (ino 258)
# |----- file2 (ino 259)
# |----- file3 (ino 260)
#
btrfs subvolume snapshot -r $MNT $MNT/snap1
btrfs send -f /tmp/snap1.send $MNT/snap1
# Now remove our directory and all its files.
rm -fr $MNT/dir
# Unmount the filesystem and mount it again. This is to ensure that
# the next inode that is created ends up with the same inode number
# that our directory "dir" had, 257, which is the first free "objectid"
# available after mounting again the filesystem.
umount $MNT
mount $DEV $MNT
# Now create a new file (it could be a directory as well).
touch $MNT/newfile
# Filesystem now looks like:
#
# . (ino 256)
# |----- newfile (ino 257)
#
btrfs subvolume snapshot -r $MNT $MNT/snap2
btrfs send -f /tmp/snap2.send -p $MNT/snap1 $MNT/snap2
# Now unmount the filesystem, create a new one, mount it and try to apply
# both send streams to recreate both snapshots.
umount $DEV
mkfs.btrfs -f $DEV >/dev/null
mount $DEV $MNT
btrfs receive -f /tmp/snap1.send $MNT
btrfs receive -f /tmp/snap2.send $MNT
umount $MNT
When running the test, the receive operation for the incremental stream
fails:
$ ./test-send-rmdir.sh
Create a readonly snapshot of '/mnt/sdi' in '/mnt/sdi/snap1'
At subvol /mnt/sdi/snap1
Create a readonly snapshot of '/mnt/sdi' in '/mnt/sdi/snap2'
At subvol /mnt/sdi/snap2
At subvol snap1
At snapshot snap2
ERROR: chown o257-9-0 failed: No such file or directory
So fix this by tracking directories that have a pending rmdir by inode
number and generation number, instead of only inode number.
A test case for fstests follows soon.
Reported-by: Massimo B. <[email protected]>
Tested-by: Massimo B. <[email protected]>
Link: https://lore.kernel.org/linux-btrfs/[email protected]/
CC: [email protected] # 4.19+
Signed-off-by: Filipe Manana <[email protected]>
Signed-off-by: David Sterba <[email protected]>1 parent ae5e070 commit 0b3f407
1 file changed
Lines changed: 31 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
| 239 | + | |
239 | 240 | | |
240 | 241 | | |
241 | 242 | | |
| |||
316 | 317 | | |
317 | 318 | | |
318 | 319 | | |
319 | | - | |
| 320 | + | |
320 | 321 | | |
321 | 322 | | |
322 | 323 | | |
| |||
2299 | 2300 | | |
2300 | 2301 | | |
2301 | 2302 | | |
2302 | | - | |
| 2303 | + | |
2303 | 2304 | | |
2304 | 2305 | | |
2305 | 2306 | | |
| |||
2858 | 2859 | | |
2859 | 2860 | | |
2860 | 2861 | | |
2861 | | - | |
2862 | | - | |
| 2862 | + | |
| 2863 | + | |
2863 | 2864 | | |
2864 | 2865 | | |
2865 | 2866 | | |
| |||
2868 | 2869 | | |
2869 | 2870 | | |
2870 | 2871 | | |
2871 | | - | |
| 2872 | + | |
2872 | 2873 | | |
2873 | | - | |
| 2874 | + | |
2874 | 2875 | | |
2875 | | - | |
| 2876 | + | |
| 2877 | + | |
| 2878 | + | |
| 2879 | + | |
| 2880 | + | |
2876 | 2881 | | |
2877 | | - | |
2878 | 2882 | | |
2879 | 2883 | | |
2880 | 2884 | | |
2881 | 2885 | | |
2882 | 2886 | | |
2883 | 2887 | | |
2884 | | - | |
| 2888 | + | |
2885 | 2889 | | |
2886 | 2890 | | |
2887 | 2891 | | |
2888 | 2892 | | |
2889 | 2893 | | |
2890 | 2894 | | |
2891 | 2895 | | |
2892 | | - | |
2893 | | - | |
| 2896 | + | |
| 2897 | + | |
2894 | 2898 | | |
2895 | 2899 | | |
2896 | 2900 | | |
| |||
2901 | 2905 | | |
2902 | 2906 | | |
2903 | 2907 | | |
| 2908 | + | |
| 2909 | + | |
| 2910 | + | |
| 2911 | + | |
2904 | 2912 | | |
2905 | 2913 | | |
2906 | 2914 | | |
2907 | 2915 | | |
2908 | 2916 | | |
2909 | 2917 | | |
2910 | | - | |
| 2918 | + | |
2911 | 2919 | | |
2912 | | - | |
| 2920 | + | |
2913 | 2921 | | |
2914 | 2922 | | |
2915 | 2923 | | |
| |||
2954 | 2962 | | |
2955 | 2963 | | |
2956 | 2964 | | |
2957 | | - | |
| 2965 | + | |
2958 | 2966 | | |
2959 | 2967 | | |
2960 | 2968 | | |
| |||
2985 | 2993 | | |
2986 | 2994 | | |
2987 | 2995 | | |
2988 | | - | |
| 2996 | + | |
2989 | 2997 | | |
2990 | 2998 | | |
2991 | 2999 | | |
2992 | 3000 | | |
2993 | 3001 | | |
2994 | 3002 | | |
2995 | 3003 | | |
| 3004 | + | |
2996 | 3005 | | |
2997 | 3006 | | |
2998 | 3007 | | |
2999 | 3008 | | |
3000 | 3009 | | |
3001 | | - | |
| 3010 | + | |
3002 | 3011 | | |
3003 | 3012 | | |
3004 | 3013 | | |
| |||
3038 | 3047 | | |
3039 | 3048 | | |
3040 | 3049 | | |
| 3050 | + | |
3041 | 3051 | | |
3042 | 3052 | | |
3043 | 3053 | | |
| |||
3183 | 3193 | | |
3184 | 3194 | | |
3185 | 3195 | | |
3186 | | - | |
| 3196 | + | |
3187 | 3197 | | |
3188 | 3198 | | |
3189 | 3199 | | |
| |||
3223 | 3233 | | |
3224 | 3234 | | |
3225 | 3235 | | |
| 3236 | + | |
3226 | 3237 | | |
3227 | 3238 | | |
3228 | 3239 | | |
| |||
3237 | 3248 | | |
3238 | 3249 | | |
3239 | 3250 | | |
| 3251 | + | |
3240 | 3252 | | |
3241 | 3253 | | |
3242 | 3254 | | |
| |||
3273 | 3285 | | |
3274 | 3286 | | |
3275 | 3287 | | |
| 3288 | + | |
3276 | 3289 | | |
3277 | 3290 | | |
3278 | 3291 | | |
| |||
3291 | 3304 | | |
3292 | 3305 | | |
3293 | 3306 | | |
3294 | | - | |
| 3307 | + | |
3295 | 3308 | | |
3296 | 3309 | | |
3297 | 3310 | | |
| |||
0 commit comments