confz

git mirror of https://ccx.te2000.cz/bzr/confz
git clone https://ccx.te2000.cz/git/confz
Log | Files | Refs

commit d4ccc0576cf407c6df76230d63834468a72f22d3
parent 22ef3df006ec928a55c133942c2d55d5b13edb64
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date:   Tue, 21 Nov 2017 17:21:15 +0100

logical_volume_extents for creating contiguous volumes on specific devices
Diffstat:
Mzsh-functions/confz_fs_init | 43+++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+), 0 deletions(-)

diff --git a/zsh-functions/confz_fs_init b/zsh-functions/confz_fs_init @@ -486,6 +486,49 @@ confz_logical_volume_check() { [[ -b ${vars[device]} ]] } +# configure LVM2 logical volume +confz_logical_volume_extents_check() { + [[ -n ${vars[vg_name]:=${DEFAULT_VG}} ]] || \ + die "$0: DEFAULT_VG is unset and no 'vg_name' was passed" + + checkvars lv_name pv_name extents + + local vg_name lv_name pv_name pvseg_start pvseg_size segtype + local -A found + pvs --segments --noheadings --separator $'\t' \ + -o vg_name,lv_name,pv_name,pvseg_start,pvseg_size,segtype \ + | while IFS=$'\t' \ + read vg_name lv_name pv_name pvseg_start pvseg_size segtype + do + vg_name=${vg_name/# #} # strip preceding space + (($#found)) && die "$0: more than one segment found" + if matchvars vg_name $vg_name lv_name $lv_name; then + if [[ $segtype != linear ]] || ! matchvars pv_name $pv_name offset $pvseg_start extents $pvseg_size; then + die "$0: non-matching physical layout of the volume" + fi + found[offset]=$pvseg_start + fi + done + unify "${(kv@)found}" \ + device /dev/mapper/$vars[vg_name]-$vars[lv_name] + + do_command=( + lvcreate + --name ${vars[lv_name]} + --extents ${vars[extents]} + ${vars[vg_name]} + $vars[pv_name]:$vars[offset]-$[ $vars[offset] + $vars[extents] ] + ) + + if ! (($#found)); then + fail_reason="not found in pvs output: ${vars[vg_name]}/${vars[lv_name]}" + return 1 + fi + + fail_reason="not a block device: ${vars[device]}" + [[ -b ${vars[device]} ]] +} + # create filesystem on block device confz_filesystem_check() {