]>
Commit | Line | Data |
---|---|---|
9e300c84 | 1 | /* |
6606c3ae AK |
2 | * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. |
3 | * Copyright (C) 2004 Red Hat, Inc. All rights reserved. | |
9e300c84 | 4 | * |
6606c3ae | 5 | * This file is part of LVM2. |
9e300c84 | 6 | * |
6606c3ae AK |
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 General Public License v.2. | |
9e300c84 AK |
10 | * |
11 | * You should have received a copy of the GNU General Public License | |
6606c3ae AK |
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 | |
9e300c84 AK |
14 | */ |
15 | ||
16 | #include "tools.h" | |
17 | ||
9e300c84 AK |
18 | int pv_max_name_len = 0; |
19 | int vg_max_name_len = 0; | |
20 | ||
8ef2b021 | 21 | static void _pvscan_display_single(struct cmd_context *cmd, |
72b2cb61 AK |
22 | struct physical_volume *pv, |
23 | void *handle __attribute((unused))) | |
5a52dca9 | 24 | { |
4dc0ec22 | 25 | char uuid[64] __attribute((aligned(8))); |
72b2cb61 | 26 | unsigned vg_name_len = 0; |
5a52dca9 | 27 | |
5a52dca9 AK |
28 | char pv_tmp_name[NAME_LEN] = { 0, }; |
29 | char vg_tmp_name[NAME_LEN] = { 0, }; | |
30 | char vg_name_this[NAME_LEN] = { 0, }; | |
31 | ||
32 | /* short listing? */ | |
33 | if (arg_count(cmd, short_ARG) > 0) { | |
ff77bb1a | 34 | log_print("%s", dev_name(pv_dev(pv))); |
5a52dca9 AK |
35 | return; |
36 | } | |
37 | ||
38 | 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 | memset(pv_tmp_name, 0, sizeof(pv_tmp_name)); | |
50 | ||
ff77bb1a | 51 | vg_name_len = strlen(pv_vg_name(pv)) + 1; |
5a52dca9 AK |
52 | |
53 | if (arg_count(cmd, uuid_ARG)) { | |
54 | if (!id_write_format(&pv->id, uuid, sizeof(uuid))) { | |
55 | stack; | |
56 | return; | |
57 | } | |
58 | ||
59 | sprintf(pv_tmp_name, "%-*s with UUID %s", | |
ff77bb1a | 60 | pv_max_name_len - 2, dev_name(pv_dev(pv)), uuid); |
5a52dca9 | 61 | } else { |
ff77bb1a | 62 | sprintf(pv_tmp_name, "%s", dev_name(pv_dev(pv))); |
5a52dca9 AK |
63 | } |
64 | ||
ff77bb1a | 65 | if (!*pv_vg_name(pv)) { |
5a52dca9 AK |
66 | 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 : " ", | |
ff77bb1a | 70 | display_size(cmd, pv_size(pv))); |
5a52dca9 AK |
71 | return; |
72 | } | |
73 | ||
ff77bb1a DW |
74 | if (pv_status(pv) & EXPORTED_VG) { |
75 | strncpy(vg_name_this, pv_vg_name(pv), vg_name_len); | |
5a52dca9 AK |
76 | log_print("PV %-*s is in exported VG %s " |
77 | "[%s / %s free]", | |
78 | pv_max_name_len, pv_tmp_name, | |
4c64ed4c | 79 | vg_name_this, |
ff77bb1a DW |
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))); | |
5a52dca9 AK |
85 | return; |
86 | } | |
87 | ||
ff77bb1a | 88 | sprintf(vg_tmp_name, "%s", pv_vg_name(pv)); |
30bab85b AK |
89 | 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 : " ", | |
ff77bb1a DW |
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))); | |
5a52dca9 AK |
97 | return; |
98 | } | |
99 | ||
72b2cb61 AK |
100 | int pvscan(struct cmd_context *cmd, int argc __attribute((unused)), |
101 | char **argv __attribute((unused))) | |
9e300c84 AK |
102 | { |
103 | int new_pvs_found = 0; | |
104 | int pvs_found = 0; | |
9e300c84 | 105 | |
8ef2b021 | 106 | struct list *pvslist; |
b6c041d7 | 107 | struct pv_list *pvl; |
9e300c84 AK |
108 | struct physical_volume *pv; |
109 | ||
ee1f91bf AK |
110 | uint64_t size_total = 0; |
111 | uint64_t size_new = 0; | |
9e300c84 AK |
112 | |
113 | int len = 0; | |
114 | pv_max_name_len = 0; | |
115 | vg_max_name_len = 0; | |
116 | ||
6fda126d | 117 | if (arg_count(cmd, novolumegroup_ARG) && arg_count(cmd, exported_ARG)) { |
b6c041d7 | 118 | log_error("Options -e and -n are incompatible"); |
ee1f91bf | 119 | return EINVALID_CMD_LINE; |
9e300c84 AK |
120 | } |
121 | ||
6fda126d | 122 | if (arg_count(cmd, exported_ARG) || arg_count(cmd, novolumegroup_ARG)) |
9e300c84 | 123 | log_print("WARNING: only considering physical volumes %s", |
6fda126d | 124 | arg_count(cmd, exported_ARG) ? |
9e300c84 AK |
125 | "of exported volume group(s)" : "in no volume group"); |
126 | ||
60274aba | 127 | persistent_filter_wipe(cmd->filter); |
914c9723 | 128 | lvmcache_destroy(); |
5a52dca9 | 129 | |
d2393d23 | 130 | log_verbose("Walking through all physical volumes"); |
8ef2b021 | 131 | if (!(pvslist = get_pvs(cmd))) |
ee1f91bf | 132 | return ECMD_FAILED; |
9e300c84 AK |
133 | |
134 | /* eliminate exported/new if required */ | |
f2b7349e | 135 | list_iterate_items(pvl, pvslist) { |
cc282870 | 136 | pv = pvl->pv; |
9e300c84 | 137 | |
25b73380 | 138 | if ((arg_count(cmd, exported_ARG) |
ff77bb1a DW |
139 | && !(pv_status(pv) & EXPORTED_VG)) |
140 | || (arg_count(cmd, novolumegroup_ARG) && (*pv_vg_name(pv)))) { | |
1b9fcf48 | 141 | list_del(&pvl->list); |
9e300c84 AK |
142 | continue; |
143 | } | |
144 | ||
145 | /* Also check for MD use? */ | |
146 | /******* | |
147 | if (MAJOR(pv_create_kdev_t(pv[p]->pv_name)) != MD_MAJOR) { | |
148 | log_print | |
149 | ("WARNING: physical volume \"%s\" belongs to a meta device", | |
150 | pv[p]->pv_name); | |
151 | } | |
152 | if (MAJOR(pv[p]->pv_dev) != MD_MAJOR) | |
153 | continue; | |
154 | ********/ | |
155 | pvs_found++; | |
25d42d50 | 156 | |
ff77bb1a | 157 | if (!*pv_vg_name(pv)) { |
9e300c84 | 158 | new_pvs_found++; |
ff77bb1a DW |
159 | size_new += pv_size(pv); |
160 | size_total += pv_size(pv); | |
1b9fcf48 | 161 | } else |
ff77bb1a | 162 | size_total += pv_pe_count(pv) * pv_pe_size(pv); |
9e300c84 AK |
163 | } |
164 | ||
165 | /* find maximum pv name length */ | |
166 | pv_max_name_len = vg_max_name_len = 0; | |
f2b7349e AK |
167 | list_iterate_items(pvl, pvslist) { |
168 | pv = pvl->pv; | |
ff77bb1a | 169 | len = strlen(dev_name(pv_dev(pv))); |
9e300c84 AK |
170 | if (pv_max_name_len < len) |
171 | pv_max_name_len = len; | |
ff77bb1a | 172 | len = strlen(pv_vg_name(pv)); |
9e300c84 AK |
173 | if (vg_max_name_len < len) |
174 | vg_max_name_len = len; | |
175 | } | |
176 | pv_max_name_len += 2; | |
177 | vg_max_name_len += 2; | |
178 | ||
f2b7349e AK |
179 | list_iterate_items(pvl, pvslist) |
180 | _pvscan_display_single(cmd, pvl->pv, NULL); | |
9e300c84 AK |
181 | |
182 | if (!pvs_found) { | |
183 | log_print("No matching physical volumes found"); | |
cfb7bfc7 | 184 | return ECMD_PROCESSED; |
9e300c84 AK |
185 | } |
186 | ||
b6c041d7 | 187 | log_print("Total: %d [%s] / in use: %d [%s] / in no VG: %d [%s]", |
9e300c84 | 188 | pvs_found, |
72b2cb61 | 189 | display_size(cmd, size_total), |
9e300c84 | 190 | pvs_found - new_pvs_found, |
72b2cb61 AK |
191 | display_size(cmd, (size_total - size_new)), |
192 | new_pvs_found, display_size(cmd, size_new)); | |
9e300c84 | 193 | |
cfb7bfc7 | 194 | return ECMD_PROCESSED; |
9e300c84 | 195 | } |