10b61f8a4SDave Chinner // SPDX-License-Identifier: GPL-2.0 21da177e4SLinus Torvalds /* 37b718769SNathan Scott * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc. 47b718769SNathan Scott * All Rights Reserved. 51da177e4SLinus Torvalds */ 61da177e4SLinus Torvalds #ifndef __XFS_LOG_H__ 71da177e4SLinus Torvalds #define __XFS_LOG_H__ 81da177e4SLinus Torvalds 989ae379dSChristoph Hellwig struct xfs_cil_ctx; 1089ae379dSChristoph Hellwig 11fc06c6d0SDave Chinner struct xfs_log_vec { 12fc06c6d0SDave Chinner struct xfs_log_vec *lv_next; /* next lv in build list */ 13fc06c6d0SDave Chinner int lv_niovecs; /* number of iovecs in lv */ 14fc06c6d0SDave Chinner struct xfs_log_iovec *lv_iovecp; /* iovec array */ 15fc06c6d0SDave Chinner struct xfs_log_item *lv_item; /* owner */ 16fc06c6d0SDave Chinner char *lv_buf; /* formatted buffer */ 17110dc24aSDave Chinner int lv_bytes; /* accounted space in buffer */ 18110dc24aSDave Chinner int lv_buf_len; /* aligned size of buffer */ 197492c5b4SDave Chinner int lv_size; /* size of allocated lv */ 20fc06c6d0SDave Chinner }; 211da177e4SLinus Torvalds 22fc06c6d0SDave Chinner #define XFS_LOG_VEC_ORDERED (-1) 23fc06c6d0SDave Chinner 241234351cSChristoph Hellwig static inline void * 25bde7cff6SChristoph Hellwig xlog_prepare_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp, 26bde7cff6SChristoph Hellwig uint type) 271234351cSChristoph Hellwig { 281234351cSChristoph Hellwig struct xfs_log_iovec *vec = *vecp; 291234351cSChristoph Hellwig 30bde7cff6SChristoph Hellwig if (vec) { 31bde7cff6SChristoph Hellwig ASSERT(vec - lv->lv_iovecp < lv->lv_niovecs); 32bde7cff6SChristoph Hellwig vec++; 33bde7cff6SChristoph Hellwig } else { 34bde7cff6SChristoph Hellwig vec = &lv->lv_iovecp[0]; 35bde7cff6SChristoph Hellwig } 361234351cSChristoph Hellwig 37bde7cff6SChristoph Hellwig vec->i_type = type; 38bde7cff6SChristoph Hellwig vec->i_addr = lv->lv_buf + lv->lv_buf_len; 39bde7cff6SChristoph Hellwig 40bde7cff6SChristoph Hellwig ASSERT(IS_ALIGNED((unsigned long)vec->i_addr, sizeof(uint64_t))); 41bde7cff6SChristoph Hellwig 42bde7cff6SChristoph Hellwig *vecp = vec; 431234351cSChristoph Hellwig return vec->i_addr; 441234351cSChristoph Hellwig } 451234351cSChristoph Hellwig 46110dc24aSDave Chinner /* 47110dc24aSDave Chinner * We need to make sure the next buffer is naturally aligned for the biggest 48110dc24aSDave Chinner * basic data type we put into it. We already accounted for this padding when 49110dc24aSDave Chinner * sizing the buffer. 50110dc24aSDave Chinner * 51110dc24aSDave Chinner * However, this padding does not get written into the log, and hence we have to 52110dc24aSDave Chinner * track the space used by the log vectors separately to prevent log space hangs 53110dc24aSDave Chinner * due to inaccurate accounting (i.e. a leak) of the used log space through the 54110dc24aSDave Chinner * CIL context ticket. 55110dc24aSDave Chinner */ 56bde7cff6SChristoph Hellwig static inline void 57bde7cff6SChristoph Hellwig xlog_finish_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec *vec, int len) 58bde7cff6SChristoph Hellwig { 59bde7cff6SChristoph Hellwig lv->lv_buf_len += round_up(len, sizeof(uint64_t)); 60110dc24aSDave Chinner lv->lv_bytes += len; 61bde7cff6SChristoph Hellwig vec->i_len = len; 62bde7cff6SChristoph Hellwig } 63bde7cff6SChristoph Hellwig 64bde7cff6SChristoph Hellwig static inline void * 65bde7cff6SChristoph Hellwig xlog_copy_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp, 66bde7cff6SChristoph Hellwig uint type, void *data, int len) 67bde7cff6SChristoph Hellwig { 68bde7cff6SChristoph Hellwig void *buf; 69bde7cff6SChristoph Hellwig 70bde7cff6SChristoph Hellwig buf = xlog_prepare_iovec(lv, vecp, type); 71bde7cff6SChristoph Hellwig memcpy(buf, data, len); 72bde7cff6SChristoph Hellwig xlog_finish_iovec(lv, *vecp, len); 73bde7cff6SChristoph Hellwig return buf; 74bde7cff6SChristoph Hellwig } 75bde7cff6SChristoph Hellwig 76fc06c6d0SDave Chinner /* 77c41564b5SNathan Scott * By comparing each component, we don't have to worry about extra 781da177e4SLinus Torvalds * endian issues in treating two 32 bit numbers as one 64 bit number 791da177e4SLinus Torvalds */ 80a1365647SAndrew Morton static inline xfs_lsn_t _lsn_cmp(xfs_lsn_t lsn1, xfs_lsn_t lsn2) 811da177e4SLinus Torvalds { 821da177e4SLinus Torvalds if (CYCLE_LSN(lsn1) != CYCLE_LSN(lsn2)) 831da177e4SLinus Torvalds return (CYCLE_LSN(lsn1)<CYCLE_LSN(lsn2))? -999 : 999; 841da177e4SLinus Torvalds 851da177e4SLinus Torvalds if (BLOCK_LSN(lsn1) != BLOCK_LSN(lsn2)) 861da177e4SLinus Torvalds return (BLOCK_LSN(lsn1)<BLOCK_LSN(lsn2))? -999 : 999; 871da177e4SLinus Torvalds 881da177e4SLinus Torvalds return 0; 891da177e4SLinus Torvalds } 901da177e4SLinus Torvalds 911da177e4SLinus Torvalds #define XFS_LSN_CMP(x,y) _lsn_cmp(x,y) 921da177e4SLinus Torvalds 931da177e4SLinus Torvalds /* 941da177e4SLinus Torvalds * Flags to xfs_log_force() 951da177e4SLinus Torvalds * 961da177e4SLinus Torvalds * XFS_LOG_SYNC: Synchronous force in-core log to disk 971da177e4SLinus Torvalds */ 981da177e4SLinus Torvalds #define XFS_LOG_SYNC 0x1 991da177e4SLinus Torvalds 1001da177e4SLinus Torvalds /* Log manager interfaces */ 1011da177e4SLinus Torvalds struct xfs_mount; 10235a8a72fSChristoph Hellwig struct xlog_in_core; 103cc09c0dcSDave Chinner struct xlog_ticket; 10443f5efc5SDave Chinner struct xfs_log_item; 10543f5efc5SDave Chinner struct xfs_item_ops; 106955833cfSDave Chinner struct xfs_trans; 107*0020a190SDave Chinner struct xlog; 10835a8a72fSChristoph Hellwig 10960e5bb78SChristoph Hellwig int xfs_log_force(struct xfs_mount *mp, uint flags); 1105f9b4b0dSDave Chinner int xfs_log_force_seq(struct xfs_mount *mp, xfs_csn_t seq, uint flags, 111a14a348bSChristoph Hellwig int *log_forced); 1121da177e4SLinus Torvalds int xfs_log_mount(struct xfs_mount *mp, 1131da177e4SLinus Torvalds struct xfs_buftarg *log_target, 1141da177e4SLinus Torvalds xfs_daddr_t start_block, 1151da177e4SLinus Torvalds int num_bblocks); 1164249023aSChristoph Hellwig int xfs_log_mount_finish(struct xfs_mount *mp); 117a7a9250eSHariprasad Kelam void xfs_log_mount_cancel(struct xfs_mount *); 11809a423a3SChristoph Hellwig xfs_lsn_t xlog_assign_tail_lsn(struct xfs_mount *mp); 1191c304625SChristoph Hellwig xfs_lsn_t xlog_assign_tail_lsn_locked(struct xfs_mount *mp); 120cfb7cdcaSChristoph Hellwig void xfs_log_space_wake(struct xfs_mount *mp); 1211da177e4SLinus Torvalds int xfs_log_reserve(struct xfs_mount *mp, 1221da177e4SLinus Torvalds int length, 1231da177e4SLinus Torvalds int count, 12435a8a72fSChristoph Hellwig struct xlog_ticket **ticket, 125c8ce540dSDarrick J. Wong uint8_t clientid, 126710b1e2cSChristoph Hellwig bool permanent); 1279006fb91SChristoph Hellwig int xfs_log_regrant(struct xfs_mount *mp, struct xlog_ticket *tic); 12821b699c8SChristoph Hellwig void xfs_log_unmount(struct xfs_mount *mp); 12950d25484SBrian Foster bool xfs_log_writable(struct xfs_mount *mp); 1301da177e4SLinus Torvalds 131cc09c0dcSDave Chinner struct xlog_ticket *xfs_log_ticket_get(struct xlog_ticket *ticket); 132cc09c0dcSDave Chinner void xfs_log_ticket_put(struct xlog_ticket *ticket); 133cc09c0dcSDave Chinner 13412e6a0f4SChristoph Hellwig void xlog_cil_process_committed(struct list_head *list); 135ccf7c23fSDave Chinner bool xfs_log_item_in_current_chkpt(struct xfs_log_item *lip); 13671e330b5SDave Chinner 137f661f1e0SDave Chinner void xfs_log_work_queue(struct xfs_mount *mp); 138303591a0SBrian Foster int xfs_log_quiesce(struct xfs_mount *mp); 1399e54ee0fSBrian Foster void xfs_log_clean(struct xfs_mount *mp); 140a45086e2SBrian Foster bool xfs_log_check_lsn(struct xfs_mount *, xfs_lsn_t); 141f661f1e0SDave Chinner 142ed1575daSDarrick J. Wong xfs_lsn_t xlog_grant_push_threshold(struct xlog *log, int need_bytes); 143b36d4651SDave Chinner bool xlog_force_shutdown(struct xlog *log, int shutdown_flags); 144ed1575daSDarrick J. Wong 1452b73a2c8SDarrick J. Wong void xlog_use_incompat_feat(struct xlog *log); 1462b73a2c8SDarrick J. Wong void xlog_drop_incompat_feat(struct xlog *log); 1472b73a2c8SDarrick J. Wong 1481da177e4SLinus Torvalds #endif /* __XFS_LOG_H__ */ 149