]>
Commit | Line | Data |
---|---|---|
959ef981 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
172793ee DW |
2 | /* |
3 | * Copyright (C) 2018 Oracle. All Rights Reserved. | |
172793ee | 4 | * Author: Darrick J. Wong <darrick.wong@oracle.com> |
172793ee DW |
5 | */ |
6 | #include "libxfs.h" | |
7 | #include "command.h" | |
8 | #include "init.h" | |
9 | #include "output.h" | |
fee68490 | 10 | #include "libfrog/fsgeom.h" |
09385584 | 11 | #include "libfrog/logging.h" |
172793ee DW |
12 | |
13 | static void | |
14 | info_help(void) | |
15 | { | |
16 | dbprintf(_( | |
17 | "\n" | |
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" | |
20 | "\n" | |
21 | )); | |
22 | ||
23 | } | |
24 | ||
25 | static int | |
26 | info_f( | |
27 | int argc, | |
28 | char **argv) | |
29 | { | |
30 | struct xfs_fsop_geom geo; | |
172793ee | 31 | |
fa25ff74 | 32 | libxfs_fs_geometry(mp, &geo, XFS_FS_GEOM_MAX_STRUCT_VER); |
732f5b90 | 33 | xfs_report_geom(&geo, x.dname, x.logname, x.rtname); |
172793ee DW |
34 | return 0; |
35 | } | |
36 | ||
37 | static const struct cmdinfo info_cmd = { | |
38 | .name = "info", | |
39 | .altname = "i", | |
40 | .cfunc = info_f, | |
41 | .argmin = 0, | |
42 | .argmax = 0, | |
43 | .canpush = 0, | |
44 | .args = NULL, | |
45 | .oneline = N_("pretty-print superblock info"), | |
46 | .help = info_help, | |
47 | }; | |
48 | ||
09385584 DW |
49 | static void |
50 | agresv_help(void) | |
51 | { | |
52 | dbprintf(_( | |
53 | "\n" | |
54 | " Print the size and per-AG reservation information some allocation groups.\n" | |
55 | "\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" | |
58 | "\n" | |
59 | )); | |
60 | ||
61 | } | |
62 | ||
63 | static void | |
64 | print_agresv_info( | |
b4c6731a | 65 | struct xfs_perag *pag) |
09385584 DW |
66 | { |
67 | struct xfs_buf *bp; | |
68 | struct xfs_agf *agf; | |
b4c6731a | 69 | xfs_agnumber_t agno = pag->pag_agno; |
09385584 DW |
70 | xfs_extlen_t ask = 0; |
71 | xfs_extlen_t used = 0; | |
72 | xfs_extlen_t free = 0; | |
73 | xfs_extlen_t length = 0; | |
74 | int error; | |
75 | ||
653f37bc | 76 | error = -libxfs_refcountbt_calc_reserves(mp, NULL, pag, &ask, &used); |
09385584 DW |
77 | if (error) |
78 | xfrog_perror(error, "refcountbt"); | |
87a02c9e | 79 | error = -libxfs_finobt_calc_reserves(pag, NULL, &ask, &used); |
09385584 DW |
80 | if (error) |
81 | xfrog_perror(error, "finobt"); | |
653f37bc | 82 | error = -libxfs_rmapbt_calc_reserves(mp, NULL, pag, &ask, &used); |
09385584 DW |
83 | if (error) |
84 | xfrog_perror(error, "rmapbt"); | |
85 | ||
c1030eda | 86 | error = -libxfs_read_agf(pag, NULL, 0, &bp); |
09385584 DW |
87 | if (error) |
88 | xfrog_perror(error, "AGF"); | |
0bc284c2 | 89 | agf = bp->b_addr; |
09385584 DW |
90 | length = be32_to_cpu(agf->agf_length); |
91 | free = be32_to_cpu(agf->agf_freeblks) + | |
92 | be32_to_cpu(agf->agf_flcount); | |
e02ba985 | 93 | libxfs_buf_relse(bp); |
09385584 DW |
94 | |
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>"); | |
99 | printf("\n"); | |
100 | } | |
101 | ||
102 | static int | |
103 | agresv_f( | |
104 | int argc, | |
105 | char **argv) | |
106 | { | |
b4c6731a | 107 | struct xfs_perag *pag; |
09385584 DW |
108 | xfs_agnumber_t agno; |
109 | int i; | |
110 | ||
111 | if (argc > 1) { | |
112 | for (i = 1; i < argc; i++) { | |
113 | long a; | |
114 | char *p; | |
115 | ||
116 | errno = 0; | |
117 | a = strtol(argv[i], &p, 0); | |
118 | if (p == argv[i]) | |
119 | errno = ERANGE; | |
120 | if (errno) { | |
121 | perror(argv[i]); | |
122 | continue; | |
123 | } | |
124 | ||
125 | if (a < 0 || a >= mp->m_sb.sb_agcount) { | |
126 | fprintf(stderr, "%ld: Not a AG.\n", a); | |
127 | continue; | |
128 | } | |
129 | ||
b4c6731a DW |
130 | pag = libxfs_perag_get(mp, a); |
131 | print_agresv_info(pag); | |
132 | libxfs_perag_put(pag); | |
09385584 DW |
133 | } |
134 | return 0; | |
135 | } | |
136 | ||
b4c6731a DW |
137 | for_each_perag(mp, agno, pag) |
138 | print_agresv_info(pag); | |
09385584 DW |
139 | |
140 | return 0; | |
141 | } | |
142 | ||
143 | static const struct cmdinfo agresv_cmd = { | |
144 | .name = "agresv", | |
145 | .altname = NULL, | |
146 | .cfunc = agresv_f, | |
147 | .argmin = 0, | |
148 | .argmax = -1, | |
149 | .canpush = 0, | |
150 | .args = NULL, | |
151 | .oneline = N_("print AG reservation stats"), | |
152 | .help = agresv_help, | |
153 | }; | |
154 | ||
172793ee DW |
155 | void |
156 | info_init(void) | |
157 | { | |
158 | add_command(&info_cmd); | |
09385584 | 159 | add_command(&agresv_cmd); |
172793ee | 160 | } |