Darrick J. Wong | 4e0cc29 | 2016-08-03 11:12:25 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 Oracle. All Rights Reserved. |
| 3 | * |
| 4 | * Author: Darrick J. Wong <darrick.wong@oracle.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version 2 |
| 9 | * of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it would be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write the Free Software Foundation, |
| 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | */ |
| 20 | #ifndef __XFS_DEFER_H__ |
| 21 | #define __XFS_DEFER_H__ |
| 22 | |
| 23 | struct xfs_defer_op_type; |
| 24 | |
| 25 | /* |
| 26 | * Save a log intent item and a list of extents, so that we can replay |
| 27 | * whatever action had to happen to the extent list and file the log done |
| 28 | * item. |
| 29 | */ |
| 30 | struct xfs_defer_pending { |
| 31 | const struct xfs_defer_op_type *dfp_type; /* function pointers */ |
| 32 | struct list_head dfp_list; /* pending items */ |
Darrick J. Wong | 4e0cc29 | 2016-08-03 11:12:25 +1000 | [diff] [blame] | 33 | void *dfp_intent; /* log intent item */ |
Darrick J. Wong | ea78d80 | 2016-08-30 13:51:39 +1000 | [diff] [blame] | 34 | void *dfp_done; /* log done item */ |
Darrick J. Wong | 4e0cc29 | 2016-08-03 11:12:25 +1000 | [diff] [blame] | 35 | struct list_head dfp_work; /* work items */ |
| 36 | unsigned int dfp_count; /* # extent items */ |
| 37 | }; |
| 38 | |
| 39 | /* |
| 40 | * Header for deferred operation list. |
| 41 | * |
| 42 | * dop_low is used by the allocator to activate the lowspace algorithm - |
| 43 | * when free space is running low the extent allocator may choose to |
| 44 | * allocate an extent from an AG without leaving sufficient space for |
| 45 | * a btree split when inserting the new extent. In this case the allocator |
| 46 | * will enable the lowspace algorithm which is supposed to allow further |
| 47 | * allocations (such as btree splits and newroots) to allocate from |
| 48 | * sequential AGs. In order to avoid locking AGs out of order the lowspace |
| 49 | * algorithm will start searching for free space from AG 0. If the correct |
| 50 | * transaction reservations have been made then this algorithm will eventually |
| 51 | * find all the space it needs. |
| 52 | */ |
| 53 | enum xfs_defer_ops_type { |
Darrick J. Wong | 9f3afb5 | 2016-10-03 09:11:28 -0700 | [diff] [blame] | 54 | XFS_DEFER_OPS_TYPE_BMAP, |
Darrick J. Wong | 33ba612 | 2016-10-03 09:11:22 -0700 | [diff] [blame] | 55 | XFS_DEFER_OPS_TYPE_REFCOUNT, |
Darrick J. Wong | f8dbebe | 2016-08-03 12:11:01 +1000 | [diff] [blame] | 56 | XFS_DEFER_OPS_TYPE_RMAP, |
Darrick J. Wong | 9749fee | 2016-08-03 11:14:35 +1000 | [diff] [blame] | 57 | XFS_DEFER_OPS_TYPE_FREE, |
Darrick J. Wong | 4e0cc29 | 2016-08-03 11:12:25 +1000 | [diff] [blame] | 58 | XFS_DEFER_OPS_TYPE_MAX, |
| 59 | }; |
| 60 | |
| 61 | #define XFS_DEFER_OPS_NR_INODES 2 /* join up to two inodes */ |
| 62 | |
| 63 | struct xfs_defer_ops { |
| 64 | bool dop_committed; /* did any trans commit? */ |
| 65 | bool dop_low; /* alloc in low mode */ |
| 66 | struct list_head dop_intake; /* unlogged pending work */ |
| 67 | struct list_head dop_pending; /* logged pending work */ |
| 68 | |
| 69 | /* relog these inodes with each roll */ |
| 70 | struct xfs_inode *dop_inodes[XFS_DEFER_OPS_NR_INODES]; |
| 71 | }; |
| 72 | |
| 73 | void xfs_defer_add(struct xfs_defer_ops *dop, enum xfs_defer_ops_type type, |
| 74 | struct list_head *h); |
| 75 | int xfs_defer_finish(struct xfs_trans **tp, struct xfs_defer_ops *dop, |
| 76 | struct xfs_inode *ip); |
| 77 | void xfs_defer_cancel(struct xfs_defer_ops *dop); |
| 78 | void xfs_defer_init(struct xfs_defer_ops *dop, xfs_fsblock_t *fbp); |
| 79 | bool xfs_defer_has_unfinished_work(struct xfs_defer_ops *dop); |
| 80 | int xfs_defer_join(struct xfs_defer_ops *dop, struct xfs_inode *ip); |
| 81 | |
| 82 | /* Description of a deferred type. */ |
| 83 | struct xfs_defer_op_type { |
| 84 | enum xfs_defer_ops_type type; |
| 85 | unsigned int max_items; |
| 86 | void (*abort_intent)(void *); |
| 87 | void *(*create_done)(struct xfs_trans *, void *, unsigned int); |
| 88 | int (*finish_item)(struct xfs_trans *, struct xfs_defer_ops *, |
| 89 | struct list_head *, void *, void **); |
| 90 | void (*finish_cleanup)(struct xfs_trans *, void *, int); |
| 91 | void (*cancel_item)(struct list_head *); |
| 92 | int (*diff_items)(void *, struct list_head *, struct list_head *); |
| 93 | void *(*create_intent)(struct xfs_trans *, uint); |
| 94 | void (*log_item)(struct xfs_trans *, void *, struct list_head *); |
| 95 | }; |
| 96 | |
| 97 | void xfs_defer_init_op_type(const struct xfs_defer_op_type *type); |
| 98 | |
Darrick J. Wong | 4e0cc29 | 2016-08-03 11:12:25 +1000 | [diff] [blame] | 99 | #endif /* __XFS_DEFER_H__ */ |