[Cluster-devel] [GFS2 PATCH 3/3] gfs2: allow fallocate to max out quotas/fs efficiently

Abhi Das adas at redhat.com
Mon Feb 16 17:59:43 UTC 2015


We can quickly get an estimate of how many more blocks are
available for allocation restricted by quota and fs size
respectively using the ap->allowed field in the gfs2_alloc_parms
structure. gfs2_quota_check() and gfs2_inplace_reserve() provide
these values.

By re-trying to allocate what's available instead of guessing, we
can max out quotas or the filesystem efficiently.

Bear in mind that this applies only when the requested fallocate
operation would otherwise error out with -EDQUOT or -ENOSPC without
utilizing all the blocks that might still be available.

Signed-off-by: Abhi Das <adas at redhat.com>
---
 fs/gfs2/file.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c
index 2ea420a..57129fa 100644
--- a/fs/gfs2/file.c
+++ b/fs/gfs2/file.c
@@ -829,20 +829,24 @@ static long __gfs2_fallocate(struct file *file, int mode, loff_t offset, loff_t
 			continue;
 		}
 		ap.target = bytes >> sdp->sd_sb.sb_bsize_shift;
+	quota_retry:
 		error = gfs2_quota_lock_check(ip, &ap);
-		if (error)
+		if (error) {
+			if (error == -EDQUOT && ap.allowed) {
+				bytes = ap.allowed << sdp->sd_sb.sb_bsize_shift;
+				ap.target = ap.allowed;
+				goto quota_retry;
+			}
 			return error;
-retry:
+		}
+	retry:
 		gfs2_write_calc_reserv(ip, bytes, &data_blocks, &ind_blocks);
 
 		ap.target = data_blocks + ind_blocks;
 		error = gfs2_inplace_reserve(ip, &ap);
 		if (error) {
-			if (error == -ENOSPC && bytes > sdp->sd_sb.sb_bsize) {
-				bytes >>= 1;
-				bytes &= bsize_mask;
-				if (bytes == 0)
-					bytes = sdp->sd_sb.sb_bsize;
+			if (error == -ENOSPC && ap.allowed) {
+				bytes = ap.allowed << sdp->sd_sb.sb_bsize_shift;
 				goto retry;
 			}
 			goto out_qunlock;
-- 
1.8.1.4




More information about the Cluster-devel mailing list