1 Index: linux-2.6.27.21-0.1/include/linux/jbd2.h
2 ===================================================================
3 --- linux-2.6.27.21-0.1.orig/include/linux/jbd2.h
4 +++ linux-2.6.27.21-0.1/include/linux/jbd2.h
5 @@ -413,6 +413,27 @@ struct jbd2_inode {
9 +#define HAVE_JOURNAL_CALLBACK_STATUS
11 + * struct journal_callback - Base structure for callback information.
12 + * @jcb_list: list information for other callbacks attached to the same handle.
13 + * @jcb_func: Function to call with this callback structure.
15 + * This struct is a 'seed' structure for a using with your own callback
16 + * structs. If you are using callbacks you must allocate one of these
17 + * or another struct of your own definition which has this struct
18 + * as it's first element and pass it to journal_callback_set().
20 + * This is used internally by jbd2 to maintain callback information.
22 + * See journal_callback_set for more information.
24 +struct journal_callback {
25 + struct list_head jcb_list; /* t_jcb_lock */
26 + void (*jcb_func)(struct journal_callback *jcb, int error);
27 + /* user data goes here */
30 struct jbd2_revoke_table_s;
33 @@ -421,6 +442,7 @@ struct jbd2_revoke_table_s;
34 * @h_transaction: Which compound transaction is this update a part of?
35 * @h_buffer_credits: Number of remaining buffers we are allowed to dirty.
36 * @h_ref: Reference count on this handle
37 + * @h_jcb: List of application registered callbacks for this handle.
38 * @h_err: Field for caller's use to track errors through large fs operations
39 * @h_sync: flag for sync-on-close
40 * @h_jdata: flag to force data journaling
41 @@ -446,6 +468,13 @@ struct handle_s
46 + * List of application registered callbacks for this handle. The
47 + * function(s) will be called after the transaction that this handle is
48 + * part of has been committed to disk. [t_jcb_lock]
50 + struct list_head h_jcb;
52 /* Flags [no locking] */
53 unsigned int h_sync: 1; /* sync-on-close */
54 unsigned int h_jdata: 1; /* force data journaling */
55 @@ -501,6 +530,8 @@ struct transaction_chp_stats_s {
57 * ->j_list_lock (journal_unmap_buffer)
64 @@ -641,6 +672,15 @@ struct transaction_s
69 + * Protects the callback list
71 + spinlock_t t_jcb_lock;
73 + * List of registered callback functions for this transaction.
74 + * Called when the transaction is committed. [t_jcb_lock]
76 + struct list_head t_jcb;
79 struct transaction_run_stats_s {
80 @@ -1044,6 +1084,9 @@ extern int jbd2_journal_stop(handle_t *
81 extern int jbd2_journal_flush (journal_t *);
82 extern void jbd2_journal_lock_updates (journal_t *);
83 extern void jbd2_journal_unlock_updates (journal_t *);
84 +extern void jbd2_journal_callback_set(handle_t *handle,
85 + void (*fn)(struct journal_callback *,int),
86 + struct journal_callback *jcb);
88 extern journal_t * jbd2_journal_init_dev(struct block_device *bdev,
89 struct block_device *fs_dev,
90 Index: linux-2.6.27.21-0.1/fs/jbd2/checkpoint.c
91 ===================================================================
92 --- linux-2.6.27.21-0.1.orig/fs/jbd2/checkpoint.c
93 +++ linux-2.6.27.21-0.1/fs/jbd2/checkpoint.c
94 @@ -728,6 +728,7 @@ void __jbd2_journal_drop_transaction(jou
95 J_ASSERT(transaction->t_checkpoint_list == NULL);
96 J_ASSERT(transaction->t_checkpoint_io_list == NULL);
97 J_ASSERT(transaction->t_updates == 0);
98 + J_ASSERT(list_empty(&transaction->t_jcb));
99 J_ASSERT(journal->j_committing_transaction != transaction);
100 J_ASSERT(journal->j_running_transaction != transaction);
102 Index: linux-2.6.27.21-0.1/fs/jbd2/commit.c
103 ===================================================================
104 --- linux-2.6.27.21-0.1.orig/fs/jbd2/commit.c
105 +++ linux-2.6.27.21-0.1/fs/jbd2/commit.c
106 @@ -805,6 +805,30 @@ wait_for_iobuf:
107 transaction can be removed from any checkpoint list it was on
111 + * Call any callbacks that had been registered for handles in this
112 + * transaction. It is up to the callback to free any allocated
115 + * The spinlocking (t_jcb_lock) here is surely unnecessary...
117 + spin_lock(&commit_transaction->t_jcb_lock);
118 + if (!list_empty(&commit_transaction->t_jcb)) {
119 + struct list_head *p, *n;
120 + int error = is_journal_aborted(journal);
122 + list_for_each_safe(p, n, &commit_transaction->t_jcb) {
123 + struct journal_callback *jcb;
125 + jcb = list_entry(p, struct journal_callback, jcb_list);
127 + spin_unlock(&commit_transaction->t_jcb_lock);
128 + jcb->jcb_func(jcb, error);
129 + spin_lock(&commit_transaction->t_jcb_lock);
132 + spin_unlock(&commit_transaction->t_jcb_lock);
134 jbd_debug(3, "JBD: commit phase 6\n");
136 J_ASSERT(list_empty(&commit_transaction->t_inode_list));
137 Index: linux-2.6.27.21-0.1/fs/jbd2/journal.c
138 ===================================================================
139 --- linux-2.6.27.21-0.1.orig/fs/jbd2/journal.c
140 +++ linux-2.6.27.21-0.1/fs/jbd2/journal.c
141 @@ -84,6 +84,8 @@ EXPORT_SYMBOL(jbd2_journal_file_inode);
142 EXPORT_SYMBOL(jbd2_journal_init_jbd_inode);
143 EXPORT_SYMBOL(jbd2_journal_release_jbd_inode);
144 EXPORT_SYMBOL(jbd2_journal_begin_ordered_truncate);
145 +EXPORT_SYMBOL(jbd2_journal_callback_set);
146 +EXPORT_SYMBOL(jbd2_journal_bmap);
148 static int journal_convert_superblock_v1(journal_t *, journal_superblock_t *);
149 static void __journal_abort_soft (journal_t *journal, int errno);
150 Index: linux-2.6.27.21-0.1/fs/jbd2/transaction.c
151 ===================================================================
152 --- linux-2.6.27.21-0.1.orig/fs/jbd2/transaction.c
153 +++ linux-2.6.27.21-0.1/fs/jbd2/transaction.c
154 @@ -50,7 +50,9 @@ jbd2_get_transaction(journal_t *journal,
155 transaction->t_state = T_RUNNING;
156 transaction->t_tid = journal->j_transaction_sequence++;
157 transaction->t_expires = jiffies + journal->j_commit_interval;
158 + INIT_LIST_HEAD(&transaction->t_jcb);
159 spin_lock_init(&transaction->t_handle_lock);
160 + spin_lock_init(&transaction->t_jcb_lock);
161 INIT_LIST_HEAD(&transaction->t_inode_list);
163 /* Set up the commit timer for the new transaction. */
164 @@ -252,6 +254,7 @@ static handle_t *new_handle(int nblocks)
165 memset(handle, 0, sizeof(*handle));
166 handle->h_buffer_credits = nblocks;
168 + INIT_LIST_HEAD(&handle->h_jcb);
170 lockdep_init_map(&handle->h_lockdep_map, "jbd2_handle",
171 &jbd2_handle_key, 0);
172 @@ -1173,6 +1176,36 @@ drop:
176 + * void jbd2_journal_callback_set() - Register a callback function for this handle.
177 + * @handle: handle to attach the callback to.
178 + * @func: function to callback.
179 + * @jcb: structure with additional information required by func() , and
180 + * some space for jbd2 internal information.
182 + * The function will be
183 + * called when the transaction that this handle is part of has been
184 + * committed to disk with the original callback data struct and the
185 + * error status of the journal as parameters. There is no guarantee of
186 + * ordering between handles within a single transaction, nor between
187 + * callbacks registered on the same handle.
189 + * The caller is responsible for allocating the journal_callback struct.
190 + * This is to allow the caller to add as much extra data to the callback
191 + * as needed, but reduce the overhead of multiple allocations. The caller
192 + * allocated struct must start with a struct journal_callback at offset 0,
193 + * and has the caller-specific data afterwards.
195 +void jbd2_journal_callback_set(handle_t *handle,
196 + void (*func)(struct journal_callback *jcb, int error),
197 + struct journal_callback *jcb)
199 + spin_lock(&handle->h_transaction->t_jcb_lock);
200 + list_add_tail(&jcb->jcb_list, &handle->h_jcb);
201 + spin_unlock(&handle->h_transaction->t_jcb_lock);
202 + jcb->jcb_func = func;
206 * int jbd2_journal_stop() - complete a transaction
207 * @handle: tranaction to complete.
209 @@ -1246,6 +1279,11 @@ int jbd2_journal_stop(handle_t *handle)
210 wake_up(&journal->j_wait_transaction_locked);
213 + /* Move callbacks from the handle to the transaction. */
214 + spin_lock(&transaction->t_jcb_lock);
215 + list_splice(&handle->h_jcb, &transaction->t_jcb);
216 + spin_unlock(&transaction->t_jcb_lock);
219 * If the handle is marked SYNC, we need to set another commit
220 * going! We also want to force a commit if the current