]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - libxfs/logitem.c
xfs: use ->t_dfops for attr set/remove operations
[thirdparty/xfsprogs-dev.git] / libxfs / logitem.c
CommitLineData
959ef981 1// SPDX-License-Identifier: GPL-2.0
2bd0ea18 2/*
da23017d
NS
3 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
2bd0ea18
NS
5 */
6
9c799827 7#include "libxfs_priv.h"
b626fb59
DC
8#include "xfs_fs.h"
9#include "xfs_shared.h"
10#include "xfs_format.h"
11#include "xfs_log_format.h"
12#include "xfs_trans_resv.h"
13#include "xfs_mount.h"
14#include "xfs_inode_buf.h"
15#include "xfs_inode_fork.h"
16#include "xfs_inode.h"
17#include "xfs_trans.h"
2bd0ea18 18
5e656dbb
BN
19kmem_zone_t *xfs_buf_item_zone;
20kmem_zone_t *xfs_ili_zone; /* inode log item zone */
2bd0ea18 21
5e656dbb
BN
22/*
23 * Following functions from fs/xfs/xfs_trans_buf.c
24 */
25
2bd0ea18
NS
26/*
27 * Check to see if a buffer matching the given parameters is already
c40bdaa2 28 * a part of the given transaction.
2bd0ea18 29 */
5e656dbb 30xfs_buf_t *
2bd0ea18 31xfs_trans_buf_item_match(
5bfc0742 32 xfs_trans_t *tp,
75c8b434 33 struct xfs_buftarg *btp,
a2ceac1f
DC
34 struct xfs_buf_map *map,
35 int nmaps)
2bd0ea18 36{
2fdd378a
DC
37 struct xfs_log_item *lip;
38 struct xfs_buf_log_item *blip;
a2ceac1f
DC
39 int len = 0;
40 int i;
41
42 for (i = 0; i < nmaps; i++)
43 len += map[i].bm_len;
c40bdaa2 44
2fdd378a
DC
45 list_for_each_entry(lip, &tp->t_items, li_trans) {
46 blip = (struct xfs_buf_log_item *)lip;
47 if (blip->bli_item.li_type == XFS_LI_BUF &&
75c8b434 48 blip->bli_buf->b_target->dev == btp->dev &&
a2ceac1f
DC
49 XFS_BUF_ADDR(blip->bli_buf) == map[0].bm_bn &&
50 blip->bli_buf->b_bcount == BBTOB(len)) {
51 ASSERT(blip->bli_buf->b_map_count == nmaps);
2fdd378a 52 return blip->bli_buf;
a2ceac1f 53 }
2fdd378a 54 }
c40bdaa2 55
2fdd378a 56 return NULL;
2bd0ea18 57}
5e656dbb
BN
58/*
59 * The following are from fs/xfs/xfs_buf_item.c
60 */
61
2bd0ea18
NS
62/*
63 * Allocate a new buf log item to go with the given buffer.
37d086ca 64 * Set the buffer's b_log_item field to point to the new
2bd0ea18
NS
65 * buf log item. If there are other item's attached to the
66 * buffer (see xfs_buf_attach_iodone() below), then put the
67 * buf log item at the front.
68 */
69void
70xfs_buf_item_init(
5bfc0742
NS
71 xfs_buf_t *bp,
72 xfs_mount_t *mp)
2bd0ea18
NS
73{
74 xfs_log_item_t *lip;
75 xfs_buf_log_item_t *bip;
76
77#ifdef LI_DEBUG
78 fprintf(stderr, "buf_item_init for buffer %p\n", bp);
79#endif
80
81 /*
82 * Check to see if there is already a buf log item for
5000d01d 83 * this buffer. If there is, it is guaranteed to be
2bd0ea18
NS
84 * the first. If we do already have one, there is
85 * nothing to do here so return.
86 */
2bd0ea18 87 XFS_BUF_SET_BDSTRAT_FUNC(bp, xfs_bdstrat_cb);
37d086ca
CM
88 if (bp->b_log_item != NULL) {
89 lip = bp->b_log_item;
2bd0ea18
NS
90 if (lip->li_type == XFS_LI_BUF) {
91#ifdef LI_DEBUG
92 fprintf(stderr,
93 "reused buf item %p for pre-logged buffer %p\n",
94 lip, bp);
95#endif
96 return;
97 }
98 }
99
100 bip = (xfs_buf_log_item_t *)kmem_zone_zalloc(xfs_buf_item_zone,
101 KM_SLEEP);
102#ifdef LI_DEBUG
103 fprintf(stderr, "adding buf item %p for not-logged buffer %p\n",
104 bip, bp);
105#endif
106 bip->bli_item.li_type = XFS_LI_BUF;
107 bip->bli_item.li_mountp = mp;
2fdd378a 108 INIT_LIST_HEAD(&bip->bli_item.li_trans);
2bd0ea18
NS
109 bip->bli_buf = bp;
110 bip->bli_format.blf_type = XFS_LI_BUF;
14f8b681 111 bip->bli_format.blf_blkno = (int64_t)XFS_BUF_ADDR(bp);
135e4bfe 112 bip->bli_format.blf_len = (unsigned short)BTOBB(bp->b_bcount);
37d086ca 113 bp->b_log_item = bip;
2bd0ea18
NS
114}
115
116
117/*
118 * Mark bytes first through last inclusive as dirty in the buf
119 * item's bitmap.
120 */
121void
122xfs_buf_item_log(
123 xfs_buf_log_item_t *bip,
124 uint first,
125 uint last)
126{
127 /*
128 * Mark the item as having some dirty data for
129 * quick reference in xfs_buf_item_dirty.
130 */
131 bip->bli_flags |= XFS_BLI_DIRTY;
132}
133
134/*
135 * Initialize the inode log item for a newly allocated (in-core) inode.
136 */
137void
138xfs_inode_item_init(
5bfc0742
NS
139 xfs_inode_t *ip,
140 xfs_mount_t *mp)
2bd0ea18
NS
141{
142 xfs_inode_log_item_t *iip;
143
144 ASSERT(ip->i_itemp == NULL);
145 iip = ip->i_itemp = (xfs_inode_log_item_t *)
146 kmem_zone_zalloc(xfs_ili_zone, KM_SLEEP);
147#ifdef LI_DEBUG
148 fprintf(stderr, "inode_item_init for inode %llu, iip=%p\n",
149 ip->i_ino, iip);
150#endif
151
152 iip->ili_item.li_type = XFS_LI_INODE;
153 iip->ili_item.li_mountp = mp;
2fdd378a 154 INIT_LIST_HEAD(&iip->ili_item.li_trans);
2bd0ea18 155 iip->ili_inode = ip;
2bd0ea18 156}