xref: /openbmc/linux/fs/xfs/xfs_log.h (revision f661f1e0bf5002bdcc8b5810ad0a184a1841537f)
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 
211da177e4SLinus Torvalds /* get lsn fields */
221da177e4SLinus Torvalds #define CYCLE_LSN(lsn) ((uint)((lsn)>>32))
231da177e4SLinus Torvalds #define BLOCK_LSN(lsn) ((uint)(lsn))
24b53e675dSChristoph Hellwig 
251da177e4SLinus Torvalds /* this is used in a spot where we might otherwise double-endian-flip */
26b53e675dSChristoph Hellwig #define CYCLE_LSN_DISK(lsn) (((__be32 *)&(lsn))[0])
271da177e4SLinus Torvalds 
281da177e4SLinus Torvalds #ifdef __KERNEL__
291da177e4SLinus Torvalds /*
30c41564b5SNathan Scott  * By comparing each component, we don't have to worry about extra
311da177e4SLinus Torvalds  * endian issues in treating two 32 bit numbers as one 64 bit number
321da177e4SLinus Torvalds  */
33a1365647SAndrew Morton static inline xfs_lsn_t	_lsn_cmp(xfs_lsn_t lsn1, xfs_lsn_t lsn2)
341da177e4SLinus Torvalds {
351da177e4SLinus Torvalds 	if (CYCLE_LSN(lsn1) != CYCLE_LSN(lsn2))
361da177e4SLinus Torvalds 		return (CYCLE_LSN(lsn1)<CYCLE_LSN(lsn2))? -999 : 999;
371da177e4SLinus Torvalds 
381da177e4SLinus Torvalds 	if (BLOCK_LSN(lsn1) != BLOCK_LSN(lsn2))
391da177e4SLinus Torvalds 		return (BLOCK_LSN(lsn1)<BLOCK_LSN(lsn2))? -999 : 999;
401da177e4SLinus Torvalds 
411da177e4SLinus Torvalds 	return 0;
421da177e4SLinus Torvalds }
431da177e4SLinus Torvalds 
441da177e4SLinus Torvalds #define	XFS_LSN_CMP(x,y) _lsn_cmp(x,y)
451da177e4SLinus Torvalds 
461da177e4SLinus Torvalds /*
471da177e4SLinus Torvalds  * Macros, structures, prototypes for interface to the log manager.
481da177e4SLinus Torvalds  */
491da177e4SLinus Torvalds 
501da177e4SLinus Torvalds /*
511da177e4SLinus Torvalds  * Flags to xfs_log_done()
521da177e4SLinus Torvalds  */
531da177e4SLinus Torvalds #define XFS_LOG_REL_PERM_RESERV	0x1
541da177e4SLinus Torvalds 
551da177e4SLinus Torvalds /*
561da177e4SLinus Torvalds  * Flags to xfs_log_force()
571da177e4SLinus Torvalds  *
581da177e4SLinus Torvalds  *	XFS_LOG_SYNC:	Synchronous force in-core log to disk
591da177e4SLinus Torvalds  */
601da177e4SLinus Torvalds #define XFS_LOG_SYNC		0x1
611da177e4SLinus Torvalds 
621da177e4SLinus Torvalds #endif	/* __KERNEL__ */
631da177e4SLinus Torvalds 
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds /* Log Clients */
661da177e4SLinus Torvalds #define XFS_TRANSACTION		0x69
671da177e4SLinus Torvalds #define XFS_VOLUME		0x2
681da177e4SLinus Torvalds #define XFS_LOG			0xaa
691da177e4SLinus Torvalds 
707e9c6396STim Shimmin 
717e9c6396STim Shimmin /* Region types for iovec's i_type */
727e9c6396STim Shimmin #define XLOG_REG_TYPE_BFORMAT		1
737e9c6396STim Shimmin #define XLOG_REG_TYPE_BCHUNK		2
747e9c6396STim Shimmin #define XLOG_REG_TYPE_EFI_FORMAT	3
757e9c6396STim Shimmin #define XLOG_REG_TYPE_EFD_FORMAT	4
767e9c6396STim Shimmin #define XLOG_REG_TYPE_IFORMAT		5
777e9c6396STim Shimmin #define XLOG_REG_TYPE_ICORE		6
787e9c6396STim Shimmin #define XLOG_REG_TYPE_IEXT		7
797e9c6396STim Shimmin #define XLOG_REG_TYPE_IBROOT		8
807e9c6396STim Shimmin #define XLOG_REG_TYPE_ILOCAL		9
817e9c6396STim Shimmin #define XLOG_REG_TYPE_IATTR_EXT		10
827e9c6396STim Shimmin #define XLOG_REG_TYPE_IATTR_BROOT	11
837e9c6396STim Shimmin #define XLOG_REG_TYPE_IATTR_LOCAL	12
847e9c6396STim Shimmin #define XLOG_REG_TYPE_QFORMAT		13
857e9c6396STim Shimmin #define XLOG_REG_TYPE_DQUOT		14
867e9c6396STim Shimmin #define XLOG_REG_TYPE_QUOTAOFF		15
877e9c6396STim Shimmin #define XLOG_REG_TYPE_LRHEADER		16
887e9c6396STim Shimmin #define XLOG_REG_TYPE_UNMOUNT		17
897e9c6396STim Shimmin #define XLOG_REG_TYPE_COMMIT		18
907e9c6396STim Shimmin #define XLOG_REG_TYPE_TRANSHDR		19
917e9c6396STim Shimmin #define XLOG_REG_TYPE_MAX		19
927e9c6396STim Shimmin 
931da177e4SLinus Torvalds typedef struct xfs_log_iovec {
944e0d5f92SChristoph Hellwig 	void		*i_addr;	/* beginning address of region */
951da177e4SLinus Torvalds 	int		i_len;		/* length in bytes of region */
967e9c6396STim Shimmin 	uint		i_type;		/* type of region */
971da177e4SLinus Torvalds } xfs_log_iovec_t;
981da177e4SLinus Torvalds 
9955b66332SDave Chinner struct xfs_log_vec {
10055b66332SDave Chinner 	struct xfs_log_vec	*lv_next;	/* next lv in build list */
10155b66332SDave Chinner 	int			lv_niovecs;	/* number of iovecs in lv */
10255b66332SDave Chinner 	struct xfs_log_iovec	*lv_iovecp;	/* iovec array */
10371e330b5SDave Chinner 	struct xfs_log_item	*lv_item;	/* owner */
10471e330b5SDave Chinner 	char			*lv_buf;	/* formatted buffer */
10571e330b5SDave Chinner 	int			lv_buf_len;	/* size of formatted buffer */
10655b66332SDave Chinner };
10755b66332SDave Chinner 
1081da177e4SLinus Torvalds /*
1091da177e4SLinus Torvalds  * Structure used to pass callback function and the function's argument
1101da177e4SLinus Torvalds  * to the log manager.
1111da177e4SLinus Torvalds  */
1121da177e4SLinus Torvalds typedef struct xfs_log_callback {
1131da177e4SLinus Torvalds 	struct xfs_log_callback	*cb_next;
1141da177e4SLinus Torvalds 	void			(*cb_func)(void *, int);
1151da177e4SLinus Torvalds 	void			*cb_arg;
1161da177e4SLinus Torvalds } xfs_log_callback_t;
1171da177e4SLinus Torvalds 
1181da177e4SLinus Torvalds 
1191da177e4SLinus Torvalds #ifdef __KERNEL__
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;
12743f5efc5SDave Chinner 
12843f5efc5SDave Chinner void	xfs_log_item_init(struct xfs_mount	*mp,
12943f5efc5SDave Chinner 			struct xfs_log_item	*item,
13043f5efc5SDave Chinner 			int			type,
131272e42b2SChristoph Hellwig 			const struct xfs_item_ops *ops);
13235a8a72fSChristoph Hellwig 
1331da177e4SLinus Torvalds xfs_lsn_t xfs_log_done(struct xfs_mount *mp,
13435a8a72fSChristoph Hellwig 		       struct xlog_ticket *ticket,
13535a8a72fSChristoph Hellwig 		       struct xlog_in_core **iclog,
1361da177e4SLinus Torvalds 		       uint		flags);
137f538d4daSChristoph Hellwig int	  _xfs_log_force(struct xfs_mount *mp,
138f538d4daSChristoph Hellwig 			 uint		flags,
139f538d4daSChristoph Hellwig 			 int		*log_forced);
140b911ca04SDavid Chinner void	  xfs_log_force(struct xfs_mount	*mp,
141a14a348bSChristoph Hellwig 			uint			flags);
142a14a348bSChristoph Hellwig int	  _xfs_log_force_lsn(struct xfs_mount *mp,
143a14a348bSChristoph Hellwig 			     xfs_lsn_t		lsn,
144a14a348bSChristoph Hellwig 			     uint		flags,
145a14a348bSChristoph Hellwig 			     int		*log_forced);
146a14a348bSChristoph Hellwig void	  xfs_log_force_lsn(struct xfs_mount	*mp,
147b911ca04SDavid Chinner 			    xfs_lsn_t		lsn,
148b911ca04SDavid Chinner 			    uint		flags);
1491da177e4SLinus Torvalds int	  xfs_log_mount(struct xfs_mount	*mp,
1501da177e4SLinus Torvalds 			struct xfs_buftarg	*log_target,
1511da177e4SLinus Torvalds 			xfs_daddr_t		start_block,
1521da177e4SLinus Torvalds 			int		 	num_bblocks);
1534249023aSChristoph Hellwig int	  xfs_log_mount_finish(struct xfs_mount *mp);
15409a423a3SChristoph Hellwig xfs_lsn_t xlog_assign_tail_lsn(struct xfs_mount *mp);
1551c304625SChristoph Hellwig xfs_lsn_t xlog_assign_tail_lsn_locked(struct xfs_mount *mp);
156cfb7cdcaSChristoph Hellwig void	  xfs_log_space_wake(struct xfs_mount *mp);
1571da177e4SLinus Torvalds int	  xfs_log_notify(struct xfs_mount	*mp,
15835a8a72fSChristoph Hellwig 			 struct xlog_in_core	*iclog,
1591da177e4SLinus Torvalds 			 xfs_log_callback_t	*callback_entry);
1601da177e4SLinus Torvalds int	  xfs_log_release_iclog(struct xfs_mount *mp,
16135a8a72fSChristoph Hellwig 			 struct xlog_in_core	 *iclog);
1621da177e4SLinus Torvalds int	  xfs_log_reserve(struct xfs_mount *mp,
1631da177e4SLinus Torvalds 			  int		   length,
1641da177e4SLinus Torvalds 			  int		   count,
16535a8a72fSChristoph Hellwig 			  struct xlog_ticket **ticket,
1661da177e4SLinus Torvalds 			  __uint8_t	   clientid,
1679006fb91SChristoph Hellwig 			  bool		   permanent,
1687e9c6396STim Shimmin 			  uint		   t_type);
1699006fb91SChristoph Hellwig int	  xfs_log_regrant(struct xfs_mount *mp, struct xlog_ticket *tic);
1701da177e4SLinus Torvalds int	  xfs_log_unmount_write(struct xfs_mount *mp);
17121b699c8SChristoph Hellwig void      xfs_log_unmount(struct xfs_mount *mp);
1721da177e4SLinus Torvalds int	  xfs_log_force_umount(struct xfs_mount *mp, int logerror);
1731da177e4SLinus Torvalds int	  xfs_log_need_covered(struct xfs_mount *mp);
1741da177e4SLinus Torvalds 
1751da177e4SLinus Torvalds void	  xlog_iodone(struct xfs_buf *);
1761da177e4SLinus Torvalds 
177cc09c0dcSDave Chinner struct xlog_ticket *xfs_log_ticket_get(struct xlog_ticket *ticket);
178cc09c0dcSDave Chinner void	  xfs_log_ticket_put(struct xlog_ticket *ticket);
179cc09c0dcSDave Chinner 
1800244b960SChristoph Hellwig int	xfs_log_commit_cil(struct xfs_mount *mp, struct xfs_trans *tp,
18171e330b5SDave Chinner 				xfs_lsn_t *commit_lsn, int flags);
182ccf7c23fSDave Chinner bool	xfs_log_item_in_current_chkpt(struct xfs_log_item *lip);
18371e330b5SDave Chinner 
184*f661f1e0SDave Chinner void	xfs_log_work_queue(struct xfs_mount *mp);
185*f661f1e0SDave Chinner void	xfs_log_worker(struct work_struct *work);
186*f661f1e0SDave Chinner 
1871da177e4SLinus Torvalds #endif
1881da177e4SLinus Torvalds #endif	/* __XFS_LOG_H__ */
189