xref: /openbmc/linux/fs/xfs/xfs_log.h (revision 8d547cf9d2392585204075243f29022a619550f2)
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 
24*8d547cf9SDave Chinner void *xlog_prepare_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp,
25*8d547cf9SDave Chinner 		uint type);
261234351cSChristoph Hellwig 
27bde7cff6SChristoph Hellwig static inline void
28bde7cff6SChristoph Hellwig xlog_finish_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec *vec, int len)
29bde7cff6SChristoph Hellwig {
30*8d547cf9SDave Chinner 	struct xlog_op_header	*oph = vec->i_addr;
31*8d547cf9SDave Chinner 
32*8d547cf9SDave Chinner 	/* opheader tracks payload length, logvec tracks region length */
33*8d547cf9SDave Chinner 	oph->oh_len = cpu_to_be32(len);
34*8d547cf9SDave Chinner 
35*8d547cf9SDave Chinner 	len += sizeof(struct xlog_op_header);
363c352befSDave Chinner 	lv->lv_buf_len += len;
37110dc24aSDave Chinner 	lv->lv_bytes += len;
38bde7cff6SChristoph Hellwig 	vec->i_len = len;
39bde7cff6SChristoph Hellwig }
40bde7cff6SChristoph Hellwig 
41bde7cff6SChristoph Hellwig static inline void *
42bde7cff6SChristoph Hellwig xlog_copy_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp,
43bde7cff6SChristoph Hellwig 		uint type, void *data, int len)
44bde7cff6SChristoph Hellwig {
45bde7cff6SChristoph Hellwig 	void *buf;
46bde7cff6SChristoph Hellwig 
47bde7cff6SChristoph Hellwig 	buf = xlog_prepare_iovec(lv, vecp, type);
48bde7cff6SChristoph Hellwig 	memcpy(buf, data, len);
49bde7cff6SChristoph Hellwig 	xlog_finish_iovec(lv, *vecp, len);
50bde7cff6SChristoph Hellwig 	return buf;
51bde7cff6SChristoph Hellwig }
52bde7cff6SChristoph Hellwig 
53fc06c6d0SDave Chinner /*
54c41564b5SNathan Scott  * By comparing each component, we don't have to worry about extra
551da177e4SLinus Torvalds  * endian issues in treating two 32 bit numbers as one 64 bit number
561da177e4SLinus Torvalds  */
57a1365647SAndrew Morton static inline xfs_lsn_t	_lsn_cmp(xfs_lsn_t lsn1, xfs_lsn_t lsn2)
581da177e4SLinus Torvalds {
591da177e4SLinus Torvalds 	if (CYCLE_LSN(lsn1) != CYCLE_LSN(lsn2))
601da177e4SLinus Torvalds 		return (CYCLE_LSN(lsn1)<CYCLE_LSN(lsn2))? -999 : 999;
611da177e4SLinus Torvalds 
621da177e4SLinus Torvalds 	if (BLOCK_LSN(lsn1) != BLOCK_LSN(lsn2))
631da177e4SLinus Torvalds 		return (BLOCK_LSN(lsn1)<BLOCK_LSN(lsn2))? -999 : 999;
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds 	return 0;
661da177e4SLinus Torvalds }
671da177e4SLinus Torvalds 
681da177e4SLinus Torvalds #define	XFS_LSN_CMP(x,y) _lsn_cmp(x,y)
691da177e4SLinus Torvalds 
701da177e4SLinus Torvalds /*
711da177e4SLinus Torvalds  * Flags to xfs_log_force()
721da177e4SLinus Torvalds  *
731da177e4SLinus Torvalds  *	XFS_LOG_SYNC:	Synchronous force in-core log to disk
741da177e4SLinus Torvalds  */
751da177e4SLinus Torvalds #define XFS_LOG_SYNC		0x1
761da177e4SLinus Torvalds 
771da177e4SLinus Torvalds /* Log manager interfaces */
781da177e4SLinus Torvalds struct xfs_mount;
7935a8a72fSChristoph Hellwig struct xlog_in_core;
80cc09c0dcSDave Chinner struct xlog_ticket;
8143f5efc5SDave Chinner struct xfs_log_item;
8243f5efc5SDave Chinner struct xfs_item_ops;
83955833cfSDave Chinner struct xfs_trans;
840020a190SDave Chinner struct xlog;
8535a8a72fSChristoph Hellwig 
8660e5bb78SChristoph Hellwig int	  xfs_log_force(struct xfs_mount *mp, uint flags);
875f9b4b0dSDave Chinner int	  xfs_log_force_seq(struct xfs_mount *mp, xfs_csn_t seq, uint flags,
88a14a348bSChristoph Hellwig 		int *log_forced);
891da177e4SLinus Torvalds int	  xfs_log_mount(struct xfs_mount	*mp,
901da177e4SLinus Torvalds 			struct xfs_buftarg	*log_target,
911da177e4SLinus Torvalds 			xfs_daddr_t		start_block,
921da177e4SLinus Torvalds 			int		 	num_bblocks);
934249023aSChristoph Hellwig int	  xfs_log_mount_finish(struct xfs_mount *mp);
94a7a9250eSHariprasad Kelam void	xfs_log_mount_cancel(struct xfs_mount *);
9509a423a3SChristoph Hellwig xfs_lsn_t xlog_assign_tail_lsn(struct xfs_mount *mp);
961c304625SChristoph Hellwig xfs_lsn_t xlog_assign_tail_lsn_locked(struct xfs_mount *mp);
97cfb7cdcaSChristoph Hellwig void	xfs_log_space_wake(struct xfs_mount *mp);
98c7610dceSDave Chinner int	xfs_log_reserve(struct xfs_mount *mp, int length, int count,
99c7610dceSDave Chinner 			struct xlog_ticket **ticket, bool permanent);
1009006fb91SChristoph Hellwig int	xfs_log_regrant(struct xfs_mount *mp, struct xlog_ticket *tic);
10121b699c8SChristoph Hellwig void	xfs_log_unmount(struct xfs_mount *mp);
10250d25484SBrian Foster bool	xfs_log_writable(struct xfs_mount *mp);
1031da177e4SLinus Torvalds 
104cc09c0dcSDave Chinner struct xlog_ticket *xfs_log_ticket_get(struct xlog_ticket *ticket);
105cc09c0dcSDave Chinner void	  xfs_log_ticket_put(struct xlog_ticket *ticket);
106cc09c0dcSDave Chinner 
10712e6a0f4SChristoph Hellwig void	xlog_cil_process_committed(struct list_head *list);
108ccf7c23fSDave Chinner bool	xfs_log_item_in_current_chkpt(struct xfs_log_item *lip);
10971e330b5SDave Chinner 
110f661f1e0SDave Chinner void	xfs_log_work_queue(struct xfs_mount *mp);
111303591a0SBrian Foster int	xfs_log_quiesce(struct xfs_mount *mp);
1129e54ee0fSBrian Foster void	xfs_log_clean(struct xfs_mount *mp);
113a45086e2SBrian Foster bool	xfs_log_check_lsn(struct xfs_mount *, xfs_lsn_t);
114f661f1e0SDave Chinner 
115ed1575daSDarrick J. Wong xfs_lsn_t xlog_grant_push_threshold(struct xlog *log, int need_bytes);
116b36d4651SDave Chinner bool	  xlog_force_shutdown(struct xlog *log, int shutdown_flags);
117ed1575daSDarrick J. Wong 
1182b73a2c8SDarrick J. Wong void xlog_use_incompat_feat(struct xlog *log);
1192b73a2c8SDarrick J. Wong void xlog_drop_incompat_feat(struct xlog *log);
1202b73a2c8SDarrick J. Wong 
1211da177e4SLinus Torvalds #endif	/* __XFS_LOG_H__ */
122