]>
Commit | Line | Data |
---|---|---|
959ef981 | 1 | // SPDX-License-Identifier: GPL-2.0 |
c7a8ea47 BF |
2 | /* |
3 | * Copyright (c) 2015 Red Hat, Inc. | |
4 | * All Rights Reserved. | |
c7a8ea47 BF |
5 | */ |
6 | ||
7 | #include "libxfs.h" | |
8 | #include "command.h" | |
9 | #include "init.h" | |
10 | #include "output.h" | |
11 | #include "libxlog.h" | |
4a87b332 | 12 | #include "logformat.h" |
c7a8ea47 BF |
13 | |
14 | #define MAX_LSUNIT 256 * 1024 /* max log buf. size */ | |
15 | ||
16 | static int | |
17 | logformat_f(int argc, char **argv) | |
18 | { | |
19 | xfs_daddr_t head_blk; | |
20 | xfs_daddr_t tail_blk; | |
21 | int logversion; | |
22 | int lsunit = -1; | |
23 | int cycle = -1; | |
24 | int error; | |
25 | int c; | |
26 | ||
2660e653 | 27 | logversion = xfs_has_logv2(mp) ? 2 : 1; |
c7a8ea47 BF |
28 | |
29 | while ((c = getopt(argc, argv, "c:s:")) != EOF) { | |
30 | switch (c) { | |
31 | case 'c': | |
32 | cycle = strtol(optarg, NULL, 0); | |
33 | if (cycle == 0) { | |
34 | dbprintf("invalid cycle\n"); | |
35 | return -1; | |
36 | } | |
37 | break; | |
38 | case 's': | |
39 | lsunit = strtol(optarg, NULL, 0); | |
40 | /* | |
41 | * The log stripe unit must be block aligned and no | |
42 | * larger than 256k. | |
43 | */ | |
44 | if (lsunit > 1 && | |
45 | (lsunit % mp->m_sb.sb_blocksize || | |
46 | (logversion == 2 && lsunit > MAX_LSUNIT))) { | |
47 | dbprintf("invalid log stripe unit\n"); | |
48 | return -1; | |
49 | } | |
50 | break; | |
51 | default: | |
52 | dbprintf("invalid option\n"); | |
53 | return -1; | |
54 | } | |
55 | } | |
56 | ||
57 | /* | |
58 | * Check whether the log is dirty. This also determines the current log | |
59 | * cycle if we have to use it by default below. | |
60 | */ | |
61 | memset(mp->m_log, 0, sizeof(struct xlog)); | |
62 | mp->m_log->l_mp = mp; | |
63 | mp->m_log->l_dev = mp->m_logdev_targp; | |
64 | mp->m_log->l_logBBsize = XFS_FSB_TO_BB(mp, mp->m_sb.sb_logblocks); | |
65 | mp->m_log->l_logBBstart = XFS_FSB_TO_DADDR(mp, mp->m_sb.sb_logstart); | |
66 | mp->m_log->l_sectBBsize = BBSIZE; | |
2660e653 | 67 | if (xfs_has_sector(mp)) |
c7a8ea47 BF |
68 | mp->m_log->l_sectBBsize <<= (mp->m_sb.sb_logsectlog - BBSHIFT); |
69 | mp->m_log->l_sectBBsize = BTOBB(mp->m_log->l_sectBBsize); | |
70 | ||
71 | error = xlog_find_tail(mp->m_log, &head_blk, &tail_blk); | |
72 | if (error) { | |
73 | dbprintf("could not find log head/tail\n"); | |
74 | return -1; | |
75 | } | |
76 | if (head_blk != tail_blk) { | |
77 | dbprintf(_( | |
78 | "The log is dirty. Please mount to replay the log.\n")); | |
79 | return -1; | |
80 | } | |
81 | ||
82 | /* | |
83 | * Use the current cycle and/or log stripe unit if either is not | |
84 | * provided by the user. | |
85 | */ | |
86 | if (cycle < 0) | |
87 | cycle = mp->m_log->l_curr_cycle; | |
88 | if (lsunit < 0) | |
89 | lsunit = mp->m_sb.sb_logsunit; | |
90 | ||
91 | dbprintf("Formatting the log to cycle %d, stripe unit %d bytes.\n", | |
92 | cycle, lsunit); | |
e2f60652 | 93 | error = -libxfs_log_clear(mp->m_logdev_targp, NULL, |
c7a8ea47 BF |
94 | mp->m_log->l_logBBstart, |
95 | mp->m_log->l_logBBsize, | |
96 | &mp->m_sb.sb_uuid, logversion, lsunit, | |
97 | XLOG_FMT, cycle, false); | |
98 | if (error) { | |
99 | dbprintf("error formatting log - %d\n", error); | |
100 | return error; | |
101 | } | |
102 | ||
103 | return 0; | |
104 | } | |
105 | ||
106 | static void | |
107 | logformat_help(void) | |
108 | { | |
109 | dbprintf(_( | |
110 | "\n" | |
111 | " The 'logformat' command reformats (clears) the log to the specified log\n" | |
112 | " cycle and log stripe unit. If the log cycle is not specified, the log is\n" | |
113 | " reformatted to the current cycle. If the log stripe unit is not specified,\n" | |
114 | " the stripe unit from the filesystem superblock is used.\n" | |
115 | "\n" | |
116 | )); | |
117 | } | |
118 | ||
119 | static const struct cmdinfo logformat_cmd = { | |
120 | .name = "logformat", | |
121 | .altname = NULL, | |
122 | .cfunc = logformat_f, | |
123 | .argmin = 0, | |
124 | .argmax = 4, | |
125 | .canpush = 0, | |
126 | .args = N_("[-c cycle] [-s sunit]"), | |
127 | .oneline = N_("reformat the log"), | |
128 | .help = logformat_help, | |
129 | }; | |
130 | ||
131 | void | |
132 | logformat_init(void) | |
133 | { | |
134 | if (!expert_mode) | |
135 | return; | |
136 | ||
137 | add_command(&logformat_cmd); | |
138 | } | |
ad9ac929 DW |
139 | |
140 | static void | |
141 | print_logres( | |
142 | int i, | |
143 | struct xfs_trans_res *res) | |
144 | { | |
145 | dbprintf(_("type %d logres %u logcount %d flags 0x%x\n"), | |
146 | i, res->tr_logres, res->tr_logcount, res->tr_logflags); | |
147 | } | |
148 | ||
00ff2b10 | 149 | static int |
ad9ac929 DW |
150 | logres_f( |
151 | int argc, | |
152 | char **argv) | |
153 | { | |
154 | struct xfs_trans_res resv; | |
155 | struct xfs_trans_res *res; | |
156 | struct xfs_trans_res *end_res; | |
157 | int i; | |
158 | ||
159 | res = (struct xfs_trans_res *)M_RES(mp); | |
160 | end_res = (struct xfs_trans_res *)(M_RES(mp) + 1); | |
161 | for (i = 0; res < end_res; i++, res++) | |
162 | print_logres(i, res); | |
766bfbd7 | 163 | |
ad9ac929 | 164 | libxfs_log_get_max_trans_res(mp, &resv); |
766bfbd7 DW |
165 | dbprintf(_("minlogsize logres %u logcount %d\n"), |
166 | resv.tr_logres, resv.tr_logcount); | |
ad9ac929 DW |
167 | |
168 | return 0; | |
169 | } | |
170 | ||
171 | static void | |
172 | logres_help(void) | |
173 | { | |
174 | dbprintf(_( | |
175 | "\n" | |
176 | " The 'logres' command prints information about all log reservation types.\n" | |
177 | " This includes the reservation space, the intended transaction roll count,\n" | |
178 | " and the reservation flags, if any.\n" | |
179 | "\n" | |
180 | )); | |
181 | } | |
182 | ||
183 | static const struct cmdinfo logres_cmd = { | |
184 | .name = "logres", | |
185 | .altname = NULL, | |
186 | .cfunc = logres_f, | |
187 | .argmin = 0, | |
188 | .argmax = 0, | |
189 | .canpush = 0, | |
190 | .args = NULL, | |
191 | .oneline = N_("dump log reservations"), | |
192 | .help = logres_help, | |
193 | }; | |
194 | ||
195 | void | |
196 | logres_init(void) | |
197 | { | |
198 | add_command(&logres_cmd); | |
199 | } |