Skip to contentSkip to conversation

ceph: fix up async vmtruncate race

PATCH New Sage Weil 1 participant 1 message Feb 9, 2010 Ceph client

lore
Share & tools
lore

Sage Weil

author
#0 lore raw

PATCH 1/1 ceph: fix up async vmtruncate race

Use a helper to ensure that we properly maintain the i_truncate_pending counter when we queue an async truncation.

---
 fs/ceph/caps.c  |    4 +---
 fs/ceph/inode.c |   25 ++++++++++++++++++++++---
 2 files changed, 23 insertions(+), 6 deletions(-)
fs/ceph/caps.c +1 -3
index 7f4841c..726f7c8 100644
@@ -2479,9 +2479,7 @@ static void handle_cap_trunc(struct inode *inode,
 	spin_unlock(&inode->i_lock);
 
 	if (queue_trunc)
-		if (queue_work(ceph_client(inode->i_sb)->trunc_wq,
-			       &ci->i_vmtruncate_work))
-			igrab(inode);
+		__ceph_queue_vmtruncate(inode);
 }
 
 /*
fs/ceph/inode.c +22 -3
index e75847d..37f9be8 100644
@@ -675,9 +675,7 @@ no_change:
 
 	/* queue truncate if we saw i_size decrease */
 	if (queue_trunc)
-		if (queue_work(ceph_client(inode->i_sb)->trunc_wq,
-			       &ci->i_vmtruncate_work))
-			igrab(inode);
+		__ceph_queue_vmtruncate(inode);
 
 	/* populate frag tree */
 	/* FIXME: move me up, if/when version reflects fragtree changes */
@@ -1321,6 +1319,27 @@ void ceph_vmtruncate_work(struct work_struct *work)
 }
 
 /*
+ * Queue an async vmtruncate.  If we fail to queue work, decrement the
+ * pending counter (which the caller incremented when we decided to
+ * try to queue).
+ */
+void __ceph_queue_vmtruncate(struct inode *inode)
+{
+	struct ceph_inode_info *ci = ceph_inode(inode);
+
+	if (queue_work(ceph_client(inode->i_sb)->trunc_wq,
+		       &ci->i_vmtruncate_work)) {
+		igrab(inode);
+	} else {
+		spin_lock(&inode->i_lock);
+		ci->i_truncate_pending--;
+		spin_unlock(&inode->i_lock);
+		dout("__ceph_queue_vmtruncate failed to queue, pending=%d\n",
+		     ci->i_truncate_pending);
+	}
+}
+
+/*
  * called with i_mutex held.
  *
  * Make sure any pending truncation is applied before doing anything
Signature · 7 lines
1.5.6.5


------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev