コード例 #1
0
ファイル: pvremove.c プロジェクト: ErisBlastar/osfree
/*
 * Decide whether it is "safe" to wipe the labels on this device.
 * 0 indicates we may not.
 */
static int pvremove_check(struct cmd_context *cmd, const char *name)
{
    struct physical_volume *pv;

    /* is the partition type set correctly ? */
    if ((arg_count(cmd, force_ARG) < 1) && !is_lvm_partition(name)) {
        log_error("%s: Not LVM partition type: use -f to override",
                  name);
        return 0;
    }

    /* Is there a pv here already? */
    /* If not, this is an error unless you used -f. */
    if (!(pv = pv_read(cmd, name, NULL, NULL, 1))) {
        if (arg_count(cmd, force_ARG))
            return 1;
        log_error("Physical Volume %s not found", name);
        return 0;
    }

    /* orphan ? */
    if (is_orphan(pv))
        return 1;

    /* Allow partial & exported VGs to be destroyed. */
    /* we must have -ff to overwrite a non orphan */
    if (arg_count(cmd, force_ARG) < 2) {
        log_error("Can't pvremove physical volume \"%s\" of "
                  "volume group \"%s\" without -ff", name, pv_vg_name(pv));
        return 0;
    }

    /* prompt */
    if (!arg_count(cmd, yes_ARG) &&
            yes_no_prompt(_really_wipe, name, pv_vg_name(pv)) == 'n') {
        log_print("%s: physical volume label not removed", name);
        return 0;
    }

    if (arg_count(cmd, force_ARG)) {
        log_warn("WARNING: Wiping physical volume label from "
                 "%s%s%s%s", name,
                 !is_orphan(pv) ? " of volume group \"" : "",
                 !is_orphan(pv) ? pv_vg_name(pv) : "",
                 !is_orphan(pv) ? "\"" : "");
    }

    return 1;
}
コード例 #2
0
ファイル: pvresize.c プロジェクト: tasleson/lvm2
static int _pvresize_single(struct cmd_context *cmd,
			    struct volume_group *vg,
			    struct physical_volume *pv,
			    struct processing_handle *handle)
{
	struct pvresize_params *params = (struct pvresize_params *) handle->custom_handle;

	if (!params) {
		log_error(INTERNAL_ERROR "Invalid resize params.");
		return ECMD_FAILED;
	}
	params->total++;

	if (vg && vg_is_exported(vg)) {
		log_error("Volume group %s is exported", vg->name);
		return ECMD_FAILED;
	}

	/*
	 * Needed to change a property on an orphan PV.
	 * i.e. the global lock is only needed for orphans.
	 * Convert sh to ex.
	 */
	if (is_orphan(pv)) {
		if (!lockd_gl(cmd, "ex", 0))
			return_ECMD_FAILED;
		cmd->lockd_gl_disable = 1;
	}

	if (!pv_resize_single(cmd, vg, pv, params->new_size, arg_is_set(cmd, yes_ARG)))
		return_ECMD_FAILED;

	params->done++;

	return ECMD_PROCESSED;
}
コード例 #3
0
ファイル: pvremove.c プロジェクト: ystk/debian-lvm2
/*
 * Decide whether it is "safe" to wipe the labels on this device.
 * 0 indicates we may not.
 */
static int pvremove_check(struct cmd_context *cmd, const char *name)
{
	struct physical_volume *pv;
	struct dm_list mdas;

	dm_list_init(&mdas);

	/* FIXME Check partition type is LVM unless --force is given */

	/* Is there a pv here already? */
	/* If not, this is an error unless you used -f. */
	if (!(pv = pv_read(cmd, name, &mdas, NULL, 1, 0))) {
		if (arg_count(cmd, force_ARG))
			return 1;
		log_error("Physical Volume %s not found", name);
		return 0;
	}

	/*
	 * If a PV has no MDAs it may appear to be an
	 * orphan until the metadata is read off
	 * another PV in the same VG.  Detecting this
	 * means checking every VG by scanning every
	 * PV on the system.
	 */
	if (is_orphan(pv) && !dm_list_size(&mdas)) {
		if (!scan_vgs_for_pvs(cmd)) {
			log_error("Rescan for PVs without metadata areas "
				  "failed.");
			return 0;
		}
		if (!(pv = pv_read(cmd, name, NULL, NULL, 1, 0))) {
			log_error("Failed to read physical volume %s", name);
			return 0;
		}
	}

	/* orphan ? */
	if (is_orphan(pv))
		return 1;

	/* Allow partial & exported VGs to be destroyed. */
	/* we must have -ff to overwrite a non orphan */
	if (arg_count(cmd, force_ARG) < 2) {
		log_error("Can't pvremove physical volume \"%s\" of "
			  "volume group \"%s\" without -ff", name, pv_vg_name(pv));
		return 0;
	}

	/* prompt */
	if (!arg_count(cmd, yes_ARG) &&
	    yes_no_prompt(_really_wipe, name, pv_vg_name(pv)) == 'n') {
		log_error("%s: physical volume label not removed", name);
		return 0;
	}

	if (arg_count(cmd, force_ARG)) {
		log_warn("WARNING: Wiping physical volume label from "
			  "%s%s%s%s", name,
			  !is_orphan(pv) ? " of volume group \"" : "",
			  !is_orphan(pv) ? pv_vg_name(pv) : "",
			  !is_orphan(pv) ? "\"" : "");
	}

	return 1;
}
コード例 #4
0
ファイル: pvremove.c プロジェクト: inteos/WBSAirback
/*
 * Decide whether it is "safe" to wipe the labels on this device.
 * 0 indicates we may not.
 */
static int pvremove_check(struct cmd_context *cmd, const char *name)
{
	struct physical_volume *pv;

	/* FIXME Check partition type is LVM unless --force is given */

	/* Is there a pv here already? */
	/* If not, this is an error unless you used -f. */
	if (!(pv = pv_read(cmd, name, 1, 0))) {
		if (arg_count(cmd, force_ARG))
			return 1;
		log_error("Physical Volume %s not found", name);
		return 0;
	}

	/*
	 * If a PV has no MDAs it may appear to be an
	 * orphan until the metadata is read off
	 * another PV in the same VG.  Detecting this
	 * means checking every VG by scanning every
	 * PV on the system.
	 */
	if (is_orphan(pv) && !dm_list_size(&pv->fid->metadata_areas_in_use) &&
	    !dm_list_size(&pv->fid->metadata_areas_ignored)) {
		if (!scan_vgs_for_pvs(cmd, 0)) {
			log_error("Rescan for PVs without metadata areas "
				  "failed.");
			goto bad;
		}
		free_pv_fid(pv);
		if (!(pv = pv_read(cmd, name, 1, 0))) {
			log_error("Failed to read physical volume %s", name);
			goto bad;
		}
	}

	/* orphan ? */
	if (is_orphan(pv)) {
		free_pv_fid(pv);
		return 1;
	}

	/* Allow partial & exported VGs to be destroyed. */
	/* we must have -ff to overwrite a non orphan */
	if (arg_count(cmd, force_ARG) < 2) {
		log_error("PV %s belongs to Volume Group %s so please use vgreduce first.", name, pv_vg_name(pv));
		log_error("(If you are certain you need pvremove, then confirm by using --force twice.)");
		goto bad;
	}

	/* prompt */
	if (!arg_count(cmd, yes_ARG) &&
	    yes_no_prompt(_really_wipe, name, pv_vg_name(pv)) == 'n') {
		log_error("%s: physical volume label not removed", name);
		goto bad;
	}

	if (arg_count(cmd, force_ARG)) {
		log_warn("WARNING: Wiping physical volume label from "
			  "%s%s%s%s", name,
			  !is_orphan(pv) ? " of volume group \"" : "",
			  !is_orphan(pv) ? pv_vg_name(pv) : "",
			  !is_orphan(pv) ? "\"" : "");
	}

	free_pv_fid(pv);
	return 1;

bad:
	free_pv_fid(pv);
	return 0;
}
コード例 #5
0
ファイル: pvcreate.c プロジェクト: ErisBlastar/osfree
/*
 * See if we may pvcreate on this device.
 * 0 indicates we may not.
 */
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)) {
		log_error("%s: Not LVM partition type: use -f to override",
			  name);
		return 0;
	}

	/* Is there a pv here already? */
	/* FIXME Use partial mode here? */
	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 (pv && !is_orphan(pv) && arg_count(cmd, force_ARG) != 2) {
		log_error("Can't initialize physical volume \"%s\" of "
			  "volume group \"%s\" without -ff", name, pv_vg_name(pv));
		return 0;
	}

	/* prompt */
	if (pv && !is_orphan(pv) && !arg_count(cmd, yes_ARG) &&
	    yes_no_prompt(_really_init, name, pv_vg_name(pv)) == 'n') {
		log_print("%s: physical volume not initialized", name);
		return 0;
	}

	if (sigint_caught())
		return 0;

	dev = dev_cache_get(name, cmd->filter);

	/* Is there an md superblock here? */
	if (!dev && md_filtering()) {
		unlock_vg(cmd, ORPHAN);

		persistent_filter_wipe(cmd->filter);
		lvmcache_destroy();

		init_md_filtering(0);
		if (!lock_vol(cmd, ORPHAN, 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 (or ignored by filtering).", name);
		return 0;
	}

	if (!dev_test_excl(dev)) {
		log_error("Can't open %s exclusively.  Mounted filesystem?",
			  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_set(dev, md_superblock, 4, 0)) {
			log_error("Failed to wipe RAID md superblock on %s",
				  name);
			return 0;
		}
	}

	if (sigint_caught())
		return 0;

	if (pv && !is_orphan(pv) && arg_count(cmd, force_ARG)) {
		log_warn("WARNING: Forcing physical volume creation on "
			  "%s%s%s%s", name,
			  !is_orphan(pv) ? " of volume group \"" : "",
			  !is_orphan(pv) ? pv_vg_name(pv) : "",
			  !is_orphan(pv) ? "\"" : "");
	}

	return 1;
}