The following patch adds preliminary support for the FITRIM ioctl (as
used by the `fstrim' command).  For those unfamiliar with this
command, it instructs the filesystem to send "TRIM" (aka "DISCARD")
requests for all unused areas of the filesystem.  Usually this means
that the underlying device is able to release these blocks for other
uses -- commonly known as thin-provisioning.

As I'm not very familiar with the ntfs-3g code, it would be good for
someone to check this over in detail, in case I've made some obvious
blunders.  Some areas that I'm unclear about:

 - Can FUSE entry points be called from multiple threads?  It is
   unlikely that this code is thread safe.

 - Can we include <linux/fs.h> directly?  You will note that I had to
   add a rather ugly hack to make this work.

 - Does FUSE-lite get pulled in from FUSE?  FUSE-lite does not appear
   to support the ioctl entry point, whereas external FUSE does.  At
   the moment you must use external FUSE.

 - I did not add an ntfs_* operation for discarding.  Instead this
   code just calls ctx->vol->dev->d_ops->ioctl directly.

There are some known shortcomings:

 - It does not support the fstrim range options -o/-l/-m.

 - I have only tested it on recent Linux with external FUSE.

You can test this using a loopback device.  For example:

  truncate -s1G /tmp/fs
  mkntfs --force /tmp/fs
  losetup -f /tmp/fs
  mkdir /tmp/mnt
  ./src/ntfs-3g -o no_detach,debug /dev/loop0 /tmp/mnt

First of all notice that /tmp/fs starts off fully allocated (because
mkntfs writes zeroes over the whole disk):

  $ du -sh /tmp/fs
  1.1G     /tmp/fs

Now copy data to the filesystem and issue an fstrim command, and the
underlying loop file should become sparse:

  $ fstrim /tmp/mnt
  $ du -sh /tmp/fs
  69M      /tmp/fs

(This test probably requires a recent kernel to work - I am testing
this with 3.16.0).

Comments gladly received,

Rich.



------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
ntfs-3g-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ntfs-3g-devel

Reply via email to