]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxlog/util.c
xfs_scrub: remove moveon from progress report helpers
[thirdparty/xfsprogs-dev.git] / libxlog / util.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2000-2001,2004-2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6
7 #include "libxfs.h"
8 #include "libxlog.h"
9
10 int print_exit;
11 int print_skip_uuid;
12 int print_record_header;
13 libxfs_init_t x;
14
15 /*
16 * Return 1 for dirty, 0 for clean, -1 for errors
17 */
18 int
19 xlog_is_dirty(
20 struct xfs_mount *mp,
21 struct xlog *log,
22 libxfs_init_t *x,
23 int verbose)
24 {
25 int error;
26 xfs_daddr_t head_blk, tail_blk;
27
28 memset(log, 0, sizeof(*log));
29
30 /* We (re-)init members of libxfs_init_t here? really? */
31 x->logBBsize = XFS_FSB_TO_BB(mp, mp->m_sb.sb_logblocks);
32 x->logBBstart = XFS_FSB_TO_DADDR(mp, mp->m_sb.sb_logstart);
33 x->lbsize = BBSIZE;
34 if (xfs_sb_version_hassector(&mp->m_sb))
35 x->lbsize <<= (mp->m_sb.sb_logsectlog - BBSHIFT);
36
37 log->l_dev = mp->m_logdev_targp;
38 log->l_logBBsize = x->logBBsize;
39 log->l_logBBstart = x->logBBstart;
40 log->l_sectBBsize = BTOBB(x->lbsize);
41 log->l_mp = mp;
42 if (xfs_sb_version_hassector(&mp->m_sb)) {
43 log->l_sectbb_log = mp->m_sb.sb_logsectlog - BBSHIFT;
44 ASSERT(log->l_sectbb_log <= mp->m_sectbb_log);
45 /* for larger sector sizes, must have v2 or external log */
46 ASSERT(log->l_sectbb_log == 0 ||
47 log->l_logBBstart == 0 ||
48 xfs_sb_version_haslogv2(&mp->m_sb));
49 ASSERT(mp->m_sb.sb_logsectlog >= BBSHIFT);
50 }
51 log->l_sectbb_mask = (1 << log->l_sectbb_log) - 1;
52
53 error = xlog_find_tail(log, &head_blk, &tail_blk);
54 if (error) {
55 xlog_warn(_("%s: cannot find log head/tail "
56 "(xlog_find_tail=%d)\n"),
57 __func__, error);
58 return -1;
59 }
60
61 if (verbose)
62 xlog_warn(
63 _("%s: head block %" PRId64 " tail block %" PRId64 "\n"),
64 __func__, head_blk, tail_blk);
65
66 if (head_blk != tail_blk)
67 return 1;
68
69 return 0;
70 }
71
72 static int
73 header_check_uuid(xfs_mount_t *mp, xlog_rec_header_t *head)
74 {
75 char uu_log[64], uu_sb[64];
76
77 if (print_skip_uuid)
78 return 0;
79 if (!platform_uuid_compare(&mp->m_sb.sb_uuid, &head->h_fs_uuid))
80 return 0;
81
82 platform_uuid_unparse(&mp->m_sb.sb_uuid, uu_sb);
83 platform_uuid_unparse(&head->h_fs_uuid, uu_log);
84
85 printf(_("* ERROR: mismatched uuid in log\n"
86 "* SB : %s\n* log: %s\n"),
87 uu_sb, uu_log);
88
89 memcpy(&mp->m_sb.sb_uuid, &head->h_fs_uuid, sizeof(uuid_t));
90
91 return 0;
92 }
93
94 int
95 xlog_header_check_recover(xfs_mount_t *mp, xlog_rec_header_t *head)
96 {
97 if (print_record_header)
98 printf(_("\nLOG REC AT LSN cycle %d block %d (0x%x, 0x%x)\n"),
99 CYCLE_LSN(be64_to_cpu(head->h_lsn)),
100 BLOCK_LSN(be64_to_cpu(head->h_lsn)),
101 CYCLE_LSN(be64_to_cpu(head->h_lsn)),
102 BLOCK_LSN(be64_to_cpu(head->h_lsn)));
103
104 if (be32_to_cpu(head->h_magicno) != XLOG_HEADER_MAGIC_NUM) {
105
106 printf(_("* ERROR: bad magic number in log header: 0x%x\n"),
107 be32_to_cpu(head->h_magicno));
108
109 } else if (header_check_uuid(mp, head)) {
110
111 /* failed - fall through */
112
113 } else if (be32_to_cpu(head->h_fmt) != XLOG_FMT) {
114
115 printf(_("* ERROR: log format incompatible (log=%d, ours=%d)\n"),
116 be32_to_cpu(head->h_fmt), XLOG_FMT);
117
118 } else {
119 /* everything is ok */
120 return 0;
121 }
122
123 /* bail out now or just carry on regardless */
124 if (print_exit)
125 xlog_exit(_("Bad log"));
126
127 return 0;
128 }
129
130 int
131 xlog_header_check_mount(xfs_mount_t *mp, xlog_rec_header_t *head)
132 {
133 if (platform_uuid_is_null(&head->h_fs_uuid)) return 0;
134 if (header_check_uuid(mp, head)) {
135 /* bail out now or just carry on regardless */
136 if (print_exit)
137 xlog_exit(_("Bad log"));
138 }
139 return 0;
140 }
141
142 /*
143 * Userspace versions of common diagnostic routines (varargs fun).
144 */
145 void
146 xlog_warn(char *fmt, ...)
147 {
148 va_list ap;
149
150 va_start(ap, fmt);
151 vfprintf(stderr, fmt, ap);
152 fputs("\n", stderr);
153 va_end(ap);
154 }
155
156 void
157 xlog_exit(char *fmt, ...)
158 {
159 va_list ap;
160
161 va_start(ap, fmt);
162 vfprintf(stderr, fmt, ap);
163 fputs("\n", stderr);
164 va_end(ap);
165 exit(1);
166 }
167
168 void
169 xlog_panic(char *fmt, ...)
170 {
171 va_list ap;
172
173 va_start(ap, fmt);
174 vfprintf(stderr, fmt, ap);
175 fputs("\n", stderr);
176 va_end(ap);
177 abort();
178 }