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" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 9 | #include "xfs_log_format.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 10 | #include "xfs_trans.h" |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 11 | #include "xfs_trans_priv.h" |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 12 | #include "xfs_icreate_item.h" |
Christoph Hellwig | 1234351 | 2013-12-13 11:00:43 +1100 | [diff] [blame] | 13 | #include "xfs_log.h" |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 14 | |
| 15 | kmem_zone_t *xfs_icreate_zone; /* inode create item zone */ |
| 16 | |
| 17 | static inline struct xfs_icreate_item *ICR_ITEM(struct xfs_log_item *lip) |
| 18 | { |
| 19 | return container_of(lip, struct xfs_icreate_item, ic_item); |
| 20 | } |
| 21 | |
| 22 | /* |
| 23 | * This returns the number of iovecs needed to log the given inode item. |
| 24 | * |
| 25 | * We only need one iovec for the icreate log structure. |
| 26 | */ |
Dave Chinner | 166d136 | 2013-08-12 20:50:04 +1000 | [diff] [blame] | 27 | STATIC void |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 28 | xfs_icreate_item_size( |
Dave Chinner | 166d136 | 2013-08-12 20:50:04 +1000 | [diff] [blame] | 29 | struct xfs_log_item *lip, |
| 30 | int *nvecs, |
| 31 | int *nbytes) |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 32 | { |
Dave Chinner | 166d136 | 2013-08-12 20:50:04 +1000 | [diff] [blame] | 33 | *nvecs += 1; |
| 34 | *nbytes += sizeof(struct xfs_icreate_log); |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | /* |
| 38 | * This is called to fill in the vector of log iovecs for the |
| 39 | * given inode create log item. |
| 40 | */ |
| 41 | STATIC void |
| 42 | xfs_icreate_item_format( |
| 43 | struct xfs_log_item *lip, |
Christoph Hellwig | bde7cff | 2013-12-13 11:34:02 +1100 | [diff] [blame] | 44 | struct xfs_log_vec *lv) |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 45 | { |
| 46 | struct xfs_icreate_item *icp = ICR_ITEM(lip); |
Christoph Hellwig | bde7cff | 2013-12-13 11:34:02 +1100 | [diff] [blame] | 47 | struct xfs_log_iovec *vecp = NULL; |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 48 | |
Christoph Hellwig | bde7cff | 2013-12-13 11:34:02 +1100 | [diff] [blame] | 49 | xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_ICREATE, |
Christoph Hellwig | 1234351 | 2013-12-13 11:00:43 +1100 | [diff] [blame] | 50 | &icp->ic_format, |
| 51 | sizeof(struct xfs_icreate_log)); |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 52 | } |
| 53 | |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 54 | STATIC void |
Christoph Hellwig | ddf9205 | 2019-06-28 19:27:32 -0700 | [diff] [blame] | 55 | xfs_icreate_item_release( |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 56 | struct xfs_log_item *lip) |
| 57 | { |
Christoph Hellwig | ddf9205 | 2019-06-28 19:27:32 -0700 | [diff] [blame] | 58 | kmem_zone_free(xfs_icreate_zone, ICR_ITEM(lip)); |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 59 | } |
| 60 | |
Bhumika Goyal | bb6e0eb | 2016-11-28 14:57:42 +1100 | [diff] [blame] | 61 | static const struct xfs_item_ops xfs_icreate_item_ops = { |
Christoph Hellwig | 9ce632a | 2019-06-28 19:27:32 -0700 | [diff] [blame] | 62 | .flags = XFS_ITEM_RELEASE_WHEN_COMMITTED, |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 63 | .iop_size = xfs_icreate_item_size, |
| 64 | .iop_format = xfs_icreate_item_format, |
Christoph Hellwig | ddf9205 | 2019-06-28 19:27:32 -0700 | [diff] [blame] | 65 | .iop_release = xfs_icreate_item_release, |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | |
| 69 | /* |
| 70 | * Initialize the inode log item for a newly allocated (in-core) inode. |
| 71 | * |
| 72 | * Inode extents can only reside within an AG. Hence specify the starting |
| 73 | * block for the inode chunk by offset within an AG as well as the |
| 74 | * length of the allocated extent. |
| 75 | * |
| 76 | * This joins the item to the transaction and marks it dirty so |
| 77 | * that we don't need a separate call to do this, nor does the |
| 78 | * caller need to know anything about the icreate item. |
| 79 | */ |
| 80 | void |
| 81 | xfs_icreate_log( |
| 82 | struct xfs_trans *tp, |
| 83 | xfs_agnumber_t agno, |
| 84 | xfs_agblock_t agbno, |
| 85 | unsigned int count, |
| 86 | unsigned int inode_size, |
| 87 | xfs_agblock_t length, |
| 88 | unsigned int generation) |
| 89 | { |
| 90 | struct xfs_icreate_item *icp; |
| 91 | |
| 92 | icp = kmem_zone_zalloc(xfs_icreate_zone, KM_SLEEP); |
| 93 | |
| 94 | xfs_log_item_init(tp->t_mountp, &icp->ic_item, XFS_LI_ICREATE, |
| 95 | &xfs_icreate_item_ops); |
| 96 | |
| 97 | icp->ic_format.icl_type = XFS_LI_ICREATE; |
| 98 | icp->ic_format.icl_size = 1; /* single vector */ |
| 99 | icp->ic_format.icl_ag = cpu_to_be32(agno); |
| 100 | icp->ic_format.icl_agbno = cpu_to_be32(agbno); |
| 101 | icp->ic_format.icl_count = cpu_to_be32(count); |
| 102 | icp->ic_format.icl_isize = cpu_to_be32(inode_size); |
| 103 | icp->ic_format.icl_length = cpu_to_be32(length); |
| 104 | icp->ic_format.icl_gen = cpu_to_be32(generation); |
| 105 | |
| 106 | xfs_trans_add_item(tp, &icp->ic_item); |
| 107 | tp->t_flags |= XFS_TRANS_DIRTY; |
Dave Chinner | e6631f8 | 2018-05-09 07:49:37 -0700 | [diff] [blame] | 108 | set_bit(XFS_LI_DIRTY, &icp->ic_item.li_flags); |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 109 | } |