1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Copyright (c) 2000-2005 Silicon Graphics, Inc.
4*4882a593Smuzhiyun * Copyright (c) 2013 Red Hat, Inc.
5*4882a593Smuzhiyun * All Rights Reserved.
6*4882a593Smuzhiyun */
7*4882a593Smuzhiyun #include "xfs.h"
8*4882a593Smuzhiyun #include "xfs_fs.h"
9*4882a593Smuzhiyun #include "xfs_shared.h"
10*4882a593Smuzhiyun #include "xfs_format.h"
11*4882a593Smuzhiyun #include "xfs_log_format.h"
12*4882a593Smuzhiyun #include "xfs_trans_resv.h"
13*4882a593Smuzhiyun #include "xfs_bit.h"
14*4882a593Smuzhiyun #include "xfs_mount.h"
15*4882a593Smuzhiyun #include "xfs_da_format.h"
16*4882a593Smuzhiyun #include "xfs_da_btree.h"
17*4882a593Smuzhiyun #include "xfs_inode.h"
18*4882a593Smuzhiyun #include "xfs_attr_remote.h"
19*4882a593Smuzhiyun #include "xfs_trans.h"
20*4882a593Smuzhiyun #include "xfs_bmap.h"
21*4882a593Smuzhiyun #include "xfs_attr.h"
22*4882a593Smuzhiyun #include "xfs_attr_leaf.h"
23*4882a593Smuzhiyun #include "xfs_quota.h"
24*4882a593Smuzhiyun #include "xfs_dir2.h"
25*4882a593Smuzhiyun #include "xfs_error.h"
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun /*
28*4882a593Smuzhiyun * Invalidate any incore buffers associated with this remote attribute value
29*4882a593Smuzhiyun * extent. We never log remote attribute value buffers, which means that they
30*4882a593Smuzhiyun * won't be attached to a transaction and are therefore safe to mark stale.
31*4882a593Smuzhiyun * The actual bunmapi will be taken care of later.
32*4882a593Smuzhiyun */
33*4882a593Smuzhiyun STATIC int
xfs_attr3_rmt_stale(struct xfs_inode * dp,xfs_dablk_t blkno,int blkcnt)34*4882a593Smuzhiyun xfs_attr3_rmt_stale(
35*4882a593Smuzhiyun struct xfs_inode *dp,
36*4882a593Smuzhiyun xfs_dablk_t blkno,
37*4882a593Smuzhiyun int blkcnt)
38*4882a593Smuzhiyun {
39*4882a593Smuzhiyun struct xfs_bmbt_irec map;
40*4882a593Smuzhiyun int nmap;
41*4882a593Smuzhiyun int error;
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun /*
44*4882a593Smuzhiyun * Roll through the "value", invalidating the attribute value's
45*4882a593Smuzhiyun * blocks.
46*4882a593Smuzhiyun */
47*4882a593Smuzhiyun while (blkcnt > 0) {
48*4882a593Smuzhiyun /*
49*4882a593Smuzhiyun * Try to remember where we decided to put the value.
50*4882a593Smuzhiyun */
51*4882a593Smuzhiyun nmap = 1;
52*4882a593Smuzhiyun error = xfs_bmapi_read(dp, (xfs_fileoff_t)blkno, blkcnt,
53*4882a593Smuzhiyun &map, &nmap, XFS_BMAPI_ATTRFORK);
54*4882a593Smuzhiyun if (error)
55*4882a593Smuzhiyun return error;
56*4882a593Smuzhiyun if (XFS_IS_CORRUPT(dp->i_mount, nmap != 1))
57*4882a593Smuzhiyun return -EFSCORRUPTED;
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun /*
60*4882a593Smuzhiyun * Mark any incore buffers for the remote value as stale. We
61*4882a593Smuzhiyun * never log remote attr value buffers, so the buffer should be
62*4882a593Smuzhiyun * easy to kill.
63*4882a593Smuzhiyun */
64*4882a593Smuzhiyun error = xfs_attr_rmtval_stale(dp, &map, 0);
65*4882a593Smuzhiyun if (error)
66*4882a593Smuzhiyun return error;
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun blkno += map.br_blockcount;
69*4882a593Smuzhiyun blkcnt -= map.br_blockcount;
70*4882a593Smuzhiyun }
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun return 0;
73*4882a593Smuzhiyun }
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun /*
76*4882a593Smuzhiyun * Invalidate all of the "remote" value regions pointed to by a particular
77*4882a593Smuzhiyun * leaf block.
78*4882a593Smuzhiyun * Note that we must release the lock on the buffer so that we are not
79*4882a593Smuzhiyun * caught holding something that the logging code wants to flush to disk.
80*4882a593Smuzhiyun */
81*4882a593Smuzhiyun STATIC int
xfs_attr3_leaf_inactive(struct xfs_trans ** trans,struct xfs_inode * dp,struct xfs_buf * bp)82*4882a593Smuzhiyun xfs_attr3_leaf_inactive(
83*4882a593Smuzhiyun struct xfs_trans **trans,
84*4882a593Smuzhiyun struct xfs_inode *dp,
85*4882a593Smuzhiyun struct xfs_buf *bp)
86*4882a593Smuzhiyun {
87*4882a593Smuzhiyun struct xfs_attr3_icleaf_hdr ichdr;
88*4882a593Smuzhiyun struct xfs_mount *mp = bp->b_mount;
89*4882a593Smuzhiyun struct xfs_attr_leafblock *leaf = bp->b_addr;
90*4882a593Smuzhiyun struct xfs_attr_leaf_entry *entry;
91*4882a593Smuzhiyun struct xfs_attr_leaf_name_remote *name_rmt;
92*4882a593Smuzhiyun int error = 0;
93*4882a593Smuzhiyun int i;
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &ichdr, leaf);
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun /*
98*4882a593Smuzhiyun * Find the remote value extents for this leaf and invalidate their
99*4882a593Smuzhiyun * incore buffers.
100*4882a593Smuzhiyun */
101*4882a593Smuzhiyun entry = xfs_attr3_leaf_entryp(leaf);
102*4882a593Smuzhiyun for (i = 0; i < ichdr.count; entry++, i++) {
103*4882a593Smuzhiyun int blkcnt;
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun if (!entry->nameidx || (entry->flags & XFS_ATTR_LOCAL))
106*4882a593Smuzhiyun continue;
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun name_rmt = xfs_attr3_leaf_name_remote(leaf, i);
109*4882a593Smuzhiyun if (!name_rmt->valueblk)
110*4882a593Smuzhiyun continue;
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun blkcnt = xfs_attr3_rmt_blocks(dp->i_mount,
113*4882a593Smuzhiyun be32_to_cpu(name_rmt->valuelen));
114*4882a593Smuzhiyun error = xfs_attr3_rmt_stale(dp,
115*4882a593Smuzhiyun be32_to_cpu(name_rmt->valueblk), blkcnt);
116*4882a593Smuzhiyun if (error)
117*4882a593Smuzhiyun goto err;
118*4882a593Smuzhiyun }
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun xfs_trans_brelse(*trans, bp);
121*4882a593Smuzhiyun err:
122*4882a593Smuzhiyun return error;
123*4882a593Smuzhiyun }
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun /*
126*4882a593Smuzhiyun * Recurse (gasp!) through the attribute nodes until we find leaves.
127*4882a593Smuzhiyun * We're doing a depth-first traversal in order to invalidate everything.
128*4882a593Smuzhiyun */
129*4882a593Smuzhiyun STATIC int
xfs_attr3_node_inactive(struct xfs_trans ** trans,struct xfs_inode * dp,struct xfs_buf * bp,int level)130*4882a593Smuzhiyun xfs_attr3_node_inactive(
131*4882a593Smuzhiyun struct xfs_trans **trans,
132*4882a593Smuzhiyun struct xfs_inode *dp,
133*4882a593Smuzhiyun struct xfs_buf *bp,
134*4882a593Smuzhiyun int level)
135*4882a593Smuzhiyun {
136*4882a593Smuzhiyun struct xfs_mount *mp = dp->i_mount;
137*4882a593Smuzhiyun struct xfs_da_blkinfo *info;
138*4882a593Smuzhiyun xfs_dablk_t child_fsb;
139*4882a593Smuzhiyun xfs_daddr_t parent_blkno, child_blkno;
140*4882a593Smuzhiyun struct xfs_buf *child_bp;
141*4882a593Smuzhiyun struct xfs_da3_icnode_hdr ichdr;
142*4882a593Smuzhiyun int error, i;
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun /*
145*4882a593Smuzhiyun * Since this code is recursive (gasp!) we must protect ourselves.
146*4882a593Smuzhiyun */
147*4882a593Smuzhiyun if (level > XFS_DA_NODE_MAXDEPTH) {
148*4882a593Smuzhiyun xfs_buf_mark_corrupt(bp);
149*4882a593Smuzhiyun xfs_trans_brelse(*trans, bp); /* no locks for later trans */
150*4882a593Smuzhiyun return -EFSCORRUPTED;
151*4882a593Smuzhiyun }
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun xfs_da3_node_hdr_from_disk(dp->i_mount, &ichdr, bp->b_addr);
154*4882a593Smuzhiyun parent_blkno = bp->b_bn;
155*4882a593Smuzhiyun if (!ichdr.count) {
156*4882a593Smuzhiyun xfs_trans_brelse(*trans, bp);
157*4882a593Smuzhiyun return 0;
158*4882a593Smuzhiyun }
159*4882a593Smuzhiyun child_fsb = be32_to_cpu(ichdr.btree[0].before);
160*4882a593Smuzhiyun xfs_trans_brelse(*trans, bp); /* no locks for later trans */
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun /*
163*4882a593Smuzhiyun * If this is the node level just above the leaves, simply loop
164*4882a593Smuzhiyun * over the leaves removing all of them. If this is higher up
165*4882a593Smuzhiyun * in the tree, recurse downward.
166*4882a593Smuzhiyun */
167*4882a593Smuzhiyun for (i = 0; i < ichdr.count; i++) {
168*4882a593Smuzhiyun /*
169*4882a593Smuzhiyun * Read the subsidiary block to see what we have to work with.
170*4882a593Smuzhiyun * Don't do this in a transaction. This is a depth-first
171*4882a593Smuzhiyun * traversal of the tree so we may deal with many blocks
172*4882a593Smuzhiyun * before we come back to this one.
173*4882a593Smuzhiyun */
174*4882a593Smuzhiyun error = xfs_da3_node_read(*trans, dp, child_fsb, &child_bp,
175*4882a593Smuzhiyun XFS_ATTR_FORK);
176*4882a593Smuzhiyun if (error)
177*4882a593Smuzhiyun return error;
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun /* save for re-read later */
180*4882a593Smuzhiyun child_blkno = XFS_BUF_ADDR(child_bp);
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun /*
183*4882a593Smuzhiyun * Invalidate the subtree, however we have to.
184*4882a593Smuzhiyun */
185*4882a593Smuzhiyun info = child_bp->b_addr;
186*4882a593Smuzhiyun switch (info->magic) {
187*4882a593Smuzhiyun case cpu_to_be16(XFS_DA_NODE_MAGIC):
188*4882a593Smuzhiyun case cpu_to_be16(XFS_DA3_NODE_MAGIC):
189*4882a593Smuzhiyun error = xfs_attr3_node_inactive(trans, dp, child_bp,
190*4882a593Smuzhiyun level + 1);
191*4882a593Smuzhiyun break;
192*4882a593Smuzhiyun case cpu_to_be16(XFS_ATTR_LEAF_MAGIC):
193*4882a593Smuzhiyun case cpu_to_be16(XFS_ATTR3_LEAF_MAGIC):
194*4882a593Smuzhiyun error = xfs_attr3_leaf_inactive(trans, dp, child_bp);
195*4882a593Smuzhiyun break;
196*4882a593Smuzhiyun default:
197*4882a593Smuzhiyun xfs_buf_mark_corrupt(child_bp);
198*4882a593Smuzhiyun xfs_trans_brelse(*trans, child_bp);
199*4882a593Smuzhiyun error = -EFSCORRUPTED;
200*4882a593Smuzhiyun break;
201*4882a593Smuzhiyun }
202*4882a593Smuzhiyun if (error)
203*4882a593Smuzhiyun return error;
204*4882a593Smuzhiyun
205*4882a593Smuzhiyun /*
206*4882a593Smuzhiyun * Remove the subsidiary block from the cache and from the log.
207*4882a593Smuzhiyun */
208*4882a593Smuzhiyun error = xfs_trans_get_buf(*trans, mp->m_ddev_targp,
209*4882a593Smuzhiyun child_blkno,
210*4882a593Smuzhiyun XFS_FSB_TO_BB(mp, mp->m_attr_geo->fsbcount), 0,
211*4882a593Smuzhiyun &child_bp);
212*4882a593Smuzhiyun if (error)
213*4882a593Smuzhiyun return error;
214*4882a593Smuzhiyun error = bp->b_error;
215*4882a593Smuzhiyun if (error) {
216*4882a593Smuzhiyun xfs_trans_brelse(*trans, child_bp);
217*4882a593Smuzhiyun return error;
218*4882a593Smuzhiyun }
219*4882a593Smuzhiyun xfs_trans_binval(*trans, child_bp);
220*4882a593Smuzhiyun
221*4882a593Smuzhiyun /*
222*4882a593Smuzhiyun * If we're not done, re-read the parent to get the next
223*4882a593Smuzhiyun * child block number.
224*4882a593Smuzhiyun */
225*4882a593Smuzhiyun if (i + 1 < ichdr.count) {
226*4882a593Smuzhiyun struct xfs_da3_icnode_hdr phdr;
227*4882a593Smuzhiyun
228*4882a593Smuzhiyun error = xfs_da3_node_read_mapped(*trans, dp,
229*4882a593Smuzhiyun parent_blkno, &bp, XFS_ATTR_FORK);
230*4882a593Smuzhiyun if (error)
231*4882a593Smuzhiyun return error;
232*4882a593Smuzhiyun xfs_da3_node_hdr_from_disk(dp->i_mount, &phdr,
233*4882a593Smuzhiyun bp->b_addr);
234*4882a593Smuzhiyun child_fsb = be32_to_cpu(phdr.btree[i + 1].before);
235*4882a593Smuzhiyun xfs_trans_brelse(*trans, bp);
236*4882a593Smuzhiyun }
237*4882a593Smuzhiyun /*
238*4882a593Smuzhiyun * Atomically commit the whole invalidate stuff.
239*4882a593Smuzhiyun */
240*4882a593Smuzhiyun error = xfs_trans_roll_inode(trans, dp);
241*4882a593Smuzhiyun if (error)
242*4882a593Smuzhiyun return error;
243*4882a593Smuzhiyun }
244*4882a593Smuzhiyun
245*4882a593Smuzhiyun return 0;
246*4882a593Smuzhiyun }
247*4882a593Smuzhiyun
248*4882a593Smuzhiyun /*
249*4882a593Smuzhiyun * Indiscriminately delete the entire attribute fork
250*4882a593Smuzhiyun *
251*4882a593Smuzhiyun * Recurse (gasp!) through the attribute nodes until we find leaves.
252*4882a593Smuzhiyun * We're doing a depth-first traversal in order to invalidate everything.
253*4882a593Smuzhiyun */
254*4882a593Smuzhiyun static int
xfs_attr3_root_inactive(struct xfs_trans ** trans,struct xfs_inode * dp)255*4882a593Smuzhiyun xfs_attr3_root_inactive(
256*4882a593Smuzhiyun struct xfs_trans **trans,
257*4882a593Smuzhiyun struct xfs_inode *dp)
258*4882a593Smuzhiyun {
259*4882a593Smuzhiyun struct xfs_mount *mp = dp->i_mount;
260*4882a593Smuzhiyun struct xfs_da_blkinfo *info;
261*4882a593Smuzhiyun struct xfs_buf *bp;
262*4882a593Smuzhiyun xfs_daddr_t blkno;
263*4882a593Smuzhiyun int error;
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun /*
266*4882a593Smuzhiyun * Read block 0 to see what we have to work with.
267*4882a593Smuzhiyun * We only get here if we have extents, since we remove
268*4882a593Smuzhiyun * the extents in reverse order the extent containing
269*4882a593Smuzhiyun * block 0 must still be there.
270*4882a593Smuzhiyun */
271*4882a593Smuzhiyun error = xfs_da3_node_read(*trans, dp, 0, &bp, XFS_ATTR_FORK);
272*4882a593Smuzhiyun if (error)
273*4882a593Smuzhiyun return error;
274*4882a593Smuzhiyun blkno = bp->b_bn;
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun /*
277*4882a593Smuzhiyun * Invalidate the tree, even if the "tree" is only a single leaf block.
278*4882a593Smuzhiyun * This is a depth-first traversal!
279*4882a593Smuzhiyun */
280*4882a593Smuzhiyun info = bp->b_addr;
281*4882a593Smuzhiyun switch (info->magic) {
282*4882a593Smuzhiyun case cpu_to_be16(XFS_DA_NODE_MAGIC):
283*4882a593Smuzhiyun case cpu_to_be16(XFS_DA3_NODE_MAGIC):
284*4882a593Smuzhiyun error = xfs_attr3_node_inactive(trans, dp, bp, 1);
285*4882a593Smuzhiyun break;
286*4882a593Smuzhiyun case cpu_to_be16(XFS_ATTR_LEAF_MAGIC):
287*4882a593Smuzhiyun case cpu_to_be16(XFS_ATTR3_LEAF_MAGIC):
288*4882a593Smuzhiyun error = xfs_attr3_leaf_inactive(trans, dp, bp);
289*4882a593Smuzhiyun break;
290*4882a593Smuzhiyun default:
291*4882a593Smuzhiyun error = -EFSCORRUPTED;
292*4882a593Smuzhiyun xfs_buf_mark_corrupt(bp);
293*4882a593Smuzhiyun xfs_trans_brelse(*trans, bp);
294*4882a593Smuzhiyun break;
295*4882a593Smuzhiyun }
296*4882a593Smuzhiyun if (error)
297*4882a593Smuzhiyun return error;
298*4882a593Smuzhiyun
299*4882a593Smuzhiyun /*
300*4882a593Smuzhiyun * Invalidate the incore copy of the root block.
301*4882a593Smuzhiyun */
302*4882a593Smuzhiyun error = xfs_trans_get_buf(*trans, mp->m_ddev_targp, blkno,
303*4882a593Smuzhiyun XFS_FSB_TO_BB(mp, mp->m_attr_geo->fsbcount), 0, &bp);
304*4882a593Smuzhiyun if (error)
305*4882a593Smuzhiyun return error;
306*4882a593Smuzhiyun error = bp->b_error;
307*4882a593Smuzhiyun if (error) {
308*4882a593Smuzhiyun xfs_trans_brelse(*trans, bp);
309*4882a593Smuzhiyun return error;
310*4882a593Smuzhiyun }
311*4882a593Smuzhiyun xfs_trans_binval(*trans, bp); /* remove from cache */
312*4882a593Smuzhiyun /*
313*4882a593Smuzhiyun * Commit the invalidate and start the next transaction.
314*4882a593Smuzhiyun */
315*4882a593Smuzhiyun error = xfs_trans_roll_inode(trans, dp);
316*4882a593Smuzhiyun
317*4882a593Smuzhiyun return error;
318*4882a593Smuzhiyun }
319*4882a593Smuzhiyun
320*4882a593Smuzhiyun /*
321*4882a593Smuzhiyun * xfs_attr_inactive kills all traces of an attribute fork on an inode. It
322*4882a593Smuzhiyun * removes both the on-disk and in-memory inode fork. Note that this also has to
323*4882a593Smuzhiyun * handle the condition of inodes without attributes but with an attribute fork
324*4882a593Smuzhiyun * configured, so we can't use xfs_inode_hasattr() here.
325*4882a593Smuzhiyun *
326*4882a593Smuzhiyun * The in-memory attribute fork is removed even on error.
327*4882a593Smuzhiyun */
328*4882a593Smuzhiyun int
xfs_attr_inactive(struct xfs_inode * dp)329*4882a593Smuzhiyun xfs_attr_inactive(
330*4882a593Smuzhiyun struct xfs_inode *dp)
331*4882a593Smuzhiyun {
332*4882a593Smuzhiyun struct xfs_trans *trans;
333*4882a593Smuzhiyun struct xfs_mount *mp;
334*4882a593Smuzhiyun int lock_mode = XFS_ILOCK_SHARED;
335*4882a593Smuzhiyun int error = 0;
336*4882a593Smuzhiyun
337*4882a593Smuzhiyun mp = dp->i_mount;
338*4882a593Smuzhiyun ASSERT(! XFS_NOT_DQATTACHED(mp, dp));
339*4882a593Smuzhiyun
340*4882a593Smuzhiyun xfs_ilock(dp, lock_mode);
341*4882a593Smuzhiyun if (!XFS_IFORK_Q(dp))
342*4882a593Smuzhiyun goto out_destroy_fork;
343*4882a593Smuzhiyun xfs_iunlock(dp, lock_mode);
344*4882a593Smuzhiyun
345*4882a593Smuzhiyun lock_mode = 0;
346*4882a593Smuzhiyun
347*4882a593Smuzhiyun error = xfs_trans_alloc(mp, &M_RES(mp)->tr_attrinval, 0, 0, 0, &trans);
348*4882a593Smuzhiyun if (error)
349*4882a593Smuzhiyun goto out_destroy_fork;
350*4882a593Smuzhiyun
351*4882a593Smuzhiyun lock_mode = XFS_ILOCK_EXCL;
352*4882a593Smuzhiyun xfs_ilock(dp, lock_mode);
353*4882a593Smuzhiyun
354*4882a593Smuzhiyun if (!XFS_IFORK_Q(dp))
355*4882a593Smuzhiyun goto out_cancel;
356*4882a593Smuzhiyun
357*4882a593Smuzhiyun /*
358*4882a593Smuzhiyun * No need to make quota reservations here. We expect to release some
359*4882a593Smuzhiyun * blocks, not allocate, in the common case.
360*4882a593Smuzhiyun */
361*4882a593Smuzhiyun xfs_trans_ijoin(trans, dp, 0);
362*4882a593Smuzhiyun
363*4882a593Smuzhiyun /*
364*4882a593Smuzhiyun * Invalidate and truncate the attribute fork extents. Make sure the
365*4882a593Smuzhiyun * fork actually has attributes as otherwise the invalidation has no
366*4882a593Smuzhiyun * blocks to read and returns an error. In this case, just do the fork
367*4882a593Smuzhiyun * removal below.
368*4882a593Smuzhiyun */
369*4882a593Smuzhiyun if (xfs_inode_hasattr(dp) &&
370*4882a593Smuzhiyun dp->i_afp->if_format != XFS_DINODE_FMT_LOCAL) {
371*4882a593Smuzhiyun error = xfs_attr3_root_inactive(&trans, dp);
372*4882a593Smuzhiyun if (error)
373*4882a593Smuzhiyun goto out_cancel;
374*4882a593Smuzhiyun
375*4882a593Smuzhiyun error = xfs_itruncate_extents(&trans, dp, XFS_ATTR_FORK, 0);
376*4882a593Smuzhiyun if (error)
377*4882a593Smuzhiyun goto out_cancel;
378*4882a593Smuzhiyun }
379*4882a593Smuzhiyun
380*4882a593Smuzhiyun /* Reset the attribute fork - this also destroys the in-core fork */
381*4882a593Smuzhiyun xfs_attr_fork_remove(dp, trans);
382*4882a593Smuzhiyun
383*4882a593Smuzhiyun error = xfs_trans_commit(trans);
384*4882a593Smuzhiyun xfs_iunlock(dp, lock_mode);
385*4882a593Smuzhiyun return error;
386*4882a593Smuzhiyun
387*4882a593Smuzhiyun out_cancel:
388*4882a593Smuzhiyun xfs_trans_cancel(trans);
389*4882a593Smuzhiyun out_destroy_fork:
390*4882a593Smuzhiyun /* kill the in-core attr fork before we drop the inode lock */
391*4882a593Smuzhiyun if (dp->i_afp) {
392*4882a593Smuzhiyun xfs_idestroy_fork(dp->i_afp);
393*4882a593Smuzhiyun kmem_cache_free(xfs_ifork_zone, dp->i_afp);
394*4882a593Smuzhiyun dp->i_afp = NULL;
395*4882a593Smuzhiyun }
396*4882a593Smuzhiyun if (lock_mode)
397*4882a593Smuzhiyun xfs_iunlock(dp, lock_mode);
398*4882a593Smuzhiyun return error;
399*4882a593Smuzhiyun }
400