From: Abhi Das <adas@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [GFS2 PATCH 2/4] gfs2: add new quota check functions
Date: Thu, 12 Feb 2015 10:54:12 -0600 [thread overview]
Message-ID: <1423760054-63438-3-git-send-email-adas@redhat.com> (raw)
In-Reply-To: <1423760054-63438-1-git-send-email-adas@redhat.com>
gfs2_quota_chk_ret_allow and gfs2_quota_lck_chk_ret_allow are
variants of gfs2_quota_check and gfs2_quota_lock_check respectively.
If an operation will not succeed due to a quota violation, these
functions will return the number of blocks that quota will actually
allow without failing in an extra parameter 'allow'
If acceptable to the caller logic, any of the quota_check functions
may be called again with the 'allow'ed blocks to try and avoid a
quota violation.
Signed-off-by: Abhi Das <adas@redhat.com>
---
fs/gfs2/quota.c | 24 ++++++++++++++++++++----
fs/gfs2/quota.h | 20 +++++++++++++++++---
2 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index e2f86ec..98cdf97 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -1092,8 +1092,20 @@ static int print_message(struct gfs2_quota_data *qd, char *type)
return 0;
}
-
-int gfs2_quota_check(struct gfs2_inode *ip, kuid_t uid, kgid_t gid, s64 exp_change)
+/**
+ * gfs2_quota_chk_ret_allow - Checks if adding the specified number of
+ * blocks will exceed usr/grp quotas
+ * @ip: The inode for which this check is being performed
+ * @uid: The uid to check against
+ * @gid: The gid to check against
+ * @exp_change: The expected change in blocks
+ * @allow: If non-NULL, we should return the number of blocks
+ * quota will allow if exp_change exceeds limits
+ *
+ * Returns: 0 on success, error code otherwise.
+ */
+int gfs2_quota_chk_ret_allow(struct gfs2_inode *ip, kuid_t uid, kgid_t gid,
+ s64 exp_change, u32 *allow)
{
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
struct gfs2_quota_data *qd;
@@ -1119,12 +1131,16 @@ int gfs2_quota_check(struct gfs2_inode *ip, kuid_t uid, kgid_t gid, s64 exp_chan
value += qd->qd_change + exp_change;
spin_unlock(&qd_lock);
- if (be64_to_cpu(qd->qd_qb.qb_limit) && (s64)be64_to_cpu(qd->qd_qb.qb_limit) < value) {
+ if (be64_to_cpu(qd->qd_qb.qb_limit) &&
+ (s64)be64_to_cpu(qd->qd_qb.qb_limit) < value) {
print_message(qd, "exceeded");
quota_send_warning(qd->qd_id,
sdp->sd_vfs->s_dev, QUOTA_NL_BHARDWARN);
-
error = -EDQUOT;
+ if (allow) {
+ *allow = (s64)be64_to_cpu(qd->qd_qb.qb_limit) -
+ (value - exp_change);
+ }
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/quota.h b/fs/gfs2/quota.h
index 1457c66..49d1fd9 100644
--- a/fs/gfs2/quota.h
+++ b/fs/gfs2/quota.h
@@ -24,7 +24,14 @@ extern void gfs2_quota_unhold(struct gfs2_inode *ip);
extern int gfs2_quota_lock(struct gfs2_inode *ip, kuid_t uid, kgid_t gid);
extern void gfs2_quota_unlock(struct gfs2_inode *ip);
-extern int gfs2_quota_check(struct gfs2_inode *ip, kuid_t uid, kgid_t gid, s64 exp_change);
+extern int gfs2_quota_chk_ret_allow(struct gfs2_inode *ip, kuid_t uid,
+ kgid_t gid, s64 exp_change, u32 *allow);
+static inline int gfs2_quota_check(struct gfs2_inode *ip, kuid_t uid, kgid_t gid,
+ s64 exp_change)
+{
+ return gfs2_quota_chk_ret_allow(ip, uid, gid, exp_change, NULL);
+}
+
extern void gfs2_quota_change(struct gfs2_inode *ip, s64 change,
kuid_t uid, kgid_t gid);
@@ -37,7 +44,8 @@ extern int gfs2_quotad(void *data);
extern void gfs2_wake_up_statfs(struct gfs2_sbd *sdp);
-static inline int gfs2_quota_lock_check(struct gfs2_inode *ip, s64 exp_change)
+static inline int gfs2_quota_lck_chk_ret_allow(struct gfs2_inode *ip,
+ s64 exp_change, u32 *allow)
{
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
int ret;
@@ -48,12 +56,18 @@ static inline int gfs2_quota_lock_check(struct gfs2_inode *ip, s64 exp_change)
return ret;
if (sdp->sd_args.ar_quota != GFS2_QUOTA_ON)
return 0;
- ret = gfs2_quota_check(ip, ip->i_inode.i_uid, ip->i_inode.i_gid, exp_change);
+ ret = gfs2_quota_chk_ret_allow(ip, ip->i_inode.i_uid, ip->i_inode.i_gid,
+ exp_change, allow);
if (ret)
gfs2_quota_unlock(ip);
return ret;
}
+static inline int gfs2_quota_lock_check(struct gfs2_inode *ip, s64 exp_change)
+{
+ return gfs2_quota_lck_chk_ret_allow(ip, exp_change, NULL);
+}
+
extern const struct quotactl_ops gfs2_quotactl_ops;
extern struct shrinker gfs2_qd_shrinker;
extern struct list_lru gfs2_qd_lru;
--
1.8.1.4
next prev parent reply other threads:[~2015-02-12 16:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-12 16:54 [Cluster-devel] [GFS2 PATCH 0/4] fallocate quota fixes Abhi Das
2015-02-12 16:54 ` [Cluster-devel] [GFS2 PATCH 1/4] gfs2: check quota for blocks we're about to allocate Abhi Das
2015-02-12 18:12 ` Andrew Price
2015-02-12 18:23 ` Abhijith Das
2015-02-12 16:54 ` Abhi Das [this message]
2015-02-13 13:34 ` [Cluster-devel] [GFS2 PATCH 2/4] gfs2: add new quota check functions Steven Whitehouse
2015-02-12 16:54 ` [Cluster-devel] [GFS2 PATCH 3/4] gfs2: add new function gfs2_inpl_rsrv_ret_max_avl Abhi Das
2015-02-13 13:36 ` Steven Whitehouse
2015-02-12 16:54 ` [Cluster-devel] [GFS2 PATCH 4/4] gfs2: allow fallocate to max out quotas/fs efficiently Abhi Das
2015-02-12 17:47 ` [Cluster-devel] [GFS2 PATCH 0/4] fallocate quota fixes Bob Peterson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1423760054-63438-3-git-send-email-adas@redhat.com \
--to=adas@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).