From a2dd9e97808fa3dd2247e35d89dbe36c3692ff79 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sun, 3 Nov 2013 18:03:39 +0100 Subject: [PATCH] feature #2357: When creating a Datastore, if a wrong DISK_TYPE is specified an error is reported --- include/Image.h | 3 ++- src/datastore/Datastore.cc | 11 +++++++++-- src/image/Image.cc | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/Image.h b/include/Image.h index b777f1d51e..d9a222f704 100644 --- a/include/Image.h +++ b/include/Image.h @@ -80,7 +80,8 @@ public: BLOCK = 2, /** < Block-device disk */ RBD = 3, /** < CEPH RBD disk */ RBD_CDROM = 4, /** < CEPH RBD CDROM disk */ - GLUSTER = 5 /** < Gluster Block Device */ + GLUSTER = 5, /** < Gluster Block Device */ + NONE = 255 /** < No disk type, error situation */ }; /** diff --git a/src/datastore/Datastore.cc b/src/datastore/Datastore.cc index 98043ad636..6c6d4cc918 100644 --- a/src/datastore/Datastore.cc +++ b/src/datastore/Datastore.cc @@ -297,14 +297,17 @@ int Datastore::insert(SqlDB *db, string& error_str) base_path = oss.str(); - disk_type = Image::FILE; - erase_template_attribute("DISK_TYPE", s_disk_type); if ( type == IMAGE_DS ) { disk_type = Image::str_to_disk_type(s_disk_type); + if (disk_type == Image::NONE) + { + goto error_disk_type; + } + add_template_attribute("DISK_TYPE", Image::disk_type_to_str(disk_type)); } @@ -332,6 +335,10 @@ error_empty_tm: error_str = "No TM_MAD in template."; goto error_common; +error_disk_type: + error_str = "Unknown DISK_TYPE in template."; + goto error_common; + error_common: NebulaLog::log("DATASTORE", Log::ERROR, error_str); return -1; diff --git a/src/image/Image.cc b/src/image/Image.cc index 3cae35a894..9f144b0806 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -732,7 +732,7 @@ Image::ImageType Image::str_to_type(string& str_type) Image::DiskType Image::str_to_disk_type(string& s_disk_type) { - Image::DiskType type = FILE; + Image::DiskType type = NONE; one_util::toupper(s_disk_type);