Whamcloud - gitweb
b=16893,18503
[fs/lustre-release.git] / lustre / kernel_patches / patches / jbd2-jcberr-2.6-rhel5.patch
1 Index: linux-2.6.18-128.1.6/include/linux/jbd2.h
2 ===================================================================
3 --- linux-2.6.18-128.1.6.orig/include/linux/jbd2.h      2009-04-15 08:35:28.000000000 +0530
4 +++ linux-2.6.18-128.1.6/include/linux/jbd2.h   2009-05-28 15:10:18.000000000 +0530
5 @@ -381,6 +381,27 @@
6         bit_spin_unlock(BH_JournalHead, &bh->b_state);
7  }
8  
9 +#define HAVE_JOURNAL_CALLBACK_STATUS
10 +/**
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.
14 + *
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().
19 + *
20 + *   This is used internally by jbd2 to maintain callback information.
21 + *
22 + *   See journal_callback_set for more information.
23 + **/
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 */
28 +};
29 +
30  struct jbd2_revoke_table_s;
31  
32  /**
33 @@ -389,6 +410,7 @@
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 @@ -414,6 +436,13 @@
42         /* operations */
43         int                     h_err;
44  
45 +       /*
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]
49 +        */
50 +       struct list_head        h_jcb;
51 +
52         /* Flags [no locking] */
53         unsigned int    h_sync:         1;      /* sync-on-close */
54         unsigned int    h_jdata:        1;      /* force data journaling */
55 @@ -469,6 +498,8 @@
56   *    j_state_lock
57   *    ->j_list_lock                    (journal_unmap_buffer)
58   *
59 + *    t_handle_lock
60 + *    ->t_jcb_lock
61   */
62  
63  struct transaction_s
64 @@ -615,6 +646,15 @@
65          */
66         int t_handle_count;
67  
68 +       /*
69 +        * Protects the callback list
70 +        */
71 +       spinlock_t              t_jcb_lock;
72 +       /*
73 +        * List of registered callback functions for this transaction.
74 +        * Called when the transaction is committed. [t_jcb_lock]
75 +        */
76 +       struct list_head        t_jcb;
77  };
78  
79  struct transaction_run_stats_s {
80 @@ -1018,6 +1058,9 @@
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);
87  
88  extern journal_t * jbd2_journal_init_dev(struct block_device *bdev,
89                                 struct block_device *fs_dev,
90 Index: linux-2.6.18-128.1.6/fs/jbd2/checkpoint.c
91 ===================================================================
92 --- linux-2.6.18-128.1.6.orig/fs/jbd2/checkpoint.c      2009-04-15 08:35:28.000000000 +0530
93 +++ linux-2.6.18-128.1.6/fs/jbd2/checkpoint.c   2009-05-28 15:10:18.000000000 +0530
94 @@ -695,6 +695,7 @@
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);
101  
102 Index: linux-2.6.18-128.1.6/fs/jbd2/commit.c
103 ===================================================================
104 --- linux-2.6.18-128.1.6.orig/fs/jbd2/commit.c  2009-04-15 08:35:28.000000000 +0530
105 +++ linux-2.6.18-128.1.6/fs/jbd2/commit.c       2009-05-28 15:12:45.000000000 +0530
106 @@ -898,6 +898,30 @@
107             transaction can be removed from any checkpoint list it was on
108             before. */
109  
110 +       /*
111 +        * Call any callbacks that had been registered for handles in this
112 +        * transaction.  It is up to the callback to free any allocated
113 +        * memory.
114 +        *
115 +        * The spinlocking (t_jcb_lock) here is surely unnecessary...
116 +        */
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);
121 +
122 +               list_for_each_safe(p, n, &commit_transaction->t_jcb) {
123 +                       struct journal_callback *jcb;
124 +
125 +                       jcb = list_entry(p, struct journal_callback, jcb_list);
126 +                       list_del(p);
127 +                       spin_unlock(&commit_transaction->t_jcb_lock);
128 +                       jcb->jcb_func(jcb, error);
129 +                       spin_lock(&commit_transaction->t_jcb_lock);
130 +               }
131 +       }
132 +       spin_unlock(&commit_transaction->t_jcb_lock);
133 +
134         jbd_debug(3, "JBD: commit phase 7\n");
135  
136         J_ASSERT(commit_transaction->t_sync_datalist == NULL);
137 Index: linux-2.6.18-128.1.6/fs/jbd2/journal.c
138 ===================================================================
139 --- linux-2.6.18-128.1.6.orig/fs/jbd2/journal.c 2009-04-15 08:35:28.000000000 +0530
140 +++ linux-2.6.18-128.1.6/fs/jbd2/journal.c      2009-05-28 17:13:35.000000000 +0530
141 @@ -80,6 +80,9 @@
142  EXPORT_SYMBOL(jbd2_journal_invalidatepage);
143  EXPORT_SYMBOL(jbd2_journal_try_to_free_buffers);
144  EXPORT_SYMBOL(jbd2_journal_force_commit);
145 +EXPORT_SYMBOL(jbd2_journal_callback_set);
146 +EXPORT_SYMBOL(jbd2_journal_bmap);
147 +EXPORT_SYMBOL(jbd2_log_start_commit);
148  
149  static int journal_convert_superblock_v1(journal_t *, journal_superblock_t *);
150  static void __journal_abort_soft (journal_t *journal, int errno);
151 Index: linux-2.6.18-128.1.6/fs/jbd2/transaction.c
152 ===================================================================
153 --- linux-2.6.18-128.1.6.orig/fs/jbd2/transaction.c     2009-04-15 08:35:28.000000000 +0530
154 +++ linux-2.6.18-128.1.6/fs/jbd2/transaction.c  2009-05-28 15:11:28.000000000 +0530
155 @@ -51,6 +51,9 @@
156         transaction->t_tid = journal->j_transaction_sequence++;
157         transaction->t_expires = jiffies + journal->j_commit_interval;
158         spin_lock_init(&transaction->t_handle_lock);
159 +       INIT_LIST_HEAD(&transaction->t_jcb);
160 +       spin_lock_init(&transaction->t_jcb_lock);
161 +
162  
163         /* Set up the commit timer for the new transaction. */
164         journal->j_commit_timer.expires = round_jiffies(transaction->t_expires);
165 @@ -251,6 +254,7 @@
166         memset(handle, 0, sizeof(*handle));
167         handle->h_buffer_credits = nblocks;
168         handle->h_ref = 1;
169 +       INIT_LIST_HEAD(&handle->h_jcb);
170  
171         lockdep_init_map(&handle->h_lockdep_map, "jbd2_handle",
172                                                 &jbd2_handle_key, 0);
173 @@ -1349,6 +1353,36 @@
174  }
175  
176  /**
177 + * void jbd2_journal_callback_set() -  Register a callback function for this handle.
178 + * @handle: handle to attach the callback to.
179 + * @func: function to callback.
180 + * @jcb:  structure with additional information required by func() , and
181 + *     some space for jbd2 internal information.
182 + *
183 + * The function will be
184 + * called when the transaction that this handle is part of has been
185 + * committed to disk with the original callback data struct and the
186 + * error status of the journal as parameters.  There is no guarantee of
187 + * ordering between handles within a single transaction, nor between
188 + * callbacks registered on the same handle.
189 + *
190 + * The caller is responsible for allocating the journal_callback struct.
191 + * This is to allow the caller to add as much extra data to the callback
192 + * as needed, but reduce the overhead of multiple allocations.  The caller
193 + * allocated struct must start with a struct journal_callback at offset 0,
194 + * and has the caller-specific data afterwards.
195 + */
196 +void jbd2_journal_callback_set(handle_t *handle,
197 +                     void (*func)(struct journal_callback *jcb, int error),
198 +                     struct journal_callback *jcb)
199 +{
200 +       spin_lock(&handle->h_transaction->t_jcb_lock);
201 +       list_add_tail(&jcb->jcb_list, &handle->h_jcb);
202 +       spin_unlock(&handle->h_transaction->t_jcb_lock);
203 +       jcb->jcb_func = func;
204 +}
205 +
206 +/**
207   * int jbd2_journal_stop() - complete a transaction
208   * @handle: tranaction to complete.
209   *
210 @@ -1422,6 +1456,11 @@
211                         wake_up(&journal->j_wait_transaction_locked);
212         }
213  
214 +       /* Move callbacks from the handle to the transaction. */
215 +       spin_lock(&transaction->t_jcb_lock);
216 +       list_splice(&handle->h_jcb, &transaction->t_jcb);
217 +       spin_unlock(&transaction->t_jcb_lock);
218 +
219         /*
220          * If the handle is marked SYNC, we need to set another commit
221          * going!  We also want to force a commit if the current