]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/info.c
libxfs: remove the volname concept
[thirdparty/xfsprogs-dev.git] / db / info.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2018 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
5 */
6 #include "libxfs.h"
7 #include "command.h"
8 #include "init.h"
9 #include "output.h"
10 #include "libfrog/fsgeom.h"
11 #include "libfrog/logging.h"
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;
31
32 libxfs_fs_geometry(mp, &geo, XFS_FS_GEOM_MAX_STRUCT_VER);
33 xfs_report_geom(&geo, x.dname, x.logname, x.rtname);
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
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(
65 struct xfs_perag *pag)
66 {
67 struct xfs_buf *bp;
68 struct xfs_agf *agf;
69 xfs_agnumber_t agno = pag->pag_agno;
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
76 error = -libxfs_refcountbt_calc_reserves(mp, NULL, pag, &ask, &used);
77 if (error)
78 xfrog_perror(error, "refcountbt");
79 error = -libxfs_finobt_calc_reserves(pag, NULL, &ask, &used);
80 if (error)
81 xfrog_perror(error, "finobt");
82 error = -libxfs_rmapbt_calc_reserves(mp, NULL, pag, &ask, &used);
83 if (error)
84 xfrog_perror(error, "rmapbt");
85
86 error = -libxfs_read_agf(pag, NULL, 0, &bp);
87 if (error)
88 xfrog_perror(error, "AGF");
89 agf = bp->b_addr;
90 length = be32_to_cpu(agf->agf_length);
91 free = be32_to_cpu(agf->agf_freeblks) +
92 be32_to_cpu(agf->agf_flcount);
93 libxfs_buf_relse(bp);
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 {
107 struct xfs_perag *pag;
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
130 pag = libxfs_perag_get(mp, a);
131 print_agresv_info(pag);
132 libxfs_perag_put(pag);
133 }
134 return 0;
135 }
136
137 for_each_perag(mp, agno, pag)
138 print_agresv_info(pag);
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
155 void
156 info_init(void)
157 {
158 add_command(&info_cmd);
159 add_command(&agresv_cmd);
160 }