Lines Matching refs:osb

49 static int ocfs2_recover_node(struct ocfs2_super *osb,
52 static int ocfs2_commit_cache(struct ocfs2_super *osb);
53 static int __ocfs2_wait_on_mount(struct ocfs2_super *osb, int quota);
54 static int ocfs2_journal_toggle_dirty(struct ocfs2_super *osb,
56 static int ocfs2_trylock_journal(struct ocfs2_super *osb,
58 static int ocfs2_recover_orphans(struct ocfs2_super *osb,
69 static inline int ocfs2_wait_on_mount(struct ocfs2_super *osb)
71 return __ocfs2_wait_on_mount(osb, 0);
74 static inline int ocfs2_wait_on_quotas(struct ocfs2_super *osb)
76 return __ocfs2_wait_on_mount(osb, 1);
96 static void ocfs2_replay_map_set_state(struct ocfs2_super *osb, int state)
98 if (!osb->replay_map)
102 if (osb->replay_map->rm_state == REPLAY_DONE)
105 osb->replay_map->rm_state = state;
108 int ocfs2_compute_replay_slots(struct ocfs2_super *osb)
114 if (osb->replay_map)
118 osb->max_slots),
125 spin_lock(&osb->osb_lock);
127 replay_map->rm_slots = osb->max_slots;
132 if (ocfs2_slot_to_node_num_locked(osb, i, &node_num) == -ENOENT)
136 osb->replay_map = replay_map;
137 spin_unlock(&osb->osb_lock);
141 static void ocfs2_queue_replay_slots(struct ocfs2_super *osb,
144 struct ocfs2_replay_map *replay_map = osb->replay_map;
155 ocfs2_queue_recovery_completion(osb->journal, i, NULL,
161 void ocfs2_free_replay_slots(struct ocfs2_super *osb)
163 struct ocfs2_replay_map *replay_map = osb->replay_map;
165 if (!osb->replay_map)
169 osb->replay_map = NULL;
172 int ocfs2_recovery_init(struct ocfs2_super *osb)
176 mutex_init(&osb->recovery_lock);
177 osb->disable_recovery = 0;
178 osb->recovery_thread_task = NULL;
179 init_waitqueue_head(&osb->recovery_event);
181 rm = kzalloc(struct_size(rm, rm_entries, osb->max_slots),
188 osb->recovery_map = rm;
196 static int ocfs2_recovery_thread_running(struct ocfs2_super *osb)
199 return osb->recovery_thread_task != NULL;
202 void ocfs2_recovery_exit(struct ocfs2_super *osb)
208 mutex_lock(&osb->recovery_lock);
209 osb->disable_recovery = 1;
210 mutex_unlock(&osb->recovery_lock);
211 wait_event(osb->recovery_event, !ocfs2_recovery_thread_running(osb));
216 if (osb->ocfs2_wq)
217 flush_workqueue(osb->ocfs2_wq);
220 * Now that recovery is shut down, and the osb is about to be
223 rm = osb->recovery_map;
229 static int __ocfs2_recovery_map_test(struct ocfs2_super *osb,
233 struct ocfs2_recovery_map *rm = osb->recovery_map;
235 assert_spin_locked(&osb->osb_lock);
246 static int ocfs2_recovery_map_set(struct ocfs2_super *osb,
249 struct ocfs2_recovery_map *rm = osb->recovery_map;
251 spin_lock(&osb->osb_lock);
252 if (__ocfs2_recovery_map_test(osb, node_num)) {
253 spin_unlock(&osb->osb_lock);
258 BUG_ON(rm->rm_used >= osb->max_slots);
262 spin_unlock(&osb->osb_lock);
267 static void ocfs2_recovery_map_clear(struct ocfs2_super *osb,
271 struct ocfs2_recovery_map *rm = osb->recovery_map;
273 spin_lock(&osb->osb_lock);
287 spin_unlock(&osb->osb_lock);
290 static int ocfs2_commit_cache(struct ocfs2_super *osb)
296 journal = osb->journal;
325 ocfs2_wake_downconvert_thread(osb);
331 handle_t *ocfs2_start_trans(struct ocfs2_super *osb, int max_buffs)
333 journal_t *journal = osb->journal->j_journal;
336 BUG_ON(!osb || !osb->journal->j_journal);
338 if (ocfs2_is_hard_readonly(osb))
341 BUG_ON(osb->journal->j_state == OCFS2_JOURNAL_FREE);
348 sb_start_intwrite(osb->sb);
350 down_read(&osb->journal->j_trans_barrier);
354 up_read(&osb->journal->j_trans_barrier);
355 sb_end_intwrite(osb->sb);
360 ocfs2_abort(osb->sb, "Detected aborted journal\n");
364 if (!ocfs2_mount_local(osb))
365 atomic_inc(&(osb->journal->j_num_trans));
371 int ocfs2_commit_trans(struct ocfs2_super *osb,
375 struct ocfs2_journal *journal = osb->journal;
386 sb_end_intwrite(osb->sb);
638 struct ocfs2_super *osb =
668 return ocfs2_error(osb->sb, "A previous attempt to "
680 ocfs2_set_ci_lock_trans(osb->journal, ci);
697 if (!status && ocfs2_meta_ecc(osb) && triggers)
794 void ocfs2_set_journal_params(struct ocfs2_super *osb)
796 journal_t *journal = osb->journal->j_journal;
799 if (osb->osb_commit_interval)
800 commit_interval = osb->osb_commit_interval;
804 if (osb->s_mount_opt & OCFS2_MOUNT_BARRIER)
815 int ocfs2_journal_alloc(struct ocfs2_super *osb)
826 osb->journal = journal;
827 journal->j_osb = osb;
855 int ocfs2_journal_init(struct ocfs2_super *osb, int *dirty)
860 struct ocfs2_journal *journal = osb->journal;
867 inode = ocfs2_get_system_file_inode(osb, JOURNAL_SYSTEM_INODE,
868 osb->slot_num);
930 ocfs2_set_journal_params(osb);
959 static int ocfs2_journal_toggle_dirty(struct ocfs2_super *osb,
964 struct ocfs2_journal *journal = osb->journal;
970 /* The journal bh on the osb always comes from ocfs2_journal_init()
985 ocfs2_compute_meta_ecc(osb->sb, bh->b_data, &fe->i_check);
986 status = ocfs2_write_block(osb, bh, INODE_CACHE(journal->j_inode));
997 void ocfs2_journal_shutdown(struct ocfs2_super *osb)
1004 BUG_ON(!osb);
1006 journal = osb->journal;
1019 num_running_trans = atomic_read(&(osb->journal->j_num_trans));
1031 if (osb->commit_task) {
1033 trace_ocfs2_journal_shutdown_wait(osb->commit_task);
1034 kthread_stop(osb->commit_task);
1035 osb->commit_task = NULL;
1038 BUG_ON(atomic_read(&(osb->journal->j_num_trans)) != 0);
1040 if (ocfs2_mount_local(osb)) {
1054 status = ocfs2_journal_toggle_dirty(osb, 0, 0);
1073 osb->journal = NULL;
1097 struct ocfs2_super *osb;
1101 osb = journal->j_osb;
1109 ocfs2_clear_journal_error(osb->sb, journal->j_journal, osb->slot_num);
1119 status = ocfs2_journal_toggle_dirty(osb, 1, replayed);
1127 osb->commit_task = kthread_run(ocfs2_commit_thread, osb,
1128 "ocfs2cmt-%s", osb->uuid_str);
1129 if (IS_ERR(osb->commit_task)) {
1130 status = PTR_ERR(osb->commit_task);
1131 osb->commit_task = NULL;
1137 osb->commit_task = NULL;
1166 static int ocfs2_recovery_completed(struct ocfs2_super *osb)
1169 struct ocfs2_recovery_map *rm = osb->recovery_map;
1171 spin_lock(&osb->osb_lock);
1173 spin_unlock(&osb->osb_lock);
1178 void ocfs2_wait_for_recovery(struct ocfs2_super *osb)
1180 wait_event(osb->recovery_event, ocfs2_recovery_completed(osb));
1199 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1212 bh = __find_get_block(osb->sb->s_bdev, p_blkno,
1213 osb->sb->s_blocksize);
1223 status = ocfs2_read_blocks_sync(osb, p_blkno, 1, &bh);
1264 struct ocfs2_super *osb = journal->j_osb;
1281 ocfs2_wait_on_quotas(osb);
1294 ret = ocfs2_complete_local_alloc_recovery(osb,
1303 ret = ocfs2_complete_truncate_log_recovery(osb,
1311 ret = ocfs2_recover_orphans(osb, item->lri_slot,
1317 ret = ocfs2_finish_quota_recovery(osb, qrec,
1372 void ocfs2_complete_mount_recovery(struct ocfs2_super *osb)
1374 struct ocfs2_journal *journal = osb->journal;
1376 if (ocfs2_is_hard_readonly(osb))
1381 ocfs2_queue_recovery_completion(journal, osb->slot_num,
1382 osb->local_alloc_copy, NULL, NULL,
1384 ocfs2_schedule_truncate_log_flush(osb, 0);
1386 osb->local_alloc_copy = NULL;
1389 ocfs2_replay_map_set_state(osb, REPLAY_NEEDED);
1390 ocfs2_queue_replay_slots(osb, ORPHAN_NEED_TRUNCATE);
1391 ocfs2_free_replay_slots(osb);
1394 void ocfs2_complete_quota_recovery(struct ocfs2_super *osb)
1396 if (osb->quota_rec) {
1397 ocfs2_queue_recovery_completion(osb->journal,
1398 osb->slot_num,
1401 osb->quota_rec,
1403 osb->quota_rec = NULL;
1410 struct ocfs2_super *osb = arg;
1411 struct ocfs2_recovery_map *rm = osb->recovery_map;
1417 int quota_enabled = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb,
1419 || OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb,
1422 status = ocfs2_wait_on_mount(osb);
1428 rm_quota = kcalloc(osb->max_slots, sizeof(int), GFP_NOFS);
1435 status = ocfs2_super_lock(osb, 1);
1441 status = ocfs2_compute_replay_slots(osb);
1446 ocfs2_queue_recovery_completion(osb->journal, osb->slot_num, NULL,
1449 spin_lock(&osb->osb_lock);
1454 spin_unlock(&osb->osb_lock);
1455 slot_num = ocfs2_node_num_to_slot(osb, node_num);
1477 status = ocfs2_recover_node(osb, node_num, slot_num);
1480 ocfs2_recovery_map_clear(osb, node_num);
1485 MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
1489 spin_lock(&osb->osb_lock);
1491 spin_unlock(&osb->osb_lock);
1495 status = ocfs2_check_journals_nolocks(osb);
1505 qrec = ocfs2_begin_quota_recovery(osb, rm_quota[i]);
1511 ocfs2_queue_recovery_completion(osb->journal,
1518 ocfs2_super_unlock(osb, 1);
1521 ocfs2_queue_replay_slots(osb, ORPHAN_NEED_TRUNCATE);
1524 mutex_lock(&osb->recovery_lock);
1525 if (!status && !ocfs2_recovery_completed(osb)) {
1526 mutex_unlock(&osb->recovery_lock);
1530 ocfs2_free_replay_slots(osb);
1531 osb->recovery_thread_task = NULL;
1533 wake_up(&osb->recovery_event);
1535 mutex_unlock(&osb->recovery_lock);
1543 void ocfs2_recovery_thread(struct ocfs2_super *osb, int node_num)
1545 mutex_lock(&osb->recovery_lock);
1547 trace_ocfs2_recovery_thread(node_num, osb->node_num,
1548 osb->disable_recovery, osb->recovery_thread_task,
1549 osb->disable_recovery ?
1550 -1 : ocfs2_recovery_map_set(osb, node_num));
1552 if (osb->disable_recovery)
1555 if (osb->recovery_thread_task)
1558 osb->recovery_thread_task = kthread_run(__ocfs2_recovery_thread, osb,
1559 "ocfs2rec-%s", osb->uuid_str);
1560 if (IS_ERR(osb->recovery_thread_task)) {
1561 mlog_errno((int)PTR_ERR(osb->recovery_thread_task));
1562 osb->recovery_thread_task = NULL;
1566 mutex_unlock(&osb->recovery_lock);
1567 wake_up(&osb->recovery_event);
1570 static int ocfs2_read_journal_inode(struct ocfs2_super *osb,
1578 BUG_ON(slot_num >= osb->max_slots);
1580 inode = ocfs2_get_system_file_inode(osb, JOURNAL_SYSTEM_INODE,
1608 static int ocfs2_replay_journal(struct ocfs2_super *osb,
1621 status = ocfs2_read_journal_inode(osb, slot_num, &bh, &inode);
1640 if (osb->slot_recovery_generations[slot_num] != slot_reco_gen) {
1642 osb->slot_recovery_generations[slot_num], slot_reco_gen);
1643 osb->slot_recovery_generations[slot_num] = slot_reco_gen;
1667 osb->slot_recovery_generations[slot_num] = slot_reco_gen;
1672 ocfs2_replay_map_set_state(osb, REPLAY_NEEDED);
1675 "device (%u,%u)\n", node_num, slot_num, MAJOR(osb->sb->s_dev),
1676 MINOR(osb->sb->s_dev));
1701 ocfs2_clear_journal_error(osb->sb, journal, slot_num);
1717 osb->slot_recovery_generations[slot_num] =
1720 ocfs2_compute_meta_ecc(osb->sb, bh->b_data, &fe->i_check);
1721 status = ocfs2_write_block(osb, bh, INODE_CACHE(inode));
1730 "device (%u,%u)\n", node_num, slot_num, MAJOR(osb->sb->s_dev),
1731 MINOR(osb->sb->s_dev));
1755 static int ocfs2_recover_node(struct ocfs2_super *osb,
1762 trace_ocfs2_recover_node(node_num, slot_num, osb->node_num);
1766 BUG_ON(osb->node_num == node_num);
1768 status = ocfs2_replay_journal(osb, node_num, slot_num);
1780 status = ocfs2_begin_local_alloc_recovery(osb, slot_num, &la_copy);
1789 status = ocfs2_begin_truncate_log_recovery(osb, slot_num, &tl_copy);
1795 status = ocfs2_clear_slot(osb, slot_num);
1800 ocfs2_queue_recovery_completion(osb->journal, slot_num, la_copy,
1812 static int ocfs2_trylock_journal(struct ocfs2_super *osb,
1818 inode = ocfs2_get_system_file_inode(osb, JOURNAL_SYSTEM_INODE,
1851 int ocfs2_mark_dead_nodes(struct ocfs2_super *osb)
1862 for (i = 0; i < osb->max_slots; i++) {
1864 status = ocfs2_read_journal_inode(osb, i, &bh, NULL);
1874 spin_lock(&osb->osb_lock);
1875 osb->slot_recovery_generations[i] = gen;
1878 osb->slot_recovery_generations[i]);
1880 if (i == osb->slot_num) {
1881 spin_unlock(&osb->osb_lock);
1885 status = ocfs2_slot_to_node_num_locked(osb, i, &node_num);
1887 spin_unlock(&osb->osb_lock);
1891 if (__ocfs2_recovery_map_test(osb, node_num)) {
1892 spin_unlock(&osb->osb_lock);
1895 spin_unlock(&osb->osb_lock);
1900 status = ocfs2_trylock_journal(osb, i);
1905 ocfs2_recovery_thread(osb, node_num);
1958 static void ocfs2_queue_orphan_scan(struct ocfs2_super *osb)
1964 os = &osb->osb_orphan_scan;
1972 status = ocfs2_orphan_scan_lock(osb, &seqno);
1988 for (i = 0; i < osb->max_slots; i++)
1989 ocfs2_queue_recovery_completion(osb->journal, i, NULL, NULL,
1999 ocfs2_orphan_scan_unlock(osb, seqno);
2010 struct ocfs2_super *osb;
2014 osb = os->os_osb;
2017 ocfs2_queue_orphan_scan(osb);
2019 queue_delayed_work(osb->ocfs2_wq, &os->os_orphan_scan_work,
2024 void ocfs2_orphan_scan_stop(struct ocfs2_super *osb)
2028 os = &osb->osb_orphan_scan;
2037 void ocfs2_orphan_scan_init(struct ocfs2_super *osb)
2041 os = &osb->osb_orphan_scan;
2042 os->os_osb = osb;
2049 void ocfs2_orphan_scan_start(struct ocfs2_super *osb)
2053 os = &osb->osb_orphan_scan;
2055 if (ocfs2_is_hard_readonly(osb) || ocfs2_mount_local(osb))
2059 queue_delayed_work(osb->ocfs2_wq, &os->os_orphan_scan_work,
2067 struct ocfs2_super *osb;
2091 iter = ocfs2_iget(p->osb, ino,
2116 static int ocfs2_queue_orphans(struct ocfs2_super *osb,
2125 .osb = osb,
2130 orphan_dir_inode = ocfs2_get_system_file_inode(osb,
2162 static int ocfs2_orphan_recovery_can_continue(struct ocfs2_super *osb,
2167 spin_lock(&osb->osb_lock);
2168 ret = !osb->osb_orphan_wipes[slot];
2169 spin_unlock(&osb->osb_lock);
2173 static void ocfs2_mark_recovering_orphan_dir(struct ocfs2_super *osb,
2176 spin_lock(&osb->osb_lock);
2179 ocfs2_node_map_set_bit(osb, &osb->osb_recovering_orphan_dirs, slot);
2180 while (osb->osb_orphan_wipes[slot]) {
2184 spin_unlock(&osb->osb_lock);
2185 wait_event_interruptible(osb->osb_wipe_event,
2186 ocfs2_orphan_recovery_can_continue(osb, slot));
2187 spin_lock(&osb->osb_lock);
2189 spin_unlock(&osb->osb_lock);
2192 static void ocfs2_clear_recovering_orphan_dir(struct ocfs2_super *osb,
2195 ocfs2_node_map_clear_bit(osb, &osb->osb_recovering_orphan_dirs, slot);
2216 static int ocfs2_recover_orphans(struct ocfs2_super *osb,
2229 ocfs2_mark_recovering_orphan_dir(osb, slot);
2230 ret = ocfs2_queue_orphans(osb, slot, &inode, orphan_reco_type);
2231 ocfs2_clear_recovering_orphan_dir(osb, slot);
2274 ret = ocfs2_del_inode_from_orphan(osb, inode,
2305 static int __ocfs2_wait_on_mount(struct ocfs2_super *osb, int quota)
2310 wait_event(osb->osb_mount_event,
2311 (!quota && atomic_read(&osb->vol_state) == VOLUME_MOUNTED) ||
2312 atomic_read(&osb->vol_state) == VOLUME_MOUNTED_QUOTAS ||
2313 atomic_read(&osb->vol_state) == VOLUME_DISABLED);
2318 if (atomic_read(&osb->vol_state) == VOLUME_DISABLED) {
2330 struct ocfs2_super *osb = arg;
2331 struct ocfs2_journal *journal = osb->journal;
2340 wait_event_interruptible(osb->checkpoint_event,
2344 status = ocfs2_commit_cache(osb);
2376 int ocfs2_check_journals_nolocks(struct ocfs2_super *osb)
2384 for(slot = 0; slot < osb->max_slots; slot++) {
2385 ret = ocfs2_read_journal_inode(osb, slot, &di_bh, NULL);
2393 osb->slot_recovery_generations[slot] =