2 * Copyright (c) 2000,2005 Silicon Graphics, Inc.
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
7 * published by the Free Software Foundation.
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.
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
20 #include "xfs_types.h"
23 #include "xfs_trans.h"
26 #include "xfs_mount.h"
27 #include "xfs_trans_priv.h"
28 #include "xfs_extfree_item.h"
31 * This routine is called to allocate an "extent free intention"
32 * log item that will hold nextents worth of extents. The
33 * caller must use all nextents extents, because we are not
34 * flexible about this at all.
37 xfs_trans_get_efi(xfs_trans_t
*tp
,
40 xfs_efi_log_item_t
*efip
;
45 efip
= xfs_efi_init(tp
->t_mountp
, nextents
);
49 * Get a log_item_desc to point at the new item.
51 xfs_trans_add_item(tp
, &efip
->efi_item
);
56 * This routine is called to indicate that the described
57 * extent is to be logged as needing to be freed. It should
58 * be called once for each extent to be freed.
61 xfs_trans_log_efi_extent(xfs_trans_t
*tp
,
62 xfs_efi_log_item_t
*efip
,
63 xfs_fsblock_t start_block
,
69 tp
->t_flags
|= XFS_TRANS_DIRTY
;
70 efip
->efi_item
.li_desc
->lid_flags
|= XFS_LID_DIRTY
;
73 * atomic_inc_return gives us the value after the increment;
74 * we want to use it as an array index so we need to subtract 1 from
77 next_extent
= atomic_inc_return(&efip
->efi_next_extent
) - 1;
78 ASSERT(next_extent
< efip
->efi_format
.efi_nextents
);
79 extp
= &(efip
->efi_format
.efi_extents
[next_extent
]);
80 extp
->ext_start
= start_block
;
81 extp
->ext_len
= ext_len
;
86 * This routine is called to allocate an "extent free done"
87 * log item that will hold nextents worth of extents. The
88 * caller must use all nextents extents, because we are not
89 * flexible about this at all.
92 xfs_trans_get_efd(xfs_trans_t
*tp
,
93 xfs_efi_log_item_t
*efip
,
96 xfs_efd_log_item_t
*efdp
;
101 efdp
= xfs_efd_init(tp
->t_mountp
, efip
, nextents
);
102 ASSERT(efdp
!= NULL
);
105 * Get a log_item_desc to point at the new item.
107 xfs_trans_add_item(tp
, &efdp
->efd_item
);
112 * This routine is called to indicate that the described
113 * extent is to be logged as having been freed. It should
114 * be called once for each extent freed.
117 xfs_trans_log_efd_extent(xfs_trans_t
*tp
,
118 xfs_efd_log_item_t
*efdp
,
119 xfs_fsblock_t start_block
,
120 xfs_extlen_t ext_len
)
125 tp
->t_flags
|= XFS_TRANS_DIRTY
;
126 efdp
->efd_item
.li_desc
->lid_flags
|= XFS_LID_DIRTY
;
128 next_extent
= efdp
->efd_next_extent
;
129 ASSERT(next_extent
< efdp
->efd_format
.efd_nextents
);
130 extp
= &(efdp
->efd_format
.efd_extents
[next_extent
]);
131 extp
->ext_start
= start_block
;
132 extp
->ext_len
= ext_len
;
133 efdp
->efd_next_extent
++;