Introduced flag base_dir_name. Fixes bug 973194

rebased from master.

If user faces locking related problem when two nova-compute hosts
sharing same disk area via nfs, try to download same image into
cache concurrently - Then base_dir_name can be set to "_base_$my_ip" in
nova.conf

Default value for base_dir_name is "_base" thus retaining existing
behavior.

Change-Id: Icff10ed75ba83f7256731614dc9e01e578b347a4
This commit is contained in:
Mandar Vaze 2012-04-05 01:33:34 -07:00 committed by Ghe Rivero
parent 1209af4552
commit 7028d66ae9
6 changed files with 22 additions and 9 deletions

View File

@ -122,6 +122,7 @@ Likitha Shetty <likitha.shetty@citrix.com>
Loganathan Parthipan <parthipan@hp.com>
Lorin Hochstein <lorin@nimbisservices.com>
Lvov Maxim <usrleon@gmail.com>
Mandar Vaze <mandar.vaze@vertex.co.in>
Mandell Degerness <mdegerne@gmail.com>
Mark McClain <mark.mcclain@dreamhost.com>
Mark McLoughlin <markmc@redhat.com>

View File

@ -28,6 +28,7 @@ terminating it.
**Related Flags**
:instances_path: Where instances are kept on disk
:base_dir_name: Where cached images are stored under instances_path
:compute_driver: Name of class that is used to handle virtualization, loaded
by :func:`nova.utils.import_object`
@ -72,6 +73,11 @@ compute_opts = [
cfg.StrOpt('instances_path',
default='$state_path/instances',
help='where instances are stored on disk'),
cfg.StrOpt('base_dir_name',
default='_base',
help="where cached images are stored under $instances_path"
"This is NOT full path - just a folder name"
"For per-compute-host cached images, Set to _base_$my_ip"),
cfg.StrOpt('compute_driver',
default='nova.virt.connection.get_connection',
help='Driver to use for controlling virtualization'),

View File

@ -36,6 +36,7 @@ from nova.virt.libvirt import utils as virtutils
flags.DECLARE('instances_path', 'nova.compute.manager')
flags.DECLARE('base_dir_name', 'nova.compute.manager')
FLAGS = flags.FLAGS
LOG = log.getLogger(__name__)
@ -155,7 +156,7 @@ class ImageCacheManagerTestCase(test.TestCase):
self.stubs.Set(virtutils, 'get_disk_backing_file',
lambda x: 'e97222e91fc4241f49a7f520d1dcf446751129b3_sm')
found = os.path.join(FLAGS.instances_path, '_base',
found = os.path.join(FLAGS.instances_path, FLAGS.base_dir_name,
'e97222e91fc4241f49a7f520d1dcf446751129b3_sm')
image_cache_manager = imagecache.ImageCacheManager()
@ -177,7 +178,7 @@ class ImageCacheManagerTestCase(test.TestCase):
lambda x: ('e97222e91fc4241f49a7f520d1dcf446751129b3_'
'10737418240'))
found = os.path.join(FLAGS.instances_path, '_base',
found = os.path.join(FLAGS.instances_path, FLAGS.base_dir_name,
'e97222e91fc4241f49a7f520d1dcf446751129b3_'
'10737418240')
@ -198,7 +199,7 @@ class ImageCacheManagerTestCase(test.TestCase):
self.stubs.Set(virtutils, 'get_disk_backing_file',
lambda x: 'e97222e91fc4241f49a7f520d1dcf446751129b3_sm')
found = os.path.join(FLAGS.instances_path, '_base',
found = os.path.join(FLAGS.instances_path, FLAGS.base_dir_name,
'e97222e91fc4241f49a7f520d1dcf446751129b3_sm')
image_cache_manager = imagecache.ImageCacheManager()
@ -521,6 +522,7 @@ class ImageCacheManagerTestCase(test.TestCase):
hashed_42 = '92cfceb39d57d914ed8b14d0e37643de0797ae56'
self.flags(instances_path='/instance_path')
self.flags(base_dir_name='_base')
self.flags(remove_unused_base_images=True)
base_file_list = ['00000001',

View File

@ -322,7 +322,7 @@ class CacheConcurrencyTestCase(test.TestCase):
self.flags(instances_path='nova.compute.manager')
def fake_exists(fname):
basedir = os.path.join(FLAGS.instances_path, '_base')
basedir = os.path.join(FLAGS.instances_path, FLAGS.base_dir_name)
if fname == basedir:
return True
return False
@ -1317,9 +1317,10 @@ class LibvirtConnTestCase(test.TestCase):
if os.path.isdir(path):
shutil.rmtree(path)
path = os.path.join(FLAGS.instances_path, '_base')
path = os.path.join(FLAGS.instances_path, FLAGS.base_dir_name)
if os.path.isdir(path):
shutil.rmtree(os.path.join(FLAGS.instances_path, '_base'))
shutil.rmtree(os.path.join(FLAGS.instances_path,
FLAGS.base_dir_name))
def test_get_host_ip_addr(self):
conn = connection.LibvirtConnection(False)

View File

@ -1090,7 +1090,8 @@ class LibvirtConnection(driver.ComputeDriver):
generating = 'image_id' not in kwargs
if not os.path.exists(target):
base_dir = os.path.join(FLAGS.instances_path, '_base')
base_dir = os.path.join(FLAGS.instances_path, FLAGS.base_dir_name)
if not os.path.exists(base_dir):
libvirt_utils.ensure_tree(base_dir)
base = os.path.join(base_dir, fname)

View File

@ -58,6 +58,7 @@ imagecache_opts = [
]
flags.DECLARE('instances_path', 'nova.compute.manager')
flags.DECLARE('base_dir_name', 'nova.compute.manager')
FLAGS = flags.FLAGS
FLAGS.register_opts(imagecache_opts)
@ -178,7 +179,8 @@ class ImageCacheManager(object):
'backing': backing_file})
backing_path = os.path.join(FLAGS.instances_path,
'_base', backing_file)
FLAGS.base_dir_name,
backing_file)
if not backing_path in inuse_images:
inuse_images.append(backing_path)
@ -372,7 +374,7 @@ class ImageCacheManager(object):
# created, but may remain from previous versions.
self._reset_state()
base_dir = os.path.join(FLAGS.instances_path, '_base')
base_dir = os.path.join(FLAGS.instances_path, FLAGS.base_dir_name)
if not os.path.exists(base_dir):
LOG.debug(_('Skipping verification, no base directory at %s'),
base_dir)