Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright (c) 2000,2005 Silicon Graphics, Inc.
0004  * All Rights Reserved.
0005  */
0006 #ifndef __XFS_LOG_RECOVER_H__
0007 #define __XFS_LOG_RECOVER_H__
0008 
0009 /*
0010  * Each log item type (XFS_LI_*) gets its own xlog_recover_item_ops to
0011  * define how recovery should work for that type of log item.
0012  */
0013 struct xlog_recover_item;
0014 
0015 /* Sorting hat for log items as they're read in. */
0016 enum xlog_recover_reorder {
0017     XLOG_REORDER_BUFFER_LIST,
0018     XLOG_REORDER_ITEM_LIST,
0019     XLOG_REORDER_INODE_BUFFER_LIST,
0020     XLOG_REORDER_CANCEL_LIST,
0021 };
0022 
0023 struct xlog_recover_item_ops {
0024     uint16_t    item_type;  /* XFS_LI_* type code. */
0025 
0026     /*
0027      * Help sort recovered log items into the order required to replay them
0028      * correctly.  Log item types that always use XLOG_REORDER_ITEM_LIST do
0029      * not have to supply a function here.  See the comment preceding
0030      * xlog_recover_reorder_trans for more details about what the return
0031      * values mean.
0032      */
0033     enum xlog_recover_reorder (*reorder)(struct xlog_recover_item *item);
0034 
0035     /* Start readahead for pass2, if provided. */
0036     void (*ra_pass2)(struct xlog *log, struct xlog_recover_item *item);
0037 
0038     /* Do whatever work we need to do for pass1, if provided. */
0039     int (*commit_pass1)(struct xlog *log, struct xlog_recover_item *item);
0040 
0041     /*
0042      * This function should do whatever work is needed for pass2 of log
0043      * recovery, if provided.
0044      *
0045      * If the recovered item is an intent item, this function should parse
0046      * the recovered item to construct an in-core log intent item and
0047      * insert it into the AIL.  The in-core log intent item should have 1
0048      * refcount so that the item is freed either (a) when we commit the
0049      * recovered log item for the intent-done item; (b) replay the work and
0050      * log a new intent-done item; or (c) recovery fails and we have to
0051      * abort.
0052      *
0053      * If the recovered item is an intent-done item, this function should
0054      * parse the recovered item to find the id of the corresponding intent
0055      * log item.  Next, it should find the in-core log intent item in the
0056      * AIL and release it.
0057      */
0058     int (*commit_pass2)(struct xlog *log, struct list_head *buffer_list,
0059                 struct xlog_recover_item *item, xfs_lsn_t lsn);
0060 };
0061 
0062 extern const struct xlog_recover_item_ops xlog_icreate_item_ops;
0063 extern const struct xlog_recover_item_ops xlog_buf_item_ops;
0064 extern const struct xlog_recover_item_ops xlog_inode_item_ops;
0065 extern const struct xlog_recover_item_ops xlog_dquot_item_ops;
0066 extern const struct xlog_recover_item_ops xlog_quotaoff_item_ops;
0067 extern const struct xlog_recover_item_ops xlog_bui_item_ops;
0068 extern const struct xlog_recover_item_ops xlog_bud_item_ops;
0069 extern const struct xlog_recover_item_ops xlog_efi_item_ops;
0070 extern const struct xlog_recover_item_ops xlog_efd_item_ops;
0071 extern const struct xlog_recover_item_ops xlog_rui_item_ops;
0072 extern const struct xlog_recover_item_ops xlog_rud_item_ops;
0073 extern const struct xlog_recover_item_ops xlog_cui_item_ops;
0074 extern const struct xlog_recover_item_ops xlog_cud_item_ops;
0075 extern const struct xlog_recover_item_ops xlog_attri_item_ops;
0076 extern const struct xlog_recover_item_ops xlog_attrd_item_ops;
0077 
0078 /*
0079  * Macros, structures, prototypes for internal log manager use.
0080  */
0081 
0082 #define XLOG_RHASH_BITS  4
0083 #define XLOG_RHASH_SIZE 16
0084 #define XLOG_RHASH_SHIFT 2
0085 #define XLOG_RHASH(tid) \
0086     ((((uint32_t)tid)>>XLOG_RHASH_SHIFT) & (XLOG_RHASH_SIZE-1))
0087 
0088 #define XLOG_MAX_REGIONS_IN_ITEM   (XFS_MAX_BLOCKSIZE / XFS_BLF_CHUNK / 2 + 1)
0089 
0090 
0091 /*
0092  * item headers are in ri_buf[0].  Additional buffers follow.
0093  */
0094 struct xlog_recover_item {
0095     struct list_head    ri_list;
0096     int         ri_cnt; /* count of regions found */
0097     int         ri_total;   /* total regions */
0098     struct xfs_log_iovec    *ri_buf;    /* ptr to regions buffer */
0099     const struct xlog_recover_item_ops *ri_ops;
0100 };
0101 
0102 struct xlog_recover {
0103     struct hlist_node   r_list;
0104     xlog_tid_t      r_log_tid;  /* log's transaction id */
0105     xfs_trans_header_t  r_theader;  /* trans header for partial */
0106     int         r_state;    /* not needed */
0107     xfs_lsn_t       r_lsn;      /* xact lsn */
0108     struct list_head    r_itemq;    /* q for items */
0109 };
0110 
0111 #define ITEM_TYPE(i)    (*(unsigned short *)(i)->ri_buf[0].i_addr)
0112 
0113 #define XLOG_RECOVER_CRCPASS    0
0114 #define XLOG_RECOVER_PASS1  1
0115 #define XLOG_RECOVER_PASS2  2
0116 
0117 void xlog_buf_readahead(struct xlog *log, xfs_daddr_t blkno, uint len,
0118         const struct xfs_buf_ops *ops);
0119 bool xlog_is_buffer_cancelled(struct xlog *log, xfs_daddr_t blkno, uint len);
0120 
0121 int xlog_recover_iget(struct xfs_mount *mp, xfs_ino_t ino,
0122         struct xfs_inode **ipp);
0123 void xlog_recover_release_intent(struct xlog *log, unsigned short intent_type,
0124         uint64_t intent_id);
0125 int xlog_alloc_buf_cancel_table(struct xlog *log);
0126 void xlog_free_buf_cancel_table(struct xlog *log);
0127 
0128 #ifdef DEBUG
0129 void xlog_check_buf_cancel_table(struct xlog *log);
0130 #else
0131 #define xlog_check_buf_cancel_table(log) do { } while (0)
0132 #endif
0133 
0134 #endif  /* __XFS_LOG_RECOVER_H__ */