Skip to content

Commit

Permalink
utils: rm_offset_get_from_fd: Don't combine separate extents
Browse files Browse the repository at this point in the history
There can be a hole between two physically adjacent extents. To avoid
breaking any code that calls this function, don't merge their
representation, since it completely hides the hole and makes the
physical length of the on-disk extent look larger than it really is.

Fixes sahib#530
  • Loading branch information
cebtenzzre committed Feb 9, 2022
1 parent 923312a commit 933fc58
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/utilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -1190,11 +1190,11 @@ RmOff rm_offset_get_from_fd(int fd, RmOff file_offset, RmOff *file_offset_next,
#if _RM_OFFSET_DEBUG
int errnum = 0;
#endif
struct fiemap_extent fm_last;
rm_util_set_nullable_bool(is_last, FALSE);
rm_util_set_nullable_bool(is_inline, FALSE);

/* used for detecting contiguous extents */
unsigned long expected = 0;
memset(&fm_last, 0, sizeof(fm_last));

fsync(fd);

Expand Down Expand Up @@ -1228,7 +1228,9 @@ RmOff rm_offset_get_from_fd(int fd, RmOff file_offset, RmOff *file_offset_next,
first = FALSE;
} else {
/* check if subsequent extents are contiguous */
if(fm_ext.fe_physical != expected) {
unsigned long expected_dense = fm_last.fe_physical + fm_last.fe_length;
unsigned long expected = fm_last.fe_physical + fm_ext.fe_logical - fm_last.fe_logical;
if(fm_ext.fe_physical != expected || fm_ext.fe_physical != expected_dense) {
/* current extent is not contiguous with previous, so we can stop */
g_free(fm);
break;
Expand All @@ -1252,7 +1254,7 @@ RmOff rm_offset_get_from_fd(int fd, RmOff file_offset, RmOff *file_offset_next,

/* move offsets in preparation for reading next extent */
file_offset = fm_ext.fe_logical + fm_ext.fe_length;
expected = fm_ext.fe_physical + fm_ext.fe_length;
fm_last = fm_ext;
}

g_free(fm);
Expand Down

0 comments on commit 933fc58

Please sign in to comment.