tree-log.h 3.6 KB

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