xref: /openbmc/linux/fs/xfs/xfs_log.h (revision ccf7c23fc129e75ef60e6f59f60a485b7a056598)
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_SLEEP:	 If space is not available, sleep (default)
591da177e4SLinus Torvalds  *	XFS_LOG_NOSLEEP: If space is not available, return error
601da177e4SLinus Torvalds  *	XFS_LOG_PERM_RESERV: Permanent reservation.  When writes are
611da177e4SLinus Torvalds  *		performed against this type of reservation, the reservation
621da177e4SLinus Torvalds  *		is not decreased.  Long running transactions should use this.
631da177e4SLinus Torvalds  */
641da177e4SLinus Torvalds #define XFS_LOG_SLEEP		0x0
651da177e4SLinus Torvalds #define XFS_LOG_NOSLEEP		0x1
661da177e4SLinus Torvalds #define XFS_LOG_PERM_RESERV	0x2
671da177e4SLinus Torvalds 
681da177e4SLinus Torvalds /*
691da177e4SLinus Torvalds  * Flags to xfs_log_force()
701da177e4SLinus Torvalds  *
711da177e4SLinus Torvalds  *	XFS_LOG_SYNC:	Synchronous force in-core log to disk
721da177e4SLinus Torvalds  */
731da177e4SLinus Torvalds #define XFS_LOG_SYNC		0x1
741da177e4SLinus Torvalds 
751da177e4SLinus Torvalds #endif	/* __KERNEL__ */
761da177e4SLinus Torvalds 
771da177e4SLinus Torvalds 
781da177e4SLinus Torvalds /* Log Clients */
791da177e4SLinus Torvalds #define XFS_TRANSACTION		0x69
801da177e4SLinus Torvalds #define XFS_VOLUME		0x2
811da177e4SLinus Torvalds #define XFS_LOG			0xaa
821da177e4SLinus Torvalds 
837e9c6396STim Shimmin 
847e9c6396STim Shimmin /* Region types for iovec's i_type */
857e9c6396STim Shimmin #define XLOG_REG_TYPE_BFORMAT		1
867e9c6396STim Shimmin #define XLOG_REG_TYPE_BCHUNK		2
877e9c6396STim Shimmin #define XLOG_REG_TYPE_EFI_FORMAT	3
887e9c6396STim Shimmin #define XLOG_REG_TYPE_EFD_FORMAT	4
897e9c6396STim Shimmin #define XLOG_REG_TYPE_IFORMAT		5
907e9c6396STim Shimmin #define XLOG_REG_TYPE_ICORE		6
917e9c6396STim Shimmin #define XLOG_REG_TYPE_IEXT		7
927e9c6396STim Shimmin #define XLOG_REG_TYPE_IBROOT		8
937e9c6396STim Shimmin #define XLOG_REG_TYPE_ILOCAL		9
947e9c6396STim Shimmin #define XLOG_REG_TYPE_IATTR_EXT		10
957e9c6396STim Shimmin #define XLOG_REG_TYPE_IATTR_BROOT	11
967e9c6396STim Shimmin #define XLOG_REG_TYPE_IATTR_LOCAL	12
977e9c6396STim Shimmin #define XLOG_REG_TYPE_QFORMAT		13
987e9c6396STim Shimmin #define XLOG_REG_TYPE_DQUOT		14
997e9c6396STim Shimmin #define XLOG_REG_TYPE_QUOTAOFF		15
1007e9c6396STim Shimmin #define XLOG_REG_TYPE_LRHEADER		16
1017e9c6396STim Shimmin #define XLOG_REG_TYPE_UNMOUNT		17
1027e9c6396STim Shimmin #define XLOG_REG_TYPE_COMMIT		18
1037e9c6396STim Shimmin #define XLOG_REG_TYPE_TRANSHDR		19
1047e9c6396STim Shimmin #define XLOG_REG_TYPE_MAX		19
1057e9c6396STim Shimmin 
1061da177e4SLinus Torvalds typedef struct xfs_log_iovec {
1071da177e4SLinus Torvalds 	xfs_caddr_t	i_addr;		/* beginning address of region */
1081da177e4SLinus Torvalds 	int		i_len;		/* length in bytes of region */
1097e9c6396STim Shimmin 	uint		i_type;		/* type of region */
1101da177e4SLinus Torvalds } xfs_log_iovec_t;
1111da177e4SLinus Torvalds 
11255b66332SDave Chinner struct xfs_log_vec {
11355b66332SDave Chinner 	struct xfs_log_vec	*lv_next;	/* next lv in build list */
11455b66332SDave Chinner 	int			lv_niovecs;	/* number of iovecs in lv */
11555b66332SDave Chinner 	struct xfs_log_iovec	*lv_iovecp;	/* iovec array */
11671e330b5SDave Chinner 	struct xfs_log_item	*lv_item;	/* owner */
11771e330b5SDave Chinner 	char			*lv_buf;	/* formatted buffer */
11871e330b5SDave Chinner 	int			lv_buf_len;	/* size of formatted buffer */
11955b66332SDave Chinner };
12055b66332SDave Chinner 
1211da177e4SLinus Torvalds /*
1221da177e4SLinus Torvalds  * Structure used to pass callback function and the function's argument
1231da177e4SLinus Torvalds  * to the log manager.
1241da177e4SLinus Torvalds  */
1251da177e4SLinus Torvalds typedef struct xfs_log_callback {
1261da177e4SLinus Torvalds 	struct xfs_log_callback	*cb_next;
1271da177e4SLinus Torvalds 	void			(*cb_func)(void *, int);
1281da177e4SLinus Torvalds 	void			*cb_arg;
1291da177e4SLinus Torvalds } xfs_log_callback_t;
1301da177e4SLinus Torvalds 
1311da177e4SLinus Torvalds 
1321da177e4SLinus Torvalds #ifdef __KERNEL__
1331da177e4SLinus Torvalds /* Log manager interfaces */
1341da177e4SLinus Torvalds struct xfs_mount;
13535a8a72fSChristoph Hellwig struct xlog_in_core;
136cc09c0dcSDave Chinner struct xlog_ticket;
13743f5efc5SDave Chinner struct xfs_log_item;
13843f5efc5SDave Chinner struct xfs_item_ops;
139955833cfSDave Chinner struct xfs_trans;
14043f5efc5SDave Chinner 
14143f5efc5SDave Chinner void	xfs_log_item_init(struct xfs_mount	*mp,
14243f5efc5SDave Chinner 			struct xfs_log_item	*item,
14343f5efc5SDave Chinner 			int			type,
14443f5efc5SDave Chinner 			struct xfs_item_ops	*ops);
14535a8a72fSChristoph Hellwig 
1461da177e4SLinus Torvalds xfs_lsn_t xfs_log_done(struct xfs_mount *mp,
14735a8a72fSChristoph Hellwig 		       struct xlog_ticket *ticket,
14835a8a72fSChristoph Hellwig 		       struct xlog_in_core **iclog,
1491da177e4SLinus Torvalds 		       uint		flags);
150f538d4daSChristoph Hellwig int	  _xfs_log_force(struct xfs_mount *mp,
151f538d4daSChristoph Hellwig 			 uint		flags,
152f538d4daSChristoph Hellwig 			 int		*log_forced);
153b911ca04SDavid Chinner void	  xfs_log_force(struct xfs_mount	*mp,
154a14a348bSChristoph Hellwig 			uint			flags);
155a14a348bSChristoph Hellwig int	  _xfs_log_force_lsn(struct xfs_mount *mp,
156a14a348bSChristoph Hellwig 			     xfs_lsn_t		lsn,
157a14a348bSChristoph Hellwig 			     uint		flags,
158a14a348bSChristoph Hellwig 			     int		*log_forced);
159a14a348bSChristoph Hellwig void	  xfs_log_force_lsn(struct xfs_mount	*mp,
160b911ca04SDavid Chinner 			    xfs_lsn_t		lsn,
161b911ca04SDavid Chinner 			    uint		flags);
1621da177e4SLinus Torvalds int	  xfs_log_mount(struct xfs_mount	*mp,
1631da177e4SLinus Torvalds 			struct xfs_buftarg	*log_target,
1641da177e4SLinus Torvalds 			xfs_daddr_t		start_block,
1651da177e4SLinus Torvalds 			int		 	num_bblocks);
1664249023aSChristoph Hellwig int	  xfs_log_mount_finish(struct xfs_mount *mp);
1671da177e4SLinus Torvalds void	  xfs_log_move_tail(struct xfs_mount	*mp,
1681da177e4SLinus Torvalds 			    xfs_lsn_t		tail_lsn);
1691da177e4SLinus Torvalds int	  xfs_log_notify(struct xfs_mount	*mp,
17035a8a72fSChristoph Hellwig 			 struct xlog_in_core	*iclog,
1711da177e4SLinus Torvalds 			 xfs_log_callback_t	*callback_entry);
1721da177e4SLinus Torvalds int	  xfs_log_release_iclog(struct xfs_mount *mp,
17335a8a72fSChristoph Hellwig 			 struct xlog_in_core	 *iclog);
1741da177e4SLinus Torvalds int	  xfs_log_reserve(struct xfs_mount *mp,
1751da177e4SLinus Torvalds 			  int		   length,
1761da177e4SLinus Torvalds 			  int		   count,
17735a8a72fSChristoph Hellwig 			  struct xlog_ticket **ticket,
1781da177e4SLinus Torvalds 			  __uint8_t	   clientid,
1797e9c6396STim Shimmin 			  uint		   flags,
1807e9c6396STim Shimmin 			  uint		   t_type);
1811da177e4SLinus Torvalds int	  xfs_log_write(struct xfs_mount *mp,
1821da177e4SLinus Torvalds 			xfs_log_iovec_t  region[],
1831da177e4SLinus Torvalds 			int		 nentries,
18435a8a72fSChristoph Hellwig 			struct xlog_ticket *ticket,
1851da177e4SLinus Torvalds 			xfs_lsn_t	 *start_lsn);
1861da177e4SLinus Torvalds int	  xfs_log_unmount_write(struct xfs_mount *mp);
18721b699c8SChristoph Hellwig void      xfs_log_unmount(struct xfs_mount *mp);
1881da177e4SLinus Torvalds int	  xfs_log_force_umount(struct xfs_mount *mp, int logerror);
1891da177e4SLinus Torvalds int	  xfs_log_need_covered(struct xfs_mount *mp);
1901da177e4SLinus Torvalds 
1911da177e4SLinus Torvalds void	  xlog_iodone(struct xfs_buf *);
1921da177e4SLinus Torvalds 
193cc09c0dcSDave Chinner struct xlog_ticket *xfs_log_ticket_get(struct xlog_ticket *ticket);
194cc09c0dcSDave Chinner void	  xfs_log_ticket_put(struct xlog_ticket *ticket);
195cc09c0dcSDave Chinner 
196955833cfSDave Chinner xlog_tid_t xfs_log_get_trans_ident(struct xfs_trans *tp);
197955833cfSDave Chinner 
19871e330b5SDave Chinner int	xfs_log_commit_cil(struct xfs_mount *mp, struct xfs_trans *tp,
19971e330b5SDave Chinner 				struct xfs_log_vec *log_vector,
20071e330b5SDave Chinner 				xfs_lsn_t *commit_lsn, int flags);
201*ccf7c23fSDave Chinner bool	xfs_log_item_in_current_chkpt(struct xfs_log_item *lip);
20271e330b5SDave Chinner 
2031da177e4SLinus Torvalds #endif
2041da177e4SLinus Torvalds 
2051da177e4SLinus Torvalds 
2061da177e4SLinus Torvalds extern int xlog_debug;		/* set to 1 to enable real log */
2071da177e4SLinus Torvalds 
2081da177e4SLinus Torvalds 
2091da177e4SLinus Torvalds #endif	/* __XFS_LOG_H__ */
210