]>
Commit | Line | Data |
---|---|---|
0b61f8a4 | 1 | // SPDX-License-Identifier: GPL-2.0 |
3ebe7d2d DC |
2 | /* |
3 | * Copyright (c) 2008-2010, 2013 Dave Chinner | |
4 | * All Rights Reserved. | |
3ebe7d2d DC |
5 | */ |
6 | #include "xfs.h" | |
7 | #include "xfs_fs.h" | |
70a9883c | 8 | #include "xfs_shared.h" |
4fb6e8ad | 9 | #include "xfs_format.h" |
239880ef DC |
10 | #include "xfs_log_format.h" |
11 | #include "xfs_trans_resv.h" | |
3ebe7d2d | 12 | #include "xfs_bit.h" |
3ebe7d2d | 13 | #include "xfs_mount.h" |
239880ef | 14 | #include "xfs_trans.h" |
3ebe7d2d | 15 | #include "xfs_trans_priv.h" |
3ebe7d2d DC |
16 | #include "xfs_error.h" |
17 | #include "xfs_icreate_item.h" | |
1234351c | 18 | #include "xfs_log.h" |
3ebe7d2d DC |
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 | */ | |
166d1368 | 32 | STATIC void |
3ebe7d2d | 33 | xfs_icreate_item_size( |
166d1368 DC |
34 | struct xfs_log_item *lip, |
35 | int *nvecs, | |
36 | int *nbytes) | |
3ebe7d2d | 37 | { |
166d1368 DC |
38 | *nvecs += 1; |
39 | *nbytes += sizeof(struct xfs_icreate_log); | |
3ebe7d2d DC |
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, | |
bde7cff6 | 49 | struct xfs_log_vec *lv) |
3ebe7d2d DC |
50 | { |
51 | struct xfs_icreate_item *icp = ICR_ITEM(lip); | |
bde7cff6 | 52 | struct xfs_log_iovec *vecp = NULL; |
3ebe7d2d | 53 | |
bde7cff6 | 54 | xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_ICREATE, |
1234351c CH |
55 | &icp->ic_format, |
56 | sizeof(struct xfs_icreate_log)); | |
3ebe7d2d DC |
57 | } |
58 | ||
3ebe7d2d | 59 | STATIC void |
ddf92053 | 60 | xfs_icreate_item_release( |
3ebe7d2d DC |
61 | struct xfs_log_item *lip) |
62 | { | |
ddf92053 | 63 | kmem_zone_free(xfs_icreate_zone, ICR_ITEM(lip)); |
3ebe7d2d DC |
64 | } |
65 | ||
66 | /* | |
67 | * Because we have ordered buffers being tracked in the AIL for the inode | |
68 | * creation, we don't need the create item after this. Hence we can free | |
69 | * the log item and return -1 to tell the caller we're done with the item. | |
70 | */ | |
71 | STATIC xfs_lsn_t | |
72 | xfs_icreate_item_committed( | |
73 | struct xfs_log_item *lip, | |
74 | xfs_lsn_t lsn) | |
75 | { | |
76 | struct xfs_icreate_item *icp = ICR_ITEM(lip); | |
77 | ||
78 | kmem_zone_free(xfs_icreate_zone, icp); | |
79 | return (xfs_lsn_t)-1; | |
80 | } | |
81 | ||
3ebe7d2d DC |
82 | /* |
83 | * This is the ops vector shared by all buf log items. | |
84 | */ | |
bb6e0ebe | 85 | static const struct xfs_item_ops xfs_icreate_item_ops = { |
3ebe7d2d DC |
86 | .iop_size = xfs_icreate_item_size, |
87 | .iop_format = xfs_icreate_item_format, | |
ddf92053 | 88 | .iop_release = xfs_icreate_item_release, |
3ebe7d2d | 89 | .iop_committed = xfs_icreate_item_committed, |
3ebe7d2d DC |
90 | }; |
91 | ||
92 | ||
93 | /* | |
94 | * Initialize the inode log item for a newly allocated (in-core) inode. | |
95 | * | |
96 | * Inode extents can only reside within an AG. Hence specify the starting | |
97 | * block for the inode chunk by offset within an AG as well as the | |
98 | * length of the allocated extent. | |
99 | * | |
100 | * This joins the item to the transaction and marks it dirty so | |
101 | * that we don't need a separate call to do this, nor does the | |
102 | * caller need to know anything about the icreate item. | |
103 | */ | |
104 | void | |
105 | xfs_icreate_log( | |
106 | struct xfs_trans *tp, | |
107 | xfs_agnumber_t agno, | |
108 | xfs_agblock_t agbno, | |
109 | unsigned int count, | |
110 | unsigned int inode_size, | |
111 | xfs_agblock_t length, | |
112 | unsigned int generation) | |
113 | { | |
114 | struct xfs_icreate_item *icp; | |
115 | ||
116 | icp = kmem_zone_zalloc(xfs_icreate_zone, KM_SLEEP); | |
117 | ||
118 | xfs_log_item_init(tp->t_mountp, &icp->ic_item, XFS_LI_ICREATE, | |
119 | &xfs_icreate_item_ops); | |
120 | ||
121 | icp->ic_format.icl_type = XFS_LI_ICREATE; | |
122 | icp->ic_format.icl_size = 1; /* single vector */ | |
123 | icp->ic_format.icl_ag = cpu_to_be32(agno); | |
124 | icp->ic_format.icl_agbno = cpu_to_be32(agbno); | |
125 | icp->ic_format.icl_count = cpu_to_be32(count); | |
126 | icp->ic_format.icl_isize = cpu_to_be32(inode_size); | |
127 | icp->ic_format.icl_length = cpu_to_be32(length); | |
128 | icp->ic_format.icl_gen = cpu_to_be32(generation); | |
129 | ||
130 | xfs_trans_add_item(tp, &icp->ic_item); | |
131 | tp->t_flags |= XFS_TRANS_DIRTY; | |
e6631f85 | 132 | set_bit(XFS_LI_DIRTY, &icp->ic_item.li_flags); |
3ebe7d2d | 133 | } |