1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
10 #include "libfrog/fsgeom.h"
11 #include "libfrog/logging.h"
18 " Pretty-prints the filesystem geometry as derived from the superblock.\n"
19 " The output has the same format as mkfs.xfs, xfs_info, and other utilities.\n"
30 struct xfs_fsop_geom geo
;
32 libxfs_fs_geometry(mp
, &geo
, XFS_FS_GEOM_MAX_STRUCT_VER
);
33 xfs_report_geom(&geo
, x
.dname
, x
.logname
, x
.rtname
);
37 static const struct cmdinfo info_cmd
= {
45 .oneline
= N_("pretty-print superblock info"),
54 " Print the size and per-AG reservation information some allocation groups.\n"
56 " Specific allocation group numbers can be provided as command line arguments.\n"
57 " If no arguments are provided, all allocation groups are iterated.\n"
65 struct xfs_perag
*pag
)
69 xfs_agnumber_t agno
= pag
->pag_agno
;
71 xfs_extlen_t used
= 0;
72 xfs_extlen_t free
= 0;
73 xfs_extlen_t length
= 0;
76 error
= -libxfs_refcountbt_calc_reserves(mp
, NULL
, pag
, &ask
, &used
);
78 xfrog_perror(error
, "refcountbt");
79 error
= -libxfs_finobt_calc_reserves(pag
, NULL
, &ask
, &used
);
81 xfrog_perror(error
, "finobt");
82 error
= -libxfs_rmapbt_calc_reserves(mp
, NULL
, pag
, &ask
, &used
);
84 xfrog_perror(error
, "rmapbt");
86 error
= -libxfs_read_agf(pag
, NULL
, 0, &bp
);
88 xfrog_perror(error
, "AGF");
90 length
= be32_to_cpu(agf
->agf_length
);
91 free
= be32_to_cpu(agf
->agf_freeblks
) +
92 be32_to_cpu(agf
->agf_flcount
);
95 printf("AG %d: length: %u free: %u reserved: %u used: %u",
96 agno
, length
, free
, ask
, used
);
97 if (ask
- used
> free
)
98 printf(" <not enough space>");
107 struct xfs_perag
*pag
;
112 for (i
= 1; i
< argc
; i
++) {
117 a
= strtol(argv
[i
], &p
, 0);
125 if (a
< 0 || a
>= mp
->m_sb
.sb_agcount
) {
126 fprintf(stderr
, "%ld: Not a AG.\n", a
);
130 pag
= libxfs_perag_get(mp
, a
);
131 print_agresv_info(pag
);
132 libxfs_perag_put(pag
);
137 for_each_perag(mp
, agno
, pag
)
138 print_agresv_info(pag
);
143 static const struct cmdinfo agresv_cmd
= {
151 .oneline
= N_("print AG reservation stats"),
158 add_command(&info_cmd
);
159 add_command(&agresv_cmd
);