xfs
[Top] [All Lists]

[PATCH 4/7] xfs: lockdep annotations for xfs_dqlock2

To: xfs@xxxxxxxxxxx
Subject: [PATCH 4/7] xfs: lockdep annotations for xfs_dqlock2
From: Christoph Hellwig <hch@xxxxxxxxxxxxx>
Date: Fri, 09 Jan 2009 17:11:08 -0500
References: <20090109221104.237540000@xxxxxxxxxxxxxxxxxxxxxx>
User-agent: quilt/0.46-1
xfs_dqlock2 locks two xfs_dquots, which is fine as it always locks the
dquot with the lower id first.  Use mutex_lock_nested to tell lockdep 
about this fact.


Signed-off-by: Christoph Hellwig <hch@xxxxxx>

Index: xfs/fs/xfs/quota/xfs_dquot.c
===================================================================
--- xfs.orig/fs/xfs/quota/xfs_dquot.c   2008-12-29 11:28:54.459613573 +0100
+++ xfs/fs/xfs/quota/xfs_dquot.c        2008-12-29 11:29:31.037738842 +0100
@@ -1383,6 +1383,12 @@ xfs_dqunlock_nonotify(
        mutex_unlock(&(dqp->q_qlock));
 }
 
+/*
+ * Lock two xfs_dquot structures.
+ *
+ * To avoid deadlocks we always lock the quota structure with
+ * the lowerd id first.
+ */
 void
 xfs_dqlock2(
        xfs_dquot_t     *d1,
@@ -1393,10 +1399,10 @@ xfs_dqlock2(
                if (be32_to_cpu(d1->q_core.d_id) >
                    be32_to_cpu(d2->q_core.d_id)) {
                        xfs_dqlock(d2);
-                       xfs_dqlock(d1);
+                       mutex_lock_nested(&d1->q_qlock, XFS_QLOCK_2ND);
                } else {
                        xfs_dqlock(d1);
-                       xfs_dqlock(d2);
+                       mutex_lock_nested(&d2->q_qlock, XFS_QLOCK_2ND);
                }
        } else {
                if (d1) {
Index: xfs/fs/xfs/quota/xfs_dquot.h
===================================================================
--- xfs.orig/fs/xfs/quota/xfs_dquot.h   2008-12-27 17:55:09.920686659 +0100
+++ xfs/fs/xfs/quota/xfs_dquot.h        2008-12-29 11:29:31.043768451 +0100
@@ -97,6 +97,16 @@ typedef struct xfs_dquot {
 #define dq_hashlist    q_lists.dqm_hashlist
 #define dq_flags       q_lists.dqm_flags
 
+/*
+ * Lock hierachy for q_qlock:
+ *     XFS_QLOCK_NORMAL is the implicit default,
+ *     XFS_QLOCK_DOUBLE is the dquot with the higher id in xfs_dqlock2
+ */
+enum {
+       XFS_QLOCK_NORMAL = 0,
+       XFS_QLOCK_2ND,
+};
+
 #define XFS_DQHOLD(dqp)                ((dqp)->q_nrefs++)
 
 #ifdef DEBUG

-- 

<Prev in Thread] Current Thread [Next in Thread>