xfs_log_priv.h revision 153323
1/*
2 * Copyright (c) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like.  Any license provided herein, whether implied or
15 * otherwise, applies only to this software file.  Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA  94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32#ifndef	__XFS_LOG_PRIV_H__
33#define __XFS_LOG_PRIV_H__
34
35struct xfs_buf;
36struct ktrace;
37struct log;
38struct xfs_buf_cancel;
39struct xfs_mount;
40
41/*
42 * Macros, structures, prototypes for internal log manager use.
43 */
44
45#define XLOG_MIN_ICLOGS		2
46#define XLOG_MED_ICLOGS		4
47#define XLOG_MAX_ICLOGS		8
48#define XLOG_CALLBACK_SIZE	10
49#define XLOG_HEADER_MAGIC_NUM	0xFEEDbabe	/* Invalid cycle number */
50#define XLOG_VERSION_1		1
51#define XLOG_VERSION_2		2		/* Large IClogs, Log sunit */
52#define XLOG_VERSION_OKBITS	(XLOG_VERSION_1 | XLOG_VERSION_2)
53#define XLOG_RECORD_BSIZE	(16*1024)	/* eventually 32k */
54#define XLOG_BIG_RECORD_BSIZE	(32*1024)	/* 32k buffers */
55#define XLOG_MAX_RECORD_BSIZE	(256*1024)
56#define XLOG_HEADER_CYCLE_SIZE	(32*1024)	/* cycle data in header */
57#define XLOG_RECORD_BSHIFT	14		/* 16384 == 1 << 14 */
58#define XLOG_BIG_RECORD_BSHIFT	15		/* 32k == 1 << 15 */
59#define XLOG_MAX_RECORD_BSHIFT	18		/* 256k == 1 << 18 */
60
61#if XFS_WANT_FUNCS || XFS_WANT_FUNCS_C || (XFS_WANT_SPACE && XFSSO_XLOG_BTOLRBB)
62int xlog_btolrbb(int b);
63#endif
64
65#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XLOG_BTOLRBB)
66#define XLOG_BTOLRBB(b)		xlog_btolrbb(b)
67#else
68#define XLOG_BTOLRBB(b)		(((b)+XLOG_RECORD_BSIZE-1) >> XLOG_RECORD_BSHIFT)
69#endif
70#define XLOG_BTOLSUNIT(log, b)  (((b)+(log)->l_mp->m_sb.sb_logsunit-1) / \
71                                 (log)->l_mp->m_sb.sb_logsunit)
72#define XLOG_LSUNITTOB(log, su) ((su) * (log)->l_mp->m_sb.sb_logsunit)
73
74#define XLOG_HEADER_SIZE	512
75
76#define XLOG_REC_SHIFT(log) \
77	BTOBB(1 << (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb) ? \
78	 XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT))
79#define XLOG_TOTAL_REC_SHIFT(log) \
80	BTOBB(XLOG_MAX_ICLOGS << (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb) ? \
81	 XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT))
82
83/*
84 *  set lsns
85 */
86
87#define ASSIGN_LSN_CYCLE(lsn,cycle,arch) \
88    INT_SET(((uint *)&(lsn))[LSN_FIELD_CYCLE(arch)], arch, (cycle));
89#define ASSIGN_LSN_BLOCK(lsn,block,arch) \
90    INT_SET(((uint *)&(lsn))[LSN_FIELD_BLOCK(arch)], arch, (block));
91#define ASSIGN_ANY_LSN(lsn,cycle,block,arch)  \
92    { \
93	ASSIGN_LSN_CYCLE(lsn,cycle,arch); \
94	ASSIGN_LSN_BLOCK(lsn,block,arch); \
95    }
96#define ASSIGN_LSN(lsn,log,arch) \
97    ASSIGN_ANY_LSN(lsn,(log)->l_curr_cycle,(log)->l_curr_block,arch);
98
99#define XLOG_SET(f,b)		(((f) & (b)) == (b))
100
101#define GET_CYCLE(ptr, arch) \
102    (INT_GET(*(uint *)(ptr), arch) == XLOG_HEADER_MAGIC_NUM ? \
103	 INT_GET(*((uint *)(ptr)+1), arch) : \
104	 INT_GET(*(uint *)(ptr), arch) \
105    )
106
107#define BLK_AVG(blk1, blk2)	((blk1+blk2) >> 1)
108
109
110#ifdef __KERNEL__
111
112/*
113 * get client id from packed copy.
114 *
115 * this hack is here because the xlog_pack code copies four bytes
116 * of xlog_op_header containing the fields oh_clientid, oh_flags
117 * and oh_res2 into the packed copy.
118 *
119 * later on this four byte chunk is treated as an int and the
120 * client id is pulled out.
121 *
122 * this has endian issues, of course.
123 */
124
125#if __BYTE_ORDER == __LITTLE_ENDIAN
126#define GET_CLIENT_ID(i,arch) \
127    ((i) & 0xff)
128#else
129#define GET_CLIENT_ID(i,arch) \
130    ((i) >> 24)
131#endif
132
133#if XFS_WANT_FUNCS || XFS_WANT_FUNCS_C || (XFS_WANT_SPACE && XFSSO_XLOG_GRANT_SUB_SPACE)
134void xlog_grant_sub_space(struct log *log, int bytes, int type);
135#endif
136
137#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XLOG_GRANT_SUB_SPACE)
138#define XLOG_GRANT_SUB_SPACE(log,bytes,type)	\
139	xlog_grant_sub_space(log,bytes,type)
140#else
141#define XLOG_GRANT_SUB_SPACE(log,bytes,type)				\
142    {									\
143	if (type == 'w') {						\
144		(log)->l_grant_write_bytes -= (bytes);			\
145		if ((log)->l_grant_write_bytes < 0) {			\
146			(log)->l_grant_write_bytes += (log)->l_logsize;	\
147			(log)->l_grant_write_cycle--;			\
148		}							\
149	} else {							\
150		(log)->l_grant_reserve_bytes -= (bytes);		\
151		if ((log)->l_grant_reserve_bytes < 0) {			\
152			(log)->l_grant_reserve_bytes += (log)->l_logsize;\
153			(log)->l_grant_reserve_cycle--;			\
154		}							\
155	 }								\
156    }
157#endif
158
159
160#if XFS_WANT_FUNCS || XFS_WANT_FUNCS_C || (XFS_WANT_SPACE && XFSSO_XLOG_GRANT_ADD_SPACE)
161void xlog_grant_add_space(struct log *log, int bytes, int type);
162#endif
163
164#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XLOG_GRANT_ADD_SPACE)
165#define XLOG_GRANT_ADD_SPACE(log,bytes,type)	\
166	xlog_grant_add_space(log,bytes,type)
167#else
168#define XLOG_GRANT_ADD_SPACE(log,bytes,type)				\
169    {									\
170	if (type == 'w') {						\
171		(log)->l_grant_write_bytes += (bytes);			\
172		if ((log)->l_grant_write_bytes > (log)->l_logsize) {	\
173			(log)->l_grant_write_bytes -= (log)->l_logsize;	\
174			(log)->l_grant_write_cycle++;			\
175		}							\
176	} else {							\
177		(log)->l_grant_reserve_bytes += (bytes);		\
178		if ((log)->l_grant_reserve_bytes > (log)->l_logsize) {	\
179			(log)->l_grant_reserve_bytes -= (log)->l_logsize;\
180			(log)->l_grant_reserve_cycle++;			\
181		}							\
182	 }								\
183    }
184#endif
185#define XLOG_INS_TICKETQ(q,tic)				\
186    {							\
187	if (q) {					\
188		(tic)->t_next	    = (q);		\
189		(tic)->t_prev	    = (q)->t_prev;	\
190		(q)->t_prev->t_next = (tic);		\
191		(q)->t_prev	    = (tic);		\
192	} else {					\
193		(tic)->t_prev = (tic)->t_next = (tic);	\
194		(q) = (tic);				\
195	}						\
196	(tic)->t_flags |= XLOG_TIC_IN_Q;		\
197    }
198#define XLOG_DEL_TICKETQ(q,tic)				\
199    {							\
200	if ((tic) == (tic)->t_next) {			\
201		(q) = NULL;				\
202	} else {					\
203		(q) = (tic)->t_next;			\
204		(tic)->t_next->t_prev = (tic)->t_prev;	\
205		(tic)->t_prev->t_next = (tic)->t_next;	\
206	}						\
207	(tic)->t_next = (tic)->t_prev = NULL;		\
208	(tic)->t_flags &= ~XLOG_TIC_IN_Q;		\
209    }
210
211
212#define GRANT_LOCK(log)		mutex_spinlock(&(log)->l_grant_lock)
213#define GRANT_UNLOCK(log, s)	mutex_spinunlock(&(log)->l_grant_lock, s)
214#define LOG_LOCK(log)		mutex_spinlock(&(log)->l_icloglock)
215#define LOG_UNLOCK(log, s)	mutex_spinunlock(&(log)->l_icloglock, s)
216
217#define xlog_panic(args...)	cmn_err(CE_PANIC, ## args)
218#define xlog_exit(args...)	cmn_err(CE_PANIC, ## args)
219#define xlog_warn(args...)	cmn_err(CE_WARN, ## args)
220
221/*
222 * In core log state
223 */
224#define XLOG_STATE_ACTIVE    0x0001 /* Current IC log being written to */
225#define XLOG_STATE_WANT_SYNC 0x0002 /* Want to sync this iclog; no more writes */
226#define XLOG_STATE_SYNCING   0x0004 /* This IC log is syncing */
227#define XLOG_STATE_DONE_SYNC 0x0008 /* Done syncing to disk */
228#define XLOG_STATE_DO_CALLBACK \
229			     0x0010 /* Process callback functions */
230#define XLOG_STATE_CALLBACK  0x0020 /* Callback functions now */
231#define XLOG_STATE_DIRTY     0x0040 /* Dirty IC log, not ready for ACTIVE status*/
232#define XLOG_STATE_IOERROR   0x0080 /* IO error happened in sync'ing log */
233#define XLOG_STATE_ALL	     0x7FFF /* All possible valid flags */
234#define XLOG_STATE_NOTUSED   0x8000 /* This IC log not being used */
235#endif	/* __KERNEL__ */
236
237/*
238 * Flags to log operation header
239 *
240 * The first write of a new transaction will be preceded with a start
241 * record, XLOG_START_TRANS.  Once a transaction is committed, a commit
242 * record is written, XLOG_COMMIT_TRANS.  If a single region can not fit into
243 * the remainder of the current active in-core log, it is split up into
244 * multiple regions.  Each partial region will be marked with a
245 * XLOG_CONTINUE_TRANS until the last one, which gets marked with XLOG_END_TRANS.
246 *
247 */
248#define XLOG_START_TRANS	0x01	/* Start a new transaction */
249#define XLOG_COMMIT_TRANS	0x02	/* Commit this transaction */
250#define XLOG_CONTINUE_TRANS	0x04	/* Cont this trans into new region */
251#define XLOG_WAS_CONT_TRANS	0x08	/* Cont this trans into new region */
252#define XLOG_END_TRANS		0x10	/* End a continued transaction */
253#define XLOG_UNMOUNT_TRANS	0x20	/* Unmount a filesystem transaction */
254#define XLOG_SKIP_TRANS		(XLOG_COMMIT_TRANS | XLOG_CONTINUE_TRANS | \
255				 XLOG_WAS_CONT_TRANS | XLOG_END_TRANS | \
256				 XLOG_UNMOUNT_TRANS)
257
258#ifdef __KERNEL__
259/*
260 * Flags to log ticket
261 */
262#define XLOG_TIC_INITED		0x1	/* has been initialized */
263#define XLOG_TIC_PERM_RESERV	0x2	/* permanent reservation */
264#define XLOG_TIC_IN_Q		0x4
265#endif	/* __KERNEL__ */
266
267#define XLOG_UNMOUNT_TYPE	0x556e	/* Un for Unmount */
268
269/*
270 * Flags for log structure
271 */
272#define XLOG_CHKSUM_MISMATCH	0x1	/* used only during recovery */
273#define XLOG_ACTIVE_RECOVERY	0x2	/* in the middle of recovery */
274#define	XLOG_RECOVERY_NEEDED	0x4	/* log was recovered */
275#define XLOG_IO_ERROR		0x8	/* log hit an I/O error, and being
276					   shutdown */
277typedef __uint32_t xlog_tid_t;
278
279
280#ifdef __KERNEL__
281/*
282 * Below are states for covering allocation transactions.
283 * By covering, we mean changing the h_tail_lsn in the last on-disk
284 * log write such that no allocation transactions will be re-done during
285 * recovery after a system crash. Recovery starts at the last on-disk
286 * log write.
287 *
288 * These states are used to insert dummy log entries to cover
289 * space allocation transactions which can undo non-transactional changes
290 * after a crash. Writes to a file with space
291 * already allocated do not result in any transactions. Allocations
292 * might include space beyond the EOF. So if we just push the EOF a
293 * little, the last transaction for the file could contain the wrong
294 * size. If there is no file system activity, after an allocation
295 * transaction, and the system crashes, the allocation transaction
296 * will get replayed and the file will be truncated. This could
297 * be hours/days/... after the allocation occurred.
298 *
299 * The fix for this is to do two dummy transactions when the
300 * system is idle. We need two dummy transaction because the h_tail_lsn
301 * in the log record header needs to point beyond the last possible
302 * non-dummy transaction. The first dummy changes the h_tail_lsn to
303 * the first transaction before the dummy. The second dummy causes
304 * h_tail_lsn to point to the first dummy. Recovery starts at h_tail_lsn.
305 *
306 * These dummy transactions get committed when everything
307 * is idle (after there has been some activity).
308 *
309 * There are 5 states used to control this.
310 *
311 *  IDLE -- no logging has been done on the file system or
312 *		we are done covering previous transactions.
313 *  NEED -- logging has occurred and we need a dummy transaction
314 *		when the log becomes idle.
315 *  DONE -- we were in the NEED state and have committed a dummy
316 *		transaction.
317 *  NEED2 -- we detected that a dummy transaction has gone to the
318 *		on disk log with no other transactions.
319 *  DONE2 -- we committed a dummy transaction when in the NEED2 state.
320 *
321 * There are two places where we switch states:
322 *
323 * 1.) In xfs_sync, when we detect an idle log and are in NEED or NEED2.
324 *	We commit the dummy transaction and switch to DONE or DONE2,
325 *	respectively. In all other states, we don't do anything.
326 *
327 * 2.) When we finish writing the on-disk log (xlog_state_clean_log).
328 *
329 *	No matter what state we are in, if this isn't the dummy
330 *	transaction going out, the next state is NEED.
331 *	So, if we aren't in the DONE or DONE2 states, the next state
332 *	is NEED. We can't be finishing a write of the dummy record
333 *	unless it was committed and the state switched to DONE or DONE2.
334 *
335 *	If we are in the DONE state and this was a write of the
336 *		dummy transaction, we move to NEED2.
337 *
338 *	If we are in the DONE2 state and this was a write of the
339 *		dummy transaction, we move to IDLE.
340 *
341 *
342 * Writing only one dummy transaction can get appended to
343 * one file space allocation. When this happens, the log recovery
344 * code replays the space allocation and a file could be truncated.
345 * This is why we have the NEED2 and DONE2 states before going idle.
346 */
347
348#define XLOG_STATE_COVER_IDLE	0
349#define XLOG_STATE_COVER_NEED	1
350#define XLOG_STATE_COVER_DONE	2
351#define XLOG_STATE_COVER_NEED2	3
352#define XLOG_STATE_COVER_DONE2	4
353
354#define XLOG_COVER_OPS		5
355
356typedef struct xlog_ticket {
357	sv_t		   t_sema;	 /* sleep on this semaphore	 :20 */
358	struct xlog_ticket *t_next;	 /*			         : 4 */
359	struct xlog_ticket *t_prev;	 /*				 : 4 */
360	xlog_tid_t	   t_tid;	 /* transaction identifier	 : 4 */
361	int		   t_curr_res;	 /* current reservation in bytes : 4 */
362	int		   t_unit_res;	 /* unit reservation in bytes    : 4 */
363	__uint8_t	   t_ocnt;	 /* original count		 : 1 */
364	__uint8_t	   t_cnt;	 /* current count		 : 1 */
365	__uint8_t	   t_clientid;	 /* who does this belong to;	 : 1 */
366	__uint8_t	   t_flags;	 /* properties of reservation	 : 1 */
367} xlog_ticket_t;
368#endif
369
370
371typedef struct xlog_op_header {
372	xlog_tid_t oh_tid;	/* transaction id of operation	:  4 b */
373	int	   oh_len;	/* bytes in data region		:  4 b */
374	__uint8_t  oh_clientid;	/* who sent me this		:  1 b */
375	__uint8_t  oh_flags;	/*				:  1 b */
376	ushort	   oh_res2;	/* 32 bit align			:  2 b */
377} xlog_op_header_t;
378
379
380/* valid values for h_fmt */
381#define XLOG_FMT_UNKNOWN  0
382#define XLOG_FMT_LINUX_LE 1
383#define XLOG_FMT_LINUX_BE 2
384#define XLOG_FMT_IRIX_BE  3
385
386/* our fmt */
387#if __BYTE_ORDER == __LITTLE_ENDIAN
388#define XLOG_FMT XLOG_FMT_LINUX_LE
389#else
390#if __BYTE_ORDER == __BIG_ENDIAN
391#define XLOG_FMT XLOG_FMT_LINUX_BE
392#else
393#error unknown byte order
394#endif
395#endif
396
397typedef struct xlog_rec_header {
398	uint	  h_magicno;	/* log record (LR) identifier		:  4 */
399	uint	  h_cycle;	/* write cycle of log			:  4 */
400	int	  h_version;	/* LR version				:  4 */
401	int	  h_len;	/* len in bytes; should be 64-bit aligned: 4 */
402	xfs_lsn_t h_lsn;	/* lsn of this LR			:  8 */
403	xfs_lsn_t h_tail_lsn;	/* lsn of 1st LR w/ buffers not committed: 8 */
404	uint	  h_chksum;	/* may not be used; non-zero if used	:  4 */
405	int	  h_prev_block; /* block number to previous LR		:  4 */
406	int	  h_num_logops;	/* number of log operations in this LR	:  4 */
407	uint	  h_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE];
408	/* new fields */
409	int       h_fmt;        /* format of log record                 :  4 */
410	uuid_t    h_fs_uuid;    /* uuid of FS                           : 16 */
411	int       h_size;	/* iclog size				:  4 */
412} xlog_rec_header_t;
413
414typedef struct xlog_rec_ext_header {
415	uint	  xh_cycle;	/* write cycle of log			: 4 */
416	uint	  xh_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE]; /*	: 256 */
417} xlog_rec_ext_header_t;
418
419#ifdef __KERNEL__
420/*
421 * - A log record header is 512 bytes.  There is plenty of room to grow the
422 *	xlog_rec_header_t into the reserved space.
423 * - ic_data follows, so a write to disk can start at the beginning of
424 *	the iclog.
425 * - ic_forcesema is used to implement synchronous forcing of the iclog to disk.
426 * - ic_next is the pointer to the next iclog in the ring.
427 * - ic_bp is a pointer to the buffer used to write this incore log to disk.
428 * - ic_log is a pointer back to the global log structure.
429 * - ic_callback is a linked list of callback function/argument pairs to be
430 *	called after an iclog finishes writing.
431 * - ic_size is the full size of the header plus data.
432 * - ic_offset is the current number of bytes written to in this iclog.
433 * - ic_refcnt is bumped when someone is writing to the log.
434 * - ic_state is the state of the iclog.
435 */
436typedef struct xlog_iclog_fields {
437	sv_t			ic_forcesema;
438	sv_t			ic_writesema;
439	struct xlog_in_core	*ic_next;
440	struct xlog_in_core	*ic_prev;
441	struct xfs_buf		*ic_bp;
442	struct log		*ic_log;
443	xfs_log_callback_t	*ic_callback;
444	xfs_log_callback_t	**ic_callback_tail;
445#ifdef XFS_LOG_TRACE
446	struct ktrace		*ic_trace;
447#endif
448	int			ic_size;
449	int			ic_offset;
450	int			ic_refcnt;
451	int			ic_roundoff;
452	int			ic_bwritecnt;
453	ushort_t		ic_state;
454	char			*ic_datap;	/* pointer to iclog data */
455} xlog_iclog_fields_t;
456
457typedef union xlog_in_core2 {
458	xlog_rec_header_t	hic_header;
459	xlog_rec_ext_header_t	hic_xheader;
460	char			hic_sector[XLOG_HEADER_SIZE];
461} xlog_in_core_2_t;
462
463typedef struct xlog_in_core {
464	xlog_iclog_fields_t	hic_fields;
465	xlog_in_core_2_t	*hic_data;
466} xlog_in_core_t;
467
468/*
469 * Defines to save our code from this glop.
470 */
471#define	ic_forcesema	hic_fields.ic_forcesema
472#define ic_writesema	hic_fields.ic_writesema
473#define	ic_next		hic_fields.ic_next
474#define	ic_prev		hic_fields.ic_prev
475#define	ic_bp		hic_fields.ic_bp
476#define	ic_log		hic_fields.ic_log
477#define	ic_callback	hic_fields.ic_callback
478#define	ic_callback_tail hic_fields.ic_callback_tail
479#define	ic_trace	hic_fields.ic_trace
480#define	ic_size		hic_fields.ic_size
481#define	ic_offset	hic_fields.ic_offset
482#define	ic_refcnt	hic_fields.ic_refcnt
483#define	ic_roundoff	hic_fields.ic_roundoff
484#define	ic_bwritecnt	hic_fields.ic_bwritecnt
485#define	ic_state	hic_fields.ic_state
486#define ic_datap	hic_fields.ic_datap
487#define ic_header	hic_data->hic_header
488
489/*
490 * The reservation head lsn is not made up of a cycle number and block number.
491 * Instead, it uses a cycle number and byte number.  Logs don't expect to
492 * overflow 31 bits worth of byte offset, so using a byte number will mean
493 * that round off problems won't occur when releasing partial reservations.
494 */
495typedef struct log {
496	/* The following block of fields are changed while holding icloglock */
497	sema_t			l_flushsema;    /* iclog flushing semaphore */
498	int			l_flushcnt;	/* # of procs waiting on this
499						 * sema */
500	int			l_ticket_cnt;	/* free ticket count */
501	int			l_ticket_tcnt;	/* total ticket count */
502	int			l_covered_state;/* state of "covering disk
503						 * log entries" */
504	xlog_ticket_t		*l_freelist;    /* free list of tickets */
505	xlog_ticket_t		*l_unmount_free;/* kmem_free these addresses */
506	xlog_ticket_t		*l_tail;        /* free list of tickets */
507	xlog_in_core_t		*l_iclog;       /* head log queue	*/
508	lock_t			l_icloglock;    /* grab to change iclog state */
509	xfs_lsn_t		l_tail_lsn;     /* lsn of 1st LR with unflushed
510						 * buffers */
511	xfs_lsn_t		l_last_sync_lsn;/* lsn of last LR on disk */
512	struct xfs_mount	*l_mp;	        /* mount point */
513	struct xfs_buf		*l_xbuf;        /* extra buffer for log
514						 * wrapping */
515	struct xfs_buftarg	*l_targ;        /* buftarg of log */
516	xfs_daddr_t		l_logBBstart;   /* start block of log */
517	int			l_logsize;      /* size of log in bytes */
518	int			l_logBBsize;    /* size of log in BB chunks */
519	int			l_roundoff;	/* round off error of iclogs */
520	int			l_curr_cycle;   /* Cycle number of log writes */
521	int			l_prev_cycle;   /* Cycle number before last
522						 * block increment */
523	int			l_curr_block;   /* current logical log block */
524	int			l_prev_block;   /* previous logical log block */
525	int			l_iclog_size;	/* size of log in bytes */
526	int			l_iclog_size_log; /* log power size of log */
527	int			l_iclog_bufs;	/* number of iclog buffers */
528
529	/* The following field are used for debugging; need to hold icloglock */
530	char			*l_iclog_bak[XLOG_MAX_ICLOGS];
531
532	/* The following block of fields are changed while holding grant_lock */
533	lock_t			l_grant_lock;
534	xlog_ticket_t		*l_reserve_headq;
535	xlog_ticket_t		*l_write_headq;
536	int			l_grant_reserve_cycle;
537	int			l_grant_reserve_bytes;
538	int			l_grant_write_cycle;
539	int			l_grant_write_bytes;
540
541	/* The following fields don't need locking */
542#ifdef XFS_LOG_TRACE
543	struct ktrace		*l_trace;
544	struct ktrace		*l_grant_trace;
545#endif
546	uint			l_flags;
547	uint			l_quotaoffs_flag; /* XFS_DQ_*, for QUOTAOFFs */
548	struct xfs_buf_cancel	**l_buf_cancel_table;
549	int			l_iclog_hsize;  /* size of iclog header */
550	int			l_iclog_heads;  /* # of iclog header sectors */
551	uint			l_sectbb_log;   /* log2 of sector size in BBs */
552	uint			l_sectbb_mask;  /* sector size (in BBs)
553						 * alignment mask */
554} xlog_t;
555
556
557/* common routines */
558extern xfs_lsn_t xlog_assign_tail_lsn(struct xfs_mount *mp);
559extern int	 xlog_find_head(xlog_t *log, xfs_daddr_t *head_blk);
560extern int	 xlog_find_tail(xlog_t	*log,
561				xfs_daddr_t *head_blk,
562				xfs_daddr_t *tail_blk,
563				int readonly);
564extern int	 xlog_print_find_oldest(xlog_t *log, xfs_daddr_t *last_blk);
565extern int	 xlog_recover(xlog_t *log, int readonly);
566extern int	 xlog_recover_finish(xlog_t *log, int mfsi_flags);
567extern void	 xlog_pack_data(xlog_t *log, xlog_in_core_t *iclog);
568extern void	 xlog_recover_process_iunlinks(xlog_t *log);
569
570extern struct xfs_buf *xlog_get_bp(xlog_t *, int);
571extern void	 xlog_put_bp(struct xfs_buf *);
572extern int	 xlog_bread(xlog_t *, xfs_daddr_t, int, struct xfs_buf *);
573extern xfs_caddr_t xlog_align(xlog_t *, xfs_daddr_t, int, struct xfs_buf *);
574
575#define XLOG_TRACE_GRAB_FLUSH  1
576#define XLOG_TRACE_REL_FLUSH   2
577#define XLOG_TRACE_SLEEP_FLUSH 3
578#define XLOG_TRACE_WAKE_FLUSH  4
579
580#endif	/* __KERNEL__ */
581
582#endif	/* __XFS_LOG_PRIV_H__ */
583