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 24b2c28035SDave Chinner /* 25b2c28035SDave Chinner * Calculate the log iovec length for a given user buffer length. Intended to be 26b2c28035SDave Chinner * used by ->iop_size implementations when sizing buffers of arbitrary 27b2c28035SDave Chinner * alignments. 28b2c28035SDave Chinner */ 29b2c28035SDave Chinner static inline int 30b2c28035SDave Chinner xlog_calc_iovec_len(int len) 31b2c28035SDave Chinner { 32b2c28035SDave Chinner return roundup(len, sizeof(uint32_t)); 33b2c28035SDave Chinner } 34b2c28035SDave Chinner 358d547cf9SDave Chinner void *xlog_prepare_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp, 368d547cf9SDave Chinner uint type); 371234351cSChristoph Hellwig 38bde7cff6SChristoph Hellwig static inline void 39b2c28035SDave Chinner xlog_finish_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec *vec, 40b2c28035SDave Chinner int data_len) 41bde7cff6SChristoph Hellwig { 428d547cf9SDave Chinner struct xlog_op_header *oph = vec->i_addr; 43b2c28035SDave Chinner int len; 448d547cf9SDave Chinner 45b2c28035SDave Chinner /* 46b2c28035SDave Chinner * Always round up the length to the correct alignment so callers don't 47b2c28035SDave Chinner * need to know anything about this log vec layout requirement. This 48b2c28035SDave Chinner * means we have to zero the area the data to be written does not cover. 49b2c28035SDave Chinner * This is complicated by fact the payload region is offset into the 50b2c28035SDave Chinner * logvec region by the opheader that tracks the payload. 51b2c28035SDave Chinner */ 52b2c28035SDave Chinner len = xlog_calc_iovec_len(data_len); 53b2c28035SDave Chinner if (len - data_len != 0) { 54b2c28035SDave Chinner char *buf = vec->i_addr + sizeof(struct xlog_op_header); 55b2c28035SDave Chinner 56b2c28035SDave Chinner memset(buf + data_len, 0, len - data_len); 57b2c28035SDave Chinner } 58b2c28035SDave Chinner 59b2c28035SDave Chinner /* 60b2c28035SDave Chinner * The opheader tracks aligned payload length, whilst the logvec tracks 61b2c28035SDave Chinner * the overall region length. 62b2c28035SDave Chinner */ 638d547cf9SDave Chinner oph->oh_len = cpu_to_be32(len); 648d547cf9SDave Chinner 658d547cf9SDave Chinner len += sizeof(struct xlog_op_header); 663c352befSDave Chinner lv->lv_buf_len += len; 67110dc24aSDave Chinner lv->lv_bytes += len; 68bde7cff6SChristoph Hellwig vec->i_len = len; 69b2c28035SDave Chinner 70b2c28035SDave Chinner /* Catch buffer overruns */ 71b2c28035SDave Chinner ASSERT((void *)lv->lv_buf + lv->lv_bytes <= (void *)lv + lv->lv_size); 72bde7cff6SChristoph Hellwig } 73bde7cff6SChristoph Hellwig 74b2c28035SDave Chinner /* 75b2c28035SDave Chinner * Copy the amount of data requested by the caller into a new log iovec. 76b2c28035SDave Chinner */ 77bde7cff6SChristoph Hellwig static inline void * 78bde7cff6SChristoph Hellwig xlog_copy_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp, 79bde7cff6SChristoph Hellwig uint type, void *data, int len) 80bde7cff6SChristoph Hellwig { 81bde7cff6SChristoph Hellwig void *buf; 82bde7cff6SChristoph Hellwig 83bde7cff6SChristoph Hellwig buf = xlog_prepare_iovec(lv, vecp, type); 84bde7cff6SChristoph Hellwig memcpy(buf, data, len); 85bde7cff6SChristoph Hellwig xlog_finish_iovec(lv, *vecp, len); 86bde7cff6SChristoph Hellwig return buf; 87bde7cff6SChristoph Hellwig } 88bde7cff6SChristoph Hellwig 89*4183e4f2SDarrick J. Wong static inline void * 90*4183e4f2SDarrick J. Wong xlog_copy_from_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp, 91*4183e4f2SDarrick J. Wong const struct xfs_log_iovec *src) 92*4183e4f2SDarrick J. Wong { 93*4183e4f2SDarrick J. Wong return xlog_copy_iovec(lv, vecp, src->i_type, src->i_addr, src->i_len); 94*4183e4f2SDarrick J. Wong } 95*4183e4f2SDarrick J. Wong 96fc06c6d0SDave Chinner /* 97c41564b5SNathan Scott * By comparing each component, we don't have to worry about extra 981da177e4SLinus Torvalds * endian issues in treating two 32 bit numbers as one 64 bit number 991da177e4SLinus Torvalds */ 100a1365647SAndrew Morton static inline xfs_lsn_t _lsn_cmp(xfs_lsn_t lsn1, xfs_lsn_t lsn2) 1011da177e4SLinus Torvalds { 1021da177e4SLinus Torvalds if (CYCLE_LSN(lsn1) != CYCLE_LSN(lsn2)) 1031da177e4SLinus Torvalds return (CYCLE_LSN(lsn1)<CYCLE_LSN(lsn2))? -999 : 999; 1041da177e4SLinus Torvalds 1051da177e4SLinus Torvalds if (BLOCK_LSN(lsn1) != BLOCK_LSN(lsn2)) 1061da177e4SLinus Torvalds return (BLOCK_LSN(lsn1)<BLOCK_LSN(lsn2))? -999 : 999; 1071da177e4SLinus Torvalds 1081da177e4SLinus Torvalds return 0; 1091da177e4SLinus Torvalds } 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds #define XFS_LSN_CMP(x,y) _lsn_cmp(x,y) 1121da177e4SLinus Torvalds 1131da177e4SLinus Torvalds /* 1141da177e4SLinus Torvalds * Flags to xfs_log_force() 1151da177e4SLinus Torvalds * 1161da177e4SLinus Torvalds * XFS_LOG_SYNC: Synchronous force in-core log to disk 1171da177e4SLinus Torvalds */ 1181da177e4SLinus Torvalds #define XFS_LOG_SYNC 0x1 1191da177e4SLinus Torvalds 1201da177e4SLinus Torvalds /* Log manager interfaces */ 1211da177e4SLinus Torvalds struct xfs_mount; 12235a8a72fSChristoph Hellwig struct xlog_in_core; 123cc09c0dcSDave Chinner struct xlog_ticket; 12443f5efc5SDave Chinner struct xfs_log_item; 12543f5efc5SDave Chinner struct xfs_item_ops; 126955833cfSDave Chinner struct xfs_trans; 1270020a190SDave Chinner struct xlog; 12835a8a72fSChristoph Hellwig 12960e5bb78SChristoph Hellwig int xfs_log_force(struct xfs_mount *mp, uint flags); 1305f9b4b0dSDave Chinner int xfs_log_force_seq(struct xfs_mount *mp, xfs_csn_t seq, uint flags, 131a14a348bSChristoph Hellwig int *log_forced); 1321da177e4SLinus Torvalds int xfs_log_mount(struct xfs_mount *mp, 1331da177e4SLinus Torvalds struct xfs_buftarg *log_target, 1341da177e4SLinus Torvalds xfs_daddr_t start_block, 1351da177e4SLinus Torvalds int num_bblocks); 1364249023aSChristoph Hellwig int xfs_log_mount_finish(struct xfs_mount *mp); 137a7a9250eSHariprasad Kelam void xfs_log_mount_cancel(struct xfs_mount *); 13809a423a3SChristoph Hellwig xfs_lsn_t xlog_assign_tail_lsn(struct xfs_mount *mp); 1391c304625SChristoph Hellwig xfs_lsn_t xlog_assign_tail_lsn_locked(struct xfs_mount *mp); 140cfb7cdcaSChristoph Hellwig void xfs_log_space_wake(struct xfs_mount *mp); 141c7610dceSDave Chinner int xfs_log_reserve(struct xfs_mount *mp, int length, int count, 142c7610dceSDave Chinner struct xlog_ticket **ticket, bool permanent); 1439006fb91SChristoph Hellwig int xfs_log_regrant(struct xfs_mount *mp, struct xlog_ticket *tic); 14421b699c8SChristoph Hellwig void xfs_log_unmount(struct xfs_mount *mp); 14550d25484SBrian Foster bool xfs_log_writable(struct xfs_mount *mp); 1461da177e4SLinus Torvalds 147cc09c0dcSDave Chinner struct xlog_ticket *xfs_log_ticket_get(struct xlog_ticket *ticket); 148cc09c0dcSDave Chinner void xfs_log_ticket_put(struct xlog_ticket *ticket); 149cc09c0dcSDave Chinner 15012e6a0f4SChristoph Hellwig void xlog_cil_process_committed(struct list_head *list); 151ccf7c23fSDave Chinner bool xfs_log_item_in_current_chkpt(struct xfs_log_item *lip); 15271e330b5SDave Chinner 153f661f1e0SDave Chinner void xfs_log_work_queue(struct xfs_mount *mp); 154303591a0SBrian Foster int xfs_log_quiesce(struct xfs_mount *mp); 1559e54ee0fSBrian Foster void xfs_log_clean(struct xfs_mount *mp); 156a45086e2SBrian Foster bool xfs_log_check_lsn(struct xfs_mount *, xfs_lsn_t); 157f661f1e0SDave Chinner 158ed1575daSDarrick J. Wong xfs_lsn_t xlog_grant_push_threshold(struct xlog *log, int need_bytes); 1592eb7550dSDave Chinner bool xlog_force_shutdown(struct xlog *log, uint32_t shutdown_flags); 160ed1575daSDarrick J. Wong 1612b73a2c8SDarrick J. Wong void xlog_use_incompat_feat(struct xlog *log); 1622b73a2c8SDarrick J. Wong void xlog_drop_incompat_feat(struct xlog *log); 163f3f36c89SAllison Henderson int xfs_attr_use_log_assist(struct xfs_mount *mp); 1642b73a2c8SDarrick J. Wong 1651da177e4SLinus Torvalds #endif /* __XFS_LOG_H__ */ 166