aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_fsops.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/xfs_fsops.c')
-rw-r--r--fs/xfs/xfs_fsops.c161
1 files changed, 71 insertions, 90 deletions
diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c
index ca535d613190..7ceabd0e2d9d 100644
--- a/fs/xfs/xfs_fsops.c
+++ b/fs/xfs/xfs_fsops.c
@@ -1,66 +1,51 @@
1/* 1/*
2 * Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved. 2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
3 * 4 *
4 * This program is free software; you can redistribute it and/or modify it 5 * This program is free software; you can redistribute it and/or
5 * under the terms of version 2 of the GNU General Public License as 6 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
7 * 8 *
8 * This program is distributed in the hope that it would be useful, but 9 * This program is distributed in the hope that it would be useful,
9 * WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
11 * 13 *
12 * Further, this software is distributed without any warranty that it is 14 * You should have received a copy of the GNU General Public License
13 * free of the rightful claim of any third person regarding infringement 15 * along with this program; if not, write the Free Software Foundation,
14 * or the like. Any license provided herein, whether implied or 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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 */ 17 */
32
33#include "xfs.h" 18#include "xfs.h"
34#include "xfs_macros.h" 19#include "xfs_fs.h"
35#include "xfs_types.h" 20#include "xfs_types.h"
21#include "xfs_bit.h"
36#include "xfs_inum.h" 22#include "xfs_inum.h"
37#include "xfs_log.h" 23#include "xfs_log.h"
38#include "xfs_trans.h" 24#include "xfs_trans.h"
39#include "xfs_sb.h" 25#include "xfs_sb.h"
26#include "xfs_ag.h"
40#include "xfs_dir.h" 27#include "xfs_dir.h"
28#include "xfs_dir2.h"
41#include "xfs_dmapi.h" 29#include "xfs_dmapi.h"
42#include "xfs_mount.h" 30#include "xfs_mount.h"
43#include "xfs_ag.h"
44#include "xfs_alloc_btree.h"
45#include "xfs_bmap_btree.h" 31#include "xfs_bmap_btree.h"
32#include "xfs_alloc_btree.h"
46#include "xfs_ialloc_btree.h" 33#include "xfs_ialloc_btree.h"
34#include "xfs_dir_sf.h"
35#include "xfs_dir2_sf.h"
36#include "xfs_attr_sf.h"
37#include "xfs_dinode.h"
38#include "xfs_inode.h"
39#include "xfs_inode_item.h"
47#include "xfs_btree.h" 40#include "xfs_btree.h"
48#include "xfs_error.h" 41#include "xfs_error.h"
49#include "xfs_alloc.h" 42#include "xfs_alloc.h"
50#include "xfs_ialloc.h" 43#include "xfs_ialloc.h"
51#include "xfs_fsops.h" 44#include "xfs_fsops.h"
52#include "xfs_itable.h" 45#include "xfs_itable.h"
53#include "xfs_rw.h"
54#include "xfs_refcache.h"
55#include "xfs_trans_space.h" 46#include "xfs_trans_space.h"
56#include "xfs_rtalloc.h" 47#include "xfs_rtalloc.h"
57#include "xfs_dir2.h" 48#include "xfs_rw.h"
58#include "xfs_attr_sf.h"
59#include "xfs_dir_sf.h"
60#include "xfs_dir2_sf.h"
61#include "xfs_dinode.h"
62#include "xfs_inode.h"
63#include "xfs_inode_item.h"
64 49
65/* 50/*
66 * File system operations 51 * File system operations
@@ -110,7 +95,9 @@ xfs_fs_geometry(
110 (XFS_SB_VERSION_HASDIRV2(&mp->m_sb) ? 95 (XFS_SB_VERSION_HASDIRV2(&mp->m_sb) ?
111 XFS_FSOP_GEOM_FLAGS_DIRV2 : 0) | 96 XFS_FSOP_GEOM_FLAGS_DIRV2 : 0) |
112 (XFS_SB_VERSION_HASSECTOR(&mp->m_sb) ? 97 (XFS_SB_VERSION_HASSECTOR(&mp->m_sb) ?
113 XFS_FSOP_GEOM_FLAGS_SECTOR : 0); 98 XFS_FSOP_GEOM_FLAGS_SECTOR : 0) |
99 (XFS_SB_VERSION_HASATTR2(&mp->m_sb) ?
100 XFS_FSOP_GEOM_FLAGS_ATTR2 : 0);
114 geo->logsectsize = XFS_SB_VERSION_HASSECTOR(&mp->m_sb) ? 101 geo->logsectsize = XFS_SB_VERSION_HASSECTOR(&mp->m_sb) ?
115 mp->m_sb.sb_logsectsize : BBSIZE; 102 mp->m_sb.sb_logsectsize : BBSIZE;
116 geo->rtsectsize = mp->m_sb.sb_blocksize; 103 geo->rtsectsize = mp->m_sb.sb_blocksize;
@@ -184,7 +171,7 @@ xfs_growfs_data_private(
184 memset(&mp->m_perag[oagcount], 0, 171 memset(&mp->m_perag[oagcount], 0,
185 (nagcount - oagcount) * sizeof(xfs_perag_t)); 172 (nagcount - oagcount) * sizeof(xfs_perag_t));
186 mp->m_flags |= XFS_MOUNT_32BITINODES; 173 mp->m_flags |= XFS_MOUNT_32BITINODES;
187 nagimax = xfs_initialize_perag(mp, nagcount); 174 nagimax = xfs_initialize_perag(XFS_MTOVFS(mp), mp, nagcount);
188 up_write(&mp->m_peraglock); 175 up_write(&mp->m_peraglock);
189 } 176 }
190 tp = xfs_trans_alloc(mp, XFS_TRANS_GROWFS); 177 tp = xfs_trans_alloc(mp, XFS_TRANS_GROWFS);
@@ -204,28 +191,26 @@ xfs_growfs_data_private(
204 XFS_FSS_TO_BB(mp, 1), 0); 191 XFS_FSS_TO_BB(mp, 1), 0);
205 agf = XFS_BUF_TO_AGF(bp); 192 agf = XFS_BUF_TO_AGF(bp);
206 memset(agf, 0, mp->m_sb.sb_sectsize); 193 memset(agf, 0, mp->m_sb.sb_sectsize);
207 INT_SET(agf->agf_magicnum, ARCH_CONVERT, XFS_AGF_MAGIC); 194 agf->agf_magicnum = cpu_to_be32(XFS_AGF_MAGIC);
208 INT_SET(agf->agf_versionnum, ARCH_CONVERT, XFS_AGF_VERSION); 195 agf->agf_versionnum = cpu_to_be32(XFS_AGF_VERSION);
209 INT_SET(agf->agf_seqno, ARCH_CONVERT, agno); 196 agf->agf_seqno = cpu_to_be32(agno);
210 if (agno == nagcount - 1) 197 if (agno == nagcount - 1)
211 agsize = 198 agsize =
212 nb - 199 nb -
213 (agno * (xfs_rfsblock_t)mp->m_sb.sb_agblocks); 200 (agno * (xfs_rfsblock_t)mp->m_sb.sb_agblocks);
214 else 201 else
215 agsize = mp->m_sb.sb_agblocks; 202 agsize = mp->m_sb.sb_agblocks;
216 INT_SET(agf->agf_length, ARCH_CONVERT, agsize); 203 agf->agf_length = cpu_to_be32(agsize);
217 INT_SET(agf->agf_roots[XFS_BTNUM_BNOi], ARCH_CONVERT, 204 agf->agf_roots[XFS_BTNUM_BNOi] = cpu_to_be32(XFS_BNO_BLOCK(mp));
218 XFS_BNO_BLOCK(mp)); 205 agf->agf_roots[XFS_BTNUM_CNTi] = cpu_to_be32(XFS_CNT_BLOCK(mp));
219 INT_SET(agf->agf_roots[XFS_BTNUM_CNTi], ARCH_CONVERT, 206 agf->agf_levels[XFS_BTNUM_BNOi] = cpu_to_be32(1);
220 XFS_CNT_BLOCK(mp)); 207 agf->agf_levels[XFS_BTNUM_CNTi] = cpu_to_be32(1);
221 INT_SET(agf->agf_levels[XFS_BTNUM_BNOi], ARCH_CONVERT, 1);
222 INT_SET(agf->agf_levels[XFS_BTNUM_CNTi], ARCH_CONVERT, 1);
223 agf->agf_flfirst = 0; 208 agf->agf_flfirst = 0;
224 INT_SET(agf->agf_fllast, ARCH_CONVERT, XFS_AGFL_SIZE(mp) - 1); 209 agf->agf_fllast = cpu_to_be32(XFS_AGFL_SIZE(mp) - 1);
225 agf->agf_flcount = 0; 210 agf->agf_flcount = 0;
226 tmpsize = agsize - XFS_PREALLOC_BLOCKS(mp); 211 tmpsize = agsize - XFS_PREALLOC_BLOCKS(mp);
227 INT_SET(agf->agf_freeblks, ARCH_CONVERT, tmpsize); 212 agf->agf_freeblks = cpu_to_be32(tmpsize);
228 INT_SET(agf->agf_longest, ARCH_CONVERT, tmpsize); 213 agf->agf_longest = cpu_to_be32(tmpsize);
229 error = xfs_bwrite(mp, bp); 214 error = xfs_bwrite(mp, bp);
230 if (error) { 215 if (error) {
231 goto error0; 216 goto error0;
@@ -238,19 +223,18 @@ xfs_growfs_data_private(
238 XFS_FSS_TO_BB(mp, 1), 0); 223 XFS_FSS_TO_BB(mp, 1), 0);
239 agi = XFS_BUF_TO_AGI(bp); 224 agi = XFS_BUF_TO_AGI(bp);
240 memset(agi, 0, mp->m_sb.sb_sectsize); 225 memset(agi, 0, mp->m_sb.sb_sectsize);
241 INT_SET(agi->agi_magicnum, ARCH_CONVERT, XFS_AGI_MAGIC); 226 agi->agi_magicnum = cpu_to_be32(XFS_AGI_MAGIC);
242 INT_SET(agi->agi_versionnum, ARCH_CONVERT, XFS_AGI_VERSION); 227 agi->agi_versionnum = cpu_to_be32(XFS_AGI_VERSION);
243 INT_SET(agi->agi_seqno, ARCH_CONVERT, agno); 228 agi->agi_seqno = cpu_to_be32(agno);
244 INT_SET(agi->agi_length, ARCH_CONVERT, agsize); 229 agi->agi_length = cpu_to_be32(agsize);
245 agi->agi_count = 0; 230 agi->agi_count = 0;
246 INT_SET(agi->agi_root, ARCH_CONVERT, XFS_IBT_BLOCK(mp)); 231 agi->agi_root = cpu_to_be32(XFS_IBT_BLOCK(mp));
247 INT_SET(agi->agi_level, ARCH_CONVERT, 1); 232 agi->agi_level = cpu_to_be32(1);
248 agi->agi_freecount = 0; 233 agi->agi_freecount = 0;
249 INT_SET(agi->agi_newino, ARCH_CONVERT, NULLAGINO); 234 agi->agi_newino = cpu_to_be32(NULLAGINO);
250 INT_SET(agi->agi_dirino, ARCH_CONVERT, NULLAGINO); 235 agi->agi_dirino = cpu_to_be32(NULLAGINO);
251 for (bucket = 0; bucket < XFS_AGI_UNLINKED_BUCKETS; bucket++) 236 for (bucket = 0; bucket < XFS_AGI_UNLINKED_BUCKETS; bucket++)
252 INT_SET(agi->agi_unlinked[bucket], ARCH_CONVERT, 237 agi->agi_unlinked[bucket] = cpu_to_be32(NULLAGINO);
253 NULLAGINO);
254 error = xfs_bwrite(mp, bp); 238 error = xfs_bwrite(mp, bp);
255 if (error) { 239 if (error) {
256 goto error0; 240 goto error0;
@@ -263,17 +247,16 @@ xfs_growfs_data_private(
263 BTOBB(mp->m_sb.sb_blocksize), 0); 247 BTOBB(mp->m_sb.sb_blocksize), 0);
264 block = XFS_BUF_TO_SBLOCK(bp); 248 block = XFS_BUF_TO_SBLOCK(bp);
265 memset(block, 0, mp->m_sb.sb_blocksize); 249 memset(block, 0, mp->m_sb.sb_blocksize);
266 INT_SET(block->bb_magic, ARCH_CONVERT, XFS_ABTB_MAGIC); 250 block->bb_magic = cpu_to_be32(XFS_ABTB_MAGIC);
267 block->bb_level = 0; 251 block->bb_level = 0;
268 INT_SET(block->bb_numrecs, ARCH_CONVERT, 1); 252 block->bb_numrecs = cpu_to_be16(1);
269 INT_SET(block->bb_leftsib, ARCH_CONVERT, NULLAGBLOCK); 253 block->bb_leftsib = cpu_to_be32(NULLAGBLOCK);
270 INT_SET(block->bb_rightsib, ARCH_CONVERT, NULLAGBLOCK); 254 block->bb_rightsib = cpu_to_be32(NULLAGBLOCK);
271 arec = XFS_BTREE_REC_ADDR(mp->m_sb.sb_blocksize, xfs_alloc, 255 arec = XFS_BTREE_REC_ADDR(mp->m_sb.sb_blocksize, xfs_alloc,
272 block, 1, mp->m_alloc_mxr[0]); 256 block, 1, mp->m_alloc_mxr[0]);
273 INT_SET(arec->ar_startblock, ARCH_CONVERT, 257 arec->ar_startblock = cpu_to_be32(XFS_PREALLOC_BLOCKS(mp));
274 XFS_PREALLOC_BLOCKS(mp)); 258 arec->ar_blockcount = cpu_to_be32(
275 INT_SET(arec->ar_blockcount, ARCH_CONVERT, 259 agsize - be32_to_cpu(arec->ar_startblock));
276 agsize - INT_GET(arec->ar_startblock, ARCH_CONVERT));
277 error = xfs_bwrite(mp, bp); 260 error = xfs_bwrite(mp, bp);
278 if (error) { 261 if (error) {
279 goto error0; 262 goto error0;
@@ -286,18 +269,17 @@ xfs_growfs_data_private(
286 BTOBB(mp->m_sb.sb_blocksize), 0); 269 BTOBB(mp->m_sb.sb_blocksize), 0);
287 block = XFS_BUF_TO_SBLOCK(bp); 270 block = XFS_BUF_TO_SBLOCK(bp);
288 memset(block, 0, mp->m_sb.sb_blocksize); 271 memset(block, 0, mp->m_sb.sb_blocksize);
289 INT_SET(block->bb_magic, ARCH_CONVERT, XFS_ABTC_MAGIC); 272 block->bb_magic = cpu_to_be32(XFS_ABTC_MAGIC);
290 block->bb_level = 0; 273 block->bb_level = 0;
291 INT_SET(block->bb_numrecs, ARCH_CONVERT, 1); 274 block->bb_numrecs = cpu_to_be16(1);
292 INT_SET(block->bb_leftsib, ARCH_CONVERT, NULLAGBLOCK); 275 block->bb_leftsib = cpu_to_be32(NULLAGBLOCK);
293 INT_SET(block->bb_rightsib, ARCH_CONVERT, NULLAGBLOCK); 276 block->bb_rightsib = cpu_to_be32(NULLAGBLOCK);
294 arec = XFS_BTREE_REC_ADDR(mp->m_sb.sb_blocksize, xfs_alloc, 277 arec = XFS_BTREE_REC_ADDR(mp->m_sb.sb_blocksize, xfs_alloc,
295 block, 1, mp->m_alloc_mxr[0]); 278 block, 1, mp->m_alloc_mxr[0]);
296 INT_SET(arec->ar_startblock, ARCH_CONVERT, 279 arec->ar_startblock = cpu_to_be32(XFS_PREALLOC_BLOCKS(mp));
297 XFS_PREALLOC_BLOCKS(mp)); 280 arec->ar_blockcount = cpu_to_be32(
298 INT_SET(arec->ar_blockcount, ARCH_CONVERT, 281 agsize - be32_to_cpu(arec->ar_startblock));
299 agsize - INT_GET(arec->ar_startblock, ARCH_CONVERT)); 282 nfree += be32_to_cpu(arec->ar_blockcount);
300 nfree += INT_GET(arec->ar_blockcount, ARCH_CONVERT);
301 error = xfs_bwrite(mp, bp); 283 error = xfs_bwrite(mp, bp);
302 if (error) { 284 if (error) {
303 goto error0; 285 goto error0;
@@ -310,11 +292,11 @@ xfs_growfs_data_private(
310 BTOBB(mp->m_sb.sb_blocksize), 0); 292 BTOBB(mp->m_sb.sb_blocksize), 0);
311 block = XFS_BUF_TO_SBLOCK(bp); 293 block = XFS_BUF_TO_SBLOCK(bp);
312 memset(block, 0, mp->m_sb.sb_blocksize); 294 memset(block, 0, mp->m_sb.sb_blocksize);
313 INT_SET(block->bb_magic, ARCH_CONVERT, XFS_IBT_MAGIC); 295 block->bb_magic = cpu_to_be32(XFS_IBT_MAGIC);
314 block->bb_level = 0; 296 block->bb_level = 0;
315 block->bb_numrecs = 0; 297 block->bb_numrecs = 0;
316 INT_SET(block->bb_leftsib, ARCH_CONVERT, NULLAGBLOCK); 298 block->bb_leftsib = cpu_to_be32(NULLAGBLOCK);
317 INT_SET(block->bb_rightsib, ARCH_CONVERT, NULLAGBLOCK); 299 block->bb_rightsib = cpu_to_be32(NULLAGBLOCK);
318 error = xfs_bwrite(mp, bp); 300 error = xfs_bwrite(mp, bp);
319 if (error) { 301 if (error) {
320 goto error0; 302 goto error0;
@@ -334,10 +316,9 @@ xfs_growfs_data_private(
334 } 316 }
335 ASSERT(bp); 317 ASSERT(bp);
336 agi = XFS_BUF_TO_AGI(bp); 318 agi = XFS_BUF_TO_AGI(bp);
337 INT_MOD(agi->agi_length, ARCH_CONVERT, new); 319 be32_add(&agi->agi_length, new);
338 ASSERT(nagcount == oagcount || 320 ASSERT(nagcount == oagcount ||
339 INT_GET(agi->agi_length, ARCH_CONVERT) == 321 be32_to_cpu(agi->agi_length) == mp->m_sb.sb_agblocks);
340 mp->m_sb.sb_agblocks);
341 xfs_ialloc_log_agi(tp, bp, XFS_AGI_LENGTH); 322 xfs_ialloc_log_agi(tp, bp, XFS_AGI_LENGTH);
342 /* 323 /*
343 * Change agf length. 324 * Change agf length.
@@ -348,14 +329,14 @@ xfs_growfs_data_private(
348 } 329 }
349 ASSERT(bp); 330 ASSERT(bp);
350 agf = XFS_BUF_TO_AGF(bp); 331 agf = XFS_BUF_TO_AGF(bp);
351 INT_MOD(agf->agf_length, ARCH_CONVERT, new); 332 be32_add(&agf->agf_length, new);
352 ASSERT(INT_GET(agf->agf_length, ARCH_CONVERT) == 333 ASSERT(be32_to_cpu(agf->agf_length) ==
353 INT_GET(agi->agi_length, ARCH_CONVERT)); 334 be32_to_cpu(agi->agi_length));
354 /* 335 /*
355 * Free the new space. 336 * Free the new space.
356 */ 337 */
357 error = xfs_free_extent(tp, XFS_AGB_TO_FSB(mp, agno, 338 error = xfs_free_extent(tp, XFS_AGB_TO_FSB(mp, agno,
358 INT_GET(agf->agf_length, ARCH_CONVERT) - new), new); 339 be32_to_cpu(agf->agf_length) - new), new);
359 if (error) { 340 if (error) {
360 goto error0; 341 goto error0;
361 } 342 }