| 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc. |
| 4 | * All Rights Reserved. |
| 5 | */ |
| 6 | #ifndef __XFS_LOG_H__ |
| 7 | #define __XFS_LOG_H__ |
| 8 | |
| 9 | struct xfs_cil_ctx; |
| 10 | |
| 11 | struct xfs_log_vec { |
| 12 | struct list_head lv_list; /* CIL lv chain ptrs */ |
| 13 | uint32_t lv_order_id; /* chain ordering info */ |
| 14 | int lv_niovecs; /* number of iovecs in lv */ |
| 15 | struct xfs_log_iovec *lv_iovecp; /* iovec array */ |
| 16 | struct xfs_log_item *lv_item; /* owner */ |
| 17 | char *lv_buf; /* formatted buffer */ |
| 18 | int lv_bytes; /* accounted space in buffer */ |
| 19 | int lv_buf_used; /* buffer space used so far */ |
| 20 | int lv_alloc_size; /* size of allocated lv */ |
| 21 | }; |
| 22 | |
| 23 | /* Region types for iovec's i_type */ |
| 24 | #define XLOG_REG_TYPE_BFORMAT 1 |
| 25 | #define XLOG_REG_TYPE_BCHUNK 2 |
| 26 | #define XLOG_REG_TYPE_EFI_FORMAT 3 |
| 27 | #define XLOG_REG_TYPE_EFD_FORMAT 4 |
| 28 | #define XLOG_REG_TYPE_IFORMAT 5 |
| 29 | #define XLOG_REG_TYPE_ICORE 6 |
| 30 | #define XLOG_REG_TYPE_IEXT 7 |
| 31 | #define XLOG_REG_TYPE_IBROOT 8 |
| 32 | #define XLOG_REG_TYPE_ILOCAL 9 |
| 33 | #define XLOG_REG_TYPE_IATTR_EXT 10 |
| 34 | #define XLOG_REG_TYPE_IATTR_BROOT 11 |
| 35 | #define XLOG_REG_TYPE_IATTR_LOCAL 12 |
| 36 | #define XLOG_REG_TYPE_QFORMAT 13 |
| 37 | #define XLOG_REG_TYPE_DQUOT 14 |
| 38 | #define XLOG_REG_TYPE_QUOTAOFF 15 |
| 39 | #define 16 |
| 40 | #define XLOG_REG_TYPE_UNMOUNT 17 |
| 41 | #define XLOG_REG_TYPE_COMMIT 18 |
| 42 | #define XLOG_REG_TYPE_TRANSHDR 19 |
| 43 | #define XLOG_REG_TYPE_ICREATE 20 |
| 44 | #define XLOG_REG_TYPE_RUI_FORMAT 21 |
| 45 | #define XLOG_REG_TYPE_RUD_FORMAT 22 |
| 46 | #define XLOG_REG_TYPE_CUI_FORMAT 23 |
| 47 | #define XLOG_REG_TYPE_CUD_FORMAT 24 |
| 48 | #define XLOG_REG_TYPE_BUI_FORMAT 25 |
| 49 | #define XLOG_REG_TYPE_BUD_FORMAT 26 |
| 50 | #define XLOG_REG_TYPE_ATTRI_FORMAT 27 |
| 51 | #define XLOG_REG_TYPE_ATTRD_FORMAT 28 |
| 52 | #define XLOG_REG_TYPE_ATTR_NAME 29 |
| 53 | #define XLOG_REG_TYPE_ATTR_VALUE 30 |
| 54 | #define XLOG_REG_TYPE_XMI_FORMAT 31 |
| 55 | #define XLOG_REG_TYPE_XMD_FORMAT 32 |
| 56 | #define XLOG_REG_TYPE_ATTR_NEWNAME 33 |
| 57 | #define XLOG_REG_TYPE_ATTR_NEWVALUE 34 |
| 58 | #define XLOG_REG_TYPE_MAX 34 |
| 59 | |
| 60 | #define XFS_LOG_VEC_ORDERED (-1) |
| 61 | |
| 62 | /* |
| 63 | * Calculate the log iovec length for a given user buffer length. Intended to be |
| 64 | * used by ->iop_size implementations when sizing buffers of arbitrary |
| 65 | * alignments. |
| 66 | */ |
| 67 | static inline int |
| 68 | xlog_calc_iovec_len(int len) |
| 69 | { |
| 70 | return roundup(len, sizeof(uint32_t)); |
| 71 | } |
| 72 | |
| 73 | void *xlog_prepare_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp, |
| 74 | uint type); |
| 75 | |
| 76 | static inline void |
| 77 | xlog_finish_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec *vec, |
| 78 | int data_len) |
| 79 | { |
| 80 | struct *oph = vec->i_addr; |
| 81 | int len; |
| 82 | |
| 83 | /* |
| 84 | * Always round up the length to the correct alignment so callers don't |
| 85 | * need to know anything about this log vec layout requirement. This |
| 86 | * means we have to zero the area the data to be written does not cover. |
| 87 | * This is complicated by fact the payload region is offset into the |
| 88 | * logvec region by the opheader that tracks the payload. |
| 89 | */ |
| 90 | len = xlog_calc_iovec_len(len: data_len); |
| 91 | if (len - data_len != 0) { |
| 92 | char *buf = vec->i_addr + sizeof(struct xlog_op_header); |
| 93 | |
| 94 | memset(buf + data_len, 0, len - data_len); |
| 95 | } |
| 96 | |
| 97 | /* |
| 98 | * The opheader tracks aligned payload length, whilst the logvec tracks |
| 99 | * the overall region length. |
| 100 | */ |
| 101 | oph->oh_len = cpu_to_be32(len); |
| 102 | |
| 103 | len += sizeof(struct xlog_op_header); |
| 104 | lv->lv_buf_used += len; |
| 105 | lv->lv_bytes += len; |
| 106 | vec->i_len = len; |
| 107 | |
| 108 | /* Catch buffer overruns */ |
| 109 | ASSERT((void *)lv->lv_buf + lv->lv_bytes <= |
| 110 | (void *)lv + lv->lv_alloc_size); |
| 111 | } |
| 112 | |
| 113 | /* |
| 114 | * Copy the amount of data requested by the caller into a new log iovec. |
| 115 | */ |
| 116 | static inline void * |
| 117 | xlog_copy_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp, |
| 118 | uint type, void *data, int len) |
| 119 | { |
| 120 | void *buf; |
| 121 | |
| 122 | buf = xlog_prepare_iovec(lv, vecp, type); |
| 123 | memcpy(buf, data, len); |
| 124 | xlog_finish_iovec(lv, vec: *vecp, data_len: len); |
| 125 | return buf; |
| 126 | } |
| 127 | |
| 128 | /* |
| 129 | * By comparing each component, we don't have to worry about extra |
| 130 | * endian issues in treating two 32 bit numbers as one 64 bit number |
| 131 | */ |
| 132 | static inline xfs_lsn_t _lsn_cmp(xfs_lsn_t lsn1, xfs_lsn_t lsn2) |
| 133 | { |
| 134 | if (CYCLE_LSN(lsn1) != CYCLE_LSN(lsn2)) |
| 135 | return (CYCLE_LSN(lsn1)<CYCLE_LSN(lsn2))? -999 : 999; |
| 136 | |
| 137 | if (BLOCK_LSN(lsn1) != BLOCK_LSN(lsn2)) |
| 138 | return (BLOCK_LSN(lsn1)<BLOCK_LSN(lsn2))? -999 : 999; |
| 139 | |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | #define XFS_LSN_CMP(x,y) _lsn_cmp(x,y) |
| 144 | |
| 145 | /* |
| 146 | * Flags to xfs_log_force() |
| 147 | * |
| 148 | * XFS_LOG_SYNC: Synchronous force in-core log to disk |
| 149 | */ |
| 150 | #define XFS_LOG_SYNC 0x1 |
| 151 | |
| 152 | /* Log manager interfaces */ |
| 153 | struct xfs_mount; |
| 154 | struct xlog_in_core; |
| 155 | struct xlog_ticket; |
| 156 | struct xfs_log_item; |
| 157 | struct xfs_item_ops; |
| 158 | struct xfs_trans; |
| 159 | struct xlog; |
| 160 | |
| 161 | int xfs_log_force(struct xfs_mount *mp, uint flags); |
| 162 | int xfs_log_force_seq(struct xfs_mount *mp, xfs_csn_t seq, uint flags, |
| 163 | int *log_forced); |
| 164 | int xfs_log_mount(struct xfs_mount *mp, |
| 165 | struct xfs_buftarg *log_target, |
| 166 | xfs_daddr_t start_block, |
| 167 | int num_bblocks); |
| 168 | int xfs_log_mount_finish(struct xfs_mount *mp); |
| 169 | void xfs_log_mount_cancel(struct xfs_mount *); |
| 170 | xfs_lsn_t xlog_assign_tail_lsn(struct xfs_mount *mp); |
| 171 | xfs_lsn_t xlog_assign_tail_lsn_locked(struct xfs_mount *mp); |
| 172 | void xfs_log_space_wake(struct xfs_mount *mp); |
| 173 | int xfs_log_reserve(struct xfs_mount *mp, int length, int count, |
| 174 | struct xlog_ticket **ticket, bool permanent); |
| 175 | int xfs_log_regrant(struct xfs_mount *mp, struct xlog_ticket *tic); |
| 176 | void xfs_log_unmount(struct xfs_mount *mp); |
| 177 | bool xfs_log_writable(struct xfs_mount *mp); |
| 178 | |
| 179 | struct xlog_ticket *xfs_log_ticket_get(struct xlog_ticket *ticket); |
| 180 | void xfs_log_ticket_put(struct xlog_ticket *ticket); |
| 181 | |
| 182 | void xlog_cil_process_committed(struct list_head *list); |
| 183 | bool xfs_log_item_in_current_chkpt(struct xfs_log_item *lip); |
| 184 | |
| 185 | void xfs_log_work_queue(struct xfs_mount *mp); |
| 186 | int xfs_log_quiesce(struct xfs_mount *mp); |
| 187 | void xfs_log_clean(struct xfs_mount *mp); |
| 188 | bool xfs_log_check_lsn(struct xfs_mount *, xfs_lsn_t); |
| 189 | |
| 190 | bool xlog_force_shutdown(struct xlog *log, uint32_t shutdown_flags); |
| 191 | |
| 192 | #endif /* __XFS_LOG_H__ */ |
| 193 | |