xref: /openbmc/linux/fs/xfs/xfs_log.h (revision f3f36c893f260275eb9229cdc3dabb4c79650591)
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 
89fc06c6d0SDave Chinner /*
90c41564b5SNathan Scott  * By comparing each component, we don't have to worry about extra
911da177e4SLinus Torvalds  * endian issues in treating two 32 bit numbers as one 64 bit number
921da177e4SLinus Torvalds  */
93a1365647SAndrew Morton static inline xfs_lsn_t	_lsn_cmp(xfs_lsn_t lsn1, xfs_lsn_t lsn2)
941da177e4SLinus Torvalds {
951da177e4SLinus Torvalds 	if (CYCLE_LSN(lsn1) != CYCLE_LSN(lsn2))
961da177e4SLinus Torvalds 		return (CYCLE_LSN(lsn1)<CYCLE_LSN(lsn2))? -999 : 999;
971da177e4SLinus Torvalds 
981da177e4SLinus Torvalds 	if (BLOCK_LSN(lsn1) != BLOCK_LSN(lsn2))
991da177e4SLinus Torvalds 		return (BLOCK_LSN(lsn1)<BLOCK_LSN(lsn2))? -999 : 999;
1001da177e4SLinus Torvalds 
1011da177e4SLinus Torvalds 	return 0;
1021da177e4SLinus Torvalds }
1031da177e4SLinus Torvalds 
1041da177e4SLinus Torvalds #define	XFS_LSN_CMP(x,y) _lsn_cmp(x,y)
1051da177e4SLinus Torvalds 
1061da177e4SLinus Torvalds /*
1071da177e4SLinus Torvalds  * Flags to xfs_log_force()
1081da177e4SLinus Torvalds  *
1091da177e4SLinus Torvalds  *	XFS_LOG_SYNC:	Synchronous force in-core log to disk
1101da177e4SLinus Torvalds  */
1111da177e4SLinus Torvalds #define XFS_LOG_SYNC		0x1
1121da177e4SLinus Torvalds 
1131da177e4SLinus Torvalds /* Log manager interfaces */
1141da177e4SLinus Torvalds struct xfs_mount;
11535a8a72fSChristoph Hellwig struct xlog_in_core;
116cc09c0dcSDave Chinner struct xlog_ticket;
11743f5efc5SDave Chinner struct xfs_log_item;
11843f5efc5SDave Chinner struct xfs_item_ops;
119955833cfSDave Chinner struct xfs_trans;
1200020a190SDave Chinner struct xlog;
12135a8a72fSChristoph Hellwig 
12260e5bb78SChristoph Hellwig int	  xfs_log_force(struct xfs_mount *mp, uint flags);
1235f9b4b0dSDave Chinner int	  xfs_log_force_seq(struct xfs_mount *mp, xfs_csn_t seq, uint flags,
124a14a348bSChristoph Hellwig 		int *log_forced);
1251da177e4SLinus Torvalds int	  xfs_log_mount(struct xfs_mount	*mp,
1261da177e4SLinus Torvalds 			struct xfs_buftarg	*log_target,
1271da177e4SLinus Torvalds 			xfs_daddr_t		start_block,
1281da177e4SLinus Torvalds 			int		 	num_bblocks);
1294249023aSChristoph Hellwig int	  xfs_log_mount_finish(struct xfs_mount *mp);
130a7a9250eSHariprasad Kelam void	xfs_log_mount_cancel(struct xfs_mount *);
13109a423a3SChristoph Hellwig xfs_lsn_t xlog_assign_tail_lsn(struct xfs_mount *mp);
1321c304625SChristoph Hellwig xfs_lsn_t xlog_assign_tail_lsn_locked(struct xfs_mount *mp);
133cfb7cdcaSChristoph Hellwig void	xfs_log_space_wake(struct xfs_mount *mp);
134c7610dceSDave Chinner int	xfs_log_reserve(struct xfs_mount *mp, int length, int count,
135c7610dceSDave Chinner 			struct xlog_ticket **ticket, bool permanent);
1369006fb91SChristoph Hellwig int	xfs_log_regrant(struct xfs_mount *mp, struct xlog_ticket *tic);
13721b699c8SChristoph Hellwig void	xfs_log_unmount(struct xfs_mount *mp);
13850d25484SBrian Foster bool	xfs_log_writable(struct xfs_mount *mp);
1391da177e4SLinus Torvalds 
140cc09c0dcSDave Chinner struct xlog_ticket *xfs_log_ticket_get(struct xlog_ticket *ticket);
141cc09c0dcSDave Chinner void	  xfs_log_ticket_put(struct xlog_ticket *ticket);
142cc09c0dcSDave Chinner 
14312e6a0f4SChristoph Hellwig void	xlog_cil_process_committed(struct list_head *list);
144ccf7c23fSDave Chinner bool	xfs_log_item_in_current_chkpt(struct xfs_log_item *lip);
14571e330b5SDave Chinner 
146f661f1e0SDave Chinner void	xfs_log_work_queue(struct xfs_mount *mp);
147303591a0SBrian Foster int	xfs_log_quiesce(struct xfs_mount *mp);
1489e54ee0fSBrian Foster void	xfs_log_clean(struct xfs_mount *mp);
149a45086e2SBrian Foster bool	xfs_log_check_lsn(struct xfs_mount *, xfs_lsn_t);
150f661f1e0SDave Chinner 
151ed1575daSDarrick J. Wong xfs_lsn_t xlog_grant_push_threshold(struct xlog *log, int need_bytes);
1522eb7550dSDave Chinner bool	  xlog_force_shutdown(struct xlog *log, uint32_t shutdown_flags);
153ed1575daSDarrick J. Wong 
1542b73a2c8SDarrick J. Wong void xlog_use_incompat_feat(struct xlog *log);
1552b73a2c8SDarrick J. Wong void xlog_drop_incompat_feat(struct xlog *log);
156*f3f36c89SAllison Henderson int xfs_attr_use_log_assist(struct xfs_mount *mp);
1572b73a2c8SDarrick J. Wong 
1581da177e4SLinus Torvalds #endif	/* __XFS_LOG_H__ */
159