]> sourceware.org Git - lvm2.git/blob - tools/pvremove.c
devices: fix dev_dm_uuid
[lvm2.git] / tools / pvremove.c
1 /*
2 * Copyright (C) 2002-2004 Sistina Software, Inc. All rights reserved.
3 * Copyright (C) 2004-2013 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
14 */
15
16 #include "tools.h"
17
18 int pvremove(struct cmd_context *cmd, int argc, char **argv)
19 {
20 struct processing_handle *handle;
21 struct pvcreate_params pp;
22 int ret;
23
24 if (!argc) {
25 log_error("Please enter a physical volume path");
26 return EINVALID_CMD_LINE;
27 }
28
29 pvcreate_params_set_defaults(&pp);
30
31 pp.is_remove = 1;
32 pp.force = arg_count(cmd, force_ARG);
33 pp.yes = arg_count(cmd, yes_ARG);
34 pp.pv_count = argc;
35 pp.pv_names = argv;
36
37 /* Needed to change the set of orphan PVs. */
38 if (!lock_global(cmd, "ex")) {
39 /* Let pvremove -ff skip locks */
40 if (pp.force == DONT_PROMPT_OVERRIDE)
41 log_warn("WARNING: skipping global lock for force.");
42 else
43 return_ECMD_FAILED;
44 }
45
46 clear_hint_file(cmd);
47
48 if (!lvmcache_label_scan(cmd))
49 return_ECMD_FAILED;
50
51 /* When forcibly clearing a PV we don't care about a VG lock. */
52 if (pp.force == DONT_PROMPT_OVERRIDE)
53 cmd->lockd_vg_disable = 1;
54
55 if (!(handle = init_processing_handle(cmd, NULL))) {
56 log_error("Failed to initialize processing handle.");
57 return ECMD_FAILED;
58 }
59
60 /*
61 * pvremove uses the same toollib function as pvcreate,
62 * but sets "is_remove" which changes the check function,
63 * and the actual create vs remove step.
64 */
65
66 if (!pvcreate_each_device(cmd, handle, &pp))
67 ret = ECMD_FAILED;
68 else
69 ret = ECMD_PROCESSED;
70
71 destroy_processing_handle(cmd, handle);
72 return ret;
73 }
This page took 0.042057 seconds and 6 git commands to generate.