Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 2 | * Copyright (c) 2000,2005 Silicon Graphics, Inc. |
| 3 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * published by the Free Software Foundation. |
| 8 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 9 | * This program is distributed in the hope that it would be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write the Free Software Foundation, |
| 16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
| 18 | #ifndef __XFS_EXTFREE_ITEM_H__ |
| 19 | #define __XFS_EXTFREE_ITEM_H__ |
| 20 | |
Dave Chinner | 9fbe24d | 2013-08-12 20:49:25 +1000 | [diff] [blame] | 21 | /* kernel only EFI/EFD definitions */ |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | struct xfs_mount; |
| 24 | struct kmem_zone; |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | /* |
| 27 | * Max number of extents in fast allocation path. |
| 28 | */ |
| 29 | #define XFS_EFI_MAX_FAST_EXTENTS 16 |
| 30 | |
| 31 | /* |
Dave Chinner | b199c8a | 2010-12-20 11:59:49 +1100 | [diff] [blame] | 32 | * Define EFI flag bits. Manipulated by set/clear/test_bit operators. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | */ |
Dave Chinner | b199c8a | 2010-12-20 11:59:49 +1100 | [diff] [blame] | 34 | #define XFS_EFI_RECOVERED 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | /* |
Dave Chinner | 666d644 | 2013-04-03 14:09:21 +1100 | [diff] [blame] | 37 | * This is the "extent free intention" log item. It is used to log the fact |
| 38 | * that some extents need to be free. It is used in conjunction with the |
| 39 | * "extent free done" log item described below. |
| 40 | * |
| 41 | * The EFI is reference counted so that it is not freed prior to both the EFI |
Brian Foster | 8d99fe9 | 2015-08-19 09:51:16 +1000 | [diff] [blame] | 42 | * and EFD being committed and unpinned. This ensures the EFI is inserted into |
| 43 | * the AIL even in the event of out of order EFI/EFD processing. In other words, |
| 44 | * an EFI is born with two references: |
| 45 | * |
| 46 | * 1.) an EFI held reference to track EFI AIL insertion |
| 47 | * 2.) an EFD held reference to track EFD commit |
| 48 | * |
| 49 | * On allocation, both references are the responsibility of the caller. Once the |
| 50 | * EFI is added to and dirtied in a transaction, ownership of reference one |
| 51 | * transfers to the transaction. The reference is dropped once the EFI is |
| 52 | * inserted to the AIL or in the event of failure along the way (e.g., commit |
| 53 | * failure, log I/O error, etc.). Note that the caller remains responsible for |
| 54 | * the EFD reference under all circumstances to this point. The caller has no |
| 55 | * means to detect failure once the transaction is committed, however. |
| 56 | * Therefore, an EFD is required after this point, even in the event of |
| 57 | * unrelated failure. |
| 58 | * |
| 59 | * Once an EFD is allocated and dirtied in a transaction, reference two |
| 60 | * transfers to the transaction. The EFD reference is dropped once it reaches |
| 61 | * the unpin handler. Similar to the EFI, the reference also drops in the event |
| 62 | * of commit failure or log I/O errors. Note that the EFD is not inserted in the |
| 63 | * AIL, so at this point both the EFI and EFD are freed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | */ |
| 65 | typedef struct xfs_efi_log_item { |
| 66 | xfs_log_item_t efi_item; |
Dave Chinner | 666d644 | 2013-04-03 14:09:21 +1100 | [diff] [blame] | 67 | atomic_t efi_refcount; |
Dave Chinner | b199c8a | 2010-12-20 11:59:49 +1100 | [diff] [blame] | 68 | atomic_t efi_next_extent; |
| 69 | unsigned long efi_flags; /* misc flags */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | xfs_efi_log_format_t efi_format; |
| 71 | } xfs_efi_log_item_t; |
| 72 | |
| 73 | /* |
| 74 | * This is the "extent free done" log item. It is used to log |
| 75 | * the fact that some extents earlier mentioned in an efi item |
| 76 | * have been freed. |
| 77 | */ |
| 78 | typedef struct xfs_efd_log_item { |
| 79 | xfs_log_item_t efd_item; |
| 80 | xfs_efi_log_item_t *efd_efip; |
| 81 | uint efd_next_extent; |
| 82 | xfs_efd_log_format_t efd_format; |
| 83 | } xfs_efd_log_item_t; |
| 84 | |
| 85 | /* |
| 86 | * Max number of extents in fast allocation path. |
| 87 | */ |
| 88 | #define XFS_EFD_MAX_FAST_EXTENTS 16 |
| 89 | |
| 90 | extern struct kmem_zone *xfs_efi_zone; |
| 91 | extern struct kmem_zone *xfs_efd_zone; |
| 92 | |
| 93 | xfs_efi_log_item_t *xfs_efi_init(struct xfs_mount *, uint); |
| 94 | xfs_efd_log_item_t *xfs_efd_init(struct xfs_mount *, xfs_efi_log_item_t *, |
| 95 | uint); |
Tim Shimmin | 6d192a9 | 2006-06-09 14:55:38 +1000 | [diff] [blame] | 96 | int xfs_efi_copy_format(xfs_log_iovec_t *buf, |
| 97 | xfs_efi_log_format_t *dst_efi_fmt); |
Christoph Hellwig | 7d795ca | 2005-06-21 15:41:19 +1000 | [diff] [blame] | 98 | void xfs_efi_item_free(xfs_efi_log_item_t *); |
Brian Foster | 5e4b538 | 2015-08-19 09:50:12 +1000 | [diff] [blame] | 99 | void xfs_efi_release(struct xfs_efi_log_item *); |
Christoph Hellwig | 7d795ca | 2005-06-21 15:41:19 +1000 | [diff] [blame] | 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | #endif /* __XFS_EXTFREE_ITEM_H__ */ |