blob: 656d6692d207f9d322f289500111cbe27ef531f7 [file] [log] [blame]
Darrick J. Wong77d61fe2016-10-03 09:11:26 -07001/*
2 * Copyright (C) 2016 Oracle. All Rights Reserved.
3 *
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it would be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20#include "xfs.h"
21#include "xfs_fs.h"
22#include "xfs_shared.h"
23#include "xfs_format.h"
24#include "xfs_log_format.h"
25#include "xfs_trans_resv.h"
26#include "xfs_mount.h"
27#include "xfs_defer.h"
28#include "xfs_trans.h"
29#include "xfs_trans_priv.h"
30#include "xfs_bmap_item.h"
31#include "xfs_alloc.h"
32#include "xfs_bmap.h"
33#include "xfs_inode.h"
34
35/*
36 * This routine is called to allocate a "bmap update done"
37 * log item.
38 */
39struct xfs_bud_log_item *
40xfs_trans_get_bud(
41 struct xfs_trans *tp,
42 struct xfs_bui_log_item *buip)
43{
44 struct xfs_bud_log_item *budp;
45
46 budp = xfs_bud_init(tp->t_mountp, buip);
47 xfs_trans_add_item(tp, &budp->bud_item);
48 return budp;
49}
50
51/*
52 * Finish an bmap update and log it to the BUD. Note that the
53 * transaction is marked dirty regardless of whether the bmap update
54 * succeeds or fails to support the BUI/BUD lifecycle rules.
55 */
56int
57xfs_trans_log_finish_bmap_update(
58 struct xfs_trans *tp,
59 struct xfs_bud_log_item *budp,
60 struct xfs_defer_ops *dop,
61 enum xfs_bmap_intent_type type,
62 struct xfs_inode *ip,
63 int whichfork,
64 xfs_fileoff_t startoff,
65 xfs_fsblock_t startblock,
66 xfs_filblks_t blockcount,
67 xfs_exntst_t state)
68{
69 int error;
70
71 error = -EFSCORRUPTED;
72
73 /*
74 * Mark the transaction dirty, even on error. This ensures the
75 * transaction is aborted, which:
76 *
77 * 1.) releases the BUI and frees the BUD
78 * 2.) shuts down the filesystem
79 */
80 tp->t_flags |= XFS_TRANS_DIRTY;
81 budp->bud_item.li_desc->lid_flags |= XFS_LID_DIRTY;
82
83 return error;
84}