xref: /linux/fs/xfs/xfs_extfree_item.h (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
10b61f8a4SDave Chinner // SPDX-License-Identifier: GPL-2.0
21da177e4SLinus Torvalds /*
37b718769SNathan Scott  * Copyright (c) 2000,2005 Silicon Graphics, Inc.
47b718769SNathan Scott  * All Rights Reserved.
51da177e4SLinus Torvalds  */
61da177e4SLinus Torvalds #ifndef	__XFS_EXTFREE_ITEM_H__
71da177e4SLinus Torvalds #define	__XFS_EXTFREE_ITEM_H__
81da177e4SLinus Torvalds 
99fbe24d9SDave Chinner /* kernel only EFI/EFD definitions */
109fbe24d9SDave Chinner 
111da177e4SLinus Torvalds struct xfs_mount;
12e7720afaSDarrick J. Wong struct kmem_cache;
131da177e4SLinus Torvalds 
141da177e4SLinus Torvalds /*
151da177e4SLinus Torvalds  * Max number of extents in fast allocation path.
161da177e4SLinus Torvalds  */
171da177e4SLinus Torvalds #define	XFS_EFI_MAX_FAST_EXTENTS	16
181da177e4SLinus Torvalds 
191da177e4SLinus Torvalds /*
20666d644cSDave Chinner  * This is the "extent free intention" log item.  It is used to log the fact
21666d644cSDave Chinner  * that some extents need to be free.  It is used in conjunction with the
22666d644cSDave Chinner  * "extent free done" log item described below.
23666d644cSDave Chinner  *
24666d644cSDave Chinner  * The EFI is reference counted so that it is not freed prior to both the EFI
258d99fe92SBrian Foster  * and EFD being committed and unpinned. This ensures the EFI is inserted into
268d99fe92SBrian Foster  * the AIL even in the event of out of order EFI/EFD processing. In other words,
278d99fe92SBrian Foster  * an EFI is born with two references:
288d99fe92SBrian Foster  *
298d99fe92SBrian Foster  * 	1.) an EFI held reference to track EFI AIL insertion
308d99fe92SBrian Foster  * 	2.) an EFD held reference to track EFD commit
318d99fe92SBrian Foster  *
328d99fe92SBrian Foster  * On allocation, both references are the responsibility of the caller. Once the
338d99fe92SBrian Foster  * EFI is added to and dirtied in a transaction, ownership of reference one
348d99fe92SBrian Foster  * transfers to the transaction. The reference is dropped once the EFI is
358d99fe92SBrian Foster  * inserted to the AIL or in the event of failure along the way (e.g., commit
368d99fe92SBrian Foster  * failure, log I/O error, etc.). Note that the caller remains responsible for
378d99fe92SBrian Foster  * the EFD reference under all circumstances to this point. The caller has no
388d99fe92SBrian Foster  * means to detect failure once the transaction is committed, however.
398d99fe92SBrian Foster  * Therefore, an EFD is required after this point, even in the event of
408d99fe92SBrian Foster  * unrelated failure.
418d99fe92SBrian Foster  *
428d99fe92SBrian Foster  * Once an EFD is allocated and dirtied in a transaction, reference two
438d99fe92SBrian Foster  * transfers to the transaction. The EFD reference is dropped once it reaches
448d99fe92SBrian Foster  * the unpin handler. Similar to the EFI, the reference also drops in the event
458d99fe92SBrian Foster  * of commit failure or log I/O errors. Note that the EFD is not inserted in the
468d99fe92SBrian Foster  * AIL, so at this point both the EFI and EFD are freed.
471da177e4SLinus Torvalds  */
4882ff450bSChristoph Hellwig struct xfs_efi_log_item {
49efe2330fSChristoph Hellwig 	struct xfs_log_item	efi_item;
50666d644cSDave Chinner 	atomic_t		efi_refcount;
51b199c8a4SDave Chinner 	atomic_t		efi_next_extent;
521da177e4SLinus Torvalds 	xfs_efi_log_format_t	efi_format;
5382ff450bSChristoph Hellwig };
541da177e4SLinus Torvalds 
553c5aaaceSDarrick J. Wong static inline size_t
xfs_efi_log_item_sizeof(unsigned int nr)563c5aaaceSDarrick J. Wong xfs_efi_log_item_sizeof(
573c5aaaceSDarrick J. Wong 	unsigned int		nr)
583c5aaaceSDarrick J. Wong {
593c5aaaceSDarrick J. Wong 	return offsetof(struct xfs_efi_log_item, efi_format) +
603c5aaaceSDarrick J. Wong 			xfs_efi_log_format_sizeof(nr);
613c5aaaceSDarrick J. Wong }
623c5aaaceSDarrick J. Wong 
631da177e4SLinus Torvalds /*
641da177e4SLinus Torvalds  * This is the "extent free done" log item.  It is used to log
651da177e4SLinus Torvalds  * the fact that some extents earlier mentioned in an efi item
661da177e4SLinus Torvalds  * have been freed.
671da177e4SLinus Torvalds  */
68c84e8190SChristoph Hellwig struct xfs_efd_log_item {
69efe2330fSChristoph Hellwig 	struct xfs_log_item	efd_item;
7082ff450bSChristoph Hellwig 	struct xfs_efi_log_item *efd_efip;
711da177e4SLinus Torvalds 	uint			efd_next_extent;
721da177e4SLinus Torvalds 	xfs_efd_log_format_t	efd_format;
73c84e8190SChristoph Hellwig };
741da177e4SLinus Torvalds 
753c5aaaceSDarrick J. Wong static inline size_t
xfs_efd_log_item_sizeof(unsigned int nr)763c5aaaceSDarrick J. Wong xfs_efd_log_item_sizeof(
773c5aaaceSDarrick J. Wong 	unsigned int		nr)
783c5aaaceSDarrick J. Wong {
793c5aaaceSDarrick J. Wong 	return offsetof(struct xfs_efd_log_item, efd_format) +
803c5aaaceSDarrick J. Wong 			xfs_efd_log_format_sizeof(nr);
813c5aaaceSDarrick J. Wong }
823c5aaaceSDarrick J. Wong 
831da177e4SLinus Torvalds /*
841da177e4SLinus Torvalds  * Max number of extents in fast allocation path.
851da177e4SLinus Torvalds  */
861da177e4SLinus Torvalds #define	XFS_EFD_MAX_FAST_EXTENTS	16
871da177e4SLinus Torvalds 
88182696fbSDarrick J. Wong extern struct kmem_cache	*xfs_efi_cache;
89182696fbSDarrick J. Wong extern struct kmem_cache	*xfs_efd_cache;
901da177e4SLinus Torvalds 
91*84a3c157SDarrick J. Wong struct xfs_extent_free_item;
92*84a3c157SDarrick J. Wong 
93*84a3c157SDarrick J. Wong void xfs_extent_free_defer_add(struct xfs_trans *tp,
94*84a3c157SDarrick J. Wong 		struct xfs_extent_free_item *xefi,
95*84a3c157SDarrick J. Wong 		struct xfs_defer_pending **dfpp);
96*84a3c157SDarrick J. Wong 
971da177e4SLinus Torvalds #endif	/* __XFS_EXTFREE_ITEM_H__ */
98