blob: 1f6b17777f2d6c86ea3ff30a1b3c1a853fe1da78 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include "xfs.h"
Nathan Scotta844f452005-11-02 14:38:42 +110033#include "xfs_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "xfs_types.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include "xfs_log.h"
Nathan Scotta844f452005-11-02 14:38:42 +110036#include "xfs_inum.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include "xfs_trans.h"
38#include "xfs_sb.h"
39#include "xfs_dir.h"
40#include "xfs_dmapi.h"
41#include "xfs_mount.h"
42#include "xfs_trans_priv.h"
43#include "xfs_extfree_item.h"
44
45/*
46 * This routine is called to allocate an "extent free intention"
47 * log item that will hold nextents worth of extents. The
48 * caller must use all nextents extents, because we are not
49 * flexible about this at all.
50 */
51xfs_efi_log_item_t *
52xfs_trans_get_efi(xfs_trans_t *tp,
53 uint nextents)
54{
55 xfs_efi_log_item_t *efip;
56
57 ASSERT(tp != NULL);
58 ASSERT(nextents > 0);
59
60 efip = xfs_efi_init(tp->t_mountp, nextents);
61 ASSERT(efip != NULL);
62
63 /*
64 * Get a log_item_desc to point at the new item.
65 */
66 (void) xfs_trans_add_item(tp, (xfs_log_item_t*)efip);
67
68 return (efip);
69}
70
71/*
72 * This routine is called to indicate that the described
73 * extent is to be logged as needing to be freed. It should
74 * be called once for each extent to be freed.
75 */
76void
77xfs_trans_log_efi_extent(xfs_trans_t *tp,
78 xfs_efi_log_item_t *efip,
79 xfs_fsblock_t start_block,
80 xfs_extlen_t ext_len)
81{
82 xfs_log_item_desc_t *lidp;
83 uint next_extent;
84 xfs_extent_t *extp;
85
86 lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)efip);
87 ASSERT(lidp != NULL);
88
89 tp->t_flags |= XFS_TRANS_DIRTY;
90 lidp->lid_flags |= XFS_LID_DIRTY;
91
92 next_extent = efip->efi_next_extent;
93 ASSERT(next_extent < efip->efi_format.efi_nextents);
94 extp = &(efip->efi_format.efi_extents[next_extent]);
95 extp->ext_start = start_block;
96 extp->ext_len = ext_len;
97 efip->efi_next_extent++;
98}
99
100
101/*
102 * This routine is called to allocate an "extent free done"
103 * log item that will hold nextents worth of extents. The
104 * caller must use all nextents extents, because we are not
105 * flexible about this at all.
106 */
107xfs_efd_log_item_t *
108xfs_trans_get_efd(xfs_trans_t *tp,
109 xfs_efi_log_item_t *efip,
110 uint nextents)
111{
112 xfs_efd_log_item_t *efdp;
113
114 ASSERT(tp != NULL);
115 ASSERT(nextents > 0);
116
117 efdp = xfs_efd_init(tp->t_mountp, efip, nextents);
118 ASSERT(efdp != NULL);
119
120 /*
121 * Get a log_item_desc to point at the new item.
122 */
123 (void) xfs_trans_add_item(tp, (xfs_log_item_t*)efdp);
124
125 return (efdp);
126}
127
128/*
129 * This routine is called to indicate that the described
130 * extent is to be logged as having been freed. It should
131 * be called once for each extent freed.
132 */
133void
134xfs_trans_log_efd_extent(xfs_trans_t *tp,
135 xfs_efd_log_item_t *efdp,
136 xfs_fsblock_t start_block,
137 xfs_extlen_t ext_len)
138{
139 xfs_log_item_desc_t *lidp;
140 uint next_extent;
141 xfs_extent_t *extp;
142
143 lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)efdp);
144 ASSERT(lidp != NULL);
145
146 tp->t_flags |= XFS_TRANS_DIRTY;
147 lidp->lid_flags |= XFS_LID_DIRTY;
148
149 next_extent = efdp->efd_next_extent;
150 ASSERT(next_extent < efdp->efd_format.efd_nextents);
151 extp = &(efdp->efd_format.efd_extents[next_extent]);
152 extp->ext_start = start_block;
153 extp->ext_len = ext_len;
154 efdp->efd_next_extent++;
155}