]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - scrub/common.c
2 * Copyright (C) 2018 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
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.
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.
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.
23 #include "platform_defs.h"
25 #include "xfs_scrub.h"
29 * Reporting Status to the Console
31 * We aim for a roughly standard reporting format -- the severity of the
32 * status being reported, a textual description of the object being
33 * reported, and whatever the status happens to be.
35 * Errors are the most severe and reflect filesystem corruption.
36 * Warnings indicate that something is amiss and needs the attention of
37 * the administrator, but does not constitute a corruption. Information
41 /* Too many errors? Bail out. */
43 xfs_scrub_excessive_errors(
44 struct scrub_ctx
*ctx
)
48 pthread_mutex_lock(&ctx
->lock
);
49 ret
= ctx
->max_errors
> 0 && ctx
->errors_found
>= ctx
->max_errors
;
50 pthread_mutex_unlock(&ctx
->lock
);
55 static const char *err_str
[] = {
61 /* Print a warning string and some warning text. */
64 struct scrub_ctx
*ctx
,
66 enum error_level level
,
73 FILE *stream
= stderr
;
75 char buf
[DESCR_BUFSZ
];
77 /* print strerror or format of choice but not both */
78 assert(!(error
&& format
));
83 pthread_mutex_lock(&ctx
->lock
);
84 fprintf(stream
, "%s: %s: ", _(err_str
[level
]), descr
);
86 fprintf(stream
, _("%s."), strerror_r(error
, buf
, DESCR_BUFSZ
));
88 va_start(args
, format
);
89 vfprintf(stream
, format
, args
);
94 fprintf(stream
, _(" (%s line %d)"), file
, line
);
95 fprintf(stream
, "\n");
99 if (error
) /* A syscall failed */
100 ctx
->runtime_errors
++;
101 else if (level
== S_ERROR
)
103 else if (level
== S_WARN
)
104 ctx
->warnings_found
++;
106 pthread_mutex_unlock(&ctx
->lock
);
114 return ((tv1
->tv_sec
- tv2
->tv_sec
) +
115 ((float) (tv1
->tv_usec
- tv2
->tv_usec
)) / 1000000);
118 /* Produce human readable disk space output. */
121 unsigned long long bytes
,
126 if (bytes
> (1ULL << 40)) {
128 return (double)bytes
/ (1ULL << 40);
129 } else if (bytes
> (1ULL << 30)) {
131 return (double)bytes
/ (1ULL << 30);
132 } else if (bytes
> (1ULL << 20)) {
134 return (double)bytes
/ (1ULL << 20);
135 } else if (bytes
> (1ULL << 10)) {
137 return (double)bytes
/ (1ULL << 10);
145 /* Produce human readable discrete number output. */
148 unsigned long long number
,
153 if (number
> 1000000000000ULL) {
155 return number
/ 1000000000000.0;
156 } else if (number
> 1000000000ULL) {
158 return number
/ 1000000000.0;
159 } else if (number
> 1000000ULL) {
161 return number
/ 1000000.0;
162 } else if (number
> 1000ULL) {
164 return number
/ 1000.0;