Branch data Line data Source code
1 : : /*
2 : : * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3 : : * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
4 : : *
5 : : * This file is part of LVM2.
6 : : *
7 : : * This copyrighted material is made available to anyone wishing to use,
8 : : * modify, copy, or redistribute it subject to the terms and conditions
9 : : * of the GNU Lesser General Public License v.2.1.
10 : : *
11 : : * You should have received a copy of the GNU Lesser General Public License
12 : : * along with this program; if not, write to the Free Software Foundation,
13 : : * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 : : */
15 : :
16 : : #include "tools.h"
17 : :
18 : : int pv_max_name_len = 0;
19 : : int vg_max_name_len = 0;
20 : :
21 : 0 : static void _pvscan_display_single(struct cmd_context *cmd,
22 : : struct physical_volume *pv,
23 : : void *handle __attribute((unused)))
24 : : {
25 : : char uuid[64] __attribute((aligned(8)));
26 : 0 : unsigned vg_name_len = 0;
27 : :
28 : 0 : char pv_tmp_name[NAME_LEN] = { 0, };
29 : 0 : char vg_tmp_name[NAME_LEN] = { 0, };
30 : 0 : char vg_name_this[NAME_LEN] = { 0, };
31 : :
32 : : /* short listing? */
33 [ # # ]: 0 : if (arg_count(cmd, short_ARG) > 0) {
34 : 0 : log_print("%s", pv_dev_name(pv));
35 : 0 : return;
36 : : }
37 : :
38 : 0 : if (arg_count(cmd, verbose_ARG) > 1) {
39 : : /* FIXME As per pv_display! Drop through for now. */
40 : : /* pv_show(pv); */
41 : :
42 : : /* FIXME - Moved to Volume Group structure */
43 : : /* log_print("System Id %s", pv->vg->system_id); */
44 : :
45 : : /* log_print(" "); */
46 : : /* return; */
47 : : }
48 : :
49 : 0 : memset(pv_tmp_name, 0, sizeof(pv_tmp_name));
50 : :
51 : 0 : vg_name_len = strlen(pv_vg_name(pv)) + 1;
52 : :
53 [ # # ]: 0 : if (arg_count(cmd, uuid_ARG)) {
54 [ # # ]: 0 : if (!id_write_format(&pv->id, uuid, sizeof(uuid))) {
55 : 0 : stack;
56 : 0 : return;
57 : : }
58 : :
59 : 0 : sprintf(pv_tmp_name, "%-*s with UUID %s",
60 : : pv_max_name_len - 2, pv_dev_name(pv), uuid);
61 : : } else {
62 : 0 : sprintf(pv_tmp_name, "%s", pv_dev_name(pv));
63 : : }
64 : :
65 [ # # ]: 0 : if (is_orphan(pv)) {
66 [ # # ]: 0 : log_print("PV %-*s %-*s %s [%s]",
67 : : pv_max_name_len, pv_tmp_name,
68 : : vg_max_name_len, " ",
69 : : pv->fmt ? pv->fmt->name : " ",
70 : : display_size(cmd, pv_size(pv)));
71 : 0 : return;
72 : : }
73 : :
74 [ # # ]: 0 : if (pv_status(pv) & EXPORTED_VG) {
75 : 0 : strncpy(vg_name_this, pv_vg_name(pv), vg_name_len);
76 : 0 : log_print("PV %-*s is in exported VG %s "
77 : : "[%s / %s free]",
78 : : pv_max_name_len, pv_tmp_name,
79 : : vg_name_this,
80 : : display_size(cmd, (uint64_t) pv_pe_count(pv) *
81 : : pv_pe_size(pv)),
82 : : display_size(cmd, (uint64_t) (pv_pe_count(pv) -
83 : : pv_pe_alloc_count(pv))
84 : : * pv_pe_size(pv)));
85 : 0 : return;
86 : : }
87 : :
88 : 0 : sprintf(vg_tmp_name, "%s", pv_vg_name(pv));
89 [ # # ]: 0 : log_print("PV %-*s VG %-*s %s [%s / %s free]", pv_max_name_len,
90 : : pv_tmp_name, vg_max_name_len, vg_tmp_name,
91 : : pv->fmt ? pv->fmt->name : " ",
92 : : display_size(cmd, (uint64_t) pv_pe_count(pv) *
93 : : pv_pe_size(pv)),
94 : : display_size(cmd, (uint64_t) (pv_pe_count(pv) -
95 : : pv_pe_alloc_count(pv)) *
96 : : pv_pe_size(pv)));
97 : : }
98 : :
99 : 0 : int pvscan(struct cmd_context *cmd, int argc __attribute((unused)),
100 : : char **argv __attribute((unused)))
101 : : {
102 : 0 : int new_pvs_found = 0;
103 : 0 : int pvs_found = 0;
104 : :
105 : : struct dm_list *pvslist;
106 : : struct pv_list *pvl;
107 : : struct physical_volume *pv;
108 : :
109 : 0 : uint64_t size_total = 0;
110 : 0 : uint64_t size_new = 0;
111 : :
112 : 0 : int len = 0;
113 : 0 : pv_max_name_len = 0;
114 : 0 : vg_max_name_len = 0;
115 : :
116 [ # # ][ # # ]: 0 : if (arg_count(cmd, novolumegroup_ARG) && arg_count(cmd, exported_ARG)) {
117 : 0 : log_error("Options -e and -n are incompatible");
118 : 0 : return EINVALID_CMD_LINE;
119 : : }
120 : :
121 [ # # ][ # # ]: 0 : if (arg_count(cmd, exported_ARG) || arg_count(cmd, novolumegroup_ARG))
122 [ # # ]: 0 : log_warn("WARNING: only considering physical volumes %s",
123 : : arg_count(cmd, exported_ARG) ?
124 : : "of exported volume group(s)" : "in no volume group");
125 : :
126 [ # # ]: 0 : if (!lock_vol(cmd, VG_GLOBAL, LCK_VG_WRITE)) {
127 : 0 : log_error("Unable to obtain global lock.");
128 : 0 : return ECMD_FAILED;
129 : : }
130 : :
131 : 0 : persistent_filter_wipe(cmd->filter);
132 : 0 : lvmcache_destroy(cmd, 1);
133 : :
134 : 0 : log_verbose("Walking through all physical volumes");
135 [ # # ]: 0 : if (!(pvslist = get_pvs(cmd))) {
136 : 0 : unlock_vg(cmd, VG_GLOBAL);
137 : 0 : stack;
138 : 0 : return ECMD_FAILED;
139 : : }
140 : :
141 : : /* eliminate exported/new if required */
142 [ # # ]: 0 : dm_list_iterate_items(pvl, pvslist) {
143 : 0 : pv = pvl->pv;
144 : :
145 [ # # # # # : 0 : if ((arg_count(cmd, exported_ARG)
# # # ]
146 : 0 : && !(pv_status(pv) & EXPORTED_VG))
147 : 0 : || (arg_count(cmd, novolumegroup_ARG) && (!is_orphan(pv)))) {
148 : 0 : dm_list_del(&pvl->list);
149 : 0 : continue;
150 : : }
151 : :
152 : : /* Also check for MD use? */
153 : : /*******
154 : : if (MAJOR(pv_create_kdev_t(pv[p]->pv_name)) != MD_MAJOR) {
155 : : log_warn
156 : : ("WARNING: physical volume \"%s\" belongs to a meta device",
157 : : pv[p]->pv_name);
158 : : }
159 : : if (MAJOR(pv[p]->pv_dev) != MD_MAJOR)
160 : : continue;
161 : : ********/
162 : 0 : pvs_found++;
163 : :
164 [ # # ]: 0 : if (is_orphan(pv)) {
165 : 0 : new_pvs_found++;
166 : 0 : size_new += pv_size(pv);
167 : 0 : size_total += pv_size(pv);
168 : : } else
169 : 0 : size_total += pv_pe_count(pv) * pv_pe_size(pv);
170 : : }
171 : :
172 : : /* find maximum pv name length */
173 : 0 : pv_max_name_len = vg_max_name_len = 0;
174 [ # # ]: 0 : dm_list_iterate_items(pvl, pvslist) {
175 : 0 : pv = pvl->pv;
176 : 0 : len = strlen(pv_dev_name(pv));
177 [ # # ]: 0 : if (pv_max_name_len < len)
178 : 0 : pv_max_name_len = len;
179 : 0 : len = strlen(pv_vg_name(pv));
180 [ # # ]: 0 : if (vg_max_name_len < len)
181 : 0 : vg_max_name_len = len;
182 : : }
183 : 0 : pv_max_name_len += 2;
184 : 0 : vg_max_name_len += 2;
185 : :
186 [ # # ]: 0 : dm_list_iterate_items(pvl, pvslist)
187 : 0 : _pvscan_display_single(cmd, pvl->pv, NULL);
188 : :
189 [ # # ]: 0 : if (!pvs_found) {
190 : 0 : log_print("No matching physical volumes found");
191 : 0 : unlock_vg(cmd, VG_GLOBAL);
192 : 0 : return ECMD_PROCESSED;
193 : : }
194 : :
195 : 0 : log_print("Total: %d [%s] / in use: %d [%s] / in no VG: %d [%s]",
196 : : pvs_found,
197 : : display_size(cmd, size_total),
198 : : pvs_found - new_pvs_found,
199 : : display_size(cmd, (size_total - size_new)),
200 : : new_pvs_found, display_size(cmd, size_new));
201 : :
202 : 0 : unlock_vg(cmd, VG_GLOBAL);
203 : :
204 : 0 : return ECMD_PROCESSED;
205 : : }
|