xref: /openbmc/linux/fs/xfs/xfs_log.h (revision c8ce540db5f67d254aafb14b5d76422c62a906df)
11da177e4SLinus Torvalds /*
27b718769SNathan Scott  * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
37b718769SNathan Scott  * All Rights Reserved.
41da177e4SLinus Torvalds  *
57b718769SNathan Scott  * This program is free software; you can redistribute it and/or
67b718769SNathan Scott  * modify it under the terms of the GNU General Public License as
71da177e4SLinus Torvalds  * published by the Free Software Foundation.
81da177e4SLinus Torvalds  *
97b718769SNathan Scott  * This program is distributed in the hope that it would be useful,
107b718769SNathan Scott  * but WITHOUT ANY WARRANTY; without even the implied warranty of
117b718769SNathan Scott  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
127b718769SNathan Scott  * GNU General Public License for more details.
131da177e4SLinus Torvalds  *
147b718769SNathan Scott  * You should have received a copy of the GNU General Public License
157b718769SNathan Scott  * along with this program; if not, write the Free Software Foundation,
167b718769SNathan Scott  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
171da177e4SLinus Torvalds  */
181da177e4SLinus Torvalds #ifndef	__XFS_LOG_H__
191da177e4SLinus Torvalds #define __XFS_LOG_H__
201da177e4SLinus Torvalds 
21fc06c6d0SDave Chinner struct xfs_log_vec {
22fc06c6d0SDave Chinner 	struct xfs_log_vec	*lv_next;	/* next lv in build list */
23fc06c6d0SDave Chinner 	int			lv_niovecs;	/* number of iovecs in lv */
24fc06c6d0SDave Chinner 	struct xfs_log_iovec	*lv_iovecp;	/* iovec array */
25fc06c6d0SDave Chinner 	struct xfs_log_item	*lv_item;	/* owner */
26fc06c6d0SDave Chinner 	char			*lv_buf;	/* formatted buffer */
27110dc24aSDave Chinner 	int			lv_bytes;	/* accounted space in buffer */
28110dc24aSDave Chinner 	int			lv_buf_len;	/* aligned size of buffer */
297492c5b4SDave Chinner 	int			lv_size;	/* size of allocated lv */
30fc06c6d0SDave Chinner };
311da177e4SLinus Torvalds 
32fc06c6d0SDave Chinner #define XFS_LOG_VEC_ORDERED	(-1)
33fc06c6d0SDave Chinner 
341234351cSChristoph Hellwig static inline void *
35bde7cff6SChristoph Hellwig xlog_prepare_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp,
36bde7cff6SChristoph Hellwig 		uint type)
371234351cSChristoph Hellwig {
381234351cSChristoph Hellwig 	struct xfs_log_iovec *vec = *vecp;
391234351cSChristoph Hellwig 
40bde7cff6SChristoph Hellwig 	if (vec) {
41bde7cff6SChristoph Hellwig 		ASSERT(vec - lv->lv_iovecp < lv->lv_niovecs);
42bde7cff6SChristoph Hellwig 		vec++;
43bde7cff6SChristoph Hellwig 	} else {
44bde7cff6SChristoph Hellwig 		vec = &lv->lv_iovecp[0];
45bde7cff6SChristoph Hellwig 	}
461234351cSChristoph Hellwig 
47bde7cff6SChristoph Hellwig 	vec->i_type = type;
48bde7cff6SChristoph Hellwig 	vec->i_addr = lv->lv_buf + lv->lv_buf_len;
49bde7cff6SChristoph Hellwig 
50bde7cff6SChristoph Hellwig 	ASSERT(IS_ALIGNED((unsigned long)vec->i_addr, sizeof(uint64_t)));
51bde7cff6SChristoph Hellwig 
52bde7cff6SChristoph Hellwig 	*vecp = vec;
531234351cSChristoph Hellwig 	return vec->i_addr;
541234351cSChristoph Hellwig }
551234351cSChristoph Hellwig 
56110dc24aSDave Chinner /*
57110dc24aSDave Chinner  * We need to make sure the next buffer is naturally aligned for the biggest
58110dc24aSDave Chinner  * basic data type we put into it.  We already accounted for this padding when
59110dc24aSDave Chinner  * sizing the buffer.
60110dc24aSDave Chinner  *
61110dc24aSDave Chinner  * However, this padding does not get written into the log, and hence we have to
62110dc24aSDave Chinner  * track the space used by the log vectors separately to prevent log space hangs
63110dc24aSDave Chinner  * due to inaccurate accounting (i.e. a leak) of the used log space through the
64110dc24aSDave Chinner  * CIL context ticket.
65110dc24aSDave Chinner  */
66bde7cff6SChristoph Hellwig static inline void
67bde7cff6SChristoph Hellwig xlog_finish_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec *vec, int len)
68bde7cff6SChristoph Hellwig {
69bde7cff6SChristoph Hellwig 	lv->lv_buf_len += round_up(len, sizeof(uint64_t));
70110dc24aSDave Chinner 	lv->lv_bytes += len;
71bde7cff6SChristoph Hellwig 	vec->i_len = len;
72bde7cff6SChristoph Hellwig }
73bde7cff6SChristoph Hellwig 
74bde7cff6SChristoph Hellwig static inline void *
75bde7cff6SChristoph Hellwig xlog_copy_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp,
76bde7cff6SChristoph Hellwig 		uint type, void *data, int len)
77bde7cff6SChristoph Hellwig {
78bde7cff6SChristoph Hellwig 	void *buf;
79bde7cff6SChristoph Hellwig 
80bde7cff6SChristoph Hellwig 	buf = xlog_prepare_iovec(lv, vecp, type);
81bde7cff6SChristoph Hellwig 	memcpy(buf, data, len);
82bde7cff6SChristoph Hellwig 	xlog_finish_iovec(lv, *vecp, len);
83bde7cff6SChristoph Hellwig 	return buf;
84bde7cff6SChristoph Hellwig }
85bde7cff6SChristoph Hellwig 
86fc06c6d0SDave Chinner /*
87fc06c6d0SDave Chinner  * Structure used to pass callback function and the function's argument
88fc06c6d0SDave Chinner  * to the log manager.
89fc06c6d0SDave Chinner  */
90fc06c6d0SDave Chinner typedef struct xfs_log_callback {
91fc06c6d0SDave Chinner 	struct xfs_log_callback	*cb_next;
92fc06c6d0SDave Chinner 	void			(*cb_func)(void *, int);
93fc06c6d0SDave Chinner 	void			*cb_arg;
94fc06c6d0SDave Chinner } xfs_log_callback_t;
95fc06c6d0SDave Chinner 
961da177e4SLinus Torvalds /*
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;
12735a8a72fSChristoph Hellwig 
1281da177e4SLinus Torvalds xfs_lsn_t xfs_log_done(struct xfs_mount *mp,
12935a8a72fSChristoph Hellwig 		       struct xlog_ticket *ticket,
13035a8a72fSChristoph Hellwig 		       struct xlog_in_core **iclog,
131f78c3901SChristoph Hellwig 		       bool regrant);
132f538d4daSChristoph Hellwig int	  _xfs_log_force(struct xfs_mount *mp,
133f538d4daSChristoph Hellwig 			 uint		flags,
134f538d4daSChristoph Hellwig 			 int		*log_forced);
135b911ca04SDavid Chinner void	  xfs_log_force(struct xfs_mount	*mp,
136a14a348bSChristoph Hellwig 			uint			flags);
137a14a348bSChristoph Hellwig int	  _xfs_log_force_lsn(struct xfs_mount *mp,
138a14a348bSChristoph Hellwig 			     xfs_lsn_t		lsn,
139a14a348bSChristoph Hellwig 			     uint		flags,
140a14a348bSChristoph Hellwig 			     int		*log_forced);
141a14a348bSChristoph Hellwig void	  xfs_log_force_lsn(struct xfs_mount	*mp,
142b911ca04SDavid Chinner 			    xfs_lsn_t		lsn,
143b911ca04SDavid Chinner 			    uint		flags);
1441da177e4SLinus Torvalds int	  xfs_log_mount(struct xfs_mount	*mp,
1451da177e4SLinus Torvalds 			struct xfs_buftarg	*log_target,
1461da177e4SLinus Torvalds 			xfs_daddr_t		start_block,
1471da177e4SLinus Torvalds 			int		 	num_bblocks);
1484249023aSChristoph Hellwig int	  xfs_log_mount_finish(struct xfs_mount *mp);
149f0b2efadSBrian Foster int	xfs_log_mount_cancel(struct xfs_mount *);
15009a423a3SChristoph Hellwig xfs_lsn_t xlog_assign_tail_lsn(struct xfs_mount *mp);
1511c304625SChristoph Hellwig xfs_lsn_t xlog_assign_tail_lsn_locked(struct xfs_mount *mp);
152cfb7cdcaSChristoph Hellwig void	  xfs_log_space_wake(struct xfs_mount *mp);
1531da177e4SLinus Torvalds int	  xfs_log_notify(struct xfs_mount	*mp,
15435a8a72fSChristoph Hellwig 			 struct xlog_in_core	*iclog,
155239880efSDave Chinner 			 struct xfs_log_callback *callback_entry);
1561da177e4SLinus Torvalds int	  xfs_log_release_iclog(struct xfs_mount *mp,
15735a8a72fSChristoph Hellwig 			 struct xlog_in_core	 *iclog);
1581da177e4SLinus Torvalds int	  xfs_log_reserve(struct xfs_mount *mp,
1591da177e4SLinus Torvalds 			  int		   length,
1601da177e4SLinus Torvalds 			  int		   count,
16135a8a72fSChristoph Hellwig 			  struct xlog_ticket **ticket,
162*c8ce540dSDarrick J. Wong 			  uint8_t		   clientid,
163710b1e2cSChristoph Hellwig 			  bool		   permanent);
1649006fb91SChristoph Hellwig int	  xfs_log_regrant(struct xfs_mount *mp, struct xlog_ticket *tic);
16521b699c8SChristoph Hellwig void      xfs_log_unmount(struct xfs_mount *mp);
1661da177e4SLinus Torvalds int	  xfs_log_force_umount(struct xfs_mount *mp, int logerror);
1671da177e4SLinus Torvalds 
168cc09c0dcSDave Chinner struct xlog_ticket *xfs_log_ticket_get(struct xlog_ticket *ticket);
169cc09c0dcSDave Chinner void	  xfs_log_ticket_put(struct xlog_ticket *ticket);
170cc09c0dcSDave Chinner 
171c6f97264SJie Liu void	xfs_log_commit_cil(struct xfs_mount *mp, struct xfs_trans *tp,
17270393313SChristoph Hellwig 				xfs_lsn_t *commit_lsn, bool regrant);
173ccf7c23fSDave Chinner bool	xfs_log_item_in_current_chkpt(struct xfs_log_item *lip);
17471e330b5SDave Chinner 
175f661f1e0SDave Chinner void	xfs_log_work_queue(struct xfs_mount *mp);
176c75921a7SDave Chinner void	xfs_log_quiesce(struct xfs_mount *mp);
177a45086e2SBrian Foster bool	xfs_log_check_lsn(struct xfs_mount *, xfs_lsn_t);
178f661f1e0SDave Chinner 
1791da177e4SLinus Torvalds #endif	/* __XFS_LOG_H__ */
180