]> Pileus Git - ~andy/linux/blobdiff - include/linux/jbd2.h
jbd2: cleanup needed free block estimates when starting a transaction
[~andy/linux] / include / linux / jbd2.h
index 6e051f472edb6db62f7e292b71c3bc5b2c5575f5..7a1f6cd864c8c4876c41535144bad214005291c4 100644 (file)
@@ -302,6 +302,34 @@ typedef struct journal_superblock_s
 
 #include <linux/fs.h>
 #include <linux/sched.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_Shadow,              /* IO on shadow buffer is running */
+       BH_Verified,            /* Metadata block has been verified ok */
+       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)
+BUFFER_FNS(Shadow, shadow)
+BUFFER_FNS(Verified, verified)
+
 #include <linux/jbd_common.h>
 
 #define J_ASSERT(assert)       BUG_ON(!(assert))
@@ -523,12 +551,6 @@ struct transaction_s
         */
        struct journal_head     *t_checkpoint_io_list;
 
-       /*
-        * Doubly-linked circular list of temporary buffers currently undergoing
-        * IO in the log [j_list_lock]
-        */
-       struct journal_head     *t_iobuf_list;
-
        /*
         * Doubly-linked circular list of metadata buffers being shadowed by log
         * IO.  The IO buffers on the iobuf list and the shadow buffers on this
@@ -536,12 +558,6 @@ struct transaction_s
         */
        struct journal_head     *t_shadow_list;
 
-       /*
-        * Doubly-linked circular list of control buffers being written to the
-        * log. [j_list_lock]
-        */
-       struct journal_head     *t_log_list;
-
        /*
         * List of inodes whose data we've modified in data=ordered mode.
         * [j_list_lock]
@@ -991,9 +1007,17 @@ extern void __jbd2_journal_file_buffer(struct journal_head *, transaction_t *, i
 extern void __journal_free_buffer(struct journal_head *bh);
 extern void jbd2_journal_file_buffer(struct journal_head *, transaction_t *, int);
 extern void __journal_clean_data_list(transaction_t *transaction);
+static inline void jbd2_file_log_bh(struct list_head *head, struct buffer_head *bh)
+{
+       list_add_tail(&bh->b_assoc_buffers, head);
+}
+static inline void jbd2_unfile_log_bh(struct buffer_head *bh)
+{
+       list_del_init(&bh->b_assoc_buffers);
+}
 
 /* Log buffer allocation */
-extern struct journal_head * jbd2_journal_get_descriptor_buffer(journal_t *);
+struct buffer_head *jbd2_journal_get_descriptor_buffer(journal_t *journal);
 int jbd2_journal_next_log_block(journal_t *, unsigned long long *);
 int jbd2_journal_get_log_tail(journal_t *journal, tid_t *tid,
                              unsigned long *block);
@@ -1039,11 +1063,10 @@ extern void jbd2_buffer_abort_trigger(struct journal_head *jh,
                                      struct jbd2_buffer_trigger_type *triggers);
 
 /* Buffer IO */
-extern int
-jbd2_journal_write_metadata_buffer(transaction_t         *transaction,
-                             struct journal_head  *jh_in,
-                             struct journal_head **jh_out,
-                             unsigned long long   blocknr);
+extern int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
+                                             struct journal_head *jh_in,
+                                             struct buffer_head **bh_out,
+                                             sector_t blocknr);
 
 /* Transaction locking */
 extern void            __wait_on_journal (journal_t *);
@@ -1090,7 +1113,7 @@ extern int         jbd2_journal_dirty_metadata (handle_t *, struct buffer_head *);
 extern int      jbd2_journal_forget (handle_t *, struct buffer_head *);
 extern void     journal_sync_buffer (struct buffer_head *);
 extern int      jbd2_journal_invalidatepage(journal_t *,
-                               struct page *, unsigned long);
+                               struct page *, unsigned int, unsigned int);
 extern int      jbd2_journal_try_to_free_buffers(journal_t *, struct page *, gfp_t);
 extern int      jbd2_journal_stop(handle_t *);
 extern int      jbd2_journal_flush (journal_t *);
@@ -1178,8 +1201,10 @@ extern int          jbd2_journal_init_revoke_caches(void);
 extern void       jbd2_journal_destroy_revoke(journal_t *);
 extern int        jbd2_journal_revoke (handle_t *, unsigned long long, struct buffer_head *);
 extern int        jbd2_journal_cancel_revoke(handle_t *, struct journal_head *);
-extern void       jbd2_journal_write_revoke_records(journal_t *,
-                                                    transaction_t *, int);
+extern void       jbd2_journal_write_revoke_records(journal_t *journal,
+                                                    transaction_t *transaction,
+                                                    struct list_head *log_bufs,
+                                                    int write_op);
 
 /* Recovery revoke support */
 extern int     jbd2_journal_set_revoke(journal_t *, unsigned long long, tid_t);
@@ -1195,7 +1220,6 @@ extern void       jbd2_clear_buffer_revoked_flags(journal_t *journal);
  * transitions on demand.
  */
 
-int __jbd2_log_space_left(journal_t *); /* Called with journal locked */
 int jbd2_log_start_commit(journal_t *journal, tid_t tid);
 int __jbd2_log_start_commit(journal_t *journal, tid_t tid);
 int jbd2_journal_start_commit(journal_t *journal, tid_t *tid);
@@ -1265,17 +1289,38 @@ static inline int tid_geq(tid_t x, tid_t y)
 extern int jbd2_journal_blocks_per_page(struct inode *inode);
 extern size_t journal_tag_bytes(journal_t *journal);
 
+/*
+ * We reserve t_outstanding_credits >> JBD2_CONTROL_BLOCKS_SHIFT for
+ * transaction control blocks.
+ */
+#define JBD2_CONTROL_BLOCKS_SHIFT 5
+
 /*
  * Return the minimum number of blocks which must be free in the journal
  * before a new transaction may be started.  Must be called under j_state_lock.
  */
-static inline int jbd_space_needed(journal_t *journal)
+static inline int jbd2_space_needed(journal_t *journal)
 {
        int nblocks = journal->j_max_transaction_buffers;
-       if (journal->j_committing_transaction)
-               nblocks += atomic_read(&journal->j_committing_transaction->
-                                      t_outstanding_credits);
-       return nblocks;
+       return nblocks + (nblocks >> JBD2_CONTROL_BLOCKS_SHIFT);
+}
+
+/*
+ * Return number of free blocks in the log. Must be called under j_state_lock.
+ */
+static inline unsigned long jbd2_log_space_left(journal_t *journal)
+{
+       /* Allow for rounding errors */
+       unsigned long free = journal->j_free - 32;
+
+       if (journal->j_committing_transaction) {
+               unsigned long committing = atomic_read(&journal->
+                       j_committing_transaction->t_outstanding_credits);
+
+               /* Transaction + control blocks */
+               free -= committing + (committing >> JBD2_CONTROL_BLOCKS_SHIFT);
+       }
+       return free;
 }
 
 /*
@@ -1286,11 +1331,9 @@ static inline int jbd_space_needed(journal_t *journal)
 #define BJ_None                0       /* Not journaled */
 #define BJ_Metadata    1       /* Normal journaled metadata */
 #define BJ_Forget      2       /* Buffer superseded by this transaction */
-#define BJ_IO          3       /* Buffer is for temporary IO use */
-#define BJ_Shadow      4       /* Buffer contents being shadowed to the log */
-#define BJ_LogCtl      5       /* Buffer contains log descriptors */
-#define BJ_Reserved    6       /* Buffer is reserved for access by journal */
-#define BJ_Types       7
+#define BJ_Shadow      3       /* Buffer contents being shadowed to the log */
+#define BJ_Reserved    4       /* Buffer is reserved for access by journal */
+#define BJ_Types       5
 
 extern int jbd_blocks_per_page(struct inode *inode);