Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1 | /* -*- mode: c; c-basic-offset: 8; -*- |
| 2 | * vim: noexpandtab sw=8 ts=8 sts=0: |
| 3 | * |
| 4 | * journal.c |
| 5 | * |
| 6 | * Defines functions of journalling api |
| 7 | * |
| 8 | * Copyright (C) 2003, 2004 Oracle. All rights reserved. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public |
| 12 | * License as published by the Free Software Foundation; either |
| 13 | * version 2 of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public |
| 21 | * License along with this program; if not, write to the |
| 22 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 23 | * Boston, MA 021110-1307, USA. |
| 24 | */ |
| 25 | |
| 26 | #include <linux/fs.h> |
| 27 | #include <linux/types.h> |
| 28 | #include <linux/slab.h> |
| 29 | #include <linux/highmem.h> |
| 30 | #include <linux/kthread.h> |
| 31 | |
| 32 | #define MLOG_MASK_PREFIX ML_JOURNAL |
| 33 | #include <cluster/masklog.h> |
| 34 | |
| 35 | #include "ocfs2.h" |
| 36 | |
| 37 | #include "alloc.h" |
Joel Becker | 50655ae | 2008-09-11 15:53:07 -0700 | [diff] [blame] | 38 | #include "blockcheck.h" |
Mark Fasheh | 316f4b9 | 2007-09-07 18:21:26 -0700 | [diff] [blame] | 39 | #include "dir.h" |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 40 | #include "dlmglue.h" |
| 41 | #include "extent_map.h" |
| 42 | #include "heartbeat.h" |
| 43 | #include "inode.h" |
| 44 | #include "journal.h" |
| 45 | #include "localalloc.h" |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 46 | #include "slot_map.h" |
| 47 | #include "super.h" |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 48 | #include "sysfile.h" |
Jan Kara | 2205363 | 2008-10-20 23:50:38 +0200 | [diff] [blame] | 49 | #include "quota.h" |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 50 | |
| 51 | #include "buffer_head_io.h" |
| 52 | |
Ingo Molnar | 34af946 | 2006-06-27 02:53:55 -0700 | [diff] [blame] | 53 | DEFINE_SPINLOCK(trans_inc_lock); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 54 | |
| 55 | static int ocfs2_force_read_journal(struct inode *inode); |
| 56 | static int ocfs2_recover_node(struct ocfs2_super *osb, |
Jan Kara | 2205363 | 2008-10-20 23:50:38 +0200 | [diff] [blame] | 57 | int node_num, int slot_num); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 58 | static int __ocfs2_recovery_thread(void *arg); |
| 59 | static int ocfs2_commit_cache(struct ocfs2_super *osb); |
Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 60 | static int __ocfs2_wait_on_mount(struct ocfs2_super *osb, int quota); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 61 | static int ocfs2_journal_toggle_dirty(struct ocfs2_super *osb, |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 62 | int dirty, int replayed); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 63 | static int ocfs2_trylock_journal(struct ocfs2_super *osb, |
| 64 | int slot_num); |
| 65 | static int ocfs2_recover_orphans(struct ocfs2_super *osb, |
| 66 | int slot); |
| 67 | static int ocfs2_commit_thread(void *arg); |
| 68 | |
Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 69 | static inline int ocfs2_wait_on_mount(struct ocfs2_super *osb) |
| 70 | { |
| 71 | return __ocfs2_wait_on_mount(osb, 0); |
| 72 | } |
| 73 | |
| 74 | static inline int ocfs2_wait_on_quotas(struct ocfs2_super *osb) |
| 75 | { |
| 76 | return __ocfs2_wait_on_mount(osb, 1); |
| 77 | } |
| 78 | |
| 79 | |
Joel Becker | 553abd0 | 2008-02-01 12:03:57 -0800 | [diff] [blame] | 80 | |
| 81 | /* |
| 82 | * The recovery_list is a simple linked list of node numbers to recover. |
| 83 | * It is protected by the recovery_lock. |
| 84 | */ |
| 85 | |
| 86 | struct ocfs2_recovery_map { |
Joel Becker | fc881fa | 2008-02-01 12:04:48 -0800 | [diff] [blame] | 87 | unsigned int rm_used; |
Joel Becker | 553abd0 | 2008-02-01 12:03:57 -0800 | [diff] [blame] | 88 | unsigned int *rm_entries; |
| 89 | }; |
| 90 | |
| 91 | int ocfs2_recovery_init(struct ocfs2_super *osb) |
| 92 | { |
| 93 | struct ocfs2_recovery_map *rm; |
| 94 | |
| 95 | mutex_init(&osb->recovery_lock); |
| 96 | osb->disable_recovery = 0; |
| 97 | osb->recovery_thread_task = NULL; |
| 98 | init_waitqueue_head(&osb->recovery_event); |
| 99 | |
| 100 | rm = kzalloc(sizeof(struct ocfs2_recovery_map) + |
| 101 | osb->max_slots * sizeof(unsigned int), |
| 102 | GFP_KERNEL); |
| 103 | if (!rm) { |
| 104 | mlog_errno(-ENOMEM); |
| 105 | return -ENOMEM; |
| 106 | } |
| 107 | |
| 108 | rm->rm_entries = (unsigned int *)((char *)rm + |
| 109 | sizeof(struct ocfs2_recovery_map)); |
| 110 | osb->recovery_map = rm; |
| 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | /* we can't grab the goofy sem lock from inside wait_event, so we use |
| 116 | * memory barriers to make sure that we'll see the null task before |
| 117 | * being woken up */ |
| 118 | static int ocfs2_recovery_thread_running(struct ocfs2_super *osb) |
| 119 | { |
| 120 | mb(); |
| 121 | return osb->recovery_thread_task != NULL; |
| 122 | } |
| 123 | |
| 124 | void ocfs2_recovery_exit(struct ocfs2_super *osb) |
| 125 | { |
| 126 | struct ocfs2_recovery_map *rm; |
| 127 | |
| 128 | /* disable any new recovery threads and wait for any currently |
| 129 | * running ones to exit. Do this before setting the vol_state. */ |
| 130 | mutex_lock(&osb->recovery_lock); |
| 131 | osb->disable_recovery = 1; |
| 132 | mutex_unlock(&osb->recovery_lock); |
| 133 | wait_event(osb->recovery_event, !ocfs2_recovery_thread_running(osb)); |
| 134 | |
| 135 | /* At this point, we know that no more recovery threads can be |
| 136 | * launched, so wait for any recovery completion work to |
| 137 | * complete. */ |
| 138 | flush_workqueue(ocfs2_wq); |
| 139 | |
| 140 | /* |
| 141 | * Now that recovery is shut down, and the osb is about to be |
| 142 | * freed, the osb_lock is not taken here. |
| 143 | */ |
| 144 | rm = osb->recovery_map; |
| 145 | /* XXX: Should we bug if there are dirty entries? */ |
| 146 | |
| 147 | kfree(rm); |
| 148 | } |
| 149 | |
| 150 | static int __ocfs2_recovery_map_test(struct ocfs2_super *osb, |
| 151 | unsigned int node_num) |
| 152 | { |
| 153 | int i; |
| 154 | struct ocfs2_recovery_map *rm = osb->recovery_map; |
| 155 | |
| 156 | assert_spin_locked(&osb->osb_lock); |
| 157 | |
| 158 | for (i = 0; i < rm->rm_used; i++) { |
| 159 | if (rm->rm_entries[i] == node_num) |
| 160 | return 1; |
| 161 | } |
| 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | /* Behaves like test-and-set. Returns the previous value */ |
| 167 | static int ocfs2_recovery_map_set(struct ocfs2_super *osb, |
| 168 | unsigned int node_num) |
| 169 | { |
| 170 | struct ocfs2_recovery_map *rm = osb->recovery_map; |
| 171 | |
| 172 | spin_lock(&osb->osb_lock); |
| 173 | if (__ocfs2_recovery_map_test(osb, node_num)) { |
| 174 | spin_unlock(&osb->osb_lock); |
| 175 | return 1; |
| 176 | } |
| 177 | |
| 178 | /* XXX: Can this be exploited? Not from o2dlm... */ |
| 179 | BUG_ON(rm->rm_used >= osb->max_slots); |
| 180 | |
| 181 | rm->rm_entries[rm->rm_used] = node_num; |
| 182 | rm->rm_used++; |
| 183 | spin_unlock(&osb->osb_lock); |
| 184 | |
| 185 | return 0; |
| 186 | } |
| 187 | |
| 188 | static void ocfs2_recovery_map_clear(struct ocfs2_super *osb, |
| 189 | unsigned int node_num) |
| 190 | { |
| 191 | int i; |
| 192 | struct ocfs2_recovery_map *rm = osb->recovery_map; |
| 193 | |
| 194 | spin_lock(&osb->osb_lock); |
| 195 | |
| 196 | for (i = 0; i < rm->rm_used; i++) { |
| 197 | if (rm->rm_entries[i] == node_num) |
| 198 | break; |
| 199 | } |
| 200 | |
| 201 | if (i < rm->rm_used) { |
| 202 | /* XXX: be careful with the pointer math */ |
| 203 | memmove(&(rm->rm_entries[i]), &(rm->rm_entries[i + 1]), |
| 204 | (rm->rm_used - i - 1) * sizeof(unsigned int)); |
| 205 | rm->rm_used--; |
| 206 | } |
| 207 | |
| 208 | spin_unlock(&osb->osb_lock); |
| 209 | } |
| 210 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 211 | static int ocfs2_commit_cache(struct ocfs2_super *osb) |
| 212 | { |
| 213 | int status = 0; |
| 214 | unsigned int flushed; |
| 215 | unsigned long old_id; |
| 216 | struct ocfs2_journal *journal = NULL; |
| 217 | |
| 218 | mlog_entry_void(); |
| 219 | |
| 220 | journal = osb->journal; |
| 221 | |
| 222 | /* Flush all pending commits and checkpoint the journal. */ |
| 223 | down_write(&journal->j_trans_barrier); |
| 224 | |
| 225 | if (atomic_read(&journal->j_num_trans) == 0) { |
| 226 | up_write(&journal->j_trans_barrier); |
| 227 | mlog(0, "No transactions for me to flush!\n"); |
| 228 | goto finally; |
| 229 | } |
| 230 | |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 231 | jbd2_journal_lock_updates(journal->j_journal); |
| 232 | status = jbd2_journal_flush(journal->j_journal); |
| 233 | jbd2_journal_unlock_updates(journal->j_journal); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 234 | if (status < 0) { |
| 235 | up_write(&journal->j_trans_barrier); |
| 236 | mlog_errno(status); |
| 237 | goto finally; |
| 238 | } |
| 239 | |
| 240 | old_id = ocfs2_inc_trans_id(journal); |
| 241 | |
| 242 | flushed = atomic_read(&journal->j_num_trans); |
| 243 | atomic_set(&journal->j_num_trans, 0); |
| 244 | up_write(&journal->j_trans_barrier); |
| 245 | |
| 246 | mlog(0, "commit_thread: flushed transaction %lu (%u handles)\n", |
| 247 | journal->j_trans_id, flushed); |
| 248 | |
Mark Fasheh | 34d024f | 2007-09-24 15:56:19 -0700 | [diff] [blame] | 249 | ocfs2_wake_downconvert_thread(osb); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 250 | wake_up(&journal->j_checkpointed); |
| 251 | finally: |
| 252 | mlog_exit(status); |
| 253 | return status; |
| 254 | } |
| 255 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 256 | /* pass it NULL and it will allocate a new handle object for you. If |
| 257 | * you pass it a handle however, it may still return error, in which |
| 258 | * case it has free'd the passed handle for you. */ |
Mark Fasheh | 1fabe14 | 2006-10-09 18:11:45 -0700 | [diff] [blame] | 259 | handle_t *ocfs2_start_trans(struct ocfs2_super *osb, int max_buffs) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 260 | { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 261 | journal_t *journal = osb->journal->j_journal; |
Mark Fasheh | 1fabe14 | 2006-10-09 18:11:45 -0700 | [diff] [blame] | 262 | handle_t *handle; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 263 | |
Eric Sesterhenn / snakebyte | ebdec83 | 2006-01-27 10:32:52 +0100 | [diff] [blame] | 264 | BUG_ON(!osb || !osb->journal->j_journal); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 265 | |
Mark Fasheh | 65eff9c | 2006-10-09 17:26:22 -0700 | [diff] [blame] | 266 | if (ocfs2_is_hard_readonly(osb)) |
| 267 | return ERR_PTR(-EROFS); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 268 | |
| 269 | BUG_ON(osb->journal->j_state == OCFS2_JOURNAL_FREE); |
| 270 | BUG_ON(max_buffs <= 0); |
| 271 | |
Jan Kara | 90e86a6 | 2008-08-27 22:30:28 +0200 | [diff] [blame] | 272 | /* Nested transaction? Just return the handle... */ |
| 273 | if (journal_current_handle()) |
| 274 | return jbd2_journal_start(journal, max_buffs); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 275 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 276 | down_read(&osb->journal->j_trans_barrier); |
| 277 | |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 278 | handle = jbd2_journal_start(journal, max_buffs); |
Mark Fasheh | 1fabe14 | 2006-10-09 18:11:45 -0700 | [diff] [blame] | 279 | if (IS_ERR(handle)) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 280 | up_read(&osb->journal->j_trans_barrier); |
| 281 | |
Mark Fasheh | 1fabe14 | 2006-10-09 18:11:45 -0700 | [diff] [blame] | 282 | mlog_errno(PTR_ERR(handle)); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 283 | |
| 284 | if (is_journal_aborted(journal)) { |
| 285 | ocfs2_abort(osb->sb, "Detected aborted journal"); |
Mark Fasheh | 1fabe14 | 2006-10-09 18:11:45 -0700 | [diff] [blame] | 286 | handle = ERR_PTR(-EROFS); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 287 | } |
Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 288 | } else { |
| 289 | if (!ocfs2_mount_local(osb)) |
| 290 | atomic_inc(&(osb->journal->j_num_trans)); |
| 291 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 292 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 293 | return handle; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 294 | } |
| 295 | |
Mark Fasheh | 1fabe14 | 2006-10-09 18:11:45 -0700 | [diff] [blame] | 296 | int ocfs2_commit_trans(struct ocfs2_super *osb, |
| 297 | handle_t *handle) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 298 | { |
Jan Kara | 90e86a6 | 2008-08-27 22:30:28 +0200 | [diff] [blame] | 299 | int ret, nested; |
Mark Fasheh | 02dc1af | 2006-10-09 16:48:10 -0700 | [diff] [blame] | 300 | struct ocfs2_journal *journal = osb->journal; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 301 | |
| 302 | BUG_ON(!handle); |
| 303 | |
Jan Kara | 90e86a6 | 2008-08-27 22:30:28 +0200 | [diff] [blame] | 304 | nested = handle->h_ref > 1; |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 305 | ret = jbd2_journal_stop(handle); |
Mark Fasheh | 1fabe14 | 2006-10-09 18:11:45 -0700 | [diff] [blame] | 306 | if (ret < 0) |
| 307 | mlog_errno(ret); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 308 | |
Jan Kara | 90e86a6 | 2008-08-27 22:30:28 +0200 | [diff] [blame] | 309 | if (!nested) |
| 310 | up_read(&journal->j_trans_barrier); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 311 | |
Mark Fasheh | 1fabe14 | 2006-10-09 18:11:45 -0700 | [diff] [blame] | 312 | return ret; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | /* |
| 316 | * 'nblocks' is what you want to add to the current |
| 317 | * transaction. extend_trans will either extend the current handle by |
| 318 | * nblocks, or commit it and start a new one with nblocks credits. |
| 319 | * |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 320 | * This might call jbd2_journal_restart() which will commit dirty buffers |
Mark Fasheh | e8aed34 | 2007-12-03 16:43:01 -0800 | [diff] [blame] | 321 | * and then restart the transaction. Before calling |
| 322 | * ocfs2_extend_trans(), any changed blocks should have been |
| 323 | * dirtied. After calling it, all blocks which need to be changed must |
| 324 | * go through another set of journal_access/journal_dirty calls. |
| 325 | * |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 326 | * WARNING: This will not release any semaphores or disk locks taken |
| 327 | * during the transaction, so make sure they were taken *before* |
| 328 | * start_trans or we'll have ordering deadlocks. |
| 329 | * |
| 330 | * WARNING2: Note that we do *not* drop j_trans_barrier here. This is |
| 331 | * good because transaction ids haven't yet been recorded on the |
| 332 | * cluster locks associated with this handle. |
| 333 | */ |
Mark Fasheh | 1fc5814 | 2006-10-05 14:15:36 -0700 | [diff] [blame] | 334 | int ocfs2_extend_trans(handle_t *handle, int nblocks) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 335 | { |
| 336 | int status; |
| 337 | |
| 338 | BUG_ON(!handle); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 339 | BUG_ON(!nblocks); |
| 340 | |
| 341 | mlog_entry_void(); |
| 342 | |
| 343 | mlog(0, "Trying to extend transaction by %d blocks\n", nblocks); |
| 344 | |
Joel Becker | e407e39 | 2008-06-12 22:35:39 -0700 | [diff] [blame] | 345 | #ifdef CONFIG_OCFS2_DEBUG_FS |
Mark Fasheh | 0879c58 | 2007-12-03 16:42:19 -0800 | [diff] [blame] | 346 | status = 1; |
| 347 | #else |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 348 | status = jbd2_journal_extend(handle, nblocks); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 349 | if (status < 0) { |
| 350 | mlog_errno(status); |
| 351 | goto bail; |
| 352 | } |
Mark Fasheh | 0879c58 | 2007-12-03 16:42:19 -0800 | [diff] [blame] | 353 | #endif |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 354 | |
| 355 | if (status > 0) { |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 356 | mlog(0, |
| 357 | "jbd2_journal_extend failed, trying " |
| 358 | "jbd2_journal_restart\n"); |
| 359 | status = jbd2_journal_restart(handle, nblocks); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 360 | if (status < 0) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 361 | mlog_errno(status); |
| 362 | goto bail; |
| 363 | } |
Mark Fasheh | 01ddf1e | 2006-10-05 13:54:39 -0700 | [diff] [blame] | 364 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 365 | |
| 366 | status = 0; |
| 367 | bail: |
| 368 | |
| 369 | mlog_exit(status); |
| 370 | return status; |
| 371 | } |
| 372 | |
Joel Becker | 50655ae | 2008-09-11 15:53:07 -0700 | [diff] [blame] | 373 | struct ocfs2_triggers { |
| 374 | struct jbd2_buffer_trigger_type ot_triggers; |
| 375 | int ot_offset; |
| 376 | }; |
| 377 | |
| 378 | static inline struct ocfs2_triggers *to_ocfs2_trigger(struct jbd2_buffer_trigger_type *triggers) |
| 379 | { |
| 380 | return container_of(triggers, struct ocfs2_triggers, ot_triggers); |
| 381 | } |
| 382 | |
| 383 | static void ocfs2_commit_trigger(struct jbd2_buffer_trigger_type *triggers, |
| 384 | struct buffer_head *bh, |
| 385 | void *data, size_t size) |
| 386 | { |
| 387 | struct ocfs2_triggers *ot = to_ocfs2_trigger(triggers); |
| 388 | |
| 389 | /* |
| 390 | * We aren't guaranteed to have the superblock here, so we |
| 391 | * must unconditionally compute the ecc data. |
| 392 | * __ocfs2_journal_access() will only set the triggers if |
| 393 | * metaecc is enabled. |
| 394 | */ |
| 395 | ocfs2_block_check_compute(data, size, data + ot->ot_offset); |
| 396 | } |
| 397 | |
| 398 | /* |
| 399 | * Quota blocks have their own trigger because the struct ocfs2_block_check |
| 400 | * offset depends on the blocksize. |
| 401 | */ |
| 402 | static void ocfs2_dq_commit_trigger(struct jbd2_buffer_trigger_type *triggers, |
| 403 | struct buffer_head *bh, |
| 404 | void *data, size_t size) |
| 405 | { |
| 406 | struct ocfs2_disk_dqtrailer *dqt = |
| 407 | ocfs2_block_dqtrailer(size, data); |
| 408 | |
| 409 | /* |
| 410 | * We aren't guaranteed to have the superblock here, so we |
| 411 | * must unconditionally compute the ecc data. |
| 412 | * __ocfs2_journal_access() will only set the triggers if |
| 413 | * metaecc is enabled. |
| 414 | */ |
| 415 | ocfs2_block_check_compute(data, size, &dqt->dq_check); |
| 416 | } |
| 417 | |
Joel Becker | c175a51 | 2008-12-10 17:58:22 -0800 | [diff] [blame^] | 418 | /* |
| 419 | * Directory blocks also have their own trigger because the |
| 420 | * struct ocfs2_block_check offset depends on the blocksize. |
| 421 | */ |
| 422 | static void ocfs2_db_commit_trigger(struct jbd2_buffer_trigger_type *triggers, |
| 423 | struct buffer_head *bh, |
| 424 | void *data, size_t size) |
| 425 | { |
| 426 | struct ocfs2_dir_block_trailer *trailer = |
| 427 | ocfs2_dir_trailer_from_size(size, data); |
| 428 | |
| 429 | /* |
| 430 | * We aren't guaranteed to have the superblock here, so we |
| 431 | * must unconditionally compute the ecc data. |
| 432 | * __ocfs2_journal_access() will only set the triggers if |
| 433 | * metaecc is enabled. |
| 434 | */ |
| 435 | ocfs2_block_check_compute(data, size, &trailer->db_check); |
| 436 | } |
| 437 | |
Joel Becker | 50655ae | 2008-09-11 15:53:07 -0700 | [diff] [blame] | 438 | static void ocfs2_abort_trigger(struct jbd2_buffer_trigger_type *triggers, |
| 439 | struct buffer_head *bh) |
| 440 | { |
| 441 | mlog(ML_ERROR, |
| 442 | "ocfs2_abort_trigger called by JBD2. bh = 0x%lx, " |
| 443 | "bh->b_blocknr = %llu\n", |
| 444 | (unsigned long)bh, |
| 445 | (unsigned long long)bh->b_blocknr); |
| 446 | |
| 447 | /* We aren't guaranteed to have the superblock here - but if we |
| 448 | * don't, it'll just crash. */ |
| 449 | ocfs2_error(bh->b_assoc_map->host->i_sb, |
| 450 | "JBD2 has aborted our journal, ocfs2 cannot continue\n"); |
| 451 | } |
| 452 | |
| 453 | static struct ocfs2_triggers di_triggers = { |
| 454 | .ot_triggers = { |
| 455 | .t_commit = ocfs2_commit_trigger, |
| 456 | .t_abort = ocfs2_abort_trigger, |
| 457 | }, |
| 458 | .ot_offset = offsetof(struct ocfs2_dinode, i_check), |
| 459 | }; |
| 460 | |
| 461 | static struct ocfs2_triggers eb_triggers = { |
| 462 | .ot_triggers = { |
| 463 | .t_commit = ocfs2_commit_trigger, |
| 464 | .t_abort = ocfs2_abort_trigger, |
| 465 | }, |
| 466 | .ot_offset = offsetof(struct ocfs2_extent_block, h_check), |
| 467 | }; |
| 468 | |
| 469 | static struct ocfs2_triggers gd_triggers = { |
| 470 | .ot_triggers = { |
| 471 | .t_commit = ocfs2_commit_trigger, |
| 472 | .t_abort = ocfs2_abort_trigger, |
| 473 | }, |
| 474 | .ot_offset = offsetof(struct ocfs2_group_desc, bg_check), |
| 475 | }; |
| 476 | |
Joel Becker | c175a51 | 2008-12-10 17:58:22 -0800 | [diff] [blame^] | 477 | static struct ocfs2_triggers db_triggers = { |
| 478 | .ot_triggers = { |
| 479 | .t_commit = ocfs2_db_commit_trigger, |
| 480 | .t_abort = ocfs2_abort_trigger, |
| 481 | }, |
| 482 | }; |
| 483 | |
Joel Becker | 50655ae | 2008-09-11 15:53:07 -0700 | [diff] [blame] | 484 | static struct ocfs2_triggers xb_triggers = { |
| 485 | .ot_triggers = { |
| 486 | .t_commit = ocfs2_commit_trigger, |
| 487 | .t_abort = ocfs2_abort_trigger, |
| 488 | }, |
| 489 | .ot_offset = offsetof(struct ocfs2_xattr_block, xb_check), |
| 490 | }; |
| 491 | |
| 492 | static struct ocfs2_triggers dq_triggers = { |
| 493 | .ot_triggers = { |
| 494 | .t_commit = ocfs2_dq_commit_trigger, |
| 495 | .t_abort = ocfs2_abort_trigger, |
| 496 | }, |
| 497 | }; |
| 498 | |
| 499 | static int __ocfs2_journal_access(handle_t *handle, |
| 500 | struct inode *inode, |
| 501 | struct buffer_head *bh, |
| 502 | struct ocfs2_triggers *triggers, |
| 503 | int type) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 504 | { |
| 505 | int status; |
| 506 | |
| 507 | BUG_ON(!inode); |
| 508 | BUG_ON(!handle); |
| 509 | BUG_ON(!bh); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 510 | |
Badari Pulavarty | 205f87f | 2006-03-26 01:38:00 -0800 | [diff] [blame] | 511 | mlog_entry("bh->b_blocknr=%llu, type=%d (\"%s\"), bh->b_size = %zu\n", |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 512 | (unsigned long long)bh->b_blocknr, type, |
| 513 | (type == OCFS2_JOURNAL_ACCESS_CREATE) ? |
| 514 | "OCFS2_JOURNAL_ACCESS_CREATE" : |
| 515 | "OCFS2_JOURNAL_ACCESS_WRITE", |
| 516 | bh->b_size); |
| 517 | |
| 518 | /* we can safely remove this assertion after testing. */ |
| 519 | if (!buffer_uptodate(bh)) { |
| 520 | mlog(ML_ERROR, "giving me a buffer that's not uptodate!\n"); |
| 521 | mlog(ML_ERROR, "b_blocknr=%llu\n", |
| 522 | (unsigned long long)bh->b_blocknr); |
| 523 | BUG(); |
| 524 | } |
| 525 | |
| 526 | /* Set the current transaction information on the inode so |
| 527 | * that the locking code knows whether it can drop it's locks |
| 528 | * on this inode or not. We're protected from the commit |
| 529 | * thread updating the current transaction id until |
| 530 | * ocfs2_commit_trans() because ocfs2_start_trans() took |
| 531 | * j_trans_barrier for us. */ |
| 532 | ocfs2_set_inode_lock_trans(OCFS2_SB(inode->i_sb)->journal, inode); |
| 533 | |
Mark Fasheh | 251b6ec | 2006-01-10 15:41:43 -0800 | [diff] [blame] | 534 | mutex_lock(&OCFS2_I(inode)->ip_io_mutex); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 535 | switch (type) { |
| 536 | case OCFS2_JOURNAL_ACCESS_CREATE: |
| 537 | case OCFS2_JOURNAL_ACCESS_WRITE: |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 538 | status = jbd2_journal_get_write_access(handle, bh); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 539 | break; |
| 540 | |
| 541 | case OCFS2_JOURNAL_ACCESS_UNDO: |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 542 | status = jbd2_journal_get_undo_access(handle, bh); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 543 | break; |
| 544 | |
| 545 | default: |
| 546 | status = -EINVAL; |
| 547 | mlog(ML_ERROR, "Uknown access type!\n"); |
| 548 | } |
Joel Becker | 50655ae | 2008-09-11 15:53:07 -0700 | [diff] [blame] | 549 | if (!status && ocfs2_meta_ecc(OCFS2_SB(inode->i_sb)) && triggers) |
| 550 | jbd2_journal_set_triggers(bh, &triggers->ot_triggers); |
Mark Fasheh | 251b6ec | 2006-01-10 15:41:43 -0800 | [diff] [blame] | 551 | mutex_unlock(&OCFS2_I(inode)->ip_io_mutex); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 552 | |
| 553 | if (status < 0) |
| 554 | mlog(ML_ERROR, "Error %d getting %d access to buffer!\n", |
| 555 | status, type); |
| 556 | |
| 557 | mlog_exit(status); |
| 558 | return status; |
| 559 | } |
| 560 | |
Joel Becker | 50655ae | 2008-09-11 15:53:07 -0700 | [diff] [blame] | 561 | int ocfs2_journal_access_di(handle_t *handle, struct inode *inode, |
| 562 | struct buffer_head *bh, int type) |
| 563 | { |
| 564 | return __ocfs2_journal_access(handle, inode, bh, &di_triggers, |
| 565 | type); |
| 566 | } |
| 567 | |
| 568 | int ocfs2_journal_access_eb(handle_t *handle, struct inode *inode, |
| 569 | struct buffer_head *bh, int type) |
| 570 | { |
| 571 | return __ocfs2_journal_access(handle, inode, bh, &eb_triggers, |
| 572 | type); |
| 573 | } |
| 574 | |
| 575 | int ocfs2_journal_access_gd(handle_t *handle, struct inode *inode, |
| 576 | struct buffer_head *bh, int type) |
| 577 | { |
| 578 | return __ocfs2_journal_access(handle, inode, bh, &gd_triggers, |
| 579 | type); |
| 580 | } |
| 581 | |
| 582 | int ocfs2_journal_access_db(handle_t *handle, struct inode *inode, |
| 583 | struct buffer_head *bh, int type) |
| 584 | { |
Joel Becker | c175a51 | 2008-12-10 17:58:22 -0800 | [diff] [blame^] | 585 | return __ocfs2_journal_access(handle, inode, bh, &db_triggers, |
| 586 | type); |
Joel Becker | 50655ae | 2008-09-11 15:53:07 -0700 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | int ocfs2_journal_access_xb(handle_t *handle, struct inode *inode, |
| 590 | struct buffer_head *bh, int type) |
| 591 | { |
| 592 | return __ocfs2_journal_access(handle, inode, bh, &xb_triggers, |
| 593 | type); |
| 594 | } |
| 595 | |
| 596 | int ocfs2_journal_access_dq(handle_t *handle, struct inode *inode, |
| 597 | struct buffer_head *bh, int type) |
| 598 | { |
| 599 | return __ocfs2_journal_access(handle, inode, bh, &dq_triggers, |
| 600 | type); |
| 601 | } |
| 602 | |
| 603 | int ocfs2_journal_access(handle_t *handle, struct inode *inode, |
| 604 | struct buffer_head *bh, int type) |
| 605 | { |
| 606 | return __ocfs2_journal_access(handle, inode, bh, NULL, type); |
| 607 | } |
| 608 | |
Mark Fasheh | 1fabe14 | 2006-10-09 18:11:45 -0700 | [diff] [blame] | 609 | int ocfs2_journal_dirty(handle_t *handle, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 610 | struct buffer_head *bh) |
| 611 | { |
| 612 | int status; |
| 613 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 614 | mlog_entry("(bh->b_blocknr=%llu)\n", |
| 615 | (unsigned long long)bh->b_blocknr); |
| 616 | |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 617 | status = jbd2_journal_dirty_metadata(handle, bh); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 618 | if (status < 0) |
| 619 | mlog(ML_ERROR, "Could not dirty metadata buffer. " |
| 620 | "(bh->b_blocknr=%llu)\n", |
| 621 | (unsigned long long)bh->b_blocknr); |
| 622 | |
| 623 | mlog_exit(status); |
| 624 | return status; |
| 625 | } |
| 626 | |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 627 | #define OCFS2_DEFAULT_COMMIT_INTERVAL (HZ * JBD2_DEFAULT_MAX_COMMIT_AGE) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 628 | |
| 629 | void ocfs2_set_journal_params(struct ocfs2_super *osb) |
| 630 | { |
| 631 | journal_t *journal = osb->journal->j_journal; |
Mark Fasheh | d147b3d | 2007-11-07 14:40:36 -0800 | [diff] [blame] | 632 | unsigned long commit_interval = OCFS2_DEFAULT_COMMIT_INTERVAL; |
| 633 | |
| 634 | if (osb->osb_commit_interval) |
| 635 | commit_interval = osb->osb_commit_interval; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 636 | |
| 637 | spin_lock(&journal->j_state_lock); |
Mark Fasheh | d147b3d | 2007-11-07 14:40:36 -0800 | [diff] [blame] | 638 | journal->j_commit_interval = commit_interval; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 639 | if (osb->s_mount_opt & OCFS2_MOUNT_BARRIER) |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 640 | journal->j_flags |= JBD2_BARRIER; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 641 | else |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 642 | journal->j_flags &= ~JBD2_BARRIER; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 643 | spin_unlock(&journal->j_state_lock); |
| 644 | } |
| 645 | |
| 646 | int ocfs2_journal_init(struct ocfs2_journal *journal, int *dirty) |
| 647 | { |
| 648 | int status = -1; |
| 649 | struct inode *inode = NULL; /* the journal inode */ |
| 650 | journal_t *j_journal = NULL; |
| 651 | struct ocfs2_dinode *di = NULL; |
| 652 | struct buffer_head *bh = NULL; |
| 653 | struct ocfs2_super *osb; |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 654 | int inode_lock = 0; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 655 | |
| 656 | mlog_entry_void(); |
| 657 | |
| 658 | BUG_ON(!journal); |
| 659 | |
| 660 | osb = journal->j_osb; |
| 661 | |
| 662 | /* already have the inode for our journal */ |
| 663 | inode = ocfs2_get_system_file_inode(osb, JOURNAL_SYSTEM_INODE, |
| 664 | osb->slot_num); |
| 665 | if (inode == NULL) { |
| 666 | status = -EACCES; |
| 667 | mlog_errno(status); |
| 668 | goto done; |
| 669 | } |
| 670 | if (is_bad_inode(inode)) { |
| 671 | mlog(ML_ERROR, "access error (bad inode)\n"); |
| 672 | iput(inode); |
| 673 | inode = NULL; |
| 674 | status = -EACCES; |
| 675 | goto done; |
| 676 | } |
| 677 | |
| 678 | SET_INODE_JOURNAL(inode); |
| 679 | OCFS2_I(inode)->ip_open_count++; |
| 680 | |
Mark Fasheh | 6eff579 | 2006-01-18 10:31:47 -0800 | [diff] [blame] | 681 | /* Skip recovery waits here - journal inode metadata never |
| 682 | * changes in a live cluster so it can be considered an |
| 683 | * exception to the rule. */ |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 684 | status = ocfs2_inode_lock_full(inode, &bh, 1, OCFS2_META_LOCK_RECOVERY); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 685 | if (status < 0) { |
| 686 | if (status != -ERESTARTSYS) |
| 687 | mlog(ML_ERROR, "Could not get lock on journal!\n"); |
| 688 | goto done; |
| 689 | } |
| 690 | |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 691 | inode_lock = 1; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 692 | di = (struct ocfs2_dinode *)bh->b_data; |
| 693 | |
| 694 | if (inode->i_size < OCFS2_MIN_JOURNAL_SIZE) { |
| 695 | mlog(ML_ERROR, "Journal file size (%lld) is too small!\n", |
| 696 | inode->i_size); |
| 697 | status = -EINVAL; |
| 698 | goto done; |
| 699 | } |
| 700 | |
| 701 | mlog(0, "inode->i_size = %lld\n", inode->i_size); |
Andrew Morton | 5515eff | 2006-03-26 01:37:53 -0800 | [diff] [blame] | 702 | mlog(0, "inode->i_blocks = %llu\n", |
| 703 | (unsigned long long)inode->i_blocks); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 704 | mlog(0, "inode->ip_clusters = %u\n", OCFS2_I(inode)->ip_clusters); |
| 705 | |
| 706 | /* call the kernels journal init function now */ |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 707 | j_journal = jbd2_journal_init_inode(inode); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 708 | if (j_journal == NULL) { |
| 709 | mlog(ML_ERROR, "Linux journal layer error\n"); |
| 710 | status = -EINVAL; |
| 711 | goto done; |
| 712 | } |
| 713 | |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 714 | mlog(0, "Returned from jbd2_journal_init_inode\n"); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 715 | mlog(0, "j_journal->j_maxlen = %u\n", j_journal->j_maxlen); |
| 716 | |
| 717 | *dirty = (le32_to_cpu(di->id1.journal1.ij_flags) & |
| 718 | OCFS2_JOURNAL_DIRTY_FL); |
| 719 | |
| 720 | journal->j_journal = j_journal; |
| 721 | journal->j_inode = inode; |
| 722 | journal->j_bh = bh; |
| 723 | |
| 724 | ocfs2_set_journal_params(osb); |
| 725 | |
| 726 | journal->j_state = OCFS2_JOURNAL_LOADED; |
| 727 | |
| 728 | status = 0; |
| 729 | done: |
| 730 | if (status < 0) { |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 731 | if (inode_lock) |
| 732 | ocfs2_inode_unlock(inode, 1); |
Mark Fasheh | a81cb88 | 2008-10-07 14:25:16 -0700 | [diff] [blame] | 733 | brelse(bh); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 734 | if (inode) { |
| 735 | OCFS2_I(inode)->ip_open_count--; |
| 736 | iput(inode); |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | mlog_exit(status); |
| 741 | return status; |
| 742 | } |
| 743 | |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 744 | static void ocfs2_bump_recovery_generation(struct ocfs2_dinode *di) |
| 745 | { |
| 746 | le32_add_cpu(&(di->id1.journal1.ij_recovery_generation), 1); |
| 747 | } |
| 748 | |
| 749 | static u32 ocfs2_get_recovery_generation(struct ocfs2_dinode *di) |
| 750 | { |
| 751 | return le32_to_cpu(di->id1.journal1.ij_recovery_generation); |
| 752 | } |
| 753 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 754 | static int ocfs2_journal_toggle_dirty(struct ocfs2_super *osb, |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 755 | int dirty, int replayed) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 756 | { |
| 757 | int status; |
| 758 | unsigned int flags; |
| 759 | struct ocfs2_journal *journal = osb->journal; |
| 760 | struct buffer_head *bh = journal->j_bh; |
| 761 | struct ocfs2_dinode *fe; |
| 762 | |
| 763 | mlog_entry_void(); |
| 764 | |
| 765 | fe = (struct ocfs2_dinode *)bh->b_data; |
Joel Becker | 10995aa | 2008-11-13 14:49:12 -0800 | [diff] [blame] | 766 | |
| 767 | /* The journal bh on the osb always comes from ocfs2_journal_init() |
| 768 | * and was validated there inside ocfs2_inode_lock_full(). It's a |
| 769 | * code bug if we mess it up. */ |
| 770 | BUG_ON(!OCFS2_IS_VALID_DINODE(fe)); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 771 | |
| 772 | flags = le32_to_cpu(fe->id1.journal1.ij_flags); |
| 773 | if (dirty) |
| 774 | flags |= OCFS2_JOURNAL_DIRTY_FL; |
| 775 | else |
| 776 | flags &= ~OCFS2_JOURNAL_DIRTY_FL; |
| 777 | fe->id1.journal1.ij_flags = cpu_to_le32(flags); |
| 778 | |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 779 | if (replayed) |
| 780 | ocfs2_bump_recovery_generation(fe); |
| 781 | |
Joel Becker | 13723d0 | 2008-10-17 19:25:01 -0700 | [diff] [blame] | 782 | ocfs2_compute_meta_ecc(osb->sb, bh->b_data, &fe->i_check); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 783 | status = ocfs2_write_block(osb, bh, journal->j_inode); |
| 784 | if (status < 0) |
| 785 | mlog_errno(status); |
| 786 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 787 | mlog_exit(status); |
| 788 | return status; |
| 789 | } |
| 790 | |
| 791 | /* |
| 792 | * If the journal has been kmalloc'd it needs to be freed after this |
| 793 | * call. |
| 794 | */ |
| 795 | void ocfs2_journal_shutdown(struct ocfs2_super *osb) |
| 796 | { |
| 797 | struct ocfs2_journal *journal = NULL; |
| 798 | int status = 0; |
| 799 | struct inode *inode = NULL; |
| 800 | int num_running_trans = 0; |
| 801 | |
| 802 | mlog_entry_void(); |
| 803 | |
Eric Sesterhenn / snakebyte | ebdec83 | 2006-01-27 10:32:52 +0100 | [diff] [blame] | 804 | BUG_ON(!osb); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 805 | |
| 806 | journal = osb->journal; |
| 807 | if (!journal) |
| 808 | goto done; |
| 809 | |
| 810 | inode = journal->j_inode; |
| 811 | |
| 812 | if (journal->j_state != OCFS2_JOURNAL_LOADED) |
| 813 | goto done; |
| 814 | |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 815 | /* need to inc inode use count - jbd2_journal_destroy will iput. */ |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 816 | if (!igrab(inode)) |
| 817 | BUG(); |
| 818 | |
| 819 | num_running_trans = atomic_read(&(osb->journal->j_num_trans)); |
| 820 | if (num_running_trans > 0) |
| 821 | mlog(0, "Shutting down journal: must wait on %d " |
| 822 | "running transactions!\n", |
| 823 | num_running_trans); |
| 824 | |
| 825 | /* Do a commit_cache here. It will flush our journal, *and* |
| 826 | * release any locks that are still held. |
| 827 | * set the SHUTDOWN flag and release the trans lock. |
| 828 | * the commit thread will take the trans lock for us below. */ |
| 829 | journal->j_state = OCFS2_JOURNAL_IN_SHUTDOWN; |
| 830 | |
| 831 | /* The OCFS2_JOURNAL_IN_SHUTDOWN will signal to commit_cache to not |
| 832 | * drop the trans_lock (which we want to hold until we |
| 833 | * completely destroy the journal. */ |
| 834 | if (osb->commit_task) { |
| 835 | /* Wait for the commit thread */ |
| 836 | mlog(0, "Waiting for ocfs2commit to exit....\n"); |
| 837 | kthread_stop(osb->commit_task); |
| 838 | osb->commit_task = NULL; |
| 839 | } |
| 840 | |
| 841 | BUG_ON(atomic_read(&(osb->journal->j_num_trans)) != 0); |
| 842 | |
Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 843 | if (ocfs2_mount_local(osb)) { |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 844 | jbd2_journal_lock_updates(journal->j_journal); |
| 845 | status = jbd2_journal_flush(journal->j_journal); |
| 846 | jbd2_journal_unlock_updates(journal->j_journal); |
Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 847 | if (status < 0) |
| 848 | mlog_errno(status); |
| 849 | } |
| 850 | |
| 851 | if (status == 0) { |
| 852 | /* |
| 853 | * Do not toggle if flush was unsuccessful otherwise |
| 854 | * will leave dirty metadata in a "clean" journal |
| 855 | */ |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 856 | status = ocfs2_journal_toggle_dirty(osb, 0, 0); |
Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 857 | if (status < 0) |
| 858 | mlog_errno(status); |
| 859 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 860 | |
| 861 | /* Shutdown the kernel journal system */ |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 862 | jbd2_journal_destroy(journal->j_journal); |
Sunil Mushran | ae0dff6 | 2008-10-22 13:24:29 -0700 | [diff] [blame] | 863 | journal->j_journal = NULL; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 864 | |
| 865 | OCFS2_I(inode)->ip_open_count--; |
| 866 | |
| 867 | /* unlock our journal */ |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 868 | ocfs2_inode_unlock(inode, 1); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 869 | |
| 870 | brelse(journal->j_bh); |
| 871 | journal->j_bh = NULL; |
| 872 | |
| 873 | journal->j_state = OCFS2_JOURNAL_FREE; |
| 874 | |
| 875 | // up_write(&journal->j_trans_barrier); |
| 876 | done: |
| 877 | if (inode) |
| 878 | iput(inode); |
| 879 | mlog_exit_void(); |
| 880 | } |
| 881 | |
| 882 | static void ocfs2_clear_journal_error(struct super_block *sb, |
| 883 | journal_t *journal, |
| 884 | int slot) |
| 885 | { |
| 886 | int olderr; |
| 887 | |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 888 | olderr = jbd2_journal_errno(journal); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 889 | if (olderr) { |
| 890 | mlog(ML_ERROR, "File system error %d recorded in " |
| 891 | "journal %u.\n", olderr, slot); |
| 892 | mlog(ML_ERROR, "File system on device %s needs checking.\n", |
| 893 | sb->s_id); |
| 894 | |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 895 | jbd2_journal_ack_err(journal); |
| 896 | jbd2_journal_clear_err(journal); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 897 | } |
| 898 | } |
| 899 | |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 900 | int ocfs2_journal_load(struct ocfs2_journal *journal, int local, int replayed) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 901 | { |
| 902 | int status = 0; |
| 903 | struct ocfs2_super *osb; |
| 904 | |
| 905 | mlog_entry_void(); |
| 906 | |
Julia Lawall | b1f3550 | 2008-03-04 15:21:05 -0800 | [diff] [blame] | 907 | BUG_ON(!journal); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 908 | |
| 909 | osb = journal->j_osb; |
| 910 | |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 911 | status = jbd2_journal_load(journal->j_journal); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 912 | if (status < 0) { |
| 913 | mlog(ML_ERROR, "Failed to load journal!\n"); |
| 914 | goto done; |
| 915 | } |
| 916 | |
| 917 | ocfs2_clear_journal_error(osb->sb, journal->j_journal, osb->slot_num); |
| 918 | |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 919 | status = ocfs2_journal_toggle_dirty(osb, 1, replayed); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 920 | if (status < 0) { |
| 921 | mlog_errno(status); |
| 922 | goto done; |
| 923 | } |
| 924 | |
| 925 | /* Launch the commit thread */ |
Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 926 | if (!local) { |
| 927 | osb->commit_task = kthread_run(ocfs2_commit_thread, osb, |
| 928 | "ocfs2cmt"); |
| 929 | if (IS_ERR(osb->commit_task)) { |
| 930 | status = PTR_ERR(osb->commit_task); |
| 931 | osb->commit_task = NULL; |
| 932 | mlog(ML_ERROR, "unable to launch ocfs2commit thread, " |
| 933 | "error=%d", status); |
| 934 | goto done; |
| 935 | } |
| 936 | } else |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 937 | osb->commit_task = NULL; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 938 | |
| 939 | done: |
| 940 | mlog_exit(status); |
| 941 | return status; |
| 942 | } |
| 943 | |
| 944 | |
| 945 | /* 'full' flag tells us whether we clear out all blocks or if we just |
| 946 | * mark the journal clean */ |
| 947 | int ocfs2_journal_wipe(struct ocfs2_journal *journal, int full) |
| 948 | { |
| 949 | int status; |
| 950 | |
| 951 | mlog_entry_void(); |
| 952 | |
Eric Sesterhenn / snakebyte | ebdec83 | 2006-01-27 10:32:52 +0100 | [diff] [blame] | 953 | BUG_ON(!journal); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 954 | |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 955 | status = jbd2_journal_wipe(journal->j_journal, full); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 956 | if (status < 0) { |
| 957 | mlog_errno(status); |
| 958 | goto bail; |
| 959 | } |
| 960 | |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 961 | status = ocfs2_journal_toggle_dirty(journal->j_osb, 0, 0); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 962 | if (status < 0) |
| 963 | mlog_errno(status); |
| 964 | |
| 965 | bail: |
| 966 | mlog_exit(status); |
| 967 | return status; |
| 968 | } |
| 969 | |
Joel Becker | 553abd0 | 2008-02-01 12:03:57 -0800 | [diff] [blame] | 970 | static int ocfs2_recovery_completed(struct ocfs2_super *osb) |
| 971 | { |
| 972 | int empty; |
| 973 | struct ocfs2_recovery_map *rm = osb->recovery_map; |
| 974 | |
| 975 | spin_lock(&osb->osb_lock); |
| 976 | empty = (rm->rm_used == 0); |
| 977 | spin_unlock(&osb->osb_lock); |
| 978 | |
| 979 | return empty; |
| 980 | } |
| 981 | |
| 982 | void ocfs2_wait_for_recovery(struct ocfs2_super *osb) |
| 983 | { |
| 984 | wait_event(osb->recovery_event, ocfs2_recovery_completed(osb)); |
| 985 | } |
| 986 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 987 | /* |
| 988 | * JBD Might read a cached version of another nodes journal file. We |
| 989 | * don't want this as this file changes often and we get no |
| 990 | * notification on those changes. The only way to be sure that we've |
| 991 | * got the most up to date version of those blocks then is to force |
| 992 | * read them off disk. Just searching through the buffer cache won't |
| 993 | * work as there may be pages backing this file which are still marked |
| 994 | * up to date. We know things can't change on this file underneath us |
| 995 | * as we have the lock by now :) |
| 996 | */ |
| 997 | static int ocfs2_force_read_journal(struct inode *inode) |
| 998 | { |
| 999 | int status = 0; |
Mark Fasheh | 4f902c3 | 2007-03-09 16:26:50 -0800 | [diff] [blame] | 1000 | int i; |
Mark Fasheh | 8110b07 | 2007-03-22 16:53:23 -0700 | [diff] [blame] | 1001 | u64 v_blkno, p_blkno, p_blocks, num_blocks; |
Mark Fasheh | 4f902c3 | 2007-03-09 16:26:50 -0800 | [diff] [blame] | 1002 | #define CONCURRENT_JOURNAL_FILL 32ULL |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1003 | struct buffer_head *bhs[CONCURRENT_JOURNAL_FILL]; |
| 1004 | |
| 1005 | mlog_entry_void(); |
| 1006 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1007 | memset(bhs, 0, sizeof(struct buffer_head *) * CONCURRENT_JOURNAL_FILL); |
| 1008 | |
Mark Fasheh | 8110b07 | 2007-03-22 16:53:23 -0700 | [diff] [blame] | 1009 | num_blocks = ocfs2_blocks_for_bytes(inode->i_sb, inode->i_size); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1010 | v_blkno = 0; |
Mark Fasheh | 8110b07 | 2007-03-22 16:53:23 -0700 | [diff] [blame] | 1011 | while (v_blkno < num_blocks) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1012 | status = ocfs2_extent_map_get_blocks(inode, v_blkno, |
Mark Fasheh | 49cb8d2 | 2007-03-09 16:21:46 -0800 | [diff] [blame] | 1013 | &p_blkno, &p_blocks, NULL); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1014 | if (status < 0) { |
| 1015 | mlog_errno(status); |
| 1016 | goto bail; |
| 1017 | } |
| 1018 | |
| 1019 | if (p_blocks > CONCURRENT_JOURNAL_FILL) |
| 1020 | p_blocks = CONCURRENT_JOURNAL_FILL; |
| 1021 | |
Mark Fasheh | dd4a2c2 | 2006-04-12 14:24:05 -0700 | [diff] [blame] | 1022 | /* We are reading journal data which should not |
| 1023 | * be put in the uptodate cache */ |
Joel Becker | da1e909 | 2008-10-09 17:20:29 -0700 | [diff] [blame] | 1024 | status = ocfs2_read_blocks_sync(OCFS2_SB(inode->i_sb), |
| 1025 | p_blkno, p_blocks, bhs); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1026 | if (status < 0) { |
| 1027 | mlog_errno(status); |
| 1028 | goto bail; |
| 1029 | } |
| 1030 | |
| 1031 | for(i = 0; i < p_blocks; i++) { |
| 1032 | brelse(bhs[i]); |
| 1033 | bhs[i] = NULL; |
| 1034 | } |
| 1035 | |
| 1036 | v_blkno += p_blocks; |
| 1037 | } |
| 1038 | |
| 1039 | bail: |
| 1040 | for(i = 0; i < CONCURRENT_JOURNAL_FILL; i++) |
Mark Fasheh | a81cb88 | 2008-10-07 14:25:16 -0700 | [diff] [blame] | 1041 | brelse(bhs[i]); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1042 | mlog_exit(status); |
| 1043 | return status; |
| 1044 | } |
| 1045 | |
| 1046 | struct ocfs2_la_recovery_item { |
| 1047 | struct list_head lri_list; |
| 1048 | int lri_slot; |
| 1049 | struct ocfs2_dinode *lri_la_dinode; |
| 1050 | struct ocfs2_dinode *lri_tl_dinode; |
Jan Kara | 2205363 | 2008-10-20 23:50:38 +0200 | [diff] [blame] | 1051 | struct ocfs2_quota_recovery *lri_qrec; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1052 | }; |
| 1053 | |
| 1054 | /* Does the second half of the recovery process. By this point, the |
| 1055 | * node is marked clean and can actually be considered recovered, |
| 1056 | * hence it's no longer in the recovery map, but there's still some |
| 1057 | * cleanup we can do which shouldn't happen within the recovery thread |
| 1058 | * as locking in that context becomes very difficult if we are to take |
| 1059 | * recovering nodes into account. |
| 1060 | * |
| 1061 | * NOTE: This function can and will sleep on recovery of other nodes |
| 1062 | * during cluster locking, just like any other ocfs2 process. |
| 1063 | */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1064 | void ocfs2_complete_recovery(struct work_struct *work) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1065 | { |
| 1066 | int ret; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1067 | struct ocfs2_journal *journal = |
| 1068 | container_of(work, struct ocfs2_journal, j_recovery_work); |
| 1069 | struct ocfs2_super *osb = journal->j_osb; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1070 | struct ocfs2_dinode *la_dinode, *tl_dinode; |
Christoph Hellwig | 800deef | 2007-05-17 16:03:13 +0200 | [diff] [blame] | 1071 | struct ocfs2_la_recovery_item *item, *n; |
Jan Kara | 2205363 | 2008-10-20 23:50:38 +0200 | [diff] [blame] | 1072 | struct ocfs2_quota_recovery *qrec; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1073 | LIST_HEAD(tmp_la_list); |
| 1074 | |
| 1075 | mlog_entry_void(); |
| 1076 | |
| 1077 | mlog(0, "completing recovery from keventd\n"); |
| 1078 | |
| 1079 | spin_lock(&journal->j_lock); |
| 1080 | list_splice_init(&journal->j_la_cleanups, &tmp_la_list); |
| 1081 | spin_unlock(&journal->j_lock); |
| 1082 | |
Christoph Hellwig | 800deef | 2007-05-17 16:03:13 +0200 | [diff] [blame] | 1083 | list_for_each_entry_safe(item, n, &tmp_la_list, lri_list) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1084 | list_del_init(&item->lri_list); |
| 1085 | |
| 1086 | mlog(0, "Complete recovery for slot %d\n", item->lri_slot); |
| 1087 | |
Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 1088 | ocfs2_wait_on_quotas(osb); |
| 1089 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1090 | la_dinode = item->lri_la_dinode; |
| 1091 | if (la_dinode) { |
Mark Fasheh | b069705 | 2006-03-03 10:24:33 -0800 | [diff] [blame] | 1092 | mlog(0, "Clean up local alloc %llu\n", |
Mark Fasheh | 1ca1a11 | 2007-04-27 16:01:25 -0700 | [diff] [blame] | 1093 | (unsigned long long)le64_to_cpu(la_dinode->i_blkno)); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1094 | |
| 1095 | ret = ocfs2_complete_local_alloc_recovery(osb, |
| 1096 | la_dinode); |
| 1097 | if (ret < 0) |
| 1098 | mlog_errno(ret); |
| 1099 | |
| 1100 | kfree(la_dinode); |
| 1101 | } |
| 1102 | |
| 1103 | tl_dinode = item->lri_tl_dinode; |
| 1104 | if (tl_dinode) { |
Mark Fasheh | b069705 | 2006-03-03 10:24:33 -0800 | [diff] [blame] | 1105 | mlog(0, "Clean up truncate log %llu\n", |
Mark Fasheh | 1ca1a11 | 2007-04-27 16:01:25 -0700 | [diff] [blame] | 1106 | (unsigned long long)le64_to_cpu(tl_dinode->i_blkno)); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1107 | |
| 1108 | ret = ocfs2_complete_truncate_log_recovery(osb, |
| 1109 | tl_dinode); |
| 1110 | if (ret < 0) |
| 1111 | mlog_errno(ret); |
| 1112 | |
| 1113 | kfree(tl_dinode); |
| 1114 | } |
| 1115 | |
| 1116 | ret = ocfs2_recover_orphans(osb, item->lri_slot); |
| 1117 | if (ret < 0) |
| 1118 | mlog_errno(ret); |
| 1119 | |
Jan Kara | 2205363 | 2008-10-20 23:50:38 +0200 | [diff] [blame] | 1120 | qrec = item->lri_qrec; |
| 1121 | if (qrec) { |
| 1122 | mlog(0, "Recovering quota files"); |
| 1123 | ret = ocfs2_finish_quota_recovery(osb, qrec, |
| 1124 | item->lri_slot); |
| 1125 | if (ret < 0) |
| 1126 | mlog_errno(ret); |
| 1127 | /* Recovery info is already freed now */ |
| 1128 | } |
| 1129 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1130 | kfree(item); |
| 1131 | } |
| 1132 | |
| 1133 | mlog(0, "Recovery completion\n"); |
| 1134 | mlog_exit_void(); |
| 1135 | } |
| 1136 | |
| 1137 | /* NOTE: This function always eats your references to la_dinode and |
| 1138 | * tl_dinode, either manually on error, or by passing them to |
| 1139 | * ocfs2_complete_recovery */ |
| 1140 | static void ocfs2_queue_recovery_completion(struct ocfs2_journal *journal, |
| 1141 | int slot_num, |
| 1142 | struct ocfs2_dinode *la_dinode, |
Jan Kara | 2205363 | 2008-10-20 23:50:38 +0200 | [diff] [blame] | 1143 | struct ocfs2_dinode *tl_dinode, |
| 1144 | struct ocfs2_quota_recovery *qrec) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1145 | { |
| 1146 | struct ocfs2_la_recovery_item *item; |
| 1147 | |
Sunil Mushran | afae00ab | 2006-04-12 14:37:00 -0700 | [diff] [blame] | 1148 | item = kmalloc(sizeof(struct ocfs2_la_recovery_item), GFP_NOFS); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1149 | if (!item) { |
| 1150 | /* Though we wish to avoid it, we are in fact safe in |
| 1151 | * skipping local alloc cleanup as fsck.ocfs2 is more |
| 1152 | * than capable of reclaiming unused space. */ |
| 1153 | if (la_dinode) |
| 1154 | kfree(la_dinode); |
| 1155 | |
| 1156 | if (tl_dinode) |
| 1157 | kfree(tl_dinode); |
| 1158 | |
Jan Kara | 2205363 | 2008-10-20 23:50:38 +0200 | [diff] [blame] | 1159 | if (qrec) |
| 1160 | ocfs2_free_quota_recovery(qrec); |
| 1161 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1162 | mlog_errno(-ENOMEM); |
| 1163 | return; |
| 1164 | } |
| 1165 | |
| 1166 | INIT_LIST_HEAD(&item->lri_list); |
| 1167 | item->lri_la_dinode = la_dinode; |
| 1168 | item->lri_slot = slot_num; |
| 1169 | item->lri_tl_dinode = tl_dinode; |
Jan Kara | 2205363 | 2008-10-20 23:50:38 +0200 | [diff] [blame] | 1170 | item->lri_qrec = qrec; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1171 | |
| 1172 | spin_lock(&journal->j_lock); |
| 1173 | list_add_tail(&item->lri_list, &journal->j_la_cleanups); |
| 1174 | queue_work(ocfs2_wq, &journal->j_recovery_work); |
| 1175 | spin_unlock(&journal->j_lock); |
| 1176 | } |
| 1177 | |
| 1178 | /* Called by the mount code to queue recovery the last part of |
| 1179 | * recovery for it's own slot. */ |
| 1180 | void ocfs2_complete_mount_recovery(struct ocfs2_super *osb) |
| 1181 | { |
| 1182 | struct ocfs2_journal *journal = osb->journal; |
| 1183 | |
| 1184 | if (osb->dirty) { |
| 1185 | /* No need to queue up our truncate_log as regular |
| 1186 | * cleanup will catch that. */ |
| 1187 | ocfs2_queue_recovery_completion(journal, |
| 1188 | osb->slot_num, |
| 1189 | osb->local_alloc_copy, |
Jan Kara | 2205363 | 2008-10-20 23:50:38 +0200 | [diff] [blame] | 1190 | NULL, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1191 | NULL); |
| 1192 | ocfs2_schedule_truncate_log_flush(osb, 0); |
| 1193 | |
| 1194 | osb->local_alloc_copy = NULL; |
| 1195 | osb->dirty = 0; |
| 1196 | } |
| 1197 | } |
| 1198 | |
Jan Kara | 2205363 | 2008-10-20 23:50:38 +0200 | [diff] [blame] | 1199 | void ocfs2_complete_quota_recovery(struct ocfs2_super *osb) |
| 1200 | { |
| 1201 | if (osb->quota_rec) { |
| 1202 | ocfs2_queue_recovery_completion(osb->journal, |
| 1203 | osb->slot_num, |
| 1204 | NULL, |
| 1205 | NULL, |
| 1206 | osb->quota_rec); |
| 1207 | osb->quota_rec = NULL; |
| 1208 | } |
| 1209 | } |
| 1210 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1211 | static int __ocfs2_recovery_thread(void *arg) |
| 1212 | { |
Jan Kara | 2205363 | 2008-10-20 23:50:38 +0200 | [diff] [blame] | 1213 | int status, node_num, slot_num; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1214 | struct ocfs2_super *osb = arg; |
Joel Becker | 553abd0 | 2008-02-01 12:03:57 -0800 | [diff] [blame] | 1215 | struct ocfs2_recovery_map *rm = osb->recovery_map; |
Jan Kara | 2205363 | 2008-10-20 23:50:38 +0200 | [diff] [blame] | 1216 | int *rm_quota = NULL; |
| 1217 | int rm_quota_used = 0, i; |
| 1218 | struct ocfs2_quota_recovery *qrec; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1219 | |
| 1220 | mlog_entry_void(); |
| 1221 | |
| 1222 | status = ocfs2_wait_on_mount(osb); |
| 1223 | if (status < 0) { |
| 1224 | goto bail; |
| 1225 | } |
| 1226 | |
Jan Kara | 2205363 | 2008-10-20 23:50:38 +0200 | [diff] [blame] | 1227 | rm_quota = kzalloc(osb->max_slots * sizeof(int), GFP_NOFS); |
| 1228 | if (!rm_quota) { |
| 1229 | status = -ENOMEM; |
| 1230 | goto bail; |
| 1231 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1232 | restart: |
| 1233 | status = ocfs2_super_lock(osb, 1); |
| 1234 | if (status < 0) { |
| 1235 | mlog_errno(status); |
| 1236 | goto bail; |
| 1237 | } |
| 1238 | |
Joel Becker | 553abd0 | 2008-02-01 12:03:57 -0800 | [diff] [blame] | 1239 | spin_lock(&osb->osb_lock); |
| 1240 | while (rm->rm_used) { |
| 1241 | /* It's always safe to remove entry zero, as we won't |
| 1242 | * clear it until ocfs2_recover_node() has succeeded. */ |
| 1243 | node_num = rm->rm_entries[0]; |
| 1244 | spin_unlock(&osb->osb_lock); |
Jan Kara | 2205363 | 2008-10-20 23:50:38 +0200 | [diff] [blame] | 1245 | mlog(0, "checking node %d\n", node_num); |
| 1246 | slot_num = ocfs2_node_num_to_slot(osb, node_num); |
| 1247 | if (slot_num == -ENOENT) { |
| 1248 | status = 0; |
| 1249 | mlog(0, "no slot for this node, so no recovery" |
| 1250 | "required.\n"); |
| 1251 | goto skip_recovery; |
| 1252 | } |
| 1253 | mlog(0, "node %d was using slot %d\n", node_num, slot_num); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1254 | |
Jan Kara | 2205363 | 2008-10-20 23:50:38 +0200 | [diff] [blame] | 1255 | /* It is a bit subtle with quota recovery. We cannot do it |
| 1256 | * immediately because we have to obtain cluster locks from |
| 1257 | * quota files and we also don't want to just skip it because |
| 1258 | * then quota usage would be out of sync until some node takes |
| 1259 | * the slot. So we remember which nodes need quota recovery |
| 1260 | * and when everything else is done, we recover quotas. */ |
| 1261 | for (i = 0; i < rm_quota_used && rm_quota[i] != slot_num; i++); |
| 1262 | if (i == rm_quota_used) |
| 1263 | rm_quota[rm_quota_used++] = slot_num; |
| 1264 | |
| 1265 | status = ocfs2_recover_node(osb, node_num, slot_num); |
| 1266 | skip_recovery: |
Joel Becker | 553abd0 | 2008-02-01 12:03:57 -0800 | [diff] [blame] | 1267 | if (!status) { |
| 1268 | ocfs2_recovery_map_clear(osb, node_num); |
| 1269 | } else { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1270 | mlog(ML_ERROR, |
| 1271 | "Error %d recovering node %d on device (%u,%u)!\n", |
| 1272 | status, node_num, |
| 1273 | MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev)); |
| 1274 | mlog(ML_ERROR, "Volume requires unmount.\n"); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1275 | } |
| 1276 | |
Joel Becker | 553abd0 | 2008-02-01 12:03:57 -0800 | [diff] [blame] | 1277 | spin_lock(&osb->osb_lock); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1278 | } |
Joel Becker | 553abd0 | 2008-02-01 12:03:57 -0800 | [diff] [blame] | 1279 | spin_unlock(&osb->osb_lock); |
| 1280 | mlog(0, "All nodes recovered\n"); |
| 1281 | |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1282 | /* Refresh all journal recovery generations from disk */ |
| 1283 | status = ocfs2_check_journals_nolocks(osb); |
| 1284 | status = (status == -EROFS) ? 0 : status; |
| 1285 | if (status < 0) |
| 1286 | mlog_errno(status); |
| 1287 | |
Jan Kara | 2205363 | 2008-10-20 23:50:38 +0200 | [diff] [blame] | 1288 | /* Now it is right time to recover quotas... We have to do this under |
| 1289 | * superblock lock so that noone can start using the slot (and crash) |
| 1290 | * before we recover it */ |
| 1291 | for (i = 0; i < rm_quota_used; i++) { |
| 1292 | qrec = ocfs2_begin_quota_recovery(osb, rm_quota[i]); |
| 1293 | if (IS_ERR(qrec)) { |
| 1294 | status = PTR_ERR(qrec); |
| 1295 | mlog_errno(status); |
| 1296 | continue; |
| 1297 | } |
| 1298 | ocfs2_queue_recovery_completion(osb->journal, rm_quota[i], |
| 1299 | NULL, NULL, qrec); |
| 1300 | } |
| 1301 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1302 | ocfs2_super_unlock(osb, 1); |
| 1303 | |
| 1304 | /* We always run recovery on our own orphan dir - the dead |
Mark Fasheh | 34d024f | 2007-09-24 15:56:19 -0700 | [diff] [blame] | 1305 | * node(s) may have disallowd a previos inode delete. Re-processing |
| 1306 | * is therefore required. */ |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1307 | ocfs2_queue_recovery_completion(osb->journal, osb->slot_num, NULL, |
Jan Kara | 2205363 | 2008-10-20 23:50:38 +0200 | [diff] [blame] | 1308 | NULL, NULL); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1309 | |
| 1310 | bail: |
Arjan van de Ven | c74ec2f | 2006-01-13 21:54:23 -0800 | [diff] [blame] | 1311 | mutex_lock(&osb->recovery_lock); |
Joel Becker | 553abd0 | 2008-02-01 12:03:57 -0800 | [diff] [blame] | 1312 | if (!status && !ocfs2_recovery_completed(osb)) { |
Arjan van de Ven | c74ec2f | 2006-01-13 21:54:23 -0800 | [diff] [blame] | 1313 | mutex_unlock(&osb->recovery_lock); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1314 | goto restart; |
| 1315 | } |
| 1316 | |
| 1317 | osb->recovery_thread_task = NULL; |
| 1318 | mb(); /* sync with ocfs2_recovery_thread_running */ |
| 1319 | wake_up(&osb->recovery_event); |
| 1320 | |
Arjan van de Ven | c74ec2f | 2006-01-13 21:54:23 -0800 | [diff] [blame] | 1321 | mutex_unlock(&osb->recovery_lock); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1322 | |
Jan Kara | 2205363 | 2008-10-20 23:50:38 +0200 | [diff] [blame] | 1323 | if (rm_quota) |
| 1324 | kfree(rm_quota); |
| 1325 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1326 | mlog_exit(status); |
| 1327 | /* no one is callint kthread_stop() for us so the kthread() api |
| 1328 | * requires that we call do_exit(). And it isn't exported, but |
| 1329 | * complete_and_exit() seems to be a minimal wrapper around it. */ |
| 1330 | complete_and_exit(NULL, status); |
| 1331 | return status; |
| 1332 | } |
| 1333 | |
| 1334 | void ocfs2_recovery_thread(struct ocfs2_super *osb, int node_num) |
| 1335 | { |
| 1336 | mlog_entry("(node_num=%d, osb->node_num = %d)\n", |
| 1337 | node_num, osb->node_num); |
| 1338 | |
Arjan van de Ven | c74ec2f | 2006-01-13 21:54:23 -0800 | [diff] [blame] | 1339 | mutex_lock(&osb->recovery_lock); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1340 | if (osb->disable_recovery) |
| 1341 | goto out; |
| 1342 | |
| 1343 | /* People waiting on recovery will wait on |
| 1344 | * the recovery map to empty. */ |
Joel Becker | 553abd0 | 2008-02-01 12:03:57 -0800 | [diff] [blame] | 1345 | if (ocfs2_recovery_map_set(osb, node_num)) |
| 1346 | mlog(0, "node %d already in recovery map.\n", node_num); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1347 | |
| 1348 | mlog(0, "starting recovery thread...\n"); |
| 1349 | |
| 1350 | if (osb->recovery_thread_task) |
| 1351 | goto out; |
| 1352 | |
| 1353 | osb->recovery_thread_task = kthread_run(__ocfs2_recovery_thread, osb, |
Mark Fasheh | 7842704 | 2006-05-04 12:03:26 -0700 | [diff] [blame] | 1354 | "ocfs2rec"); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1355 | if (IS_ERR(osb->recovery_thread_task)) { |
| 1356 | mlog_errno((int)PTR_ERR(osb->recovery_thread_task)); |
| 1357 | osb->recovery_thread_task = NULL; |
| 1358 | } |
| 1359 | |
| 1360 | out: |
Arjan van de Ven | c74ec2f | 2006-01-13 21:54:23 -0800 | [diff] [blame] | 1361 | mutex_unlock(&osb->recovery_lock); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1362 | wake_up(&osb->recovery_event); |
| 1363 | |
| 1364 | mlog_exit_void(); |
| 1365 | } |
| 1366 | |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1367 | static int ocfs2_read_journal_inode(struct ocfs2_super *osb, |
| 1368 | int slot_num, |
| 1369 | struct buffer_head **bh, |
| 1370 | struct inode **ret_inode) |
| 1371 | { |
| 1372 | int status = -EACCES; |
| 1373 | struct inode *inode = NULL; |
| 1374 | |
| 1375 | BUG_ON(slot_num >= osb->max_slots); |
| 1376 | |
| 1377 | inode = ocfs2_get_system_file_inode(osb, JOURNAL_SYSTEM_INODE, |
| 1378 | slot_num); |
| 1379 | if (!inode || is_bad_inode(inode)) { |
| 1380 | mlog_errno(status); |
| 1381 | goto bail; |
| 1382 | } |
| 1383 | SET_INODE_JOURNAL(inode); |
| 1384 | |
Joel Becker | b657c95 | 2008-11-13 14:49:11 -0800 | [diff] [blame] | 1385 | status = ocfs2_read_inode_block_full(inode, bh, OCFS2_BH_IGNORE_CACHE); |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1386 | if (status < 0) { |
| 1387 | mlog_errno(status); |
| 1388 | goto bail; |
| 1389 | } |
| 1390 | |
| 1391 | status = 0; |
| 1392 | |
| 1393 | bail: |
| 1394 | if (inode) { |
| 1395 | if (status || !ret_inode) |
| 1396 | iput(inode); |
| 1397 | else |
| 1398 | *ret_inode = inode; |
| 1399 | } |
| 1400 | return status; |
| 1401 | } |
| 1402 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1403 | /* Does the actual journal replay and marks the journal inode as |
| 1404 | * clean. Will only replay if the journal inode is marked dirty. */ |
| 1405 | static int ocfs2_replay_journal(struct ocfs2_super *osb, |
| 1406 | int node_num, |
| 1407 | int slot_num) |
| 1408 | { |
| 1409 | int status; |
| 1410 | int got_lock = 0; |
| 1411 | unsigned int flags; |
| 1412 | struct inode *inode = NULL; |
| 1413 | struct ocfs2_dinode *fe; |
| 1414 | journal_t *journal = NULL; |
| 1415 | struct buffer_head *bh = NULL; |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1416 | u32 slot_reco_gen; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1417 | |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1418 | status = ocfs2_read_journal_inode(osb, slot_num, &bh, &inode); |
| 1419 | if (status) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1420 | mlog_errno(status); |
| 1421 | goto done; |
| 1422 | } |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1423 | |
| 1424 | fe = (struct ocfs2_dinode *)bh->b_data; |
| 1425 | slot_reco_gen = ocfs2_get_recovery_generation(fe); |
| 1426 | brelse(bh); |
| 1427 | bh = NULL; |
| 1428 | |
| 1429 | /* |
| 1430 | * As the fs recovery is asynchronous, there is a small chance that |
| 1431 | * another node mounted (and recovered) the slot before the recovery |
| 1432 | * thread could get the lock. To handle that, we dirty read the journal |
| 1433 | * inode for that slot to get the recovery generation. If it is |
| 1434 | * different than what we expected, the slot has been recovered. |
| 1435 | * If not, it needs recovery. |
| 1436 | */ |
| 1437 | if (osb->slot_recovery_generations[slot_num] != slot_reco_gen) { |
| 1438 | mlog(0, "Slot %u already recovered (old/new=%u/%u)\n", slot_num, |
| 1439 | osb->slot_recovery_generations[slot_num], slot_reco_gen); |
| 1440 | osb->slot_recovery_generations[slot_num] = slot_reco_gen; |
| 1441 | status = -EBUSY; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1442 | goto done; |
| 1443 | } |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1444 | |
| 1445 | /* Continue with recovery as the journal has not yet been recovered */ |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1446 | |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1447 | status = ocfs2_inode_lock_full(inode, &bh, 1, OCFS2_META_LOCK_RECOVERY); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1448 | if (status < 0) { |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1449 | mlog(0, "status returned from ocfs2_inode_lock=%d\n", status); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1450 | if (status != -ERESTARTSYS) |
| 1451 | mlog(ML_ERROR, "Could not lock journal!\n"); |
| 1452 | goto done; |
| 1453 | } |
| 1454 | got_lock = 1; |
| 1455 | |
| 1456 | fe = (struct ocfs2_dinode *) bh->b_data; |
| 1457 | |
| 1458 | flags = le32_to_cpu(fe->id1.journal1.ij_flags); |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1459 | slot_reco_gen = ocfs2_get_recovery_generation(fe); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1460 | |
| 1461 | if (!(flags & OCFS2_JOURNAL_DIRTY_FL)) { |
| 1462 | mlog(0, "No recovery required for node %d\n", node_num); |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1463 | /* Refresh recovery generation for the slot */ |
| 1464 | osb->slot_recovery_generations[slot_num] = slot_reco_gen; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1465 | goto done; |
| 1466 | } |
| 1467 | |
| 1468 | mlog(ML_NOTICE, "Recovering node %d from slot %d on device (%u,%u)\n", |
| 1469 | node_num, slot_num, |
| 1470 | MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev)); |
| 1471 | |
| 1472 | OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters); |
| 1473 | |
| 1474 | status = ocfs2_force_read_journal(inode); |
| 1475 | if (status < 0) { |
| 1476 | mlog_errno(status); |
| 1477 | goto done; |
| 1478 | } |
| 1479 | |
| 1480 | mlog(0, "calling journal_init_inode\n"); |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 1481 | journal = jbd2_journal_init_inode(inode); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1482 | if (journal == NULL) { |
| 1483 | mlog(ML_ERROR, "Linux journal layer error\n"); |
| 1484 | status = -EIO; |
| 1485 | goto done; |
| 1486 | } |
| 1487 | |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 1488 | status = jbd2_journal_load(journal); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1489 | if (status < 0) { |
| 1490 | mlog_errno(status); |
| 1491 | if (!igrab(inode)) |
| 1492 | BUG(); |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 1493 | jbd2_journal_destroy(journal); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1494 | goto done; |
| 1495 | } |
| 1496 | |
| 1497 | ocfs2_clear_journal_error(osb->sb, journal, slot_num); |
| 1498 | |
| 1499 | /* wipe the journal */ |
| 1500 | mlog(0, "flushing the journal.\n"); |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 1501 | jbd2_journal_lock_updates(journal); |
| 1502 | status = jbd2_journal_flush(journal); |
| 1503 | jbd2_journal_unlock_updates(journal); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1504 | if (status < 0) |
| 1505 | mlog_errno(status); |
| 1506 | |
| 1507 | /* This will mark the node clean */ |
| 1508 | flags = le32_to_cpu(fe->id1.journal1.ij_flags); |
| 1509 | flags &= ~OCFS2_JOURNAL_DIRTY_FL; |
| 1510 | fe->id1.journal1.ij_flags = cpu_to_le32(flags); |
| 1511 | |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1512 | /* Increment recovery generation to indicate successful recovery */ |
| 1513 | ocfs2_bump_recovery_generation(fe); |
| 1514 | osb->slot_recovery_generations[slot_num] = |
| 1515 | ocfs2_get_recovery_generation(fe); |
| 1516 | |
Joel Becker | 13723d0 | 2008-10-17 19:25:01 -0700 | [diff] [blame] | 1517 | ocfs2_compute_meta_ecc(osb->sb, bh->b_data, &fe->i_check); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1518 | status = ocfs2_write_block(osb, bh, inode); |
| 1519 | if (status < 0) |
| 1520 | mlog_errno(status); |
| 1521 | |
| 1522 | if (!igrab(inode)) |
| 1523 | BUG(); |
| 1524 | |
Joel Becker | 2b4e30f | 2008-09-03 20:03:41 -0700 | [diff] [blame] | 1525 | jbd2_journal_destroy(journal); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1526 | |
| 1527 | done: |
| 1528 | /* drop the lock on this nodes journal */ |
| 1529 | if (got_lock) |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1530 | ocfs2_inode_unlock(inode, 1); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1531 | |
| 1532 | if (inode) |
| 1533 | iput(inode); |
| 1534 | |
Mark Fasheh | a81cb88 | 2008-10-07 14:25:16 -0700 | [diff] [blame] | 1535 | brelse(bh); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1536 | |
| 1537 | mlog_exit(status); |
| 1538 | return status; |
| 1539 | } |
| 1540 | |
| 1541 | /* |
| 1542 | * Do the most important parts of node recovery: |
| 1543 | * - Replay it's journal |
| 1544 | * - Stamp a clean local allocator file |
| 1545 | * - Stamp a clean truncate log |
| 1546 | * - Mark the node clean |
| 1547 | * |
| 1548 | * If this function completes without error, a node in OCFS2 can be |
| 1549 | * said to have been safely recovered. As a result, failure during the |
| 1550 | * second part of a nodes recovery process (local alloc recovery) is |
| 1551 | * far less concerning. |
| 1552 | */ |
| 1553 | static int ocfs2_recover_node(struct ocfs2_super *osb, |
Jan Kara | 2205363 | 2008-10-20 23:50:38 +0200 | [diff] [blame] | 1554 | int node_num, int slot_num) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1555 | { |
| 1556 | int status = 0; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1557 | struct ocfs2_dinode *la_copy = NULL; |
| 1558 | struct ocfs2_dinode *tl_copy = NULL; |
| 1559 | |
Jan Kara | 2205363 | 2008-10-20 23:50:38 +0200 | [diff] [blame] | 1560 | mlog_entry("(node_num=%d, slot_num=%d, osb->node_num = %d)\n", |
| 1561 | node_num, slot_num, osb->node_num); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1562 | |
| 1563 | /* Should not ever be called to recover ourselves -- in that |
| 1564 | * case we should've called ocfs2_journal_load instead. */ |
Eric Sesterhenn / snakebyte | ebdec83 | 2006-01-27 10:32:52 +0100 | [diff] [blame] | 1565 | BUG_ON(osb->node_num == node_num); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1566 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1567 | status = ocfs2_replay_journal(osb, node_num, slot_num); |
| 1568 | if (status < 0) { |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1569 | if (status == -EBUSY) { |
| 1570 | mlog(0, "Skipping recovery for slot %u (node %u) " |
| 1571 | "as another node has recovered it\n", slot_num, |
| 1572 | node_num); |
| 1573 | status = 0; |
| 1574 | goto done; |
| 1575 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1576 | mlog_errno(status); |
| 1577 | goto done; |
| 1578 | } |
| 1579 | |
| 1580 | /* Stamp a clean local alloc file AFTER recovering the journal... */ |
| 1581 | status = ocfs2_begin_local_alloc_recovery(osb, slot_num, &la_copy); |
| 1582 | if (status < 0) { |
| 1583 | mlog_errno(status); |
| 1584 | goto done; |
| 1585 | } |
| 1586 | |
| 1587 | /* An error from begin_truncate_log_recovery is not |
| 1588 | * serious enough to warrant halting the rest of |
| 1589 | * recovery. */ |
| 1590 | status = ocfs2_begin_truncate_log_recovery(osb, slot_num, &tl_copy); |
| 1591 | if (status < 0) |
| 1592 | mlog_errno(status); |
| 1593 | |
| 1594 | /* Likewise, this would be a strange but ultimately not so |
| 1595 | * harmful place to get an error... */ |
Mark Fasheh | 8e8a460 | 2008-02-01 11:59:09 -0800 | [diff] [blame] | 1596 | status = ocfs2_clear_slot(osb, slot_num); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1597 | if (status < 0) |
| 1598 | mlog_errno(status); |
| 1599 | |
| 1600 | /* This will kfree the memory pointed to by la_copy and tl_copy */ |
| 1601 | ocfs2_queue_recovery_completion(osb->journal, slot_num, la_copy, |
Jan Kara | 2205363 | 2008-10-20 23:50:38 +0200 | [diff] [blame] | 1602 | tl_copy, NULL); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1603 | |
| 1604 | status = 0; |
| 1605 | done: |
| 1606 | |
| 1607 | mlog_exit(status); |
| 1608 | return status; |
| 1609 | } |
| 1610 | |
| 1611 | /* Test node liveness by trylocking his journal. If we get the lock, |
| 1612 | * we drop it here. Return 0 if we got the lock, -EAGAIN if node is |
| 1613 | * still alive (we couldn't get the lock) and < 0 on error. */ |
| 1614 | static int ocfs2_trylock_journal(struct ocfs2_super *osb, |
| 1615 | int slot_num) |
| 1616 | { |
| 1617 | int status, flags; |
| 1618 | struct inode *inode = NULL; |
| 1619 | |
| 1620 | inode = ocfs2_get_system_file_inode(osb, JOURNAL_SYSTEM_INODE, |
| 1621 | slot_num); |
| 1622 | if (inode == NULL) { |
| 1623 | mlog(ML_ERROR, "access error\n"); |
| 1624 | status = -EACCES; |
| 1625 | goto bail; |
| 1626 | } |
| 1627 | if (is_bad_inode(inode)) { |
| 1628 | mlog(ML_ERROR, "access error (bad inode)\n"); |
| 1629 | iput(inode); |
| 1630 | inode = NULL; |
| 1631 | status = -EACCES; |
| 1632 | goto bail; |
| 1633 | } |
| 1634 | SET_INODE_JOURNAL(inode); |
| 1635 | |
| 1636 | flags = OCFS2_META_LOCK_RECOVERY | OCFS2_META_LOCK_NOQUEUE; |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1637 | status = ocfs2_inode_lock_full(inode, NULL, 1, flags); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1638 | if (status < 0) { |
| 1639 | if (status != -EAGAIN) |
| 1640 | mlog_errno(status); |
| 1641 | goto bail; |
| 1642 | } |
| 1643 | |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1644 | ocfs2_inode_unlock(inode, 1); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1645 | bail: |
| 1646 | if (inode) |
| 1647 | iput(inode); |
| 1648 | |
| 1649 | return status; |
| 1650 | } |
| 1651 | |
| 1652 | /* Call this underneath ocfs2_super_lock. It also assumes that the |
| 1653 | * slot info struct has been updated from disk. */ |
| 1654 | int ocfs2_mark_dead_nodes(struct ocfs2_super *osb) |
| 1655 | { |
Joel Becker | d85b20e | 2008-02-01 12:01:05 -0800 | [diff] [blame] | 1656 | unsigned int node_num; |
| 1657 | int status, i; |
Mark Fasheh | a1af7d1 | 2008-08-19 17:20:28 -0700 | [diff] [blame] | 1658 | u32 gen; |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1659 | struct buffer_head *bh = NULL; |
| 1660 | struct ocfs2_dinode *di; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1661 | |
| 1662 | /* This is called with the super block cluster lock, so we |
| 1663 | * know that the slot map can't change underneath us. */ |
| 1664 | |
Joel Becker | d85b20e | 2008-02-01 12:01:05 -0800 | [diff] [blame] | 1665 | for (i = 0; i < osb->max_slots; i++) { |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1666 | /* Read journal inode to get the recovery generation */ |
| 1667 | status = ocfs2_read_journal_inode(osb, i, &bh, NULL); |
| 1668 | if (status) { |
| 1669 | mlog_errno(status); |
| 1670 | goto bail; |
| 1671 | } |
| 1672 | di = (struct ocfs2_dinode *)bh->b_data; |
Mark Fasheh | a1af7d1 | 2008-08-19 17:20:28 -0700 | [diff] [blame] | 1673 | gen = ocfs2_get_recovery_generation(di); |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1674 | brelse(bh); |
| 1675 | bh = NULL; |
| 1676 | |
Mark Fasheh | a1af7d1 | 2008-08-19 17:20:28 -0700 | [diff] [blame] | 1677 | spin_lock(&osb->osb_lock); |
| 1678 | osb->slot_recovery_generations[i] = gen; |
| 1679 | |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1680 | mlog(0, "Slot %u recovery generation is %u\n", i, |
| 1681 | osb->slot_recovery_generations[i]); |
| 1682 | |
Mark Fasheh | a1af7d1 | 2008-08-19 17:20:28 -0700 | [diff] [blame] | 1683 | if (i == osb->slot_num) { |
| 1684 | spin_unlock(&osb->osb_lock); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1685 | continue; |
Mark Fasheh | a1af7d1 | 2008-08-19 17:20:28 -0700 | [diff] [blame] | 1686 | } |
Joel Becker | d85b20e | 2008-02-01 12:01:05 -0800 | [diff] [blame] | 1687 | |
| 1688 | status = ocfs2_slot_to_node_num_locked(osb, i, &node_num); |
Mark Fasheh | a1af7d1 | 2008-08-19 17:20:28 -0700 | [diff] [blame] | 1689 | if (status == -ENOENT) { |
| 1690 | spin_unlock(&osb->osb_lock); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1691 | continue; |
Mark Fasheh | a1af7d1 | 2008-08-19 17:20:28 -0700 | [diff] [blame] | 1692 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1693 | |
Mark Fasheh | a1af7d1 | 2008-08-19 17:20:28 -0700 | [diff] [blame] | 1694 | if (__ocfs2_recovery_map_test(osb, node_num)) { |
| 1695 | spin_unlock(&osb->osb_lock); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1696 | continue; |
Mark Fasheh | a1af7d1 | 2008-08-19 17:20:28 -0700 | [diff] [blame] | 1697 | } |
Joel Becker | d85b20e | 2008-02-01 12:01:05 -0800 | [diff] [blame] | 1698 | spin_unlock(&osb->osb_lock); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1699 | |
| 1700 | /* Ok, we have a slot occupied by another node which |
| 1701 | * is not in the recovery map. We trylock his journal |
| 1702 | * file here to test if he's alive. */ |
| 1703 | status = ocfs2_trylock_journal(osb, i); |
| 1704 | if (!status) { |
| 1705 | /* Since we're called from mount, we know that |
| 1706 | * the recovery thread can't race us on |
| 1707 | * setting / checking the recovery bits. */ |
| 1708 | ocfs2_recovery_thread(osb, node_num); |
| 1709 | } else if ((status < 0) && (status != -EAGAIN)) { |
| 1710 | mlog_errno(status); |
| 1711 | goto bail; |
| 1712 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1713 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1714 | |
| 1715 | status = 0; |
| 1716 | bail: |
| 1717 | mlog_exit(status); |
| 1718 | return status; |
| 1719 | } |
| 1720 | |
Mark Fasheh | 5eae5b9 | 2007-09-10 17:50:51 -0700 | [diff] [blame] | 1721 | struct ocfs2_orphan_filldir_priv { |
| 1722 | struct inode *head; |
| 1723 | struct ocfs2_super *osb; |
| 1724 | }; |
| 1725 | |
| 1726 | static int ocfs2_orphan_filldir(void *priv, const char *name, int name_len, |
| 1727 | loff_t pos, u64 ino, unsigned type) |
| 1728 | { |
| 1729 | struct ocfs2_orphan_filldir_priv *p = priv; |
| 1730 | struct inode *iter; |
| 1731 | |
| 1732 | if (name_len == 1 && !strncmp(".", name, 1)) |
| 1733 | return 0; |
| 1734 | if (name_len == 2 && !strncmp("..", name, 2)) |
| 1735 | return 0; |
| 1736 | |
| 1737 | /* Skip bad inodes so that recovery can continue */ |
| 1738 | iter = ocfs2_iget(p->osb, ino, |
Jan Kara | 5fa0613 | 2008-01-11 00:11:45 +0100 | [diff] [blame] | 1739 | OCFS2_FI_FLAG_ORPHAN_RECOVERY, 0); |
Mark Fasheh | 5eae5b9 | 2007-09-10 17:50:51 -0700 | [diff] [blame] | 1740 | if (IS_ERR(iter)) |
| 1741 | return 0; |
| 1742 | |
| 1743 | mlog(0, "queue orphan %llu\n", |
| 1744 | (unsigned long long)OCFS2_I(iter)->ip_blkno); |
| 1745 | /* No locking is required for the next_orphan queue as there |
| 1746 | * is only ever a single process doing orphan recovery. */ |
| 1747 | OCFS2_I(iter)->ip_next_orphan = p->head; |
| 1748 | p->head = iter; |
| 1749 | |
| 1750 | return 0; |
| 1751 | } |
| 1752 | |
Mark Fasheh | b4df6ed | 2006-02-22 17:35:08 -0800 | [diff] [blame] | 1753 | static int ocfs2_queue_orphans(struct ocfs2_super *osb, |
| 1754 | int slot, |
| 1755 | struct inode **head) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1756 | { |
Mark Fasheh | b4df6ed | 2006-02-22 17:35:08 -0800 | [diff] [blame] | 1757 | int status; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1758 | struct inode *orphan_dir_inode = NULL; |
Mark Fasheh | 5eae5b9 | 2007-09-10 17:50:51 -0700 | [diff] [blame] | 1759 | struct ocfs2_orphan_filldir_priv priv; |
| 1760 | loff_t pos = 0; |
| 1761 | |
| 1762 | priv.osb = osb; |
| 1763 | priv.head = *head; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1764 | |
| 1765 | orphan_dir_inode = ocfs2_get_system_file_inode(osb, |
| 1766 | ORPHAN_DIR_SYSTEM_INODE, |
| 1767 | slot); |
| 1768 | if (!orphan_dir_inode) { |
| 1769 | status = -ENOENT; |
| 1770 | mlog_errno(status); |
Mark Fasheh | b4df6ed | 2006-02-22 17:35:08 -0800 | [diff] [blame] | 1771 | return status; |
| 1772 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1773 | |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 1774 | mutex_lock(&orphan_dir_inode->i_mutex); |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1775 | status = ocfs2_inode_lock(orphan_dir_inode, NULL, 0); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1776 | if (status < 0) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1777 | mlog_errno(status); |
| 1778 | goto out; |
| 1779 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1780 | |
Mark Fasheh | 5eae5b9 | 2007-09-10 17:50:51 -0700 | [diff] [blame] | 1781 | status = ocfs2_dir_foreach(orphan_dir_inode, &pos, &priv, |
| 1782 | ocfs2_orphan_filldir); |
| 1783 | if (status) { |
| 1784 | mlog_errno(status); |
Mark Fasheh | a86370f | 2007-12-03 14:06:23 -0800 | [diff] [blame] | 1785 | goto out_cluster; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1786 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1787 | |
Mark Fasheh | 5eae5b9 | 2007-09-10 17:50:51 -0700 | [diff] [blame] | 1788 | *head = priv.head; |
| 1789 | |
Mark Fasheh | a86370f | 2007-12-03 14:06:23 -0800 | [diff] [blame] | 1790 | out_cluster: |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1791 | ocfs2_inode_unlock(orphan_dir_inode, 0); |
Mark Fasheh | b4df6ed | 2006-02-22 17:35:08 -0800 | [diff] [blame] | 1792 | out: |
| 1793 | mutex_unlock(&orphan_dir_inode->i_mutex); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1794 | iput(orphan_dir_inode); |
Mark Fasheh | b4df6ed | 2006-02-22 17:35:08 -0800 | [diff] [blame] | 1795 | return status; |
| 1796 | } |
| 1797 | |
| 1798 | static int ocfs2_orphan_recovery_can_continue(struct ocfs2_super *osb, |
| 1799 | int slot) |
| 1800 | { |
| 1801 | int ret; |
| 1802 | |
| 1803 | spin_lock(&osb->osb_lock); |
| 1804 | ret = !osb->osb_orphan_wipes[slot]; |
| 1805 | spin_unlock(&osb->osb_lock); |
| 1806 | return ret; |
| 1807 | } |
| 1808 | |
| 1809 | static void ocfs2_mark_recovering_orphan_dir(struct ocfs2_super *osb, |
| 1810 | int slot) |
| 1811 | { |
| 1812 | spin_lock(&osb->osb_lock); |
| 1813 | /* Mark ourselves such that new processes in delete_inode() |
| 1814 | * know to quit early. */ |
| 1815 | ocfs2_node_map_set_bit(osb, &osb->osb_recovering_orphan_dirs, slot); |
| 1816 | while (osb->osb_orphan_wipes[slot]) { |
| 1817 | /* If any processes are already in the middle of an |
| 1818 | * orphan wipe on this dir, then we need to wait for |
| 1819 | * them. */ |
| 1820 | spin_unlock(&osb->osb_lock); |
| 1821 | wait_event_interruptible(osb->osb_wipe_event, |
| 1822 | ocfs2_orphan_recovery_can_continue(osb, slot)); |
| 1823 | spin_lock(&osb->osb_lock); |
| 1824 | } |
| 1825 | spin_unlock(&osb->osb_lock); |
| 1826 | } |
| 1827 | |
| 1828 | static void ocfs2_clear_recovering_orphan_dir(struct ocfs2_super *osb, |
| 1829 | int slot) |
| 1830 | { |
| 1831 | ocfs2_node_map_clear_bit(osb, &osb->osb_recovering_orphan_dirs, slot); |
| 1832 | } |
| 1833 | |
| 1834 | /* |
| 1835 | * Orphan recovery. Each mounted node has it's own orphan dir which we |
| 1836 | * must run during recovery. Our strategy here is to build a list of |
| 1837 | * the inodes in the orphan dir and iget/iput them. The VFS does |
| 1838 | * (most) of the rest of the work. |
| 1839 | * |
| 1840 | * Orphan recovery can happen at any time, not just mount so we have a |
| 1841 | * couple of extra considerations. |
| 1842 | * |
| 1843 | * - We grab as many inodes as we can under the orphan dir lock - |
| 1844 | * doing iget() outside the orphan dir risks getting a reference on |
| 1845 | * an invalid inode. |
| 1846 | * - We must be sure not to deadlock with other processes on the |
| 1847 | * system wanting to run delete_inode(). This can happen when they go |
| 1848 | * to lock the orphan dir and the orphan recovery process attempts to |
| 1849 | * iget() inside the orphan dir lock. This can be avoided by |
| 1850 | * advertising our state to ocfs2_delete_inode(). |
| 1851 | */ |
| 1852 | static int ocfs2_recover_orphans(struct ocfs2_super *osb, |
| 1853 | int slot) |
| 1854 | { |
| 1855 | int ret = 0; |
| 1856 | struct inode *inode = NULL; |
| 1857 | struct inode *iter; |
| 1858 | struct ocfs2_inode_info *oi; |
| 1859 | |
| 1860 | mlog(0, "Recover inodes from orphan dir in slot %d\n", slot); |
| 1861 | |
| 1862 | ocfs2_mark_recovering_orphan_dir(osb, slot); |
| 1863 | ret = ocfs2_queue_orphans(osb, slot, &inode); |
| 1864 | ocfs2_clear_recovering_orphan_dir(osb, slot); |
| 1865 | |
| 1866 | /* Error here should be noted, but we want to continue with as |
| 1867 | * many queued inodes as we've got. */ |
| 1868 | if (ret) |
| 1869 | mlog_errno(ret); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1870 | |
| 1871 | while (inode) { |
| 1872 | oi = OCFS2_I(inode); |
Mark Fasheh | b069705 | 2006-03-03 10:24:33 -0800 | [diff] [blame] | 1873 | mlog(0, "iput orphan %llu\n", (unsigned long long)oi->ip_blkno); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1874 | |
| 1875 | iter = oi->ip_next_orphan; |
| 1876 | |
| 1877 | spin_lock(&oi->ip_lock); |
Mark Fasheh | 34d024f | 2007-09-24 15:56:19 -0700 | [diff] [blame] | 1878 | /* The remote delete code may have set these on the |
| 1879 | * assumption that the other node would wipe them |
| 1880 | * successfully. If they are still in the node's |
| 1881 | * orphan dir, we need to reset that state. */ |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1882 | oi->ip_flags &= ~(OCFS2_INODE_DELETED|OCFS2_INODE_SKIP_DELETE); |
| 1883 | |
| 1884 | /* Set the proper information to get us going into |
| 1885 | * ocfs2_delete_inode. */ |
| 1886 | oi->ip_flags |= OCFS2_INODE_MAYBE_ORPHANED; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1887 | spin_unlock(&oi->ip_lock); |
| 1888 | |
| 1889 | iput(inode); |
| 1890 | |
| 1891 | inode = iter; |
| 1892 | } |
| 1893 | |
Mark Fasheh | b4df6ed | 2006-02-22 17:35:08 -0800 | [diff] [blame] | 1894 | return ret; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1895 | } |
| 1896 | |
Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 1897 | static int __ocfs2_wait_on_mount(struct ocfs2_super *osb, int quota) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1898 | { |
| 1899 | /* This check is good because ocfs2 will wait on our recovery |
| 1900 | * thread before changing it to something other than MOUNTED |
| 1901 | * or DISABLED. */ |
| 1902 | wait_event(osb->osb_mount_event, |
Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 1903 | (!quota && atomic_read(&osb->vol_state) == VOLUME_MOUNTED) || |
| 1904 | atomic_read(&osb->vol_state) == VOLUME_MOUNTED_QUOTAS || |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1905 | atomic_read(&osb->vol_state) == VOLUME_DISABLED); |
| 1906 | |
| 1907 | /* If there's an error on mount, then we may never get to the |
| 1908 | * MOUNTED flag, but this is set right before |
| 1909 | * dismount_volume() so we can trust it. */ |
| 1910 | if (atomic_read(&osb->vol_state) == VOLUME_DISABLED) { |
| 1911 | mlog(0, "mount error, exiting!\n"); |
| 1912 | return -EBUSY; |
| 1913 | } |
| 1914 | |
| 1915 | return 0; |
| 1916 | } |
| 1917 | |
| 1918 | static int ocfs2_commit_thread(void *arg) |
| 1919 | { |
| 1920 | int status; |
| 1921 | struct ocfs2_super *osb = arg; |
| 1922 | struct ocfs2_journal *journal = osb->journal; |
| 1923 | |
| 1924 | /* we can trust j_num_trans here because _should_stop() is only set in |
| 1925 | * shutdown and nobody other than ourselves should be able to start |
| 1926 | * transactions. committing on shutdown might take a few iterations |
| 1927 | * as final transactions put deleted inodes on the list */ |
| 1928 | while (!(kthread_should_stop() && |
| 1929 | atomic_read(&journal->j_num_trans) == 0)) { |
| 1930 | |
Mark Fasheh | 745ae8ba | 2006-02-09 13:23:39 -0800 | [diff] [blame] | 1931 | wait_event_interruptible(osb->checkpoint_event, |
| 1932 | atomic_read(&journal->j_num_trans) |
| 1933 | || kthread_should_stop()); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1934 | |
| 1935 | status = ocfs2_commit_cache(osb); |
| 1936 | if (status < 0) |
| 1937 | mlog_errno(status); |
| 1938 | |
| 1939 | if (kthread_should_stop() && atomic_read(&journal->j_num_trans)){ |
| 1940 | mlog(ML_KTHREAD, |
| 1941 | "commit_thread: %u transactions pending on " |
| 1942 | "shutdown\n", |
| 1943 | atomic_read(&journal->j_num_trans)); |
| 1944 | } |
| 1945 | } |
| 1946 | |
| 1947 | return 0; |
| 1948 | } |
| 1949 | |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1950 | /* Reads all the journal inodes without taking any cluster locks. Used |
| 1951 | * for hard readonly access to determine whether any journal requires |
| 1952 | * recovery. Also used to refresh the recovery generation numbers after |
| 1953 | * a journal has been recovered by another node. |
| 1954 | */ |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1955 | int ocfs2_check_journals_nolocks(struct ocfs2_super *osb) |
| 1956 | { |
| 1957 | int ret = 0; |
| 1958 | unsigned int slot; |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1959 | struct buffer_head *di_bh = NULL; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1960 | struct ocfs2_dinode *di; |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1961 | int journal_dirty = 0; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1962 | |
| 1963 | for(slot = 0; slot < osb->max_slots; slot++) { |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1964 | ret = ocfs2_read_journal_inode(osb, slot, &di_bh, NULL); |
| 1965 | if (ret) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1966 | mlog_errno(ret); |
| 1967 | goto out; |
| 1968 | } |
| 1969 | |
| 1970 | di = (struct ocfs2_dinode *) di_bh->b_data; |
| 1971 | |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1972 | osb->slot_recovery_generations[slot] = |
| 1973 | ocfs2_get_recovery_generation(di); |
| 1974 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1975 | if (le32_to_cpu(di->id1.journal1.ij_flags) & |
| 1976 | OCFS2_JOURNAL_DIRTY_FL) |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1977 | journal_dirty = 1; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1978 | |
| 1979 | brelse(di_bh); |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1980 | di_bh = NULL; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1981 | } |
| 1982 | |
| 1983 | out: |
Sunil Mushran | 539d826 | 2008-07-14 17:31:10 -0700 | [diff] [blame] | 1984 | if (journal_dirty) |
| 1985 | ret = -EROFS; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1986 | return ret; |
| 1987 | } |