Re: [RFD] : Allowing xfs_fsr to defragment portions of a file

Dhruvesh Rathore
2015-03-03T14:48:51Z

(P.S We have already achieved the above using XFS_IOC_FIEMAPFS, and have
got extent information in fiemap structures)

2) The temp file getting created in xfs_fsr.c, will be made similar to
the donor file of e4defrag.c.
We were a bit unsure about the function of join_extents() in
e4defrag.c, which finds a continuous region (extents group), and how
it will fit in the XFS API.
Is it similar to the process of preallocating extents[toff, tlen] in temp file ?

3) Now instead of copying data from [orig, off, len] to [temp, toff,
tlen] and then calling
XFS_IOC_SWPEXT, we will need to simulate the ioctl EXT4_IOC_MOVE_EXT.

In call_defrag( ) in e4defrag.c, the struct fiemap_extent_list
structure, which is basically
a link list of extent information is used.
In our XFS API we will similarly use this structure in a loop and call
the IOCTL for
each of the extents (off donor file) which needs to be filled by
swapping data blocks.

In this loop the fields orig_start, donor_start, len and moved_len of
struct move_extent
will be populated from the fiemap_extent_list structure before each ioctl call.

-----

Before all of the above we will need to select the extents that can be
defragmented
i.e the best possible choice, and then mark them.
For this we decided to create another data structure - an array
(user_array[ ]), which
will store extent size information (blocks).
For instance say a file has 5 extents then
user_array[0] : save size of extent 1
user_array[1] : save size of extents 1, 2
user_array[2] : save size of extents 1, 2, 3
user_array[3] : save size of extents 1, 2, 3, 4
user_array[4] : save size of extents 1, 2 3, 4, 5
This way we could perform the selection efficiently, by necessary
comparison with
available space.

----

As said, we have already added to the XFS API, and have got extent info
in fiemap structures.