2 * Copyright (c) 2000-2005 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_types.h"
38 #include "xfs_trans.h"
43 #include "xfs_dmapi.h"
44 #include "xfs_mount.h"
45 #include "xfs_bmap_btree.h"
46 #include "xfs_alloc_btree.h"
47 #include "xfs_ialloc_btree.h"
48 #include "xfs_dir_sf.h"
49 #include "xfs_dir2_sf.h"
50 #include "xfs_attr_sf.h"
51 #include "xfs_dinode.h"
52 #include "xfs_inode.h"
53 #include "xfs_btree.h"
54 #include "xfs_ialloc.h"
55 #include "xfs_alloc.h"
56 #include "xfs_rtalloc.h"
58 #include "xfs_error.h"
60 #include "xfs_quota.h"
61 #include "xfs_fsops.h"
63 STATIC
void xfs_mount_log_sbunit(xfs_mount_t
*, __int64_t
);
64 STATIC
int xfs_uuid_mount(xfs_mount_t
*);
65 STATIC
void xfs_uuid_unmount(xfs_mount_t
*mp
);
66 STATIC
void xfs_unmountfs_wait(xfs_mount_t
*);
70 short type
; /* 0 = integer
71 * 1 = binary / string (no translation)
74 { offsetof(xfs_sb_t
, sb_magicnum
), 0 },
75 { offsetof(xfs_sb_t
, sb_blocksize
), 0 },
76 { offsetof(xfs_sb_t
, sb_dblocks
), 0 },
77 { offsetof(xfs_sb_t
, sb_rblocks
), 0 },
78 { offsetof(xfs_sb_t
, sb_rextents
), 0 },
79 { offsetof(xfs_sb_t
, sb_uuid
), 1 },
80 { offsetof(xfs_sb_t
, sb_logstart
), 0 },
81 { offsetof(xfs_sb_t
, sb_rootino
), 0 },
82 { offsetof(xfs_sb_t
, sb_rbmino
), 0 },
83 { offsetof(xfs_sb_t
, sb_rsumino
), 0 },
84 { offsetof(xfs_sb_t
, sb_rextsize
), 0 },
85 { offsetof(xfs_sb_t
, sb_agblocks
), 0 },
86 { offsetof(xfs_sb_t
, sb_agcount
), 0 },
87 { offsetof(xfs_sb_t
, sb_rbmblocks
), 0 },
88 { offsetof(xfs_sb_t
, sb_logblocks
), 0 },
89 { offsetof(xfs_sb_t
, sb_versionnum
), 0 },
90 { offsetof(xfs_sb_t
, sb_sectsize
), 0 },
91 { offsetof(xfs_sb_t
, sb_inodesize
), 0 },
92 { offsetof(xfs_sb_t
, sb_inopblock
), 0 },
93 { offsetof(xfs_sb_t
, sb_fname
[0]), 1 },
94 { offsetof(xfs_sb_t
, sb_blocklog
), 0 },
95 { offsetof(xfs_sb_t
, sb_sectlog
), 0 },
96 { offsetof(xfs_sb_t
, sb_inodelog
), 0 },
97 { offsetof(xfs_sb_t
, sb_inopblog
), 0 },
98 { offsetof(xfs_sb_t
, sb_agblklog
), 0 },
99 { offsetof(xfs_sb_t
, sb_rextslog
), 0 },
100 { offsetof(xfs_sb_t
, sb_inprogress
), 0 },
101 { offsetof(xfs_sb_t
, sb_imax_pct
), 0 },
102 { offsetof(xfs_sb_t
, sb_icount
), 0 },
103 { offsetof(xfs_sb_t
, sb_ifree
), 0 },
104 { offsetof(xfs_sb_t
, sb_fdblocks
), 0 },
105 { offsetof(xfs_sb_t
, sb_frextents
), 0 },
106 { offsetof(xfs_sb_t
, sb_uquotino
), 0 },
107 { offsetof(xfs_sb_t
, sb_gquotino
), 0 },
108 { offsetof(xfs_sb_t
, sb_qflags
), 0 },
109 { offsetof(xfs_sb_t
, sb_flags
), 0 },
110 { offsetof(xfs_sb_t
, sb_shared_vn
), 0 },
111 { offsetof(xfs_sb_t
, sb_inoalignmt
), 0 },
112 { offsetof(xfs_sb_t
, sb_unit
), 0 },
113 { offsetof(xfs_sb_t
, sb_width
), 0 },
114 { offsetof(xfs_sb_t
, sb_dirblklog
), 0 },
115 { offsetof(xfs_sb_t
, sb_logsectlog
), 0 },
116 { offsetof(xfs_sb_t
, sb_logsectsize
),0 },
117 { offsetof(xfs_sb_t
, sb_logsunit
), 0 },
118 { offsetof(xfs_sb_t
, sb_features2
), 0 },
119 { sizeof(xfs_sb_t
), 0 }
123 * Return a pointer to an initialized xfs_mount structure.
130 mp
= kmem_zalloc(sizeof(*mp
), KM_SLEEP
);
132 AIL_LOCKINIT(&mp
->m_ail_lock
, "xfs_ail");
133 spinlock_init(&mp
->m_sb_lock
, "xfs_sb");
134 mutex_init(&mp
->m_ilock
, MUTEX_DEFAULT
, "xfs_ilock");
135 initnsema(&mp
->m_growlock
, 1, "xfs_grow");
137 * Initialize the AIL.
139 xfs_trans_ail_init(mp
);
141 atomic_set(&mp
->m_active_trans
, 0);
147 * Free up the resources associated with a mount structure. Assume that
148 * the structure was initially zeroed, so we can tell which fields got
164 for (agno
= 0; agno
< mp
->m_maxagi
; agno
++)
165 if (mp
->m_perag
[agno
].pagb_list
)
166 kmem_free(mp
->m_perag
[agno
].pagb_list
,
167 sizeof(xfs_perag_busy_t
) *
169 kmem_free(mp
->m_perag
,
170 sizeof(xfs_perag_t
) * mp
->m_sb
.sb_agcount
);
173 AIL_LOCK_DESTROY(&mp
->m_ail_lock
);
174 spinlock_destroy(&mp
->m_sb_lock
);
175 mutex_destroy(&mp
->m_ilock
);
176 freesema(&mp
->m_growlock
);
180 if (mp
->m_fsname
!= NULL
)
181 kmem_free(mp
->m_fsname
, mp
->m_fsname_len
);
182 if (mp
->m_rtname
!= NULL
)
183 kmem_free(mp
->m_rtname
, strlen(mp
->m_rtname
) + 1);
184 if (mp
->m_logname
!= NULL
)
185 kmem_free(mp
->m_logname
, strlen(mp
->m_logname
) + 1);
188 struct vfs
*vfsp
= XFS_MTOVFS(mp
);
190 bhv_remove_all_vfsops(vfsp
, 0);
191 VFS_REMOVEBHV(vfsp
, &mp
->m_bhv
);
194 kmem_free(mp
, sizeof(xfs_mount_t
));
199 * Check the validity of the SB found.
202 xfs_mount_validate_sb(
207 * If the log device and data device have the
208 * same device number, the log is internal.
209 * Consequently, the sb_logstart should be non-zero. If
210 * we have a zero sb_logstart in this case, we may be trying to mount
211 * a volume filesystem in a non-volume manner.
213 if (sbp
->sb_magicnum
!= XFS_SB_MAGIC
) {
214 cmn_err(CE_WARN
, "XFS: bad magic number");
215 return XFS_ERROR(EWRONGFS
);
218 if (!XFS_SB_GOOD_VERSION(sbp
)) {
219 cmn_err(CE_WARN
, "XFS: bad version");
220 return XFS_ERROR(EWRONGFS
);
224 sbp
->sb_logstart
== 0 && mp
->m_logdev_targp
== mp
->m_ddev_targp
)) {
226 "XFS: filesystem is marked as having an external log; "
227 "specify logdev on the\nmount command line.");
228 XFS_CORRUPTION_ERROR("xfs_mount_validate_sb(1)",
229 XFS_ERRLEVEL_HIGH
, mp
, sbp
);
230 return XFS_ERROR(EFSCORRUPTED
);
234 sbp
->sb_logstart
!= 0 && mp
->m_logdev_targp
!= mp
->m_ddev_targp
)) {
236 "XFS: filesystem is marked as having an internal log; "
237 "don't specify logdev on\nthe mount command line.");
238 XFS_CORRUPTION_ERROR("xfs_mount_validate_sb(2)",
239 XFS_ERRLEVEL_HIGH
, mp
, sbp
);
240 return XFS_ERROR(EFSCORRUPTED
);
244 * More sanity checking. These were stolen directly from
248 sbp
->sb_agcount
<= 0 ||
249 sbp
->sb_sectsize
< XFS_MIN_SECTORSIZE
||
250 sbp
->sb_sectsize
> XFS_MAX_SECTORSIZE
||
251 sbp
->sb_sectlog
< XFS_MIN_SECTORSIZE_LOG
||
252 sbp
->sb_sectlog
> XFS_MAX_SECTORSIZE_LOG
||
253 sbp
->sb_blocksize
< XFS_MIN_BLOCKSIZE
||
254 sbp
->sb_blocksize
> XFS_MAX_BLOCKSIZE
||
255 sbp
->sb_blocklog
< XFS_MIN_BLOCKSIZE_LOG
||
256 sbp
->sb_blocklog
> XFS_MAX_BLOCKSIZE_LOG
||
257 sbp
->sb_inodesize
< XFS_DINODE_MIN_SIZE
||
258 sbp
->sb_inodesize
> XFS_DINODE_MAX_SIZE
||
259 (sbp
->sb_rextsize
* sbp
->sb_blocksize
> XFS_MAX_RTEXTSIZE
) ||
260 (sbp
->sb_rextsize
* sbp
->sb_blocksize
< XFS_MIN_RTEXTSIZE
) ||
261 sbp
->sb_imax_pct
> 100)) {
262 cmn_err(CE_WARN
, "XFS: SB sanity check 1 failed");
263 XFS_CORRUPTION_ERROR("xfs_mount_validate_sb(3)",
264 XFS_ERRLEVEL_LOW
, mp
, sbp
);
265 return XFS_ERROR(EFSCORRUPTED
);
269 * Sanity check AG count, size fields against data size field
272 sbp
->sb_dblocks
== 0 ||
274 (xfs_drfsbno_t
)sbp
->sb_agcount
* sbp
->sb_agblocks
||
275 sbp
->sb_dblocks
< (xfs_drfsbno_t
)(sbp
->sb_agcount
- 1) *
276 sbp
->sb_agblocks
+ XFS_MIN_AG_BLOCKS
)) {
277 cmn_err(CE_WARN
, "XFS: SB sanity check 2 failed");
278 XFS_ERROR_REPORT("xfs_mount_validate_sb(4)",
279 XFS_ERRLEVEL_LOW
, mp
);
280 return XFS_ERROR(EFSCORRUPTED
);
283 ASSERT(PAGE_SHIFT
>= sbp
->sb_blocklog
);
284 ASSERT(sbp
->sb_blocklog
>= BBSHIFT
);
286 #if XFS_BIG_BLKNOS /* Limited by ULONG_MAX of page cache index */
288 (sbp
->sb_dblocks
>> (PAGE_SHIFT
- sbp
->sb_blocklog
)) > ULONG_MAX
||
289 (sbp
->sb_rblocks
>> (PAGE_SHIFT
- sbp
->sb_blocklog
)) > ULONG_MAX
)) {
290 #else /* Limited by UINT_MAX of sectors */
292 (sbp
->sb_dblocks
<< (sbp
->sb_blocklog
- BBSHIFT
)) > UINT_MAX
||
293 (sbp
->sb_rblocks
<< (sbp
->sb_blocklog
- BBSHIFT
)) > UINT_MAX
)) {
296 "XFS: File system is too large to be mounted on this system.");
297 return XFS_ERROR(E2BIG
);
300 if (unlikely(sbp
->sb_inprogress
)) {
301 cmn_err(CE_WARN
, "XFS: file system busy");
302 XFS_ERROR_REPORT("xfs_mount_validate_sb(5)",
303 XFS_ERRLEVEL_LOW
, mp
);
304 return XFS_ERROR(EFSCORRUPTED
);
308 * Version 1 directory format has never worked on Linux.
310 if (unlikely(!XFS_SB_VERSION_HASDIRV2(sbp
))) {
312 "XFS: Attempted to mount file system using version 1 directory format");
313 return XFS_ERROR(ENOSYS
);
317 * Until this is fixed only page-sized or smaller data blocks work.
319 if (unlikely(sbp
->sb_blocksize
> PAGE_SIZE
)) {
321 "XFS: Attempted to mount file system with blocksize %d bytes",
324 "XFS: Only page-sized (%ld) or less blocksizes currently work.",
326 return XFS_ERROR(ENOSYS
);
333 xfs_initialize_perag(xfs_mount_t
*mp
, xfs_agnumber_t agcount
)
335 xfs_agnumber_t index
, max_metadata
;
339 xfs_sb_t
*sbp
= &mp
->m_sb
;
340 xfs_ino_t max_inum
= XFS_MAXINUMBER_32
;
342 /* Check to see if the filesystem can overflow 32 bit inodes */
343 agino
= XFS_OFFBNO_TO_AGINO(mp
, sbp
->sb_agblocks
- 1, 0);
344 ino
= XFS_AGINO_TO_INO(mp
, agcount
- 1, agino
);
346 /* Clear the mount flag if no inode can overflow 32 bits
347 * on this filesystem, or if specifically requested..
349 if ((mp
->m_flags
& XFS_MOUNT_32BITINOOPT
) && ino
> max_inum
) {
350 mp
->m_flags
|= XFS_MOUNT_32BITINODES
;
352 mp
->m_flags
&= ~XFS_MOUNT_32BITINODES
;
355 /* If we can overflow then setup the ag headers accordingly */
356 if (mp
->m_flags
& XFS_MOUNT_32BITINODES
) {
357 /* Calculate how much should be reserved for inodes to
358 * meet the max inode percentage.
360 if (mp
->m_maxicount
) {
363 icount
= sbp
->sb_dblocks
* sbp
->sb_imax_pct
;
365 icount
+= sbp
->sb_agblocks
- 1;
366 do_div(icount
, mp
->m_ialloc_blks
);
367 max_metadata
= icount
;
369 max_metadata
= agcount
;
371 for (index
= 0; index
< agcount
; index
++) {
372 ino
= XFS_AGINO_TO_INO(mp
, index
, agino
);
373 if (ino
> max_inum
) {
378 /* This ag is prefered for inodes */
379 pag
= &mp
->m_perag
[index
];
380 pag
->pagi_inodeok
= 1;
381 if (index
< max_metadata
)
382 pag
->pagf_metadata
= 1;
385 /* Setup default behavior for smaller filesystems */
386 for (index
= 0; index
< agcount
; index
++) {
387 pag
= &mp
->m_perag
[index
];
388 pag
->pagi_inodeok
= 1;
397 * data - on disk version of sb
399 * dir - conversion direction: <0 - convert sb to buf
400 * >0 - convert buf to sb
401 * fields - which fields to copy (bitmask)
422 buf_ptr
= (xfs_caddr_t
)data
;
423 mem_ptr
= (xfs_caddr_t
)sb
;
426 f
= (xfs_sb_field_t
)xfs_lowbit64((__uint64_t
)fields
);
427 first
= xfs_sb_info
[f
].offset
;
428 size
= xfs_sb_info
[f
+ 1].offset
- first
;
430 ASSERT(xfs_sb_info
[f
].type
== 0 || xfs_sb_info
[f
].type
== 1);
432 if (size
== 1 || xfs_sb_info
[f
].type
== 1) {
434 memcpy(mem_ptr
+ first
, buf_ptr
+ first
, size
);
436 memcpy(buf_ptr
+ first
, mem_ptr
+ first
, size
);
441 INT_XLATE(*(__uint16_t
*)(buf_ptr
+first
),
442 *(__uint16_t
*)(mem_ptr
+first
),
446 INT_XLATE(*(__uint32_t
*)(buf_ptr
+first
),
447 *(__uint32_t
*)(mem_ptr
+first
),
451 INT_XLATE(*(__uint64_t
*)(buf_ptr
+first
),
452 *(__uint64_t
*)(mem_ptr
+first
), dir
, ARCH_CONVERT
);
459 fields
&= ~(1LL << f
);
466 * Does the initial read of the superblock.
469 xfs_readsb(xfs_mount_t
*mp
)
471 unsigned int sector_size
;
472 unsigned int extra_flags
;
477 ASSERT(mp
->m_sb_bp
== NULL
);
478 ASSERT(mp
->m_ddev_targp
!= NULL
);
481 * Allocate a (locked) buffer to hold the superblock.
482 * This will be kept around at all times to optimize
483 * access to the superblock.
485 sector_size
= xfs_getsize_buftarg(mp
->m_ddev_targp
);
486 extra_flags
= XFS_BUF_LOCK
| XFS_BUF_MANAGE
| XFS_BUF_MAPPED
;
488 bp
= xfs_buf_read_flags(mp
->m_ddev_targp
, XFS_SB_DADDR
,
489 BTOBB(sector_size
), extra_flags
);
490 if (!bp
|| XFS_BUF_ISERROR(bp
)) {
491 cmn_err(CE_WARN
, "XFS: SB read failed");
492 error
= bp
? XFS_BUF_GETERROR(bp
) : ENOMEM
;
495 ASSERT(XFS_BUF_ISBUSY(bp
));
496 ASSERT(XFS_BUF_VALUSEMA(bp
) <= 0);
499 * Initialize the mount structure from the superblock.
500 * But first do some basic consistency checking.
502 sbp
= XFS_BUF_TO_SBP(bp
);
503 xfs_xlatesb(XFS_BUF_PTR(bp
), &(mp
->m_sb
), 1, XFS_SB_ALL_BITS
);
505 error
= xfs_mount_validate_sb(mp
, &(mp
->m_sb
));
507 cmn_err(CE_WARN
, "XFS: SB validate failed");
512 * We must be able to do sector-sized and sector-aligned IO.
514 if (sector_size
> mp
->m_sb
.sb_sectsize
) {
516 "XFS: device supports only %u byte sectors (not %u)",
517 sector_size
, mp
->m_sb
.sb_sectsize
);
523 * If device sector size is smaller than the superblock size,
524 * re-read the superblock so the buffer is correctly sized.
526 if (sector_size
< mp
->m_sb
.sb_sectsize
) {
527 XFS_BUF_UNMANAGE(bp
);
529 sector_size
= mp
->m_sb
.sb_sectsize
;
530 bp
= xfs_buf_read_flags(mp
->m_ddev_targp
, XFS_SB_DADDR
,
531 BTOBB(sector_size
), extra_flags
);
532 if (!bp
|| XFS_BUF_ISERROR(bp
)) {
533 cmn_err(CE_WARN
, "XFS: SB re-read failed");
534 error
= bp
? XFS_BUF_GETERROR(bp
) : ENOMEM
;
537 ASSERT(XFS_BUF_ISBUSY(bp
));
538 ASSERT(XFS_BUF_VALUSEMA(bp
) <= 0);
543 ASSERT(XFS_BUF_VALUSEMA(bp
) > 0);
548 XFS_BUF_UNMANAGE(bp
);
558 * Mount initialization code establishing various mount
559 * fields from the superblock associated with the given
563 xfs_mount_common(xfs_mount_t
*mp
, xfs_sb_t
*sbp
)
567 mp
->m_agfrotor
= mp
->m_agirotor
= 0;
568 spinlock_init(&mp
->m_agirotor_lock
, "m_agirotor_lock");
569 mp
->m_maxagi
= mp
->m_sb
.sb_agcount
;
570 mp
->m_blkbit_log
= sbp
->sb_blocklog
+ XFS_NBBYLOG
;
571 mp
->m_blkbb_log
= sbp
->sb_blocklog
- BBSHIFT
;
572 mp
->m_sectbb_log
= sbp
->sb_sectlog
- BBSHIFT
;
573 mp
->m_agno_log
= xfs_highbit32(sbp
->sb_agcount
- 1) + 1;
574 mp
->m_agino_log
= sbp
->sb_inopblog
+ sbp
->sb_agblklog
;
575 mp
->m_litino
= sbp
->sb_inodesize
-
576 ((uint
)sizeof(xfs_dinode_core_t
) + (uint
)sizeof(xfs_agino_t
));
577 mp
->m_blockmask
= sbp
->sb_blocksize
- 1;
578 mp
->m_blockwsize
= sbp
->sb_blocksize
>> XFS_WORDLOG
;
579 mp
->m_blockwmask
= mp
->m_blockwsize
- 1;
580 INIT_LIST_HEAD(&mp
->m_del_inodes
);
583 * Setup for attributes, in case they get created.
584 * This value is for inodes getting attributes for the first time,
585 * the per-inode value is for old attribute values.
587 ASSERT(sbp
->sb_inodesize
>= 256 && sbp
->sb_inodesize
<= 2048);
588 switch (sbp
->sb_inodesize
) {
590 mp
->m_attroffset
= XFS_LITINO(mp
) -
591 XFS_BMDR_SPACE_CALC(MINABTPTRS
);
596 mp
->m_attroffset
= XFS_BMDR_SPACE_CALC(6 * MINABTPTRS
);
601 ASSERT(mp
->m_attroffset
< XFS_LITINO(mp
));
603 for (i
= 0; i
< 2; i
++) {
604 mp
->m_alloc_mxr
[i
] = XFS_BTREE_BLOCK_MAXRECS(sbp
->sb_blocksize
,
606 mp
->m_alloc_mnr
[i
] = XFS_BTREE_BLOCK_MINRECS(sbp
->sb_blocksize
,
609 for (i
= 0; i
< 2; i
++) {
610 mp
->m_bmap_dmxr
[i
] = XFS_BTREE_BLOCK_MAXRECS(sbp
->sb_blocksize
,
612 mp
->m_bmap_dmnr
[i
] = XFS_BTREE_BLOCK_MINRECS(sbp
->sb_blocksize
,
615 for (i
= 0; i
< 2; i
++) {
616 mp
->m_inobt_mxr
[i
] = XFS_BTREE_BLOCK_MAXRECS(sbp
->sb_blocksize
,
618 mp
->m_inobt_mnr
[i
] = XFS_BTREE_BLOCK_MINRECS(sbp
->sb_blocksize
,
622 mp
->m_bsize
= XFS_FSB_TO_BB(mp
, 1);
623 mp
->m_ialloc_inos
= (int)MAX((__uint16_t
)XFS_INODES_PER_CHUNK
,
625 mp
->m_ialloc_blks
= mp
->m_ialloc_inos
>> sbp
->sb_inopblog
;
630 * This function does the following on an initial mount of a file system:
631 * - reads the superblock from disk and init the mount struct
632 * - if we're a 32-bit kernel, do a size check on the superblock
633 * so we don't mount terabyte filesystems
634 * - init mount struct realtime fields
635 * - allocate inode hash table for fs
636 * - init directory manager
637 * - perform recovery and init the log manager
646 xfs_sb_t
*sbp
= &(mp
->m_sb
);
649 int readio_log
, writeio_log
;
652 __int64_t update_flags
;
653 uint quotamount
, quotaflags
;
655 int uuid_mounted
= 0;
658 if (mp
->m_sb_bp
== NULL
) {
659 if ((error
= xfs_readsb(mp
))) {
663 xfs_mount_common(mp
, sbp
);
666 * Check if sb_agblocks is aligned at stripe boundary
667 * If sb_agblocks is NOT aligned turn off m_dalign since
668 * allocator alignment is within an ag, therefore ag has
669 * to be aligned at stripe boundary.
672 if (mp
->m_dalign
&& !(mfsi_flags
& XFS_MFSI_SECOND
)) {
674 * If stripe unit and stripe width are not multiples
675 * of the fs blocksize turn off alignment.
677 if ((BBTOB(mp
->m_dalign
) & mp
->m_blockmask
) ||
678 (BBTOB(mp
->m_swidth
) & mp
->m_blockmask
)) {
679 if (mp
->m_flags
& XFS_MOUNT_RETERR
) {
681 "XFS: alignment check 1 failed");
682 error
= XFS_ERROR(EINVAL
);
685 mp
->m_dalign
= mp
->m_swidth
= 0;
688 * Convert the stripe unit and width to FSBs.
690 mp
->m_dalign
= XFS_BB_TO_FSBT(mp
, mp
->m_dalign
);
691 if (mp
->m_dalign
&& (sbp
->sb_agblocks
% mp
->m_dalign
)) {
692 if (mp
->m_flags
& XFS_MOUNT_RETERR
) {
693 error
= XFS_ERROR(EINVAL
);
696 xfs_fs_cmn_err(CE_WARN
, mp
,
697 "stripe alignment turned off: sunit(%d)/swidth(%d) incompatible with agsize(%d)",
698 mp
->m_dalign
, mp
->m_swidth
,
703 } else if (mp
->m_dalign
) {
704 mp
->m_swidth
= XFS_BB_TO_FSBT(mp
, mp
->m_swidth
);
706 if (mp
->m_flags
& XFS_MOUNT_RETERR
) {
707 xfs_fs_cmn_err(CE_WARN
, mp
,
708 "stripe alignment turned off: sunit(%d) less than bsize(%d)",
711 error
= XFS_ERROR(EINVAL
);
719 * Update superblock with new values
722 if (XFS_SB_VERSION_HASDALIGN(sbp
)) {
723 if (sbp
->sb_unit
!= mp
->m_dalign
) {
724 sbp
->sb_unit
= mp
->m_dalign
;
725 update_flags
|= XFS_SB_UNIT
;
727 if (sbp
->sb_width
!= mp
->m_swidth
) {
728 sbp
->sb_width
= mp
->m_swidth
;
729 update_flags
|= XFS_SB_WIDTH
;
732 } else if ((mp
->m_flags
& XFS_MOUNT_NOALIGN
) != XFS_MOUNT_NOALIGN
&&
733 XFS_SB_VERSION_HASDALIGN(&mp
->m_sb
)) {
734 mp
->m_dalign
= sbp
->sb_unit
;
735 mp
->m_swidth
= sbp
->sb_width
;
738 xfs_alloc_compute_maxlevels(mp
);
739 xfs_bmap_compute_maxlevels(mp
, XFS_DATA_FORK
);
740 xfs_bmap_compute_maxlevels(mp
, XFS_ATTR_FORK
);
741 xfs_ialloc_compute_maxlevels(mp
);
743 if (sbp
->sb_imax_pct
) {
746 /* Make sure the maximum inode count is a multiple of the
747 * units we allocate inodes in.
750 icount
= sbp
->sb_dblocks
* sbp
->sb_imax_pct
;
752 do_div(icount
, mp
->m_ialloc_blks
);
753 mp
->m_maxicount
= (icount
* mp
->m_ialloc_blks
) <<
758 mp
->m_maxioffset
= xfs_max_file_offset(sbp
->sb_blocklog
);
761 * XFS uses the uuid from the superblock as the unique
762 * identifier for fsid. We can not use the uuid from the volume
763 * since a single partition filesystem is identical to a single
764 * partition volume/filesystem.
766 if ((mfsi_flags
& XFS_MFSI_SECOND
) == 0 &&
767 (mp
->m_flags
& XFS_MOUNT_NOUUID
) == 0) {
768 if (xfs_uuid_mount(mp
)) {
769 error
= XFS_ERROR(EINVAL
);
773 ret64
= uuid_hash64(&sbp
->sb_uuid
);
774 memcpy(&vfsp
->vfs_fsid
, &ret64
, sizeof(ret64
));
778 * Set the default minimum read and write sizes unless
779 * already specified in a mount option.
780 * We use smaller I/O sizes when the file system
781 * is being used for NFS service (wsync mount option).
783 if (!(mp
->m_flags
& XFS_MOUNT_DFLT_IOSIZE
)) {
784 if (mp
->m_flags
& XFS_MOUNT_WSYNC
) {
785 readio_log
= XFS_WSYNC_READIO_LOG
;
786 writeio_log
= XFS_WSYNC_WRITEIO_LOG
;
788 readio_log
= XFS_READIO_LOG_LARGE
;
789 writeio_log
= XFS_WRITEIO_LOG_LARGE
;
792 readio_log
= mp
->m_readio_log
;
793 writeio_log
= mp
->m_writeio_log
;
797 * Set the number of readahead buffers to use based on
798 * physical memory size.
800 if (xfs_physmem
<= 4096) /* <= 16MB */
801 mp
->m_nreadaheads
= XFS_RW_NREADAHEAD_16MB
;
802 else if (xfs_physmem
<= 8192) /* <= 32MB */
803 mp
->m_nreadaheads
= XFS_RW_NREADAHEAD_32MB
;
805 mp
->m_nreadaheads
= XFS_RW_NREADAHEAD_K32
;
806 if (sbp
->sb_blocklog
> readio_log
) {
807 mp
->m_readio_log
= sbp
->sb_blocklog
;
809 mp
->m_readio_log
= readio_log
;
811 mp
->m_readio_blocks
= 1 << (mp
->m_readio_log
- sbp
->sb_blocklog
);
812 if (sbp
->sb_blocklog
> writeio_log
) {
813 mp
->m_writeio_log
= sbp
->sb_blocklog
;
815 mp
->m_writeio_log
= writeio_log
;
817 mp
->m_writeio_blocks
= 1 << (mp
->m_writeio_log
- sbp
->sb_blocklog
);
820 * Set the inode cluster size based on the physical memory
821 * size. This may still be overridden by the file system
822 * block size if it is larger than the chosen cluster size.
824 if (xfs_physmem
<= btoc(32 * 1024 * 1024)) { /* <= 32 MB */
825 mp
->m_inode_cluster_size
= XFS_INODE_SMALL_CLUSTER_SIZE
;
827 mp
->m_inode_cluster_size
= XFS_INODE_BIG_CLUSTER_SIZE
;
830 * Set whether we're using inode alignment.
832 if (XFS_SB_VERSION_HASALIGN(&mp
->m_sb
) &&
833 mp
->m_sb
.sb_inoalignmt
>=
834 XFS_B_TO_FSBT(mp
, mp
->m_inode_cluster_size
))
835 mp
->m_inoalign_mask
= mp
->m_sb
.sb_inoalignmt
- 1;
837 mp
->m_inoalign_mask
= 0;
839 * If we are using stripe alignment, check whether
840 * the stripe unit is a multiple of the inode alignment
842 if (mp
->m_dalign
&& mp
->m_inoalign_mask
&&
843 !(mp
->m_dalign
& mp
->m_inoalign_mask
))
844 mp
->m_sinoalign
= mp
->m_dalign
;
848 * Check that the data (and log if separate) are an ok size.
850 d
= (xfs_daddr_t
)XFS_FSB_TO_BB(mp
, mp
->m_sb
.sb_dblocks
);
851 if (XFS_BB_TO_FSB(mp
, d
) != mp
->m_sb
.sb_dblocks
) {
852 cmn_err(CE_WARN
, "XFS: size check 1 failed");
853 error
= XFS_ERROR(E2BIG
);
856 error
= xfs_read_buf(mp
, mp
->m_ddev_targp
,
857 d
- XFS_FSS_TO_BB(mp
, 1),
858 XFS_FSS_TO_BB(mp
, 1), 0, &bp
);
862 cmn_err(CE_WARN
, "XFS: size check 2 failed");
863 if (error
== ENOSPC
) {
864 error
= XFS_ERROR(E2BIG
);
869 if (((mfsi_flags
& XFS_MFSI_CLIENT
) == 0) &&
870 mp
->m_logdev_targp
!= mp
->m_ddev_targp
) {
871 d
= (xfs_daddr_t
)XFS_FSB_TO_BB(mp
, mp
->m_sb
.sb_logblocks
);
872 if (XFS_BB_TO_FSB(mp
, d
) != mp
->m_sb
.sb_logblocks
) {
873 cmn_err(CE_WARN
, "XFS: size check 3 failed");
874 error
= XFS_ERROR(E2BIG
);
877 error
= xfs_read_buf(mp
, mp
->m_logdev_targp
,
878 d
- XFS_FSB_TO_BB(mp
, 1),
879 XFS_FSB_TO_BB(mp
, 1), 0, &bp
);
883 cmn_err(CE_WARN
, "XFS: size check 3 failed");
884 if (error
== ENOSPC
) {
885 error
= XFS_ERROR(E2BIG
);
892 * Initialize realtime fields in the mount structure
894 if ((error
= xfs_rtmount_init(mp
))) {
895 cmn_err(CE_WARN
, "XFS: RT mount failed");
900 * For client case we are done now
902 if (mfsi_flags
& XFS_MFSI_CLIENT
) {
907 * Copies the low order bits of the timestamp and the randomly
908 * set "sequence" number out of a UUID.
910 uuid_getnodeuniq(&sbp
->sb_uuid
, mp
->m_fixedfsid
);
913 * The vfs structure needs to have a file system independent
914 * way of checking for the invariant file system ID. Since it
915 * can't look at mount structures it has a pointer to the data
916 * in the mount structure.
918 * File systems that don't support user level file handles (i.e.
919 * all of them except for XFS) will leave vfs_altfsid as NULL.
921 vfsp
->vfs_altfsid
= (xfs_fsid_t
*)mp
->m_fixedfsid
;
922 mp
->m_dmevmask
= 0; /* not persistent; set after each mount */
925 * Select the right directory manager.
928 XFS_SB_VERSION_HASDIRV2(&mp
->m_sb
) ?
933 * Initialize directory manager's entries.
938 * Initialize the attribute manager's entries.
940 mp
->m_attr_magicpct
= (mp
->m_sb
.sb_blocksize
* 37) / 100;
943 * Initialize the precomputed transaction reservations values.
948 * Allocate and initialize the inode hash table for this
955 * Allocate and initialize the per-ag data.
957 init_rwsem(&mp
->m_peraglock
);
959 kmem_zalloc(sbp
->sb_agcount
* sizeof(xfs_perag_t
), KM_SLEEP
);
961 mp
->m_maxagi
= xfs_initialize_perag(mp
, sbp
->sb_agcount
);
964 * log's mount-time initialization. Perform 1st part recovery if needed
966 if (likely(sbp
->sb_logblocks
> 0)) { /* check for volume case */
967 error
= xfs_log_mount(mp
, mp
->m_logdev_targp
,
968 XFS_FSB_TO_DADDR(mp
, sbp
->sb_logstart
),
969 XFS_FSB_TO_BB(mp
, sbp
->sb_logblocks
));
971 cmn_err(CE_WARN
, "XFS: log mount failed");
974 } else { /* No log has been defined */
975 cmn_err(CE_WARN
, "XFS: no log defined");
976 XFS_ERROR_REPORT("xfs_mountfs_int(1)", XFS_ERRLEVEL_LOW
, mp
);
977 error
= XFS_ERROR(EFSCORRUPTED
);
982 * Get and sanity-check the root inode.
983 * Save the pointer to it in the mount structure.
985 error
= xfs_iget(mp
, NULL
, sbp
->sb_rootino
, 0, XFS_ILOCK_EXCL
, &rip
, 0);
987 cmn_err(CE_WARN
, "XFS: failed to read root inode");
994 if (unlikely((rip
->i_d
.di_mode
& S_IFMT
) != S_IFDIR
)) {
995 cmn_err(CE_WARN
, "XFS: corrupted root inode");
996 prdev("Root inode %llu is not a directory",
997 mp
->m_ddev_targp
, (unsigned long long)rip
->i_ino
);
998 xfs_iunlock(rip
, XFS_ILOCK_EXCL
);
999 XFS_ERROR_REPORT("xfs_mountfs_int(2)", XFS_ERRLEVEL_LOW
,
1001 error
= XFS_ERROR(EFSCORRUPTED
);
1004 mp
->m_rootip
= rip
; /* save it */
1006 xfs_iunlock(rip
, XFS_ILOCK_EXCL
);
1009 * Initialize realtime inode pointers in the mount structure
1011 if ((error
= xfs_rtmount_inodes(mp
))) {
1013 * Free up the root inode.
1015 cmn_err(CE_WARN
, "XFS: failed to read RT inodes");
1020 * If fs is not mounted readonly, then update the superblock
1021 * unit and width changes.
1023 if (update_flags
&& !(vfsp
->vfs_flag
& VFS_RDONLY
))
1024 xfs_mount_log_sbunit(mp
, update_flags
);
1027 * Initialise the XFS quota management subsystem for this mount
1029 if ((error
= XFS_QM_INIT(mp
, "amount
, "aflags
)))
1033 * Finish recovering the file system. This part needed to be
1034 * delayed until after the root and real-time bitmap inodes
1035 * were consistently read in.
1037 error
= xfs_log_mount_finish(mp
, mfsi_flags
);
1039 cmn_err(CE_WARN
, "XFS: log mount finish failed");
1044 * Complete the quota initialisation, post-log-replay component.
1046 if ((error
= XFS_QM_MOUNT(mp
, quotamount
, quotaflags
, mfsi_flags
)))
1053 * Free up the root inode.
1057 xfs_log_unmount_dealloc(mp
);
1061 for (agno
= 0; agno
< sbp
->sb_agcount
; agno
++)
1062 if (mp
->m_perag
[agno
].pagb_list
)
1063 kmem_free(mp
->m_perag
[agno
].pagb_list
,
1064 sizeof(xfs_perag_busy_t
) * XFS_PAGB_NUM_SLOTS
);
1065 kmem_free(mp
->m_perag
, sbp
->sb_agcount
* sizeof(xfs_perag_t
));
1070 xfs_uuid_unmount(mp
);
1078 * This flushes out the inodes,dquots and the superblock, unmounts the
1079 * log and makes sure that incore structures are freed.
1082 xfs_unmountfs(xfs_mount_t
*mp
, struct cred
*cr
)
1084 struct vfs
*vfsp
= XFS_MTOVFS(mp
);
1085 #if defined(DEBUG) || defined(INDUCE_IO_ERROR)
1091 XFS_QM_DQPURGEALL(mp
,
1092 XFS_QMOPT_UQUOTA
| XFS_QMOPT_GQUOTA
| XFS_QMOPT_UMOUNTING
);
1095 * Flush out the log synchronously so that we know for sure
1096 * that nothing is pinned. This is important because bflush()
1097 * will skip pinned buffers.
1099 xfs_log_force(mp
, (xfs_lsn_t
)0, XFS_LOG_FORCE
| XFS_LOG_SYNC
);
1101 xfs_binval(mp
->m_ddev_targp
);
1102 if (mp
->m_rtdev_targp
) {
1103 xfs_binval(mp
->m_rtdev_targp
);
1106 xfs_unmountfs_writesb(mp
);
1108 xfs_unmountfs_wait(mp
); /* wait for async bufs */
1110 xfs_log_unmount(mp
); /* Done! No more fs ops. */
1115 * All inodes from this mount point should be freed.
1117 ASSERT(mp
->m_inodes
== NULL
);
1119 xfs_unmountfs_close(mp
, cr
);
1120 if ((mp
->m_flags
& XFS_MOUNT_NOUUID
) == 0)
1121 xfs_uuid_unmount(mp
);
1123 #if defined(DEBUG) || defined(INDUCE_IO_ERROR)
1125 * clear all error tags on this filesystem
1127 memcpy(&fsid
, &vfsp
->vfs_fsid
, sizeof(int64_t));
1128 xfs_errortag_clearall_umount(fsid
, mp
->m_fsname
, 0);
1131 xfs_mount_free(mp
, 1);
1136 xfs_unmountfs_close(xfs_mount_t
*mp
, struct cred
*cr
)
1138 if (mp
->m_logdev_targp
!= mp
->m_ddev_targp
)
1139 xfs_free_buftarg(mp
->m_logdev_targp
, 1);
1140 if (mp
->m_rtdev_targp
)
1141 xfs_free_buftarg(mp
->m_rtdev_targp
, 1);
1142 xfs_free_buftarg(mp
->m_ddev_targp
, 0);
1146 xfs_unmountfs_wait(xfs_mount_t
*mp
)
1148 if (mp
->m_logdev_targp
!= mp
->m_ddev_targp
)
1149 xfs_wait_buftarg(mp
->m_logdev_targp
);
1150 if (mp
->m_rtdev_targp
)
1151 xfs_wait_buftarg(mp
->m_rtdev_targp
);
1152 xfs_wait_buftarg(mp
->m_ddev_targp
);
1156 xfs_unmountfs_writesb(xfs_mount_t
*mp
)
1163 * skip superblock write if fs is read-only, or
1164 * if we are doing a forced umount.
1166 sbp
= xfs_getsb(mp
, 0);
1167 if (!(XFS_MTOVFS(mp
)->vfs_flag
& VFS_RDONLY
||
1168 XFS_FORCED_SHUTDOWN(mp
))) {
1170 * mark shared-readonly if desired
1172 sb
= XFS_BUF_TO_SBP(sbp
);
1173 if (mp
->m_mk_sharedro
) {
1174 if (!(sb
->sb_flags
& XFS_SBF_READONLY
))
1175 sb
->sb_flags
|= XFS_SBF_READONLY
;
1176 if (!XFS_SB_VERSION_HASSHARED(sb
))
1177 XFS_SB_VERSION_ADDSHARED(sb
);
1178 xfs_fs_cmn_err(CE_NOTE
, mp
,
1179 "Unmounting, marking shared read-only");
1181 XFS_BUF_UNDONE(sbp
);
1182 XFS_BUF_UNREAD(sbp
);
1183 XFS_BUF_UNDELAYWRITE(sbp
);
1185 XFS_BUF_UNASYNC(sbp
);
1186 ASSERT(XFS_BUF_TARGET(sbp
) == mp
->m_ddev_targp
);
1187 xfsbdstrat(mp
, sbp
);
1188 /* Nevermind errors we might get here. */
1189 error
= xfs_iowait(sbp
);
1191 xfs_ioerror_alert("xfs_unmountfs_writesb",
1192 mp
, sbp
, XFS_BUF_ADDR(sbp
));
1193 if (error
&& mp
->m_mk_sharedro
)
1194 xfs_fs_cmn_err(CE_ALERT
, mp
, "Superblock write error detected while unmounting. Filesystem may not be marked shared readonly");
1201 * xfs_mod_sb() can be used to copy arbitrary changes to the
1202 * in-core superblock into the superblock buffer to be logged.
1203 * It does not provide the higher level of locking that is
1204 * needed to protect the in-core superblock from concurrent
1208 xfs_mod_sb(xfs_trans_t
*tp
, __int64_t fields
)
1221 bp
= xfs_trans_getsb(tp
, mp
, 0);
1222 sbp
= XFS_BUF_TO_SBP(bp
);
1223 first
= sizeof(xfs_sb_t
);
1226 /* translate/copy */
1228 xfs_xlatesb(XFS_BUF_PTR(bp
), &(mp
->m_sb
), -1, fields
);
1230 /* find modified range */
1232 f
= (xfs_sb_field_t
)xfs_lowbit64((__uint64_t
)fields
);
1233 ASSERT((1LL << f
) & XFS_SB_MOD_BITS
);
1234 first
= xfs_sb_info
[f
].offset
;
1236 f
= (xfs_sb_field_t
)xfs_highbit64((__uint64_t
)fields
);
1237 ASSERT((1LL << f
) & XFS_SB_MOD_BITS
);
1238 last
= xfs_sb_info
[f
+ 1].offset
- 1;
1240 xfs_trans_log_buf(tp
, bp
, first
, last
);
1244 * xfs_mod_incore_sb_unlocked() is a utility routine common used to apply
1245 * a delta to a specified field in the in-core superblock. Simply
1246 * switch on the field indicated and apply the delta to that field.
1247 * Fields are not allowed to dip below zero, so if the delta would
1248 * do this do not apply it and return EINVAL.
1250 * The SB_LOCK must be held when this routine is called.
1253 xfs_mod_incore_sb_unlocked(xfs_mount_t
*mp
, xfs_sb_field_t field
,
1254 int delta
, int rsvd
)
1256 int scounter
; /* short counter for 32 bit fields */
1257 long long lcounter
; /* long counter for 64 bit fields */
1258 long long res_used
, rem
;
1261 * With the in-core superblock spin lock held, switch
1262 * on the indicated field. Apply the delta to the
1263 * proper field. If the fields value would dip below
1264 * 0, then do not apply the delta and return EINVAL.
1267 case XFS_SBS_ICOUNT
:
1268 lcounter
= (long long)mp
->m_sb
.sb_icount
;
1272 return (XFS_ERROR(EINVAL
));
1274 mp
->m_sb
.sb_icount
= lcounter
;
1277 lcounter
= (long long)mp
->m_sb
.sb_ifree
;
1281 return (XFS_ERROR(EINVAL
));
1283 mp
->m_sb
.sb_ifree
= lcounter
;
1285 case XFS_SBS_FDBLOCKS
:
1287 lcounter
= (long long)mp
->m_sb
.sb_fdblocks
;
1288 res_used
= (long long)(mp
->m_resblks
- mp
->m_resblks_avail
);
1290 if (delta
> 0) { /* Putting blocks back */
1291 if (res_used
> delta
) {
1292 mp
->m_resblks_avail
+= delta
;
1294 rem
= delta
- res_used
;
1295 mp
->m_resblks_avail
= mp
->m_resblks
;
1298 } else { /* Taking blocks away */
1303 * If were out of blocks, use any available reserved blocks if
1309 lcounter
= (long long)mp
->m_resblks_avail
+ delta
;
1311 return (XFS_ERROR(ENOSPC
));
1313 mp
->m_resblks_avail
= lcounter
;
1315 } else { /* not reserved */
1316 return (XFS_ERROR(ENOSPC
));
1321 mp
->m_sb
.sb_fdblocks
= lcounter
;
1323 case XFS_SBS_FREXTENTS
:
1324 lcounter
= (long long)mp
->m_sb
.sb_frextents
;
1327 return (XFS_ERROR(ENOSPC
));
1329 mp
->m_sb
.sb_frextents
= lcounter
;
1331 case XFS_SBS_DBLOCKS
:
1332 lcounter
= (long long)mp
->m_sb
.sb_dblocks
;
1336 return (XFS_ERROR(EINVAL
));
1338 mp
->m_sb
.sb_dblocks
= lcounter
;
1340 case XFS_SBS_AGCOUNT
:
1341 scounter
= mp
->m_sb
.sb_agcount
;
1345 return (XFS_ERROR(EINVAL
));
1347 mp
->m_sb
.sb_agcount
= scounter
;
1349 case XFS_SBS_IMAX_PCT
:
1350 scounter
= mp
->m_sb
.sb_imax_pct
;
1354 return (XFS_ERROR(EINVAL
));
1356 mp
->m_sb
.sb_imax_pct
= scounter
;
1358 case XFS_SBS_REXTSIZE
:
1359 scounter
= mp
->m_sb
.sb_rextsize
;
1363 return (XFS_ERROR(EINVAL
));
1365 mp
->m_sb
.sb_rextsize
= scounter
;
1367 case XFS_SBS_RBMBLOCKS
:
1368 scounter
= mp
->m_sb
.sb_rbmblocks
;
1372 return (XFS_ERROR(EINVAL
));
1374 mp
->m_sb
.sb_rbmblocks
= scounter
;
1376 case XFS_SBS_RBLOCKS
:
1377 lcounter
= (long long)mp
->m_sb
.sb_rblocks
;
1381 return (XFS_ERROR(EINVAL
));
1383 mp
->m_sb
.sb_rblocks
= lcounter
;
1385 case XFS_SBS_REXTENTS
:
1386 lcounter
= (long long)mp
->m_sb
.sb_rextents
;
1390 return (XFS_ERROR(EINVAL
));
1392 mp
->m_sb
.sb_rextents
= lcounter
;
1394 case XFS_SBS_REXTSLOG
:
1395 scounter
= mp
->m_sb
.sb_rextslog
;
1399 return (XFS_ERROR(EINVAL
));
1401 mp
->m_sb
.sb_rextslog
= scounter
;
1405 return (XFS_ERROR(EINVAL
));
1410 * xfs_mod_incore_sb() is used to change a field in the in-core
1411 * superblock structure by the specified delta. This modification
1412 * is protected by the SB_LOCK. Just use the xfs_mod_incore_sb_unlocked()
1413 * routine to do the work.
1416 xfs_mod_incore_sb(xfs_mount_t
*mp
, xfs_sb_field_t field
, int delta
, int rsvd
)
1421 s
= XFS_SB_LOCK(mp
);
1422 status
= xfs_mod_incore_sb_unlocked(mp
, field
, delta
, rsvd
);
1423 XFS_SB_UNLOCK(mp
, s
);
1428 * xfs_mod_incore_sb_batch() is used to change more than one field
1429 * in the in-core superblock structure at a time. This modification
1430 * is protected by a lock internal to this module. The fields and
1431 * changes to those fields are specified in the array of xfs_mod_sb
1432 * structures passed in.
1434 * Either all of the specified deltas will be applied or none of
1435 * them will. If any modified field dips below 0, then all modifications
1436 * will be backed out and EINVAL will be returned.
1439 xfs_mod_incore_sb_batch(xfs_mount_t
*mp
, xfs_mod_sb_t
*msb
, uint nmsb
, int rsvd
)
1446 * Loop through the array of mod structures and apply each
1447 * individually. If any fail, then back out all those
1448 * which have already been applied. Do all of this within
1449 * the scope of the SB_LOCK so that all of the changes will
1452 s
= XFS_SB_LOCK(mp
);
1454 for (msbp
= &msbp
[0]; msbp
< (msb
+ nmsb
); msbp
++) {
1456 * Apply the delta at index n. If it fails, break
1457 * from the loop so we'll fall into the undo loop
1460 status
= xfs_mod_incore_sb_unlocked(mp
, msbp
->msb_field
,
1461 msbp
->msb_delta
, rsvd
);
1468 * If we didn't complete the loop above, then back out
1469 * any changes made to the superblock. If you add code
1470 * between the loop above and here, make sure that you
1471 * preserve the value of status. Loop back until
1472 * we step below the beginning of the array. Make sure
1473 * we don't touch anything back there.
1477 while (msbp
>= msb
) {
1478 status
= xfs_mod_incore_sb_unlocked(mp
,
1479 msbp
->msb_field
, -(msbp
->msb_delta
), rsvd
);
1480 ASSERT(status
== 0);
1484 XFS_SB_UNLOCK(mp
, s
);
1489 * xfs_getsb() is called to obtain the buffer for the superblock.
1490 * The buffer is returned locked and read in from disk.
1491 * The buffer should be released with a call to xfs_brelse().
1493 * If the flags parameter is BUF_TRYLOCK, then we'll only return
1494 * the superblock buffer if it can be locked without sleeping.
1495 * If it can't then we'll return NULL.
1504 ASSERT(mp
->m_sb_bp
!= NULL
);
1506 if (flags
& XFS_BUF_TRYLOCK
) {
1507 if (!XFS_BUF_CPSEMA(bp
)) {
1511 XFS_BUF_PSEMA(bp
, PRIBIO
);
1514 ASSERT(XFS_BUF_ISDONE(bp
));
1519 * Used to free the superblock along various error paths.
1528 * Use xfs_getsb() so that the buffer will be locked
1529 * when we call xfs_buf_relse().
1531 bp
= xfs_getsb(mp
, 0);
1532 XFS_BUF_UNMANAGE(bp
);
1538 * See if the UUID is unique among mounted XFS filesystems.
1539 * Mount fails if UUID is nil or a FS with the same UUID is already mounted.
1545 if (uuid_is_nil(&mp
->m_sb
.sb_uuid
)) {
1547 "XFS: Filesystem %s has nil UUID - can't mount",
1551 if (!uuid_table_insert(&mp
->m_sb
.sb_uuid
)) {
1553 "XFS: Filesystem %s has duplicate UUID - can't mount",
1561 * Remove filesystem from the UUID table.
1567 uuid_table_remove(&mp
->m_sb
.sb_uuid
);
1571 * Used to log changes to the superblock unit and width fields which could
1572 * be altered by the mount options. Only the first superblock is updated.
1575 xfs_mount_log_sbunit(
1581 ASSERT(fields
& (XFS_SB_UNIT
|XFS_SB_WIDTH
|XFS_SB_UUID
));
1583 tp
= xfs_trans_alloc(mp
, XFS_TRANS_SB_UNIT
);
1584 if (xfs_trans_reserve(tp
, 0, mp
->m_sb
.sb_sectsize
+ 128, 0, 0,
1585 XFS_DEFAULT_LOG_COUNT
)) {
1586 xfs_trans_cancel(tp
, 0);
1589 xfs_mod_sb(tp
, fields
);
1590 xfs_trans_commit(tp
, 0, NULL
);