tree-log.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 "ctree.h"
  8. #include "transaction.h"
  9. /* return value for btrfs_log_dentry_safe that means we don't need to log it at all */
  10. #define BTRFS_NO_LOG_SYNC 256
  11. struct btrfs_log_ctx {
  12. int log_ret;
  13. int log_transid;
  14. int io_err;
  15. bool log_new_dentries;
  16. struct inode *inode;
  17. struct list_head list;
  18. };
  19. static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx,
  20. struct inode *inode)
  21. {
  22. ctx->log_ret = 0;
  23. ctx->log_transid = 0;
  24. ctx->io_err = 0;
  25. ctx->log_new_dentries = false;
  26. ctx->inode = inode;
  27. INIT_LIST_HEAD(&ctx->list);
  28. }
  29. static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
  30. struct btrfs_trans_handle *trans)
  31. {
  32. WRITE_ONCE(fs_info->last_trans_log_full_commit, trans->transid);
  33. }
  34. static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
  35. struct btrfs_trans_handle *trans)
  36. {
  37. return READ_ONCE(fs_info->last_trans_log_full_commit) ==
  38. trans->transid;
  39. }
  40. int btrfs_sync_log(struct btrfs_trans_handle *trans,
  41. struct btrfs_root *root, struct btrfs_log_ctx *ctx);
  42. int btrfs_free_log(struct btrfs_trans_handle *trans, struct btrfs_root *root);
  43. int btrfs_free_log_root_tree(struct btrfs_trans_handle *trans,
  44. struct btrfs_fs_info *fs_info);
  45. int btrfs_recover_log_trees(struct btrfs_root *tree_root);
  46. int btrfs_log_dentry_safe(struct btrfs_trans_handle *trans,
  47. struct dentry *dentry,
  48. const loff_t start,
  49. const loff_t end,
  50. struct btrfs_log_ctx *ctx);
  51. int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans,
  52. struct btrfs_root *root,
  53. const char *name, int name_len,
  54. struct btrfs_inode *dir, u64 index);
  55. int btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans,
  56. struct btrfs_root *root,
  57. const char *name, int name_len,
  58. struct btrfs_inode *inode, u64 dirid);
  59. void btrfs_end_log_trans(struct btrfs_root *root);
  60. int btrfs_pin_log_trans(struct btrfs_root *root);
  61. void btrfs_record_unlink_dir(struct btrfs_trans_handle *trans,
  62. struct btrfs_inode *dir, struct btrfs_inode *inode,
  63. int for_rename);
  64. void btrfs_record_snapshot_destroy(struct btrfs_trans_handle *trans,
  65. struct btrfs_inode *dir);
  66. /* Return values for btrfs_log_new_name() */
  67. enum {
  68. BTRFS_DONT_NEED_TRANS_COMMIT,
  69. BTRFS_NEED_TRANS_COMMIT,
  70. BTRFS_DONT_NEED_LOG_SYNC,
  71. BTRFS_NEED_LOG_SYNC,
  72. };
  73. int btrfs_log_new_name(struct btrfs_trans_handle *trans,
  74. struct btrfs_inode *inode, struct btrfs_inode *old_dir,
  75. struct dentry *parent,
  76. bool sync_log, struct btrfs_log_ctx *ctx);
  77. #endif