sahib / rmlint

Extremely fast tool to remove duplicates and other lint from your filesystem
http://rmlint.rtfd.org
GNU General Public License v3.0
1.91k stars 132 forks source link

--is-reflink skips every second extent #527

Closed cebtenzzre closed 1 year ago

cebtenzzre commented 3 years ago

Description

rmlint --is-reflink completely skips every second extent.

Steps to reproduce

Build rmlint from the develop branch with _RM_OFFSET_DEBUG=1. Then run these commands:

$ dd if=/dev/urandom of=foo bs=100K oflag=sync count=9
$ cp --reflink foo bar
$ dd if=/dev/urandom of=bar bs=100K oflag=sync count=1 seek=1 conv=notrunc
$ filefrag -vb1 foo bar
Filesystem type is: 9123683e
File size of foo is 921600 (921600 blocks of 1 bytes)
 ext:     logical_offset:        physical_offset: length:   expected: flags:
   0:        0..  102399: 672928833536..672928935935: 102400:             shared
   1:   102400..  204799: 673052336128..673052438527: 102400: 672928935936: shared
   2:   204800..  307199: 686491369472..686491471871: 102400: 673052438528: shared
   3:   307200..  409599: 690860650496..690860752895: 102400: 686491471872: shared
   4:   409600..  511999: 691562287104..691562389503: 102400: 690860752896: shared
   5:   512000..  614399: 699126407168..699126509567: 102400: 691562389504: shared
   6:   614400..  716799: 699169431552..699169533951: 102400: 699126509568: shared
   7:   716800..  819199: 699183190016..699183292415: 102400: 699169533952: shared
   8:   819200..  921599: 699530420224..699530522623: 102400: 699183292416: last,shared,eof
foo: 9 extents found
File size of bar is 921600 (921600 blocks of 1 bytes)
 ext:     logical_offset:        physical_offset: length:   expected: flags:
   0:        0..  102399: 672928833536..672928935935: 102400:             shared
   1:   102400..  204799: 682882265088..682882367487: 102400: 672928935936:
   2:   204800..  307199: 686491369472..686491471871: 102400: 682882367488: shared
   3:   307200..  409599: 690860650496..690860752895: 102400: 686491471872: shared
   4:   409600..  511999: 691562287104..691562389503: 102400: 690860752896: shared
   5:   512000..  614399: 699126407168..699126509567: 102400: 691562389504: shared
   6:   614400..  716799: 699169431552..699169533951: 102400: 699126509568: shared
   7:   716800..  819199: 699183190016..699183292415: 102400: 699169533952: shared
   8:   819200..  921599: 699530420224..699530522623: 102400: 699183292416: last,shared,eof
bar: 9 extents found
$ cmp foo bar
foo bar differ: byte 102401, line 406
$ rmlint --is-reflink -vv foo bar
DEBUG: Testing if foo is clone of bar
DEBUG: Checking link type for foo vs bar
DEBUG: rm_offset_get_fiemap: fd=3, n_extents=1, file_offset=0
DEBUG: rm_offset_get_fiemap: fd=3, n_extents=1, file_offset=102400
DEBUG: rm_offset_get_fiemap: fd=4, n_extents=1, file_offset=0
DEBUG: rm_offset_get_fiemap: fd=4, n_extents=1, file_offset=102400
DEBUG: Offsets match at fd1=3, fd2=4, logical=0, physical=672928833536
DEBUG: rm_offset_get_fiemap: fd=3, n_extents=1, file_offset=204800
DEBUG: rm_offset_get_fiemap: fd=3, n_extents=1, file_offset=307200
DEBUG: rm_offset_get_fiemap: fd=4, n_extents=1, file_offset=204800
DEBUG: rm_offset_get_fiemap: fd=4, n_extents=1, file_offset=307200
DEBUG: Offsets match at fd1=3, fd2=4, logical=204800, physical=686491369472
DEBUG: rm_offset_get_fiemap: fd=3, n_extents=1, file_offset=409600
DEBUG: rm_offset_get_fiemap: fd=3, n_extents=1, file_offset=512000
DEBUG: rm_offset_get_fiemap: fd=4, n_extents=1, file_offset=409600
DEBUG: rm_offset_get_fiemap: fd=4, n_extents=1, file_offset=512000
DEBUG: Offsets match at fd1=3, fd2=4, logical=409600, physical=691562287104
DEBUG: rm_offset_get_fiemap: fd=3, n_extents=1, file_offset=614400
DEBUG: rm_offset_get_fiemap: fd=3, n_extents=1, file_offset=716800
DEBUG: rm_offset_get_fiemap: fd=4, n_extents=1, file_offset=614400
DEBUG: rm_offset_get_fiemap: fd=4, n_extents=1, file_offset=716800
DEBUG: Offsets match at fd1=3, fd2=4, logical=614400, physical=699169431552
DEBUG: rm_offset_get_fiemap: fd=3, n_extents=1, file_offset=819200
DEBUG: rm_offset_get_fiemap: fd=4, n_extents=1, file_offset=819200
Link type for 'foo' and 'bar', result:
Reflink
$ echo $?
0

Actual result

rmlint prints "Reflink" and exits with status 0. It compares four pairs of physical offsets, despite the files having nine extents each.

Expected result

rmlint prints "Not linked" and exits with status 11. There should be a message like DEBUG: Physical offsets differ at byte 102400: 673052336128<> 682882265088.

Versions

rmlint version 2.10.1 built from develop commit bdb591f4 with _RM_OFFSET_DEBUG=1.