]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/logformat.c
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2015 Red Hat, Inc.
12 #include "logformat.h"
14 #define MAX_LSUNIT 256 * 1024 /* max log buf. size */
17 logformat_f(int argc
, char **argv
)
27 logversion
= xfs_sb_version_haslogv2(&mp
->m_sb
) ? 2 : 1;
29 while ((c
= getopt(argc
, argv
, "c:s:")) != EOF
) {
32 cycle
= strtol(optarg
, NULL
, 0);
34 dbprintf("invalid cycle\n");
39 lsunit
= strtol(optarg
, NULL
, 0);
41 * The log stripe unit must be block aligned and no
45 (lsunit
% mp
->m_sb
.sb_blocksize
||
46 (logversion
== 2 && lsunit
> MAX_LSUNIT
))) {
47 dbprintf("invalid log stripe unit\n");
52 dbprintf("invalid option\n");
58 * Check whether the log is dirty. This also determines the current log
59 * cycle if we have to use it by default below.
61 memset(mp
->m_log
, 0, sizeof(struct xlog
));
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
;
67 if (xfs_sb_version_hassector(&mp
->m_sb
))
68 mp
->m_log
->l_sectBBsize
<<= (mp
->m_sb
.sb_logsectlog
- BBSHIFT
);
69 mp
->m_log
->l_sectBBsize
= BTOBB(mp
->m_log
->l_sectBBsize
);
71 error
= xlog_find_tail(mp
->m_log
, &head_blk
, &tail_blk
);
73 dbprintf("could not find log head/tail\n");
76 if (head_blk
!= tail_blk
) {
78 "The log is dirty. Please mount to replay the log.\n"));
83 * Use the current cycle and/or log stripe unit if either is not
84 * provided by the user.
87 cycle
= mp
->m_log
->l_curr_cycle
;
89 lsunit
= mp
->m_sb
.sb_logsunit
;
91 dbprintf("Formatting the log to cycle %d, stripe unit %d bytes.\n",
93 error
= -libxfs_log_clear(mp
->m_logdev_targp
, NULL
,
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);
99 dbprintf("error formatting log - %d\n", error
);
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"
119 static const struct cmdinfo logformat_cmd
= {
122 .cfunc
= logformat_f
,
126 .args
= N_("[-c cycle] [-s sunit]"),
127 .oneline
= N_("reformat the log"),
128 .help
= logformat_help
,
137 add_command(&logformat_cmd
);
143 struct xfs_trans_res
*res
)
145 dbprintf(_("type %d logres %u logcount %d flags 0x%x\n"),
146 i
, res
->tr_logres
, res
->tr_logcount
, res
->tr_logflags
);
154 struct xfs_trans_res resv
;
155 struct xfs_trans_res
*res
;
156 struct xfs_trans_res
*end_res
;
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
);
163 libxfs_log_get_max_trans_res(mp
, &resv
);
164 print_logres(-1, &resv
);
174 " The 'logres' command prints information about all log reservation types.\n"
175 " This includes the reservation space, the intended transaction roll count,\n"
176 " and the reservation flags, if any.\n"
181 static const struct cmdinfo logres_cmd
= {
189 .oneline
= N_("dump log reservations"),
196 add_command(&logres_cmd
);