Dave Chinner | 0b61f8a | 2018-06-05 19:42:14 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2008-2010, 2013 Dave Chinner |
| 4 | * All Rights Reserved. |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 5 | */ |
| 6 | #include "xfs.h" |
| 7 | #include "xfs_fs.h" |
Dave Chinner | 70a9883 | 2013-10-23 10:36:05 +1100 | [diff] [blame] | 8 | #include "xfs_shared.h" |
Christoph Hellwig | 4fb6e8a | 2014-11-28 14:25:04 +1100 | [diff] [blame] | 9 | #include "xfs_format.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 10 | #include "xfs_log_format.h" |
| 11 | #include "xfs_trans_resv.h" |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 12 | #include "xfs_bit.h" |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 13 | #include "xfs_mount.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 14 | #include "xfs_trans.h" |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 15 | #include "xfs_trans_priv.h" |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 16 | #include "xfs_error.h" |
| 17 | #include "xfs_icreate_item.h" |
Christoph Hellwig | 1234351 | 2013-12-13 11:00:43 +1100 | [diff] [blame] | 18 | #include "xfs_log.h" |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 19 | |
| 20 | kmem_zone_t *xfs_icreate_zone; /* inode create item zone */ |
| 21 | |
| 22 | static inline struct xfs_icreate_item *ICR_ITEM(struct xfs_log_item *lip) |
| 23 | { |
| 24 | return container_of(lip, struct xfs_icreate_item, ic_item); |
| 25 | } |
| 26 | |
| 27 | /* |
| 28 | * This returns the number of iovecs needed to log the given inode item. |
| 29 | * |
| 30 | * We only need one iovec for the icreate log structure. |
| 31 | */ |
Dave Chinner | 166d136 | 2013-08-12 20:50:04 +1000 | [diff] [blame] | 32 | STATIC void |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 33 | xfs_icreate_item_size( |
Dave Chinner | 166d136 | 2013-08-12 20:50:04 +1000 | [diff] [blame] | 34 | struct xfs_log_item *lip, |
| 35 | int *nvecs, |
| 36 | int *nbytes) |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 37 | { |
Dave Chinner | 166d136 | 2013-08-12 20:50:04 +1000 | [diff] [blame] | 38 | *nvecs += 1; |
| 39 | *nbytes += sizeof(struct xfs_icreate_log); |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | /* |
| 43 | * This is called to fill in the vector of log iovecs for the |
| 44 | * given inode create log item. |
| 45 | */ |
| 46 | STATIC void |
| 47 | xfs_icreate_item_format( |
| 48 | struct xfs_log_item *lip, |
Christoph Hellwig | bde7cff | 2013-12-13 11:34:02 +1100 | [diff] [blame] | 49 | struct xfs_log_vec *lv) |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 50 | { |
| 51 | struct xfs_icreate_item *icp = ICR_ITEM(lip); |
Christoph Hellwig | bde7cff | 2013-12-13 11:34:02 +1100 | [diff] [blame] | 52 | struct xfs_log_iovec *vecp = NULL; |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 53 | |
Christoph Hellwig | bde7cff | 2013-12-13 11:34:02 +1100 | [diff] [blame] | 54 | xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_ICREATE, |
Christoph Hellwig | 1234351 | 2013-12-13 11:00:43 +1100 | [diff] [blame] | 55 | &icp->ic_format, |
| 56 | sizeof(struct xfs_icreate_log)); |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | |
| 60 | /* Pinning has no meaning for the create item, so just return. */ |
| 61 | STATIC void |
| 62 | xfs_icreate_item_pin( |
| 63 | struct xfs_log_item *lip) |
| 64 | { |
| 65 | } |
| 66 | |
| 67 | |
| 68 | /* pinning has no meaning for the create item, so just return. */ |
| 69 | STATIC void |
| 70 | xfs_icreate_item_unpin( |
| 71 | struct xfs_log_item *lip, |
| 72 | int remove) |
| 73 | { |
| 74 | } |
| 75 | |
| 76 | STATIC void |
| 77 | xfs_icreate_item_unlock( |
| 78 | struct xfs_log_item *lip) |
| 79 | { |
| 80 | struct xfs_icreate_item *icp = ICR_ITEM(lip); |
| 81 | |
Dave Chinner | 22525c1 | 2018-05-09 07:47:34 -0700 | [diff] [blame] | 82 | if (test_bit(XFS_LI_ABORTED, &lip->li_flags)) |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 83 | kmem_zone_free(xfs_icreate_zone, icp); |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | /* |
| 88 | * Because we have ordered buffers being tracked in the AIL for the inode |
| 89 | * creation, we don't need the create item after this. Hence we can free |
| 90 | * the log item and return -1 to tell the caller we're done with the item. |
| 91 | */ |
| 92 | STATIC xfs_lsn_t |
| 93 | xfs_icreate_item_committed( |
| 94 | struct xfs_log_item *lip, |
| 95 | xfs_lsn_t lsn) |
| 96 | { |
| 97 | struct xfs_icreate_item *icp = ICR_ITEM(lip); |
| 98 | |
| 99 | kmem_zone_free(xfs_icreate_zone, icp); |
| 100 | return (xfs_lsn_t)-1; |
| 101 | } |
| 102 | |
| 103 | /* item can never get into the AIL */ |
| 104 | STATIC uint |
| 105 | xfs_icreate_item_push( |
| 106 | struct xfs_log_item *lip, |
| 107 | struct list_head *buffer_list) |
| 108 | { |
| 109 | ASSERT(0); |
| 110 | return XFS_ITEM_SUCCESS; |
| 111 | } |
| 112 | |
| 113 | /* Ordered buffers do the dependency tracking here, so this does nothing. */ |
| 114 | STATIC void |
| 115 | xfs_icreate_item_committing( |
| 116 | struct xfs_log_item *lip, |
| 117 | xfs_lsn_t lsn) |
| 118 | { |
| 119 | } |
| 120 | |
| 121 | /* |
| 122 | * This is the ops vector shared by all buf log items. |
| 123 | */ |
Bhumika Goyal | bb6e0eb | 2016-11-28 14:57:42 +1100 | [diff] [blame] | 124 | static const struct xfs_item_ops xfs_icreate_item_ops = { |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 125 | .iop_size = xfs_icreate_item_size, |
| 126 | .iop_format = xfs_icreate_item_format, |
| 127 | .iop_pin = xfs_icreate_item_pin, |
| 128 | .iop_unpin = xfs_icreate_item_unpin, |
| 129 | .iop_push = xfs_icreate_item_push, |
| 130 | .iop_unlock = xfs_icreate_item_unlock, |
| 131 | .iop_committed = xfs_icreate_item_committed, |
| 132 | .iop_committing = xfs_icreate_item_committing, |
| 133 | }; |
| 134 | |
| 135 | |
| 136 | /* |
| 137 | * Initialize the inode log item for a newly allocated (in-core) inode. |
| 138 | * |
| 139 | * Inode extents can only reside within an AG. Hence specify the starting |
| 140 | * block for the inode chunk by offset within an AG as well as the |
| 141 | * length of the allocated extent. |
| 142 | * |
| 143 | * This joins the item to the transaction and marks it dirty so |
| 144 | * that we don't need a separate call to do this, nor does the |
| 145 | * caller need to know anything about the icreate item. |
| 146 | */ |
| 147 | void |
| 148 | xfs_icreate_log( |
| 149 | struct xfs_trans *tp, |
| 150 | xfs_agnumber_t agno, |
| 151 | xfs_agblock_t agbno, |
| 152 | unsigned int count, |
| 153 | unsigned int inode_size, |
| 154 | xfs_agblock_t length, |
| 155 | unsigned int generation) |
| 156 | { |
| 157 | struct xfs_icreate_item *icp; |
| 158 | |
| 159 | icp = kmem_zone_zalloc(xfs_icreate_zone, KM_SLEEP); |
| 160 | |
| 161 | xfs_log_item_init(tp->t_mountp, &icp->ic_item, XFS_LI_ICREATE, |
| 162 | &xfs_icreate_item_ops); |
| 163 | |
| 164 | icp->ic_format.icl_type = XFS_LI_ICREATE; |
| 165 | icp->ic_format.icl_size = 1; /* single vector */ |
| 166 | icp->ic_format.icl_ag = cpu_to_be32(agno); |
| 167 | icp->ic_format.icl_agbno = cpu_to_be32(agbno); |
| 168 | icp->ic_format.icl_count = cpu_to_be32(count); |
| 169 | icp->ic_format.icl_isize = cpu_to_be32(inode_size); |
| 170 | icp->ic_format.icl_length = cpu_to_be32(length); |
| 171 | icp->ic_format.icl_gen = cpu_to_be32(generation); |
| 172 | |
| 173 | xfs_trans_add_item(tp, &icp->ic_item); |
| 174 | tp->t_flags |= XFS_TRANS_DIRTY; |
Dave Chinner | e6631f8 | 2018-05-09 07:49:37 -0700 | [diff] [blame] | 175 | set_bit(XFS_LI_DIRTY, &icp->ic_item.li_flags); |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 176 | } |