From bc6ae465d919cee8cb8c929745001a5193d72ae3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 21 Nov 2013 16:01:35 +0100 Subject: [PATCH] Feature #2479: Allow CONTEXT/DEV_PREFIX, and make 'hd' the default prefix for cdrom type disks --- include/ImagePool.h | 10 ++++++++++ src/image/Image.cc | 23 ++++++++++++++++++++--- src/image/ImagePool.cc | 3 +++ src/vm/VirtualMachine.cc | 9 ++++++++- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/include/ImagePool.h b/include/ImagePool.h index 27d039c1a3..bad9d59ab1 100644 --- a/include/ImagePool.h +++ b/include/ImagePool.h @@ -185,6 +185,11 @@ public: return _default_dev_prefix; }; + static const string& default_cdrom_dev_prefix() + { + return _default_cdrom_dev_prefix; + }; + /** * Get the effective uid to get an image. Used in VM parsers * @param disk a vector attribute with the image data @@ -215,6 +220,11 @@ private: **/ static string _default_dev_prefix; + /** + * Default device prefix for cdrom disks + **/ + static string _default_cdrom_dev_prefix; + /** * Image attributes to be inherited into the VM disk */ diff --git a/src/image/Image.cc b/src/image/Image.cc index 935aed30f9..56a1559dfc 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -148,8 +148,18 @@ int Image::insert(SqlDB *db, string& error_str) if( dev_prefix.empty() ) { - SingleAttribute * dev_att = new SingleAttribute("DEV_PREFIX", - ImagePool::default_dev_prefix()); + if (type == CDROM) + { + dev_prefix = ImagePool::default_cdrom_dev_prefix(); + } + else + { + dev_prefix = ImagePool::default_dev_prefix(); + } + + SingleAttribute * dev_att = + new SingleAttribute("DEV_PREFIX", dev_prefix); + obj_template->set(dev_att); } break; @@ -508,7 +518,14 @@ int Image::disk_attribute( VectorAttribute * disk, if (dev_prefix.empty())//Removed from image template, get it again { - dev_prefix = ImagePool::default_dev_prefix(); + if ( type == CDROM ) + { + dev_prefix = ImagePool::default_cdrom_dev_prefix(); + } + else + { + dev_prefix = ImagePool::default_dev_prefix(); + } } disk->replace("DEV_PREFIX", dev_prefix); diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index b2f7cff44d..a7341f5b9c 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -27,6 +27,7 @@ /* -------------------------------------------------------------------------- */ string ImagePool::_default_type; string ImagePool::_default_dev_prefix; +string ImagePool::_default_cdrom_dev_prefix; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -46,6 +47,8 @@ ImagePool::ImagePool( _default_type = __default_type; _default_dev_prefix = __default_dev_prefix; + _default_cdrom_dev_prefix = "hd"; + // Init inherit attributes vector::const_iterator it; diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index bc0185519d..da2b0593fc 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -1682,7 +1682,14 @@ int VirtualMachine::get_disk_images(string& error_str) } else { - cdrom_disks.push(make_pair(ipool->default_dev_prefix(), disk)); + dev_prefix = disk->vector_value("DEV_PREFIX"); + + if ( dev_prefix.empty() ) + { + dev_prefix = ipool->default_cdrom_dev_prefix(); + } + + cdrom_disks.push(make_pair(dev_prefix, disk)); } // Disk IDs are 0..num-1, context disk is is num