transaction.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright (C) 2007 Oracle. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public
  6. * License v2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public
  14. * License along with this program; if not, write to the
  15. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. * Boston, MA 021110-1307, USA.
  17. */
  18. #ifndef __BTRFS_TRANSACTION__
  19. #define __BTRFS_TRANSACTION__
  20. #include "btrfs_inode.h"
  21. #include "delayed-ref.h"
  22. #include "ctree.h"
  23. struct btrfs_transaction {
  24. u64 transid;
  25. /*
  26. * total external writers(USERSPACE/START/ATTACH) in this
  27. * transaction, it must be zero before the transaction is
  28. * being committed
  29. */
  30. atomic_t num_extwriters;
  31. /*
  32. * total writers in this transaction, it must be zero before the
  33. * transaction can end
  34. */
  35. atomic_t num_writers;
  36. atomic_t use_count;
  37. unsigned long num_joined;
  38. spinlock_t commit_lock;
  39. int in_commit;
  40. int commit_done;
  41. int blocked;
  42. struct list_head list;
  43. struct extent_io_tree dirty_pages;
  44. unsigned long start_time;
  45. wait_queue_head_t writer_wait;
  46. wait_queue_head_t commit_wait;
  47. struct list_head pending_snapshots;
  48. struct list_head ordered_operations;
  49. struct btrfs_delayed_ref_root delayed_refs;
  50. int aborted;
  51. };
  52. #define __TRANS_FREEZABLE (1U << 0)
  53. #define __TRANS_USERSPACE (1U << 8)
  54. #define __TRANS_START (1U << 9)
  55. #define __TRANS_ATTACH (1U << 10)
  56. #define __TRANS_JOIN (1U << 11)
  57. #define __TRANS_JOIN_NOLOCK (1U << 12)
  58. #define TRANS_USERSPACE (__TRANS_USERSPACE | __TRANS_FREEZABLE)
  59. #define TRANS_START (__TRANS_START | __TRANS_FREEZABLE)
  60. #define TRANS_ATTACH (__TRANS_ATTACH)
  61. #define TRANS_JOIN (__TRANS_JOIN | __TRANS_FREEZABLE)
  62. #define TRANS_JOIN_NOLOCK (__TRANS_JOIN_NOLOCK)
  63. #define TRANS_EXTWRITERS (__TRANS_USERSPACE | __TRANS_START | \
  64. __TRANS_ATTACH)
  65. struct btrfs_trans_handle {
  66. u64 transid;
  67. u64 bytes_reserved;
  68. u64 qgroup_reserved;
  69. unsigned long use_count;
  70. unsigned long blocks_reserved;
  71. unsigned long blocks_used;
  72. unsigned long delayed_ref_updates;
  73. struct btrfs_transaction *transaction;
  74. struct btrfs_block_rsv *block_rsv;
  75. struct btrfs_block_rsv *orig_rsv;
  76. short aborted;
  77. short adding_csums;
  78. bool allocating_chunk;
  79. unsigned int type;
  80. /*
  81. * this root is only needed to validate that the root passed to
  82. * start_transaction is the same as the one passed to end_transaction.
  83. * Subvolume quota depends on this
  84. */
  85. struct btrfs_root *root;
  86. struct seq_list delayed_ref_elem;
  87. struct list_head qgroup_ref_list;
  88. struct list_head new_bgs;
  89. };
  90. struct btrfs_pending_snapshot {
  91. struct dentry *dentry;
  92. struct inode *dir;
  93. struct btrfs_root *root;
  94. struct btrfs_root *snap;
  95. struct btrfs_qgroup_inherit *inherit;
  96. /* block reservation for the operation */
  97. struct btrfs_block_rsv block_rsv;
  98. u64 qgroup_reserved;
  99. /* extra metadata reseration for relocation */
  100. int error;
  101. bool readonly;
  102. struct list_head list;
  103. };
  104. static inline void btrfs_set_inode_last_trans(struct btrfs_trans_handle *trans,
  105. struct inode *inode)
  106. {
  107. BTRFS_I(inode)->last_trans = trans->transaction->transid;
  108. BTRFS_I(inode)->last_sub_trans = BTRFS_I(inode)->root->log_transid;
  109. BTRFS_I(inode)->last_log_commit = BTRFS_I(inode)->root->last_log_commit;
  110. }
  111. int btrfs_end_transaction(struct btrfs_trans_handle *trans,
  112. struct btrfs_root *root);
  113. struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root,
  114. int num_items);
  115. struct btrfs_trans_handle *btrfs_start_transaction_lflush(
  116. struct btrfs_root *root, int num_items);
  117. struct btrfs_trans_handle *btrfs_join_transaction(struct btrfs_root *root);
  118. struct btrfs_trans_handle *btrfs_join_transaction_nolock(struct btrfs_root *root);
  119. struct btrfs_trans_handle *btrfs_attach_transaction(struct btrfs_root *root);
  120. struct btrfs_trans_handle *btrfs_attach_transaction_barrier(
  121. struct btrfs_root *root);
  122. struct btrfs_trans_handle *btrfs_start_ioctl_transaction(struct btrfs_root *root);
  123. int btrfs_wait_for_commit(struct btrfs_root *root, u64 transid);
  124. int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans,
  125. struct btrfs_root *root);
  126. int btrfs_add_dead_root(struct btrfs_root *root);
  127. int btrfs_defrag_root(struct btrfs_root *root);
  128. int btrfs_clean_one_deleted_snapshot(struct btrfs_root *root);
  129. int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
  130. struct btrfs_root *root);
  131. int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans,
  132. struct btrfs_root *root,
  133. int wait_for_unblock);
  134. int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans,
  135. struct btrfs_root *root);
  136. int btrfs_end_transaction_dmeta(struct btrfs_trans_handle *trans,
  137. struct btrfs_root *root);
  138. int btrfs_should_end_transaction(struct btrfs_trans_handle *trans,
  139. struct btrfs_root *root);
  140. void btrfs_throttle(struct btrfs_root *root);
  141. int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans,
  142. struct btrfs_root *root);
  143. int btrfs_write_and_wait_marked_extents(struct btrfs_root *root,
  144. struct extent_io_tree *dirty_pages, int mark);
  145. int btrfs_write_marked_extents(struct btrfs_root *root,
  146. struct extent_io_tree *dirty_pages, int mark);
  147. int btrfs_wait_marked_extents(struct btrfs_root *root,
  148. struct extent_io_tree *dirty_pages, int mark);
  149. int btrfs_transaction_blocked(struct btrfs_fs_info *info);
  150. int btrfs_transaction_in_commit(struct btrfs_fs_info *info);
  151. #endif