]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - scrub/xfs_scrub.h
xfs_scrub: schedule and manage optimizations/repairs to the filesystem
[thirdparty/xfsprogs-dev.git] / scrub / xfs_scrub.h
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2018 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
5 */
6 #ifndef XFS_SCRUB_XFS_SCRUB_H_
7 #define XFS_SCRUB_XFS_SCRUB_H_
8
9 #define _PATH_PROC_MOUNTS "/proc/mounts"
10
11 extern unsigned int nr_threads;
12 extern unsigned int bg_mode;
13 extern unsigned int debug;
14 extern int nproc;
15 extern bool verbose;
16 extern long page_size;
17 extern bool want_fstrim;
18 extern bool stderr_isatty;
19 extern bool stdout_isatty;
20 extern bool is_service;
21
22 enum scrub_mode {
23 SCRUB_MODE_DRY_RUN,
24 SCRUB_MODE_REPAIR,
25 };
26
27 enum error_action {
28 ERRORS_CONTINUE,
29 ERRORS_SHUTDOWN,
30 };
31
32 struct scrub_ctx {
33 /* Immutable scrub state. */
34
35 /* Strings we need for presentation */
36 char *mntpoint;
37
38 /* Mountpoint info */
39 struct stat mnt_sb;
40 struct statvfs mnt_sv;
41 struct statfs mnt_sf;
42
43 /* Open block devices */
44 struct disk *datadev;
45 struct disk *logdev;
46 struct disk *rtdev;
47
48 /* What does the user want us to do? */
49 enum scrub_mode mode;
50
51 /* How does the user want us to react to errors? */
52 enum error_action error_action;
53
54 /* fd to filesystem mount point */
55 int mnt_fd;
56
57 /* Number of threads for metadata scrubbing */
58 unsigned int nr_io_threads;
59
60 /* XFS specific geometry */
61 struct xfs_fsop_geom geo;
62 struct fs_path fsinfo;
63 unsigned int agblklog;
64 unsigned int blocklog;
65 unsigned int inodelog;
66 unsigned int inopblog;
67 void *fshandle;
68 size_t fshandle_len;
69
70 /* Data block read verification buffer */
71 void *readbuf;
72
73 /* Mutable scrub state; use lock. */
74 pthread_mutex_t lock;
75 struct xfs_action_list *action_lists;
76 unsigned long long max_errors;
77 unsigned long long runtime_errors;
78 unsigned long long errors_found;
79 unsigned long long warnings_found;
80 unsigned long long inodes_checked;
81 unsigned long long bytes_checked;
82 unsigned long long naming_warnings;
83 unsigned long long repairs;
84 unsigned long long preens;
85 bool scrub_setup_succeeded;
86 bool preen_triggers[XFS_SCRUB_TYPE_NR];
87 };
88
89 /* Phase helper functions */
90 void xfs_shutdown_fs(struct scrub_ctx *ctx);
91 bool xfs_cleanup_fs(struct scrub_ctx *ctx);
92 bool xfs_setup_fs(struct scrub_ctx *ctx);
93 bool xfs_scan_metadata(struct scrub_ctx *ctx);
94 bool xfs_scan_inodes(struct scrub_ctx *ctx);
95 bool xfs_scan_connections(struct scrub_ctx *ctx);
96 bool xfs_scan_blocks(struct scrub_ctx *ctx);
97 bool xfs_scan_summary(struct scrub_ctx *ctx);
98 bool xfs_repair_fs(struct scrub_ctx *ctx);
99
100 /* Progress estimator functions */
101 uint64_t xfs_estimate_inodes(struct scrub_ctx *ctx);
102 unsigned int xfs_scrub_estimate_ag_work(struct scrub_ctx *ctx);
103 bool xfs_estimate_metadata_work(struct scrub_ctx *ctx, uint64_t *items,
104 unsigned int *nr_threads, int *rshift);
105 bool xfs_estimate_inodes_work(struct scrub_ctx *ctx, uint64_t *items,
106 unsigned int *nr_threads, int *rshift);
107 bool xfs_estimate_repair_work(struct scrub_ctx *ctx, uint64_t *items,
108 unsigned int *nr_threads, int *rshift);
109 bool xfs_estimate_verify_work(struct scrub_ctx *ctx, uint64_t *items,
110 unsigned int *nr_threads, int *rshift);
111
112 #endif /* XFS_SCRUB_XFS_SCRUB_H_ */