]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
gfs2: Encode glock holding and retry flags in journal_info
authorAndreas Gruenbacher <agruenba@redhat.com>
Wed, 12 May 2021 16:07:08 +0000 (18:07 +0200)
committerAndreas Gruenbacher <agruenba@redhat.com>
Wed, 2 Jun 2021 09:47:03 +0000 (11:47 +0200)
Use the lowest two bits in current->journal_info to encode when
we're holding a glock and when an operation holding a glock
needs to be retried.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
fs/gfs2/incore.h

index aa8d1a23132d4493db6e27e9bcff85c459fa1b99..e32433df119c9e06afd4b8e0899095bf46e1d8ac 100644 (file)
@@ -871,14 +871,45 @@ static inline unsigned gfs2_max_stuffed_size(const struct gfs2_inode *ip)
        return GFS2_SB(&ip->i_inode)->sd_sb.sb_bsize - sizeof(struct gfs2_dinode);
 }
 
+/*
+ * Transactions are always memory aligned, so we use bit 0 of
+ * current->journal_info to indicate when we're holding a glock and so taking
+ * random additional glocks might deadlock, and bit 1 to indicate when such an
+ * operation needs to be retried after dropping and re-acquiring that "outer"
+ * glock.
+ */
+
 static inline struct gfs2_trans *current_trans(void)
 {
-       return current->journal_info;
+       return (void *)((long)current->journal_info & ~3);
 }
 
 static inline void set_current_trans(struct gfs2_trans *tr)
 {
-       current->journal_info = tr;
+       long flags = (long)current->journal_info & 3;
+       current->journal_info = (void *)((long)tr | flags);
+}
+
+static inline bool current_holds_glock(void)
+{
+       return (long)current->journal_info & 1;
+}
+
+static inline bool current_needs_retry(void)
+{
+       return (long)current->journal_info & 2;
+}
+
+static inline void set_current_holds_glock(bool b)
+{
+       current->journal_info =
+               (void *)(((long)current->journal_info & ~1) | b);
+}
+
+static inline void set_current_needs_retry(bool b)
+{
+       current->journal_info =
+               (void *)(((long)current->journal_info & ~2) | (b << 1));
 }
 
 #endif /* __INCORE_DOT_H__ */