mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Whitehouse <swhiteho@redhat.com>
To: cluster-devel@redhat.com, linux-kernel@vger.kernel.org
Cc: Steven Whitehouse <swhiteho@redhat.com>, Abhijith Das <adas@redhat.com>
Subject: [PATCH 17/19] GFS2: Use reflink for quota data cache
Date: Mon,  4 Nov 2013 11:22:28 +0000	[thread overview]
Message-ID: <1383564150-8975-1-git-send-email-swhiteho@redhat.com> (raw)
In-Reply-To: <1383563382-8535-1-git-send-email-swhiteho@redhat.com>

This patch adds reflink support to the quota data cache. It
looks a bit strange because we still don't have a sensible
split in the lookup by id and the lru list. That is coming in
later patches though.

The intent here is just to swap the current ref count for
reflinks in all cases with as little as possible other change.

Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Signed-off-by: Abhijith Das <adas@redhat.com>
Tested-by: Abhijith Das <adas@redhat.com>

diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index bb88e41..9d77804 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -422,7 +422,7 @@ struct gfs2_quota_data {
 	struct list_head qd_list;
 	struct list_head qd_reclaim;
 
-	atomic_t qd_count;
+	struct lockref qd_lockref;
 
 	struct kqid qd_id;
 	unsigned long qd_flags;		/* QDF_... */
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index 4a9726a..ed08911 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -50,6 +50,7 @@
 #include <linux/freezer.h>
 #include <linux/quota.h>
 #include <linux/dqblk_xfs.h>
+#include <linux/lockref.h>
 
 #include "gfs2.h"
 #include "incore.h"
@@ -148,7 +149,8 @@ static int qd_alloc(struct gfs2_sbd *sdp, struct kqid qid,
 	if (!qd)
 		return -ENOMEM;
 
-	atomic_set(&qd->qd_count, 1);
+	qd->qd_lockref.count = 1;
+	spin_lock_init(&qd->qd_lockref.lock);
 	qd->qd_id = qid;
 	qd->qd_slot = -1;
 	INIT_LIST_HEAD(&qd->qd_reclaim);
@@ -180,13 +182,12 @@ static int qd_get(struct gfs2_sbd *sdp, struct kqid qid,
 		spin_lock(&qd_lru_lock);
 		list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) {
 			if (qid_eq(qd->qd_id, qid)) {
-				if (!atomic_read(&qd->qd_count) &&
-				    !list_empty(&qd->qd_reclaim)) {
+				lockref_get(&qd->qd_lockref);
+				if (!list_empty(&qd->qd_reclaim)) {
 					/* Remove it from reclaim list */
 					list_del_init(&qd->qd_reclaim);
 					atomic_dec(&qd_lru_count);
 				}
-				atomic_inc(&qd->qd_count);
 				found = 1;
 				break;
 			}
@@ -222,18 +223,24 @@ static int qd_get(struct gfs2_sbd *sdp, struct kqid qid,
 static void qd_hold(struct gfs2_quota_data *qd)
 {
 	struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
-	gfs2_assert(sdp, atomic_read(&qd->qd_count));
-	atomic_inc(&qd->qd_count);
+	gfs2_assert(sdp, !__lockref_is_dead(&qd->qd_lockref));
+	lockref_get(&qd->qd_lockref);
 }
 
 static void qd_put(struct gfs2_quota_data *qd)
 {
-	if (atomic_dec_and_lock(&qd->qd_count, &qd_lru_lock)) {
+	spin_lock(&qd_lru_lock);
+
+	if (!lockref_put_or_lock(&qd->qd_lockref)) {
+
 		/* Add to the reclaim list */
 		list_add_tail(&qd->qd_reclaim, &qd_lru_list);
 		atomic_inc(&qd_lru_count);
-		spin_unlock(&qd_lru_lock);
+
+		spin_unlock(&qd->qd_lockref.lock);
 	}
+
+	spin_unlock(&qd_lru_lock);
 }
 
 static int slot_get(struct gfs2_quota_data *qd)
@@ -394,8 +401,8 @@ static int qd_check_sync(struct gfs2_sbd *sdp, struct gfs2_quota_data *qd,
 	list_move_tail(&qd->qd_list, &sdp->sd_quota_list);
 
 	set_bit(QDF_LOCKED, &qd->qd_flags);
-	gfs2_assert_warn(sdp, atomic_read(&qd->qd_count));
-	atomic_inc(&qd->qd_count);
+	gfs2_assert_warn(sdp, !__lockref_is_dead(&qd->qd_lockref));
+	lockref_get(&qd->qd_lockref);
 	qd->qd_change_sync = qd->qd_change;
 	gfs2_assert_warn(sdp, qd->qd_slot_count);
 	qd->qd_slot_count++;
@@ -1303,15 +1310,22 @@ void gfs2_quota_cleanup(struct gfs2_sbd *sdp)
 	while (!list_empty(head)) {
 		qd = list_entry(head->prev, struct gfs2_quota_data, qd_list);
 
-		if (atomic_read(&qd->qd_count) > 1 ||
-		    (atomic_read(&qd->qd_count) &&
-		     !test_bit(QDF_CHANGE, &qd->qd_flags))) {
+		/*
+		 * To be removed in due course... we should be able to
+		 * ensure that all refs to the qd have done by this point
+		 * so that this rather odd test is not required
+		 */
+		spin_lock(&qd->qd_lockref.lock);
+		if (qd->qd_lockref.count > 1 ||
+		    (qd->qd_lockref.count && !test_bit(QDF_CHANGE, &qd->qd_flags))) {
+			spin_unlock(&qd->qd_lockref.lock);
 			list_move(&qd->qd_list, head);
 			spin_unlock(&qd_lru_lock);
 			schedule();
 			spin_lock(&qd_lru_lock);
 			continue;
 		}
+		spin_unlock(&qd->qd_lockref.lock);
 
 		list_del(&qd->qd_list);
 		/* Also remove if this qd exists in the reclaim list */
@@ -1322,7 +1336,7 @@ void gfs2_quota_cleanup(struct gfs2_sbd *sdp)
 		atomic_dec(&sdp->sd_quota_count);
 		spin_unlock(&qd_lru_lock);
 
-		if (!atomic_read(&qd->qd_count)) {
+		if (!qd->qd_lockref.count) {
 			gfs2_assert_warn(sdp, !qd->qd_change);
 			gfs2_assert_warn(sdp, !qd->qd_slot_count);
 		} else
-- 
1.7.4.4


  parent reply	other threads:[~2013-11-04 11:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-04 11:09 GFS2: Pre-pull patch posting (merge window) Steven Whitehouse
2013-11-04 11:09 ` [PATCH 01/19] GFS2: d_splice_alias() can't return error Steven Whitehouse
2013-11-04 11:09 ` [PATCH 02/19] GFS2: optimize rbm_from_block wrt bi_start Steven Whitehouse
2013-11-04 11:09 ` [PATCH 03/19] GFS2: introduce bi_blocks for optimization Steven Whitehouse
2013-11-04 11:09 ` [PATCH 04/19] GFS2: Do not reset flags on active reservations Steven Whitehouse
2013-11-04 11:09 ` [PATCH 05/19] GFS2: Introduce rbm field bii Steven Whitehouse
2013-11-04 11:09 ` [PATCH 06/19] GFS2: new function gfs2_rbm_incr Steven Whitehouse
2013-11-04 11:09 ` [PATCH 07/19] GFS2: fix dentry leaks Steven Whitehouse
2013-11-04 11:09 ` [PATCH 08/19] GFS2: Clean up reservation removal Steven Whitehouse
2013-11-04 11:09 ` [PATCH 09/19] GFS2: Add allocation parameters structure Steven Whitehouse
2013-11-04 11:09 ` [PATCH 10/19] GFS2: Speed up starting point selection for block allocation Steven Whitehouse
2013-11-04 11:09 ` [PATCH 11/19] GFS2: Move gfs2_icbit_munge into quota.c Steven Whitehouse
2013-11-04 11:09 ` [PATCH 12/19] GFS2: Remove obsolete quota tunable Steven Whitehouse
2013-11-04 11:09 ` [PATCH 13/19] GFS2: Make two similar quota code fragments into a function Steven Whitehouse
2013-11-04 11:09 ` [PATCH 14/19] GFS2: Inline qd_trylock into gfs2_quota_unlock Steven Whitehouse
2013-11-04 11:09 ` [PATCH 15/19] GFS2: Protect quota sync generation Steven Whitehouse
2013-11-04 11:09 ` [PATCH 16/19] GFS2: Use lockref for glocks Steven Whitehouse
2013-11-04 11:22 ` Steven Whitehouse [this message]
2013-11-04 11:22   ` [PATCH 18/19] GFS2: Rename quota qd_lru_lock qd_lock Steven Whitehouse
2013-11-04 11:22   ` [PATCH 19/19] GFS2: Use generic list_lru for quota Steven Whitehouse

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=1383564150-8975-1-git-send-email-swhiteho@redhat.com \
    --to=swhiteho@redhat.com \
    --cc=adas@redhat.com \
    --cc=cluster-devel@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    /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

Powered by JetHome