xref: /netbsd-src/external/gpl2/lvm2/dist/tools/pvdisplay.c (revision 7c604eea85b4f330dc75ffe65e947f4d73758aa0)
1*7c604eeaShaad /*	$NetBSD: pvdisplay.c,v 1.1.1.2 2009/12/02 00:25:54 haad Exp $	*/
256a34939Shaad 
356a34939Shaad /*
456a34939Shaad  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
556a34939Shaad  * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
656a34939Shaad  *
756a34939Shaad  * This file is part of LVM2.
856a34939Shaad  *
956a34939Shaad  * This copyrighted material is made available to anyone wishing to use,
1056a34939Shaad  * modify, copy, or redistribute it subject to the terms and conditions
1156a34939Shaad  * of the GNU Lesser General Public License v.2.1.
1256a34939Shaad  *
1356a34939Shaad  * You should have received a copy of the GNU Lesser General Public License
1456a34939Shaad  * along with this program; if not, write to the Free Software Foundation,
1556a34939Shaad  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
1656a34939Shaad  */
1756a34939Shaad 
1856a34939Shaad #include "tools.h"
1956a34939Shaad 
_pvdisplay_single(struct cmd_context * cmd,struct volume_group * vg,struct physical_volume * pv,void * handle)2056a34939Shaad static int _pvdisplay_single(struct cmd_context *cmd,
2156a34939Shaad 			     struct volume_group *vg,
2256a34939Shaad 			     struct physical_volume *pv, void *handle)
2356a34939Shaad {
2456a34939Shaad 	struct pv_list *pvl;
2556a34939Shaad 	int ret = ECMD_PROCESSED;
2656a34939Shaad 	uint64_t size;
27*7c604eeaShaad 	struct volume_group *old_vg = vg;
2856a34939Shaad 
2956a34939Shaad 	const char *pv_name = pv_dev_name(pv);
3056a34939Shaad 	const char *vg_name = NULL;
3156a34939Shaad 
3256a34939Shaad 	if (!is_orphan(pv) && !vg) {
3356a34939Shaad 		vg_name = pv_vg_name(pv);
34*7c604eeaShaad 		vg = vg_read(cmd, vg_name, (char *)&pv->vgid, 0);
35*7c604eeaShaad 		if (vg_read_error(vg)) {
3656a34939Shaad 			log_error("Skipping volume group %s", vg_name);
37*7c604eeaShaad 			vg_release(vg);
3856a34939Shaad 			/* FIXME If CLUSTERED should return ECMD_PROCESSED here */
3956a34939Shaad 			return ECMD_FAILED;
4056a34939Shaad 		}
4156a34939Shaad 
4256a34939Shaad 	 	/*
4356a34939Shaad 		 * Replace possibly incomplete PV structure with new one
44*7c604eeaShaad 		 * allocated in vg_read_internal() path.
4556a34939Shaad 		 */
4656a34939Shaad 		 if (!(pvl = find_pv_in_vg(vg, pv_name))) {
4756a34939Shaad 			 log_error("Unable to find \"%s\" in volume group \"%s\"",
4856a34939Shaad 				   pv_name, vg->name);
4956a34939Shaad 			 ret = ECMD_FAILED;
5056a34939Shaad 			 goto out;
5156a34939Shaad 		 }
5256a34939Shaad 
5356a34939Shaad 		 pv = pvl->pv;
5456a34939Shaad 	}
5556a34939Shaad 
5656a34939Shaad 	if (is_orphan(pv))
5756a34939Shaad 		size = pv_size(pv);
5856a34939Shaad 	else
5956a34939Shaad 		size = (pv_pe_count(pv) - pv_pe_alloc_count(pv)) *
6056a34939Shaad 			pv_pe_size(pv);
6156a34939Shaad 
6256a34939Shaad 	if (arg_count(cmd, short_ARG)) {
6356a34939Shaad 		log_print("Device \"%s\" has a capacity of %s", pv_name,
6456a34939Shaad 			  display_size(cmd, size));
6556a34939Shaad 		goto out;
6656a34939Shaad 	}
6756a34939Shaad 
6856a34939Shaad 	if (pv_status(pv) & EXPORTED_VG)
6956a34939Shaad 		log_print("Physical volume \"%s\" of volume group \"%s\" "
7056a34939Shaad 			  "is exported", pv_name, pv_vg_name(pv));
7156a34939Shaad 
7256a34939Shaad 	if (is_orphan(pv))
7356a34939Shaad 		log_print("\"%s\" is a new physical volume of \"%s\"",
7456a34939Shaad 			  pv_name, display_size(cmd, size));
7556a34939Shaad 
7656a34939Shaad 	if (arg_count(cmd, colon_ARG)) {
7756a34939Shaad 		pvdisplay_colons(pv);
7856a34939Shaad 		goto out;
7956a34939Shaad 	}
8056a34939Shaad 
8156a34939Shaad 	pvdisplay_full(cmd, pv, handle);
8256a34939Shaad 
8356a34939Shaad 	if (arg_count(cmd, maps_ARG))
8456a34939Shaad 		pvdisplay_segments(pv);
8556a34939Shaad 
8656a34939Shaad out:
8756a34939Shaad 	if (vg_name)
8856a34939Shaad 		unlock_vg(cmd, vg_name);
89*7c604eeaShaad 	if (!old_vg)
90*7c604eeaShaad 		vg_release(vg);
9156a34939Shaad 
9256a34939Shaad 	return ret;
9356a34939Shaad }
9456a34939Shaad 
pvdisplay(struct cmd_context * cmd,int argc,char ** argv)9556a34939Shaad int pvdisplay(struct cmd_context *cmd, int argc, char **argv)
9656a34939Shaad {
9756a34939Shaad 	if (arg_count(cmd, columns_ARG)) {
9856a34939Shaad 		if (arg_count(cmd, colon_ARG) || arg_count(cmd, maps_ARG) ||
9956a34939Shaad 		    arg_count(cmd, short_ARG)) {
10056a34939Shaad 			log_error("Incompatible options selected");
10156a34939Shaad 			return EINVALID_CMD_LINE;
10256a34939Shaad 		}
10356a34939Shaad 		return pvs(cmd, argc, argv);
10456a34939Shaad 	} else if (arg_count(cmd, aligned_ARG) ||
10556a34939Shaad 		   arg_count(cmd, all_ARG) ||
10656a34939Shaad 		   arg_count(cmd, noheadings_ARG) ||
10756a34939Shaad 		   arg_count(cmd, options_ARG) ||
10856a34939Shaad 		   arg_count(cmd, separator_ARG) ||
10956a34939Shaad 		   arg_count(cmd, sort_ARG) || arg_count(cmd, unbuffered_ARG)) {
11056a34939Shaad 		log_error("Incompatible options selected");
11156a34939Shaad 		return EINVALID_CMD_LINE;
11256a34939Shaad 	}
11356a34939Shaad 
11456a34939Shaad 	if (arg_count(cmd, colon_ARG) && arg_count(cmd, maps_ARG)) {
11556a34939Shaad 		log_error("Option -v not allowed with option -c");
11656a34939Shaad 		return EINVALID_CMD_LINE;
11756a34939Shaad 	}
11856a34939Shaad 
119*7c604eeaShaad 	return process_each_pv(cmd, argc, argv, NULL, 0, 0, NULL,
12056a34939Shaad 			       _pvdisplay_single);
12156a34939Shaad }
122