Whamcloud - gitweb
b=21610 Kernel update for SLES11 SP1.
[fs/lustre-release.git] / lustre / kernel_patches / patches / jbd2-jcberr-2.6-sles11.patch
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 {
6         unsigned int i_flags;
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 @@ -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
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 @@ -501,6 +530,8 @@ struct transaction_chp_stats_s {
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 @@ -641,6 +672,16 @@ struct transaction_s
65          * structures associated with the transaction
66          */
67         struct list_head        t_private_list;
68 +
69 +       /*
70 +        * Protects the callback list
71 +        */
72 +       spinlock_t              t_jcb_lock;
73 +       /*
74 +        * List of registered callback functions for this transaction.
75 +        * Called when the transaction is committed. [t_jcb_lock]
76 +        */
77 +       struct list_head        t_jcb;
78  };
79  
80  struct transaction_run_stats_s {
81 @@ -1044,6 +1084,9 @@ extern int         jbd2_journal_stop(handle_t *
82  extern int      jbd2_journal_flush (journal_t *);
83  extern void     jbd2_journal_lock_updates (journal_t *);
84  extern void     jbd2_journal_unlock_updates (journal_t *);
85 +extern void     jbd2_journal_callback_set(handle_t *handle,
86 +                                      void (*fn)(struct journal_callback *,int),
87 +                                      struct journal_callback *jcb);
88  
89  extern journal_t * jbd2_journal_init_dev(struct block_device *bdev,
90                                 struct block_device *fs_dev,
91 Index: linux-2.6.27.21-0.1/fs/jbd2/checkpoint.c
92 ===================================================================
93 --- linux-2.6.27.21-0.1.orig/fs/jbd2/checkpoint.c
94 +++ linux-2.6.27.21-0.1/fs/jbd2/checkpoint.c
95 @@ -728,6 +728,7 @@ void __jbd2_journal_drop_transaction(jou
96         J_ASSERT(transaction->t_checkpoint_list == NULL);
97         J_ASSERT(transaction->t_checkpoint_io_list == NULL);
98         J_ASSERT(transaction->t_updates == 0);
99 +       J_ASSERT(list_empty(&transaction->t_jcb));
100         J_ASSERT(journal->j_committing_transaction != transaction);
101         J_ASSERT(journal->j_running_transaction != transaction);
102  
103 Index: linux-2.6.27.21-0.1/fs/jbd2/commit.c
104 ===================================================================
105 --- linux-2.6.27.21-0.1.orig/fs/jbd2/commit.c
106 +++ linux-2.6.27.21-0.1/fs/jbd2/commit.c
107 @@ -805,6 +805,30 @@ wait_for_iobuf:
108             transaction can be removed from any checkpoint list it was on
109             before. */
110  
111 +       /*
112 +        * Call any callbacks that had been registered for handles in this
113 +        * transaction.  It is up to the callback to free any allocated
114 +        * memory.
115 +        *
116 +        * The spinlocking (t_jcb_lock) here is surely unnecessary...
117 +        */
118 +       spin_lock(&commit_transaction->t_jcb_lock);
119 +       if (!list_empty(&commit_transaction->t_jcb)) {
120 +               struct list_head *p, *n;
121 +               int error = is_journal_aborted(journal);
122 +
123 +               list_for_each_safe(p, n, &commit_transaction->t_jcb) {
124 +                       struct journal_callback *jcb;
125 +
126 +                       jcb = list_entry(p, struct journal_callback, jcb_list);
127 +                       list_del(p);
128 +                       spin_unlock(&commit_transaction->t_jcb_lock);
129 +                       jcb->jcb_func(jcb, error);
130 +                       spin_lock(&commit_transaction->t_jcb_lock);
131 +               }
132 +       }
133 +       spin_unlock(&commit_transaction->t_jcb_lock);
134 +
135         jbd_debug(3, "JBD: commit phase 6\n");
136  
137         J_ASSERT(list_empty(&commit_transaction->t_inode_list));
138 Index: linux-2.6.27.21-0.1/fs/jbd2/journal.c
139 ===================================================================
140 --- linux-2.6.27.21-0.1.orig/fs/jbd2/journal.c
141 +++ linux-2.6.27.21-0.1/fs/jbd2/journal.c
142 @@ -84,6 +84,8 @@ EXPORT_SYMBOL(jbd2_journal_file_inode);
143  EXPORT_SYMBOL(jbd2_journal_init_jbd_inode);
144  EXPORT_SYMBOL(jbd2_journal_release_jbd_inode);
145  EXPORT_SYMBOL(jbd2_journal_begin_ordered_truncate);
146 +EXPORT_SYMBOL(jbd2_journal_callback_set);
147 +EXPORT_SYMBOL(jbd2_journal_bmap);
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.27.21-0.1/fs/jbd2/transaction.c
152 ===================================================================
153 --- linux-2.6.27.21-0.1.orig/fs/jbd2/transaction.c
154 +++ linux-2.6.27.21-0.1/fs/jbd2/transaction.c
155 @@ -50,7 +50,9 @@ jbd2_get_transaction(journal_t *journal,
156         transaction->t_start_time = ktime_get();
157         transaction->t_tid = journal->j_transaction_sequence++;
158         transaction->t_expires = jiffies + journal->j_commit_interval;
159 +       INIT_LIST_HEAD(&transaction->t_jcb);
160         spin_lock_init(&transaction->t_handle_lock);
161 +       spin_lock_init(&transaction->t_jcb_lock);
162         INIT_LIST_HEAD(&transaction->t_inode_list);
163         INIT_LIST_HEAD(&transaction->t_private_list);
164  
165 @@ -252,6 +254,7 @@ static handle_t *new_handle(int nblocks)
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 @@ -1173,6 +1176,36 @@ drop:
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 @@ -1246,6 +1279,11 @@ int jbd2_journal_stop(handle_t *handle)
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