tree-log.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2008 Oracle. All rights reserved.
  4. */
  5. #ifndef BTRFS_TREE_LOG_H
  6. #define BTRFS_TREE_LOG_H
  7. #include <linux/list.h>
  8. #include <linux/fs.h>
  9. #include "messages.h"
  10. #include "ctree.h"
  11. #include "transaction.h"
  12. struct inode;
  13. struct dentry;
  14. struct btrfs_ordered_extent;
  15. struct btrfs_root;
  16. struct btrfs_trans_handle;
  17. /* return value for btrfs_log_dentry_safe that means we don't need to log it at all */
  18. #define BTRFS_NO_LOG_SYNC 256
  19. /*
  20. * We can't use the tree log for whatever reason, force a transaction commit.
  21. * We use a negative value because there are functions through the logging code
  22. * that need to return an error (< 0 value), false (0) or true (1). Any negative
  23. * value will do, as it will cause the log to be marked for a full sync.
  24. */
  25. #define BTRFS_LOG_FORCE_COMMIT (-(MAX_ERRNO + 1))
  26. struct btrfs_log_ctx {
  27. int log_ret;
  28. int log_transid;
  29. bool log_new_dentries;
  30. bool logging_new_name;
  31. bool logging_new_delayed_dentries;
  32. /* Indicate if the inode being logged was logged before. */
  33. bool logged_before;
  34. struct btrfs_inode *inode;
  35. struct list_head list;
  36. /* Only used for fast fsyncs. */
  37. struct list_head ordered_extents;
  38. struct list_head conflict_inodes;
  39. int num_conflict_inodes;
  40. bool logging_conflict_inodes;
  41. /*
  42. * Used for fsyncs that need to copy items from the subvolume tree to
  43. * the log tree (full sync flag set or copy everything flag set) to
  44. * avoid allocating a temporary extent buffer while holding a lock on
  45. * an extent buffer of the subvolume tree and under the log transaction.
  46. * Also helps to avoid allocating and freeing a temporary extent buffer
  47. * in case we need to process multiple leaves from the subvolume tree.
  48. */
  49. struct extent_buffer *scratch_eb;
  50. };
  51. void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx, struct btrfs_inode *inode);
  52. void btrfs_init_log_ctx_scratch_eb(struct btrfs_log_ctx *ctx);
  53. void btrfs_release_log_ctx_extents(struct btrfs_log_ctx *ctx);
  54. static inline void btrfs_set_log_full_commit(struct btrfs_trans_handle *trans)
  55. {
  56. WRITE_ONCE(trans->fs_info->last_trans_log_full_commit, trans->transid);
  57. }
  58. static inline int btrfs_need_log_full_commit(struct btrfs_trans_handle *trans)
  59. {
  60. return READ_ONCE(trans->fs_info->last_trans_log_full_commit) ==
  61. trans->transid;
  62. }
  63. int btrfs_sync_log(struct btrfs_trans_handle *trans,
  64. struct btrfs_root *root, struct btrfs_log_ctx *ctx);
  65. int btrfs_free_log(struct btrfs_trans_handle *trans, struct btrfs_root *root);
  66. int btrfs_free_log_root_tree(struct btrfs_trans_handle *trans,
  67. struct btrfs_fs_info *fs_info);
  68. int btrfs_recover_log_trees(struct btrfs_root *tree_root);
  69. int btrfs_log_dentry_safe(struct btrfs_trans_handle *trans,
  70. struct dentry *dentry,
  71. struct btrfs_log_ctx *ctx);
  72. void btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans,
  73. struct btrfs_root *root,
  74. const struct fscrypt_str *name,
  75. struct btrfs_inode *dir, u64 index);
  76. void btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans,
  77. struct btrfs_root *root,
  78. const struct fscrypt_str *name,
  79. struct btrfs_inode *inode, u64 dirid);
  80. void btrfs_end_log_trans(struct btrfs_root *root);
  81. void btrfs_pin_log_trans(struct btrfs_root *root);
  82. void btrfs_record_unlink_dir(struct btrfs_trans_handle *trans,
  83. struct btrfs_inode *dir, struct btrfs_inode *inode,
  84. bool for_rename);
  85. void btrfs_record_snapshot_destroy(struct btrfs_trans_handle *trans,
  86. struct btrfs_inode *dir);
  87. void btrfs_record_new_subvolume(const struct btrfs_trans_handle *trans,
  88. struct btrfs_inode *dir);
  89. void btrfs_log_new_name(struct btrfs_trans_handle *trans,
  90. struct dentry *old_dentry, struct btrfs_inode *old_dir,
  91. u64 old_dir_index, struct dentry *parent);
  92. #endif