diff options
author | Dominique Martinet <asmadeus@codewreck.org> | 2011-12-23 15:18:21 +0100 |
---|---|---|
committer | Dominique Martinet <asmadeus@codewreck.org> | 2011-12-23 15:18:21 +0100 |
commit | 69cf064282d401f576a48ff362c72eccf797ab0a (patch) | |
tree | 442fc0c272518d6944a3ee2e5c3f4655eb1bc0f2 /kvm-wrapper.sh | |
parent | 03499b0d33d153ccefdba5bbc4419f5d8d487ea6 (diff) |
prepared for a more generic lvchange -a layer
Diffstat (limited to 'kvm-wrapper.sh')
-rwxr-xr-x | kvm-wrapper.sh | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/kvm-wrapper.sh b/kvm-wrapper.sh index c17b5e6..622a3ca 100755 --- a/kvm-wrapper.sh +++ b/kvm-wrapper.sh @@ -236,18 +236,32 @@ function kvm_nbd_disconnect () } # LVM helpers -function check_activate_lv () +function prepare_disks () { - for DISK in $@; do - [[ "$LVM_MANAGE_LV" == "yes" ]] && [[ "$DISK" == "/dev/"*"/"* ]] && lvchange -ay "$DISK" || true - done + case "$KVM_MANAGE_DISKS" in + "ACTIVATE_LV") + for DISK in $@; do + [[ "$DISK" == "/dev/"*"/"* ]] && lvchange -ay "$DISK" || true + done + ;; + "USER_DEFINED") + eval "$USER_PREPARE_DISKS" + ;; + esac; } -function check_deactivate_lv () +function unprepare_disks () { - for DISK in $@; do - [[ "$LVM_MANAGE_LV" == "yes" ]] && [[ "$DISK" == "/dev/"*"/"* ]] && lvchange -an "$DISK" || true - done + case "$KVM_MANAGE_DISKS" in + "ACTIVATE_LV") + for DISK in $@; do + [[ "$DISK" == "/dev/"*"/"* ]] && lvchange -an "$DISK" || true + done + ;; + "USER_DEFINED") + eval "$USER_UNPREPARE_DISKS" + ;; + esac; } function lvm_create_disk () @@ -281,7 +295,7 @@ function lvm_mount_disk() test_exist "$PID_FILE" && fail_exit "VM $VM_NAME seems to be running! (PID file $PID_FILE exists)\nYou cannot mount disk on a running VM" echo "Attempting to mount first partition of $KVM_DISK1" - check_activate_lv "$KVM_DISK1" + prepare_disks "$KVM_DISK1" PART=`map_disk "$KVM_DISK1"` mkdir -p "/mnt/$VM_NAME" mount "$PART" "/mnt/$VM_NAME" @@ -295,7 +309,7 @@ function lvm_umount_disk() umount "/mnt/$VM_NAME" rmdir "/mnt/$VM_NAME" unmap_disk "$KVM_DISK1" - check_deactivate_lv "$KVM_DISK1" + unprepare_disks "$KVM_DISK1" set +e } @@ -418,7 +432,7 @@ function kvm_start_vm () [[ -n "$KVM_APPEND" ]] && LINUXBOOT="$LINUXBOOT -append \"$KVM_APPEND\"" # If drive is a lv in the main vg, activate the lv - check_activate_lv "$KVM_DISK1" "$KVM_DISK2" "$KVM_DISK3" "$KVM_DISK4" + prepare_disks "$KVM_DISK1" "$KVM_DISK2" "$KVM_DISK3" "$KVM_DISK4" # Network scripts [[ -z "$KVM_BRIDGE" ]] && KVM_BRIDGE="kvmnat" @@ -460,7 +474,7 @@ function kvm_start_vm () rm -rf "$SERIAL_FILE" # If drive is a lv in the main vg, deactivate the lv - check_deactivate_lv "$KVM_DISK1" "$KVM_DISK2" "$KVM_DISK3" "$KVM_DISK4" + unprepare_disks "$KVM_DISK1" "$KVM_DISK2" "$KVM_DISK3" "$KVM_DISK4" # Exit return 0 @@ -521,14 +535,14 @@ function kvm_run_disk () { require_exec "$KVM_BIN" KVM_DISK1="$1" - check_activate_lv "$KVM_DISK1" + prepare_disks "$KVM_DISK1" test_file_rw "$KVM_DISK1" || "Couldn't read/write image file :\n$KVM_DISK1" # Build kvm exec string local EXEC_STRING="$KVM_BIN -net nic,model=$KVM_NETWORK_MODEL,macaddr=$KVM_MACADDRESS -net tap -hda $KVM_DISK1 -boot c $KVM_KEYMAP $KVM_OUTPUT $KVM_ADDITIONNAL_PARAMS" eval "$EXEC_STRING" - check_deactivate_lv "$KVM_DISK1" + unprepare_disks "$KVM_DISK1" return 0 } @@ -676,8 +690,8 @@ function kvm_bootstrap_vm () test_file "$BOOTSTRAP_SCRIPT" || fail_exit "Couldn't read $BOOTSTRAP_SCRIPT to bootstrap $VM_NAME as $BOOTSTRAP_DISTRIB" source "$BOOTSTRAP_SCRIPT" - check_activate_lv "$KVM_DISK1" - CLEANUP+=("check_deactivate_lv \"$KVM_DISK1\"") + prepare_disks "$KVM_DISK1" + CLEANUP+=("unprepare_disks \"$KVM_DISK1\"") if ! test_blockdev "$KVM_DISK1" then require_exec "$KVM_NBD_BIN" |