Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright (C) 2008 Oracle.  All rights reserved.
0004  */
0005 
0006 #ifndef BTRFS_TREE_LOG_H
0007 #define BTRFS_TREE_LOG_H
0008 
0009 #include "ctree.h"
0010 #include "transaction.h"
0011 
0012 /* return value for btrfs_log_dentry_safe that means we don't need to log it at all */
0013 #define BTRFS_NO_LOG_SYNC 256
0014 
0015 /* We can't use the tree log for whatever reason, force a transaction commit */
0016 #define BTRFS_LOG_FORCE_COMMIT              (1)
0017 
0018 struct btrfs_log_ctx {
0019     int log_ret;
0020     int log_transid;
0021     bool log_new_dentries;
0022     bool logging_new_name;
0023     /* Indicate if the inode being logged was logged before. */
0024     bool logged_before;
0025     /* Tracks the last logged dir item/index key offset. */
0026     u64 last_dir_item_offset;
0027     struct inode *inode;
0028     struct list_head list;
0029     /* Only used for fast fsyncs. */
0030     struct list_head ordered_extents;
0031 };
0032 
0033 static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx,
0034                       struct inode *inode)
0035 {
0036     ctx->log_ret = 0;
0037     ctx->log_transid = 0;
0038     ctx->log_new_dentries = false;
0039     ctx->logging_new_name = false;
0040     ctx->logged_before = false;
0041     ctx->inode = inode;
0042     INIT_LIST_HEAD(&ctx->list);
0043     INIT_LIST_HEAD(&ctx->ordered_extents);
0044 }
0045 
0046 static inline void btrfs_release_log_ctx_extents(struct btrfs_log_ctx *ctx)
0047 {
0048     struct btrfs_ordered_extent *ordered;
0049     struct btrfs_ordered_extent *tmp;
0050 
0051     ASSERT(inode_is_locked(ctx->inode));
0052 
0053     list_for_each_entry_safe(ordered, tmp, &ctx->ordered_extents, log_list) {
0054         list_del_init(&ordered->log_list);
0055         btrfs_put_ordered_extent(ordered);
0056     }
0057 }
0058 
0059 static inline void btrfs_set_log_full_commit(struct btrfs_trans_handle *trans)
0060 {
0061     WRITE_ONCE(trans->fs_info->last_trans_log_full_commit, trans->transid);
0062 }
0063 
0064 static inline int btrfs_need_log_full_commit(struct btrfs_trans_handle *trans)
0065 {
0066     return READ_ONCE(trans->fs_info->last_trans_log_full_commit) ==
0067         trans->transid;
0068 }
0069 
0070 int btrfs_sync_log(struct btrfs_trans_handle *trans,
0071            struct btrfs_root *root, struct btrfs_log_ctx *ctx);
0072 int btrfs_free_log(struct btrfs_trans_handle *trans, struct btrfs_root *root);
0073 int btrfs_free_log_root_tree(struct btrfs_trans_handle *trans,
0074                  struct btrfs_fs_info *fs_info);
0075 int btrfs_recover_log_trees(struct btrfs_root *tree_root);
0076 int btrfs_log_dentry_safe(struct btrfs_trans_handle *trans,
0077               struct dentry *dentry,
0078               struct btrfs_log_ctx *ctx);
0079 void btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans,
0080                   struct btrfs_root *root,
0081                   const char *name, int name_len,
0082                   struct btrfs_inode *dir, u64 index);
0083 void btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans,
0084                 struct btrfs_root *root,
0085                 const char *name, int name_len,
0086                 struct btrfs_inode *inode, u64 dirid);
0087 void btrfs_end_log_trans(struct btrfs_root *root);
0088 void btrfs_pin_log_trans(struct btrfs_root *root);
0089 void btrfs_record_unlink_dir(struct btrfs_trans_handle *trans,
0090                  struct btrfs_inode *dir, struct btrfs_inode *inode,
0091                  int for_rename);
0092 void btrfs_record_snapshot_destroy(struct btrfs_trans_handle *trans,
0093                    struct btrfs_inode *dir);
0094 void btrfs_log_new_name(struct btrfs_trans_handle *trans,
0095             struct dentry *old_dentry, struct btrfs_inode *old_dir,
0096             u64 old_dir_index, struct dentry *parent);
0097 
0098 #endif