From 5ab925debf247277f6b6c7fca32474da6218bfe9 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Fri, 19 Nov 2004 19:25:07 +0000 Subject: pvcreate wipes md superblocks. (With --uuid or --restorefile it prompts.) --- tools/pvcreate.c | 58 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 11 deletions(-) (limited to 'tools/pvcreate.c') diff --git a/tools/pvcreate.c b/tools/pvcreate.c index 96c47a54..908e8c0c 100644 --- a/tools/pvcreate.c +++ b/tools/pvcreate.c @@ -25,6 +25,8 @@ const char _really_init[] = static int pvcreate_check(struct cmd_context *cmd, const char *name) { struct physical_volume *pv; + struct device *dev; + uint64_t md_superblock; /* is the partition type set correctly ? */ if ((arg_count(cmd, force_ARG) < 1) && !is_lvm_partition(name)) { @@ -33,31 +35,65 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name) return 0; } - /* is there a pv here already */ + /* Is there a pv here already? */ /* FIXME Use partial mode here? */ - if (!(pv = pv_read(cmd, name, NULL, NULL, 0))) - return 1; - - /* orphan ? */ - if (!pv->vg_name[0]) - return 1; + pv = pv_read(cmd, name, NULL, NULL, 0); /* Allow partial & exported VGs to be destroyed. */ - /* we must have -ff to overwrite a non orphan */ - if (arg_count(cmd, force_ARG) < 2) { + /* We must have -ff to overwrite a non orphan */ + if (pv && pv->vg_name[0] && arg_count(cmd, force_ARG) != 2) { log_error("Can't initialize physical volume \"%s\" of " "volume group \"%s\" without -ff", name, pv->vg_name); return 0; } /* prompt */ - if (!arg_count(cmd, yes_ARG) && + if (pv && pv->vg_name[0] && !arg_count(cmd, yes_ARG) && yes_no_prompt(_really_init, name, pv->vg_name) == 'n') { log_print("%s: physical volume not initialized", name); return 0; } - if (arg_count(cmd, force_ARG)) { + dev = dev_cache_get(name, cmd->filter); + + /* Is there an md superblock here? */ + if (!dev && md_filtering()) { + unlock_vg(cmd, ""); + log_verbose("Wiping cache of LVM-capable devices"); + persistent_filter_wipe(cmd->filter); + log_verbose("Wiping internal cache"); + lvmcache_destroy(); + init_md_filtering(0); + if (!lock_vol(cmd, "", LCK_VG_WRITE)) { + log_error("Can't get lock for orphan PVs"); + init_md_filtering(1); + return 0; + } + dev = dev_cache_get(name, cmd->filter); + init_md_filtering(1); + } + + if (!dev) { + log_error("Device %s not found.", name); + return 0; + } + + /* Wipe superblock? */ + if (dev_is_md(dev, &md_superblock) && + ((!arg_count(cmd, uuidstr_ARG) && + !arg_count(cmd, restorefile_ARG)) || + arg_count(cmd, yes_ARG) || + (yes_no_prompt("Software RAID md superblock " + "detected on %s. Wipe it? [y/n] ", name) == 'y'))) { + log_print("Wiping software RAID md superblock on %s", name); + if (!dev_zero(dev, md_superblock, 512)) { + log_error("Failed to wipe RAID md superblock on %s", + name); + return 0; + } + } + + if (pv && pv->vg_name[0] && arg_count(cmd, force_ARG)) { log_print("WARNING: Forcing physical volume creation on " "%s%s%s%s", name, pv->vg_name[0] ? " of volume group \"" : "", -- cgit