<div dir="ltr"><br><div>Hi All,</div><div><br></div><div>In glusterfs, there is an issue regarding the fallocate behavior. In short, if someone does fallocate from the mount point with some size that is greater than the available size in the backend filesystem where the file is present, then fallocate can fail with a subset of the required number of blocks allocated and then failing in the backend filesystem with ENOSPC error.</div><div><br></div><div>The behavior of fallocate in itself is simlar to how it would have been on a disk filesystem (atleast xfs where it was checked). i.e. allocates subset of the required number of blocks and then fail with ENOSPC. And the file in itself would show the number of blocks in stat to be whatever was allocated as part of fallocate. Please refer [1] where the issue is explained.</div><div><br></div><div>Now, there is one small difference between how the behavior is between glusterfs and xfs.</div><div>In xfs after fallocate fails, doing &#39;stat&#39; on the file shows the number of blocks that have been allocated. Whereas in glusterfs, the number of blocks is shown as zero which makes tools like &quot;du&quot; show zero consumption. This difference in behavior in glusterfs is because of libglusterfs on how it handles sparse files etc for calculating number of blocks (mentioned in [1])</div><div><br></div><div>At this point I can think of 3 things on how to handle this.</div><div><br></div><div>1) Except for how many blocks are shown in the stat output for the file from the mount point (on which fallocate was done), the remaining behavior of attempting to allocate the requested size and failing when the filesystem becomes full is similar to that of XFS. </div><div><br></div><div>Hence, what is required is to come up with a solution on how libglusterfs calculate blocks for sparse files etc (without breaking any of the existing components and features). This makes the behavior similar to that of backend filesystem. This might require its own time to fix libglusterfs logic without impacting anything else.</div><div><br></div><div>OR</div><div><br></div><div>2) Once the fallocate fails in the backend filesystem, make posix xlator in the brick truncate the file to the previous size of the file before attempting fallocate. A patch [2] has been sent for this. But there is an issue with this when there are parallel writes and fallocate operations happening on the same file. It can lead to a data loss.</div><div><br></div><div><span style="color:rgb(53,53,53);font-family:sans-serif;white-space:pre-wrap">a) statpre is obtained ===&gt; before fallocate is attempted, get the stat hence the size of the file
b) A parrallel Write fop on the same file that extends the file is successful
c) Fallocate fails 
d) ftruncate truncates it to size given by statpre (i.e. the previous stat and the size obtained in step a)</span><br></div><div><br></div><div>OR </div><div><br></div><div>3) Make posix check for available disk size before doing fallocate. i.e. in fallocate once posix gets the number of bytes to be allocated for the file from a particular offset, it checks whether so many bytes are available or not in the disk. If not, fail the fallocate fop with ENOSPC (without attempting it on the backend filesystem). </div><div><br></div><div>There still is a probability of a parallel write happening while this fallocate is happening and by the time falllocate system call is attempted on the disk, the available space might have been less than what was calculated before fallocate.</div><div>i.e. following things can happen</div><div><br></div><div> a) statfs ===&gt; get the available space of the backend filesystem</div><div> b) a parallel write succeeds and extends the file</div><div> c) fallocate is attempted assuming there is sufficient space in the backend</div><div><br></div><div>While the above situation can arise, I think we are still fine. Because fallocate is attempted from the offset received in the fop. So, irrespective of whether write extended the file or not, the fallocate itself will be attempted for so many bytes from the offset which we found to be available by getting statfs information.</div><div><br></div><div>[1] <a href="https://bugzilla.redhat.com/show_bug.cgi?id=1724754#c3">https://bugzilla.redhat.com/show_bug.cgi?id=1724754#c3</a></div><div>[2] <a href="https://review.gluster.org/#/c/glusterfs/+/22969/">https://review.gluster.org/#/c/glusterfs/+/22969/</a></div><div><br></div><div>Please provide feedback.</div><div><br></div><div>Regards,</div><div>Raghavendra</div></div>