]> sourceware.org Git - lvm2.git/blame - tools/pvdisplay.c
thin: tighten discard string conversions
[lvm2.git] / tools / pvdisplay.c
CommitLineData
269930c0 1/*
6606c3ae 2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
be684599 3 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
269930c0 4 *
6606c3ae 5 * This file is part of LVM2.
269930c0 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
be684599 9 * of the GNU Lesser General Public License v.2.1.
269930c0 10 *
be684599 11 * You should have received a copy of the GNU Lesser 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
269930c0
AK
14 */
15
16#include "tools.h"
17
72b2cb61 18static int _pvdisplay_single(struct cmd_context *cmd,
223c62e7 19 struct volume_group *vg,
8ef2b021 20 struct physical_volume *pv, void *handle)
269930c0 21{
7da954d1 22 struct pv_list *pvl;
e663b4e8 23 int ret = ECMD_PROCESSED;
6fda126d 24 uint64_t size;
043b1362 25 struct volume_group *old_vg = vg;
269930c0 26
1b8de4cb 27 const char *pv_name = pv_dev_name(pv);
d38bf361 28 const char *vg_name = NULL;
269930c0 29
fb3226a3 30 if (!is_orphan(pv) && !vg) {
d38bf361 31 vg_name = pv_vg_name(pv);
b8b3508c
DW
32 vg = vg_read(cmd, vg_name, (char *)&pv->vgid, 0);
33 if (vg_read_error(vg)) {
fed0e904 34 log_error("Skipping volume group %s", vg_name);
077a6755 35 release_vg(vg);
57d921e9 36 /* FIXME If CLUSTERED should return ECMD_PROCESSED here */
fed0e904
MB
37 return ECMD_FAILED;
38 }
223c62e7 39
223c62e7
AK
40 /*
41 * Replace possibly incomplete PV structure with new one
8544a8a2 42 * allocated in vg_read_internal() path.
223c62e7 43 */
7da954d1
DW
44 if (!(pvl = find_pv_in_vg(vg, pv_name))) {
45 log_error("Unable to find \"%s\" in volume group \"%s\"",
46 pv_name, vg->name);
67cdbd7e
AK
47 ret = ECMD_FAILED;
48 goto out;
3008bc44 49 }
7da954d1
DW
50
51 pv = pvl->pv;
3008bc44 52 }
e663b4e8 53
9c1dbeb3 54 if (is_orphan(pv))
ff77bb1a 55 size = pv_size(pv);
c7f0b573 56 else
67cdbd7e 57 size = (pv_pe_count(pv) - pv_pe_alloc_count(pv)) *
ff77bb1a 58 pv_pe_size(pv);
269930c0 59
6fda126d 60 if (arg_count(cmd, short_ARG)) {
4c64ed4c 61 log_print("Device \"%s\" has a capacity of %s", pv_name,
72b2cb61 62 display_size(cmd, size));
e663b4e8 63 goto out;
269930c0
AK
64 }
65
ff77bb1a 66 if (pv_status(pv) & EXPORTED_VG)
6fda126d 67 log_print("Physical volume \"%s\" of volume group \"%s\" "
ff77bb1a 68 "is exported", pv_name, pv_vg_name(pv));
269930c0 69
9c1dbeb3 70 if (is_orphan(pv))
6fda126d 71 log_print("\"%s\" is a new physical volume of \"%s\"",
72b2cb61 72 pv_name, display_size(cmd, size));
269930c0 73
6fda126d 74 if (arg_count(cmd, colon_ARG)) {
cd77c5a7 75 pvdisplay_colons(pv);
e663b4e8 76 goto out;
269930c0
AK
77 }
78
4c64ed4c 79 pvdisplay_full(cmd, pv, handle);
269930c0 80
4baa42be
DW
81 if (arg_count(cmd, maps_ARG))
82 pvdisplay_segments(pv);
e663b4e8
AK
83
84out:
67cdbd7e
AK
85 if (vg_name)
86 unlock_vg(cmd, vg_name);
043b1362 87 if (!old_vg)
077a6755 88 release_vg(vg);
269930c0 89
e663b4e8 90 return ret;
5a52dca9
AK
91}
92
93int pvdisplay(struct cmd_context *cmd, int argc, char **argv)
94{
4c64ed4c
AK
95 if (arg_count(cmd, columns_ARG)) {
96 if (arg_count(cmd, colon_ARG) || arg_count(cmd, maps_ARG) ||
97 arg_count(cmd, short_ARG)) {
98 log_error("Incompatible options selected");
99 return EINVALID_CMD_LINE;
100 }
101 return pvs(cmd, argc, argv);
102 } else if (arg_count(cmd, aligned_ARG) ||
200ef4db 103 arg_count(cmd, all_ARG) ||
4c64ed4c
AK
104 arg_count(cmd, noheadings_ARG) ||
105 arg_count(cmd, options_ARG) ||
106 arg_count(cmd, separator_ARG) ||
107 arg_count(cmd, sort_ARG) || arg_count(cmd, unbuffered_ARG)) {
108 log_error("Incompatible options selected");
109 return EINVALID_CMD_LINE;
110 }
5a52dca9
AK
111
112 if (arg_count(cmd, colon_ARG) && arg_count(cmd, maps_ARG)) {
113 log_error("Option -v not allowed with option -c");
114 return EINVALID_CMD_LINE;
115 }
116
21a98eda 117 return process_each_pv(cmd, argc, argv, NULL, 0, 0, NULL,
223c62e7 118 _pvdisplay_single);
269930c0 119}
This page took 0.121939 seconds and 5 git commands to generate.