Description
Its a well known issue that running defragment will break up reflink clones. One can google and see this is the source of a lot of headaches for users and I bet will continue to be. I'm hoping that this could be the start of remedying that.
This big idea here is to allow for a sub-optimal defragmentation that does not break up reflinks or shared extents in general. I noticed that the defragment command can take a starting byte offset and a length in bytes arguments. So it seems defragment should be able to (easily?) look at the extents of a given file and only defragment sequential extents that do not contain shared extents. Currently a script could be written to do this by getting the FIEMAP and running a series of defragment operations specifying start and length. It would be better to have this be done internally as an option for defragment. There should be a note in the documentation for this option that its a sub-optimal defragmentation.