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
);
251 xfs_extent_free_init_defer_op();
252 xfs_rmap_update_init_defer_op();
253 xfs_refcount_update_init_defer_op();
254 xfs_bmap_update_init_defer_op();
259 if(!check_open(a
->volname
,flags
,&rawfile
,&blockfile
))
261 fd
= open(rawfile
, O_RDONLY
);
262 dname
= a
->dname
= a
->volname
;
267 a
->ddev
= libxfs_device_open(dname
, a
->dcreat
, flags
,
269 a
->dfd
= libxfs_device_to_fd(a
->ddev
);
270 platform_findsizes(dname
, a
->dfd
, &a
->dsize
,
273 if (!check_open(dname
, flags
, &rawfile
, &blockfile
))
275 a
->ddev
= libxfs_device_open(rawfile
,
276 a
->dcreat
, flags
, a
->setblksize
);
277 a
->dfd
= libxfs_device_to_fd(a
->ddev
);
278 platform_findsizes(rawfile
, a
->dfd
,
279 &a
->dsize
, &a
->dbsize
);
285 a
->logdev
= libxfs_device_open(logname
,
286 a
->lcreat
, flags
, a
->setblksize
);
287 a
->logfd
= libxfs_device_to_fd(a
->logdev
);
288 platform_findsizes(dname
, a
->logfd
, &a
->logBBsize
,
291 if (!check_open(logname
, flags
, &rawfile
, &blockfile
))
293 a
->logdev
= libxfs_device_open(rawfile
,
294 a
->lcreat
, flags
, a
->setblksize
);
295 a
->logfd
= libxfs_device_to_fd(a
->logdev
);
296 platform_findsizes(rawfile
, a
->logfd
,
297 &a
->logBBsize
, &a
->lbsize
);
303 a
->rtdev
= libxfs_device_open(rtname
,
304 a
->rcreat
, flags
, a
->setblksize
);
305 a
->rtfd
= libxfs_device_to_fd(a
->rtdev
);
306 platform_findsizes(dname
, a
->rtfd
, &a
->rtsize
,
309 if (!check_open(rtname
, flags
, &rawfile
, &blockfile
))
311 a
->rtdev
= libxfs_device_open(rawfile
,
312 a
->rcreat
, flags
, a
->setblksize
);
313 a
->rtfd
= libxfs_device_to_fd(a
->rtdev
);
314 platform_findsizes(rawfile
, a
->rtfd
,
315 &a
->rtsize
, &a
->rtbsize
);
320 fprintf(stderr
, _("%s: can't get size for data subvolume\n"),
324 if (a
->logBBsize
< 0) {
325 fprintf(stderr
, _("%s: can't get size for log subvolume\n"),
330 fprintf(stderr
, _("%s: can't get size for realtime subvolume\n"),
334 if (!libxfs_bhash_size
)
335 libxfs_bhash_size
= LIBXFS_BHASHSIZE(sbp
);
336 libxfs_bcache
= cache_init(a
->bcache_flags
, libxfs_bhash_size
,
337 &libxfs_bcache_operations
);
338 use_xfs_buf_lock
= a
->usebuflock
;
350 if (!rval
&& a
->ddev
)
351 libxfs_device_close(a
->ddev
);
352 if (!rval
&& a
->logdev
)
353 libxfs_device_close(a
->logdev
);
354 if (!rval
&& a
->rtdev
)
355 libxfs_device_close(a
->rtdev
);
361 * Initialize/destroy all of the zone allocators we use.
364 manage_zones(int release
)
366 extern kmem_zone_t
*xfs_buf_zone
;
367 extern kmem_zone_t
*xfs_ili_zone
;
368 extern kmem_zone_t
*xfs_inode_zone
;
369 extern kmem_zone_t
*xfs_ifork_zone
;
370 extern kmem_zone_t
*xfs_buf_item_zone
;
371 extern kmem_zone_t
*xfs_da_state_zone
;
372 extern kmem_zone_t
*xfs_btree_cur_zone
;
373 extern kmem_zone_t
*xfs_bmap_free_item_zone
;
374 extern kmem_zone_t
*xfs_trans_zone
;
375 extern void xfs_dir_startup();
377 if (release
) { /* free zone allocation */
380 leaked
+= kmem_zone_destroy(xfs_buf_zone
);
381 leaked
+= kmem_zone_destroy(xfs_ili_zone
);
382 leaked
+= kmem_zone_destroy(xfs_inode_zone
);
383 leaked
+= kmem_zone_destroy(xfs_ifork_zone
);
384 leaked
+= kmem_zone_destroy(xfs_buf_item_zone
);
385 leaked
+= kmem_zone_destroy(xfs_da_state_zone
);
386 leaked
+= kmem_zone_destroy(xfs_btree_cur_zone
);
387 leaked
+= kmem_zone_destroy(xfs_bmap_free_item_zone
);
388 leaked
+= kmem_zone_destroy(xfs_trans_zone
);
392 /* otherwise initialise zone allocation */
393 xfs_buf_zone
= kmem_zone_init(sizeof(xfs_buf_t
), "xfs_buffer");
394 xfs_inode_zone
= kmem_zone_init(sizeof(struct xfs_inode
), "xfs_inode");
395 xfs_ifork_zone
= kmem_zone_init(sizeof(struct xfs_ifork
), "xfs_ifork");
396 xfs_ili_zone
= kmem_zone_init(
397 sizeof(xfs_inode_log_item_t
), "xfs_inode_log_item");
398 xfs_buf_item_zone
= kmem_zone_init(
399 sizeof(xfs_buf_log_item_t
), "xfs_buf_log_item");
400 xfs_da_state_zone
= kmem_zone_init(
401 sizeof(xfs_da_state_t
), "xfs_da_state");
402 xfs_btree_cur_zone
= kmem_zone_init(
403 sizeof(xfs_btree_cur_t
), "xfs_btree_cur");
404 xfs_bmap_free_item_zone
= kmem_zone_init(
405 sizeof(struct xfs_extent_free_item
),
406 "xfs_bmap_free_item");
407 xfs_trans_zone
= kmem_zone_init(
408 sizeof(struct xfs_trans
), "xfs_trans");
415 * Initialize realtime fields in the mount structure.
419 xfs_mount_t
*mp
, /* file system mount structure */
422 xfs_buf_t
*bp
; /* buffer for last block of subvolume */
423 xfs_daddr_t d
; /* address of last block of subvolume */
424 xfs_sb_t
*sbp
; /* filesystem superblock copy in mount */
427 if (sbp
->sb_rblocks
== 0)
429 if (mp
->m_rtdev_targp
->dev
== 0 && !(flags
& LIBXFS_MOUNT_DEBUGGER
)) {
430 fprintf(stderr
, _("%s: filesystem has a realtime subvolume\n"),
434 mp
->m_rsumlevels
= sbp
->sb_rextslog
+ 1;
436 (uint
)sizeof(xfs_suminfo_t
) * mp
->m_rsumlevels
*
438 mp
->m_rsumsize
= roundup(mp
->m_rsumsize
, sbp
->sb_blocksize
);
439 mp
->m_rbmip
= mp
->m_rsumip
= NULL
;
442 * Allow debugger to be run without the realtime device present.
444 if (flags
& LIBXFS_MOUNT_DEBUGGER
)
448 * Check that the realtime section is an ok size.
450 d
= (xfs_daddr_t
)XFS_FSB_TO_BB(mp
, mp
->m_sb
.sb_rblocks
);
451 if (XFS_BB_TO_FSB(mp
, d
) != mp
->m_sb
.sb_rblocks
) {
452 fprintf(stderr
, _("%s: realtime init - %llu != %llu\n"),
453 progname
, (unsigned long long) XFS_BB_TO_FSB(mp
, d
),
454 (unsigned long long) mp
->m_sb
.sb_rblocks
);
457 bp
= libxfs_readbuf(mp
->m_rtdev
,
458 d
- XFS_FSB_TO_BB(mp
, 1), XFS_FSB_TO_BB(mp
, 1), 0, NULL
);
460 fprintf(stderr
, _("%s: realtime size check failed\n"),
469 libxfs_initialize_perag(
471 xfs_agnumber_t agcount
,
472 xfs_agnumber_t
*maxagi
)
474 xfs_agnumber_t index
, max_metadata
;
475 xfs_agnumber_t first_initialised
= 0;
479 xfs_sb_t
*sbp
= &mp
->m_sb
;
483 * Walk the current per-ag tree so we don't try to initialise AGs
484 * that already exist (growfs case). Allocate and insert all the
485 * AGs we don't find ready for initialisation.
487 for (index
= 0; index
< agcount
; index
++) {
488 pag
= xfs_perag_get(mp
, index
);
493 if (!first_initialised
)
494 first_initialised
= index
;
496 pag
= kmem_zalloc(sizeof(*pag
), KM_MAYFAIL
);
499 pag
->pag_agno
= index
;
502 if (radix_tree_insert(&mp
->m_perag_tree
, index
, pag
)) {
509 * If we mount with the inode64 option, or no inode overflows
510 * the legacy 32-bit address space clear the inode32 option.
512 agino
= XFS_OFFBNO_TO_AGINO(mp
, sbp
->sb_agblocks
- 1, 0);
513 ino
= XFS_AGINO_TO_INO(mp
, agcount
- 1, agino
);
515 if ((mp
->m_flags
& XFS_MOUNT_SMALL_INUMS
) && ino
> XFS_MAXINUMBER_32
)
516 mp
->m_flags
|= XFS_MOUNT_32BITINODES
;
518 mp
->m_flags
&= ~XFS_MOUNT_32BITINODES
;
520 if (mp
->m_flags
& XFS_MOUNT_32BITINODES
) {
522 * Calculate how much should be reserved for inodes to meet
523 * the max inode percentage.
525 if (mp
->m_maxicount
) {
528 icount
= sbp
->sb_dblocks
* sbp
->sb_imax_pct
;
530 icount
+= sbp
->sb_agblocks
- 1;
531 do_div(icount
, sbp
->sb_agblocks
);
532 max_metadata
= icount
;
534 max_metadata
= agcount
;
537 for (index
= 0; index
< agcount
; index
++) {
538 ino
= XFS_AGINO_TO_INO(mp
, index
, agino
);
539 if (ino
> XFS_MAXINUMBER_32
) {
544 pag
= xfs_perag_get(mp
, index
);
545 pag
->pagi_inodeok
= 1;
546 if (index
< max_metadata
)
547 pag
->pagf_metadata
= 1;
551 for (index
= 0; index
< agcount
; index
++) {
552 pag
= xfs_perag_get(mp
, index
);
553 pag
->pagi_inodeok
= 1;
561 mp
->m_ag_prealloc_blocks
= xfs_prealloc_blocks(mp
);
566 for (; index
> first_initialised
; index
--) {
567 pag
= radix_tree_delete(&mp
->m_perag_tree
, index
);
573 static struct xfs_buftarg
*
574 libxfs_buftarg_alloc(
575 struct xfs_mount
*mp
,
578 struct xfs_buftarg
*btp
;
580 btp
= malloc(sizeof(*btp
));
582 fprintf(stderr
, _("%s: buftarg init failed\n"),
593 struct xfs_mount
*mp
,
598 if (mp
->m_ddev_targp
) {
599 /* should already have all buftargs initialised */
600 if (mp
->m_ddev_targp
->dev
!= dev
||
601 mp
->m_ddev_targp
->bt_mount
!= mp
) {
603 _("%s: bad buftarg reinit, ddev\n"),
607 if (!logdev
|| logdev
== dev
) {
608 if (mp
->m_logdev_targp
!= mp
->m_ddev_targp
) {
610 _("%s: bad buftarg reinit, ldev mismatch\n"),
614 } else if (mp
->m_logdev_targp
->dev
!= logdev
||
615 mp
->m_logdev_targp
->bt_mount
!= mp
) {
617 _("%s: bad buftarg reinit, logdev\n"),
621 if (rtdev
&& (mp
->m_rtdev_targp
->dev
!= rtdev
||
622 mp
->m_rtdev_targp
->bt_mount
!= mp
)) {
624 _("%s: bad buftarg reinit, rtdev\n"),
631 mp
->m_ddev_targp
= libxfs_buftarg_alloc(mp
, dev
);
632 if (!logdev
|| logdev
== dev
)
633 mp
->m_logdev_targp
= mp
->m_ddev_targp
;
635 mp
->m_logdev_targp
= libxfs_buftarg_alloc(mp
, logdev
);
636 mp
->m_rtdev_targp
= libxfs_buftarg_alloc(mp
, rtdev
);
640 * Mount structure initialization, provides a filled-in xfs_mount_t
641 * such that the numerous XFS_* macros can be used. If dev is zero,
642 * no IO will be performed (no size checks, read root inodes).
658 libxfs_buftarg_init(mp
, dev
, logdev
, rtdev
);
660 mp
->m_flags
= (LIBXFS_MOUNT_32BITINODES
|LIBXFS_MOUNT_32BITINOOPT
);
662 INIT_RADIX_TREE(&mp
->m_perag_tree
, GFP_KERNEL
);
665 xfs_sb_mount_common(mp
, sb
);
667 xfs_alloc_compute_maxlevels(mp
);
668 xfs_bmap_compute_maxlevels(mp
, XFS_DATA_FORK
);
669 xfs_bmap_compute_maxlevels(mp
, XFS_ATTR_FORK
);
670 xfs_ialloc_compute_maxlevels(mp
);
671 xfs_rmapbt_compute_maxlevels(mp
);
672 xfs_refcountbt_compute_maxlevels(mp
);
674 if (sbp
->sb_imax_pct
) {
675 /* Make sure the maximum inode count is a multiple of the
676 * units we allocate inodes in.
678 mp
->m_maxicount
= (sbp
->sb_dblocks
* sbp
->sb_imax_pct
) / 100;
679 mp
->m_maxicount
= ((mp
->m_maxicount
/ mp
->m_ialloc_blks
) *
680 mp
->m_ialloc_blks
) << sbp
->sb_inopblog
;
684 mp
->m_inode_cluster_size
= XFS_INODE_BIG_CLUSTER_SIZE
;
685 if (xfs_sb_version_hascrc(&mp
->m_sb
)) {
686 int new_size
= mp
->m_inode_cluster_size
;
688 new_size
*= mp
->m_sb
.sb_inodesize
/ XFS_DINODE_MIN_SIZE
;
689 if (mp
->m_sb
.sb_inoalignmt
>= XFS_B_TO_FSBT(mp
, new_size
))
690 mp
->m_inode_cluster_size
= new_size
;
694 * Set whether we're using stripe alignment.
696 if (xfs_sb_version_hasdalign(&mp
->m_sb
)) {
697 mp
->m_dalign
= sbp
->sb_unit
;
698 mp
->m_swidth
= sbp
->sb_width
;
702 * Set whether we're using inode alignment.
704 if (xfs_sb_version_hasalign(&mp
->m_sb
) &&
705 mp
->m_sb
.sb_inoalignmt
>=
706 XFS_B_TO_FSBT(mp
, mp
->m_inode_cluster_size
))
707 mp
->m_inoalign_mask
= mp
->m_sb
.sb_inoalignmt
- 1;
709 mp
->m_inoalign_mask
= 0;
711 * If we are using stripe alignment, check whether
712 * the stripe unit is a multiple of the inode alignment
714 if (mp
->m_dalign
&& mp
->m_inoalign_mask
&&
715 !(mp
->m_dalign
& mp
->m_inoalign_mask
))
716 mp
->m_sinoalign
= mp
->m_dalign
;
721 * Check that the data (and log if separate) are an ok size.
723 d
= (xfs_daddr_t
) XFS_FSB_TO_BB(mp
, mp
->m_sb
.sb_dblocks
);
724 if (XFS_BB_TO_FSB(mp
, d
) != mp
->m_sb
.sb_dblocks
) {
725 fprintf(stderr
, _("%s: size check failed\n"), progname
);
726 if (!(flags
& LIBXFS_MOUNT_DEBUGGER
))
731 * We automatically convert v1 inodes to v2 inodes now, so if
732 * the NLINK bit is not set we can't operate on the filesystem.
734 if (!(sbp
->sb_versionnum
& XFS_SB_VERSION_NLINKBIT
)) {
737 "%s: V1 inodes unsupported. Please try an older xfsprogs.\n"),
742 /* Check for supported directory formats */
743 if (!(sbp
->sb_versionnum
& XFS_SB_VERSION_DIRV2BIT
)) {
746 "%s: V1 directories unsupported. Please try an older xfsprogs.\n"),
751 /* check for unsupported other features */
752 if (!xfs_sb_good_version(sbp
)) {
754 "%s: Unsupported features detected. Please try a newer xfsprogs.\n"),
761 if (xfs_sb_version_hasattr2(&mp
->m_sb
))
762 mp
->m_flags
|= LIBXFS_MOUNT_ATTR2
;
764 /* Initialize the precomputed transaction reservations values */
767 if (dev
== 0) /* maxtrres, we have no device so leave now */
770 bp
= libxfs_readbuf(mp
->m_dev
,
771 d
- XFS_FSS_TO_BB(mp
, 1), XFS_FSS_TO_BB(mp
, 1),
772 !(flags
& LIBXFS_MOUNT_DEBUGGER
), NULL
);
774 fprintf(stderr
, _("%s: data size check failed\n"), progname
);
775 if (!(flags
& LIBXFS_MOUNT_DEBUGGER
))
780 if (mp
->m_logdev_targp
->dev
&&
781 mp
->m_logdev_targp
->dev
!= mp
->m_ddev_targp
->dev
) {
782 d
= (xfs_daddr_t
) XFS_FSB_TO_BB(mp
, mp
->m_sb
.sb_logblocks
);
783 if ( (XFS_BB_TO_FSB(mp
, d
) != mp
->m_sb
.sb_logblocks
) ||
784 (!(bp
= libxfs_readbuf(mp
->m_logdev_targp
,
785 d
- XFS_FSB_TO_BB(mp
, 1),
786 XFS_FSB_TO_BB(mp
, 1),
787 !(flags
& LIBXFS_MOUNT_DEBUGGER
), NULL
))) ) {
788 fprintf(stderr
, _("%s: log size checks failed\n"),
790 if (!(flags
& LIBXFS_MOUNT_DEBUGGER
))
797 /* Initialize realtime fields in the mount structure */
798 if (rtmount_init(mp
, flags
)) {
799 fprintf(stderr
, _("%s: realtime device init failed\n"),
805 * libxfs_initialize_perag will allocate a perag structure for each ag.
806 * If agcount is corrupted and insanely high, this will OOM the box.
807 * If the agount seems (arbitrarily) high, try to read what would be
808 * the last AG, and if that fails for a relatively high agcount, just
809 * read the first one and let the user know to check the geometry.
811 if (sbp
->sb_agcount
> 1000000) {
812 bp
= libxfs_readbuf(mp
->m_dev
,
813 XFS_AG_DADDR(mp
, sbp
->sb_agcount
- 1, 0), 1,
814 !(flags
& LIBXFS_MOUNT_DEBUGGER
), NULL
);
816 fprintf(stderr
, _("%s: read of AG %u failed\n"),
817 progname
, sbp
->sb_agcount
);
818 if (!(flags
& LIBXFS_MOUNT_DEBUGGER
))
820 fprintf(stderr
, _("%s: limiting reads to AG 0\n"),
827 error
= libxfs_initialize_perag(mp
, sbp
->sb_agcount
, &mp
->m_maxagi
);
829 fprintf(stderr
, _("%s: perag init failed\n"),
838 libxfs_rtmount_destroy(xfs_mount_t
*mp
)
841 libxfs_irele(mp
->m_rsumip
);
843 libxfs_irele(mp
->m_rbmip
);
844 mp
->m_rsumip
= mp
->m_rbmip
= NULL
;
848 * Release any resource obtained during a mount.
851 libxfs_umount(xfs_mount_t
*mp
)
853 struct xfs_perag
*pag
;
856 libxfs_rtmount_destroy(mp
);
857 libxfs_bcache_purge();
859 for (agno
= 0; agno
< mp
->m_maxagi
; agno
++) {
860 pag
= radix_tree_delete(&mp
->m_perag_tree
, agno
);
864 kmem_free(mp
->m_attr_geo
);
865 kmem_free(mp
->m_dir_geo
);
867 kmem_free(mp
->m_rtdev_targp
);
868 if (mp
->m_logdev_targp
!= mp
->m_ddev_targp
)
869 kmem_free(mp
->m_logdev_targp
);
870 kmem_free(mp
->m_ddev_targp
);
875 * Release any global resources used by libxfs.
882 /* Free everything from the buffer cache before freeing buffer zone */
883 libxfs_bcache_purge();
884 libxfs_bcache_free();
885 cache_destroy(libxfs_bcache
);
886 leaked
= manage_zones(1);
887 if (getenv("LIBXFS_LEAK_CHECK") && leaked
)
892 libxfs_device_alignment(void)
894 return platform_align_blockdev();
898 libxfs_report(FILE *fp
)
903 cache_report(fp
, "libxfs_bcache", libxfs_bcache
);
906 c
= asctime(localtime(&t
));
907 fprintf(fp
, "%s", c
);
915 nr
= platform_nproc();
924 return platform_physmem();