1 This patch is no longer needed for Lustre, since Lustre 2.2. It is kept
2 in the kernel patch series for compatibility with older Lustre releases
3 to simplify the upgrade process so that both the kernel and Lustre do
4 not need to be upgraded at the same time. See Jira issue LU-433.
6 Index: linux-2.6.18-128.1.6/include/linux/jbd2.h
7 ===================================================================
8 --- linux-2.6.18-128.1.6.orig/include/linux/jbd2.h 2009-04-15 08:35:28.000000000 +0530
9 +++ linux-2.6.18-128.1.6/include/linux/jbd2.h 2009-05-28 15:10:18.000000000 +0530
11 bit_spin_unlock(BH_JournalHead, &bh->b_state);
14 +#define HAVE_JOURNAL_CALLBACK_STATUS
16 + * struct journal_callback - Base structure for callback information.
17 + * @jcb_list: list information for other callbacks attached to the same handle.
18 + * @jcb_func: Function to call with this callback structure.
20 + * This struct is a 'seed' structure for a using with your own callback
21 + * structs. If you are using callbacks you must allocate one of these
22 + * or another struct of your own definition which has this struct
23 + * as it's first element and pass it to journal_callback_set().
25 + * This is used internally by jbd2 to maintain callback information.
27 + * See journal_callback_set for more information.
29 +struct journal_callback {
30 + struct list_head jcb_list; /* t_jcb_lock */
31 + void (*jcb_func)(struct journal_callback *jcb, int error);
32 + /* user data goes here */
35 struct jbd2_revoke_table_s;
39 * @h_transaction: Which compound transaction is this update a part of?
40 * @h_buffer_credits: Number of remaining buffers we are allowed to dirty.
41 * @h_ref: Reference count on this handle
42 + * @h_jcb: List of application registered callbacks for this handle.
43 * @h_err: Field for caller's use to track errors through large fs operations
44 * @h_sync: flag for sync-on-close
45 * @h_jdata: flag to force data journaling
51 + * List of application registered callbacks for this handle. The
52 + * function(s) will be called after the transaction that this handle is
53 + * part of has been committed to disk. [t_jcb_lock]
55 + struct list_head h_jcb;
57 /* Flags [no locking] */
58 unsigned int h_sync: 1; /* sync-on-close */
59 unsigned int h_jdata: 1; /* force data journaling */
62 * ->j_list_lock (journal_unmap_buffer)
74 + * Protects the callback list
76 + spinlock_t t_jcb_lock;
78 + * List of registered callback functions for this transaction.
79 + * Called when the transaction is committed. [t_jcb_lock]
81 + struct list_head t_jcb;
83 * For use by the filesystem to store fs-specific data
84 * structures associated with the transaction
86 extern int jbd2_journal_flush (journal_t *);
87 extern void jbd2_journal_lock_updates (journal_t *);
88 extern void jbd2_journal_unlock_updates (journal_t *);
89 +extern void jbd2_journal_callback_set(handle_t *handle,
90 + void (*fn)(struct journal_callback *,int),
91 + struct journal_callback *jcb);
93 extern journal_t * jbd2_journal_init_dev(struct block_device *bdev,
94 struct block_device *fs_dev,
95 Index: linux-2.6.18-128.1.6/fs/jbd2/checkpoint.c
96 ===================================================================
97 --- linux-2.6.18-128.1.6.orig/fs/jbd2/checkpoint.c 2009-04-15 08:35:28.000000000 +0530
98 +++ linux-2.6.18-128.1.6/fs/jbd2/checkpoint.c 2009-05-28 15:10:18.000000000 +0530
100 J_ASSERT(transaction->t_checkpoint_list == NULL);
101 J_ASSERT(transaction->t_checkpoint_io_list == NULL);
102 J_ASSERT(transaction->t_updates == 0);
103 + J_ASSERT(list_empty(&transaction->t_jcb));
104 J_ASSERT(journal->j_committing_transaction != transaction);
105 J_ASSERT(journal->j_running_transaction != transaction);
107 Index: linux-2.6.18-128.1.6/fs/jbd2/commit.c
108 ===================================================================
109 --- linux-2.6.18-164.6.1/fs/jbd2/commit.c 2010-01-21 11:24:52.000000000 +0530
110 +++ linux-2.6.18-164.6.1_new/fs/jbd2/commit.c 2010-01-21 11:26:36.000000000 +0530
111 @@ -832,6 +832,29 @@ wait_for_iobuf:
112 processing: any buffers committed as a result of this
113 transaction can be removed from any checkpoint list it was on
116 + * Call any callbacks that had been registered for handles in this
117 + * transaction. It is up to the callback to free any allocated
120 + * The spinlocking (t_jcb_lock) here is surely unnecessary...
122 + spin_lock(&commit_transaction->t_jcb_lock);
123 + if (!list_empty(&commit_transaction->t_jcb)) {
124 + struct list_head *p, *n;
125 + int error = is_journal_aborted(journal);
127 + list_for_each_safe(p, n, &commit_transaction->t_jcb) {
128 + struct journal_callback *jcb;
130 + jcb = list_entry(p, struct journal_callback, jcb_list);
132 + spin_unlock(&commit_transaction->t_jcb_lock);
133 + jcb->jcb_func(jcb, error);
134 + spin_lock(&commit_transaction->t_jcb_lock);
137 + spin_unlock(&commit_transaction->t_jcb_lock);
139 jbd_debug(3, "JBD: commit phase 6\n");
141 Index: linux-2.6.18-128.1.6/fs/jbd2/journal.c
142 ===================================================================
143 --- linux-2.6.18-128.1.6.orig/fs/jbd2/journal.c 2009-04-15 08:35:28.000000000 +0530
144 +++ linux-2.6.18-128.1.6/fs/jbd2/journal.c 2009-05-28 17:13:35.000000000 +0530
146 EXPORT_SYMBOL(jbd2_journal_init_jbd_inode);
147 EXPORT_SYMBOL(jbd2_journal_release_jbd_inode);
148 EXPORT_SYMBOL(jbd2_journal_begin_ordered_truncate);
149 +EXPORT_SYMBOL(jbd2_journal_callback_set);
150 +EXPORT_SYMBOL(jbd2_journal_bmap);
152 static int journal_convert_superblock_v1(journal_t *, journal_superblock_t *);
153 static void __journal_abort_soft (journal_t *journal, int errno);
154 Index: linux-2.6.18-128.1.6/fs/jbd2/transaction.c
155 ===================================================================
156 --- linux-2.6.18-128.1.6.orig/fs/jbd2/transaction.c 2009-04-15 08:35:28.000000000 +0530
157 +++ linux-2.6.18-128.1.6/fs/jbd2/transaction.c 2009-05-28 15:11:28.000000000 +0530
159 spin_lock_init(&transaction->t_handle_lock);
160 INIT_LIST_HEAD(&transaction->t_inode_list);
161 INIT_LIST_HEAD(&transaction->t_private_list);
162 + INIT_LIST_HEAD(&transaction->t_jcb);
163 + spin_lock_init(&transaction->t_jcb_lock);
166 /* Set up the commit timer for the new transaction. */
167 journal->j_commit_timer.expires = round_jiffies(transaction->t_expires);
169 memset(handle, 0, sizeof(*handle));
170 handle->h_buffer_credits = nblocks;
172 + INIT_LIST_HEAD(&handle->h_jcb);
174 lockdep_init_map(&handle->h_lockdep_map, "jbd2_handle",
175 &jbd2_handle_key, 0);
176 @@ -1349,6 +1353,36 @@
180 + * void jbd2_journal_callback_set() - Register a callback function for this handle.
181 + * @handle: handle to attach the callback to.
182 + * @func: function to callback.
183 + * @jcb: structure with additional information required by func() , and
184 + * some space for jbd2 internal information.
186 + * The function will be
187 + * called when the transaction that this handle is part of has been
188 + * committed to disk with the original callback data struct and the
189 + * error status of the journal as parameters. There is no guarantee of
190 + * ordering between handles within a single transaction, nor between
191 + * callbacks registered on the same handle.
193 + * The caller is responsible for allocating the journal_callback struct.
194 + * This is to allow the caller to add as much extra data to the callback
195 + * as needed, but reduce the overhead of multiple allocations. The caller
196 + * allocated struct must start with a struct journal_callback at offset 0,
197 + * and has the caller-specific data afterwards.
199 +void jbd2_journal_callback_set(handle_t *handle,
200 + void (*func)(struct journal_callback *jcb, int error),
201 + struct journal_callback *jcb)
203 + spin_lock(&handle->h_transaction->t_jcb_lock);
204 + list_add_tail(&jcb->jcb_list, &handle->h_jcb);
205 + spin_unlock(&handle->h_transaction->t_jcb_lock);
206 + jcb->jcb_func = func;
210 * int jbd2_journal_stop() - complete a transaction
211 * @handle: tranaction to complete.
213 @@ -1422,6 +1456,11 @@
214 wake_up(&journal->j_wait_transaction_locked);
217 + /* Move callbacks from the handle to the transaction. */
218 + spin_lock(&transaction->t_jcb_lock);
219 + list_splice(&handle->h_jcb, &transaction->t_jcb);
220 + spin_unlock(&transaction->t_jcb_lock);
223 * If the handle is marked SYNC, we need to set another commit
224 * going! We also want to force a commit if the current