mirror of
https://github.com/OpenNebula/one.git
synced 2025-02-27 13:57:23 +03:00
feature #3782: Delete operations for image snapshots. Core image manager
and driver functions
This commit is contained in:
parent
28d3dcb82d
commit
1bd6ffe60a
@ -199,6 +199,15 @@ public:
|
||||
*/
|
||||
void set_image_snapshots(int iid, const Snapshots& s, bool failed);
|
||||
|
||||
/**
|
||||
* Deletes the snapshot of an image
|
||||
* @param iid id of image
|
||||
* @param sid id of the snapshot
|
||||
* @param error_str Error reason, if any
|
||||
* @return 0 on success
|
||||
*/
|
||||
int delete_snapshot(int iid, int sid, string& error);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Generic name for the Image driver
|
||||
|
@ -114,6 +114,27 @@ private:
|
||||
* @param drv_msg xml data for the mad operation.
|
||||
*/
|
||||
void monitor(int oid, const string& drv_msg) const;
|
||||
|
||||
/**
|
||||
* Sends a delete snapshot command: "SNAP_DELETE DS_ID DS_XML"
|
||||
* @param oid the datastore id.
|
||||
* @param drv_msg xml data for the mad operation.
|
||||
*/
|
||||
void snapshot_delete(int oid, const string& drv_msg) const;
|
||||
|
||||
/**
|
||||
* Sends a revert snapshot command: "SNAP_REVERT DS_ID DS_XML"
|
||||
* @param oid the datastore id.
|
||||
* @param drv_msg xml data for the mad operation.
|
||||
*/
|
||||
void snapshot_revert(int oid, const string& drv_msg) const;
|
||||
|
||||
/**
|
||||
* Sends a flatten snapshot command: "SNAP_FLATTEN DS_ID DS_XML"
|
||||
* @param oid the datastore id.
|
||||
* @param drv_msg xml data for the mad operation.
|
||||
*/
|
||||
void snapshot_flatten(int oid, const string& drv_msg) const;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -941,3 +941,78 @@ void ImageManager::set_image_snapshots(int iid, const Snapshots& s, bool failed)
|
||||
|
||||
img->unlock();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ImageManager::delete_snapshot(int iid, int sid, string& error)
|
||||
{
|
||||
const ImageManagerDriver* imd = get();
|
||||
|
||||
if ( imd == 0 )
|
||||
{
|
||||
error = "Could not get datastore driver";
|
||||
NebulaLog::log("ImM",Log::ERROR, error);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
Image * img = ipool->get(iid,true);
|
||||
|
||||
if ( img == 0 )
|
||||
{
|
||||
error = "Image does not exist";
|
||||
return -1;
|
||||
}
|
||||
|
||||
const Snapshots& snaps = img->get_snapshots();
|
||||
|
||||
if (!snaps.test_delete(sid, error))
|
||||
{
|
||||
img->unlock();
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ds_id = img->get_ds_id();
|
||||
|
||||
img->unlock();
|
||||
|
||||
string ds_data;
|
||||
|
||||
Datastore * ds = dspool->get(ds_id, true);
|
||||
|
||||
if ( ds == 0 )
|
||||
{
|
||||
error = "Datastore no longer exists";
|
||||
return -1;
|
||||
}
|
||||
|
||||
ds->to_xml(ds_data);
|
||||
|
||||
ds->unlock();
|
||||
|
||||
img = ipool->get(iid,true);
|
||||
|
||||
if ( img == 0 )
|
||||
{
|
||||
error = "Image does not exist";
|
||||
return -1;
|
||||
}
|
||||
|
||||
img->set_target_snapshot(sid);
|
||||
|
||||
string img_tmpl;
|
||||
string * drv_msg = format_message(img->to_xml(img_tmpl), ds_data);
|
||||
|
||||
imd->snapshot_delete(iid, *drv_msg);
|
||||
|
||||
ipool->update(img);
|
||||
|
||||
img->unlock();
|
||||
|
||||
delete drv_msg;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -93,6 +93,39 @@ void ImageManagerDriver::monitor(int oid, const string& drv_msg) const
|
||||
write(os);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void ImageManagerDriver::snapshot_delete(int oid, const string& drv_msg) const
|
||||
{
|
||||
ostringstream os;
|
||||
|
||||
os << "SNAP_DELETE " << oid << " " << drv_msg << endl;
|
||||
|
||||
write(os);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void ImageManagerDriver::snapshot_revert(int oid, const string& drv_msg) const
|
||||
{
|
||||
ostringstream os;
|
||||
|
||||
os << "SNAP_REVERT " << oid << " " << drv_msg << endl;
|
||||
|
||||
write(os);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void ImageManagerDriver::snapshot_flatten(int oid, const string& drv_msg) const
|
||||
{
|
||||
ostringstream os;
|
||||
|
||||
os << "SNAP_FLATTEN " << oid << " " << drv_msg << endl;
|
||||
|
||||
write(os);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@ -666,6 +699,60 @@ static void monitor_action(istringstream& is,
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
static void snap_delete_action(istringstream& is,
|
||||
ImagePool* ipool,
|
||||
int id,
|
||||
const string& result)
|
||||
{
|
||||
ostringstream oss;
|
||||
string info;
|
||||
|
||||
Image * image = ipool->get(id, true);
|
||||
|
||||
if ( image == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int snap_id = image->get_target_snapshot();
|
||||
|
||||
if (snap_id == -1)
|
||||
{
|
||||
NebulaLog::log("ImM", Log::ERROR, "No target snapshot in callback");
|
||||
|
||||
image->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( result == "SUCCESS")
|
||||
{
|
||||
image->delete_snapshot(snap_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << "Error removing snapshot " << snap_id << " from image " << id;
|
||||
|
||||
getline(is, info);
|
||||
|
||||
if (!info.empty() && (info[0] != '-'))
|
||||
{
|
||||
oss << ": " << info;
|
||||
}
|
||||
|
||||
image->set_template_error_message(oss.str());
|
||||
|
||||
NebulaLog::log("ImM", Log::ERROR, oss);
|
||||
}
|
||||
|
||||
image->clear_target_snapshot();
|
||||
|
||||
ipool->update(image);
|
||||
|
||||
image->unlock();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@ -717,30 +804,34 @@ void ImageManagerDriver::protocol(const string& message) const
|
||||
else
|
||||
return;
|
||||
|
||||
if ( action == "STAT" )
|
||||
if (action == "STAT")
|
||||
{
|
||||
stat_action(is, id, result);
|
||||
}
|
||||
else if ( action == "CP" )
|
||||
else if (action == "CP")
|
||||
{
|
||||
ds_id = cp_action(is, ipool, id, result);
|
||||
}
|
||||
else if ( action == "CLONE" )
|
||||
else if (action == "CLONE")
|
||||
{
|
||||
ds_id = clone_action(is, ipool, id, result);
|
||||
}
|
||||
else if ( action == "MKFS" )
|
||||
else if (action == "MKFS")
|
||||
{
|
||||
ds_id = mkfs_action(is, ipool, id, result);
|
||||
}
|
||||
else if ( action == "RM" )
|
||||
else if (action == "RM")
|
||||
{
|
||||
ds_id = rm_action(is, ipool, id, result);
|
||||
}
|
||||
else if ( action == "MONITOR" )
|
||||
else if (action == "MONITOR")
|
||||
{
|
||||
monitor_action(is, dspool, id, result);
|
||||
}
|
||||
else if (action == "SNAP_DELETE")
|
||||
{
|
||||
snap_delete_action(is, ipool, id, result);
|
||||
}
|
||||
else if (action == "LOG")
|
||||
{
|
||||
getline(is,info);
|
||||
|
Loading…
x
Reference in New Issue
Block a user