blob: 27cce2a9c7e9108debaab50b96a92a2c0109cb39 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "xfs.h"
Nathan Scotta844f452005-11-02 14:38:42 +110019#include "xfs_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include "xfs_types.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include "xfs_log.h"
Nathan Scotta844f452005-11-02 14:38:42 +110022#include "xfs_inum.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include "xfs_trans.h"
24#include "xfs_sb.h"
David Chinnerda353b02007-08-28 14:00:13 +100025#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include "xfs_dmapi.h"
27#include "xfs_mount.h"
28#include "xfs_trans_priv.h"
29#include "xfs_extfree_item.h"
30
31/*
32 * This routine is called to allocate an "extent free intention"
33 * log item that will hold nextents worth of extents. The
34 * caller must use all nextents extents, because we are not
35 * flexible about this at all.
36 */
37xfs_efi_log_item_t *
38xfs_trans_get_efi(xfs_trans_t *tp,
39 uint nextents)
40{
41 xfs_efi_log_item_t *efip;
42
43 ASSERT(tp != NULL);
44 ASSERT(nextents > 0);
45
46 efip = xfs_efi_init(tp->t_mountp, nextents);
47 ASSERT(efip != NULL);
48
49 /*
50 * Get a log_item_desc to point at the new item.
51 */
52 (void) xfs_trans_add_item(tp, (xfs_log_item_t*)efip);
53
54 return (efip);
55}
56
57/*
58 * This routine is called to indicate that the described
59 * extent is to be logged as needing to be freed. It should
60 * be called once for each extent to be freed.
61 */
62void
63xfs_trans_log_efi_extent(xfs_trans_t *tp,
64 xfs_efi_log_item_t *efip,
65 xfs_fsblock_t start_block,
66 xfs_extlen_t ext_len)
67{
68 xfs_log_item_desc_t *lidp;
69 uint next_extent;
70 xfs_extent_t *extp;
71
72 lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)efip);
73 ASSERT(lidp != NULL);
74
75 tp->t_flags |= XFS_TRANS_DIRTY;
76 lidp->lid_flags |= XFS_LID_DIRTY;
77
78 next_extent = efip->efi_next_extent;
79 ASSERT(next_extent < efip->efi_format.efi_nextents);
80 extp = &(efip->efi_format.efi_extents[next_extent]);
81 extp->ext_start = start_block;
82 extp->ext_len = ext_len;
83 efip->efi_next_extent++;
84}
85
86
87/*
88 * This routine is called to allocate an "extent free done"
89 * log item that will hold nextents worth of extents. The
90 * caller must use all nextents extents, because we are not
91 * flexible about this at all.
92 */
93xfs_efd_log_item_t *
94xfs_trans_get_efd(xfs_trans_t *tp,
95 xfs_efi_log_item_t *efip,
96 uint nextents)
97{
98 xfs_efd_log_item_t *efdp;
99
100 ASSERT(tp != NULL);
101 ASSERT(nextents > 0);
102
103 efdp = xfs_efd_init(tp->t_mountp, efip, nextents);
104 ASSERT(efdp != NULL);
105
106 /*
107 * Get a log_item_desc to point at the new item.
108 */
109 (void) xfs_trans_add_item(tp, (xfs_log_item_t*)efdp);
110
111 return (efdp);
112}
113
114/*
115 * This routine is called to indicate that the described
116 * extent is to be logged as having been freed. It should
117 * be called once for each extent freed.
118 */
119void
120xfs_trans_log_efd_extent(xfs_trans_t *tp,
121 xfs_efd_log_item_t *efdp,
122 xfs_fsblock_t start_block,
123 xfs_extlen_t ext_len)
124{
125 xfs_log_item_desc_t *lidp;
126 uint next_extent;
127 xfs_extent_t *extp;
128
129 lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)efdp);
130 ASSERT(lidp != NULL);
131
132 tp->t_flags |= XFS_TRANS_DIRTY;
133 lidp->lid_flags |= XFS_LID_DIRTY;
134
135 next_extent = efdp->efd_next_extent;
136 ASSERT(next_extent < efdp->efd_format.efd_nextents);
137 extp = &(efdp->efd_format.efd_extents[next_extent]);
138 extp->ext_start = start_block;
139 extp->ext_len = ext_len;
140 efdp->efd_next_extent++;
141}