Dave Chinner | 0b61f8a | 2018-06-05 19:42:14 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 3 | * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc. |
| 4 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
| 6 | #ifndef __XFS_LOG_H__ |
| 7 | #define __XFS_LOG_H__ |
| 8 | |
Christoph Hellwig | 89ae379 | 2019-06-28 19:27:34 -0700 | [diff] [blame] | 9 | struct xfs_cil_ctx; |
| 10 | |
Dave Chinner | fc06c6d | 2013-08-12 20:49:22 +1000 | [diff] [blame] | 11 | struct xfs_log_vec { |
| 12 | struct xfs_log_vec *lv_next; /* next lv in build list */ |
| 13 | int lv_niovecs; /* number of iovecs in lv */ |
| 14 | struct xfs_log_iovec *lv_iovecp; /* iovec array */ |
| 15 | struct xfs_log_item *lv_item; /* owner */ |
| 16 | char *lv_buf; /* formatted buffer */ |
Dave Chinner | 110dc24 | 2014-05-20 08:18:09 +1000 | [diff] [blame] | 17 | int lv_bytes; /* accounted space in buffer */ |
| 18 | int lv_buf_len; /* aligned size of buffer */ |
Dave Chinner | 7492c5b | 2013-08-12 20:50:05 +1000 | [diff] [blame] | 19 | int lv_size; /* size of allocated lv */ |
Dave Chinner | fc06c6d | 2013-08-12 20:49:22 +1000 | [diff] [blame] | 20 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Dave Chinner | fc06c6d | 2013-08-12 20:49:22 +1000 | [diff] [blame] | 22 | #define XFS_LOG_VEC_ORDERED (-1) |
| 23 | |
Christoph Hellwig | 1234351 | 2013-12-13 11:00:43 +1100 | [diff] [blame] | 24 | static inline void * |
Christoph Hellwig | bde7cff | 2013-12-13 11:34:02 +1100 | [diff] [blame] | 25 | xlog_prepare_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp, |
| 26 | uint type) |
Christoph Hellwig | 1234351 | 2013-12-13 11:00:43 +1100 | [diff] [blame] | 27 | { |
| 28 | struct xfs_log_iovec *vec = *vecp; |
| 29 | |
Christoph Hellwig | bde7cff | 2013-12-13 11:34:02 +1100 | [diff] [blame] | 30 | if (vec) { |
| 31 | ASSERT(vec - lv->lv_iovecp < lv->lv_niovecs); |
| 32 | vec++; |
| 33 | } else { |
| 34 | vec = &lv->lv_iovecp[0]; |
| 35 | } |
Christoph Hellwig | 1234351 | 2013-12-13 11:00:43 +1100 | [diff] [blame] | 36 | |
Christoph Hellwig | bde7cff | 2013-12-13 11:34:02 +1100 | [diff] [blame] | 37 | vec->i_type = type; |
| 38 | vec->i_addr = lv->lv_buf + lv->lv_buf_len; |
| 39 | |
| 40 | ASSERT(IS_ALIGNED((unsigned long)vec->i_addr, sizeof(uint64_t))); |
| 41 | |
| 42 | *vecp = vec; |
Christoph Hellwig | 1234351 | 2013-12-13 11:00:43 +1100 | [diff] [blame] | 43 | return vec->i_addr; |
| 44 | } |
| 45 | |
Dave Chinner | 110dc24 | 2014-05-20 08:18:09 +1000 | [diff] [blame] | 46 | /* |
| 47 | * We need to make sure the next buffer is naturally aligned for the biggest |
| 48 | * basic data type we put into it. We already accounted for this padding when |
| 49 | * sizing the buffer. |
| 50 | * |
| 51 | * However, this padding does not get written into the log, and hence we have to |
| 52 | * track the space used by the log vectors separately to prevent log space hangs |
| 53 | * due to inaccurate accounting (i.e. a leak) of the used log space through the |
| 54 | * CIL context ticket. |
| 55 | */ |
Christoph Hellwig | bde7cff | 2013-12-13 11:34:02 +1100 | [diff] [blame] | 56 | static inline void |
| 57 | xlog_finish_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec *vec, int len) |
| 58 | { |
Christoph Hellwig | bde7cff | 2013-12-13 11:34:02 +1100 | [diff] [blame] | 59 | lv->lv_buf_len += round_up(len, sizeof(uint64_t)); |
Dave Chinner | 110dc24 | 2014-05-20 08:18:09 +1000 | [diff] [blame] | 60 | lv->lv_bytes += len; |
Christoph Hellwig | bde7cff | 2013-12-13 11:34:02 +1100 | [diff] [blame] | 61 | vec->i_len = len; |
| 62 | } |
| 63 | |
| 64 | static inline void * |
| 65 | xlog_copy_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp, |
| 66 | uint type, void *data, int len) |
| 67 | { |
| 68 | void *buf; |
| 69 | |
| 70 | buf = xlog_prepare_iovec(lv, vecp, type); |
| 71 | memcpy(buf, data, len); |
| 72 | xlog_finish_iovec(lv, *vecp, len); |
| 73 | return buf; |
| 74 | } |
| 75 | |
Dave Chinner | fc06c6d | 2013-08-12 20:49:22 +1000 | [diff] [blame] | 76 | /* |
Nathan Scott | c41564b | 2006-03-29 08:55:14 +1000 | [diff] [blame] | 77 | * By comparing each component, we don't have to worry about extra |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | * endian issues in treating two 32 bit numbers as one 64 bit number |
| 79 | */ |
Andrew Morton | a136564 | 2006-01-08 01:04:09 -0800 | [diff] [blame] | 80 | static inline xfs_lsn_t _lsn_cmp(xfs_lsn_t lsn1, xfs_lsn_t lsn2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
| 82 | if (CYCLE_LSN(lsn1) != CYCLE_LSN(lsn2)) |
| 83 | return (CYCLE_LSN(lsn1)<CYCLE_LSN(lsn2))? -999 : 999; |
| 84 | |
| 85 | if (BLOCK_LSN(lsn1) != BLOCK_LSN(lsn2)) |
| 86 | return (BLOCK_LSN(lsn1)<BLOCK_LSN(lsn2))? -999 : 999; |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | #define XFS_LSN_CMP(x,y) _lsn_cmp(x,y) |
| 92 | |
| 93 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | * Flags to xfs_log_force() |
| 95 | * |
| 96 | * XFS_LOG_SYNC: Synchronous force in-core log to disk |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | */ |
| 98 | #define XFS_LOG_SYNC 0x1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | /* Log manager interfaces */ |
| 101 | struct xfs_mount; |
Christoph Hellwig | 35a8a72 | 2010-02-15 23:34:54 +0000 | [diff] [blame] | 102 | struct xlog_in_core; |
Dave Chinner | cc09c0d | 2008-11-17 17:37:10 +1100 | [diff] [blame] | 103 | struct xlog_ticket; |
Dave Chinner | 43f5efc | 2010-03-23 10:10:00 +1100 | [diff] [blame] | 104 | struct xfs_log_item; |
| 105 | struct xfs_item_ops; |
Dave Chinner | 955833c | 2010-05-14 21:41:46 +1000 | [diff] [blame] | 106 | struct xfs_trans; |
Dave Chinner | 0020a19 | 2021-08-10 18:00:44 -0700 | [diff] [blame^] | 107 | struct xlog; |
Christoph Hellwig | 35a8a72 | 2010-02-15 23:34:54 +0000 | [diff] [blame] | 108 | |
Christoph Hellwig | 60e5bb7 | 2018-03-13 23:15:28 -0700 | [diff] [blame] | 109 | int xfs_log_force(struct xfs_mount *mp, uint flags); |
Dave Chinner | 5f9b4b0 | 2021-06-18 08:21:52 -0700 | [diff] [blame] | 110 | int xfs_log_force_seq(struct xfs_mount *mp, xfs_csn_t seq, uint flags, |
Christoph Hellwig | 656de4f | 2018-03-13 23:15:28 -0700 | [diff] [blame] | 111 | int *log_forced); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | int xfs_log_mount(struct xfs_mount *mp, |
| 113 | struct xfs_buftarg *log_target, |
| 114 | xfs_daddr_t start_block, |
| 115 | int num_bblocks); |
Christoph Hellwig | 4249023 | 2008-08-13 16:49:32 +1000 | [diff] [blame] | 116 | int xfs_log_mount_finish(struct xfs_mount *mp); |
Hariprasad Kelam | a7a9250 | 2019-07-03 07:34:18 -0700 | [diff] [blame] | 117 | void xfs_log_mount_cancel(struct xfs_mount *); |
Christoph Hellwig | 09a423a | 2012-02-20 02:31:20 +0000 | [diff] [blame] | 118 | xfs_lsn_t xlog_assign_tail_lsn(struct xfs_mount *mp); |
Christoph Hellwig | 1c30462 | 2012-04-23 15:58:33 +1000 | [diff] [blame] | 119 | xfs_lsn_t xlog_assign_tail_lsn_locked(struct xfs_mount *mp); |
Christoph Hellwig | cfb7cdc | 2012-02-20 02:31:23 +0000 | [diff] [blame] | 120 | void xfs_log_space_wake(struct xfs_mount *mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | int xfs_log_reserve(struct xfs_mount *mp, |
| 122 | int length, |
| 123 | int count, |
Christoph Hellwig | 35a8a72 | 2010-02-15 23:34:54 +0000 | [diff] [blame] | 124 | struct xlog_ticket **ticket, |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 125 | uint8_t clientid, |
Christoph Hellwig | 710b1e2 | 2016-04-06 09:20:36 +1000 | [diff] [blame] | 126 | bool permanent); |
Christoph Hellwig | 9006fb9 | 2012-02-20 02:31:31 +0000 | [diff] [blame] | 127 | int xfs_log_regrant(struct xfs_mount *mp, struct xlog_ticket *tic); |
Christoph Hellwig | 21b699c | 2009-03-16 08:19:29 +0100 | [diff] [blame] | 128 | void xfs_log_unmount(struct xfs_mount *mp); |
Brian Foster | 50d2548 | 2021-01-22 16:48:20 -0800 | [diff] [blame] | 129 | bool xfs_log_writable(struct xfs_mount *mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
Dave Chinner | 71e330b | 2010-05-21 14:37:18 +1000 | [diff] [blame] | 131 | struct xlog_ticket *xfs_log_ticket_get(struct xlog_ticket *ticket); |
Dave Chinner | cc09c0d | 2008-11-17 17:37:10 +1100 | [diff] [blame] | 132 | void xfs_log_ticket_put(struct xlog_ticket *ticket); |
| 133 | |
Christoph Hellwig | 12e6a0f | 2020-03-20 08:49:20 -0700 | [diff] [blame] | 134 | void xlog_cil_process_committed(struct list_head *list); |
Dave Chinner | ccf7c23 | 2010-05-20 23:19:42 +1000 | [diff] [blame] | 135 | bool xfs_log_item_in_current_chkpt(struct xfs_log_item *lip); |
Dave Chinner | 71e330b | 2010-05-21 14:37:18 +1000 | [diff] [blame] | 136 | |
Dave Chinner | f661f1e | 2012-10-08 21:56:02 +1100 | [diff] [blame] | 137 | void xfs_log_work_queue(struct xfs_mount *mp); |
Brian Foster | 303591a | 2021-01-22 16:48:22 -0800 | [diff] [blame] | 138 | int xfs_log_quiesce(struct xfs_mount *mp); |
Brian Foster | 9e54ee0 | 2021-01-22 16:48:21 -0800 | [diff] [blame] | 139 | void xfs_log_clean(struct xfs_mount *mp); |
Brian Foster | a45086e | 2015-10-12 15:59:25 +1100 | [diff] [blame] | 140 | bool xfs_log_check_lsn(struct xfs_mount *, xfs_lsn_t); |
Dave Chinner | f661f1e | 2012-10-08 21:56:02 +1100 | [diff] [blame] | 141 | |
Darrick J. Wong | ed1575d | 2020-09-25 17:39:51 -0700 | [diff] [blame] | 142 | xfs_lsn_t xlog_grant_push_threshold(struct xlog *log, int need_bytes); |
Dave Chinner | b36d465 | 2021-08-10 18:00:39 -0700 | [diff] [blame] | 143 | bool xlog_force_shutdown(struct xlog *log, int shutdown_flags); |
Darrick J. Wong | ed1575d | 2020-09-25 17:39:51 -0700 | [diff] [blame] | 144 | |
Darrick J. Wong | 2b73a2c | 2021-08-08 08:27:12 -0700 | [diff] [blame] | 145 | void xlog_use_incompat_feat(struct xlog *log); |
| 146 | void xlog_drop_incompat_feat(struct xlog *log); |
| 147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | #endif /* __XFS_LOG_H__ */ |