]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - libxfs/logitem.c
libxfs: disambiguate xfs.h
[thirdparty/xfsprogs-dev.git] / libxfs / logitem.c
CommitLineData
2bd0ea18 1/*
da23017d
NS
2 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
5000d01d 4 *
da23017d
NS
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
2bd0ea18 7 * published by the Free Software Foundation.
5000d01d 8 *
da23017d
NS
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
5000d01d 13 *
da23017d
NS
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2bd0ea18
NS
17 */
18
9c799827 19#include "libxfs_priv.h"
b626fb59
DC
20#include "xfs_fs.h"
21#include "xfs_shared.h"
22#include "xfs_format.h"
23#include "xfs_log_format.h"
24#include "xfs_trans_resv.h"
25#include "xfs_mount.h"
26#include "xfs_inode_buf.h"
27#include "xfs_inode_fork.h"
28#include "xfs_inode.h"
29#include "xfs_trans.h"
2bd0ea18 30
5e656dbb
BN
31kmem_zone_t *xfs_buf_item_zone;
32kmem_zone_t *xfs_ili_zone; /* inode log item zone */
2bd0ea18 33
5e656dbb
BN
34/*
35 * Following functions from fs/xfs/xfs_trans_buf.c
36 */
37
2bd0ea18
NS
38/*
39 * Check to see if a buffer matching the given parameters is already
c40bdaa2 40 * a part of the given transaction.
2bd0ea18 41 */
5e656dbb 42xfs_buf_t *
2bd0ea18 43xfs_trans_buf_item_match(
5bfc0742 44 xfs_trans_t *tp,
75c8b434 45 struct xfs_buftarg *btp,
a2ceac1f
DC
46 struct xfs_buf_map *map,
47 int nmaps)
2bd0ea18 48{
c40bdaa2
DC
49 struct xfs_log_item_desc *lidp;
50 struct xfs_buf_log_item *blip;
a2ceac1f
DC
51 int len = 0;
52 int i;
53
54 for (i = 0; i < nmaps; i++)
55 len += map[i].bm_len;
c40bdaa2 56
c40bdaa2
DC
57 list_for_each_entry(lidp, &tp->t_items, lid_trans) {
58 blip = (struct xfs_buf_log_item *)lidp->lid_item;
59 if (blip->bli_item.li_type == XFS_LI_BUF &&
75c8b434 60 blip->bli_buf->b_target->dev == btp->dev &&
a2ceac1f
DC
61 XFS_BUF_ADDR(blip->bli_buf) == map[0].bm_bn &&
62 blip->bli_buf->b_bcount == BBTOB(len)) {
63 ASSERT(blip->bli_buf->b_map_count == nmaps);
c40bdaa2 64 return blip->bli_buf;
a2ceac1f 65 }
c40bdaa2
DC
66 }
67
68 return NULL;
2bd0ea18 69}
5e656dbb
BN
70/*
71 * The following are from fs/xfs/xfs_buf_item.c
72 */
73
2bd0ea18
NS
74/*
75 * Allocate a new buf log item to go with the given buffer.
76 * Set the buffer's b_fsprivate field to point to the new
77 * buf log item. If there are other item's attached to the
78 * buffer (see xfs_buf_attach_iodone() below), then put the
79 * buf log item at the front.
80 */
81void
82xfs_buf_item_init(
5bfc0742
NS
83 xfs_buf_t *bp,
84 xfs_mount_t *mp)
2bd0ea18
NS
85{
86 xfs_log_item_t *lip;
87 xfs_buf_log_item_t *bip;
88
89#ifdef LI_DEBUG
90 fprintf(stderr, "buf_item_init for buffer %p\n", bp);
91#endif
92
93 /*
94 * Check to see if there is already a buf log item for
5000d01d 95 * this buffer. If there is, it is guaranteed to be
2bd0ea18
NS
96 * the first. If we do already have one, there is
97 * nothing to do here so return.
98 */
99 if (XFS_BUF_FSPRIVATE3(bp, xfs_mount_t *) != mp)
100 XFS_BUF_SET_FSPRIVATE3(bp, mp);
101 XFS_BUF_SET_BDSTRAT_FUNC(bp, xfs_bdstrat_cb);
102 if (XFS_BUF_FSPRIVATE(bp, void *) != NULL) {
103 lip = XFS_BUF_FSPRIVATE(bp, xfs_log_item_t *);
104 if (lip->li_type == XFS_LI_BUF) {
105#ifdef LI_DEBUG
106 fprintf(stderr,
107 "reused buf item %p for pre-logged buffer %p\n",
108 lip, bp);
109#endif
110 return;
111 }
112 }
113
114 bip = (xfs_buf_log_item_t *)kmem_zone_zalloc(xfs_buf_item_zone,
115 KM_SLEEP);
116#ifdef LI_DEBUG
117 fprintf(stderr, "adding buf item %p for not-logged buffer %p\n",
118 bip, bp);
119#endif
120 bip->bli_item.li_type = XFS_LI_BUF;
121 bip->bli_item.li_mountp = mp;
122 bip->bli_buf = bp;
123 bip->bli_format.blf_type = XFS_LI_BUF;
124 bip->bli_format.blf_blkno = (__int64_t)XFS_BUF_ADDR(bp);
125 bip->bli_format.blf_len = (ushort)BTOBB(XFS_BUF_COUNT(bp));
126 XFS_BUF_SET_FSPRIVATE(bp, bip);
127}
128
129
130/*
131 * Mark bytes first through last inclusive as dirty in the buf
132 * item's bitmap.
133 */
134void
135xfs_buf_item_log(
136 xfs_buf_log_item_t *bip,
137 uint first,
138 uint last)
139{
140 /*
141 * Mark the item as having some dirty data for
142 * quick reference in xfs_buf_item_dirty.
143 */
144 bip->bli_flags |= XFS_BLI_DIRTY;
145}
146
147/*
148 * Initialize the inode log item for a newly allocated (in-core) inode.
149 */
150void
151xfs_inode_item_init(
5bfc0742
NS
152 xfs_inode_t *ip,
153 xfs_mount_t *mp)
2bd0ea18
NS
154{
155 xfs_inode_log_item_t *iip;
156
157 ASSERT(ip->i_itemp == NULL);
158 iip = ip->i_itemp = (xfs_inode_log_item_t *)
159 kmem_zone_zalloc(xfs_ili_zone, KM_SLEEP);
160#ifdef LI_DEBUG
161 fprintf(stderr, "inode_item_init for inode %llu, iip=%p\n",
162 ip->i_ino, iip);
163#endif
164
165 iip->ili_item.li_type = XFS_LI_INODE;
166 iip->ili_item.li_mountp = mp;
167 iip->ili_inode = ip;
168 iip->ili_format.ilf_type = XFS_LI_INODE;
169 iip->ili_format.ilf_ino = ip->i_ino;
56b2de80
DC
170 iip->ili_format.ilf_blkno = ip->i_imap.im_blkno;
171 iip->ili_format.ilf_len = ip->i_imap.im_len;
172 iip->ili_format.ilf_boffset = ip->i_imap.im_boffset;
2bd0ea18 173}