1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
|
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2018 Oracle. All Rights Reserved.
* Author: Darrick J. Wong <darrick.wong@oracle.com>
*/
#include "libxfs.h"
#include "command.h"
#include "init.h"
#include "output.h"
#include "libfrog/fsgeom.h"
#include "libfrog/logging.h"
static void
info_help(void)
{
dbprintf(_(
"\n"
" Pretty-prints the filesystem geometry as derived from the superblock.\n"
" The output has the same format as mkfs.xfs, xfs_info, and other utilities.\n"
"\n"
));
}
static int
info_f(
int argc,
char **argv)
{
struct xfs_fsop_geom geo;
libxfs_fs_geometry(mp, &geo, XFS_FS_GEOM_MAX_STRUCT_VER);
xfs_report_geom(&geo, x.data.name, x.log.name, x.rt.name);
return 0;
}
static const struct cmdinfo info_cmd = {
.name = "info",
.altname = "i",
.cfunc = info_f,
.argmin = 0,
.argmax = 0,
.canpush = 0,
.args = NULL,
.oneline = N_("pretty-print superblock info"),
.help = info_help,
};
static void
agresv_help(void)
{
dbprintf(_(
"\n"
" Print the size and per-AG reservation information some allocation groups.\n"
"\n"
" Specific allocation group numbers can be provided as command line arguments.\n"
" If no arguments are provided, all allocation groups are iterated.\n"
"\n"
));
}
static void
print_agresv_info(
struct xfs_perag *pag)
{
struct xfs_buf *bp;
struct xfs_agf *agf;
xfs_agnumber_t agno = pag_agno(pag);
xfs_extlen_t ask = 0;
xfs_extlen_t used = 0;
xfs_extlen_t free = 0;
xfs_extlen_t length = 0;
int error;
error = -libxfs_refcountbt_calc_reserves(mp, NULL, pag, &ask, &used);
if (error)
xfrog_perror(error, "refcountbt");
error = -libxfs_finobt_calc_reserves(pag, NULL, &ask, &used);
if (error)
xfrog_perror(error, "finobt");
error = -libxfs_rmapbt_calc_reserves(mp, NULL, pag, &ask, &used);
if (error)
xfrog_perror(error, "rmapbt");
error = -libxfs_read_agf(pag, NULL, 0, &bp);
if (error)
xfrog_perror(error, "AGF");
agf = bp->b_addr;
length = be32_to_cpu(agf->agf_length);
free = be32_to_cpu(agf->agf_freeblks) +
be32_to_cpu(agf->agf_flcount);
libxfs_buf_relse(bp);
printf("AG %d: length: %u free: %u reserved: %u used: %u",
agno, length, free, ask, used);
if (ask - used > free)
printf(" <not enough space>");
printf("\n");
}
static int
agresv_f(
int argc,
char **argv)
{
struct xfs_perag *pag = NULL;
int i;
if (argc > 1) {
for (i = 1; i < argc; i++) {
long a;
char *p;
errno = 0;
a = strtol(argv[i], &p, 0);
if (p == argv[i])
errno = ERANGE;
if (errno) {
perror(argv[i]);
continue;
}
if (a < 0 || a >= mp->m_sb.sb_agcount) {
fprintf(stderr, "%ld: Not a AG.\n", a);
continue;
}
pag = libxfs_perag_get(mp, a);
print_agresv_info(pag);
libxfs_perag_put(pag);
}
return 0;
}
while ((pag = xfs_perag_next(mp, pag)))
print_agresv_info(pag);
return 0;
}
static const struct cmdinfo agresv_cmd = {
.name = "agresv",
.altname = NULL,
.cfunc = agresv_f,
.argmin = 0,
.argmax = -1,
.canpush = 0,
.args = NULL,
.oneline = N_("print AG reservation stats"),
.help = agresv_help,
};
static void
rgresv_help(void)
{
dbprintf(_(
"\n"
" Print the size and per-rtgroup reservation information for some realtime allocation groups.\n"
"\n"
" Specific realtime allocation group numbers can be provided as command line\n"
" arguments. If no arguments are provided, all allocation groups are iterated.\n"
"\n"
));
}
static void
print_rgresv_info(
struct xfs_rtgroup *rtg)
{
struct xfs_trans *tp;
xfs_filblks_t ask = 0;
xfs_filblks_t used = 0;
int error;
tp = libxfs_trans_alloc_empty(mp);
error = -libxfs_rtginode_load_parent(tp);
if (error) {
dbprintf(_("Cannot load realtime metadir, error %d\n"),
error);
goto out_trans;
}
/* rtrmapbt */
error = -libxfs_rtginode_load(rtg, XFS_RTGI_RMAP, tp);
if (error) {
dbprintf(_("Cannot load rtgroup %u rmap inode, error %d\n"),
rtg_rgno(rtg), error);
goto out_rele_dp;
}
if (rtg_rmap(rtg))
used += rtg_rmap(rtg)->i_nblocks;
libxfs_rtginode_irele(&rtg->rtg_inodes[XFS_RTGI_RMAP]);
ask += libxfs_rtrmapbt_calc_reserves(mp);
/* rtrefcount */
error = -libxfs_rtginode_load(rtg, XFS_RTGI_REFCOUNT, tp);
if (error) {
dbprintf(_("Cannot load rtgroup %u refcount inode, error %d\n"),
rtg_rgno(rtg), error);
goto out_rele_dp;
}
if (rtg_refcount(rtg))
used += rtg_refcount(rtg)->i_nblocks;
libxfs_rtginode_irele(&rtg->rtg_inodes[XFS_RTGI_REFCOUNT]);
ask += libxfs_rtrefcountbt_calc_reserves(mp);
printf(_("rtg %d: dblocks: %llu fdblocks: %llu reserved: %llu used: %llu"),
rtg_rgno(rtg),
(unsigned long long)mp->m_sb.sb_dblocks,
(unsigned long long)mp->m_sb.sb_fdblocks,
(unsigned long long)ask,
(unsigned long long)used);
if (ask - used > mp->m_sb.sb_fdblocks)
printf(_(" <not enough space>"));
printf("\n");
out_rele_dp:
libxfs_rtginode_irele(&mp->m_rtdirip);
out_trans:
libxfs_trans_cancel(tp);
}
static int
rgresv_f(
int argc,
char **argv)
{
struct xfs_rtgroup *rtg = NULL;
int i;
if (argc > 1) {
for (i = 1; i < argc; i++) {
long a;
char *p;
errno = 0;
a = strtol(argv[i], &p, 0);
if (p == argv[i])
errno = ERANGE;
if (errno) {
perror(argv[i]);
continue;
}
if (a < 0 || a >= mp->m_sb.sb_rgcount) {
fprintf(stderr, "%ld: Not a rtgroup.\n", a);
continue;
}
rtg = libxfs_rtgroup_get(mp, a);
print_rgresv_info(rtg);
libxfs_rtgroup_put(rtg);
}
return 0;
}
while ((rtg = xfs_rtgroup_next(mp, rtg)))
print_rgresv_info(rtg);
return 0;
}
static const struct cmdinfo rgresv_cmd = {
.name = "rgresv",
.altname = NULL,
.cfunc = rgresv_f,
.argmin = 0,
.argmax = -1,
.canpush = 0,
.args = NULL,
.oneline = N_("print rtgroup reservation stats"),
.help = rgresv_help,
};
void
info_init(void)
{
add_command(&info_cmd);
add_command(&agresv_cmd);
add_command(&rgresv_cmd);
}
|