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"
24 #include "libfrog/platform.h"
26 #include "xfs_format.h"
27 #include "xfs_da_format.h"
28 #include "xfs_log_format.h"
29 #include "xfs_ondisk.h"
31 #include "libxfs.h" /* for now */
33 #ifndef HAVE_LIBURCU_ATOMIC64
34 pthread_mutex_t atomic64_lock
= PTHREAD_MUTEX_INITIALIZER
;
37 char *progname
= "libxfs"; /* default, changed by each tool */
39 struct cache
*libxfs_bcache
; /* global buffer cache */
40 int libxfs_bhash_size
; /* #buckets in bcache */
42 int use_xfs_buf_lock
; /* global flag: use xfs_buf locks for MT */
44 static int nextfakedev
= -1; /* device number to give to next fake device */
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
))
72 struct libxfs_init
*xi
,
73 struct libxfs_dev
*dev
)
77 if (stat(dev
->name
, &stbuf
) < 0) {
81 if (!(xi
->flags
& LIBXFS_ISREADONLY
) &&
82 !(xi
->flags
& LIBXFS_ISINACTIVE
) &&
83 platform_check_ismounted(dev
->name
, dev
->name
, NULL
, 1))
86 if ((xi
->flags
& LIBXFS_ISINACTIVE
) &&
87 check_isactive(dev
->name
, dev
->name
, !!(xi
->flags
&
88 (LIBXFS_ISREADONLY
| LIBXFS_DANGEROUSLY
))))
96 struct libxfs_init
*xi
,
97 struct libxfs_dev
*dev
)
106 if (!dev
->isfile
&& !check_open(xi
, dev
))
109 if (xi
->flags
& LIBXFS_ISREADONLY
)
115 flags
|= O_CREAT
| O_TRUNC
;
117 if (xi
->flags
& LIBXFS_EXCLUSIVELY
)
119 if ((xi
->flags
& LIBXFS_DIRECT
) && platform_direct_blockdev())
124 dev
->fd
= open(dev
->name
, flags
, 0666);
126 if (errno
== EINVAL
&& (flags
& O_DIRECT
)) {
130 fprintf(stderr
, _("%s: cannot open %s: %s\n"),
131 progname
, dev
->name
, strerror(errno
));
135 if (fstat(dev
->fd
, &statb
) < 0) {
136 fprintf(stderr
, _("%s: cannot stat %s: %s\n"),
137 progname
, dev
->name
, strerror(errno
));
141 if (!(xi
->flags
& LIBXFS_ISREADONLY
) &&
143 (statb
.st_mode
& S_IFMT
) == S_IFBLK
) {
145 * Try to use the given explicit blocksize. Failure to set the
146 * block size is only fatal for direct I/O.
148 platform_set_blocksize(dev
->fd
, dev
->name
, statb
.st_rdev
,
149 xi
->setblksize
, flags
& O_DIRECT
);
153 * Get the device number from the stat buf - unless we're not opening a
154 * real device, in which case choose a new fake device number.
157 dev
->dev
= statb
.st_rdev
;
159 dev
->dev
= nextfakedev
--;
160 platform_findsizes(dev
->name
, dev
->fd
, &dev
->size
, &dev
->bsize
);
166 struct libxfs_dev
*dev
)
170 ret
= platform_flush_device(dev
->fd
, dev
->dev
);
174 _("%s: flush of device %s failed, err=%d"),
175 progname
, dev
->name
, ret
);
184 * Initialize/destroy all of the cache allocators we use.
191 /* initialise cache allocation */
192 xfs_buf_cache
= kmem_cache_init(sizeof(struct xfs_buf
), "xfs_buffer");
193 xfs_inode_cache
= kmem_cache_init(sizeof(struct xfs_inode
), "xfs_inode");
194 xfs_ifork_cache
= kmem_cache_init(sizeof(struct xfs_ifork
), "xfs_ifork");
195 xfs_ili_cache
= kmem_cache_init(
196 sizeof(struct xfs_inode_log_item
),"xfs_inode_log_item");
197 xfs_buf_item_cache
= kmem_cache_init(
198 sizeof(struct xfs_buf_log_item
), "xfs_buf_log_item");
199 error
= xfs_defer_init_item_caches();
201 fprintf(stderr
, "Could not allocate defer init item caches.\n");
204 xfs_da_state_cache
= kmem_cache_init(
205 sizeof(struct xfs_da_state
), "xfs_da_state");
206 error
= xfs_btree_init_cur_caches();
208 fprintf(stderr
, "Could not allocate btree cursor caches.\n");
211 xfs_extfree_item_cache
= kmem_cache_init(
212 sizeof(struct xfs_extent_free_item
),
214 xfs_trans_cache
= kmem_cache_init(
215 sizeof(struct xfs_trans
), "xfs_trans");
223 leaked
+= kmem_cache_destroy(xfs_buf_cache
);
224 leaked
+= kmem_cache_destroy(xfs_ili_cache
);
225 leaked
+= kmem_cache_destroy(xfs_inode_cache
);
226 leaked
+= kmem_cache_destroy(xfs_ifork_cache
);
227 leaked
+= kmem_cache_destroy(xfs_buf_item_cache
);
228 leaked
+= kmem_cache_destroy(xfs_da_state_cache
);
229 xfs_defer_destroy_item_caches();
230 xfs_btree_destroy_cur_caches();
231 leaked
+= kmem_cache_destroy(xfs_extfree_item_cache
);
232 leaked
+= kmem_cache_destroy(xfs_trans_cache
);
238 libxfs_close_devices(
239 struct libxfs_init
*li
)
242 libxfs_device_close(&li
->data
);
243 if (li
->log
.dev
&& li
->log
.dev
!= li
->data
.dev
)
244 libxfs_device_close(&li
->log
);
246 libxfs_device_close(&li
->rt
);
250 * libxfs initialization.
251 * Caller gets a 0 on failure (and we print a message), 1 on success.
254 libxfs_init(struct libxfs_init
*a
)
256 xfs_check_ondisk_structs();
258 rcu_register_thread();
261 if (!libxfs_device_open(a
, &a
->data
))
263 if (!libxfs_device_open(a
, &a
->log
))
265 if (!libxfs_device_open(a
, &a
->rt
))
268 if (!libxfs_bhash_size
)
269 libxfs_bhash_size
= LIBXFS_BHASHSIZE(sbp
);
270 libxfs_bcache
= cache_init(a
->bcache_flags
, libxfs_bhash_size
,
271 &libxfs_bcache_operations
);
272 use_xfs_buf_lock
= a
->flags
& LIBXFS_USEBUFLOCK
;
278 libxfs_close_devices(a
);
279 rcu_unregister_thread();
285 * Initialize realtime fields in the mount structure.
289 xfs_mount_t
*mp
) /* file system mount structure */
291 struct xfs_buf
*bp
; /* buffer for last block of subvolume */
292 xfs_daddr_t d
; /* address of last block of subvolume */
293 unsigned int rsumblocks
;
296 if (mp
->m_sb
.sb_rblocks
== 0)
299 if (xfs_has_reflink(mp
)) {
301 _("%s: Reflink not compatible with realtime device. Please try a newer xfsprogs.\n"),
306 if (xfs_has_rmapbt(mp
)) {
308 _("%s: Reverse mapping btree not compatible with realtime device. Please try a newer xfsprogs.\n"),
313 if (mp
->m_rtdev_targp
->bt_bdev
== 0 && !xfs_is_debugger(mp
)) {
314 fprintf(stderr
, _("%s: filesystem has a realtime subvolume\n"),
318 mp
->m_rsumlevels
= mp
->m_sb
.sb_rextslog
+ 1;
319 rsumblocks
= xfs_rtsummary_blockcount(mp
, mp
->m_rsumlevels
,
320 mp
->m_sb
.sb_rbmblocks
);
321 mp
->m_rsumsize
= XFS_FSB_TO_B(mp
, rsumblocks
);
322 mp
->m_rbmip
= mp
->m_rsumip
= NULL
;
325 * Allow debugger to be run without the realtime device present.
327 if (xfs_is_debugger(mp
))
331 * Check that the realtime section is an ok size.
333 d
= (xfs_daddr_t
)XFS_FSB_TO_BB(mp
, mp
->m_sb
.sb_rblocks
);
334 if (XFS_BB_TO_FSB(mp
, d
) != mp
->m_sb
.sb_rblocks
) {
335 fprintf(stderr
, _("%s: realtime init - %llu != %llu\n"),
336 progname
, (unsigned long long) XFS_BB_TO_FSB(mp
, d
),
337 (unsigned long long) mp
->m_sb
.sb_rblocks
);
340 error
= libxfs_buf_read(mp
->m_rtdev
, d
- XFS_FSB_TO_BB(mp
, 1),
341 XFS_FSB_TO_BB(mp
, 1), 0, &bp
, NULL
);
343 fprintf(stderr
, _("%s: realtime size check failed\n"),
347 libxfs_buf_relse(bp
);
352 xfs_set_inode_alloc_perag(
353 struct xfs_perag
*pag
,
355 xfs_agnumber_t max_metadata
)
357 if (!xfs_is_inode32(pag
->pag_mount
)) {
358 set_bit(XFS_AGSTATE_ALLOWS_INODES
, &pag
->pag_opstate
);
359 clear_bit(XFS_AGSTATE_PREFERS_METADATA
, &pag
->pag_opstate
);
363 if (ino
> XFS_MAXINUMBER_32
) {
364 clear_bit(XFS_AGSTATE_ALLOWS_INODES
, &pag
->pag_opstate
);
365 clear_bit(XFS_AGSTATE_PREFERS_METADATA
, &pag
->pag_opstate
);
369 set_bit(XFS_AGSTATE_ALLOWS_INODES
, &pag
->pag_opstate
);
370 if (pag
->pag_agno
< max_metadata
)
371 set_bit(XFS_AGSTATE_PREFERS_METADATA
, &pag
->pag_opstate
);
373 clear_bit(XFS_AGSTATE_PREFERS_METADATA
, &pag
->pag_opstate
);
378 * Set parameters for inode allocation heuristics, taking into account
379 * filesystem size and inode32/inode64 mount options; i.e. specifically
380 * whether or not XFS_MOUNT_SMALL_INUMS is set.
382 * Inode allocation patterns are altered only if inode32 is requested
383 * (XFS_MOUNT_SMALL_INUMS), and the filesystem is sufficiently large.
384 * If altered, XFS_MOUNT_32BITINODES is set as well.
386 * An agcount independent of that in the mount structure is provided
387 * because in the growfs case, mp->m_sb.sb_agcount is not yet updated
388 * to the potentially higher ag count.
390 * Returns the maximum AG index which may contain inodes.
392 * NOTE: userspace has no concept of "inode32" and so xfs_has_small_inums
393 * is always false, and much of this code is a no-op.
397 struct xfs_mount
*mp
,
398 xfs_agnumber_t agcount
)
400 xfs_agnumber_t index
;
401 xfs_agnumber_t maxagi
= 0;
402 xfs_sb_t
*sbp
= &mp
->m_sb
;
403 xfs_agnumber_t max_metadata
;
408 * Calculate how much should be reserved for inodes to meet
409 * the max inode percentage. Used only for inode32.
411 if (M_IGEO(mp
)->maxicount
) {
414 icount
= sbp
->sb_dblocks
* sbp
->sb_imax_pct
;
416 icount
+= sbp
->sb_agblocks
- 1;
417 do_div(icount
, sbp
->sb_agblocks
);
418 max_metadata
= icount
;
420 max_metadata
= agcount
;
423 /* Get the last possible inode in the filesystem */
424 agino
= XFS_AGB_TO_AGINO(mp
, sbp
->sb_agblocks
- 1);
425 ino
= XFS_AGINO_TO_INO(mp
, agcount
- 1, agino
);
428 * If user asked for no more than 32-bit inodes, and the fs is
429 * sufficiently large, set XFS_MOUNT_32BITINODES if we must alter
430 * the allocator to accommodate the request.
432 if (xfs_has_small_inums(mp
) && ino
> XFS_MAXINUMBER_32
)
433 set_bit(XFS_OPSTATE_INODE32
, &mp
->m_opstate
);
435 clear_bit(XFS_OPSTATE_INODE32
, &mp
->m_opstate
);
437 for (index
= 0; index
< agcount
; index
++) {
438 struct xfs_perag
*pag
;
440 ino
= XFS_AGINO_TO_INO(mp
, index
, agino
);
442 pag
= xfs_perag_get(mp
, index
);
443 if (xfs_set_inode_alloc_perag(pag
, ino
, max_metadata
))
448 return xfs_is_inode32(mp
) ? maxagi
: agcount
;
451 static struct xfs_buftarg
*
452 libxfs_buftarg_alloc(
453 struct xfs_mount
*mp
,
454 struct libxfs_dev
*dev
,
455 unsigned long write_fails
)
457 struct xfs_buftarg
*btp
;
459 btp
= malloc(sizeof(*btp
));
461 fprintf(stderr
, _("%s: buftarg init failed\n"),
466 btp
->bt_bdev
= dev
->dev
;
467 btp
->bt_bdev_fd
= dev
->fd
;
470 btp
->writes_left
= write_fails
;
471 btp
->flags
|= XFS_BUFTARG_INJECT_WRITE_FAIL
;
473 pthread_mutex_init(&btp
->lock
, NULL
);
478 enum libxfs_write_failure_nums
{
485 static char *wf_opts
[] = {
489 [WF_MAX_OPTS
] = NULL
,
494 struct xfs_mount
*mp
,
495 struct libxfs_init
*xi
)
497 char *p
= getenv("LIBXFS_DEBUG_WRITE_CRASH");
498 unsigned long dfail
= 0, lfail
= 0, rfail
= 0;
500 /* Simulate utility crash after a certain number of writes. */
504 switch (getsubopt(&p
, wf_opts
, &val
)) {
508 _("ddev write fail requires a parameter\n"));
511 dfail
= strtoul(val
, NULL
, 0);
516 _("logdev write fail requires a parameter\n"));
519 lfail
= strtoul(val
, NULL
, 0);
524 _("rtdev write fail requires a parameter\n"));
527 rfail
= strtoul(val
, NULL
, 0);
530 fprintf(stderr
, _("unknown write fail type %s\n"),
537 if (mp
->m_ddev_targp
) {
538 /* should already have all buftargs initialised */
539 if (mp
->m_ddev_targp
->bt_bdev
!= xi
->data
.dev
||
540 mp
->m_ddev_targp
->bt_mount
!= mp
) {
542 _("%s: bad buftarg reinit, ddev\n"),
546 if (!xi
->log
.dev
|| xi
->log
.dev
== xi
->data
.dev
) {
547 if (mp
->m_logdev_targp
!= mp
->m_ddev_targp
) {
549 _("%s: bad buftarg reinit, ldev mismatch\n"),
553 } else if (mp
->m_logdev_targp
->bt_bdev
!= xi
->log
.dev
||
554 mp
->m_logdev_targp
->bt_mount
!= mp
) {
556 _("%s: bad buftarg reinit, logdev\n"),
561 (mp
->m_rtdev_targp
->bt_bdev
!= xi
->rt
.dev
||
562 mp
->m_rtdev_targp
->bt_mount
!= mp
)) {
564 _("%s: bad buftarg reinit, rtdev\n"),
571 mp
->m_ddev_targp
= libxfs_buftarg_alloc(mp
, &xi
->data
, dfail
);
572 if (!xi
->log
.dev
|| xi
->log
.dev
== xi
->data
.dev
)
573 mp
->m_logdev_targp
= mp
->m_ddev_targp
;
575 mp
->m_logdev_targp
= libxfs_buftarg_alloc(mp
, &xi
->log
, lfail
);
576 mp
->m_rtdev_targp
= libxfs_buftarg_alloc(mp
, &xi
->rt
, rfail
);
579 /* Compute maximum possible height for per-AG btree types for this fs. */
581 xfs_agbtree_compute_maxlevels(
582 struct xfs_mount
*mp
)
586 levels
= max(mp
->m_alloc_maxlevels
, M_IGEO(mp
)->inobt_maxlevels
);
587 levels
= max(levels
, mp
->m_rmap_maxlevels
);
588 mp
->m_agbtree_maxlevels
= max(levels
, mp
->m_refc_maxlevels
);
591 /* Compute maximum possible height of all btrees. */
593 libxfs_compute_all_maxlevels(
594 struct xfs_mount
*mp
)
596 xfs_alloc_compute_maxlevels(mp
);
597 xfs_bmap_compute_maxlevels(mp
, XFS_DATA_FORK
);
598 xfs_bmap_compute_maxlevels(mp
, XFS_ATTR_FORK
);
599 xfs_ialloc_setup_geometry(mp
);
600 xfs_rmapbt_compute_maxlevels(mp
);
601 xfs_refcountbt_compute_maxlevels(mp
);
603 xfs_agbtree_compute_maxlevels(mp
);
607 * precalculate the low space thresholds for dynamic speculative preallocation.
610 xfs_set_low_space_thresholds(
611 struct xfs_mount
*mp
)
613 uint64_t dblocks
= mp
->m_sb
.sb_dblocks
;
616 do_div(dblocks
, 100);
618 for (i
= 0; i
< XFS_LOWSP_MAX
; i
++)
619 mp
->m_low_space
[i
] = dblocks
* (i
+ 1);
623 * Mount structure initialization, provides a filled-in xfs_mount_t
624 * such that the numerous XFS_* macros can be used. If dev is zero,
625 * no IO will be performed (no size checks, read root inodes).
629 struct xfs_mount
*mp
,
631 struct libxfs_init
*xi
,
639 mp
->m_features
= xfs_sb_version_to_features(sb
);
640 if (flags
& LIBXFS_MOUNT_DEBUGGER
)
641 xfs_set_debugger(mp
);
642 if (flags
& LIBXFS_MOUNT_REPORT_CORRUPTION
)
643 xfs_set_reporting_corruption(mp
);
644 libxfs_buftarg_init(mp
, xi
);
646 mp
->m_finobt_nores
= true;
649 INIT_RADIX_TREE(&mp
->m_perag_tree
, GFP_KERNEL
);
651 spin_lock_init(&mp
->m_sb_lock
);
652 spin_lock_init(&mp
->m_agirotor_lock
);
654 xfs_sb_mount_common(mp
, sb
);
657 * Set whether we're using stripe alignment.
659 if (xfs_has_dalign(mp
)) {
660 mp
->m_dalign
= sbp
->sb_unit
;
661 mp
->m_swidth
= sbp
->sb_width
;
664 libxfs_compute_all_maxlevels(mp
);
667 * Check that the data (and log if separate) are an ok size.
669 d
= (xfs_daddr_t
) XFS_FSB_TO_BB(mp
, mp
->m_sb
.sb_dblocks
);
670 if (XFS_BB_TO_FSB(mp
, d
) != mp
->m_sb
.sb_dblocks
) {
671 fprintf(stderr
, _("%s: size check failed\n"), progname
);
672 if (!xfs_is_debugger(mp
))
677 * We automatically convert v1 inodes to v2 inodes now, so if
678 * the NLINK bit is not set we can't operate on the filesystem.
680 if (!(sbp
->sb_versionnum
& XFS_SB_VERSION_NLINKBIT
)) {
683 "%s: V1 inodes unsupported. Please try an older xfsprogs.\n"),
688 /* Check for supported directory formats */
689 if (!(sbp
->sb_versionnum
& XFS_SB_VERSION_DIRV2BIT
)) {
692 "%s: V1 directories unsupported. Please try an older xfsprogs.\n"),
697 /* check for unsupported other features */
698 if (!xfs_sb_good_version(sbp
)) {
700 "%s: Unsupported features detected. Please try a newer xfsprogs.\n"),
707 /* Initialize the precomputed transaction reservations values */
710 if (xi
->data
.dev
== 0) /* maxtrres, we have no device so leave now */
713 /* device size checks must pass unless we're a debugger. */
714 error
= libxfs_buf_read(mp
->m_dev
, d
- XFS_FSS_TO_BB(mp
, 1),
715 XFS_FSS_TO_BB(mp
, 1), 0, &bp
, NULL
);
717 fprintf(stderr
, _("%s: data size check failed\n"), progname
);
718 if (!xfs_is_debugger(mp
))
721 libxfs_buf_relse(bp
);
723 if (mp
->m_logdev_targp
->bt_bdev
&&
724 mp
->m_logdev_targp
->bt_bdev
!= mp
->m_ddev_targp
->bt_bdev
) {
725 d
= (xfs_daddr_t
) XFS_FSB_TO_BB(mp
, mp
->m_sb
.sb_logblocks
);
726 if (XFS_BB_TO_FSB(mp
, d
) != mp
->m_sb
.sb_logblocks
||
727 libxfs_buf_read(mp
->m_logdev_targp
,
728 d
- XFS_FSB_TO_BB(mp
, 1), XFS_FSB_TO_BB(mp
, 1),
730 fprintf(stderr
, _("%s: log size checks failed\n"),
732 if (!xfs_is_debugger(mp
))
736 libxfs_buf_relse(bp
);
739 xfs_set_low_space_thresholds(mp
);
741 /* Initialize realtime fields in the mount structure */
742 if (rtmount_init(mp
)) {
743 fprintf(stderr
, _("%s: realtime device init failed\n"),
749 * libxfs_initialize_perag will allocate a perag structure for each ag.
750 * If agcount is corrupted and insanely high, this will OOM the box.
751 * If the agount seems (arbitrarily) high, try to read what would be
752 * the last AG, and if that fails for a relatively high agcount, just
753 * read the first one and let the user know to check the geometry.
755 if (sbp
->sb_agcount
> 1000000) {
756 error
= libxfs_buf_read(mp
->m_dev
,
757 XFS_AG_DADDR(mp
, sbp
->sb_agcount
- 1, 0), 1,
760 fprintf(stderr
, _("%s: read of AG %u failed\n"),
761 progname
, sbp
->sb_agcount
);
762 if (!xfs_is_debugger(mp
))
764 fprintf(stderr
, _("%s: limiting reads to AG 0\n"),
768 libxfs_buf_relse(bp
);
771 error
= libxfs_initialize_perag(mp
, sbp
->sb_agcount
, sbp
->sb_dblocks
,
774 fprintf(stderr
, _("%s: perag init failed\n"),
778 xfs_set_perag_data_loaded(mp
);
784 libxfs_rtmount_destroy(xfs_mount_t
*mp
)
787 libxfs_irele(mp
->m_rsumip
);
789 libxfs_irele(mp
->m_rbmip
);
790 mp
->m_rsumip
= mp
->m_rbmip
= NULL
;
793 /* Flush a device and report on writes that didn't make it to stable storage. */
795 libxfs_flush_buftarg(
796 struct xfs_buftarg
*btp
,
797 const char *buftarg_descr
)
803 * Write verifier failures are evidence of a buggy program. Make sure
804 * that this state is always reported to the caller.
806 if (btp
->flags
& XFS_BUFTARG_CORRUPT_WRITE
) {
808 _("%s: Refusing to write a corrupt buffer to the %s!\n"),
809 progname
, buftarg_descr
);
810 error
= -EFSCORRUPTED
;
813 if (btp
->flags
& XFS_BUFTARG_LOST_WRITE
) {
815 _("%s: Lost a write to the %s!\n"),
816 progname
, buftarg_descr
);
821 err2
= libxfs_blkdev_issue_flush(btp
);
824 _("%s: Flushing the %s failed, err=%d!\n"),
825 progname
, buftarg_descr
, -err2
);
834 * Flush all dirty buffers to stable storage and report on writes that didn't
835 * make it to stable storage.
839 struct xfs_mount
*mp
)
845 * Flush the buffer cache to write all dirty buffers to disk. Buffers
846 * that fail write verification will cause the CORRUPT_WRITE flag to be
847 * set in the buftarg. Buffers that cannot be written will cause the
848 * LOST_WRITE flag to be set in the buftarg. Once that's done,
849 * instruct the disks to persist their write caches.
851 libxfs_bcache_flush();
853 /* Flush all kernel and disk write caches, and report failures. */
854 if (mp
->m_ddev_targp
) {
855 err2
= libxfs_flush_buftarg(mp
->m_ddev_targp
, _("data device"));
860 if (mp
->m_logdev_targp
&& mp
->m_logdev_targp
!= mp
->m_ddev_targp
) {
861 err2
= libxfs_flush_buftarg(mp
->m_logdev_targp
,
867 if (mp
->m_rtdev_targp
) {
868 err2
= libxfs_flush_buftarg(mp
->m_rtdev_targp
,
869 _("realtime device"));
878 * Release any resource obtained during a mount.
882 struct xfs_mount
*mp
)
886 libxfs_rtmount_destroy(mp
);
889 * Purge the buffer cache to write all dirty buffers to disk and free
890 * all incore buffers, then pick up the outcome when we tell the disks
891 * to persist their write caches.
893 libxfs_bcache_purge();
894 error
= libxfs_flush_mount(mp
);
897 * Only try to free the per-AG structures if we set them up in the
900 if (xfs_is_perag_data_loaded(mp
))
901 libxfs_free_perag(mp
);
903 kmem_free(mp
->m_attr_geo
);
904 kmem_free(mp
->m_dir_geo
);
906 kmem_free(mp
->m_rtdev_targp
);
907 if (mp
->m_logdev_targp
!= mp
->m_ddev_targp
)
908 kmem_free(mp
->m_logdev_targp
);
909 kmem_free(mp
->m_ddev_targp
);
915 * Release any global resources used by libxfs.
919 struct libxfs_init
*li
)
923 libxfs_close_devices(li
);
925 /* Free everything from the buffer cache before freeing buffer cache */
926 libxfs_bcache_purge();
927 libxfs_bcache_free();
928 cache_destroy(libxfs_bcache
);
929 leaked
= destroy_caches();
930 rcu_unregister_thread();
931 if (getenv("LIBXFS_LEAK_CHECK") && leaked
)
936 libxfs_device_alignment(void)
938 return platform_align_blockdev();
942 libxfs_report(FILE *fp
)
947 cache_report(fp
, "libxfs_bcache", libxfs_bcache
);
950 c
= asctime(localtime(&t
));
951 fprintf(fp
, "%s", c
);