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