diff --git a/include/Datastore.h b/include/Datastore.h
index 8bce2ed79a..df9f2df319 100644
--- a/include/Datastore.h
+++ b/include/Datastore.h
@@ -51,7 +51,7 @@ public:
int add_image(int id)
{
return add_collection_id(id);
- }
+ };
/**
* Deletes this image's ID from the set.
@@ -61,7 +61,25 @@ public:
int del_image(int id)
{
return del_collection_id(id);
- }
+ };
+
+ /**
+ * Retrieves TM mad name
+ * @return string tm mad name
+ */
+ const string& get_tm_mad() const
+ {
+ return tm_mad;
+ };
+
+ /**
+ * Modifies the given VM disk attribute adding the relevant datastore
+ * attributes
+ *
+ * @param disk
+ * @return 0 on success
+ */
+ int disk_attribute(VectorAttribute * disk);
private:
@@ -80,6 +98,11 @@ private:
*/
string type;
+ /**
+ * Name of the TM driver used to transfer file to and from the hosts
+ */
+ string tm_mad;
+
/**
* Base path for the storage
*/
diff --git a/include/DatastorePool.h b/include/DatastorePool.h
index 3d68f48f97..da9bf3aacc 100644
--- a/include/DatastorePool.h
+++ b/include/DatastorePool.h
@@ -29,8 +29,10 @@ public:
DatastorePool(SqlDB * db,
const string& system_base_path,
const string& system_type,
+ const string& system_tm_mad,
const string& default_base_path,
- const string& default_type);
+ const string& default_type,
+ const string& default_tm_mad);
~DatastorePool(){};
diff --git a/share/etc/oned.conf b/share/etc/oned.conf
index fb762b4b21..d99bea70ba 100644
--- a/share/etc/oned.conf
+++ b/share/etc/oned.conf
@@ -107,12 +107,14 @@ MAC_PREFIX = "02:00"
SYSTEM_DS = [
base_path = "/var/lib/one/system_ds",
- type = "fs"
+ type = "fs",
+ tm_mad = "tm_shared"
]
DEFAULT_DS = [
base_path = "/var/lib/one/images",
- type = "fs"
+ type = "fs",
+ tm_mad = "tm_shared"
]
DEFAULT_IMAGE_TYPE = "OS"
diff --git a/src/datastore/Datastore.cc b/src/datastore/Datastore.cc
index 4ae45fabe6..a6bfe8e1ea 100644
--- a/src/datastore/Datastore.cc
+++ b/src/datastore/Datastore.cc
@@ -38,6 +38,7 @@ Datastore::Datastore(int id,
PoolObjectSQL(id,DATASTORE,"",-1,-1,"","",table),
ObjectCollection("IMAGES"),
type(""),
+ tm_mad(""),
base_path("")
{
if (ds_template != 0)
@@ -50,6 +51,22 @@ Datastore::Datastore(int id,
}
}
+/* ------------------------------------------------------------------------ */
+/* ------------------------------------------------------------------------ */
+
+int Datastore::disk_attribute(VectorAttribute * disk)
+{
+ ostringstream oss;
+
+ oss << oid;
+
+ disk->replace("DATASTORE", get_name());
+ disk->replace("DATASTORE_ID", oss.str());
+ disk->replace("TM_MAD", get_tm_mad());
+
+ return 0;
+}
+
/* ************************************************************************ */
/* Datastore :: Database Access Functions */
/* ************************************************************************ */
@@ -65,7 +82,6 @@ int Datastore::insert(SqlDB *db, string& error_str)
// Check default datastore attributes
// ---------------------------------------------------------------------
-
erase_template_attribute("NAME", name);
// NAME is checked in DatastorePool::allocate
@@ -76,6 +92,13 @@ int Datastore::insert(SqlDB *db, string& error_str)
goto error_type;
}
+ erase_template_attribute("TM_MAD", tm_mad);
+
+ if ( tm_mad.empty() == true )
+ {
+ goto error_tm;
+ }
+
erase_template_attribute("BASE_PATH", base_path);
if ( base_path.empty() == true )
@@ -95,6 +118,10 @@ error_type:
error_str = "No TYPE in template.";
goto error_common;
+error_tm:
+ error_str = "No TM_MAD in template.";
+ goto error_common;
+
error_base_path:
error_str = "No BASE_PATH in template.";
goto error_common;
@@ -207,6 +234,7 @@ string& Datastore::to_xml(string& xml) const
"" << oid << "" <<
"" << name << "" <<
"" << type << "" <<
+ "" << tm_mad << "" <<
"" << base_path << "" <<
collection_xml <<
"";
@@ -231,6 +259,7 @@ int Datastore::from_xml(const string& xml)
rc += xpath(oid, "/DATASTORE/ID", -1);
rc += xpath(name, "/DATASTORE/NAME", "not_found");
rc += xpath(type, "/DATASTORE/TYPE", "not_found");
+ rc += xpath(tm_mad, "/DATASTORE/TM_MAD", "not_found");
rc += xpath(base_path, "/DATASTORE/BASE_PATH", "not_found");
// Set the owner and group to oneadmin
diff --git a/src/datastore/DatastorePool.cc b/src/datastore/DatastorePool.cc
index d5e9644cdf..f2f96da820 100644
--- a/src/datastore/DatastorePool.cc
+++ b/src/datastore/DatastorePool.cc
@@ -38,8 +38,10 @@ const int DatastorePool::DEFAULT_DS_ID = 1;
DatastorePool::DatastorePool(SqlDB * db,
const string& system_base_path,
const string& system_type,
+ const string& system_tm_mad,
const string& default_base_path,
- const string& default_type):
+ const string& default_type,
+ const string& default_tm_mad):
PoolSQL(db, Datastore::table)
{
ostringstream oss;
@@ -55,7 +57,8 @@ DatastorePool::DatastorePool(SqlDB * db,
oss << "NAME = " << SYSTEM_DS_NAME << endl
<< "BASE_PATH = " << system_base_path << endl
- << "TYPE = " << system_type;
+ << "TYPE = " << system_type << endl
+ << "TM_MAD = " << system_tm_mad;
ds_tmpl = new DatastoreTemplate;
rc = ds_tmpl->parse_str_or_xml(oss.str(), error_str);
@@ -78,7 +81,8 @@ DatastorePool::DatastorePool(SqlDB * db,
oss << "NAME = " << DEFAULT_DS_NAME << endl
<< "BASE_PATH = " << default_base_path << endl
- << "TYPE = " << default_type;
+ << "TYPE = " << default_type << endl
+ << "TM_MAD = " << default_tm_mad;
ds_tmpl = new DatastoreTemplate;
rc = ds_tmpl->parse_str_or_xml(oss.str(), error_str);
@@ -103,6 +107,7 @@ DatastorePool::DatastorePool(SqlDB * db,
return;
error_bootstrap:
+ oss.str("");
oss << "Error trying to create default datastore: " << error_str;
NebulaLog::log("DATASTORE",Log::ERROR,oss);
diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc
index 2f7275cf22..1845fc5e13 100644
--- a/src/image/ImagePool.cc
+++ b/src/image/ImagePool.cc
@@ -221,11 +221,14 @@ int ImagePool::disk_attribute(VectorAttribute * disk,
string source;
Image * img = 0;
int rc = 0;
+ int datastore_id;
ostringstream oss;
- Nebula& nd = Nebula::instance();
- ImageManager * imagem = nd.get_imagem();
+ Nebula& nd = Nebula::instance();
+ ImageManager * imagem = nd.get_imagem();
+ DatastorePool * ds_pool = nd.get_dspool();
+ Datastore * ds = 0;
if (!(source = disk->vector_value("IMAGE")).empty())
{
@@ -287,11 +290,23 @@ int ImagePool::disk_attribute(VectorAttribute * disk,
{
img->disk_attribute(disk, index, img_type);
- image_id = img->get_oid();
-
+ image_id = img->get_oid();
+ datastore_id = img->get_ds_id();
+
update(img);
img->unlock();
+
+ ds = ds_pool->get(datastore_id, true);
+
+ if ( ds == 0 )
+ {
+ return -1;
+ }
+
+ ds->disk_attribute(disk);
+
+ ds->unlock();
}
oss << disk_id;
diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc
index f414535537..a11504e9e2 100644
--- a/src/nebula/Nebula.cc
+++ b/src/nebula/Nebula.cc
@@ -278,10 +278,12 @@ void Nebula::start()
vector system_ds;
string system_ds_base_path;
string system_ds_type;
+ string system_tm_mad;
vector default_ds;
string default_ds_base_path;
string default_ds_type;
+ string default_tm_mad;
vector vm_hooks;
vector host_hooks;
@@ -328,6 +330,7 @@ void Nebula::start()
system_ds_base_path = ds_conf->vector_value("BASE_PATH");
system_ds_type = ds_conf->vector_value("TYPE");
+ system_tm_mad = ds_conf->vector_value("TM_MAD");
nebula_configuration->get("DEFAULT_DS", default_ds);
@@ -335,10 +338,11 @@ void Nebula::start()
default_ds_base_path = ds_conf->vector_value("BASE_PATH");
default_ds_type = ds_conf->vector_value("TYPE");
+ default_tm_mad = ds_conf->vector_value("TM_MAD");
dspool = new DatastorePool(db,
- system_ds_base_path, system_ds_type,
- default_ds_base_path, default_ds_type);
+ system_ds_base_path, system_ds_type, system_tm_mad,
+ default_ds_base_path, default_ds_type, default_tm_mad);
}
catch (exception&)
{
diff --git a/src/nebula/NebulaTemplate.cc b/src/nebula/NebulaTemplate.cc
index 96a0a89c53..f6d56b30c9 100644
--- a/src/nebula/NebulaTemplate.cc
+++ b/src/nebula/NebulaTemplate.cc
@@ -189,7 +189,8 @@ void OpenNebulaTemplate::set_conf_default()
//SYSTEM_DS
vvalue.clear();
vvalue.insert(make_pair("BASE_PATH","/var/lib/one/system_ds"));
- vvalue.insert(make_pair("TYPE","fs"));
+ vvalue.insert(make_pair("TYPE", "fs"));
+ vvalue.insert(make_pair("TM_MAD", "tm_shared"));
vattribute = new VectorAttribute("SYSTEM_DS",vvalue);
conf_default.insert(make_pair(vattribute->name(),vattribute));
@@ -197,7 +198,8 @@ void OpenNebulaTemplate::set_conf_default()
//DEFAULT_DS
vvalue.clear();
vvalue.insert(make_pair("BASE_PATH","/var/lib/one/images"));
- vvalue.insert(make_pair("TYPE","fs"));
+ vvalue.insert(make_pair("TYPE", "fs"));
+ vvalue.insert(make_pair("TM_MAD", "tm_shared"));
vattribute = new VectorAttribute("DEFAULT_DS",vvalue);
conf_default.insert(make_pair(vattribute->name(),vattribute));