xref: /openbmc/linux/fs/xfs/xfs_log.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
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 {
1216924853SDave Chinner 	struct list_head	lv_list;	/* CIL lv chain ptrs */
13*4eb56069SDave Chinner 	uint32_t		lv_order_id;	/* chain ordering info */
14fc06c6d0SDave Chinner 	int			lv_niovecs;	/* number of iovecs in lv */
15fc06c6d0SDave Chinner 	struct xfs_log_iovec	*lv_iovecp;	/* iovec array */
16fc06c6d0SDave Chinner 	struct xfs_log_item	*lv_item;	/* owner */
17fc06c6d0SDave Chinner 	char			*lv_buf;	/* formatted buffer */
18110dc24aSDave Chinner 	int			lv_bytes;	/* accounted space in buffer */
19110dc24aSDave Chinner 	int			lv_buf_len;	/* aligned size of buffer */
207492c5b4SDave Chinner 	int			lv_size;	/* size of allocated lv */
21fc06c6d0SDave Chinner };
221da177e4SLinus Torvalds 
23fc06c6d0SDave Chinner #define XFS_LOG_VEC_ORDERED	(-1)
24fc06c6d0SDave Chinner 
25b2c28035SDave Chinner /*
26b2c28035SDave Chinner  * Calculate the log iovec length for a given user buffer length. Intended to be
27b2c28035SDave Chinner  * used by ->iop_size implementations when sizing buffers of arbitrary
28b2c28035SDave Chinner  * alignments.
29b2c28035SDave Chinner  */
30b2c28035SDave Chinner static inline int
xlog_calc_iovec_len(int len)31b2c28035SDave Chinner xlog_calc_iovec_len(int len)
32b2c28035SDave Chinner {
33b2c28035SDave Chinner 	return roundup(len, sizeof(uint32_t));
34b2c28035SDave Chinner }
35b2c28035SDave Chinner 
368d547cf9SDave Chinner void *xlog_prepare_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp,
378d547cf9SDave Chinner 		uint type);
381234351cSChristoph Hellwig 
39bde7cff6SChristoph Hellwig static inline void
xlog_finish_iovec(struct xfs_log_vec * lv,struct xfs_log_iovec * vec,int data_len)40b2c28035SDave Chinner xlog_finish_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec *vec,
41b2c28035SDave Chinner 		int data_len)
42bde7cff6SChristoph Hellwig {
438d547cf9SDave Chinner 	struct xlog_op_header	*oph = vec->i_addr;
44b2c28035SDave Chinner 	int			len;
458d547cf9SDave Chinner 
46b2c28035SDave Chinner 	/*
47b2c28035SDave Chinner 	 * Always round up the length to the correct alignment so callers don't
48b2c28035SDave Chinner 	 * need to know anything about this log vec layout requirement. This
49b2c28035SDave Chinner 	 * means we have to zero the area the data to be written does not cover.
50b2c28035SDave Chinner 	 * This is complicated by fact the payload region is offset into the
51b2c28035SDave Chinner 	 * logvec region by the opheader that tracks the payload.
52b2c28035SDave Chinner 	 */
53b2c28035SDave Chinner 	len = xlog_calc_iovec_len(data_len);
54b2c28035SDave Chinner 	if (len - data_len != 0) {
55b2c28035SDave Chinner 		char	*buf = vec->i_addr + sizeof(struct xlog_op_header);
56b2c28035SDave Chinner 
57b2c28035SDave Chinner 		memset(buf + data_len, 0, len - data_len);
58b2c28035SDave Chinner 	}
59b2c28035SDave Chinner 
60b2c28035SDave Chinner 	/*
61b2c28035SDave Chinner 	 * The opheader tracks aligned payload length, whilst the logvec tracks
62b2c28035SDave Chinner 	 * the overall region length.
63b2c28035SDave Chinner 	 */
648d547cf9SDave Chinner 	oph->oh_len = cpu_to_be32(len);
658d547cf9SDave Chinner 
668d547cf9SDave Chinner 	len += sizeof(struct xlog_op_header);
673c352befSDave Chinner 	lv->lv_buf_len += len;
68110dc24aSDave Chinner 	lv->lv_bytes += len;
69bde7cff6SChristoph Hellwig 	vec->i_len = len;
70b2c28035SDave Chinner 
71b2c28035SDave Chinner 	/* Catch buffer overruns */
72b2c28035SDave Chinner 	ASSERT((void *)lv->lv_buf + lv->lv_bytes <= (void *)lv + lv->lv_size);
73bde7cff6SChristoph Hellwig }
74bde7cff6SChristoph Hellwig 
75b2c28035SDave Chinner /*
76b2c28035SDave Chinner  * Copy the amount of data requested by the caller into a new log iovec.
77b2c28035SDave Chinner  */
78bde7cff6SChristoph Hellwig static inline void *
xlog_copy_iovec(struct xfs_log_vec * lv,struct xfs_log_iovec ** vecp,uint type,void * data,int len)79bde7cff6SChristoph Hellwig xlog_copy_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp,
80bde7cff6SChristoph Hellwig 		uint type, void *data, int len)
81bde7cff6SChristoph Hellwig {
82bde7cff6SChristoph Hellwig 	void *buf;
83bde7cff6SChristoph Hellwig 
84bde7cff6SChristoph Hellwig 	buf = xlog_prepare_iovec(lv, vecp, type);
85bde7cff6SChristoph Hellwig 	memcpy(buf, data, len);
86bde7cff6SChristoph Hellwig 	xlog_finish_iovec(lv, *vecp, len);
87bde7cff6SChristoph Hellwig 	return buf;
88bde7cff6SChristoph Hellwig }
89bde7cff6SChristoph Hellwig 
904183e4f2SDarrick J. Wong static inline void *
xlog_copy_from_iovec(struct xfs_log_vec * lv,struct xfs_log_iovec ** vecp,const struct xfs_log_iovec * src)914183e4f2SDarrick J. Wong xlog_copy_from_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp,
924183e4f2SDarrick J. Wong 		const struct xfs_log_iovec *src)
934183e4f2SDarrick J. Wong {
944183e4f2SDarrick J. Wong 	return xlog_copy_iovec(lv, vecp, src->i_type, src->i_addr, src->i_len);
954183e4f2SDarrick J. Wong }
964183e4f2SDarrick J. Wong 
97fc06c6d0SDave Chinner /*
98c41564b5SNathan Scott  * By comparing each component, we don't have to worry about extra
991da177e4SLinus Torvalds  * endian issues in treating two 32 bit numbers as one 64 bit number
1001da177e4SLinus Torvalds  */
_lsn_cmp(xfs_lsn_t lsn1,xfs_lsn_t lsn2)101a1365647SAndrew Morton static inline xfs_lsn_t	_lsn_cmp(xfs_lsn_t lsn1, xfs_lsn_t lsn2)
1021da177e4SLinus Torvalds {
1031da177e4SLinus Torvalds 	if (CYCLE_LSN(lsn1) != CYCLE_LSN(lsn2))
1041da177e4SLinus Torvalds 		return (CYCLE_LSN(lsn1)<CYCLE_LSN(lsn2))? -999 : 999;
1051da177e4SLinus Torvalds 
1061da177e4SLinus Torvalds 	if (BLOCK_LSN(lsn1) != BLOCK_LSN(lsn2))
1071da177e4SLinus Torvalds 		return (BLOCK_LSN(lsn1)<BLOCK_LSN(lsn2))? -999 : 999;
1081da177e4SLinus Torvalds 
1091da177e4SLinus Torvalds 	return 0;
1101da177e4SLinus Torvalds }
1111da177e4SLinus Torvalds 
1121da177e4SLinus Torvalds #define	XFS_LSN_CMP(x,y) _lsn_cmp(x,y)
1131da177e4SLinus Torvalds 
1141da177e4SLinus Torvalds /*
1151da177e4SLinus Torvalds  * Flags to xfs_log_force()
1161da177e4SLinus Torvalds  *
1171da177e4SLinus Torvalds  *	XFS_LOG_SYNC:	Synchronous force in-core log to disk
1181da177e4SLinus Torvalds  */
1191da177e4SLinus Torvalds #define XFS_LOG_SYNC		0x1
1201da177e4SLinus Torvalds 
1211da177e4SLinus Torvalds /* Log manager interfaces */
1221da177e4SLinus Torvalds struct xfs_mount;
12335a8a72fSChristoph Hellwig struct xlog_in_core;
124cc09c0dcSDave Chinner struct xlog_ticket;
12543f5efc5SDave Chinner struct xfs_log_item;
12643f5efc5SDave Chinner struct xfs_item_ops;
127955833cfSDave Chinner struct xfs_trans;
1280020a190SDave Chinner struct xlog;
12935a8a72fSChristoph Hellwig 
13060e5bb78SChristoph Hellwig int	  xfs_log_force(struct xfs_mount *mp, uint flags);
1315f9b4b0dSDave Chinner int	  xfs_log_force_seq(struct xfs_mount *mp, xfs_csn_t seq, uint flags,
132a14a348bSChristoph Hellwig 		int *log_forced);
1331da177e4SLinus Torvalds int	  xfs_log_mount(struct xfs_mount	*mp,
1341da177e4SLinus Torvalds 			struct xfs_buftarg	*log_target,
1351da177e4SLinus Torvalds 			xfs_daddr_t		start_block,
1361da177e4SLinus Torvalds 			int		 	num_bblocks);
1374249023aSChristoph Hellwig int	  xfs_log_mount_finish(struct xfs_mount *mp);
138a7a9250eSHariprasad Kelam void	xfs_log_mount_cancel(struct xfs_mount *);
13909a423a3SChristoph Hellwig xfs_lsn_t xlog_assign_tail_lsn(struct xfs_mount *mp);
1401c304625SChristoph Hellwig xfs_lsn_t xlog_assign_tail_lsn_locked(struct xfs_mount *mp);
141cfb7cdcaSChristoph Hellwig void	xfs_log_space_wake(struct xfs_mount *mp);
142c7610dceSDave Chinner int	xfs_log_reserve(struct xfs_mount *mp, int length, int count,
143c7610dceSDave Chinner 			struct xlog_ticket **ticket, bool permanent);
1449006fb91SChristoph Hellwig int	xfs_log_regrant(struct xfs_mount *mp, struct xlog_ticket *tic);
14521b699c8SChristoph Hellwig void	xfs_log_unmount(struct xfs_mount *mp);
14650d25484SBrian Foster bool	xfs_log_writable(struct xfs_mount *mp);
1471da177e4SLinus Torvalds 
148cc09c0dcSDave Chinner struct xlog_ticket *xfs_log_ticket_get(struct xlog_ticket *ticket);
149cc09c0dcSDave Chinner void	  xfs_log_ticket_put(struct xlog_ticket *ticket);
150cc09c0dcSDave Chinner 
15112e6a0f4SChristoph Hellwig void	xlog_cil_process_committed(struct list_head *list);
152ccf7c23fSDave Chinner bool	xfs_log_item_in_current_chkpt(struct xfs_log_item *lip);
15371e330b5SDave Chinner 
154f661f1e0SDave Chinner void	xfs_log_work_queue(struct xfs_mount *mp);
155303591a0SBrian Foster int	xfs_log_quiesce(struct xfs_mount *mp);
1569e54ee0fSBrian Foster void	xfs_log_clean(struct xfs_mount *mp);
157a45086e2SBrian Foster bool	xfs_log_check_lsn(struct xfs_mount *, xfs_lsn_t);
158f661f1e0SDave Chinner 
159ed1575daSDarrick J. Wong xfs_lsn_t xlog_grant_push_threshold(struct xlog *log, int need_bytes);
1602eb7550dSDave Chinner bool	  xlog_force_shutdown(struct xlog *log, uint32_t shutdown_flags);
161ed1575daSDarrick J. Wong 
1622b73a2c8SDarrick J. Wong void xlog_use_incompat_feat(struct xlog *log);
1632b73a2c8SDarrick J. Wong void xlog_drop_incompat_feat(struct xlog *log);
164f3f36c89SAllison Henderson int xfs_attr_use_log_assist(struct xfs_mount *mp);
1652b73a2c8SDarrick J. Wong 
1661da177e4SLinus Torvalds #endif	/* __XFS_LOG_H__ */
167