]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - scrub/xfs_scrub.h
47d63de57d688c6e11eee31bcd3c0a25893a1f1e
[thirdparty/xfsprogs-dev.git] / scrub / xfs_scrub.h
1 /*
2 * Copyright (C) 2018 Oracle. All Rights Reserved.
3 *
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it would be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20 #ifndef XFS_SCRUB_XFS_SCRUB_H_
21 #define XFS_SCRUB_XFS_SCRUB_H_
22
23 #define _PATH_PROC_MOUNTS "/proc/mounts"
24
25 extern unsigned int nr_threads;
26 extern unsigned int bg_mode;
27 extern unsigned int debug;
28 extern int nproc;
29 extern bool verbose;
30 extern long page_size;
31 extern bool want_fstrim;
32
33 enum scrub_mode {
34 SCRUB_MODE_DRY_RUN,
35 SCRUB_MODE_PREEN,
36 SCRUB_MODE_REPAIR,
37 };
38 #define SCRUB_MODE_DEFAULT SCRUB_MODE_PREEN
39
40 enum error_action {
41 ERRORS_CONTINUE,
42 ERRORS_SHUTDOWN,
43 };
44
45 struct scrub_ctx {
46 /* Immutable scrub state. */
47
48 /* Strings we need for presentation */
49 char *mntpoint;
50 char *blkdev;
51
52 /* Mountpoint info */
53 struct stat mnt_sb;
54 struct statvfs mnt_sv;
55 struct statfs mnt_sf;
56
57 /* Open block devices */
58 struct disk *datadev;
59 struct disk *logdev;
60 struct disk *rtdev;
61
62 /* What does the user want us to do? */
63 enum scrub_mode mode;
64
65 /* How does the user want us to react to errors? */
66 enum error_action error_action;
67
68 /* fd to filesystem mount point */
69 int mnt_fd;
70
71 /* Number of threads for metadata scrubbing */
72 unsigned int nr_io_threads;
73
74 /* XFS specific geometry */
75 struct xfs_fsop_geom geo;
76 struct fs_path fsinfo;
77 unsigned int agblklog;
78 unsigned int blocklog;
79 unsigned int inodelog;
80 unsigned int inopblog;
81 void *fshandle;
82 size_t fshandle_len;
83
84 /* Data block read verification buffer */
85 void *readbuf;
86
87 /* Mutable scrub state; use lock. */
88 pthread_mutex_t lock;
89 unsigned long long max_errors;
90 unsigned long long runtime_errors;
91 unsigned long long errors_found;
92 unsigned long long warnings_found;
93 unsigned long long inodes_checked;
94 unsigned long long bytes_checked;
95 unsigned long long naming_warnings;
96 bool need_repair;
97 bool preen_triggers[XFS_SCRUB_TYPE_NR];
98 };
99
100 /* Phase helper functions */
101 void xfs_shutdown_fs(struct scrub_ctx *ctx);
102 bool xfs_cleanup_fs(struct scrub_ctx *ctx);
103 bool xfs_setup_fs(struct scrub_ctx *ctx);
104 bool xfs_scan_metadata(struct scrub_ctx *ctx);
105 bool xfs_scan_inodes(struct scrub_ctx *ctx);
106 bool xfs_scan_connections(struct scrub_ctx *ctx);
107 bool xfs_scan_blocks(struct scrub_ctx *ctx);
108 bool xfs_scan_summary(struct scrub_ctx *ctx);
109 bool xfs_repair_fs(struct scrub_ctx *ctx);
110 bool xfs_optimize_fs(struct scrub_ctx *ctx);
111
112 #endif /* XFS_SCRUB_XFS_SCRUB_H_ */