2 * Copyright (c) 2000-2005 Silicon Graphics, 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
22 #include "libxfs_priv.h"
24 #include "xfs_shared.h"
25 #include "xfs_format.h"
26 #include "xfs_log_format.h"
27 #include "xfs_trans_resv.h"
28 #include "xfs_mount.h"
29 #include "xfs_defer.h"
30 #include "xfs_inode_buf.h"
31 #include "xfs_inode_fork.h"
32 #include "xfs_inode.h"
33 #include "xfs_trans.h"
34 #include "xfs_rmap_btree.h"
35 #include "xfs_refcount_btree.h"
37 #include "libxfs.h" /* for now */
39 char *progname
= "libxfs"; /* default, changed by each tool */
41 struct cache
*libxfs_bcache
; /* global buffer cache */
42 int libxfs_bhash_size
; /* #buckets in bcache */
44 int use_xfs_buf_lock
; /* global flag: use xfs_buf_t locks for MT */
46 static int manage_zones(int); /* setup/teardown global zones */
49 * dev_map - map open devices to fd.
51 #define MAX_DEVS 10 /* arbitary maximum */
52 int nextfakedev
= -1; /* device number to give to next fake device */
53 static struct dev_to_fd
{
56 } dev_map
[MAX_DEVS
]={{0}};
59 * Checks whether a given device has a mounted, writable
60 * filesystem, returns 1 if it does & fatal (just warns
61 * if not fatal, but allows us to proceed).
63 * Useful to tools which will produce uncertain results
64 * if the filesystem is active - repair, check, logprint.
67 check_isactive(char *name
, char *block
, int fatal
)
71 if (stat(block
, &st
) < 0)
73 if ((st
.st_mode
& S_IFMT
) != S_IFBLK
)
75 if (platform_check_ismounted(name
, block
, &st
, 0) == 0)
77 if (platform_check_iswritable(name
, block
, &st
))
82 /* libxfs_device_to_fd:
83 * lookup a device number in the device map
84 * return the associated fd
87 libxfs_device_to_fd(dev_t device
)
91 for (d
= 0; d
< MAX_DEVS
; d
++)
92 if (dev_map
[d
].dev
== device
)
95 fprintf(stderr
, _("%s: %s: device %lld is not open\n"),
96 progname
, __FUNCTION__
, (long long)device
);
101 /* libxfs_device_open:
102 * open a device and return its device number
105 libxfs_device_open(char *path
, int creat
, int xflags
, int setblksize
)
109 int readonly
, dio
, excl
;
112 readonly
= (xflags
& LIBXFS_ISREADONLY
);
113 excl
= (xflags
& LIBXFS_EXCLUSIVELY
) && !creat
;
114 dio
= (xflags
& LIBXFS_DIRECT
) && !creat
&& platform_direct_blockdev();
117 flags
= (readonly
? O_RDONLY
: O_RDWR
) | \
118 (creat
? (O_CREAT
|O_TRUNC
) : 0) | \
119 (dio
? O_DIRECT
: 0) | \
122 if ((fd
= open(path
, flags
, 0666)) < 0) {
123 if (errno
== EINVAL
&& --dio
== 0)
125 fprintf(stderr
, _("%s: cannot open %s: %s\n"),
126 progname
, path
, strerror(errno
));
130 if (fstat(fd
, &statb
) < 0) {
131 fprintf(stderr
, _("%s: cannot stat %s: %s\n"),
132 progname
, path
, strerror(errno
));
136 if (!readonly
&& setblksize
&& (statb
.st_mode
& S_IFMT
) == S_IFBLK
) {
138 /* use the default blocksize */
139 (void)platform_set_blocksize(fd
, path
, statb
.st_rdev
, XFS_MIN_SECTORSIZE
, 0);
141 /* given an explicit blocksize to use */
142 if (platform_set_blocksize(fd
, path
, statb
.st_rdev
, setblksize
, 1))
148 * Get the device number from the stat buf - unless
149 * we're not opening a real device, in which case
150 * choose a new fake device number.
152 dev
= (statb
.st_rdev
) ? (statb
.st_rdev
) : (nextfakedev
--);
154 for (d
= 0; d
< MAX_DEVS
; d
++)
155 if (dev_map
[d
].dev
== dev
) {
156 fprintf(stderr
, _("%s: device %lld is already open\n"),
157 progname
, (long long)dev
);
161 for (d
= 0; d
< MAX_DEVS
; d
++)
162 if (!dev_map
[d
].dev
) {
163 dev_map
[d
].dev
= dev
;
169 fprintf(stderr
, _("%s: %s: too many open devices\n"),
170 progname
, __FUNCTION__
);
176 libxfs_device_close(dev_t dev
)
180 for (d
= 0; d
< MAX_DEVS
; d
++)
181 if (dev_map
[d
].dev
== dev
) {
185 dev_map
[d
].dev
= dev_map
[d
].fd
= 0;
188 platform_flush_device(fd
, dev
);
194 fprintf(stderr
, _("%s: %s: device %lld is not open\n"),
195 progname
, __FUNCTION__
, (long long)dev
);
200 check_open(char *path
, int flags
, char **rawfile
, char **blockfile
)
202 int readonly
= (flags
& LIBXFS_ISREADONLY
);
203 int inactive
= (flags
& LIBXFS_ISINACTIVE
);
204 int dangerously
= (flags
& LIBXFS_DANGEROUSLY
);
207 if (stat(path
, &stbuf
) < 0) {
211 if (!(*rawfile
= platform_findrawpath(path
))) {
212 fprintf(stderr
, _("%s: "
213 "can't find a character device matching %s\n"),
217 if (!(*blockfile
= platform_findblockpath(path
))) {
218 fprintf(stderr
, _("%s: "
219 "can't find a block device matching %s\n"),
223 if (!readonly
&& !inactive
&& platform_check_ismounted(path
, *blockfile
, NULL
, 1))
226 if (inactive
&& check_isactive(path
, *blockfile
, ((readonly
|dangerously
)?1:0)))
233 * libxfs initialization.
234 * Caller gets a 0 on failure (and we print a message), 1 on success.
237 libxfs_init(libxfs_init_t
*a
)
251 dpath
[0] = logpath
[0] = rtpath
[0] = '\0';
253 logname
= a
->logname
;
255 a
->dfd
= a
->logfd
= a
->rtfd
= -1;
256 a
->ddev
= a
->logdev
= a
->rtdev
= 0;
257 a
->dsize
= a
->lbsize
= a
->rtbsize
= 0;
258 a
->dbsize
= a
->logBBsize
= a
->logBBstart
= a
->rtsize
= 0;
261 flags
= (a
->isreadonly
| a
->isdirect
);
263 xfs_extent_free_init_defer_op();
264 xfs_rmap_update_init_defer_op();
265 xfs_refcount_update_init_defer_op();
266 xfs_bmap_update_init_defer_op();
271 if(!check_open(a
->volname
,flags
,&rawfile
,&blockfile
))
273 fd
= open(rawfile
, O_RDONLY
);
274 dname
= a
->dname
= a
->volname
;
279 a
->ddev
= libxfs_device_open(dname
, a
->dcreat
, flags
,
281 a
->dfd
= libxfs_device_to_fd(a
->ddev
);
282 platform_findsizes(dname
, a
->dfd
, &a
->dsize
,
285 if (!check_open(dname
, flags
, &rawfile
, &blockfile
))
287 a
->ddev
= libxfs_device_open(rawfile
,
288 a
->dcreat
, flags
, a
->setblksize
);
289 a
->dfd
= libxfs_device_to_fd(a
->ddev
);
290 platform_findsizes(rawfile
, a
->dfd
,
291 &a
->dsize
, &a
->dbsize
);
297 a
->logdev
= libxfs_device_open(logname
,
298 a
->lcreat
, flags
, a
->setblksize
);
299 a
->logfd
= libxfs_device_to_fd(a
->logdev
);
300 platform_findsizes(dname
, a
->logfd
, &a
->logBBsize
,
303 if (!check_open(logname
, flags
, &rawfile
, &blockfile
))
305 a
->logdev
= libxfs_device_open(rawfile
,
306 a
->lcreat
, flags
, a
->setblksize
);
307 a
->logfd
= libxfs_device_to_fd(a
->logdev
);
308 platform_findsizes(rawfile
, a
->logfd
,
309 &a
->logBBsize
, &a
->lbsize
);
315 a
->rtdev
= libxfs_device_open(rtname
,
316 a
->rcreat
, flags
, a
->setblksize
);
317 a
->rtfd
= libxfs_device_to_fd(a
->rtdev
);
318 platform_findsizes(dname
, a
->rtfd
, &a
->rtsize
,
321 if (!check_open(rtname
, flags
, &rawfile
, &blockfile
))
323 a
->rtdev
= libxfs_device_open(rawfile
,
324 a
->rcreat
, flags
, a
->setblksize
);
325 a
->rtfd
= libxfs_device_to_fd(a
->rtdev
);
326 platform_findsizes(rawfile
, a
->rtfd
,
327 &a
->rtsize
, &a
->rtbsize
);
332 fprintf(stderr
, _("%s: can't get size for data subvolume\n"),
336 if (a
->logBBsize
< 0) {
337 fprintf(stderr
, _("%s: can't get size for log subvolume\n"),
342 fprintf(stderr
, _("%s: can't get size for realtime subvolume\n"),
346 if (!libxfs_bhash_size
)
347 libxfs_bhash_size
= LIBXFS_BHASHSIZE(sbp
);
348 libxfs_bcache
= cache_init(a
->bcache_flags
, libxfs_bhash_size
,
349 &libxfs_bcache_operations
);
350 use_xfs_buf_lock
= a
->usebuflock
;
362 if (!rval
&& a
->ddev
)
363 libxfs_device_close(a
->ddev
);
364 if (!rval
&& a
->logdev
)
365 libxfs_device_close(a
->logdev
);
366 if (!rval
&& a
->rtdev
)
367 libxfs_device_close(a
->rtdev
);
373 * Initialize/destroy all of the zone allocators we use.
376 manage_zones(int release
)
378 extern kmem_zone_t
*xfs_buf_zone
;
379 extern kmem_zone_t
*xfs_ili_zone
;
380 extern kmem_zone_t
*xfs_inode_zone
;
381 extern kmem_zone_t
*xfs_ifork_zone
;
382 extern kmem_zone_t
*xfs_buf_item_zone
;
383 extern kmem_zone_t
*xfs_da_state_zone
;
384 extern kmem_zone_t
*xfs_btree_cur_zone
;
385 extern kmem_zone_t
*xfs_bmap_free_item_zone
;
386 extern kmem_zone_t
*xfs_trans_zone
;
387 extern kmem_zone_t
*xfs_log_item_desc_zone
;
388 extern void xfs_dir_startup();
390 if (release
) { /* free zone allocation */
393 leaked
+= kmem_zone_destroy(xfs_buf_zone
);
394 leaked
+= kmem_zone_destroy(xfs_ili_zone
);
395 leaked
+= kmem_zone_destroy(xfs_inode_zone
);
396 leaked
+= kmem_zone_destroy(xfs_ifork_zone
);
397 leaked
+= kmem_zone_destroy(xfs_buf_item_zone
);
398 leaked
+= kmem_zone_destroy(xfs_da_state_zone
);
399 leaked
+= kmem_zone_destroy(xfs_btree_cur_zone
);
400 leaked
+= kmem_zone_destroy(xfs_bmap_free_item_zone
);
401 leaked
+= kmem_zone_destroy(xfs_trans_zone
);
402 leaked
+= kmem_zone_destroy(xfs_log_item_desc_zone
);
406 /* otherwise initialise zone allocation */
407 xfs_buf_zone
= kmem_zone_init(sizeof(xfs_buf_t
), "xfs_buffer");
408 xfs_inode_zone
= kmem_zone_init(sizeof(struct xfs_inode
), "xfs_inode");
409 xfs_ifork_zone
= kmem_zone_init(sizeof(xfs_ifork_t
), "xfs_ifork");
410 xfs_ili_zone
= kmem_zone_init(
411 sizeof(xfs_inode_log_item_t
), "xfs_inode_log_item");
412 xfs_buf_item_zone
= kmem_zone_init(
413 sizeof(xfs_buf_log_item_t
), "xfs_buf_log_item");
414 xfs_da_state_zone
= kmem_zone_init(
415 sizeof(xfs_da_state_t
), "xfs_da_state");
416 xfs_btree_cur_zone
= kmem_zone_init(
417 sizeof(xfs_btree_cur_t
), "xfs_btree_cur");
418 xfs_bmap_free_item_zone
= kmem_zone_init(
419 sizeof(struct xfs_extent_free_item
),
420 "xfs_bmap_free_item");
421 xfs_trans_zone
= kmem_zone_init(
422 sizeof(struct xfs_trans
), "xfs_trans");
423 xfs_log_item_desc_zone
= kmem_zone_init(
424 sizeof(struct xfs_log_item_desc
), "xfs_log_item_desc");
431 * Initialize realtime fields in the mount structure.
435 xfs_mount_t
*mp
, /* file system mount structure */
438 xfs_buf_t
*bp
; /* buffer for last block of subvolume */
439 xfs_daddr_t d
; /* address of last block of subvolume */
440 xfs_sb_t
*sbp
; /* filesystem superblock copy in mount */
443 if (sbp
->sb_rblocks
== 0)
445 if (mp
->m_rtdev_targp
->dev
== 0 && !(flags
& LIBXFS_MOUNT_DEBUGGER
)) {
446 fprintf(stderr
, _("%s: filesystem has a realtime subvolume\n"),
450 mp
->m_rsumlevels
= sbp
->sb_rextslog
+ 1;
452 (uint
)sizeof(xfs_suminfo_t
) * mp
->m_rsumlevels
*
454 mp
->m_rsumsize
= roundup(mp
->m_rsumsize
, sbp
->sb_blocksize
);
455 mp
->m_rbmip
= mp
->m_rsumip
= NULL
;
458 * Allow debugger to be run without the realtime device present.
460 if (flags
& LIBXFS_MOUNT_DEBUGGER
)
464 * Check that the realtime section is an ok size.
466 d
= (xfs_daddr_t
)XFS_FSB_TO_BB(mp
, mp
->m_sb
.sb_rblocks
);
467 if (XFS_BB_TO_FSB(mp
, d
) != mp
->m_sb
.sb_rblocks
) {
468 fprintf(stderr
, _("%s: realtime init - %llu != %llu\n"),
469 progname
, (unsigned long long) XFS_BB_TO_FSB(mp
, d
),
470 (unsigned long long) mp
->m_sb
.sb_rblocks
);
473 bp
= libxfs_readbuf(mp
->m_rtdev
,
474 d
- XFS_FSB_TO_BB(mp
, 1), XFS_FSB_TO_BB(mp
, 1), 0, NULL
);
476 fprintf(stderr
, _("%s: realtime size check failed\n"),
485 libxfs_initialize_perag(
487 xfs_agnumber_t agcount
,
488 xfs_agnumber_t
*maxagi
)
490 xfs_agnumber_t index
, max_metadata
;
491 xfs_agnumber_t first_initialised
= 0;
495 xfs_sb_t
*sbp
= &mp
->m_sb
;
499 * Walk the current per-ag tree so we don't try to initialise AGs
500 * that already exist (growfs case). Allocate and insert all the
501 * AGs we don't find ready for initialisation.
503 for (index
= 0; index
< agcount
; index
++) {
504 pag
= xfs_perag_get(mp
, index
);
509 if (!first_initialised
)
510 first_initialised
= index
;
512 pag
= kmem_zalloc(sizeof(*pag
), KM_MAYFAIL
);
515 pag
->pag_agno
= index
;
518 if (radix_tree_insert(&mp
->m_perag_tree
, index
, pag
)) {
525 * If we mount with the inode64 option, or no inode overflows
526 * the legacy 32-bit address space clear the inode32 option.
528 agino
= XFS_OFFBNO_TO_AGINO(mp
, sbp
->sb_agblocks
- 1, 0);
529 ino
= XFS_AGINO_TO_INO(mp
, agcount
- 1, agino
);
531 if ((mp
->m_flags
& XFS_MOUNT_SMALL_INUMS
) && ino
> XFS_MAXINUMBER_32
)
532 mp
->m_flags
|= XFS_MOUNT_32BITINODES
;
534 mp
->m_flags
&= ~XFS_MOUNT_32BITINODES
;
536 if (mp
->m_flags
& XFS_MOUNT_32BITINODES
) {
538 * Calculate how much should be reserved for inodes to meet
539 * the max inode percentage.
541 if (mp
->m_maxicount
) {
544 icount
= sbp
->sb_dblocks
* sbp
->sb_imax_pct
;
546 icount
+= sbp
->sb_agblocks
- 1;
547 do_div(icount
, sbp
->sb_agblocks
);
548 max_metadata
= icount
;
550 max_metadata
= agcount
;
553 for (index
= 0; index
< agcount
; index
++) {
554 ino
= XFS_AGINO_TO_INO(mp
, index
, agino
);
555 if (ino
> XFS_MAXINUMBER_32
) {
560 pag
= xfs_perag_get(mp
, index
);
561 pag
->pagi_inodeok
= 1;
562 if (index
< max_metadata
)
563 pag
->pagf_metadata
= 1;
567 for (index
= 0; index
< agcount
; index
++) {
568 pag
= xfs_perag_get(mp
, index
);
569 pag
->pagi_inodeok
= 1;
577 mp
->m_ag_prealloc_blocks
= xfs_prealloc_blocks(mp
);
582 for (; index
> first_initialised
; index
--) {
583 pag
= radix_tree_delete(&mp
->m_perag_tree
, index
);
589 static struct xfs_buftarg
*
590 libxfs_buftarg_alloc(
591 struct xfs_mount
*mp
,
594 struct xfs_buftarg
*btp
;
596 btp
= malloc(sizeof(*btp
));
598 fprintf(stderr
, _("%s: buftarg init failed\n"),
609 struct xfs_mount
*mp
,
614 if (mp
->m_ddev_targp
) {
615 /* should already have all buftargs initialised */
616 if (mp
->m_ddev_targp
->dev
!= dev
||
617 mp
->m_ddev_targp
->bt_mount
!= mp
) {
619 _("%s: bad buftarg reinit, ddev\n"),
623 if (!logdev
|| logdev
== dev
) {
624 if (mp
->m_logdev_targp
!= mp
->m_ddev_targp
) {
626 _("%s: bad buftarg reinit, ldev mismatch\n"),
630 } else if (mp
->m_logdev_targp
->dev
!= logdev
||
631 mp
->m_logdev_targp
->bt_mount
!= mp
) {
633 _("%s: bad buftarg reinit, logdev\n"),
637 if (rtdev
&& (mp
->m_rtdev_targp
->dev
!= rtdev
||
638 mp
->m_rtdev_targp
->bt_mount
!= mp
)) {
640 _("%s: bad buftarg reinit, rtdev\n"),
647 mp
->m_ddev_targp
= libxfs_buftarg_alloc(mp
, dev
);
648 if (!logdev
|| logdev
== dev
)
649 mp
->m_logdev_targp
= mp
->m_ddev_targp
;
651 mp
->m_logdev_targp
= libxfs_buftarg_alloc(mp
, logdev
);
652 mp
->m_rtdev_targp
= libxfs_buftarg_alloc(mp
, rtdev
);
656 * Mount structure initialization, provides a filled-in xfs_mount_t
657 * such that the numerous XFS_* macros can be used. If dev is zero,
658 * no IO will be performed (no size checks, read root inodes).
674 libxfs_buftarg_init(mp
, dev
, logdev
, rtdev
);
676 mp
->m_flags
= (LIBXFS_MOUNT_32BITINODES
|LIBXFS_MOUNT_32BITINOOPT
);
678 INIT_RADIX_TREE(&mp
->m_perag_tree
, GFP_KERNEL
);
681 xfs_sb_mount_common(mp
, sb
);
683 xfs_alloc_compute_maxlevels(mp
);
684 xfs_bmap_compute_maxlevels(mp
, XFS_DATA_FORK
);
685 xfs_bmap_compute_maxlevels(mp
, XFS_ATTR_FORK
);
686 xfs_ialloc_compute_maxlevels(mp
);
687 xfs_rmapbt_compute_maxlevels(mp
);
688 xfs_refcountbt_compute_maxlevels(mp
);
690 if (sbp
->sb_imax_pct
) {
691 /* Make sure the maximum inode count is a multiple of the
692 * units we allocate inodes in.
694 mp
->m_maxicount
= (sbp
->sb_dblocks
* sbp
->sb_imax_pct
) / 100;
695 mp
->m_maxicount
= ((mp
->m_maxicount
/ mp
->m_ialloc_blks
) *
696 mp
->m_ialloc_blks
) << sbp
->sb_inopblog
;
700 mp
->m_inode_cluster_size
= XFS_INODE_BIG_CLUSTER_SIZE
;
701 if (xfs_sb_version_hascrc(&mp
->m_sb
)) {
702 int new_size
= mp
->m_inode_cluster_size
;
704 new_size
*= mp
->m_sb
.sb_inodesize
/ XFS_DINODE_MIN_SIZE
;
705 if (mp
->m_sb
.sb_inoalignmt
>= XFS_B_TO_FSBT(mp
, new_size
))
706 mp
->m_inode_cluster_size
= new_size
;
710 * Set whether we're using stripe alignment.
712 if (xfs_sb_version_hasdalign(&mp
->m_sb
)) {
713 mp
->m_dalign
= sbp
->sb_unit
;
714 mp
->m_swidth
= sbp
->sb_width
;
718 * Set whether we're using inode alignment.
720 if (xfs_sb_version_hasalign(&mp
->m_sb
) &&
721 mp
->m_sb
.sb_inoalignmt
>=
722 XFS_B_TO_FSBT(mp
, mp
->m_inode_cluster_size
))
723 mp
->m_inoalign_mask
= mp
->m_sb
.sb_inoalignmt
- 1;
725 mp
->m_inoalign_mask
= 0;
727 * If we are using stripe alignment, check whether
728 * the stripe unit is a multiple of the inode alignment
730 if (mp
->m_dalign
&& mp
->m_inoalign_mask
&&
731 !(mp
->m_dalign
& mp
->m_inoalign_mask
))
732 mp
->m_sinoalign
= mp
->m_dalign
;
737 * Check that the data (and log if separate) are an ok size.
739 d
= (xfs_daddr_t
) XFS_FSB_TO_BB(mp
, mp
->m_sb
.sb_dblocks
);
740 if (XFS_BB_TO_FSB(mp
, d
) != mp
->m_sb
.sb_dblocks
) {
741 fprintf(stderr
, _("%s: size check failed\n"), progname
);
742 if (!(flags
& LIBXFS_MOUNT_DEBUGGER
))
747 * We automatically convert v1 inodes to v2 inodes now, so if
748 * the NLINK bit is not set we can't operate on the filesystem.
750 if (!(sbp
->sb_versionnum
& XFS_SB_VERSION_NLINKBIT
)) {
753 "%s: V1 inodes unsupported. Please try an older xfsprogs.\n"),
758 /* Check for supported directory formats */
759 if (!(sbp
->sb_versionnum
& XFS_SB_VERSION_DIRV2BIT
)) {
762 "%s: V1 directories unsupported. Please try an older xfsprogs.\n"),
767 /* check for unsupported other features */
768 if (!xfs_sb_good_version(sbp
)) {
770 "%s: Unsupported features detected. Please try a newer xfsprogs.\n"),
777 if (xfs_sb_version_hasattr2(&mp
->m_sb
))
778 mp
->m_flags
|= LIBXFS_MOUNT_ATTR2
;
780 /* Initialize the precomputed transaction reservations values */
783 if (dev
== 0) /* maxtrres, we have no device so leave now */
786 bp
= libxfs_readbuf(mp
->m_dev
,
787 d
- XFS_FSS_TO_BB(mp
, 1), XFS_FSS_TO_BB(mp
, 1),
788 !(flags
& LIBXFS_MOUNT_DEBUGGER
), NULL
);
790 fprintf(stderr
, _("%s: data size check failed\n"), progname
);
791 if (!(flags
& LIBXFS_MOUNT_DEBUGGER
))
796 if (mp
->m_logdev_targp
->dev
&&
797 mp
->m_logdev_targp
->dev
!= mp
->m_ddev_targp
->dev
) {
798 d
= (xfs_daddr_t
) XFS_FSB_TO_BB(mp
, mp
->m_sb
.sb_logblocks
);
799 if ( (XFS_BB_TO_FSB(mp
, d
) != mp
->m_sb
.sb_logblocks
) ||
800 (!(bp
= libxfs_readbuf(mp
->m_logdev_targp
,
801 d
- XFS_FSB_TO_BB(mp
, 1),
802 XFS_FSB_TO_BB(mp
, 1),
803 !(flags
& LIBXFS_MOUNT_DEBUGGER
), NULL
))) ) {
804 fprintf(stderr
, _("%s: log size checks failed\n"),
806 if (!(flags
& LIBXFS_MOUNT_DEBUGGER
))
813 /* Initialize realtime fields in the mount structure */
814 if (rtmount_init(mp
, flags
)) {
815 fprintf(stderr
, _("%s: realtime device init failed\n"),
821 * libxfs_initialize_perag will allocate a perag structure for each ag.
822 * If agcount is corrupted and insanely high, this will OOM the box.
823 * If the agount seems (arbitrarily) high, try to read what would be
824 * the last AG, and if that fails for a relatively high agcount, just
825 * read the first one and let the user know to check the geometry.
827 if (sbp
->sb_agcount
> 1000000) {
828 bp
= libxfs_readbuf(mp
->m_dev
,
829 XFS_AG_DADDR(mp
, sbp
->sb_agcount
- 1, 0), 1,
830 !(flags
& LIBXFS_MOUNT_DEBUGGER
), NULL
);
832 fprintf(stderr
, _("%s: read of AG %u failed\n"),
833 progname
, sbp
->sb_agcount
);
834 if (!(flags
& LIBXFS_MOUNT_DEBUGGER
))
836 fprintf(stderr
, _("%s: limiting reads to AG 0\n"),
843 error
= libxfs_initialize_perag(mp
, sbp
->sb_agcount
, &mp
->m_maxagi
);
845 fprintf(stderr
, _("%s: perag init failed\n"),
854 libxfs_rtmount_destroy(xfs_mount_t
*mp
)
860 mp
->m_rsumip
= mp
->m_rbmip
= NULL
;
864 * Release any resource obtained during a mount.
867 libxfs_umount(xfs_mount_t
*mp
)
869 struct xfs_perag
*pag
;
872 libxfs_rtmount_destroy(mp
);
873 libxfs_bcache_purge();
875 for (agno
= 0; agno
< mp
->m_maxagi
; agno
++) {
876 pag
= radix_tree_delete(&mp
->m_perag_tree
, agno
);
880 kmem_free(mp
->m_attr_geo
);
881 kmem_free(mp
->m_dir_geo
);
883 kmem_free(mp
->m_rtdev_targp
);
884 if (mp
->m_logdev_targp
!= mp
->m_ddev_targp
)
885 kmem_free(mp
->m_logdev_targp
);
886 kmem_free(mp
->m_ddev_targp
);
891 * Release any global resources used by libxfs.
898 /* Free everything from the buffer cache before freeing buffer zone */
899 libxfs_bcache_purge();
900 libxfs_bcache_free();
901 cache_destroy(libxfs_bcache
);
902 leaked
= manage_zones(1);
903 if (getenv("LIBXFS_LEAK_CHECK") && leaked
)
908 libxfs_device_alignment(void)
910 return platform_align_blockdev();
914 libxfs_report(FILE *fp
)
919 cache_report(fp
, "libxfs_bcache", libxfs_bcache
);
922 c
= asctime(localtime(&t
));
923 fprintf(fp
, "%s", c
);
931 nr
= platform_nproc();
940 return platform_physmem();