David Sterba | 9888c34 | 2018-04-03 19:16:55 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Chris Mason | e02119d | 2008-09-05 16:13:11 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2008 Oracle. All rights reserved. |
Chris Mason | e02119d | 2008-09-05 16:13:11 -0400 | [diff] [blame] | 4 | */ |
| 5 | |
David Sterba | 9888c34 | 2018-04-03 19:16:55 +0200 | [diff] [blame] | 6 | #ifndef BTRFS_TREE_LOG_H |
| 7 | #define BTRFS_TREE_LOG_H |
Chris Mason | e02119d | 2008-09-05 16:13:11 -0400 | [diff] [blame] | 8 | |
Miao Xie | 995946d | 2014-04-02 19:51:06 +0800 | [diff] [blame] | 9 | #include "ctree.h" |
| 10 | #include "transaction.h" |
| 11 | |
Chris Mason | 257c62e | 2009-10-13 13:21:08 -0400 | [diff] [blame] | 12 | /* return value for btrfs_log_dentry_safe that means we don't need to log it at all */ |
| 13 | #define BTRFS_NO_LOG_SYNC 256 |
| 14 | |
Miao Xie | 8b050d3 | 2014-02-20 18:08:58 +0800 | [diff] [blame] | 15 | struct btrfs_log_ctx { |
| 16 | int log_ret; |
Miao Xie | d1433de | 2014-02-20 18:08:59 +0800 | [diff] [blame] | 17 | int log_transid; |
Filipe Manana | 2f2ff0e | 2015-03-20 17:19:46 +0000 | [diff] [blame] | 18 | bool log_new_dentries; |
Filipe Manana | 75b463d | 2020-08-11 12:43:48 +0100 | [diff] [blame] | 19 | bool logging_new_name; |
Filipe Manana | dc28722 | 2021-09-16 11:32:14 +0100 | [diff] [blame] | 20 | /* Tracks the last logged dir item/index key offset. */ |
| 21 | u64 last_dir_item_offset; |
Filipe Manana | 28a2359 | 2016-08-23 21:13:51 +0100 | [diff] [blame] | 22 | struct inode *inode; |
Miao Xie | 8b050d3 | 2014-02-20 18:08:58 +0800 | [diff] [blame] | 23 | struct list_head list; |
Filipe Manana | 4877817 | 2020-08-11 12:43:58 +0100 | [diff] [blame] | 24 | /* Only used for fast fsyncs. */ |
| 25 | struct list_head ordered_extents; |
Miao Xie | 8b050d3 | 2014-02-20 18:08:58 +0800 | [diff] [blame] | 26 | }; |
| 27 | |
Filipe Manana | 28a2359 | 2016-08-23 21:13:51 +0100 | [diff] [blame] | 28 | static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx, |
| 29 | struct inode *inode) |
Miao Xie | 8b050d3 | 2014-02-20 18:08:58 +0800 | [diff] [blame] | 30 | { |
| 31 | ctx->log_ret = 0; |
Miao Xie | d1433de | 2014-02-20 18:08:59 +0800 | [diff] [blame] | 32 | ctx->log_transid = 0; |
Filipe Manana | 2f2ff0e | 2015-03-20 17:19:46 +0000 | [diff] [blame] | 33 | ctx->log_new_dentries = false; |
Filipe Manana | 75b463d | 2020-08-11 12:43:48 +0100 | [diff] [blame] | 34 | ctx->logging_new_name = false; |
Filipe Manana | 28a2359 | 2016-08-23 21:13:51 +0100 | [diff] [blame] | 35 | ctx->inode = inode; |
Miao Xie | 8b050d3 | 2014-02-20 18:08:58 +0800 | [diff] [blame] | 36 | INIT_LIST_HEAD(&ctx->list); |
Filipe Manana | 4877817 | 2020-08-11 12:43:58 +0100 | [diff] [blame] | 37 | INIT_LIST_HEAD(&ctx->ordered_extents); |
| 38 | } |
| 39 | |
| 40 | static inline void btrfs_release_log_ctx_extents(struct btrfs_log_ctx *ctx) |
| 41 | { |
| 42 | struct btrfs_ordered_extent *ordered; |
| 43 | struct btrfs_ordered_extent *tmp; |
| 44 | |
| 45 | ASSERT(inode_is_locked(ctx->inode)); |
| 46 | |
| 47 | list_for_each_entry_safe(ordered, tmp, &ctx->ordered_extents, log_list) { |
| 48 | list_del_init(&ordered->log_list); |
| 49 | btrfs_put_ordered_extent(ordered); |
| 50 | } |
Miao Xie | 8b050d3 | 2014-02-20 18:08:58 +0800 | [diff] [blame] | 51 | } |
| 52 | |
David Sterba | 9078776 | 2019-03-20 13:28:05 +0100 | [diff] [blame] | 53 | static inline void btrfs_set_log_full_commit(struct btrfs_trans_handle *trans) |
Miao Xie | 995946d | 2014-04-02 19:51:06 +0800 | [diff] [blame] | 54 | { |
David Sterba | 9078776 | 2019-03-20 13:28:05 +0100 | [diff] [blame] | 55 | WRITE_ONCE(trans->fs_info->last_trans_log_full_commit, trans->transid); |
Miao Xie | 995946d | 2014-04-02 19:51:06 +0800 | [diff] [blame] | 56 | } |
| 57 | |
David Sterba | 4884b8e | 2019-03-20 13:25:34 +0100 | [diff] [blame] | 58 | static inline int btrfs_need_log_full_commit(struct btrfs_trans_handle *trans) |
Miao Xie | 995946d | 2014-04-02 19:51:06 +0800 | [diff] [blame] | 59 | { |
David Sterba | 4884b8e | 2019-03-20 13:25:34 +0100 | [diff] [blame] | 60 | return READ_ONCE(trans->fs_info->last_trans_log_full_commit) == |
Miao Xie | 995946d | 2014-04-02 19:51:06 +0800 | [diff] [blame] | 61 | trans->transid; |
| 62 | } |
| 63 | |
Chris Mason | e02119d | 2008-09-05 16:13:11 -0400 | [diff] [blame] | 64 | int btrfs_sync_log(struct btrfs_trans_handle *trans, |
Miao Xie | 8b050d3 | 2014-02-20 18:08:58 +0800 | [diff] [blame] | 65 | struct btrfs_root *root, struct btrfs_log_ctx *ctx); |
Chris Mason | e02119d | 2008-09-05 16:13:11 -0400 | [diff] [blame] | 66 | int btrfs_free_log(struct btrfs_trans_handle *trans, struct btrfs_root *root); |
Yan, Zheng | 4a500fd | 2010-05-16 10:49:59 -0400 | [diff] [blame] | 67 | int btrfs_free_log_root_tree(struct btrfs_trans_handle *trans, |
| 68 | struct btrfs_fs_info *fs_info); |
Chris Mason | e02119d | 2008-09-05 16:13:11 -0400 | [diff] [blame] | 69 | int btrfs_recover_log_trees(struct btrfs_root *tree_root); |
| 70 | int btrfs_log_dentry_safe(struct btrfs_trans_handle *trans, |
Nikolay Borisov | e5b84f7a | 2018-02-27 17:37:18 +0200 | [diff] [blame] | 71 | struct dentry *dentry, |
Miao Xie | 8b050d3 | 2014-02-20 18:08:58 +0800 | [diff] [blame] | 72 | struct btrfs_log_ctx *ctx); |
Josef Bacik | 9a35fc9 | 2021-10-05 16:35:24 -0400 | [diff] [blame] | 73 | void btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans, |
| 74 | struct btrfs_root *root, |
| 75 | const char *name, int name_len, |
| 76 | struct btrfs_inode *dir, u64 index); |
| 77 | void btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans, |
| 78 | struct btrfs_root *root, |
| 79 | const char *name, int name_len, |
| 80 | struct btrfs_inode *inode, u64 dirid); |
Jeff Mahoney | 143bede | 2012-03-01 14:56:26 +0100 | [diff] [blame] | 81 | void btrfs_end_log_trans(struct btrfs_root *root); |
zhong jiang | 45128b0 | 2018-08-17 00:37:15 +0800 | [diff] [blame] | 82 | void btrfs_pin_log_trans(struct btrfs_root *root); |
Chris Mason | 12fcfd2 | 2009-03-24 10:24:20 -0400 | [diff] [blame] | 83 | void btrfs_record_unlink_dir(struct btrfs_trans_handle *trans, |
Nikolay Borisov | 4176bdb | 2017-01-18 00:31:28 +0200 | [diff] [blame] | 84 | struct btrfs_inode *dir, struct btrfs_inode *inode, |
Chris Mason | 12fcfd2 | 2009-03-24 10:24:20 -0400 | [diff] [blame] | 85 | int for_rename); |
Filipe Manana | 1ec9a1a | 2016-02-10 10:42:25 +0000 | [diff] [blame] | 86 | void btrfs_record_snapshot_destroy(struct btrfs_trans_handle *trans, |
Nikolay Borisov | 4366355 | 2017-01-18 00:31:29 +0200 | [diff] [blame] | 87 | struct btrfs_inode *dir); |
Filipe Manana | 75b463d | 2020-08-11 12:43:48 +0100 | [diff] [blame] | 88 | void btrfs_log_new_name(struct btrfs_trans_handle *trans, |
Nikolay Borisov | 9ca5fbfb | 2017-01-18 00:31:31 +0200 | [diff] [blame] | 89 | struct btrfs_inode *inode, struct btrfs_inode *old_dir, |
Filipe Manana | 75b463d | 2020-08-11 12:43:48 +0100 | [diff] [blame] | 90 | struct dentry *parent); |
David Sterba | 9888c34 | 2018-04-03 19:16:55 +0200 | [diff] [blame] | 91 | |
Chris Mason | e02119d | 2008-09-05 16:13:11 -0400 | [diff] [blame] | 92 | #endif |