0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef OCFS2_JOURNAL_H
0011 #define OCFS2_JOURNAL_H
0012
0013 #include <linux/fs.h>
0014 #include <linux/jbd2.h>
0015
0016 enum ocfs2_journal_state {
0017 OCFS2_JOURNAL_FREE = 0,
0018 OCFS2_JOURNAL_LOADED,
0019 OCFS2_JOURNAL_IN_SHUTDOWN,
0020 };
0021
0022 struct ocfs2_super;
0023 struct ocfs2_dinode;
0024
0025
0026
0027
0028
0029
0030 struct ocfs2_recovery_map {
0031 unsigned int rm_used;
0032 unsigned int *rm_entries;
0033 };
0034
0035
0036 struct ocfs2_journal {
0037 enum ocfs2_journal_state j_state;
0038
0039 journal_t *j_journal;
0040 struct inode *j_inode;
0041
0042 struct ocfs2_super *j_osb;
0043
0044
0045
0046
0047
0048
0049
0050
0051 struct buffer_head *j_bh;
0052 atomic_t j_num_trans;
0053
0054 spinlock_t j_lock;
0055 unsigned long j_trans_id;
0056 struct rw_semaphore j_trans_barrier;
0057 wait_queue_head_t j_checkpointed;
0058
0059
0060 struct list_head j_la_cleanups;
0061 struct work_struct j_recovery_work;
0062 };
0063
0064 extern spinlock_t trans_inc_lock;
0065
0066
0067 static inline unsigned long ocfs2_inc_trans_id(struct ocfs2_journal *j)
0068 {
0069 unsigned long old_id;
0070 spin_lock(&trans_inc_lock);
0071 old_id = j->j_trans_id++;
0072 if (unlikely(!j->j_trans_id))
0073 j->j_trans_id = 1;
0074 spin_unlock(&trans_inc_lock);
0075 return old_id;
0076 }
0077
0078 static inline void ocfs2_set_ci_lock_trans(struct ocfs2_journal *journal,
0079 struct ocfs2_caching_info *ci)
0080 {
0081 spin_lock(&trans_inc_lock);
0082 ci->ci_last_trans = journal->j_trans_id;
0083 spin_unlock(&trans_inc_lock);
0084 }
0085
0086
0087
0088
0089
0090
0091 static inline int ocfs2_ci_fully_checkpointed(struct ocfs2_caching_info *ci)
0092 {
0093 int ret;
0094 struct ocfs2_journal *journal =
0095 OCFS2_SB(ocfs2_metadata_cache_get_super(ci))->journal;
0096
0097 spin_lock(&trans_inc_lock);
0098 ret = time_after(journal->j_trans_id, ci->ci_last_trans);
0099 spin_unlock(&trans_inc_lock);
0100 return ret;
0101 }
0102
0103
0104
0105
0106
0107 static inline int ocfs2_ci_is_new(struct ocfs2_caching_info *ci)
0108 {
0109 int ret;
0110 struct ocfs2_journal *journal =
0111 OCFS2_SB(ocfs2_metadata_cache_get_super(ci))->journal;
0112
0113 spin_lock(&trans_inc_lock);
0114 ret = !(time_after(journal->j_trans_id, ci->ci_created_trans));
0115 if (!ret)
0116 ci->ci_created_trans = 0;
0117 spin_unlock(&trans_inc_lock);
0118 return ret;
0119 }
0120
0121
0122 static inline int ocfs2_inode_is_new(struct inode *inode)
0123 {
0124
0125
0126
0127 if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_SYSTEM_FILE)
0128 return 0;
0129
0130 return ocfs2_ci_is_new(INODE_CACHE(inode));
0131 }
0132
0133 static inline void ocfs2_ci_set_new(struct ocfs2_super *osb,
0134 struct ocfs2_caching_info *ci)
0135 {
0136 spin_lock(&trans_inc_lock);
0137 ci->ci_created_trans = osb->journal->j_trans_id;
0138 spin_unlock(&trans_inc_lock);
0139 }
0140
0141
0142 void ocfs2_orphan_scan_init(struct ocfs2_super *osb);
0143 void ocfs2_orphan_scan_start(struct ocfs2_super *osb);
0144 void ocfs2_orphan_scan_stop(struct ocfs2_super *osb);
0145
0146 void ocfs2_complete_recovery(struct work_struct *work);
0147 void ocfs2_wait_for_recovery(struct ocfs2_super *osb);
0148
0149 int ocfs2_recovery_init(struct ocfs2_super *osb);
0150 void ocfs2_recovery_exit(struct ocfs2_super *osb);
0151
0152 int ocfs2_compute_replay_slots(struct ocfs2_super *osb);
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170 void ocfs2_set_journal_params(struct ocfs2_super *osb);
0171 int ocfs2_journal_alloc(struct ocfs2_super *osb);
0172 int ocfs2_journal_init(struct ocfs2_super *osb, int *dirty);
0173 void ocfs2_journal_shutdown(struct ocfs2_super *osb);
0174 int ocfs2_journal_wipe(struct ocfs2_journal *journal,
0175 int full);
0176 int ocfs2_journal_load(struct ocfs2_journal *journal, int local,
0177 int replayed);
0178 int ocfs2_check_journals_nolocks(struct ocfs2_super *osb);
0179 void ocfs2_recovery_thread(struct ocfs2_super *osb,
0180 int node_num);
0181 int ocfs2_mark_dead_nodes(struct ocfs2_super *osb);
0182 void ocfs2_complete_mount_recovery(struct ocfs2_super *osb);
0183 void ocfs2_complete_quota_recovery(struct ocfs2_super *osb);
0184
0185 static inline void ocfs2_start_checkpoint(struct ocfs2_super *osb)
0186 {
0187 wake_up(&osb->checkpoint_event);
0188 }
0189
0190 static inline void ocfs2_checkpoint_inode(struct inode *inode)
0191 {
0192 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
0193
0194 if (ocfs2_mount_local(osb))
0195 return;
0196
0197 if (!ocfs2_ci_fully_checkpointed(INODE_CACHE(inode))) {
0198
0199
0200
0201
0202
0203
0204 ocfs2_start_checkpoint(osb);
0205
0206 wait_event(osb->journal->j_checkpointed,
0207 ocfs2_ci_fully_checkpointed(INODE_CACHE(inode)));
0208 }
0209 }
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240 handle_t *ocfs2_start_trans(struct ocfs2_super *osb,
0241 int max_buffs);
0242 int ocfs2_commit_trans(struct ocfs2_super *osb,
0243 handle_t *handle);
0244 int ocfs2_extend_trans(handle_t *handle, int nblocks);
0245 int ocfs2_allocate_extend_trans(handle_t *handle,
0246 int thresh);
0247
0248
0249
0250
0251
0252
0253
0254
0255 #define OCFS2_MAX_TRANS_DATA 64U
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268 #define OCFS2_JOURNAL_ACCESS_CREATE 0
0269 #define OCFS2_JOURNAL_ACCESS_WRITE 1
0270 #define OCFS2_JOURNAL_ACCESS_UNDO 2
0271
0272
0273
0274 int ocfs2_journal_access_di(handle_t *handle, struct ocfs2_caching_info *ci,
0275 struct buffer_head *bh, int type);
0276
0277 int ocfs2_journal_access_eb(handle_t *handle, struct ocfs2_caching_info *ci,
0278 struct buffer_head *bh, int type);
0279
0280 int ocfs2_journal_access_rb(handle_t *handle, struct ocfs2_caching_info *ci,
0281 struct buffer_head *bh, int type);
0282
0283 int ocfs2_journal_access_gd(handle_t *handle, struct ocfs2_caching_info *ci,
0284 struct buffer_head *bh, int type);
0285
0286 int ocfs2_journal_access_xb(handle_t *handle, struct ocfs2_caching_info *ci,
0287 struct buffer_head *bh, int type);
0288
0289 int ocfs2_journal_access_dq(handle_t *handle, struct ocfs2_caching_info *ci,
0290 struct buffer_head *bh, int type);
0291
0292 int ocfs2_journal_access_db(handle_t *handle, struct ocfs2_caching_info *ci,
0293 struct buffer_head *bh, int type);
0294
0295 int ocfs2_journal_access_dr(handle_t *handle, struct ocfs2_caching_info *ci,
0296 struct buffer_head *bh, int type);
0297
0298 int ocfs2_journal_access_dl(handle_t *handle, struct ocfs2_caching_info *ci,
0299 struct buffer_head *bh, int type);
0300
0301 int ocfs2_journal_access(handle_t *handle, struct ocfs2_caching_info *ci,
0302 struct buffer_head *bh, int type);
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323 void ocfs2_journal_dirty(handle_t *handle, struct buffer_head *bh);
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335 #define OCFS2_INODE_UPDATE_CREDITS 1
0336
0337
0338 #define OCFS2_XATTR_BLOCK_UPDATE_CREDITS 1
0339
0340
0341 #define OCFS2_QUOTA_BLOCK_UPDATE_CREDITS 1
0342
0343
0344 #define OCFS2_QINFO_WRITE_CREDITS (OCFS2_INODE_UPDATE_CREDITS + \
0345 OCFS2_QUOTA_BLOCK_UPDATE_CREDITS)
0346
0347 #define OCFS2_LOCAL_QINFO_WRITE_CREDITS OCFS2_QUOTA_BLOCK_UPDATE_CREDITS
0348
0349
0350
0351
0352
0353
0354 #define OCFS2_QWRITE_CREDITS (OCFS2_QINFO_WRITE_CREDITS + \
0355 OCFS2_QUOTA_BLOCK_UPDATE_CREDITS)
0356
0357
0358
0359 #define OCFS2_QSYNC_CREDITS (OCFS2_QINFO_WRITE_CREDITS + \
0360 2 * OCFS2_QUOTA_BLOCK_UPDATE_CREDITS)
0361
0362 static inline int ocfs2_quota_trans_credits(struct super_block *sb)
0363 {
0364 int credits = 0;
0365
0366 if (OCFS2_HAS_RO_COMPAT_FEATURE(sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA))
0367 credits += OCFS2_QWRITE_CREDITS;
0368 if (OCFS2_HAS_RO_COMPAT_FEATURE(sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA))
0369 credits += OCFS2_QWRITE_CREDITS;
0370 return credits;
0371 }
0372
0373
0374 #define OCFS2_GROUP_EXTEND_CREDITS (OCFS2_INODE_UPDATE_CREDITS + 1)
0375
0376
0377 #define OCFS2_GROUP_ADD_CREDITS (OCFS2_INODE_UPDATE_CREDITS + 1)
0378
0379
0380
0381 #define OCFS2_SUBALLOC_ALLOC (3)
0382
0383 static inline int ocfs2_inline_to_extents_credits(struct super_block *sb)
0384 {
0385 return OCFS2_SUBALLOC_ALLOC + OCFS2_INODE_UPDATE_CREDITS +
0386 ocfs2_quota_trans_credits(sb);
0387 }
0388
0389
0390 #define OCFS2_SUBALLOC_FREE (2)
0391
0392 #define OCFS2_TRUNCATE_LOG_UPDATE OCFS2_INODE_UPDATE_CREDITS
0393 #define OCFS2_TRUNCATE_LOG_FLUSH_ONE_REC (OCFS2_SUBALLOC_FREE \
0394 + OCFS2_TRUNCATE_LOG_UPDATE)
0395
0396 static inline int ocfs2_remove_extent_credits(struct super_block *sb)
0397 {
0398 return OCFS2_TRUNCATE_LOG_UPDATE + OCFS2_INODE_UPDATE_CREDITS +
0399 ocfs2_quota_trans_credits(sb);
0400 }
0401
0402
0403
0404 #define OCFS2_DIR_LINK_ADDITIONAL_CREDITS (1 + OCFS2_SUBALLOC_ALLOC + 1)
0405
0406 static inline int ocfs2_add_dir_index_credits(struct super_block *sb)
0407 {
0408
0409
0410 return 1 + 2 * OCFS2_SUBALLOC_ALLOC +
0411 ocfs2_clusters_to_blocks(sb, 1);
0412 }
0413
0414
0415
0416
0417 static inline int ocfs2_mknod_credits(struct super_block *sb, int is_dir,
0418 int xattr_credits)
0419 {
0420 int dir_credits = OCFS2_DIR_LINK_ADDITIONAL_CREDITS;
0421
0422 if (is_dir)
0423 dir_credits += ocfs2_add_dir_index_credits(sb);
0424
0425 return 4 + OCFS2_SUBALLOC_ALLOC + dir_credits + xattr_credits +
0426 ocfs2_quota_trans_credits(sb);
0427 }
0428
0429
0430 #define OCFS2_WINDOW_MOVE_CREDITS (OCFS2_INODE_UPDATE_CREDITS \
0431 + OCFS2_SUBALLOC_ALLOC + OCFS2_SUBALLOC_FREE)
0432
0433
0434
0435 #define OCFS2_SIMPLE_DIR_EXTEND_CREDITS (2)
0436
0437
0438
0439
0440 static inline int ocfs2_link_credits(struct super_block *sb)
0441 {
0442 return 2 * OCFS2_INODE_UPDATE_CREDITS + 4 +
0443 ocfs2_quota_trans_credits(sb);
0444 }
0445
0446
0447
0448 static inline int ocfs2_unlink_credits(struct super_block *sb)
0449 {
0450
0451 return 2 * OCFS2_INODE_UPDATE_CREDITS + 3 + ocfs2_link_credits(sb);
0452 }
0453
0454
0455
0456
0457 #define OCFS2_DELETE_INODE_CREDITS (3 * OCFS2_INODE_UPDATE_CREDITS + 4)
0458
0459
0460
0461 #define OCFS2_INODE_ADD_TO_ORPHAN_CREDITS (2 * OCFS2_INODE_UPDATE_CREDITS + 4)
0462 #define OCFS2_INODE_DEL_FROM_ORPHAN_CREDITS OCFS2_INODE_ADD_TO_ORPHAN_CREDITS
0463
0464
0465
0466
0467 static inline int ocfs2_rename_credits(struct super_block *sb)
0468 {
0469 return 3 * OCFS2_INODE_UPDATE_CREDITS + 6 + ocfs2_unlink_credits(sb);
0470 }
0471
0472
0473
0474
0475 #define OCFS2_XATTR_BLOCK_CREATE_CREDITS (OCFS2_SUBALLOC_ALLOC * 2 + \
0476 + OCFS2_INODE_UPDATE_CREDITS \
0477 + OCFS2_XATTR_BLOCK_UPDATE_CREDITS)
0478
0479
0480 #define OCFS2_DX_ROOT_REMOVE_CREDITS (OCFS2_INODE_UPDATE_CREDITS + \
0481 OCFS2_SUBALLOC_FREE)
0482
0483 static inline int ocfs2_calc_dxi_expand_credits(struct super_block *sb)
0484 {
0485 int credits = 1 + OCFS2_SUBALLOC_ALLOC;
0486
0487 credits += ocfs2_clusters_to_blocks(sb, 1);
0488 credits += ocfs2_quota_trans_credits(sb);
0489
0490 return credits;
0491 }
0492
0493
0494 #define OCFS2_REFCOUNT_TREE_CREATE_CREDITS (OCFS2_INODE_UPDATE_CREDITS + 1 \
0495 + OCFS2_SUBALLOC_ALLOC)
0496
0497
0498 #define OCFS2_REFCOUNT_TREE_SET_CREDITS (OCFS2_INODE_UPDATE_CREDITS + 1)
0499
0500
0501
0502
0503
0504
0505 #define OCFS2_REFCOUNT_TREE_REMOVE_CREDITS (OCFS2_INODE_UPDATE_CREDITS + 1)
0506
0507
0508 #define OCFS2_EXPAND_REFCOUNT_TREE_CREDITS (OCFS2_SUBALLOC_ALLOC * 2 + 3)
0509
0510
0511
0512
0513
0514
0515 static inline int ocfs2_calc_extend_credits(struct super_block *sb,
0516 struct ocfs2_extent_list *root_el)
0517 {
0518 int bitmap_blocks, sysfile_bitmap_blocks, extent_blocks;
0519
0520
0521 bitmap_blocks = OCFS2_SUBALLOC_ALLOC;
0522
0523
0524
0525
0526
0527
0528 sysfile_bitmap_blocks = 1 +
0529 (OCFS2_SUBALLOC_ALLOC - 1) * ocfs2_extend_meta_needed(root_el);
0530
0531
0532
0533
0534
0535
0536 extent_blocks = 1 + 1 + le16_to_cpu(root_el->l_tree_depth);
0537
0538 return bitmap_blocks + sysfile_bitmap_blocks + extent_blocks +
0539 ocfs2_quota_trans_credits(sb);
0540 }
0541
0542 static inline int ocfs2_calc_symlink_credits(struct super_block *sb)
0543 {
0544 int blocks = ocfs2_mknod_credits(sb, 0, 0);
0545
0546
0547
0548 blocks += ocfs2_clusters_to_blocks(sb, 1);
0549
0550 return blocks + ocfs2_quota_trans_credits(sb);
0551 }
0552
0553 static inline int ocfs2_calc_group_alloc_credits(struct super_block *sb,
0554 unsigned int cpg)
0555 {
0556 int blocks;
0557 int bitmap_blocks = OCFS2_SUBALLOC_ALLOC + 1;
0558
0559
0560 blocks = 1 + 1 + 1 + bitmap_blocks;
0561 return blocks;
0562 }
0563
0564
0565
0566
0567
0568
0569
0570
0571 static inline int ocfs2_calc_bg_discontig_credits(struct super_block *sb)
0572 {
0573 return ocfs2_extent_recs_per_gd(sb);
0574 }
0575
0576 static inline int ocfs2_jbd2_inode_add_write(handle_t *handle, struct inode *inode,
0577 loff_t start_byte, loff_t length)
0578 {
0579 return jbd2_journal_inode_ranged_write(handle,
0580 &OCFS2_I(inode)->ip_jinode,
0581 start_byte, length);
0582 }
0583
0584 static inline int ocfs2_begin_ordered_truncate(struct inode *inode,
0585 loff_t new_size)
0586 {
0587 return jbd2_journal_begin_ordered_truncate(
0588 OCFS2_SB(inode->i_sb)->journal->j_journal,
0589 &OCFS2_I(inode)->ip_jinode,
0590 new_size);
0591 }
0592
0593 static inline void ocfs2_update_inode_fsync_trans(handle_t *handle,
0594 struct inode *inode,
0595 int datasync)
0596 {
0597 struct ocfs2_inode_info *oi = OCFS2_I(inode);
0598
0599 if (!is_handle_aborted(handle)) {
0600 oi->i_sync_tid = handle->h_transaction->t_tid;
0601 if (datasync)
0602 oi->i_datasync_tid = handle->h_transaction->t_tid;
0603 }
0604 }
0605
0606 #endif