1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-23 21:57:43 +03:00

feature #523: work on the release image methods

This commit is contained in:
Ruben S. Montero 2011-03-24 16:37:15 +01:00
parent 23ea7a6a97
commit 9db8829d35
5 changed files with 69 additions and 12 deletions

View File

@ -94,6 +94,15 @@ public:
return (persistent_img == 1); return (persistent_img == 1);
}; };
/**
* Returns the source path of the image
* @return source of image
*/
const string& get_source()
{
return source;
}
/** /**
* Returns the image state * Returns the image state
* @return state of image * @return state of image

View File

@ -172,6 +172,13 @@ private:
* @return 0 on success * @return 0 on success
*/ */
int acquire_image(Image *img); int acquire_image(Image *img);
/**
* Moves a file to an image in the repository
* @param image to be updated (it's source attribute)
* @param source path of the disk file
*/
void move_image(Image *img, const string& source);
}; };
#endif /*IMAGE_MANAGER_H*/ #endif /*IMAGE_MANAGER_H*/

View File

@ -70,7 +70,7 @@ private:
*/ */
//Template driver_conf; //Template driver_conf;
void cp(int oid, const string& source, const string& destination); void cp(int oid, const string& source, const string& destination) const;
/** /**
* Sends a move request to the MAD: "MV IMAGE_ID SRC_PATH DST_PATH" * Sends a move request to the MAD: "MV IMAGE_ID SRC_PATH DST_PATH"
@ -78,7 +78,7 @@ private:
* @param destination is the path to the image to be created * @param destination is the path to the image to be created
* @param size_mb of the image to be created * @param size_mb of the image to be created
*/ */
void mv(int oid, const string& source, const string& destination); void mv(int oid, const string& source, const string& destination) const;
/** /**
* Sends a make filesystem request to the MAD: "MKFS IMAGE_ID PATH SIZE_MB" * Sends a make filesystem request to the MAD: "MKFS IMAGE_ID PATH SIZE_MB"
@ -87,14 +87,17 @@ private:
* @param fs type * @param fs type
* @param size_mb of the image to be created * @param size_mb of the image to be created
*/ */
void mkfs(int oid, const string& destination, const string& fs, int size_mb); void mkfs(int oid,
const string& destination,
const string& fs,
int size_mb) const;
/** /**
* Sends a delete request to the MAD: "DELETE IMAGE_ID PATH" * Sends a delete request to the MAD: "DELETE IMAGE_ID PATH"
* @param oid the image id. * @param oid the image id.
* @param destination is the path to the image to be removed * @param destination is the path to the image to be removed
*/ */
void rm(int oid, const string& destination); void rm(int oid, const string& destination) const;
}; };
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */

View File

@ -80,6 +80,7 @@ int ImageManager::acquire_image(Image *img)
case Image::READY: case Image::READY:
img->inc_running(); img->inc_running();
img->set_state(Image::USED); img->set_state(Image::USED);
ipool->update(img);
break; break;
case Image::USED: case Image::USED:
@ -90,6 +91,7 @@ int ImageManager::acquire_image(Image *img)
else else
{ {
img->inc_running(); img->inc_running();
ipool->update(img);
} }
break; break;
@ -103,6 +105,28 @@ int ImageManager::acquire_image(Image *img)
return rc; return rc;
} }
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void ImageManager::move_image(Image *img, const string& source)
{
const ImageManagerDriver* imd = get();
ostringstream oss;
if ( imd == 0 )
{
NebulaLog::log("ImM",Log::ERROR,
"Could not get driver to update repository");
return;
}
oss << "Moving disk " << source << " to repository image "
<< img->get_oid() << " as " << img->get_source();
imd->mv(img->get_oid(),source,img->get_source());
NebulaLog::log("ImM",Log::INFO,oss);
}
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -120,6 +144,8 @@ void ImageManager::release_image(const string& image_id,
istringstream iss; istringstream iss;
Image * img; Image * img;
ostringstream disk_file;
iss.str(image_id); iss.str(image_id);
iss >> iid; iss >> iid;
@ -145,12 +171,15 @@ void ImageManager::release_image(const string& image_id,
if ( img->isPersistent() ) if ( img->isPersistent() )
{ {
disk_file << disk_path << "/disk." << disk_num;
img->set_state(Image::LOCKED); img->set_state(Image::LOCKED);
//TODO issue move from disk to source (imgage) move_image(img,disk_file.str());
ipool->update(img);
img->unlock(); img->unlock();
} }
else else
{ {
@ -159,6 +188,8 @@ void ImageManager::release_image(const string& image_id,
img->set_state(Image::READY); img->set_state(Image::READY);
} }
ipool->update(img);
img->unlock(); img->unlock();
if ( sid != -1 ) if ( sid != -1 )
@ -167,10 +198,15 @@ void ImageManager::release_image(const string& image_id,
if ( img == 0 ) if ( img == 0 )
{ {
//TODO Warning in oned.log NebulaLog::log("ImM",Log::ERROR,
"Could not get image to saveas disk.");
} }
else
{
disk_file << disk_path << "/disk." << disk_num;
//TODO issue move from disk to source (save_image) move_image(img,disk_file.str());
}
img->unlock(); img->unlock();
} }
@ -181,6 +217,8 @@ void ImageManager::release_image(const string& image_id,
case Image::READY: case Image::READY:
case Image::ERROR: case Image::ERROR:
case Image::LOCKED: case Image::LOCKED:
NebulaLog::log("ImM",Log::ERROR,
"Trying to release image in wrong state.");
default: default:
img->unlock(); img->unlock();
break; break;

View File

@ -28,7 +28,7 @@
void ImageManagerDriver::cp(int oid, void ImageManagerDriver::cp(int oid,
const string& source, const string& source,
const string& destination) const string& destination) const
{ {
ostringstream os; ostringstream os;
@ -41,7 +41,7 @@ void ImageManagerDriver::cp(int oid,
void ImageManagerDriver::mv(int oid, void ImageManagerDriver::mv(int oid,
const string& source, const string& source,
const string& destination) const string& destination) const
{ {
ostringstream os; ostringstream os;
@ -55,7 +55,7 @@ void ImageManagerDriver::mv(int oid,
void ImageManagerDriver::mkfs(int oid, void ImageManagerDriver::mkfs(int oid,
const string& destination, const string& destination,
const string& fs, const string& fs,
int size_mb) int size_mb) const
{ {
ostringstream os; ostringstream os;
@ -66,7 +66,7 @@ void ImageManagerDriver::mkfs(int oid,
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
void ImageManagerDriver::rm(int oid, const string& destination) void ImageManagerDriver::rm(int oid, const string& destination) const
{ {
ostringstream os; ostringstream os;