blob: f6811c3df38a670544ee98166984d8d297a176f0 [file] [log] [blame]
David Sterba9888c342018-04-03 19:16:55 +02001/* SPDX-License-Identifier: GPL-2.0 */
Chris Masone02119d2008-09-05 16:13:11 -04002/*
3 * Copyright (C) 2008 Oracle. All rights reserved.
Chris Masone02119d2008-09-05 16:13:11 -04004 */
5
David Sterba9888c342018-04-03 19:16:55 +02006#ifndef BTRFS_TREE_LOG_H
7#define BTRFS_TREE_LOG_H
Chris Masone02119d2008-09-05 16:13:11 -04008
Miao Xie995946d2014-04-02 19:51:06 +08009#include "ctree.h"
10#include "transaction.h"
11
Chris Mason257c62e2009-10-13 13:21:08 -040012/* 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 Xie8b050d32014-02-20 18:08:58 +080015struct btrfs_log_ctx {
16 int log_ret;
Miao Xied1433de2014-02-20 18:08:59 +080017 int log_transid;
Filipe Manana2f2ff0e2015-03-20 17:19:46 +000018 bool log_new_dentries;
Filipe Manana75b463d2020-08-11 12:43:48 +010019 bool logging_new_name;
Filipe Mananadc287222021-09-16 11:32:14 +010020 /* Tracks the last logged dir item/index key offset. */
21 u64 last_dir_item_offset;
Filipe Manana28a23592016-08-23 21:13:51 +010022 struct inode *inode;
Miao Xie8b050d32014-02-20 18:08:58 +080023 struct list_head list;
Filipe Manana48778172020-08-11 12:43:58 +010024 /* Only used for fast fsyncs. */
25 struct list_head ordered_extents;
Miao Xie8b050d32014-02-20 18:08:58 +080026};
27
Filipe Manana28a23592016-08-23 21:13:51 +010028static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx,
29 struct inode *inode)
Miao Xie8b050d32014-02-20 18:08:58 +080030{
31 ctx->log_ret = 0;
Miao Xied1433de2014-02-20 18:08:59 +080032 ctx->log_transid = 0;
Filipe Manana2f2ff0e2015-03-20 17:19:46 +000033 ctx->log_new_dentries = false;
Filipe Manana75b463d2020-08-11 12:43:48 +010034 ctx->logging_new_name = false;
Filipe Manana28a23592016-08-23 21:13:51 +010035 ctx->inode = inode;
Miao Xie8b050d32014-02-20 18:08:58 +080036 INIT_LIST_HEAD(&ctx->list);
Filipe Manana48778172020-08-11 12:43:58 +010037 INIT_LIST_HEAD(&ctx->ordered_extents);
38}
39
40static 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 Xie8b050d32014-02-20 18:08:58 +080051}
52
David Sterba90787762019-03-20 13:28:05 +010053static inline void btrfs_set_log_full_commit(struct btrfs_trans_handle *trans)
Miao Xie995946d2014-04-02 19:51:06 +080054{
David Sterba90787762019-03-20 13:28:05 +010055 WRITE_ONCE(trans->fs_info->last_trans_log_full_commit, trans->transid);
Miao Xie995946d2014-04-02 19:51:06 +080056}
57
David Sterba4884b8e2019-03-20 13:25:34 +010058static inline int btrfs_need_log_full_commit(struct btrfs_trans_handle *trans)
Miao Xie995946d2014-04-02 19:51:06 +080059{
David Sterba4884b8e2019-03-20 13:25:34 +010060 return READ_ONCE(trans->fs_info->last_trans_log_full_commit) ==
Miao Xie995946d2014-04-02 19:51:06 +080061 trans->transid;
62}
63
Chris Masone02119d2008-09-05 16:13:11 -040064int btrfs_sync_log(struct btrfs_trans_handle *trans,
Miao Xie8b050d32014-02-20 18:08:58 +080065 struct btrfs_root *root, struct btrfs_log_ctx *ctx);
Chris Masone02119d2008-09-05 16:13:11 -040066int btrfs_free_log(struct btrfs_trans_handle *trans, struct btrfs_root *root);
Yan, Zheng4a500fd2010-05-16 10:49:59 -040067int btrfs_free_log_root_tree(struct btrfs_trans_handle *trans,
68 struct btrfs_fs_info *fs_info);
Chris Masone02119d2008-09-05 16:13:11 -040069int btrfs_recover_log_trees(struct btrfs_root *tree_root);
70int btrfs_log_dentry_safe(struct btrfs_trans_handle *trans,
Nikolay Borisove5b84f7a2018-02-27 17:37:18 +020071 struct dentry *dentry,
Miao Xie8b050d32014-02-20 18:08:58 +080072 struct btrfs_log_ctx *ctx);
Josef Bacik9a35fc92021-10-05 16:35:24 -040073void 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);
77void 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 Mahoney143bede2012-03-01 14:56:26 +010081void btrfs_end_log_trans(struct btrfs_root *root);
zhong jiang45128b02018-08-17 00:37:15 +080082void btrfs_pin_log_trans(struct btrfs_root *root);
Chris Mason12fcfd22009-03-24 10:24:20 -040083void btrfs_record_unlink_dir(struct btrfs_trans_handle *trans,
Nikolay Borisov4176bdb2017-01-18 00:31:28 +020084 struct btrfs_inode *dir, struct btrfs_inode *inode,
Chris Mason12fcfd22009-03-24 10:24:20 -040085 int for_rename);
Filipe Manana1ec9a1a2016-02-10 10:42:25 +000086void btrfs_record_snapshot_destroy(struct btrfs_trans_handle *trans,
Nikolay Borisov43663552017-01-18 00:31:29 +020087 struct btrfs_inode *dir);
Filipe Manana75b463d2020-08-11 12:43:48 +010088void btrfs_log_new_name(struct btrfs_trans_handle *trans,
Nikolay Borisov9ca5fbfb2017-01-18 00:31:31 +020089 struct btrfs_inode *inode, struct btrfs_inode *old_dir,
Filipe Manana75b463d2020-08-11 12:43:48 +010090 struct dentry *parent);
David Sterba9888c342018-04-03 19:16:55 +020091
Chris Masone02119d2008-09-05 16:13:11 -040092#endif