[Cluster-devel] [GFS2 PATCH 2/3] gfs2: allow quota_check and inplace_reserve to return available blocks

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


struct gfs2_alloc_parms is passed to gfs2_quota_check() and
gfs2_inplace_reserve() with ap->target containing the number of
blocks being requested for allocation in the current operation.

We add a new field to struct gfs2_alloc_parms called 'allowed'.
gfs2_quota_check() and gfs2_inplace_reserve() return -EDQUOT and
-ENOSPC respectively when they can't allow ap->target blocks to
be allocated due to quota violations or lack of space on the fs.
In such cases, we make these functions return the number of blocks
available in ap->allowed. A subsequent call with this value set
as ap->target is less likely to fail.

Signed-off-by: Abhi Das <adas at redhat.com>
---
 fs/gfs2/incore.h |  1 +
 fs/gfs2/quota.c  | 15 +++++++++++++++
 fs/gfs2/rgrp.c   |  8 +++++++-
 fs/gfs2/rgrp.h   |  2 +-
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index 3a4ea50..bff2d7f 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -303,6 +303,7 @@ struct gfs2_blkreserv {
 struct gfs2_alloc_parms {
 	u64 target;
 	u32 aflags;
+	u64 allowed;
 };
 
 enum {
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index 3a0b780..c0d36e9 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -1093,6 +1093,19 @@ static int print_message(struct gfs2_quota_data *qd, char *type)
 	return 0;
 }
 
+/**
+ * gfs2_quota_check - check if allocating new blocks will exceed quota
+ * @ip:  The inode for which this check is being performed
+ * @uid: The uid to check against
+ * @gid: The gid to check against
+ * @ap:  The allocation parameters. ap->target contains the requested
+ *       blocks.
+ *
+ * Returns: 0 on success
+ *          -EDQUOT on quota violation, ap->allowed is set to number of
+ *                  blocks available
+ *          error code on any other error.
+ */
 int gfs2_quota_check(struct gfs2_inode *ip, kuid_t uid, kgid_t gid,
 		     struct gfs2_alloc_parms *ap)
 {
@@ -1125,6 +1138,8 @@ int gfs2_quota_check(struct gfs2_inode *ip, kuid_t uid, kgid_t gid,
 			quota_send_warning(qd->qd_id,
 					   sdp->sd_vfs->s_dev, QUOTA_NL_BHARDWARN);
 			error = -EDQUOT;
+			ap->allowed = (s64)be64_to_cpu(qd->qd_qb.qb_limit) -
+				(value - ap->target);
 			break;
 		} else if (be64_to_cpu(qd->qd_qb.qb_warn) &&
 			   (s64)be64_to_cpu(qd->qd_qb.qb_warn) < value &&
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 9150207..e763f31 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -1947,9 +1947,11 @@ static inline int fast_to_acquire(struct gfs2_rgrpd *rgd)
  * @ap: the allocation parameters
  *
  * Returns: errno
+ *          if error is -ENOSPC, ap->allowed is set to the maximum number
+ *          of blocks available for allocation.
  */
 
-int gfs2_inplace_reserve(struct gfs2_inode *ip, const struct gfs2_alloc_parms *ap)
+int gfs2_inplace_reserve(struct gfs2_inode *ip, struct gfs2_alloc_parms *ap)
 {
 	struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
 	struct gfs2_rgrpd *begin = NULL;
@@ -1958,6 +1960,7 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, const struct gfs2_alloc_parms *a
 	u64 last_unlinked = NO_BLOCK;
 	int loops = 0;
 	u32 skip = 0;
+	u32 avail = 0;
 
 	if (sdp->sd_args.ar_rgrplvb)
 		flags |= GL_SKIP;
@@ -2030,6 +2033,8 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, const struct gfs2_alloc_parms *a
 		if (rs->rs_rbm.rgd->rd_free_clone >= ap->target) {
 			ip->i_rgd = rs->rs_rbm.rgd;
 			return 0;
+		} else if (rs->rs_rbm.rgd->rd_free_clone > avail) {
+			avail = rs->rs_rbm.rgd->rd_free_clone;
 		}
 
 check_rgrp:
@@ -2068,6 +2073,7 @@ next_rgrp:
 			gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
 	}
 
+	ap->allowed = avail;
 	return -ENOSPC;
 }
 
diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h
index b104f4a..d38e0b1 100644
--- a/fs/gfs2/rgrp.h
+++ b/fs/gfs2/rgrp.h
@@ -41,7 +41,7 @@ extern void gfs2_rgrp_go_unlock(struct gfs2_holder *gh);
 extern struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip);
 
 #define GFS2_AF_ORLOV 1
-extern int gfs2_inplace_reserve(struct gfs2_inode *ip, const struct gfs2_alloc_parms *ap);
+extern int gfs2_inplace_reserve(struct gfs2_inode *ip, struct gfs2_alloc_parms *ap);
 extern void gfs2_inplace_release(struct gfs2_inode *ip);
 
 extern int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *n,
-- 
1.8.1.4




More information about the Cluster-devel mailing list