Patchwork fs: jdb/jbd2: Put identical code in a common header

login
register
mail settings
Submitter Thomas Gleixner
Date Oct. 5, 2011, 11:29 a.m.
Message ID <alpine.LFD.2.02.1110051328010.18778@ionos>
Download mbox | patch
Permalink /patch/117822/
State Accepted
Headers show

Comments

Thomas Gleixner - Oct. 5, 2011, 11:29 a.m.
The state bits and the lock functions of jbd and jbd2 are
identical. Share them.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/jbd.h        |   64 ------------------------------------------
 include/linux/jbd2.h       |   65 -------------------------------------------
 include/linux/jbd_common.h |   68 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+), 127 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jan Kara - Oct. 18, 2011, 8:40 p.m.
On Wed 05-10-11 13:29:29, Thomas Gleixner wrote:
> The state bits and the lock functions of jbd and jbd2 are
> identical. Share them.
  Hum, Ted, I don't think this got picked up. What's your opinion?

								Honza

> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> ---
>  include/linux/jbd.h        |   64 ------------------------------------------
>  include/linux/jbd2.h       |   65 -------------------------------------------
>  include/linux/jbd_common.h |   68 +++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 70 insertions(+), 127 deletions(-)
> 
> Index: linux-2.6/include/linux/jbd.h
> ===================================================================
> --- linux-2.6.orig/include/linux/jbd.h
> +++ linux-2.6/include/linux/jbd.h
> @@ -244,6 +244,7 @@ typedef struct journal_superblock_s
>  
>  #include <linux/fs.h>
>  #include <linux/sched.h>
> +#include <linux/jbd_common.h>
>  
>  #define J_ASSERT(assert)	BUG_ON(!(assert))
>  
> @@ -270,69 +271,6 @@ typedef struct journal_superblock_s
>  #define J_EXPECT_JH(jh, expr, why...)	__journal_expect(expr, ## why)
>  #endif
>  
> -enum jbd_state_bits {
> -	BH_JBD			/* Has an attached ext3 journal_head */
> -	  = BH_PrivateStart,
> -	BH_JWrite,		/* Being written to log (@@@ DEBUGGING) */
> -	BH_Freed,		/* Has been freed (truncated) */
> -	BH_Revoked,		/* Has been revoked from the log */
> -	BH_RevokeValid,		/* Revoked flag is valid */
> -	BH_JBDDirty,		/* Is dirty but journaled */
> -	BH_State,		/* Pins most journal_head state */
> -	BH_JournalHead,		/* Pins bh->b_private and jh->b_bh */
> -	BH_Unshadow,		/* Dummy bit, for BJ_Shadow wakeup filtering */
> -};
> -
> -BUFFER_FNS(JBD, jbd)
> -BUFFER_FNS(JWrite, jwrite)
> -BUFFER_FNS(JBDDirty, jbddirty)
> -TAS_BUFFER_FNS(JBDDirty, jbddirty)
> -BUFFER_FNS(Revoked, revoked)
> -TAS_BUFFER_FNS(Revoked, revoked)
> -BUFFER_FNS(RevokeValid, revokevalid)
> -TAS_BUFFER_FNS(RevokeValid, revokevalid)
> -BUFFER_FNS(Freed, freed)
> -
> -static inline struct buffer_head *jh2bh(struct journal_head *jh)
> -{
> -	return jh->b_bh;
> -}
> -
> -static inline struct journal_head *bh2jh(struct buffer_head *bh)
> -{
> -	return bh->b_private;
> -}
> -
> -static inline void jbd_lock_bh_state(struct buffer_head *bh)
> -{
> -	bit_spin_lock(BH_State, &bh->b_state);
> -}
> -
> -static inline int jbd_trylock_bh_state(struct buffer_head *bh)
> -{
> -	return bit_spin_trylock(BH_State, &bh->b_state);
> -}
> -
> -static inline int jbd_is_locked_bh_state(struct buffer_head *bh)
> -{
> -	return bit_spin_is_locked(BH_State, &bh->b_state);
> -}
> -
> -static inline void jbd_unlock_bh_state(struct buffer_head *bh)
> -{
> -	bit_spin_unlock(BH_State, &bh->b_state);
> -}
> -
> -static inline void jbd_lock_bh_journal_head(struct buffer_head *bh)
> -{
> -	bit_spin_lock(BH_JournalHead, &bh->b_state);
> -}
> -
> -static inline void jbd_unlock_bh_journal_head(struct buffer_head *bh)
> -{
> -	bit_spin_unlock(BH_JournalHead, &bh->b_state);
> -}
> -
>  struct jbd_revoke_table_s;
>  
>  /**
> Index: linux-2.6/include/linux/jbd2.h
> ===================================================================
> --- linux-2.6.orig/include/linux/jbd2.h
> +++ linux-2.6/include/linux/jbd2.h
> @@ -275,6 +275,7 @@ typedef struct journal_superblock_s
>  
>  #include <linux/fs.h>
>  #include <linux/sched.h>
> +#include <linux/jbd_common.h>
>  
>  #define J_ASSERT(assert)	BUG_ON(!(assert))
>  
> @@ -302,70 +303,6 @@ typedef struct journal_superblock_s
>  #define J_EXPECT_JH(jh, expr, why...)	__journal_expect(expr, ## why)
>  #endif
>  
> -enum jbd_state_bits {
> -	BH_JBD			/* Has an attached ext3 journal_head */
> -	  = BH_PrivateStart,
> -	BH_JWrite,		/* Being written to log (@@@ DEBUGGING) */
> -	BH_Freed,		/* Has been freed (truncated) */
> -	BH_Revoked,		/* Has been revoked from the log */
> -	BH_RevokeValid,		/* Revoked flag is valid */
> -	BH_JBDDirty,		/* Is dirty but journaled */
> -	BH_State,		/* Pins most journal_head state */
> -	BH_JournalHead,		/* Pins bh->b_private and jh->b_bh */
> -	BH_Unshadow,		/* Dummy bit, for BJ_Shadow wakeup filtering */
> -	BH_JBDPrivateStart,	/* First bit available for private use by FS */
> -};
> -
> -BUFFER_FNS(JBD, jbd)
> -BUFFER_FNS(JWrite, jwrite)
> -BUFFER_FNS(JBDDirty, jbddirty)
> -TAS_BUFFER_FNS(JBDDirty, jbddirty)
> -BUFFER_FNS(Revoked, revoked)
> -TAS_BUFFER_FNS(Revoked, revoked)
> -BUFFER_FNS(RevokeValid, revokevalid)
> -TAS_BUFFER_FNS(RevokeValid, revokevalid)
> -BUFFER_FNS(Freed, freed)
> -
> -static inline struct buffer_head *jh2bh(struct journal_head *jh)
> -{
> -	return jh->b_bh;
> -}
> -
> -static inline struct journal_head *bh2jh(struct buffer_head *bh)
> -{
> -	return bh->b_private;
> -}
> -
> -static inline void jbd_lock_bh_state(struct buffer_head *bh)
> -{
> -	bit_spin_lock(BH_State, &bh->b_state);
> -}
> -
> -static inline int jbd_trylock_bh_state(struct buffer_head *bh)
> -{
> -	return bit_spin_trylock(BH_State, &bh->b_state);
> -}
> -
> -static inline int jbd_is_locked_bh_state(struct buffer_head *bh)
> -{
> -	return bit_spin_is_locked(BH_State, &bh->b_state);
> -}
> -
> -static inline void jbd_unlock_bh_state(struct buffer_head *bh)
> -{
> -	bit_spin_unlock(BH_State, &bh->b_state);
> -}
> -
> -static inline void jbd_lock_bh_journal_head(struct buffer_head *bh)
> -{
> -	bit_spin_lock(BH_JournalHead, &bh->b_state);
> -}
> -
> -static inline void jbd_unlock_bh_journal_head(struct buffer_head *bh)
> -{
> -	bit_spin_unlock(BH_JournalHead, &bh->b_state);
> -}
> -
>  /* Flags in jbd_inode->i_flags */
>  #define __JI_COMMIT_RUNNING 0
>  /* Commit of the inode data in progress. We use this flag to protect us from
> Index: linux-2.6/include/linux/jbd_common.h
> ===================================================================
> --- /dev/null
> +++ linux-2.6/include/linux/jbd_common.h
> @@ -0,0 +1,68 @@
> +#ifndef _LINUX_JBD_STATE_H
> +#define _LINUX_JBD_STATE_H
> +
> +enum jbd_state_bits {
> +	BH_JBD			/* Has an attached ext3 journal_head */
> +	  = BH_PrivateStart,
> +	BH_JWrite,		/* Being written to log (@@@ DEBUGGING) */
> +	BH_Freed,		/* Has been freed (truncated) */
> +	BH_Revoked,		/* Has been revoked from the log */
> +	BH_RevokeValid,		/* Revoked flag is valid */
> +	BH_JBDDirty,		/* Is dirty but journaled */
> +	BH_State,		/* Pins most journal_head state */
> +	BH_JournalHead,		/* Pins bh->b_private and jh->b_bh */
> +	BH_Unshadow,		/* Dummy bit, for BJ_Shadow wakeup filtering */
> +	BH_JBDPrivateStart,	/* First bit available for private use by FS */
> +};
> +
> +BUFFER_FNS(JBD, jbd)
> +BUFFER_FNS(JWrite, jwrite)
> +BUFFER_FNS(JBDDirty, jbddirty)
> +TAS_BUFFER_FNS(JBDDirty, jbddirty)
> +BUFFER_FNS(Revoked, revoked)
> +TAS_BUFFER_FNS(Revoked, revoked)
> +BUFFER_FNS(RevokeValid, revokevalid)
> +TAS_BUFFER_FNS(RevokeValid, revokevalid)
> +BUFFER_FNS(Freed, freed)
> +
> +static inline struct buffer_head *jh2bh(struct journal_head *jh)
> +{
> +	return jh->b_bh;
> +}
> +
> +static inline struct journal_head *bh2jh(struct buffer_head *bh)
> +{
> +	return bh->b_private;
> +}
> +
> +static inline void jbd_lock_bh_state(struct buffer_head *bh)
> +{
> +	bit_spin_lock(BH_State, &bh->b_state);
> +}
> +
> +static inline int jbd_trylock_bh_state(struct buffer_head *bh)
> +{
> +	return bit_spin_trylock(BH_State, &bh->b_state);
> +}
> +
> +static inline int jbd_is_locked_bh_state(struct buffer_head *bh)
> +{
> +	return bit_spin_is_locked(BH_State, &bh->b_state);
> +}
> +
> +static inline void jbd_unlock_bh_state(struct buffer_head *bh)
> +{
> +	bit_spin_unlock(BH_State, &bh->b_state);
> +}
> +
> +static inline void jbd_lock_bh_journal_head(struct buffer_head *bh)
> +{
> +	bit_spin_lock(BH_JournalHead, &bh->b_state);
> +}
> +
> +static inline void jbd_unlock_bh_journal_head(struct buffer_head *bh)
> +{
> +	bit_spin_unlock(BH_JournalHead, &bh->b_state);
> +}
> +
> +#endif
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
Theodore Ts'o - Oct. 27, 2011, 9:13 a.m.
On Tue, Oct 18, 2011 at 10:40:31PM +0200, Jan Kara wrote:
> On Wed 05-10-11 13:29:29, Thomas Gleixner wrote:
> > The state bits and the lock functions of jbd and jbd2 are
> > identical. Share them.
>   Hum, Ted, I don't think this got picked up. What's your opinion?

It seems reasonable to me.  Factoring out common code is a good
though, although inline functions won't save any text space and since
this part of the jbd header files are rarely changed, so the
maintainability advantages are reduced.

I'll take the patch and include it in the ext4 tree.

     	      	    		   - Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

Index: linux-2.6/include/linux/jbd.h
===================================================================
--- linux-2.6.orig/include/linux/jbd.h
+++ linux-2.6/include/linux/jbd.h
@@ -244,6 +244,7 @@  typedef struct journal_superblock_s
 
 #include <linux/fs.h>
 #include <linux/sched.h>
+#include <linux/jbd_common.h>
 
 #define J_ASSERT(assert)	BUG_ON(!(assert))
 
@@ -270,69 +271,6 @@  typedef struct journal_superblock_s
 #define J_EXPECT_JH(jh, expr, why...)	__journal_expect(expr, ## why)
 #endif
 
-enum jbd_state_bits {
-	BH_JBD			/* Has an attached ext3 journal_head */
-	  = BH_PrivateStart,
-	BH_JWrite,		/* Being written to log (@@@ DEBUGGING) */
-	BH_Freed,		/* Has been freed (truncated) */
-	BH_Revoked,		/* Has been revoked from the log */
-	BH_RevokeValid,		/* Revoked flag is valid */
-	BH_JBDDirty,		/* Is dirty but journaled */
-	BH_State,		/* Pins most journal_head state */
-	BH_JournalHead,		/* Pins bh->b_private and jh->b_bh */
-	BH_Unshadow,		/* Dummy bit, for BJ_Shadow wakeup filtering */
-};
-
-BUFFER_FNS(JBD, jbd)
-BUFFER_FNS(JWrite, jwrite)
-BUFFER_FNS(JBDDirty, jbddirty)
-TAS_BUFFER_FNS(JBDDirty, jbddirty)
-BUFFER_FNS(Revoked, revoked)
-TAS_BUFFER_FNS(Revoked, revoked)
-BUFFER_FNS(RevokeValid, revokevalid)
-TAS_BUFFER_FNS(RevokeValid, revokevalid)
-BUFFER_FNS(Freed, freed)
-
-static inline struct buffer_head *jh2bh(struct journal_head *jh)
-{
-	return jh->b_bh;
-}
-
-static inline struct journal_head *bh2jh(struct buffer_head *bh)
-{
-	return bh->b_private;
-}
-
-static inline void jbd_lock_bh_state(struct buffer_head *bh)
-{
-	bit_spin_lock(BH_State, &bh->b_state);
-}
-
-static inline int jbd_trylock_bh_state(struct buffer_head *bh)
-{
-	return bit_spin_trylock(BH_State, &bh->b_state);
-}
-
-static inline int jbd_is_locked_bh_state(struct buffer_head *bh)
-{
-	return bit_spin_is_locked(BH_State, &bh->b_state);
-}
-
-static inline void jbd_unlock_bh_state(struct buffer_head *bh)
-{
-	bit_spin_unlock(BH_State, &bh->b_state);
-}
-
-static inline void jbd_lock_bh_journal_head(struct buffer_head *bh)
-{
-	bit_spin_lock(BH_JournalHead, &bh->b_state);
-}
-
-static inline void jbd_unlock_bh_journal_head(struct buffer_head *bh)
-{
-	bit_spin_unlock(BH_JournalHead, &bh->b_state);
-}
-
 struct jbd_revoke_table_s;
 
 /**
Index: linux-2.6/include/linux/jbd2.h
===================================================================
--- linux-2.6.orig/include/linux/jbd2.h
+++ linux-2.6/include/linux/jbd2.h
@@ -275,6 +275,7 @@  typedef struct journal_superblock_s
 
 #include <linux/fs.h>
 #include <linux/sched.h>
+#include <linux/jbd_common.h>
 
 #define J_ASSERT(assert)	BUG_ON(!(assert))
 
@@ -302,70 +303,6 @@  typedef struct journal_superblock_s
 #define J_EXPECT_JH(jh, expr, why...)	__journal_expect(expr, ## why)
 #endif
 
-enum jbd_state_bits {
-	BH_JBD			/* Has an attached ext3 journal_head */
-	  = BH_PrivateStart,
-	BH_JWrite,		/* Being written to log (@@@ DEBUGGING) */
-	BH_Freed,		/* Has been freed (truncated) */
-	BH_Revoked,		/* Has been revoked from the log */
-	BH_RevokeValid,		/* Revoked flag is valid */
-	BH_JBDDirty,		/* Is dirty but journaled */
-	BH_State,		/* Pins most journal_head state */
-	BH_JournalHead,		/* Pins bh->b_private and jh->b_bh */
-	BH_Unshadow,		/* Dummy bit, for BJ_Shadow wakeup filtering */
-	BH_JBDPrivateStart,	/* First bit available for private use by FS */
-};
-
-BUFFER_FNS(JBD, jbd)
-BUFFER_FNS(JWrite, jwrite)
-BUFFER_FNS(JBDDirty, jbddirty)
-TAS_BUFFER_FNS(JBDDirty, jbddirty)
-BUFFER_FNS(Revoked, revoked)
-TAS_BUFFER_FNS(Revoked, revoked)
-BUFFER_FNS(RevokeValid, revokevalid)
-TAS_BUFFER_FNS(RevokeValid, revokevalid)
-BUFFER_FNS(Freed, freed)
-
-static inline struct buffer_head *jh2bh(struct journal_head *jh)
-{
-	return jh->b_bh;
-}
-
-static inline struct journal_head *bh2jh(struct buffer_head *bh)
-{
-	return bh->b_private;
-}
-
-static inline void jbd_lock_bh_state(struct buffer_head *bh)
-{
-	bit_spin_lock(BH_State, &bh->b_state);
-}
-
-static inline int jbd_trylock_bh_state(struct buffer_head *bh)
-{
-	return bit_spin_trylock(BH_State, &bh->b_state);
-}
-
-static inline int jbd_is_locked_bh_state(struct buffer_head *bh)
-{
-	return bit_spin_is_locked(BH_State, &bh->b_state);
-}
-
-static inline void jbd_unlock_bh_state(struct buffer_head *bh)
-{
-	bit_spin_unlock(BH_State, &bh->b_state);
-}
-
-static inline void jbd_lock_bh_journal_head(struct buffer_head *bh)
-{
-	bit_spin_lock(BH_JournalHead, &bh->b_state);
-}
-
-static inline void jbd_unlock_bh_journal_head(struct buffer_head *bh)
-{
-	bit_spin_unlock(BH_JournalHead, &bh->b_state);
-}
-
 /* Flags in jbd_inode->i_flags */
 #define __JI_COMMIT_RUNNING 0
 /* Commit of the inode data in progress. We use this flag to protect us from
Index: linux-2.6/include/linux/jbd_common.h
===================================================================
--- /dev/null
+++ linux-2.6/include/linux/jbd_common.h
@@ -0,0 +1,68 @@ 
+#ifndef _LINUX_JBD_STATE_H
+#define _LINUX_JBD_STATE_H
+
+enum jbd_state_bits {
+	BH_JBD			/* Has an attached ext3 journal_head */
+	  = BH_PrivateStart,
+	BH_JWrite,		/* Being written to log (@@@ DEBUGGING) */
+	BH_Freed,		/* Has been freed (truncated) */
+	BH_Revoked,		/* Has been revoked from the log */
+	BH_RevokeValid,		/* Revoked flag is valid */
+	BH_JBDDirty,		/* Is dirty but journaled */
+	BH_State,		/* Pins most journal_head state */
+	BH_JournalHead,		/* Pins bh->b_private and jh->b_bh */
+	BH_Unshadow,		/* Dummy bit, for BJ_Shadow wakeup filtering */
+	BH_JBDPrivateStart,	/* First bit available for private use by FS */
+};
+
+BUFFER_FNS(JBD, jbd)
+BUFFER_FNS(JWrite, jwrite)
+BUFFER_FNS(JBDDirty, jbddirty)
+TAS_BUFFER_FNS(JBDDirty, jbddirty)
+BUFFER_FNS(Revoked, revoked)
+TAS_BUFFER_FNS(Revoked, revoked)
+BUFFER_FNS(RevokeValid, revokevalid)
+TAS_BUFFER_FNS(RevokeValid, revokevalid)
+BUFFER_FNS(Freed, freed)
+
+static inline struct buffer_head *jh2bh(struct journal_head *jh)
+{
+	return jh->b_bh;
+}
+
+static inline struct journal_head *bh2jh(struct buffer_head *bh)
+{
+	return bh->b_private;
+}
+
+static inline void jbd_lock_bh_state(struct buffer_head *bh)
+{
+	bit_spin_lock(BH_State, &bh->b_state);
+}
+
+static inline int jbd_trylock_bh_state(struct buffer_head *bh)
+{
+	return bit_spin_trylock(BH_State, &bh->b_state);
+}
+
+static inline int jbd_is_locked_bh_state(struct buffer_head *bh)
+{
+	return bit_spin_is_locked(BH_State, &bh->b_state);
+}
+
+static inline void jbd_unlock_bh_state(struct buffer_head *bh)
+{
+	bit_spin_unlock(BH_State, &bh->b_state);
+}
+
+static inline void jbd_lock_bh_journal_head(struct buffer_head *bh)
+{
+	bit_spin_lock(BH_JournalHead, &bh->b_state);
+}
+
+static inline void jbd_unlock_bh_journal_head(struct buffer_head *bh)
+{
+	bit_spin_unlock(BH_JournalHead, &bh->b_state);
+}
+
+#endif