Changeset 1580


Ignore:
Timestamp:
Nov 10, 2008, 3:16:05 AM (16 years ago)
Author:
broder
Message:

Use a lock LV when starting sysvms since exclusive LV activation has
useless semantics

Location:
trunk/packages/invirt-xen-config/debian
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/invirt-xen-config/debian/changelog

    r1459 r1580  
     1invirt-xen-config (0.0.13) unstable; urgency=low
     2
     3  * Use a lock LV when attempting to start sysvms since exclusive LV
     4    activation has useless semantics
     5
     6 -- Evan Broder <broder@mit.edu>  Mon, 10 Nov 2008 03:15:31 -0500
     7
    18invirt-xen-config (0.0.12) unstable; urgency=low
    29
  • trunk/packages/invirt-xen-config/debian/invirt-xen-config.init

    r1471 r1580  
    2727   
    2828    VM="$1"
    29     DISK="/dev/xenvg/${VM}_hda"
     29    LV="${VM}_hda"
     30    DISK="/dev/xenvg/$LV"
    3031   
    3132    # Don't bother trying to start the VM if it's already running
    32     if xm list "$1" >/dev/null 2>&1; then
     33    if xm list "$VM" >/dev/null 2>&1; then
    3334        return 1
    3435    fi
    3536   
    36     if lvchange -a n "$DISK" >/dev/null 2>&1 && lvchange -a ey "$DISK" >/dev/null 2>&1; then
    37         # If we can disable and then re-enable the VMs disk, then the
    38         # VM can't be running. If the lvchange -a ey succeeds, then we
    39         # have an exclusive lock across the cluster on enabling the
    40         # disk, which avoids the potential race condition of two hosts
    41         # starting a VM at the same time
    42         [ "$VERBOSE" != no ] && log_daemon_msg "Starting sysvm $VM"
    43         xm create "sysvms/$VM" >/dev/null
    44         [ "$VERBOSE" != no ] && log_end_msg $?
    45         RET=0
    46     else
    47         RET=1
     37    RET=1
     38    # To keep multiple hosts from trying to start a VM at the same
     39    # time, lock VM creation at startup-time with a lock LV, since LV
     40    # creation is atomic
     41    if lvcreate -L 1K -n "lock_${LV}" xenvg >/dev/null 2>&1; then
     42        # If we can disable the LV, then the VM isn't already running
     43        # somewhere else
     44        if lvchange -a n "$DISK" >/dev/null 2>&1; then
     45            lvchange -a y "$DISK" >/dev/null 2>&1
     46           
     47            [ "$VERBOSE" != no ] && log_daemon_msg "Starting sysvm $VM"
     48            xm create "sysvms/$VM" >/dev/null
     49            [ "$VERBOSE" != no ] && log_end_msg $?
     50            RET=0
     51        fi
     52       
     53        # Regardless of whether we could get the lock or not, the
     54        # lvchange -a n probably disabled the LV somewhere; be sure we
     55        # clean up
     56        lvchange -a y "$DISK" >/dev/null 2>&1
     57   
     58        # Cleanup the lock, regardless of whether we started the LV
     59        lvchange -a n "/dev/xenvg/lock_${LV}"
     60        lvremove -f "/dev/xenvg/lock_${LV}"
    4861    fi
    49    
    50     # Regardless of whether we could get the lock or not, the
    51     # lvchange -a n probably disabled the LV somewhere; be sure we
    52     # clean up
    53     lvchange -a y "$DISK" >/dev/null 2>&1
    5462   
    5563    return $RET
Note: See TracChangeset for help on using the changeset viewer.