]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - scrub/fscounters.c
1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
9 #include <sys/statvfs.h>
10 #include "platform_defs.h"
12 #include "libfrog/paths.h"
13 #include "libfrog/workqueue.h"
14 #include "xfs_scrub.h"
16 #include "fscounters.h"
17 #include "libfrog/bulkstat.h"
20 * Filesystem counter collection routines. We can count the number of
21 * inodes in the filesystem, and we can estimate the block counters.
24 /* Count the number of inodes in the filesystem. */
26 /* INUMBERS wrapper routines. */
33 * Count the number of inodes. Use INUMBERS to figure out how many inodes
34 * exist in the filesystem, assuming we've already scrubbed that.
42 struct count_inodes
*ci
= arg
;
43 struct scrub_ctx
*ctx
= (struct scrub_ctx
*)wq
->wq_ctx
;
44 struct xfs_inumbers_req
*ireq
;
49 error
= -xfrog_inumbers_alloc_req(64, 0, &ireq
);
54 xfrog_inumbers_set_ag(ireq
, agno
);
56 while (!ci
->error
&& (error
= -xfrog_inumbers(&ctx
->mnt
, ireq
)) == 0) {
57 if (ireq
->hdr
.ocount
== 0)
59 for (i
= 0; i
< ireq
->hdr
.ocount
; i
++)
60 nr
+= ireq
->inumbers
[i
].xi_alloccount
;
67 ci
->counters
[agno
] = nr
;
71 * Count all the inodes in a filesystem. Returns 0 or a positive error number.
74 scrub_count_all_inodes(
75 struct scrub_ctx
*ctx
,
78 struct count_inodes
*ci
;
83 ci
= calloc(1, sizeof(struct count_inodes
) +
84 (ctx
->mnt
.fsgeom
.agcount
* sizeof(uint64_t)));
88 ret
= -workqueue_create(&wq
, (struct xfs_mount
*)ctx
,
89 scrub_nproc_workqueue(ctx
));
93 for (agno
= 0; agno
< ctx
->mnt
.fsgeom
.agcount
&& !ci
->error
; agno
++) {
94 ret
= -workqueue_add(&wq
, count_ag_inodes
, agno
, ci
);
99 ret2
= -workqueue_terminate(&wq
);
102 workqueue_destroy(&wq
);
109 for (agno
= 0; agno
< ctx
->mnt
.fsgeom
.agcount
; agno
++)
110 *count
+= ci
->counters
[agno
];
118 * Estimate the number of blocks and used inodes in the filesystem. Returns 0
119 * or a positive error number.
122 scrub_scan_estimate_blocks(
123 struct scrub_ctx
*ctx
,
124 unsigned long long *d_blocks
,
125 unsigned long long *d_bfree
,
126 unsigned long long *r_blocks
,
127 unsigned long long *r_bfree
,
128 unsigned long long *f_files_used
)
130 struct xfs_fsop_counts fc
;
133 /* Fetch the filesystem counters. */
134 error
= ioctl(ctx
->mnt
.fd
, XFS_IOC_FSCOUNTS
, &fc
);
138 *d_blocks
= ctx
->mnt
.fsgeom
.datablocks
;
139 *d_bfree
= fc
.freedata
;
140 *r_blocks
= ctx
->mnt
.fsgeom
.rtblocks
;
141 *r_bfree
= fc
.freertx
;
142 *f_files_used
= fc
.allocino
- fc
.freeino
;