]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/logformat.c
2 * Copyright (c) 2015 Red Hat, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #define MAX_LSUNIT 256 * 1024 /* max log buf. size */
28 logformat_f(int argc
, char **argv
)
38 logversion
= xfs_sb_version_haslogv2(&mp
->m_sb
) ? 2 : 1;
40 while ((c
= getopt(argc
, argv
, "c:s:")) != EOF
) {
43 cycle
= strtol(optarg
, NULL
, 0);
45 dbprintf("invalid cycle\n");
50 lsunit
= strtol(optarg
, NULL
, 0);
52 * The log stripe unit must be block aligned and no
56 (lsunit
% mp
->m_sb
.sb_blocksize
||
57 (logversion
== 2 && lsunit
> MAX_LSUNIT
))) {
58 dbprintf("invalid log stripe unit\n");
63 dbprintf("invalid option\n");
69 * Check whether the log is dirty. This also determines the current log
70 * cycle if we have to use it by default below.
72 memset(mp
->m_log
, 0, sizeof(struct xlog
));
74 mp
->m_log
->l_dev
= mp
->m_logdev_targp
;
75 mp
->m_log
->l_logBBsize
= XFS_FSB_TO_BB(mp
, mp
->m_sb
.sb_logblocks
);
76 mp
->m_log
->l_logBBstart
= XFS_FSB_TO_DADDR(mp
, mp
->m_sb
.sb_logstart
);
77 mp
->m_log
->l_sectBBsize
= BBSIZE
;
78 if (xfs_sb_version_hassector(&mp
->m_sb
))
79 mp
->m_log
->l_sectBBsize
<<= (mp
->m_sb
.sb_logsectlog
- BBSHIFT
);
80 mp
->m_log
->l_sectBBsize
= BTOBB(mp
->m_log
->l_sectBBsize
);
82 error
= xlog_find_tail(mp
->m_log
, &head_blk
, &tail_blk
);
84 dbprintf("could not find log head/tail\n");
87 if (head_blk
!= tail_blk
) {
89 "The log is dirty. Please mount to replay the log.\n"));
94 * Use the current cycle and/or log stripe unit if either is not
95 * provided by the user.
98 cycle
= mp
->m_log
->l_curr_cycle
;
100 lsunit
= mp
->m_sb
.sb_logsunit
;
102 dbprintf("Formatting the log to cycle %d, stripe unit %d bytes.\n",
104 error
= -libxfs_log_clear(mp
->m_logdev_targp
, NULL
,
105 mp
->m_log
->l_logBBstart
,
106 mp
->m_log
->l_logBBsize
,
107 &mp
->m_sb
.sb_uuid
, logversion
, lsunit
,
108 XLOG_FMT
, cycle
, false);
110 dbprintf("error formatting log - %d\n", error
);
122 " The 'logformat' command reformats (clears) the log to the specified log\n"
123 " cycle and log stripe unit. If the log cycle is not specified, the log is\n"
124 " reformatted to the current cycle. If the log stripe unit is not specified,\n"
125 " the stripe unit from the filesystem superblock is used.\n"
130 static const struct cmdinfo logformat_cmd
= {
133 .cfunc
= logformat_f
,
137 .args
= N_("[-c cycle] [-s sunit]"),
138 .oneline
= N_("reformat the log"),
139 .help
= logformat_help
,
148 add_command(&logformat_cmd
);