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 : 0 : static int _pvdisplay_single(struct cmd_context *cmd,
19 : : struct volume_group *vg,
20 : : struct physical_volume *pv, void *handle)
21 : : {
22 : : struct pv_list *pvl;
23 : 0 : int ret = ECMD_PROCESSED;
24 : : uint64_t size;
25 : 0 : struct volume_group *old_vg = vg;
26 : :
27 : 0 : const char *pv_name = pv_dev_name(pv);
28 : 0 : const char *vg_name = NULL;
29 : :
30 [ # # # # ]: 0 : if (!is_orphan(pv) && !vg) {
31 : 0 : vg_name = pv_vg_name(pv);
32 : 0 : vg = vg_read(cmd, vg_name, (char *)&pv->vgid, 0);
33 [ # # ]: 0 : if (vg_read_error(vg)) {
34 : 0 : log_error("Skipping volume group %s", vg_name);
35 : 0 : vg_release(vg);
36 : : /* FIXME If CLUSTERED should return ECMD_PROCESSED here */
37 : 0 : return ECMD_FAILED;
38 : : }
39 : :
40 : : /*
41 : : * Replace possibly incomplete PV structure with new one
42 : : * allocated in vg_read_internal() path.
43 : : */
44 [ # # ]: 0 : if (!(pvl = find_pv_in_vg(vg, pv_name))) {
45 : 0 : log_error("Unable to find \"%s\" in volume group \"%s\"",
46 : : pv_name, vg->name);
47 : 0 : ret = ECMD_FAILED;
48 : 0 : goto out;
49 : : }
50 : :
51 : 0 : pv = pvl->pv;
52 : : }
53 : :
54 [ # # ]: 0 : if (is_orphan(pv))
55 : 0 : size = pv_size(pv);
56 : : else
57 : 0 : size = (pv_pe_count(pv) - pv_pe_alloc_count(pv)) *
58 : : pv_pe_size(pv);
59 : :
60 [ # # ]: 0 : if (arg_count(cmd, short_ARG)) {
61 : 0 : log_print("Device \"%s\" has a capacity of %s", pv_name,
62 : : display_size(cmd, size));
63 : 0 : goto out;
64 : : }
65 : :
66 [ # # ]: 0 : if (pv_status(pv) & EXPORTED_VG)
67 : 0 : log_print("Physical volume \"%s\" of volume group \"%s\" "
68 : : "is exported", pv_name, pv_vg_name(pv));
69 : :
70 [ # # ]: 0 : if (is_orphan(pv))
71 : 0 : log_print("\"%s\" is a new physical volume of \"%s\"",
72 : : pv_name, display_size(cmd, size));
73 : :
74 [ # # ]: 0 : if (arg_count(cmd, colon_ARG)) {
75 : 0 : pvdisplay_colons(pv);
76 : 0 : goto out;
77 : : }
78 : :
79 : 0 : pvdisplay_full(cmd, pv, handle);
80 : :
81 [ # # ]: 0 : if (arg_count(cmd, maps_ARG))
82 : 0 : pvdisplay_segments(pv);
83 : :
84 : : out:
85 [ # # ]: 0 : if (vg_name)
86 : 0 : unlock_vg(cmd, vg_name);
87 [ # # ]: 0 : if (!old_vg)
88 : 0 : vg_release(vg);
89 : :
90 : 0 : return ret;
91 : : }
92 : :
93 : 0 : int pvdisplay(struct cmd_context *cmd, int argc, char **argv)
94 : : {
95 [ # # ]: 0 : if (arg_count(cmd, columns_ARG)) {
96 [ # # ]: 0 : if (arg_count(cmd, colon_ARG) || arg_count(cmd, maps_ARG) ||
[ # # # # ]
97 : 0 : arg_count(cmd, short_ARG)) {
98 : 0 : log_error("Incompatible options selected");
99 : 0 : return EINVALID_CMD_LINE;
100 : : }
101 : 0 : return pvs(cmd, argc, argv);
102 [ # # # # # : 0 : } else if (arg_count(cmd, aligned_ARG) ||
# # # # #
# # # # ]
103 : 0 : arg_count(cmd, all_ARG) ||
104 : 0 : arg_count(cmd, noheadings_ARG) ||
105 : 0 : arg_count(cmd, options_ARG) ||
106 : 0 : arg_count(cmd, separator_ARG) ||
107 : 0 : arg_count(cmd, sort_ARG) || arg_count(cmd, unbuffered_ARG)) {
108 : 0 : log_error("Incompatible options selected");
109 : 0 : return EINVALID_CMD_LINE;
110 : : }
111 : :
112 [ # # ][ # # ]: 0 : if (arg_count(cmd, colon_ARG) && arg_count(cmd, maps_ARG)) {
113 : 0 : log_error("Option -v not allowed with option -c");
114 : 0 : return EINVALID_CMD_LINE;
115 : : }
116 : :
117 : 0 : return process_each_pv(cmd, argc, argv, NULL, 0, 0, NULL,
118 : : _pvdisplay_single);
119 : : }
|