1*0b61f8a4SDave 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; 121da177e4SLinus Torvalds struct kmem_zone; 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 /* 20b199c8a4SDave Chinner * Define EFI flag bits. Manipulated by set/clear/test_bit operators. 211da177e4SLinus Torvalds */ 22b199c8a4SDave Chinner #define XFS_EFI_RECOVERED 1 231da177e4SLinus Torvalds 241da177e4SLinus Torvalds /* 25666d644cSDave Chinner * This is the "extent free intention" log item. It is used to log the fact 26666d644cSDave Chinner * that some extents need to be free. It is used in conjunction with the 27666d644cSDave Chinner * "extent free done" log item described below. 28666d644cSDave Chinner * 29666d644cSDave Chinner * The EFI is reference counted so that it is not freed prior to both the EFI 308d99fe92SBrian Foster * and EFD being committed and unpinned. This ensures the EFI is inserted into 318d99fe92SBrian Foster * the AIL even in the event of out of order EFI/EFD processing. In other words, 328d99fe92SBrian Foster * an EFI is born with two references: 338d99fe92SBrian Foster * 348d99fe92SBrian Foster * 1.) an EFI held reference to track EFI AIL insertion 358d99fe92SBrian Foster * 2.) an EFD held reference to track EFD commit 368d99fe92SBrian Foster * 378d99fe92SBrian Foster * On allocation, both references are the responsibility of the caller. Once the 388d99fe92SBrian Foster * EFI is added to and dirtied in a transaction, ownership of reference one 398d99fe92SBrian Foster * transfers to the transaction. The reference is dropped once the EFI is 408d99fe92SBrian Foster * inserted to the AIL or in the event of failure along the way (e.g., commit 418d99fe92SBrian Foster * failure, log I/O error, etc.). Note that the caller remains responsible for 428d99fe92SBrian Foster * the EFD reference under all circumstances to this point. The caller has no 438d99fe92SBrian Foster * means to detect failure once the transaction is committed, however. 448d99fe92SBrian Foster * Therefore, an EFD is required after this point, even in the event of 458d99fe92SBrian Foster * unrelated failure. 468d99fe92SBrian Foster * 478d99fe92SBrian Foster * Once an EFD is allocated and dirtied in a transaction, reference two 488d99fe92SBrian Foster * transfers to the transaction. The EFD reference is dropped once it reaches 498d99fe92SBrian Foster * the unpin handler. Similar to the EFI, the reference also drops in the event 508d99fe92SBrian Foster * of commit failure or log I/O errors. Note that the EFD is not inserted in the 518d99fe92SBrian Foster * AIL, so at this point both the EFI and EFD are freed. 521da177e4SLinus Torvalds */ 531da177e4SLinus Torvalds typedef struct xfs_efi_log_item { 541da177e4SLinus Torvalds xfs_log_item_t efi_item; 55666d644cSDave Chinner atomic_t efi_refcount; 56b199c8a4SDave Chinner atomic_t efi_next_extent; 57b199c8a4SDave Chinner unsigned long efi_flags; /* misc flags */ 581da177e4SLinus Torvalds xfs_efi_log_format_t efi_format; 591da177e4SLinus Torvalds } xfs_efi_log_item_t; 601da177e4SLinus Torvalds 611da177e4SLinus Torvalds /* 621da177e4SLinus Torvalds * This is the "extent free done" log item. It is used to log 631da177e4SLinus Torvalds * the fact that some extents earlier mentioned in an efi item 641da177e4SLinus Torvalds * have been freed. 651da177e4SLinus Torvalds */ 661da177e4SLinus Torvalds typedef struct xfs_efd_log_item { 671da177e4SLinus Torvalds xfs_log_item_t efd_item; 681da177e4SLinus Torvalds xfs_efi_log_item_t *efd_efip; 691da177e4SLinus Torvalds uint efd_next_extent; 701da177e4SLinus Torvalds xfs_efd_log_format_t efd_format; 711da177e4SLinus Torvalds } xfs_efd_log_item_t; 721da177e4SLinus Torvalds 731da177e4SLinus Torvalds /* 741da177e4SLinus Torvalds * Max number of extents in fast allocation path. 751da177e4SLinus Torvalds */ 761da177e4SLinus Torvalds #define XFS_EFD_MAX_FAST_EXTENTS 16 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds extern struct kmem_zone *xfs_efi_zone; 791da177e4SLinus Torvalds extern struct kmem_zone *xfs_efd_zone; 801da177e4SLinus Torvalds 811da177e4SLinus Torvalds xfs_efi_log_item_t *xfs_efi_init(struct xfs_mount *, uint); 821da177e4SLinus Torvalds xfs_efd_log_item_t *xfs_efd_init(struct xfs_mount *, xfs_efi_log_item_t *, 831da177e4SLinus Torvalds uint); 846d192a9bSTim Shimmin int xfs_efi_copy_format(xfs_log_iovec_t *buf, 856d192a9bSTim Shimmin xfs_efi_log_format_t *dst_efi_fmt); 867d795ca3SChristoph Hellwig void xfs_efi_item_free(xfs_efi_log_item_t *); 875e4b5386SBrian Foster void xfs_efi_release(struct xfs_efi_log_item *); 887d795ca3SChristoph Hellwig 89dc42375dSDarrick J. Wong int xfs_efi_recover(struct xfs_mount *mp, 90dc42375dSDarrick J. Wong struct xfs_efi_log_item *efip); 91dc42375dSDarrick J. Wong 921da177e4SLinus Torvalds #endif /* __XFS_EXTFREE_ITEM_H__ */ 93