diff options
Diffstat (limited to 'fs/ocfs2/journal.c')
-rw-r--r-- | fs/ocfs2/journal.c | 95 |
1 files changed, 20 insertions, 75 deletions
diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c index 6d9658b0c5db..c0ad7cb59521 100644 --- a/fs/ocfs2/journal.c +++ b/fs/ocfs2/journal.c | |||
@@ -110,30 +110,13 @@ finally: | |||
110 | return status; | 110 | return status; |
111 | } | 111 | } |
112 | 112 | ||
113 | static struct ocfs2_journal_handle *ocfs2_alloc_handle(struct ocfs2_super *osb) | ||
114 | { | ||
115 | struct ocfs2_journal_handle *retval = NULL; | ||
116 | |||
117 | retval = kcalloc(1, sizeof(*retval), GFP_NOFS); | ||
118 | if (!retval) { | ||
119 | mlog(ML_ERROR, "Failed to allocate memory for journal " | ||
120 | "handle!\n"); | ||
121 | return NULL; | ||
122 | } | ||
123 | retval->k_handle = NULL; | ||
124 | |||
125 | return retval; | ||
126 | } | ||
127 | |||
128 | /* pass it NULL and it will allocate a new handle object for you. If | 113 | /* pass it NULL and it will allocate a new handle object for you. If |
129 | * you pass it a handle however, it may still return error, in which | 114 | * you pass it a handle however, it may still return error, in which |
130 | * case it has free'd the passed handle for you. */ | 115 | * case it has free'd the passed handle for you. */ |
131 | struct ocfs2_journal_handle *ocfs2_start_trans(struct ocfs2_super *osb, | 116 | handle_t *ocfs2_start_trans(struct ocfs2_super *osb, int max_buffs) |
132 | int max_buffs) | ||
133 | { | 117 | { |
134 | int ret; | ||
135 | journal_t *journal = osb->journal->j_journal; | 118 | journal_t *journal = osb->journal->j_journal; |
136 | struct ocfs2_journal_handle *handle; | 119 | handle_t *handle; |
137 | 120 | ||
138 | BUG_ON(!osb || !osb->journal->j_journal); | 121 | BUG_ON(!osb || !osb->journal->j_journal); |
139 | 122 | ||
@@ -149,77 +132,39 @@ struct ocfs2_journal_handle *ocfs2_start_trans(struct ocfs2_super *osb, | |||
149 | BUG(); | 132 | BUG(); |
150 | } | 133 | } |
151 | 134 | ||
152 | handle = ocfs2_alloc_handle(osb); | ||
153 | if (!handle) { | ||
154 | ret = -ENOMEM; | ||
155 | mlog_errno(ret); | ||
156 | return ERR_PTR(ret); | ||
157 | } | ||
158 | |||
159 | down_read(&osb->journal->j_trans_barrier); | 135 | down_read(&osb->journal->j_trans_barrier); |
160 | 136 | ||
161 | /* actually start the transaction now */ | 137 | handle = journal_start(journal, max_buffs); |
162 | handle->k_handle = journal_start(journal, max_buffs); | 138 | if (IS_ERR(handle)) { |
163 | if (IS_ERR(handle->k_handle)) { | ||
164 | up_read(&osb->journal->j_trans_barrier); | 139 | up_read(&osb->journal->j_trans_barrier); |
165 | kfree(handle); | ||
166 | 140 | ||
167 | ret = PTR_ERR(handle->k_handle); | 141 | mlog_errno(PTR_ERR(handle)); |
168 | handle->k_handle = NULL; | ||
169 | mlog_errno(ret); | ||
170 | 142 | ||
171 | if (is_journal_aborted(journal)) { | 143 | if (is_journal_aborted(journal)) { |
172 | ocfs2_abort(osb->sb, "Detected aborted journal"); | 144 | ocfs2_abort(osb->sb, "Detected aborted journal"); |
173 | ret = -EROFS; | 145 | handle = ERR_PTR(-EROFS); |
174 | } | 146 | } |
175 | return ERR_PTR(ret); | 147 | } else |
176 | } | 148 | atomic_inc(&(osb->journal->j_num_trans)); |
177 | |||
178 | atomic_inc(&(osb->journal->j_num_trans)); | ||
179 | 149 | ||
180 | return handle; | 150 | return handle; |
181 | } | 151 | } |
182 | 152 | ||
183 | void ocfs2_commit_trans(struct ocfs2_super *osb, | 153 | int ocfs2_commit_trans(struct ocfs2_super *osb, |
184 | struct ocfs2_journal_handle *handle) | 154 | handle_t *handle) |
185 | { | 155 | { |
186 | handle_t *jbd_handle; | 156 | int ret; |
187 | int retval; | ||
188 | struct ocfs2_journal *journal = osb->journal; | 157 | struct ocfs2_journal *journal = osb->journal; |
189 | 158 | ||
190 | mlog_entry_void(); | ||
191 | |||
192 | BUG_ON(!handle); | 159 | BUG_ON(!handle); |
193 | 160 | ||
194 | if (!handle->k_handle) { | 161 | ret = journal_stop(handle); |
195 | kfree(handle); | 162 | if (ret < 0) |
196 | mlog_exit_void(); | 163 | mlog_errno(ret); |
197 | return; | ||
198 | } | ||
199 | |||
200 | /* ocfs2_extend_trans may have had to call journal_restart | ||
201 | * which will always commit the transaction, but may return | ||
202 | * error for any number of reasons. If this is the case, we | ||
203 | * clear k_handle as it's not valid any more. */ | ||
204 | if (handle->k_handle) { | ||
205 | jbd_handle = handle->k_handle; | ||
206 | |||
207 | /* actually stop the transaction. if we've set h_sync, | ||
208 | * it'll have been committed when we return */ | ||
209 | retval = journal_stop(jbd_handle); | ||
210 | if (retval < 0) { | ||
211 | mlog_errno(retval); | ||
212 | mlog(ML_ERROR, "Could not commit transaction\n"); | ||
213 | BUG(); | ||
214 | } | ||
215 | |||
216 | handle->k_handle = NULL; /* it's been free'd in journal_stop */ | ||
217 | } | ||
218 | 164 | ||
219 | up_read(&journal->j_trans_barrier); | 165 | up_read(&journal->j_trans_barrier); |
220 | 166 | ||
221 | kfree(handle); | 167 | return ret; |
222 | mlog_exit_void(); | ||
223 | } | 168 | } |
224 | 169 | ||
225 | /* | 170 | /* |
@@ -268,7 +213,7 @@ bail: | |||
268 | return status; | 213 | return status; |
269 | } | 214 | } |
270 | 215 | ||
271 | int ocfs2_journal_access(struct ocfs2_journal_handle *handle, | 216 | int ocfs2_journal_access(handle_t *handle, |
272 | struct inode *inode, | 217 | struct inode *inode, |
273 | struct buffer_head *bh, | 218 | struct buffer_head *bh, |
274 | int type) | 219 | int type) |
@@ -306,11 +251,11 @@ int ocfs2_journal_access(struct ocfs2_journal_handle *handle, | |||
306 | switch (type) { | 251 | switch (type) { |
307 | case OCFS2_JOURNAL_ACCESS_CREATE: | 252 | case OCFS2_JOURNAL_ACCESS_CREATE: |
308 | case OCFS2_JOURNAL_ACCESS_WRITE: | 253 | case OCFS2_JOURNAL_ACCESS_WRITE: |
309 | status = journal_get_write_access(handle->k_handle, bh); | 254 | status = journal_get_write_access(handle, bh); |
310 | break; | 255 | break; |
311 | 256 | ||
312 | case OCFS2_JOURNAL_ACCESS_UNDO: | 257 | case OCFS2_JOURNAL_ACCESS_UNDO: |
313 | status = journal_get_undo_access(handle->k_handle, bh); | 258 | status = journal_get_undo_access(handle, bh); |
314 | break; | 259 | break; |
315 | 260 | ||
316 | default: | 261 | default: |
@@ -327,7 +272,7 @@ int ocfs2_journal_access(struct ocfs2_journal_handle *handle, | |||
327 | return status; | 272 | return status; |
328 | } | 273 | } |
329 | 274 | ||
330 | int ocfs2_journal_dirty(struct ocfs2_journal_handle *handle, | 275 | int ocfs2_journal_dirty(handle_t *handle, |
331 | struct buffer_head *bh) | 276 | struct buffer_head *bh) |
332 | { | 277 | { |
333 | int status; | 278 | int status; |
@@ -335,7 +280,7 @@ int ocfs2_journal_dirty(struct ocfs2_journal_handle *handle, | |||
335 | mlog_entry("(bh->b_blocknr=%llu)\n", | 280 | mlog_entry("(bh->b_blocknr=%llu)\n", |
336 | (unsigned long long)bh->b_blocknr); | 281 | (unsigned long long)bh->b_blocknr); |
337 | 282 | ||
338 | status = journal_dirty_metadata(handle->k_handle, bh); | 283 | status = journal_dirty_metadata(handle, bh); |
339 | if (status < 0) | 284 | if (status < 0) |
340 | mlog(ML_ERROR, "Could not dirty metadata buffer. " | 285 | mlog(ML_ERROR, "Could not dirty metadata buffer. " |
341 | "(bh->b_blocknr=%llu)\n", | 286 | "(bh->b_blocknr=%llu)\n", |