xref: /openbmc/linux/fs/xfs/xfs_log.h (revision 09a423a3d6c70905f1090f01aadb8e6abff527ce)
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_reserve()
571da177e4SLinus Torvalds  *
581da177e4SLinus Torvalds  *	XFS_LOG_PERM_RESERV: Permanent reservation.  When writes are
591da177e4SLinus Torvalds  *		performed against this type of reservation, the reservation
601da177e4SLinus Torvalds  *		is not decreased.  Long running transactions should use this.
611da177e4SLinus Torvalds  */
621da177e4SLinus Torvalds #define XFS_LOG_PERM_RESERV	0x2
631da177e4SLinus Torvalds 
641da177e4SLinus Torvalds /*
651da177e4SLinus Torvalds  * Flags to xfs_log_force()
661da177e4SLinus Torvalds  *
671da177e4SLinus Torvalds  *	XFS_LOG_SYNC:	Synchronous force in-core log to disk
681da177e4SLinus Torvalds  */
691da177e4SLinus Torvalds #define XFS_LOG_SYNC		0x1
701da177e4SLinus Torvalds 
711da177e4SLinus Torvalds #endif	/* __KERNEL__ */
721da177e4SLinus Torvalds 
731da177e4SLinus Torvalds 
741da177e4SLinus Torvalds /* Log Clients */
751da177e4SLinus Torvalds #define XFS_TRANSACTION		0x69
761da177e4SLinus Torvalds #define XFS_VOLUME		0x2
771da177e4SLinus Torvalds #define XFS_LOG			0xaa
781da177e4SLinus Torvalds 
797e9c6396STim Shimmin 
807e9c6396STim Shimmin /* Region types for iovec's i_type */
817e9c6396STim Shimmin #define XLOG_REG_TYPE_BFORMAT		1
827e9c6396STim Shimmin #define XLOG_REG_TYPE_BCHUNK		2
837e9c6396STim Shimmin #define XLOG_REG_TYPE_EFI_FORMAT	3
847e9c6396STim Shimmin #define XLOG_REG_TYPE_EFD_FORMAT	4
857e9c6396STim Shimmin #define XLOG_REG_TYPE_IFORMAT		5
867e9c6396STim Shimmin #define XLOG_REG_TYPE_ICORE		6
877e9c6396STim Shimmin #define XLOG_REG_TYPE_IEXT		7
887e9c6396STim Shimmin #define XLOG_REG_TYPE_IBROOT		8
897e9c6396STim Shimmin #define XLOG_REG_TYPE_ILOCAL		9
907e9c6396STim Shimmin #define XLOG_REG_TYPE_IATTR_EXT		10
917e9c6396STim Shimmin #define XLOG_REG_TYPE_IATTR_BROOT	11
927e9c6396STim Shimmin #define XLOG_REG_TYPE_IATTR_LOCAL	12
937e9c6396STim Shimmin #define XLOG_REG_TYPE_QFORMAT		13
947e9c6396STim Shimmin #define XLOG_REG_TYPE_DQUOT		14
957e9c6396STim Shimmin #define XLOG_REG_TYPE_QUOTAOFF		15
967e9c6396STim Shimmin #define XLOG_REG_TYPE_LRHEADER		16
977e9c6396STim Shimmin #define XLOG_REG_TYPE_UNMOUNT		17
987e9c6396STim Shimmin #define XLOG_REG_TYPE_COMMIT		18
997e9c6396STim Shimmin #define XLOG_REG_TYPE_TRANSHDR		19
1007e9c6396STim Shimmin #define XLOG_REG_TYPE_MAX		19
1017e9c6396STim Shimmin 
1021da177e4SLinus Torvalds typedef struct xfs_log_iovec {
1034e0d5f92SChristoph Hellwig 	void		*i_addr;	/* beginning address of region */
1041da177e4SLinus Torvalds 	int		i_len;		/* length in bytes of region */
1057e9c6396STim Shimmin 	uint		i_type;		/* type of region */
1061da177e4SLinus Torvalds } xfs_log_iovec_t;
1071da177e4SLinus Torvalds 
10855b66332SDave Chinner struct xfs_log_vec {
10955b66332SDave Chinner 	struct xfs_log_vec	*lv_next;	/* next lv in build list */
11055b66332SDave Chinner 	int			lv_niovecs;	/* number of iovecs in lv */
11155b66332SDave Chinner 	struct xfs_log_iovec	*lv_iovecp;	/* iovec array */
11271e330b5SDave Chinner 	struct xfs_log_item	*lv_item;	/* owner */
11371e330b5SDave Chinner 	char			*lv_buf;	/* formatted buffer */
11471e330b5SDave Chinner 	int			lv_buf_len;	/* size of formatted buffer */
11555b66332SDave Chinner };
11655b66332SDave Chinner 
1171da177e4SLinus Torvalds /*
1181da177e4SLinus Torvalds  * Structure used to pass callback function and the function's argument
1191da177e4SLinus Torvalds  * to the log manager.
1201da177e4SLinus Torvalds  */
1211da177e4SLinus Torvalds typedef struct xfs_log_callback {
1221da177e4SLinus Torvalds 	struct xfs_log_callback	*cb_next;
1231da177e4SLinus Torvalds 	void			(*cb_func)(void *, int);
1241da177e4SLinus Torvalds 	void			*cb_arg;
1251da177e4SLinus Torvalds } xfs_log_callback_t;
1261da177e4SLinus Torvalds 
1271da177e4SLinus Torvalds 
1281da177e4SLinus Torvalds #ifdef __KERNEL__
1291da177e4SLinus Torvalds /* Log manager interfaces */
1301da177e4SLinus Torvalds struct xfs_mount;
13135a8a72fSChristoph Hellwig struct xlog_in_core;
132cc09c0dcSDave Chinner struct xlog_ticket;
13343f5efc5SDave Chinner struct xfs_log_item;
13443f5efc5SDave Chinner struct xfs_item_ops;
135955833cfSDave Chinner struct xfs_trans;
13643f5efc5SDave Chinner 
13743f5efc5SDave Chinner void	xfs_log_item_init(struct xfs_mount	*mp,
13843f5efc5SDave Chinner 			struct xfs_log_item	*item,
13943f5efc5SDave Chinner 			int			type,
140272e42b2SChristoph Hellwig 			const struct xfs_item_ops *ops);
14135a8a72fSChristoph Hellwig 
1421da177e4SLinus Torvalds xfs_lsn_t xfs_log_done(struct xfs_mount *mp,
14335a8a72fSChristoph Hellwig 		       struct xlog_ticket *ticket,
14435a8a72fSChristoph Hellwig 		       struct xlog_in_core **iclog,
1451da177e4SLinus Torvalds 		       uint		flags);
146f538d4daSChristoph Hellwig int	  _xfs_log_force(struct xfs_mount *mp,
147f538d4daSChristoph Hellwig 			 uint		flags,
148f538d4daSChristoph Hellwig 			 int		*log_forced);
149b911ca04SDavid Chinner void	  xfs_log_force(struct xfs_mount	*mp,
150a14a348bSChristoph Hellwig 			uint			flags);
151a14a348bSChristoph Hellwig int	  _xfs_log_force_lsn(struct xfs_mount *mp,
152a14a348bSChristoph Hellwig 			     xfs_lsn_t		lsn,
153a14a348bSChristoph Hellwig 			     uint		flags,
154a14a348bSChristoph Hellwig 			     int		*log_forced);
155a14a348bSChristoph Hellwig void	  xfs_log_force_lsn(struct xfs_mount	*mp,
156b911ca04SDavid Chinner 			    xfs_lsn_t		lsn,
157b911ca04SDavid Chinner 			    uint		flags);
1581da177e4SLinus Torvalds int	  xfs_log_mount(struct xfs_mount	*mp,
1591da177e4SLinus Torvalds 			struct xfs_buftarg	*log_target,
1601da177e4SLinus Torvalds 			xfs_daddr_t		start_block,
1611da177e4SLinus Torvalds 			int		 	num_bblocks);
1624249023aSChristoph Hellwig int	  xfs_log_mount_finish(struct xfs_mount *mp);
163*09a423a3SChristoph Hellwig xfs_lsn_t xlog_assign_tail_lsn(struct xfs_mount *mp);
164*09a423a3SChristoph Hellwig void	  xfs_log_space_wake(struct xfs_mount	*mp,
165*09a423a3SChristoph Hellwig 			     bool		opportunistic);
1661da177e4SLinus Torvalds int	  xfs_log_notify(struct xfs_mount	*mp,
16735a8a72fSChristoph Hellwig 			 struct xlog_in_core	*iclog,
1681da177e4SLinus Torvalds 			 xfs_log_callback_t	*callback_entry);
1691da177e4SLinus Torvalds int	  xfs_log_release_iclog(struct xfs_mount *mp,
17035a8a72fSChristoph Hellwig 			 struct xlog_in_core	 *iclog);
1711da177e4SLinus Torvalds int	  xfs_log_reserve(struct xfs_mount *mp,
1721da177e4SLinus Torvalds 			  int		   length,
1731da177e4SLinus Torvalds 			  int		   count,
17435a8a72fSChristoph Hellwig 			  struct xlog_ticket **ticket,
1751da177e4SLinus Torvalds 			  __uint8_t	   clientid,
1767e9c6396STim Shimmin 			  uint		   flags,
1777e9c6396STim Shimmin 			  uint		   t_type);
1781da177e4SLinus Torvalds int	  xfs_log_unmount_write(struct xfs_mount *mp);
17921b699c8SChristoph Hellwig void      xfs_log_unmount(struct xfs_mount *mp);
1801da177e4SLinus Torvalds int	  xfs_log_force_umount(struct xfs_mount *mp, int logerror);
1811da177e4SLinus Torvalds int	  xfs_log_need_covered(struct xfs_mount *mp);
1821da177e4SLinus Torvalds 
1831da177e4SLinus Torvalds void	  xlog_iodone(struct xfs_buf *);
1841da177e4SLinus Torvalds 
185cc09c0dcSDave Chinner struct xlog_ticket *xfs_log_ticket_get(struct xlog_ticket *ticket);
186cc09c0dcSDave Chinner void	  xfs_log_ticket_put(struct xlog_ticket *ticket);
187cc09c0dcSDave Chinner 
1880244b960SChristoph Hellwig int	xfs_log_commit_cil(struct xfs_mount *mp, struct xfs_trans *tp,
18971e330b5SDave Chinner 				xfs_lsn_t *commit_lsn, int flags);
190ccf7c23fSDave Chinner bool	xfs_log_item_in_current_chkpt(struct xfs_log_item *lip);
19171e330b5SDave Chinner 
1921da177e4SLinus Torvalds #endif
1931da177e4SLinus Torvalds #endif	/* __XFS_LOG_H__ */
194