~retr0h/nova/lp705504

« back to all changes in this revision

Viewing changes to nova/virt/xenapi/vm_utils.py

  • Committer: Tarmac
  • Author(s): Rick Harris
  • Date: 2011-01-21 22:34:19 UTC
  • mfrom: (600.2.2 bug705790)
  • Revision ID: tarmac-20110121223419-1rebo5d1xkra9f21
This patch adds two flags:

--xenapi_remap_vbd_dev
--xenapi_remap_vbd_dev_prefix

If the plugged-in VBD dev is wrong, these configs let your remap it on the fly. This works around a bug in Ubuntu Maverick: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/684875

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import os
23
23
import pickle
24
24
import re
 
25
import time
25
26
import urllib
26
27
from xml.dom import minidom
27
28
 
589
590
    return None
590
591
 
591
592
 
 
593
def remap_vbd_dev(dev):
 
594
    """Return the appropriate location for a plugged-in VBD device
 
595
 
 
596
    Ubuntu Maverick moved xvd? -> sd?. This is considered a bug and will be
 
597
    fixed in future versions:
 
598
        https://bugs.launchpad.net/ubuntu/+source/linux/+bug/684875
 
599
 
 
600
    For now, we work around it by just doing a string replace.
 
601
    """
 
602
    # NOTE(sirp): This hack can go away when we pull support for Maverick
 
603
    should_remap = FLAGS.xenapi_remap_vbd_dev
 
604
    if not should_remap:
 
605
        return dev
 
606
 
 
607
    old_prefix = 'xvd'
 
608
    new_prefix = FLAGS.xenapi_remap_vbd_dev_prefix
 
609
    remapped_dev = dev.replace(old_prefix, new_prefix)
 
610
 
 
611
    return remapped_dev
 
612
 
 
613
 
592
614
def with_vdi_attached_here(session, vdi, read_only, f):
593
615
    this_vm_ref = get_this_vm_ref(session)
594
616
    vbd_rec = {}
611
633
        LOG.debug(_('Plugging VBD %s ... '), vbd)
612
634
        session.get_xenapi().VBD.plug(vbd)
613
635
        LOG.debug(_('Plugging VBD %s done.'), vbd)
614
 
        return f(session.get_xenapi().VBD.get_device(vbd))
 
636
        orig_dev = session.get_xenapi().VBD.get_device(vbd)
 
637
        LOG.debug(_('VBD %s plugged as %s'), vbd, orig_dev)
 
638
        dev = remap_vbd_dev(orig_dev)
 
639
        if dev != orig_dev:
 
640
            LOG.debug(_('VBD %(vbd)s plugged into wrong dev, '
 
641
                        'remapping to %(dev)s') % locals())
 
642
        return f(dev)
615
643
    finally:
616
644
        LOG.debug(_('Destroying VBD for VDI %s ... '), vdi)
617
645
        vbd_unplug_with_retry(session, vbd)
624
652
    DEVICE_DETACH_REJECTED.  For reasons which I don't understand, we're
625
653
    seeing the device still in use, even when all processes using the device
626
654
    should be dead."""
 
655
    # FIXME(sirp): We can use LoopingCall here w/o blocking sleep()
627
656
    while True:
628
657
        try:
629
658
            session.get_xenapi().VBD.unplug(vbd)