]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - fs/xfs/libxfs/xfs_rmap.c
ce29d6b7cd58e3b179e3cff9e8cbcbc83fbfd835
2 * Copyright (c) 2014 Red Hat, 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_shared.h"
21 #include "xfs_format.h"
22 #include "xfs_log_format.h"
23 #include "xfs_trans_resv.h"
26 #include "xfs_mount.h"
27 #include "xfs_defer.h"
28 #include "xfs_da_format.h"
29 #include "xfs_da_btree.h"
30 #include "xfs_btree.h"
31 #include "xfs_trans.h"
32 #include "xfs_alloc.h"
34 #include "xfs_trans_space.h"
35 #include "xfs_trace.h"
36 #include "xfs_error.h"
37 #include "xfs_extent_busy.h"
40 * Lookup the first record less than or equal to [bno, len, owner, offset]
41 * in the btree given by cur.
45 struct xfs_btree_cur
*cur
,
53 cur
->bc_rec
.r
.rm_startblock
= bno
;
54 cur
->bc_rec
.r
.rm_blockcount
= len
;
55 cur
->bc_rec
.r
.rm_owner
= owner
;
56 cur
->bc_rec
.r
.rm_offset
= offset
;
57 cur
->bc_rec
.r
.rm_flags
= flags
;
58 return xfs_btree_lookup(cur
, XFS_LOOKUP_LE
, stat
);
62 * Lookup the record exactly matching [bno, len, owner, offset]
63 * in the btree given by cur.
67 struct xfs_btree_cur
*cur
,
75 cur
->bc_rec
.r
.rm_startblock
= bno
;
76 cur
->bc_rec
.r
.rm_blockcount
= len
;
77 cur
->bc_rec
.r
.rm_owner
= owner
;
78 cur
->bc_rec
.r
.rm_offset
= offset
;
79 cur
->bc_rec
.r
.rm_flags
= flags
;
80 return xfs_btree_lookup(cur
, XFS_LOOKUP_EQ
, stat
);
84 * Update the record referred to by cur to the value given
85 * by [bno, len, owner, offset].
86 * This either works (return 0) or gets an EFSCORRUPTED error.
90 struct xfs_btree_cur
*cur
,
91 struct xfs_rmap_irec
*irec
)
93 union xfs_btree_rec rec
;
95 rec
.rmap
.rm_startblock
= cpu_to_be32(irec
->rm_startblock
);
96 rec
.rmap
.rm_blockcount
= cpu_to_be32(irec
->rm_blockcount
);
97 rec
.rmap
.rm_owner
= cpu_to_be64(irec
->rm_owner
);
98 rec
.rmap
.rm_offset
= cpu_to_be64(
99 xfs_rmap_irec_offset_pack(irec
));
100 return xfs_btree_update(cur
, &rec
);
104 xfs_rmap_btrec_to_irec(
105 union xfs_btree_rec
*rec
,
106 struct xfs_rmap_irec
*irec
)
109 irec
->rm_startblock
= be32_to_cpu(rec
->rmap
.rm_startblock
);
110 irec
->rm_blockcount
= be32_to_cpu(rec
->rmap
.rm_blockcount
);
111 irec
->rm_owner
= be64_to_cpu(rec
->rmap
.rm_owner
);
112 return xfs_rmap_irec_offset_unpack(be64_to_cpu(rec
->rmap
.rm_offset
),
117 * Get the data from the pointed-to record.
121 struct xfs_btree_cur
*cur
,
122 struct xfs_rmap_irec
*irec
,
125 union xfs_btree_rec
*rec
;
128 error
= xfs_btree_get_rec(cur
, &rec
, stat
);
132 return xfs_rmap_btrec_to_irec(rec
, irec
);
137 struct xfs_trans
*tp
,
138 struct xfs_buf
*agbp
,
142 struct xfs_owner_info
*oinfo
)
144 struct xfs_mount
*mp
= tp
->t_mountp
;
147 if (!xfs_sb_version_hasrmapbt(&mp
->m_sb
))
150 trace_xfs_rmap_unmap(mp
, agno
, bno
, len
, false, oinfo
);
153 trace_xfs_rmap_unmap_done(mp
, agno
, bno
, len
, false, oinfo
);
157 trace_xfs_rmap_unmap_error(mp
, agno
, error
, _RET_IP_
);
163 struct xfs_trans
*tp
,
164 struct xfs_buf
*agbp
,
168 struct xfs_owner_info
*oinfo
)
170 struct xfs_mount
*mp
= tp
->t_mountp
;
173 if (!xfs_sb_version_hasrmapbt(&mp
->m_sb
))
176 trace_xfs_rmap_map(mp
, agno
, bno
, len
, false, oinfo
);
179 trace_xfs_rmap_map_done(mp
, agno
, bno
, len
, false, oinfo
);
183 trace_xfs_rmap_map_error(mp
, agno
, error
, _RET_IP_
);