18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2008 Oracle. All rights reserved. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef BTRFS_TREE_LOG_H 78c2ecf20Sopenharmony_ci#define BTRFS_TREE_LOG_H 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include "ctree.h" 108c2ecf20Sopenharmony_ci#include "transaction.h" 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci/* return value for btrfs_log_dentry_safe that means we don't need to log it at all */ 138c2ecf20Sopenharmony_ci#define BTRFS_NO_LOG_SYNC 256 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_cistruct btrfs_log_ctx { 168c2ecf20Sopenharmony_ci int log_ret; 178c2ecf20Sopenharmony_ci int log_transid; 188c2ecf20Sopenharmony_ci bool log_new_dentries; 198c2ecf20Sopenharmony_ci bool logging_new_name; 208c2ecf20Sopenharmony_ci struct inode *inode; 218c2ecf20Sopenharmony_ci struct list_head list; 228c2ecf20Sopenharmony_ci /* Only used for fast fsyncs. */ 238c2ecf20Sopenharmony_ci struct list_head ordered_extents; 248c2ecf20Sopenharmony_ci}; 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_cistatic inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx, 278c2ecf20Sopenharmony_ci struct inode *inode) 288c2ecf20Sopenharmony_ci{ 298c2ecf20Sopenharmony_ci ctx->log_ret = 0; 308c2ecf20Sopenharmony_ci ctx->log_transid = 0; 318c2ecf20Sopenharmony_ci ctx->log_new_dentries = false; 328c2ecf20Sopenharmony_ci ctx->logging_new_name = false; 338c2ecf20Sopenharmony_ci ctx->inode = inode; 348c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&ctx->list); 358c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&ctx->ordered_extents); 368c2ecf20Sopenharmony_ci} 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_cistatic inline void btrfs_release_log_ctx_extents(struct btrfs_log_ctx *ctx) 398c2ecf20Sopenharmony_ci{ 408c2ecf20Sopenharmony_ci struct btrfs_ordered_extent *ordered; 418c2ecf20Sopenharmony_ci struct btrfs_ordered_extent *tmp; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci ASSERT(inode_is_locked(ctx->inode)); 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci list_for_each_entry_safe(ordered, tmp, &ctx->ordered_extents, log_list) { 468c2ecf20Sopenharmony_ci list_del_init(&ordered->log_list); 478c2ecf20Sopenharmony_ci btrfs_put_ordered_extent(ordered); 488c2ecf20Sopenharmony_ci } 498c2ecf20Sopenharmony_ci} 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_cistatic inline void btrfs_set_log_full_commit(struct btrfs_trans_handle *trans) 528c2ecf20Sopenharmony_ci{ 538c2ecf20Sopenharmony_ci WRITE_ONCE(trans->fs_info->last_trans_log_full_commit, trans->transid); 548c2ecf20Sopenharmony_ci} 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_cistatic inline int btrfs_need_log_full_commit(struct btrfs_trans_handle *trans) 578c2ecf20Sopenharmony_ci{ 588c2ecf20Sopenharmony_ci return READ_ONCE(trans->fs_info->last_trans_log_full_commit) == 598c2ecf20Sopenharmony_ci trans->transid; 608c2ecf20Sopenharmony_ci} 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ciint btrfs_sync_log(struct btrfs_trans_handle *trans, 638c2ecf20Sopenharmony_ci struct btrfs_root *root, struct btrfs_log_ctx *ctx); 648c2ecf20Sopenharmony_ciint btrfs_free_log(struct btrfs_trans_handle *trans, struct btrfs_root *root); 658c2ecf20Sopenharmony_ciint btrfs_free_log_root_tree(struct btrfs_trans_handle *trans, 668c2ecf20Sopenharmony_ci struct btrfs_fs_info *fs_info); 678c2ecf20Sopenharmony_ciint btrfs_recover_log_trees(struct btrfs_root *tree_root); 688c2ecf20Sopenharmony_ciint btrfs_log_dentry_safe(struct btrfs_trans_handle *trans, 698c2ecf20Sopenharmony_ci struct dentry *dentry, 708c2ecf20Sopenharmony_ci struct btrfs_log_ctx *ctx); 718c2ecf20Sopenharmony_ciint btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans, 728c2ecf20Sopenharmony_ci struct btrfs_root *root, 738c2ecf20Sopenharmony_ci const char *name, int name_len, 748c2ecf20Sopenharmony_ci struct btrfs_inode *dir, u64 index); 758c2ecf20Sopenharmony_ciint btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans, 768c2ecf20Sopenharmony_ci struct btrfs_root *root, 778c2ecf20Sopenharmony_ci const char *name, int name_len, 788c2ecf20Sopenharmony_ci struct btrfs_inode *inode, u64 dirid); 798c2ecf20Sopenharmony_civoid btrfs_end_log_trans(struct btrfs_root *root); 808c2ecf20Sopenharmony_civoid btrfs_pin_log_trans(struct btrfs_root *root); 818c2ecf20Sopenharmony_civoid btrfs_record_unlink_dir(struct btrfs_trans_handle *trans, 828c2ecf20Sopenharmony_ci struct btrfs_inode *dir, struct btrfs_inode *inode, 838c2ecf20Sopenharmony_ci int for_rename); 848c2ecf20Sopenharmony_civoid btrfs_record_snapshot_destroy(struct btrfs_trans_handle *trans, 858c2ecf20Sopenharmony_ci struct btrfs_inode *dir); 868c2ecf20Sopenharmony_civoid btrfs_log_new_name(struct btrfs_trans_handle *trans, 878c2ecf20Sopenharmony_ci struct btrfs_inode *inode, struct btrfs_inode *old_dir, 888c2ecf20Sopenharmony_ci struct dentry *parent); 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci#endif 91