blob: f783d5e9fa70f30b87650a5dfe0fd09bbd80ba02 [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_mount.h"
27#include "xfs_trans_priv.h"
28#include "xfs_extfree_item.h"
29
30/*
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.
35 */
36xfs_efi_log_item_t *
37xfs_trans_get_efi(xfs_trans_t *tp,
38 uint nextents)
39{
40 xfs_efi_log_item_t *efip;
41
42 ASSERT(tp != NULL);
43 ASSERT(nextents > 0);
44
45 efip = xfs_efi_init(tp->t_mountp, nextents);
46 ASSERT(efip != NULL);
47
48 /*
49 * Get a log_item_desc to point at the new item.
50 */
Christoph Hellwige98c4142010-06-23 18:11:15 +100051 xfs_trans_add_item(tp, &efip->efi_item);
52 return efip;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053}
54
55/*
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.
59 */
60void
61xfs_trans_log_efi_extent(xfs_trans_t *tp,
62 xfs_efi_log_item_t *efip,
63 xfs_fsblock_t start_block,
64 xfs_extlen_t ext_len)
65{
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 uint next_extent;
67 xfs_extent_t *extp;
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 tp->t_flags |= XFS_TRANS_DIRTY;
Christoph Hellwige98c4142010-06-23 18:11:15 +100070 efip->efi_item.li_desc->lid_flags |= XFS_LID_DIRTY;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72 next_extent = efip->efi_next_extent;
73 ASSERT(next_extent < efip->efi_format.efi_nextents);
74 extp = &(efip->efi_format.efi_extents[next_extent]);
75 extp->ext_start = start_block;
76 extp->ext_len = ext_len;
77 efip->efi_next_extent++;
78}
79
80
81/*
82 * This routine is called to allocate an "extent free done"
83 * log item that will hold nextents worth of extents. The
84 * caller must use all nextents extents, because we are not
85 * flexible about this at all.
86 */
87xfs_efd_log_item_t *
88xfs_trans_get_efd(xfs_trans_t *tp,
89 xfs_efi_log_item_t *efip,
90 uint nextents)
91{
92 xfs_efd_log_item_t *efdp;
93
94 ASSERT(tp != NULL);
95 ASSERT(nextents > 0);
96
97 efdp = xfs_efd_init(tp->t_mountp, efip, nextents);
98 ASSERT(efdp != NULL);
99
100 /*
101 * Get a log_item_desc to point at the new item.
102 */
Christoph Hellwige98c4142010-06-23 18:11:15 +1000103 xfs_trans_add_item(tp, &efdp->efd_item);
104 return efdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105}
106
107/*
108 * This routine is called to indicate that the described
109 * extent is to be logged as having been freed. It should
110 * be called once for each extent freed.
111 */
112void
113xfs_trans_log_efd_extent(xfs_trans_t *tp,
114 xfs_efd_log_item_t *efdp,
115 xfs_fsblock_t start_block,
116 xfs_extlen_t ext_len)
117{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 uint next_extent;
119 xfs_extent_t *extp;
120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 tp->t_flags |= XFS_TRANS_DIRTY;
Christoph Hellwige98c4142010-06-23 18:11:15 +1000122 efdp->efd_item.li_desc->lid_flags |= XFS_LID_DIRTY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124 next_extent = efdp->efd_next_extent;
125 ASSERT(next_extent < efdp->efd_format.efd_nextents);
126 extp = &(efdp->efd_format.efd_extents[next_extent]);
127 extp->ext_start = start_block;
128 extp->ext_len = ext_len;
129 efdp->efd_next_extent++;
130}