]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - scrub/common.h
xfs_scrub: handle scrub-only kernels more helpfully
[thirdparty/xfsprogs-dev.git] / scrub / common.h
CommitLineData
95b1e505
DW
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_COMMON_H_
21#define XFS_SCRUB_COMMON_H_
22
f0585fce
DW
23/*
24 * When reporting a defective metadata object to the console, this
25 * is the size of the buffer to use to store the description of that
26 * item.
27 */
28#define DESCR_BUFSZ 256
29
30bool xfs_scrub_excessive_errors(struct scrub_ctx *ctx);
31
32enum error_level {
33 S_ERROR = 0,
34 S_WARN,
19852474 35 S_REPAIR,
f0585fce 36 S_INFO,
19852474 37 S_PREEN,
f0585fce
DW
38};
39
40void __str_out(struct scrub_ctx *ctx, const char *descr, enum error_level level,
41 int error, const char *file, int line, const char *format, ...);
42
43#define str_errno(ctx, str) \
44 __str_out(ctx, str, S_ERROR, errno, __FILE__, __LINE__, NULL)
45#define str_error(ctx, str, ...) \
46 __str_out(ctx, str, S_ERROR, 0, __FILE__, __LINE__, __VA_ARGS__)
47#define str_warn(ctx, str, ...) \
48 __str_out(ctx, str, S_WARN, 0, __FILE__, __LINE__, __VA_ARGS__)
49#define str_info(ctx, str, ...) \
50 __str_out(ctx, str, S_INFO, 0, __FILE__, __LINE__, __VA_ARGS__)
19852474
DW
51#define record_repair(ctx, str, ...) \
52 __str_out(ctx, str, S_REPAIR, 0, __FILE__, __LINE__, __VA_ARGS__)
53#define record_preen(ctx, str, ...) \
54 __str_out(ctx, str, S_PREEN, 0, __FILE__, __LINE__, __VA_ARGS__)
f0585fce
DW
55
56#define dbg_printf(fmt, ...) \
57 do {if (debug > 1) {printf(fmt, __VA_ARGS__);}} while (0)
58
828105d1
DW
59/* Is this debug tweak enabled? */
60static inline bool
61debug_tweak_on(
62 const char *name)
63{
64 return debug && getenv(name) != NULL;
65}
66
173a0283
DW
67double timeval_subtract(struct timeval *tv1, struct timeval *tv2);
68double auto_space_units(unsigned long long kilobytes, char **units);
69double auto_units(unsigned long long number, char **units);
e031d90f
DW
70unsigned int scrub_nproc(struct scrub_ctx *ctx);
71unsigned int scrub_nproc_workqueue(struct scrub_ctx *ctx);
173a0283 72
50a573a7
DW
73#ifndef HAVE_SYNCFS
74static inline int syncfs(int fd)
75{
76 sync();
77 return 0;
78}
79#endif
80
81bool find_mountpoint(char *mtab, struct scrub_ctx *ctx);
fd7d73c0 82void background_sleep(void);
396cd022
DW
83char *string_escape(const char *in);
84
85#define TOO_MANY_NAME_WARNINGS 10000
86bool should_warn_about_name(struct scrub_ctx *ctx);
50a573a7 87
698c6c7c
DW
88bool within_range(struct scrub_ctx *ctx, unsigned long long value,
89 unsigned long long desired, unsigned long long abs_threshold,
90 unsigned int n, unsigned int d, const char *descr);
91
95b1e505 92#endif /* XFS_SCRUB_COMMON_H_ */