1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
10 #include "libxfs_priv.h"
12 #include "xfs_shared.h"
13 #include "xfs_format.h"
14 #include "xfs_log_format.h"
15 #include "xfs_trans_resv.h"
16 #include "xfs_mount.h"
17 #include "xfs_defer.h"
18 #include "xfs_inode_buf.h"
19 #include "xfs_inode_fork.h"
20 #include "xfs_inode.h"
21 #include "xfs_trans.h"
22 #include "xfs_rmap_btree.h"
23 #include "xfs_refcount_btree.h"
25 #include "libxfs.h" /* for now */
27 char *progname
= "libxfs"; /* default, changed by each tool */
29 struct cache
*libxfs_bcache
; /* global buffer cache */
30 int libxfs_bhash_size
; /* #buckets in bcache */
32 int use_xfs_buf_lock
; /* global flag: use xfs_buf_t locks for MT */
34 static int manage_zones(int); /* setup/teardown global zones */
37 * dev_map - map open devices to fd.
39 #define MAX_DEVS 10 /* arbitary maximum */
40 static int nextfakedev
= -1; /* device number to give to next fake device */
41 static struct dev_to_fd
{
44 } dev_map
[MAX_DEVS
]={{0}};
47 * Checks whether a given device has a mounted, writable
48 * filesystem, returns 1 if it does & fatal (just warns
49 * if not fatal, but allows us to proceed).
51 * Useful to tools which will produce uncertain results
52 * if the filesystem is active - repair, check, logprint.
55 check_isactive(char *name
, char *block
, int fatal
)
59 if (stat(block
, &st
) < 0)
61 if ((st
.st_mode
& S_IFMT
) != S_IFBLK
)
63 if (platform_check_ismounted(name
, block
, &st
, 0) == 0)
65 if (platform_check_iswritable(name
, block
, &st
))
70 /* libxfs_device_to_fd:
71 * lookup a device number in the device map
72 * return the associated fd
75 libxfs_device_to_fd(dev_t device
)
79 for (d
= 0; d
< MAX_DEVS
; d
++)
80 if (dev_map
[d
].dev
== device
)
83 fprintf(stderr
, _("%s: %s: device %lld is not open\n"),
84 progname
, __FUNCTION__
, (long long)device
);
89 /* libxfs_device_open:
90 * open a device and return its device number
93 libxfs_device_open(char *path
, int creat
, int xflags
, int setblksize
)
97 int readonly
, dio
, excl
;
100 readonly
= (xflags
& LIBXFS_ISREADONLY
);
101 excl
= (xflags
& LIBXFS_EXCLUSIVELY
) && !creat
;
102 dio
= (xflags
& LIBXFS_DIRECT
) && !creat
&& platform_direct_blockdev();
105 flags
= (readonly
? O_RDONLY
: O_RDWR
) | \
106 (creat
? (O_CREAT
|O_TRUNC
) : 0) | \
107 (dio
? O_DIRECT
: 0) | \
110 if ((fd
= open(path
, flags
, 0666)) < 0) {
111 if (errno
== EINVAL
&& --dio
== 0)
113 fprintf(stderr
, _("%s: cannot open %s: %s\n"),
114 progname
, path
, strerror(errno
));
118 if (fstat(fd
, &statb
) < 0) {
119 fprintf(stderr
, _("%s: cannot stat %s: %s\n"),
120 progname
, path
, strerror(errno
));
124 if (!readonly
&& setblksize
&& (statb
.st_mode
& S_IFMT
) == S_IFBLK
) {
126 /* use the default blocksize */
127 (void)platform_set_blocksize(fd
, path
, statb
.st_rdev
, XFS_MIN_SECTORSIZE
, 0);
129 /* given an explicit blocksize to use */
130 if (platform_set_blocksize(fd
, path
, statb
.st_rdev
, setblksize
, 1))
136 * Get the device number from the stat buf - unless
137 * we're not opening a real device, in which case
138 * choose a new fake device number.
140 dev
= (statb
.st_rdev
) ? (statb
.st_rdev
) : (nextfakedev
--);
142 for (d
= 0; d
< MAX_DEVS
; d
++)
143 if (dev_map
[d
].dev
== dev
) {
144 fprintf(stderr
, _("%s: device %lld is already open\n"),
145 progname
, (long long)dev
);
149 for (d
= 0; d
< MAX_DEVS
; d
++)
150 if (!dev_map
[d
].dev
) {
151 dev_map
[d
].dev
= dev
;
157 fprintf(stderr
, _("%s: %s: too many open devices\n"),
158 progname
, __FUNCTION__
);
164 libxfs_device_close(dev_t dev
)
168 for (d
= 0; d
< MAX_DEVS
; d
++)
169 if (dev_map
[d
].dev
== dev
) {
173 dev_map
[d
].dev
= dev_map
[d
].fd
= 0;
176 platform_flush_device(fd
, dev
);
182 fprintf(stderr
, _("%s: %s: device %lld is not open\n"),
183 progname
, __FUNCTION__
, (long long)dev
);
188 check_open(char *path
, int flags
, char **rawfile
, char **blockfile
)
190 int readonly
= (flags
& LIBXFS_ISREADONLY
);
191 int inactive
= (flags
& LIBXFS_ISINACTIVE
);
192 int dangerously
= (flags
& LIBXFS_DANGEROUSLY
);
195 if (stat(path
, &stbuf
) < 0) {
199 if (!(*rawfile
= platform_findrawpath(path
))) {
200 fprintf(stderr
, _("%s: "
201 "can't find a character device matching %s\n"),
205 if (!(*blockfile
= platform_findblockpath(path
))) {
206 fprintf(stderr
, _("%s: "
207 "can't find a block device matching %s\n"),
211 if (!readonly
&& !inactive
&& platform_check_ismounted(path
, *blockfile
, NULL
, 1))
214 if (inactive
&& check_isactive(path
, *blockfile
, ((readonly
|dangerously
)?1:0)))
221 * libxfs initialization.
222 * Caller gets a 0 on failure (and we print a message), 1 on success.
225 libxfs_init(libxfs_init_t
*a
)
239 dpath
[0] = logpath
[0] = rtpath
[0] = '\0';
241 logname
= a
->logname
;
243 a
->dfd
= a
->logfd
= a
->rtfd
= -1;
244 a
->ddev
= a
->logdev
= a
->rtdev
= 0;
245 a
->dsize
= a
->lbsize
= a
->rtbsize
= 0;
246 a
->dbsize
= a
->logBBsize
= a
->logBBstart
= a
->rtsize
= 0;
249 flags
= (a
->isreadonly
| a
->isdirect
);
254 if(!check_open(a
->volname
,flags
,&rawfile
,&blockfile
))
256 fd
= open(rawfile
, O_RDONLY
);
257 dname
= a
->dname
= a
->volname
;
262 a
->ddev
= libxfs_device_open(dname
, a
->dcreat
, flags
,
264 a
->dfd
= libxfs_device_to_fd(a
->ddev
);
265 platform_findsizes(dname
, a
->dfd
, &a
->dsize
,
268 if (!check_open(dname
, flags
, &rawfile
, &blockfile
))
270 a
->ddev
= libxfs_device_open(rawfile
,
271 a
->dcreat
, flags
, a
->setblksize
);
272 a
->dfd
= libxfs_device_to_fd(a
->ddev
);
273 platform_findsizes(rawfile
, a
->dfd
,
274 &a
->dsize
, &a
->dbsize
);
280 a
->logdev
= libxfs_device_open(logname
,
281 a
->lcreat
, flags
, a
->setblksize
);
282 a
->logfd
= libxfs_device_to_fd(a
->logdev
);
283 platform_findsizes(dname
, a
->logfd
, &a
->logBBsize
,
286 if (!check_open(logname
, flags
, &rawfile
, &blockfile
))
288 a
->logdev
= libxfs_device_open(rawfile
,
289 a
->lcreat
, flags
, a
->setblksize
);
290 a
->logfd
= libxfs_device_to_fd(a
->logdev
);
291 platform_findsizes(rawfile
, a
->logfd
,
292 &a
->logBBsize
, &a
->lbsize
);
298 a
->rtdev
= libxfs_device_open(rtname
,
299 a
->rcreat
, flags
, a
->setblksize
);
300 a
->rtfd
= libxfs_device_to_fd(a
->rtdev
);
301 platform_findsizes(dname
, a
->rtfd
, &a
->rtsize
,
304 if (!check_open(rtname
, flags
, &rawfile
, &blockfile
))
306 a
->rtdev
= libxfs_device_open(rawfile
,
307 a
->rcreat
, flags
, a
->setblksize
);
308 a
->rtfd
= libxfs_device_to_fd(a
->rtdev
);
309 platform_findsizes(rawfile
, a
->rtfd
,
310 &a
->rtsize
, &a
->rtbsize
);
315 fprintf(stderr
, _("%s: can't get size for data subvolume\n"),
319 if (a
->logBBsize
< 0) {
320 fprintf(stderr
, _("%s: can't get size for log subvolume\n"),
325 fprintf(stderr
, _("%s: can't get size for realtime subvolume\n"),
329 if (!libxfs_bhash_size
)
330 libxfs_bhash_size
= LIBXFS_BHASHSIZE(sbp
);
331 libxfs_bcache
= cache_init(a
->bcache_flags
, libxfs_bhash_size
,
332 &libxfs_bcache_operations
);
333 use_xfs_buf_lock
= a
->usebuflock
;
345 if (!rval
&& a
->ddev
)
346 libxfs_device_close(a
->ddev
);
347 if (!rval
&& a
->logdev
)
348 libxfs_device_close(a
->logdev
);
349 if (!rval
&& a
->rtdev
)
350 libxfs_device_close(a
->rtdev
);
356 * Initialize/destroy all of the zone allocators we use.
359 manage_zones(int release
)
361 extern void xfs_dir_startup();
363 if (release
) { /* free zone allocation */
366 leaked
+= kmem_zone_destroy(xfs_buf_zone
);
367 leaked
+= kmem_zone_destroy(xfs_ili_zone
);
368 leaked
+= kmem_zone_destroy(xfs_inode_zone
);
369 leaked
+= kmem_zone_destroy(xfs_ifork_zone
);
370 leaked
+= kmem_zone_destroy(xfs_buf_item_zone
);
371 leaked
+= kmem_zone_destroy(xfs_da_state_zone
);
372 leaked
+= kmem_zone_destroy(xfs_btree_cur_zone
);
373 leaked
+= kmem_zone_destroy(xfs_bmap_free_item_zone
);
374 leaked
+= kmem_zone_destroy(xfs_trans_zone
);
378 /* otherwise initialise zone allocation */
379 xfs_buf_zone
= kmem_zone_init(sizeof(xfs_buf_t
), "xfs_buffer");
380 xfs_inode_zone
= kmem_zone_init(sizeof(struct xfs_inode
), "xfs_inode");
381 xfs_ifork_zone
= kmem_zone_init(sizeof(struct xfs_ifork
), "xfs_ifork");
382 xfs_ili_zone
= kmem_zone_init(
383 sizeof(xfs_inode_log_item_t
), "xfs_inode_log_item");
384 xfs_buf_item_zone
= kmem_zone_init(
385 sizeof(xfs_buf_log_item_t
), "xfs_buf_log_item");
386 xfs_da_state_zone
= kmem_zone_init(
387 sizeof(xfs_da_state_t
), "xfs_da_state");
388 xfs_btree_cur_zone
= kmem_zone_init(
389 sizeof(xfs_btree_cur_t
), "xfs_btree_cur");
390 xfs_bmap_free_item_zone
= kmem_zone_init(
391 sizeof(struct xfs_extent_free_item
),
392 "xfs_bmap_free_item");
393 xfs_trans_zone
= kmem_zone_init(
394 sizeof(struct xfs_trans
), "xfs_trans");
401 * Initialize realtime fields in the mount structure.
405 xfs_mount_t
*mp
, /* file system mount structure */
408 xfs_buf_t
*bp
; /* buffer for last block of subvolume */
409 xfs_daddr_t d
; /* address of last block of subvolume */
410 xfs_sb_t
*sbp
; /* filesystem superblock copy in mount */
413 if (sbp
->sb_rblocks
== 0)
415 if (mp
->m_rtdev_targp
->dev
== 0 && !(flags
& LIBXFS_MOUNT_DEBUGGER
)) {
416 fprintf(stderr
, _("%s: filesystem has a realtime subvolume\n"),
420 mp
->m_rsumlevels
= sbp
->sb_rextslog
+ 1;
422 (uint
)sizeof(xfs_suminfo_t
) * mp
->m_rsumlevels
*
424 mp
->m_rsumsize
= roundup(mp
->m_rsumsize
, sbp
->sb_blocksize
);
425 mp
->m_rbmip
= mp
->m_rsumip
= NULL
;
428 * Allow debugger to be run without the realtime device present.
430 if (flags
& LIBXFS_MOUNT_DEBUGGER
)
434 * Check that the realtime section is an ok size.
436 d
= (xfs_daddr_t
)XFS_FSB_TO_BB(mp
, mp
->m_sb
.sb_rblocks
);
437 if (XFS_BB_TO_FSB(mp
, d
) != mp
->m_sb
.sb_rblocks
) {
438 fprintf(stderr
, _("%s: realtime init - %llu != %llu\n"),
439 progname
, (unsigned long long) XFS_BB_TO_FSB(mp
, d
),
440 (unsigned long long) mp
->m_sb
.sb_rblocks
);
443 bp
= libxfs_readbuf(mp
->m_rtdev
,
444 d
- XFS_FSB_TO_BB(mp
, 1), XFS_FSB_TO_BB(mp
, 1), 0, NULL
);
446 fprintf(stderr
, _("%s: realtime size check failed\n"),
455 libxfs_initialize_perag(
457 xfs_agnumber_t agcount
,
458 xfs_agnumber_t
*maxagi
)
460 xfs_agnumber_t index
, max_metadata
;
461 xfs_agnumber_t first_initialised
= 0;
465 xfs_sb_t
*sbp
= &mp
->m_sb
;
469 * Walk the current per-ag tree so we don't try to initialise AGs
470 * that already exist (growfs case). Allocate and insert all the
471 * AGs we don't find ready for initialisation.
473 for (index
= 0; index
< agcount
; index
++) {
474 pag
= xfs_perag_get(mp
, index
);
479 if (!first_initialised
)
480 first_initialised
= index
;
482 pag
= kmem_zalloc(sizeof(*pag
), KM_MAYFAIL
);
485 pag
->pag_agno
= index
;
488 if (radix_tree_insert(&mp
->m_perag_tree
, index
, pag
)) {
495 * If we mount with the inode64 option, or no inode overflows
496 * the legacy 32-bit address space clear the inode32 option.
498 agino
= XFS_AGB_TO_AGINO(mp
, sbp
->sb_agblocks
- 1);
499 ino
= XFS_AGINO_TO_INO(mp
, agcount
- 1, agino
);
501 if ((mp
->m_flags
& XFS_MOUNT_SMALL_INUMS
) && ino
> XFS_MAXINUMBER_32
)
502 mp
->m_flags
|= XFS_MOUNT_32BITINODES
;
504 mp
->m_flags
&= ~XFS_MOUNT_32BITINODES
;
506 if (mp
->m_flags
& XFS_MOUNT_32BITINODES
) {
508 * Calculate how much should be reserved for inodes to meet
509 * the max inode percentage.
511 if (mp
->m_maxicount
) {
514 icount
= sbp
->sb_dblocks
* sbp
->sb_imax_pct
;
516 icount
+= sbp
->sb_agblocks
- 1;
517 do_div(icount
, sbp
->sb_agblocks
);
518 max_metadata
= icount
;
520 max_metadata
= agcount
;
523 for (index
= 0; index
< agcount
; index
++) {
524 ino
= XFS_AGINO_TO_INO(mp
, index
, agino
);
525 if (ino
> XFS_MAXINUMBER_32
) {
530 pag
= xfs_perag_get(mp
, index
);
531 pag
->pagi_inodeok
= 1;
532 if (index
< max_metadata
)
533 pag
->pagf_metadata
= 1;
537 for (index
= 0; index
< agcount
; index
++) {
538 pag
= xfs_perag_get(mp
, index
);
539 pag
->pagi_inodeok
= 1;
547 mp
->m_ag_prealloc_blocks
= xfs_prealloc_blocks(mp
);
552 for (; index
> first_initialised
; index
--) {
553 pag
= radix_tree_delete(&mp
->m_perag_tree
, index
);
559 static struct xfs_buftarg
*
560 libxfs_buftarg_alloc(
561 struct xfs_mount
*mp
,
564 struct xfs_buftarg
*btp
;
566 btp
= malloc(sizeof(*btp
));
568 fprintf(stderr
, _("%s: buftarg init failed\n"),
579 struct xfs_mount
*mp
,
584 if (mp
->m_ddev_targp
) {
585 /* should already have all buftargs initialised */
586 if (mp
->m_ddev_targp
->dev
!= dev
||
587 mp
->m_ddev_targp
->bt_mount
!= mp
) {
589 _("%s: bad buftarg reinit, ddev\n"),
593 if (!logdev
|| logdev
== dev
) {
594 if (mp
->m_logdev_targp
!= mp
->m_ddev_targp
) {
596 _("%s: bad buftarg reinit, ldev mismatch\n"),
600 } else if (mp
->m_logdev_targp
->dev
!= logdev
||
601 mp
->m_logdev_targp
->bt_mount
!= mp
) {
603 _("%s: bad buftarg reinit, logdev\n"),
607 if (rtdev
&& (mp
->m_rtdev_targp
->dev
!= rtdev
||
608 mp
->m_rtdev_targp
->bt_mount
!= mp
)) {
610 _("%s: bad buftarg reinit, rtdev\n"),
617 mp
->m_ddev_targp
= libxfs_buftarg_alloc(mp
, dev
);
618 if (!logdev
|| logdev
== dev
)
619 mp
->m_logdev_targp
= mp
->m_ddev_targp
;
621 mp
->m_logdev_targp
= libxfs_buftarg_alloc(mp
, logdev
);
622 mp
->m_rtdev_targp
= libxfs_buftarg_alloc(mp
, rtdev
);
626 * Mount structure initialization, provides a filled-in xfs_mount_t
627 * such that the numerous XFS_* macros can be used. If dev is zero,
628 * no IO will be performed (no size checks, read root inodes).
644 libxfs_buftarg_init(mp
, dev
, logdev
, rtdev
);
646 mp
->m_flags
= (LIBXFS_MOUNT_32BITINODES
|LIBXFS_MOUNT_32BITINOOPT
);
648 INIT_RADIX_TREE(&mp
->m_perag_tree
, GFP_KERNEL
);
651 xfs_sb_mount_common(mp
, sb
);
653 xfs_alloc_compute_maxlevels(mp
);
654 xfs_bmap_compute_maxlevels(mp
, XFS_DATA_FORK
);
655 xfs_bmap_compute_maxlevels(mp
, XFS_ATTR_FORK
);
656 xfs_ialloc_compute_maxlevels(mp
);
657 xfs_rmapbt_compute_maxlevels(mp
);
658 xfs_refcountbt_compute_maxlevels(mp
);
660 if (sbp
->sb_imax_pct
) {
661 /* Make sure the maximum inode count is a multiple of the
662 * units we allocate inodes in.
664 mp
->m_maxicount
= (sbp
->sb_dblocks
* sbp
->sb_imax_pct
) / 100;
665 mp
->m_maxicount
= XFS_FSB_TO_INO(mp
,
666 (mp
->m_maxicount
/ mp
->m_ialloc_blks
) *
671 mp
->m_inode_cluster_size
= XFS_INODE_BIG_CLUSTER_SIZE
;
672 if (xfs_sb_version_hascrc(&mp
->m_sb
)) {
673 int new_size
= mp
->m_inode_cluster_size
;
675 new_size
*= mp
->m_sb
.sb_inodesize
/ XFS_DINODE_MIN_SIZE
;
676 if (mp
->m_sb
.sb_inoalignmt
>= XFS_B_TO_FSBT(mp
, new_size
))
677 mp
->m_inode_cluster_size
= new_size
;
681 * Set whether we're using stripe alignment.
683 if (xfs_sb_version_hasdalign(&mp
->m_sb
)) {
684 mp
->m_dalign
= sbp
->sb_unit
;
685 mp
->m_swidth
= sbp
->sb_width
;
689 * Set whether we're using inode alignment.
691 if (xfs_sb_version_hasalign(&mp
->m_sb
) &&
692 mp
->m_sb
.sb_inoalignmt
>=
693 XFS_B_TO_FSBT(mp
, mp
->m_inode_cluster_size
))
694 mp
->m_inoalign_mask
= mp
->m_sb
.sb_inoalignmt
- 1;
696 mp
->m_inoalign_mask
= 0;
698 * If we are using stripe alignment, check whether
699 * the stripe unit is a multiple of the inode alignment
701 if (mp
->m_dalign
&& mp
->m_inoalign_mask
&&
702 !(mp
->m_dalign
& mp
->m_inoalign_mask
))
703 mp
->m_sinoalign
= mp
->m_dalign
;
708 * Check that the data (and log if separate) are an ok size.
710 d
= (xfs_daddr_t
) XFS_FSB_TO_BB(mp
, mp
->m_sb
.sb_dblocks
);
711 if (XFS_BB_TO_FSB(mp
, d
) != mp
->m_sb
.sb_dblocks
) {
712 fprintf(stderr
, _("%s: size check failed\n"), progname
);
713 if (!(flags
& LIBXFS_MOUNT_DEBUGGER
))
718 * We automatically convert v1 inodes to v2 inodes now, so if
719 * the NLINK bit is not set we can't operate on the filesystem.
721 if (!(sbp
->sb_versionnum
& XFS_SB_VERSION_NLINKBIT
)) {
724 "%s: V1 inodes unsupported. Please try an older xfsprogs.\n"),
729 /* Check for supported directory formats */
730 if (!(sbp
->sb_versionnum
& XFS_SB_VERSION_DIRV2BIT
)) {
733 "%s: V1 directories unsupported. Please try an older xfsprogs.\n"),
738 /* check for unsupported other features */
739 if (!xfs_sb_good_version(sbp
)) {
741 "%s: Unsupported features detected. Please try a newer xfsprogs.\n"),
748 if (xfs_sb_version_hasattr2(&mp
->m_sb
))
749 mp
->m_flags
|= LIBXFS_MOUNT_ATTR2
;
751 /* Initialize the precomputed transaction reservations values */
754 if (dev
== 0) /* maxtrres, we have no device so leave now */
757 bp
= libxfs_readbuf(mp
->m_dev
,
758 d
- XFS_FSS_TO_BB(mp
, 1), XFS_FSS_TO_BB(mp
, 1),
759 !(flags
& LIBXFS_MOUNT_DEBUGGER
), NULL
);
761 fprintf(stderr
, _("%s: data size check failed\n"), progname
);
762 if (!(flags
& LIBXFS_MOUNT_DEBUGGER
))
767 if (mp
->m_logdev_targp
->dev
&&
768 mp
->m_logdev_targp
->dev
!= mp
->m_ddev_targp
->dev
) {
769 d
= (xfs_daddr_t
) XFS_FSB_TO_BB(mp
, mp
->m_sb
.sb_logblocks
);
770 if ( (XFS_BB_TO_FSB(mp
, d
) != mp
->m_sb
.sb_logblocks
) ||
771 (!(bp
= libxfs_readbuf(mp
->m_logdev_targp
,
772 d
- XFS_FSB_TO_BB(mp
, 1),
773 XFS_FSB_TO_BB(mp
, 1),
774 !(flags
& LIBXFS_MOUNT_DEBUGGER
), NULL
))) ) {
775 fprintf(stderr
, _("%s: log size checks failed\n"),
777 if (!(flags
& LIBXFS_MOUNT_DEBUGGER
))
784 /* Initialize realtime fields in the mount structure */
785 if (rtmount_init(mp
, flags
)) {
786 fprintf(stderr
, _("%s: realtime device init failed\n"),
792 * libxfs_initialize_perag will allocate a perag structure for each ag.
793 * If agcount is corrupted and insanely high, this will OOM the box.
794 * If the agount seems (arbitrarily) high, try to read what would be
795 * the last AG, and if that fails for a relatively high agcount, just
796 * read the first one and let the user know to check the geometry.
798 if (sbp
->sb_agcount
> 1000000) {
799 bp
= libxfs_readbuf(mp
->m_dev
,
800 XFS_AG_DADDR(mp
, sbp
->sb_agcount
- 1, 0), 1,
801 !(flags
& LIBXFS_MOUNT_DEBUGGER
), NULL
);
803 fprintf(stderr
, _("%s: read of AG %u failed\n"),
804 progname
, sbp
->sb_agcount
);
805 if (!(flags
& LIBXFS_MOUNT_DEBUGGER
))
807 fprintf(stderr
, _("%s: limiting reads to AG 0\n"),
814 error
= libxfs_initialize_perag(mp
, sbp
->sb_agcount
, &mp
->m_maxagi
);
816 fprintf(stderr
, _("%s: perag init failed\n"),
825 libxfs_rtmount_destroy(xfs_mount_t
*mp
)
828 libxfs_irele(mp
->m_rsumip
);
830 libxfs_irele(mp
->m_rbmip
);
831 mp
->m_rsumip
= mp
->m_rbmip
= NULL
;
835 * Release any resource obtained during a mount.
838 libxfs_umount(xfs_mount_t
*mp
)
840 struct xfs_perag
*pag
;
843 libxfs_rtmount_destroy(mp
);
844 libxfs_bcache_purge();
846 for (agno
= 0; agno
< mp
->m_maxagi
; agno
++) {
847 pag
= radix_tree_delete(&mp
->m_perag_tree
, agno
);
851 kmem_free(mp
->m_attr_geo
);
852 kmem_free(mp
->m_dir_geo
);
854 kmem_free(mp
->m_rtdev_targp
);
855 if (mp
->m_logdev_targp
!= mp
->m_ddev_targp
)
856 kmem_free(mp
->m_logdev_targp
);
857 kmem_free(mp
->m_ddev_targp
);
862 * Release any global resources used by libxfs.
869 /* Free everything from the buffer cache before freeing buffer zone */
870 libxfs_bcache_purge();
871 libxfs_bcache_free();
872 cache_destroy(libxfs_bcache
);
873 leaked
= manage_zones(1);
874 if (getenv("LIBXFS_LEAK_CHECK") && leaked
)
879 libxfs_device_alignment(void)
881 return platform_align_blockdev();
885 libxfs_report(FILE *fp
)
890 cache_report(fp
, "libxfs_bcache", libxfs_bcache
);
893 c
= asctime(localtime(&t
));
894 fprintf(fp
, "%s", c
);
902 nr
= platform_nproc();
911 return platform_physmem();