2 * Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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.
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.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
34 #include "xfs_macros.h"
35 #include "xfs_types.h"
38 #include "xfs_trans.h"
43 #include "xfs_dmapi.h"
44 #include "xfs_mount.h"
45 #include "xfs_alloc_btree.h"
46 #include "xfs_bmap_btree.h"
47 #include "xfs_ialloc_btree.h"
48 #include "xfs_btree.h"
49 #include "xfs_ialloc.h"
50 #include "xfs_attr_sf.h"
51 #include "xfs_dir_sf.h"
52 #include "xfs_dir2_sf.h"
53 #include "xfs_dinode.h"
54 #include "xfs_inode.h"
55 #include "xfs_alloc.h"
56 #include "xfs_rtalloc.h"
58 #include "xfs_error.h"
61 #include "xfs_quota.h"
62 #include "xfs_fsops.h"
64 STATIC
void xfs_mount_log_sbunit(xfs_mount_t
*, __int64_t
);
65 STATIC
int xfs_uuid_mount(xfs_mount_t
*);
66 STATIC
void xfs_uuid_unmount(xfs_mount_t
*mp
);
67 STATIC
void xfs_unmountfs_wait(xfs_mount_t
*);
71 short type
; /* 0 = integer
72 * 1 = binary / string (no translation)
75 { offsetof(xfs_sb_t
, sb_magicnum
), 0 },
76 { offsetof(xfs_sb_t
, sb_blocksize
), 0 },
77 { offsetof(xfs_sb_t
, sb_dblocks
), 0 },
78 { offsetof(xfs_sb_t
, sb_rblocks
), 0 },
79 { offsetof(xfs_sb_t
, sb_rextents
), 0 },
80 { offsetof(xfs_sb_t
, sb_uuid
), 1 },
81 { offsetof(xfs_sb_t
, sb_logstart
), 0 },
82 { offsetof(xfs_sb_t
, sb_rootino
), 0 },
83 { offsetof(xfs_sb_t
, sb_rbmino
), 0 },
84 { offsetof(xfs_sb_t
, sb_rsumino
), 0 },
85 { offsetof(xfs_sb_t
, sb_rextsize
), 0 },
86 { offsetof(xfs_sb_t
, sb_agblocks
), 0 },
87 { offsetof(xfs_sb_t
, sb_agcount
), 0 },
88 { offsetof(xfs_sb_t
, sb_rbmblocks
), 0 },
89 { offsetof(xfs_sb_t
, sb_logblocks
), 0 },
90 { offsetof(xfs_sb_t
, sb_versionnum
), 0 },
91 { offsetof(xfs_sb_t
, sb_sectsize
), 0 },
92 { offsetof(xfs_sb_t
, sb_inodesize
), 0 },
93 { offsetof(xfs_sb_t
, sb_inopblock
), 0 },
94 { offsetof(xfs_sb_t
, sb_fname
[0]), 1 },
95 { offsetof(xfs_sb_t
, sb_blocklog
), 0 },
96 { offsetof(xfs_sb_t
, sb_sectlog
), 0 },
97 { offsetof(xfs_sb_t
, sb_inodelog
), 0 },
98 { offsetof(xfs_sb_t
, sb_inopblog
), 0 },
99 { offsetof(xfs_sb_t
, sb_agblklog
), 0 },
100 { offsetof(xfs_sb_t
, sb_rextslog
), 0 },
101 { offsetof(xfs_sb_t
, sb_inprogress
), 0 },
102 { offsetof(xfs_sb_t
, sb_imax_pct
), 0 },
103 { offsetof(xfs_sb_t
, sb_icount
), 0 },
104 { offsetof(xfs_sb_t
, sb_ifree
), 0 },
105 { offsetof(xfs_sb_t
, sb_fdblocks
), 0 },
106 { offsetof(xfs_sb_t
, sb_frextents
), 0 },
107 { offsetof(xfs_sb_t
, sb_uquotino
), 0 },
108 { offsetof(xfs_sb_t
, sb_gquotino
), 0 },
109 { offsetof(xfs_sb_t
, sb_qflags
), 0 },
110 { offsetof(xfs_sb_t
, sb_flags
), 0 },
111 { offsetof(xfs_sb_t
, sb_shared_vn
), 0 },
112 { offsetof(xfs_sb_t
, sb_inoalignmt
), 0 },
113 { offsetof(xfs_sb_t
, sb_unit
), 0 },
114 { offsetof(xfs_sb_t
, sb_width
), 0 },
115 { offsetof(xfs_sb_t
, sb_dirblklog
), 0 },
116 { offsetof(xfs_sb_t
, sb_logsectlog
), 0 },
117 { offsetof(xfs_sb_t
, sb_logsectsize
),0 },
118 { offsetof(xfs_sb_t
, sb_logsunit
), 0 },
119 { offsetof(xfs_sb_t
, sb_features2
), 0 },
120 { sizeof(xfs_sb_t
), 0 }
124 * Return a pointer to an initialized xfs_mount structure.
131 mp
= kmem_zalloc(sizeof(*mp
), KM_SLEEP
);
133 AIL_LOCKINIT(&mp
->m_ail_lock
, "xfs_ail");
134 spinlock_init(&mp
->m_sb_lock
, "xfs_sb");
135 mutex_init(&mp
->m_ilock
, MUTEX_DEFAULT
, "xfs_ilock");
136 initnsema(&mp
->m_growlock
, 1, "xfs_grow");
138 * Initialize the AIL.
140 xfs_trans_ail_init(mp
);
142 atomic_set(&mp
->m_active_trans
, 0);
148 * Free up the resources associated with a mount structure. Assume that
149 * the structure was initially zeroed, so we can tell which fields got
165 for (agno
= 0; agno
< mp
->m_maxagi
; agno
++)
166 if (mp
->m_perag
[agno
].pagb_list
)
167 kmem_free(mp
->m_perag
[agno
].pagb_list
,
168 sizeof(xfs_perag_busy_t
) *
170 kmem_free(mp
->m_perag
,
171 sizeof(xfs_perag_t
) * mp
->m_sb
.sb_agcount
);
174 AIL_LOCK_DESTROY(&mp
->m_ail_lock
);
175 spinlock_destroy(&mp
->m_sb_lock
);
176 mutex_destroy(&mp
->m_ilock
);
177 freesema(&mp
->m_growlock
);
181 if (mp
->m_fsname
!= NULL
)
182 kmem_free(mp
->m_fsname
, mp
->m_fsname_len
);
185 struct vfs
*vfsp
= XFS_MTOVFS(mp
);
187 bhv_remove_all_vfsops(vfsp
, 0);
188 VFS_REMOVEBHV(vfsp
, &mp
->m_bhv
);
191 kmem_free(mp
, sizeof(xfs_mount_t
));
196 * Check the validity of the SB found.
199 xfs_mount_validate_sb(
204 * If the log device and data device have the
205 * same device number, the log is internal.
206 * Consequently, the sb_logstart should be non-zero. If
207 * we have a zero sb_logstart in this case, we may be trying to mount
208 * a volume filesystem in a non-volume manner.
210 if (sbp
->sb_magicnum
!= XFS_SB_MAGIC
) {
211 cmn_err(CE_WARN
, "XFS: bad magic number");
212 return XFS_ERROR(EWRONGFS
);
215 if (!XFS_SB_GOOD_VERSION(sbp
)) {
216 cmn_err(CE_WARN
, "XFS: bad version");
217 return XFS_ERROR(EWRONGFS
);
221 sbp
->sb_logstart
== 0 && mp
->m_logdev_targp
== mp
->m_ddev_targp
)) {
223 "XFS: filesystem is marked as having an external log; "
224 "specify logdev on the\nmount command line.");
225 XFS_CORRUPTION_ERROR("xfs_mount_validate_sb(1)",
226 XFS_ERRLEVEL_HIGH
, mp
, sbp
);
227 return XFS_ERROR(EFSCORRUPTED
);
231 sbp
->sb_logstart
!= 0 && mp
->m_logdev_targp
!= mp
->m_ddev_targp
)) {
233 "XFS: filesystem is marked as having an internal log; "
234 "don't specify logdev on\nthe mount command line.");
235 XFS_CORRUPTION_ERROR("xfs_mount_validate_sb(2)",
236 XFS_ERRLEVEL_HIGH
, mp
, sbp
);
237 return XFS_ERROR(EFSCORRUPTED
);
241 * More sanity checking. These were stolen directly from
245 sbp
->sb_agcount
<= 0 ||
246 sbp
->sb_sectsize
< XFS_MIN_SECTORSIZE
||
247 sbp
->sb_sectsize
> XFS_MAX_SECTORSIZE
||
248 sbp
->sb_sectlog
< XFS_MIN_SECTORSIZE_LOG
||
249 sbp
->sb_sectlog
> XFS_MAX_SECTORSIZE_LOG
||
250 sbp
->sb_blocksize
< XFS_MIN_BLOCKSIZE
||
251 sbp
->sb_blocksize
> XFS_MAX_BLOCKSIZE
||
252 sbp
->sb_blocklog
< XFS_MIN_BLOCKSIZE_LOG
||
253 sbp
->sb_blocklog
> XFS_MAX_BLOCKSIZE_LOG
||
254 sbp
->sb_inodesize
< XFS_DINODE_MIN_SIZE
||
255 sbp
->sb_inodesize
> XFS_DINODE_MAX_SIZE
||
256 (sbp
->sb_rextsize
* sbp
->sb_blocksize
> XFS_MAX_RTEXTSIZE
) ||
257 (sbp
->sb_rextsize
* sbp
->sb_blocksize
< XFS_MIN_RTEXTSIZE
) ||
258 sbp
->sb_imax_pct
> 100)) {
259 cmn_err(CE_WARN
, "XFS: SB sanity check 1 failed");
260 XFS_CORRUPTION_ERROR("xfs_mount_validate_sb(3)",
261 XFS_ERRLEVEL_LOW
, mp
, sbp
);
262 return XFS_ERROR(EFSCORRUPTED
);
266 * Sanity check AG count, size fields against data size field
269 sbp
->sb_dblocks
== 0 ||
271 (xfs_drfsbno_t
)sbp
->sb_agcount
* sbp
->sb_agblocks
||
272 sbp
->sb_dblocks
< (xfs_drfsbno_t
)(sbp
->sb_agcount
- 1) *
273 sbp
->sb_agblocks
+ XFS_MIN_AG_BLOCKS
)) {
274 cmn_err(CE_WARN
, "XFS: SB sanity check 2 failed");
275 XFS_ERROR_REPORT("xfs_mount_validate_sb(4)",
276 XFS_ERRLEVEL_LOW
, mp
);
277 return XFS_ERROR(EFSCORRUPTED
);
280 ASSERT(PAGE_SHIFT
>= sbp
->sb_blocklog
);
281 ASSERT(sbp
->sb_blocklog
>= BBSHIFT
);
283 #if XFS_BIG_BLKNOS /* Limited by ULONG_MAX of page cache index */
285 (sbp
->sb_dblocks
>> (PAGE_SHIFT
- sbp
->sb_blocklog
)) > ULONG_MAX
||
286 (sbp
->sb_rblocks
>> (PAGE_SHIFT
- sbp
->sb_blocklog
)) > ULONG_MAX
)) {
287 #else /* Limited by UINT_MAX of sectors */
289 (sbp
->sb_dblocks
<< (sbp
->sb_blocklog
- BBSHIFT
)) > UINT_MAX
||
290 (sbp
->sb_rblocks
<< (sbp
->sb_blocklog
- BBSHIFT
)) > UINT_MAX
)) {
293 "XFS: File system is too large to be mounted on this system.");
294 return XFS_ERROR(E2BIG
);
297 if (unlikely(sbp
->sb_inprogress
)) {
298 cmn_err(CE_WARN
, "XFS: file system busy");
299 XFS_ERROR_REPORT("xfs_mount_validate_sb(5)",
300 XFS_ERRLEVEL_LOW
, mp
);
301 return XFS_ERROR(EFSCORRUPTED
);
305 * Version 1 directory format has never worked on Linux.
307 if (unlikely(!XFS_SB_VERSION_HASDIRV2(sbp
))) {
309 "XFS: Attempted to mount file system using version 1 directory format");
310 return XFS_ERROR(ENOSYS
);
314 * Until this is fixed only page-sized or smaller data blocks work.
316 if (unlikely(sbp
->sb_blocksize
> PAGE_SIZE
)) {
318 "XFS: Attempted to mount file system with blocksize %d bytes",
321 "XFS: Only page-sized (%d) or less blocksizes currently work.",
323 return XFS_ERROR(ENOSYS
);
330 xfs_initialize_perag(xfs_mount_t
*mp
, xfs_agnumber_t agcount
)
332 xfs_agnumber_t index
, max_metadata
;
336 xfs_sb_t
*sbp
= &mp
->m_sb
;
337 xfs_ino_t max_inum
= XFS_MAXINUMBER_32
;
339 /* Check to see if the filesystem can overflow 32 bit inodes */
340 agino
= XFS_OFFBNO_TO_AGINO(mp
, sbp
->sb_agblocks
- 1, 0);
341 ino
= XFS_AGINO_TO_INO(mp
, agcount
- 1, agino
);
343 /* Clear the mount flag if no inode can overflow 32 bits
344 * on this filesystem, or if specifically requested..
346 if ((mp
->m_flags
& XFS_MOUNT_32BITINOOPT
) && ino
> max_inum
) {
347 mp
->m_flags
|= XFS_MOUNT_32BITINODES
;
349 mp
->m_flags
&= ~XFS_MOUNT_32BITINODES
;
352 /* If we can overflow then setup the ag headers accordingly */
353 if (mp
->m_flags
& XFS_MOUNT_32BITINODES
) {
354 /* Calculate how much should be reserved for inodes to
355 * meet the max inode percentage.
357 if (mp
->m_maxicount
) {
360 icount
= sbp
->sb_dblocks
* sbp
->sb_imax_pct
;
362 icount
+= sbp
->sb_agblocks
- 1;
363 do_div(icount
, mp
->m_ialloc_blks
);
364 max_metadata
= icount
;
366 max_metadata
= agcount
;
368 for (index
= 0; index
< agcount
; index
++) {
369 ino
= XFS_AGINO_TO_INO(mp
, index
, agino
);
370 if (ino
> max_inum
) {
375 /* This ag is prefered for inodes */
376 pag
= &mp
->m_perag
[index
];
377 pag
->pagi_inodeok
= 1;
378 if (index
< max_metadata
)
379 pag
->pagf_metadata
= 1;
382 /* Setup default behavior for smaller filesystems */
383 for (index
= 0; index
< agcount
; index
++) {
384 pag
= &mp
->m_perag
[index
];
385 pag
->pagi_inodeok
= 1;
394 * data - on disk version of sb
396 * dir - conversion direction: <0 - convert sb to buf
397 * >0 - convert buf to sb
398 * fields - which fields to copy (bitmask)
419 buf_ptr
= (xfs_caddr_t
)data
;
420 mem_ptr
= (xfs_caddr_t
)sb
;
423 f
= (xfs_sb_field_t
)xfs_lowbit64((__uint64_t
)fields
);
424 first
= xfs_sb_info
[f
].offset
;
425 size
= xfs_sb_info
[f
+ 1].offset
- first
;
427 ASSERT(xfs_sb_info
[f
].type
== 0 || xfs_sb_info
[f
].type
== 1);
429 if (size
== 1 || xfs_sb_info
[f
].type
== 1) {
431 memcpy(mem_ptr
+ first
, buf_ptr
+ first
, size
);
433 memcpy(buf_ptr
+ first
, mem_ptr
+ first
, size
);
438 INT_XLATE(*(__uint16_t
*)(buf_ptr
+first
),
439 *(__uint16_t
*)(mem_ptr
+first
),
443 INT_XLATE(*(__uint32_t
*)(buf_ptr
+first
),
444 *(__uint32_t
*)(mem_ptr
+first
),
448 INT_XLATE(*(__uint64_t
*)(buf_ptr
+first
),
449 *(__uint64_t
*)(mem_ptr
+first
), dir
, ARCH_CONVERT
);
456 fields
&= ~(1LL << f
);
463 * Does the initial read of the superblock.
466 xfs_readsb(xfs_mount_t
*mp
)
468 unsigned int sector_size
;
469 unsigned int extra_flags
;
474 ASSERT(mp
->m_sb_bp
== NULL
);
475 ASSERT(mp
->m_ddev_targp
!= NULL
);
478 * Allocate a (locked) buffer to hold the superblock.
479 * This will be kept around at all times to optimize
480 * access to the superblock.
482 sector_size
= xfs_getsize_buftarg(mp
->m_ddev_targp
);
483 extra_flags
= XFS_BUF_LOCK
| XFS_BUF_MANAGE
| XFS_BUF_MAPPED
;
485 bp
= xfs_buf_read_flags(mp
->m_ddev_targp
, XFS_SB_DADDR
,
486 BTOBB(sector_size
), extra_flags
);
487 if (!bp
|| XFS_BUF_ISERROR(bp
)) {
488 cmn_err(CE_WARN
, "XFS: SB read failed");
489 error
= bp
? XFS_BUF_GETERROR(bp
) : ENOMEM
;
492 ASSERT(XFS_BUF_ISBUSY(bp
));
493 ASSERT(XFS_BUF_VALUSEMA(bp
) <= 0);
496 * Initialize the mount structure from the superblock.
497 * But first do some basic consistency checking.
499 sbp
= XFS_BUF_TO_SBP(bp
);
500 xfs_xlatesb(XFS_BUF_PTR(bp
), &(mp
->m_sb
), 1, XFS_SB_ALL_BITS
);
502 error
= xfs_mount_validate_sb(mp
, &(mp
->m_sb
));
504 cmn_err(CE_WARN
, "XFS: SB validate failed");
509 * We must be able to do sector-sized and sector-aligned IO.
511 if (sector_size
> mp
->m_sb
.sb_sectsize
) {
513 "XFS: device supports only %u byte sectors (not %u)",
514 sector_size
, mp
->m_sb
.sb_sectsize
);
520 * If device sector size is smaller than the superblock size,
521 * re-read the superblock so the buffer is correctly sized.
523 if (sector_size
< mp
->m_sb
.sb_sectsize
) {
524 XFS_BUF_UNMANAGE(bp
);
526 sector_size
= mp
->m_sb
.sb_sectsize
;
527 bp
= xfs_buf_read_flags(mp
->m_ddev_targp
, XFS_SB_DADDR
,
528 BTOBB(sector_size
), extra_flags
);
529 if (!bp
|| XFS_BUF_ISERROR(bp
)) {
530 cmn_err(CE_WARN
, "XFS: SB re-read failed");
531 error
= bp
? XFS_BUF_GETERROR(bp
) : ENOMEM
;
534 ASSERT(XFS_BUF_ISBUSY(bp
));
535 ASSERT(XFS_BUF_VALUSEMA(bp
) <= 0);
540 ASSERT(XFS_BUF_VALUSEMA(bp
) > 0);
545 XFS_BUF_UNMANAGE(bp
);
555 * Mount initialization code establishing various mount
556 * fields from the superblock associated with the given
560 xfs_mount_common(xfs_mount_t
*mp
, xfs_sb_t
*sbp
)
564 mp
->m_agfrotor
= mp
->m_agirotor
= 0;
565 spinlock_init(&mp
->m_agirotor_lock
, "m_agirotor_lock");
566 mp
->m_maxagi
= mp
->m_sb
.sb_agcount
;
567 mp
->m_blkbit_log
= sbp
->sb_blocklog
+ XFS_NBBYLOG
;
568 mp
->m_blkbb_log
= sbp
->sb_blocklog
- BBSHIFT
;
569 mp
->m_sectbb_log
= sbp
->sb_sectlog
- BBSHIFT
;
570 mp
->m_agno_log
= xfs_highbit32(sbp
->sb_agcount
- 1) + 1;
571 mp
->m_agino_log
= sbp
->sb_inopblog
+ sbp
->sb_agblklog
;
572 mp
->m_litino
= sbp
->sb_inodesize
-
573 ((uint
)sizeof(xfs_dinode_core_t
) + (uint
)sizeof(xfs_agino_t
));
574 mp
->m_blockmask
= sbp
->sb_blocksize
- 1;
575 mp
->m_blockwsize
= sbp
->sb_blocksize
>> XFS_WORDLOG
;
576 mp
->m_blockwmask
= mp
->m_blockwsize
- 1;
577 INIT_LIST_HEAD(&mp
->m_del_inodes
);
580 * Setup for attributes, in case they get created.
581 * This value is for inodes getting attributes for the first time,
582 * the per-inode value is for old attribute values.
584 ASSERT(sbp
->sb_inodesize
>= 256 && sbp
->sb_inodesize
<= 2048);
585 switch (sbp
->sb_inodesize
) {
587 mp
->m_attroffset
= XFS_LITINO(mp
) - XFS_BMDR_SPACE_CALC(2);
592 mp
->m_attroffset
= XFS_BMDR_SPACE_CALC(12);
597 ASSERT(mp
->m_attroffset
< XFS_LITINO(mp
));
599 for (i
= 0; i
< 2; i
++) {
600 mp
->m_alloc_mxr
[i
] = XFS_BTREE_BLOCK_MAXRECS(sbp
->sb_blocksize
,
602 mp
->m_alloc_mnr
[i
] = XFS_BTREE_BLOCK_MINRECS(sbp
->sb_blocksize
,
605 for (i
= 0; i
< 2; i
++) {
606 mp
->m_bmap_dmxr
[i
] = XFS_BTREE_BLOCK_MAXRECS(sbp
->sb_blocksize
,
608 mp
->m_bmap_dmnr
[i
] = XFS_BTREE_BLOCK_MINRECS(sbp
->sb_blocksize
,
611 for (i
= 0; i
< 2; i
++) {
612 mp
->m_inobt_mxr
[i
] = XFS_BTREE_BLOCK_MAXRECS(sbp
->sb_blocksize
,
614 mp
->m_inobt_mnr
[i
] = XFS_BTREE_BLOCK_MINRECS(sbp
->sb_blocksize
,
618 mp
->m_bsize
= XFS_FSB_TO_BB(mp
, 1);
619 mp
->m_ialloc_inos
= (int)MAX((__uint16_t
)XFS_INODES_PER_CHUNK
,
621 mp
->m_ialloc_blks
= mp
->m_ialloc_inos
>> sbp
->sb_inopblog
;
626 * This function does the following on an initial mount of a file system:
627 * - reads the superblock from disk and init the mount struct
628 * - if we're a 32-bit kernel, do a size check on the superblock
629 * so we don't mount terabyte filesystems
630 * - init mount struct realtime fields
631 * - allocate inode hash table for fs
632 * - init directory manager
633 * - perform recovery and init the log manager
642 xfs_sb_t
*sbp
= &(mp
->m_sb
);
645 int readio_log
, writeio_log
;
648 __int64_t update_flags
;
649 uint quotamount
, quotaflags
;
651 int uuid_mounted
= 0;
654 if (mp
->m_sb_bp
== NULL
) {
655 if ((error
= xfs_readsb(mp
))) {
659 xfs_mount_common(mp
, sbp
);
662 * Check if sb_agblocks is aligned at stripe boundary
663 * If sb_agblocks is NOT aligned turn off m_dalign since
664 * allocator alignment is within an ag, therefore ag has
665 * to be aligned at stripe boundary.
668 if (mp
->m_dalign
&& !(mfsi_flags
& XFS_MFSI_SECOND
)) {
670 * If stripe unit and stripe width are not multiples
671 * of the fs blocksize turn off alignment.
673 if ((BBTOB(mp
->m_dalign
) & mp
->m_blockmask
) ||
674 (BBTOB(mp
->m_swidth
) & mp
->m_blockmask
)) {
675 if (mp
->m_flags
& XFS_MOUNT_RETERR
) {
677 "XFS: alignment check 1 failed");
678 error
= XFS_ERROR(EINVAL
);
681 mp
->m_dalign
= mp
->m_swidth
= 0;
684 * Convert the stripe unit and width to FSBs.
686 mp
->m_dalign
= XFS_BB_TO_FSBT(mp
, mp
->m_dalign
);
687 if (mp
->m_dalign
&& (sbp
->sb_agblocks
% mp
->m_dalign
)) {
688 if (mp
->m_flags
& XFS_MOUNT_RETERR
) {
689 error
= XFS_ERROR(EINVAL
);
692 xfs_fs_cmn_err(CE_WARN
, mp
,
693 "stripe alignment turned off: sunit(%d)/swidth(%d) incompatible with agsize(%d)",
694 mp
->m_dalign
, mp
->m_swidth
,
699 } else if (mp
->m_dalign
) {
700 mp
->m_swidth
= XFS_BB_TO_FSBT(mp
, mp
->m_swidth
);
702 if (mp
->m_flags
& XFS_MOUNT_RETERR
) {
703 xfs_fs_cmn_err(CE_WARN
, mp
,
704 "stripe alignment turned off: sunit(%d) less than bsize(%d)",
707 error
= XFS_ERROR(EINVAL
);
715 * Update superblock with new values
718 if (XFS_SB_VERSION_HASDALIGN(sbp
)) {
719 if (sbp
->sb_unit
!= mp
->m_dalign
) {
720 sbp
->sb_unit
= mp
->m_dalign
;
721 update_flags
|= XFS_SB_UNIT
;
723 if (sbp
->sb_width
!= mp
->m_swidth
) {
724 sbp
->sb_width
= mp
->m_swidth
;
725 update_flags
|= XFS_SB_WIDTH
;
728 } else if ((mp
->m_flags
& XFS_MOUNT_NOALIGN
) != XFS_MOUNT_NOALIGN
&&
729 XFS_SB_VERSION_HASDALIGN(&mp
->m_sb
)) {
730 mp
->m_dalign
= sbp
->sb_unit
;
731 mp
->m_swidth
= sbp
->sb_width
;
734 xfs_alloc_compute_maxlevels(mp
);
735 xfs_bmap_compute_maxlevels(mp
, XFS_DATA_FORK
);
736 xfs_bmap_compute_maxlevels(mp
, XFS_ATTR_FORK
);
737 xfs_ialloc_compute_maxlevels(mp
);
739 if (sbp
->sb_imax_pct
) {
742 /* Make sure the maximum inode count is a multiple of the
743 * units we allocate inodes in.
746 icount
= sbp
->sb_dblocks
* sbp
->sb_imax_pct
;
748 do_div(icount
, mp
->m_ialloc_blks
);
749 mp
->m_maxicount
= (icount
* mp
->m_ialloc_blks
) <<
754 mp
->m_maxioffset
= xfs_max_file_offset(sbp
->sb_blocklog
);
757 * XFS uses the uuid from the superblock as the unique
758 * identifier for fsid. We can not use the uuid from the volume
759 * since a single partition filesystem is identical to a single
760 * partition volume/filesystem.
762 if ((mfsi_flags
& XFS_MFSI_SECOND
) == 0 &&
763 (mp
->m_flags
& XFS_MOUNT_NOUUID
) == 0) {
764 if (xfs_uuid_mount(mp
)) {
765 error
= XFS_ERROR(EINVAL
);
769 ret64
= uuid_hash64(&sbp
->sb_uuid
);
770 memcpy(&vfsp
->vfs_fsid
, &ret64
, sizeof(ret64
));
774 * Set the default minimum read and write sizes unless
775 * already specified in a mount option.
776 * We use smaller I/O sizes when the file system
777 * is being used for NFS service (wsync mount option).
779 if (!(mp
->m_flags
& XFS_MOUNT_DFLT_IOSIZE
)) {
780 if (mp
->m_flags
& XFS_MOUNT_WSYNC
) {
781 readio_log
= XFS_WSYNC_READIO_LOG
;
782 writeio_log
= XFS_WSYNC_WRITEIO_LOG
;
784 readio_log
= XFS_READIO_LOG_LARGE
;
785 writeio_log
= XFS_WRITEIO_LOG_LARGE
;
788 readio_log
= mp
->m_readio_log
;
789 writeio_log
= mp
->m_writeio_log
;
793 * Set the number of readahead buffers to use based on
794 * physical memory size.
796 if (xfs_physmem
<= 4096) /* <= 16MB */
797 mp
->m_nreadaheads
= XFS_RW_NREADAHEAD_16MB
;
798 else if (xfs_physmem
<= 8192) /* <= 32MB */
799 mp
->m_nreadaheads
= XFS_RW_NREADAHEAD_32MB
;
801 mp
->m_nreadaheads
= XFS_RW_NREADAHEAD_K32
;
802 if (sbp
->sb_blocklog
> readio_log
) {
803 mp
->m_readio_log
= sbp
->sb_blocklog
;
805 mp
->m_readio_log
= readio_log
;
807 mp
->m_readio_blocks
= 1 << (mp
->m_readio_log
- sbp
->sb_blocklog
);
808 if (sbp
->sb_blocklog
> writeio_log
) {
809 mp
->m_writeio_log
= sbp
->sb_blocklog
;
811 mp
->m_writeio_log
= writeio_log
;
813 mp
->m_writeio_blocks
= 1 << (mp
->m_writeio_log
- sbp
->sb_blocklog
);
816 * Set the inode cluster size based on the physical memory
817 * size. This may still be overridden by the file system
818 * block size if it is larger than the chosen cluster size.
820 if (xfs_physmem
<= btoc(32 * 1024 * 1024)) { /* <= 32 MB */
821 mp
->m_inode_cluster_size
= XFS_INODE_SMALL_CLUSTER_SIZE
;
823 mp
->m_inode_cluster_size
= XFS_INODE_BIG_CLUSTER_SIZE
;
826 * Set whether we're using inode alignment.
828 if (XFS_SB_VERSION_HASALIGN(&mp
->m_sb
) &&
829 mp
->m_sb
.sb_inoalignmt
>=
830 XFS_B_TO_FSBT(mp
, mp
->m_inode_cluster_size
))
831 mp
->m_inoalign_mask
= mp
->m_sb
.sb_inoalignmt
- 1;
833 mp
->m_inoalign_mask
= 0;
835 * If we are using stripe alignment, check whether
836 * the stripe unit is a multiple of the inode alignment
838 if (mp
->m_dalign
&& mp
->m_inoalign_mask
&&
839 !(mp
->m_dalign
& mp
->m_inoalign_mask
))
840 mp
->m_sinoalign
= mp
->m_dalign
;
844 * Check that the data (and log if separate) are an ok size.
846 d
= (xfs_daddr_t
)XFS_FSB_TO_BB(mp
, mp
->m_sb
.sb_dblocks
);
847 if (XFS_BB_TO_FSB(mp
, d
) != mp
->m_sb
.sb_dblocks
) {
848 cmn_err(CE_WARN
, "XFS: size check 1 failed");
849 error
= XFS_ERROR(E2BIG
);
852 error
= xfs_read_buf(mp
, mp
->m_ddev_targp
,
853 d
- XFS_FSS_TO_BB(mp
, 1),
854 XFS_FSS_TO_BB(mp
, 1), 0, &bp
);
858 cmn_err(CE_WARN
, "XFS: size check 2 failed");
859 if (error
== ENOSPC
) {
860 error
= XFS_ERROR(E2BIG
);
865 if (((mfsi_flags
& XFS_MFSI_CLIENT
) == 0) &&
866 mp
->m_logdev_targp
!= mp
->m_ddev_targp
) {
867 d
= (xfs_daddr_t
)XFS_FSB_TO_BB(mp
, mp
->m_sb
.sb_logblocks
);
868 if (XFS_BB_TO_FSB(mp
, d
) != mp
->m_sb
.sb_logblocks
) {
869 cmn_err(CE_WARN
, "XFS: size check 3 failed");
870 error
= XFS_ERROR(E2BIG
);
873 error
= xfs_read_buf(mp
, mp
->m_logdev_targp
,
874 d
- XFS_FSB_TO_BB(mp
, 1),
875 XFS_FSB_TO_BB(mp
, 1), 0, &bp
);
879 cmn_err(CE_WARN
, "XFS: size check 3 failed");
880 if (error
== ENOSPC
) {
881 error
= XFS_ERROR(E2BIG
);
888 * Initialize realtime fields in the mount structure
890 if ((error
= xfs_rtmount_init(mp
))) {
891 cmn_err(CE_WARN
, "XFS: RT mount failed");
896 * For client case we are done now
898 if (mfsi_flags
& XFS_MFSI_CLIENT
) {
903 * Copies the low order bits of the timestamp and the randomly
904 * set "sequence" number out of a UUID.
906 uuid_getnodeuniq(&sbp
->sb_uuid
, mp
->m_fixedfsid
);
909 * The vfs structure needs to have a file system independent
910 * way of checking for the invariant file system ID. Since it
911 * can't look at mount structures it has a pointer to the data
912 * in the mount structure.
914 * File systems that don't support user level file handles (i.e.
915 * all of them except for XFS) will leave vfs_altfsid as NULL.
917 vfsp
->vfs_altfsid
= (xfs_fsid_t
*)mp
->m_fixedfsid
;
918 mp
->m_dmevmask
= 0; /* not persistent; set after each mount */
921 * Select the right directory manager.
924 XFS_SB_VERSION_HASDIRV2(&mp
->m_sb
) ?
929 * Initialize directory manager's entries.
934 * Initialize the attribute manager's entries.
936 mp
->m_attr_magicpct
= (mp
->m_sb
.sb_blocksize
* 37) / 100;
939 * Initialize the precomputed transaction reservations values.
944 * Allocate and initialize the inode hash table for this
951 * Allocate and initialize the per-ag data.
953 init_rwsem(&mp
->m_peraglock
);
955 kmem_zalloc(sbp
->sb_agcount
* sizeof(xfs_perag_t
), KM_SLEEP
);
957 mp
->m_maxagi
= xfs_initialize_perag(mp
, sbp
->sb_agcount
);
960 * log's mount-time initialization. Perform 1st part recovery if needed
962 if (likely(sbp
->sb_logblocks
> 0)) { /* check for volume case */
963 error
= xfs_log_mount(mp
, mp
->m_logdev_targp
,
964 XFS_FSB_TO_DADDR(mp
, sbp
->sb_logstart
),
965 XFS_FSB_TO_BB(mp
, sbp
->sb_logblocks
));
967 cmn_err(CE_WARN
, "XFS: log mount failed");
970 } else { /* No log has been defined */
971 cmn_err(CE_WARN
, "XFS: no log defined");
972 XFS_ERROR_REPORT("xfs_mountfs_int(1)", XFS_ERRLEVEL_LOW
, mp
);
973 error
= XFS_ERROR(EFSCORRUPTED
);
978 * Get and sanity-check the root inode.
979 * Save the pointer to it in the mount structure.
981 error
= xfs_iget(mp
, NULL
, sbp
->sb_rootino
, 0, XFS_ILOCK_EXCL
, &rip
, 0);
983 cmn_err(CE_WARN
, "XFS: failed to read root inode");
990 if (unlikely((rip
->i_d
.di_mode
& S_IFMT
) != S_IFDIR
)) {
991 cmn_err(CE_WARN
, "XFS: corrupted root inode");
992 prdev("Root inode %llu is not a directory",
993 mp
->m_ddev_targp
, (unsigned long long)rip
->i_ino
);
994 xfs_iunlock(rip
, XFS_ILOCK_EXCL
);
995 XFS_ERROR_REPORT("xfs_mountfs_int(2)", XFS_ERRLEVEL_LOW
,
997 error
= XFS_ERROR(EFSCORRUPTED
);
1000 mp
->m_rootip
= rip
; /* save it */
1002 xfs_iunlock(rip
, XFS_ILOCK_EXCL
);
1005 * Initialize realtime inode pointers in the mount structure
1007 if ((error
= xfs_rtmount_inodes(mp
))) {
1009 * Free up the root inode.
1011 cmn_err(CE_WARN
, "XFS: failed to read RT inodes");
1016 * If fs is not mounted readonly, then update the superblock
1017 * unit and width changes.
1019 if (update_flags
&& !(vfsp
->vfs_flag
& VFS_RDONLY
))
1020 xfs_mount_log_sbunit(mp
, update_flags
);
1023 * Initialise the XFS quota management subsystem for this mount
1025 if ((error
= XFS_QM_INIT(mp
, "amount
, "aflags
)))
1029 * Finish recovering the file system. This part needed to be
1030 * delayed until after the root and real-time bitmap inodes
1031 * were consistently read in.
1033 error
= xfs_log_mount_finish(mp
, mfsi_flags
);
1035 cmn_err(CE_WARN
, "XFS: log mount finish failed");
1040 * Complete the quota initialisation, post-log-replay component.
1042 if ((error
= XFS_QM_MOUNT(mp
, quotamount
, quotaflags
, mfsi_flags
)))
1049 * Free up the root inode.
1053 xfs_log_unmount_dealloc(mp
);
1057 for (agno
= 0; agno
< sbp
->sb_agcount
; agno
++)
1058 if (mp
->m_perag
[agno
].pagb_list
)
1059 kmem_free(mp
->m_perag
[agno
].pagb_list
,
1060 sizeof(xfs_perag_busy_t
) * XFS_PAGB_NUM_SLOTS
);
1061 kmem_free(mp
->m_perag
, sbp
->sb_agcount
* sizeof(xfs_perag_t
));
1066 xfs_uuid_unmount(mp
);
1074 * This flushes out the inodes,dquots and the superblock, unmounts the
1075 * log and makes sure that incore structures are freed.
1078 xfs_unmountfs(xfs_mount_t
*mp
, struct cred
*cr
)
1080 struct vfs
*vfsp
= XFS_MTOVFS(mp
);
1081 #if defined(DEBUG) || defined(INDUCE_IO_ERROR)
1087 XFS_QM_DQPURGEALL(mp
,
1088 XFS_QMOPT_UQUOTA
| XFS_QMOPT_GQUOTA
| XFS_QMOPT_UMOUNTING
);
1091 * Flush out the log synchronously so that we know for sure
1092 * that nothing is pinned. This is important because bflush()
1093 * will skip pinned buffers.
1095 xfs_log_force(mp
, (xfs_lsn_t
)0, XFS_LOG_FORCE
| XFS_LOG_SYNC
);
1097 xfs_binval(mp
->m_ddev_targp
);
1098 if (mp
->m_rtdev_targp
) {
1099 xfs_binval(mp
->m_rtdev_targp
);
1102 xfs_unmountfs_writesb(mp
);
1104 xfs_unmountfs_wait(mp
); /* wait for async bufs */
1106 xfs_log_unmount(mp
); /* Done! No more fs ops. */
1111 * All inodes from this mount point should be freed.
1113 ASSERT(mp
->m_inodes
== NULL
);
1115 xfs_unmountfs_close(mp
, cr
);
1116 if ((mp
->m_flags
& XFS_MOUNT_NOUUID
) == 0)
1117 xfs_uuid_unmount(mp
);
1119 #if defined(DEBUG) || defined(INDUCE_IO_ERROR)
1121 * clear all error tags on this filesystem
1123 memcpy(&fsid
, &vfsp
->vfs_fsid
, sizeof(int64_t));
1124 xfs_errortag_clearall_umount(fsid
, mp
->m_fsname
, 0);
1127 xfs_mount_free(mp
, 1);
1132 xfs_unmountfs_close(xfs_mount_t
*mp
, struct cred
*cr
)
1134 if (mp
->m_logdev_targp
!= mp
->m_ddev_targp
)
1135 xfs_free_buftarg(mp
->m_logdev_targp
, 1);
1136 if (mp
->m_rtdev_targp
)
1137 xfs_free_buftarg(mp
->m_rtdev_targp
, 1);
1138 xfs_free_buftarg(mp
->m_ddev_targp
, 0);
1142 xfs_unmountfs_wait(xfs_mount_t
*mp
)
1144 if (mp
->m_logdev_targp
!= mp
->m_ddev_targp
)
1145 xfs_wait_buftarg(mp
->m_logdev_targp
);
1146 if (mp
->m_rtdev_targp
)
1147 xfs_wait_buftarg(mp
->m_rtdev_targp
);
1148 xfs_wait_buftarg(mp
->m_ddev_targp
);
1152 xfs_unmountfs_writesb(xfs_mount_t
*mp
)
1159 * skip superblock write if fs is read-only, or
1160 * if we are doing a forced umount.
1162 sbp
= xfs_getsb(mp
, 0);
1163 if (!(XFS_MTOVFS(mp
)->vfs_flag
& VFS_RDONLY
||
1164 XFS_FORCED_SHUTDOWN(mp
))) {
1166 * mark shared-readonly if desired
1168 sb
= XFS_BUF_TO_SBP(sbp
);
1169 if (mp
->m_mk_sharedro
) {
1170 if (!(sb
->sb_flags
& XFS_SBF_READONLY
))
1171 sb
->sb_flags
|= XFS_SBF_READONLY
;
1172 if (!XFS_SB_VERSION_HASSHARED(sb
))
1173 XFS_SB_VERSION_ADDSHARED(sb
);
1174 xfs_fs_cmn_err(CE_NOTE
, mp
,
1175 "Unmounting, marking shared read-only");
1177 XFS_BUF_UNDONE(sbp
);
1178 XFS_BUF_UNREAD(sbp
);
1179 XFS_BUF_UNDELAYWRITE(sbp
);
1181 XFS_BUF_UNASYNC(sbp
);
1182 ASSERT(XFS_BUF_TARGET(sbp
) == mp
->m_ddev_targp
);
1183 xfsbdstrat(mp
, sbp
);
1184 /* Nevermind errors we might get here. */
1185 error
= xfs_iowait(sbp
);
1187 xfs_ioerror_alert("xfs_unmountfs_writesb",
1188 mp
, sbp
, XFS_BUF_ADDR(sbp
));
1189 if (error
&& mp
->m_mk_sharedro
)
1190 xfs_fs_cmn_err(CE_ALERT
, mp
, "Superblock write error detected while unmounting. Filesystem may not be marked shared readonly");
1197 * xfs_mod_sb() can be used to copy arbitrary changes to the
1198 * in-core superblock into the superblock buffer to be logged.
1199 * It does not provide the higher level of locking that is
1200 * needed to protect the in-core superblock from concurrent
1204 xfs_mod_sb(xfs_trans_t
*tp
, __int64_t fields
)
1217 bp
= xfs_trans_getsb(tp
, mp
, 0);
1218 sbp
= XFS_BUF_TO_SBP(bp
);
1219 first
= sizeof(xfs_sb_t
);
1222 /* translate/copy */
1224 xfs_xlatesb(XFS_BUF_PTR(bp
), &(mp
->m_sb
), -1, fields
);
1226 /* find modified range */
1228 f
= (xfs_sb_field_t
)xfs_lowbit64((__uint64_t
)fields
);
1229 ASSERT((1LL << f
) & XFS_SB_MOD_BITS
);
1230 first
= xfs_sb_info
[f
].offset
;
1232 f
= (xfs_sb_field_t
)xfs_highbit64((__uint64_t
)fields
);
1233 ASSERT((1LL << f
) & XFS_SB_MOD_BITS
);
1234 last
= xfs_sb_info
[f
+ 1].offset
- 1;
1236 xfs_trans_log_buf(tp
, bp
, first
, last
);
1240 * xfs_mod_incore_sb_unlocked() is a utility routine common used to apply
1241 * a delta to a specified field in the in-core superblock. Simply
1242 * switch on the field indicated and apply the delta to that field.
1243 * Fields are not allowed to dip below zero, so if the delta would
1244 * do this do not apply it and return EINVAL.
1246 * The SB_LOCK must be held when this routine is called.
1249 xfs_mod_incore_sb_unlocked(xfs_mount_t
*mp
, xfs_sb_field_t field
,
1250 int delta
, int rsvd
)
1252 int scounter
; /* short counter for 32 bit fields */
1253 long long lcounter
; /* long counter for 64 bit fields */
1254 long long res_used
, rem
;
1257 * With the in-core superblock spin lock held, switch
1258 * on the indicated field. Apply the delta to the
1259 * proper field. If the fields value would dip below
1260 * 0, then do not apply the delta and return EINVAL.
1263 case XFS_SBS_ICOUNT
:
1264 lcounter
= (long long)mp
->m_sb
.sb_icount
;
1268 return (XFS_ERROR(EINVAL
));
1270 mp
->m_sb
.sb_icount
= lcounter
;
1273 lcounter
= (long long)mp
->m_sb
.sb_ifree
;
1277 return (XFS_ERROR(EINVAL
));
1279 mp
->m_sb
.sb_ifree
= lcounter
;
1281 case XFS_SBS_FDBLOCKS
:
1283 lcounter
= (long long)mp
->m_sb
.sb_fdblocks
;
1284 res_used
= (long long)(mp
->m_resblks
- mp
->m_resblks_avail
);
1286 if (delta
> 0) { /* Putting blocks back */
1287 if (res_used
> delta
) {
1288 mp
->m_resblks_avail
+= delta
;
1290 rem
= delta
- res_used
;
1291 mp
->m_resblks_avail
= mp
->m_resblks
;
1294 } else { /* Taking blocks away */
1299 * If were out of blocks, use any available reserved blocks if
1305 lcounter
= (long long)mp
->m_resblks_avail
+ delta
;
1307 return (XFS_ERROR(ENOSPC
));
1309 mp
->m_resblks_avail
= lcounter
;
1311 } else { /* not reserved */
1312 return (XFS_ERROR(ENOSPC
));
1317 mp
->m_sb
.sb_fdblocks
= lcounter
;
1319 case XFS_SBS_FREXTENTS
:
1320 lcounter
= (long long)mp
->m_sb
.sb_frextents
;
1323 return (XFS_ERROR(ENOSPC
));
1325 mp
->m_sb
.sb_frextents
= lcounter
;
1327 case XFS_SBS_DBLOCKS
:
1328 lcounter
= (long long)mp
->m_sb
.sb_dblocks
;
1332 return (XFS_ERROR(EINVAL
));
1334 mp
->m_sb
.sb_dblocks
= lcounter
;
1336 case XFS_SBS_AGCOUNT
:
1337 scounter
= mp
->m_sb
.sb_agcount
;
1341 return (XFS_ERROR(EINVAL
));
1343 mp
->m_sb
.sb_agcount
= scounter
;
1345 case XFS_SBS_IMAX_PCT
:
1346 scounter
= mp
->m_sb
.sb_imax_pct
;
1350 return (XFS_ERROR(EINVAL
));
1352 mp
->m_sb
.sb_imax_pct
= scounter
;
1354 case XFS_SBS_REXTSIZE
:
1355 scounter
= mp
->m_sb
.sb_rextsize
;
1359 return (XFS_ERROR(EINVAL
));
1361 mp
->m_sb
.sb_rextsize
= scounter
;
1363 case XFS_SBS_RBMBLOCKS
:
1364 scounter
= mp
->m_sb
.sb_rbmblocks
;
1368 return (XFS_ERROR(EINVAL
));
1370 mp
->m_sb
.sb_rbmblocks
= scounter
;
1372 case XFS_SBS_RBLOCKS
:
1373 lcounter
= (long long)mp
->m_sb
.sb_rblocks
;
1377 return (XFS_ERROR(EINVAL
));
1379 mp
->m_sb
.sb_rblocks
= lcounter
;
1381 case XFS_SBS_REXTENTS
:
1382 lcounter
= (long long)mp
->m_sb
.sb_rextents
;
1386 return (XFS_ERROR(EINVAL
));
1388 mp
->m_sb
.sb_rextents
= lcounter
;
1390 case XFS_SBS_REXTSLOG
:
1391 scounter
= mp
->m_sb
.sb_rextslog
;
1395 return (XFS_ERROR(EINVAL
));
1397 mp
->m_sb
.sb_rextslog
= scounter
;
1401 return (XFS_ERROR(EINVAL
));
1406 * xfs_mod_incore_sb() is used to change a field in the in-core
1407 * superblock structure by the specified delta. This modification
1408 * is protected by the SB_LOCK. Just use the xfs_mod_incore_sb_unlocked()
1409 * routine to do the work.
1412 xfs_mod_incore_sb(xfs_mount_t
*mp
, xfs_sb_field_t field
, int delta
, int rsvd
)
1417 s
= XFS_SB_LOCK(mp
);
1418 status
= xfs_mod_incore_sb_unlocked(mp
, field
, delta
, rsvd
);
1419 XFS_SB_UNLOCK(mp
, s
);
1424 * xfs_mod_incore_sb_batch() is used to change more than one field
1425 * in the in-core superblock structure at a time. This modification
1426 * is protected by a lock internal to this module. The fields and
1427 * changes to those fields are specified in the array of xfs_mod_sb
1428 * structures passed in.
1430 * Either all of the specified deltas will be applied or none of
1431 * them will. If any modified field dips below 0, then all modifications
1432 * will be backed out and EINVAL will be returned.
1435 xfs_mod_incore_sb_batch(xfs_mount_t
*mp
, xfs_mod_sb_t
*msb
, uint nmsb
, int rsvd
)
1442 * Loop through the array of mod structures and apply each
1443 * individually. If any fail, then back out all those
1444 * which have already been applied. Do all of this within
1445 * the scope of the SB_LOCK so that all of the changes will
1448 s
= XFS_SB_LOCK(mp
);
1450 for (msbp
= &msbp
[0]; msbp
< (msb
+ nmsb
); msbp
++) {
1452 * Apply the delta at index n. If it fails, break
1453 * from the loop so we'll fall into the undo loop
1456 status
= xfs_mod_incore_sb_unlocked(mp
, msbp
->msb_field
,
1457 msbp
->msb_delta
, rsvd
);
1464 * If we didn't complete the loop above, then back out
1465 * any changes made to the superblock. If you add code
1466 * between the loop above and here, make sure that you
1467 * preserve the value of status. Loop back until
1468 * we step below the beginning of the array. Make sure
1469 * we don't touch anything back there.
1473 while (msbp
>= msb
) {
1474 status
= xfs_mod_incore_sb_unlocked(mp
,
1475 msbp
->msb_field
, -(msbp
->msb_delta
), rsvd
);
1476 ASSERT(status
== 0);
1480 XFS_SB_UNLOCK(mp
, s
);
1485 * xfs_getsb() is called to obtain the buffer for the superblock.
1486 * The buffer is returned locked and read in from disk.
1487 * The buffer should be released with a call to xfs_brelse().
1489 * If the flags parameter is BUF_TRYLOCK, then we'll only return
1490 * the superblock buffer if it can be locked without sleeping.
1491 * If it can't then we'll return NULL.
1500 ASSERT(mp
->m_sb_bp
!= NULL
);
1502 if (flags
& XFS_BUF_TRYLOCK
) {
1503 if (!XFS_BUF_CPSEMA(bp
)) {
1507 XFS_BUF_PSEMA(bp
, PRIBIO
);
1510 ASSERT(XFS_BUF_ISDONE(bp
));
1515 * Used to free the superblock along various error paths.
1524 * Use xfs_getsb() so that the buffer will be locked
1525 * when we call xfs_buf_relse().
1527 bp
= xfs_getsb(mp
, 0);
1528 XFS_BUF_UNMANAGE(bp
);
1534 * See if the UUID is unique among mounted XFS filesystems.
1535 * Mount fails if UUID is nil or a FS with the same UUID is already mounted.
1541 if (uuid_is_nil(&mp
->m_sb
.sb_uuid
)) {
1543 "XFS: Filesystem %s has nil UUID - can't mount",
1547 if (!uuid_table_insert(&mp
->m_sb
.sb_uuid
)) {
1549 "XFS: Filesystem %s has duplicate UUID - can't mount",
1557 * Remove filesystem from the UUID table.
1563 uuid_table_remove(&mp
->m_sb
.sb_uuid
);
1567 * Used to log changes to the superblock unit and width fields which could
1568 * be altered by the mount options. Only the first superblock is updated.
1571 xfs_mount_log_sbunit(
1577 ASSERT(fields
& (XFS_SB_UNIT
|XFS_SB_WIDTH
|XFS_SB_UUID
));
1579 tp
= xfs_trans_alloc(mp
, XFS_TRANS_SB_UNIT
);
1580 if (xfs_trans_reserve(tp
, 0, mp
->m_sb
.sb_sectsize
+ 128, 0, 0,
1581 XFS_DEFAULT_LOG_COUNT
)) {
1582 xfs_trans_cancel(tp
, 0);
1585 xfs_mod_sb(tp
, fields
);
1586 xfs_trans_commit(tp
, 0, NULL
);