mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
Ensure that if the destination DS when cloning an image have a DRIVER set. The image is automatically converted during the cloning process for the fs driver. (cherry picked from commit 69759b30cc1e7cc429c1bc0cc5df44e070942182)
This commit is contained in:
parent
7961ae2416
commit
b27302cc7d
@ -47,18 +47,28 @@ while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/DRIVER \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/PATH)
|
||||
|
||||
unset i
|
||||
|
||||
BASE_PATH="${XPATH_ELEMENTS[i++]}"
|
||||
BRIDGE_LIST="${XPATH_ELEMENTS[i++]}"
|
||||
DRIVER="${XPATH_ELEMENTS[i++]}"
|
||||
SRC="${XPATH_ELEMENTS[i++]}"
|
||||
|
||||
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS"
|
||||
|
||||
DST=`generate_image_path`
|
||||
|
||||
# ------------ Check if format conversion is required -------------
|
||||
|
||||
if [ "$DRIVER" = 'qcow2' ] || [ "$DRIVER" = 'raw' ]; then
|
||||
CP_CMD="$QEMU_IMG convert -O $DRIVER $SRC $DST"
|
||||
else
|
||||
CP_CMD="cp -f $SRC $DST"
|
||||
fi
|
||||
|
||||
# ------------ Copy the image to the repository -------------
|
||||
|
||||
if [ -n "$BRIDGE_LIST" ]; then
|
||||
@ -68,7 +78,7 @@ if [ -n "$BRIDGE_LIST" ]; then
|
||||
CMD=$(cat <<EOF
|
||||
set -e -o pipefail
|
||||
mkdir -p $BASE_PATH
|
||||
cp -f $SRC $DST
|
||||
$CP_CMD
|
||||
EOF
|
||||
)
|
||||
|
||||
@ -76,7 +86,7 @@ EOF
|
||||
else
|
||||
log "Copying local image $SRC to the image repository"
|
||||
mkdir -p "$BASE_PATH"
|
||||
exec_and_log "cp -f $SRC $DST" "Error copying $SRC to $DST"
|
||||
exec_and_log "$CP_CMD" "Error copying $SRC to $DST"
|
||||
fi
|
||||
|
||||
echo "$DST"
|
||||
echo "$DST $DRIVER"
|
||||
|
@ -155,10 +155,18 @@ error_common:
|
||||
|
||||
void ImageManager::_clone(unique_ptr<image_msg_t> msg)
|
||||
{
|
||||
NebulaLog::dddebug("ImM", "_clone: " + msg->payload());
|
||||
const auto& info = msg->payload();
|
||||
|
||||
int cloning_id;
|
||||
int ds_id = -1;
|
||||
string source, format;
|
||||
|
||||
ostringstream oss;
|
||||
istringstream is(info);
|
||||
|
||||
NebulaLog::dddebug("ImM", "_clone: " + info);
|
||||
|
||||
is >> skipws;
|
||||
|
||||
auto image = ipool->get(msg->oid());
|
||||
|
||||
@ -166,12 +174,12 @@ void ImageManager::_clone(unique_ptr<image_msg_t> msg)
|
||||
{
|
||||
if (msg->status() == "SUCCESS")
|
||||
{
|
||||
ostringstream oss;
|
||||
is >> source;
|
||||
|
||||
if (!msg->payload().empty())
|
||||
if (!source.empty())
|
||||
{
|
||||
oss << "CLONE operation succeeded but image no longer exists."
|
||||
<< " Source image: " << msg->payload()
|
||||
<< " Source image: " << source
|
||||
<< ", may be left in datastore";
|
||||
|
||||
NebulaLog::log("ImM", Log::ERROR, oss);
|
||||
@ -189,7 +197,21 @@ void ImageManager::_clone(unique_ptr<image_msg_t> msg)
|
||||
goto error;
|
||||
}
|
||||
|
||||
image->set_source(msg->payload());
|
||||
is >> source;
|
||||
|
||||
if (is.fail())
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
image->set_source(source);
|
||||
|
||||
is >> format;
|
||||
|
||||
if (!format.empty())
|
||||
{
|
||||
image->set_format(format);
|
||||
}
|
||||
|
||||
image->set_state_unlock();
|
||||
|
||||
@ -208,12 +230,8 @@ void ImageManager::_clone(unique_ptr<image_msg_t> msg)
|
||||
return;
|
||||
|
||||
error:
|
||||
ostringstream oss;
|
||||
|
||||
oss << "Error cloning from Image " << cloning_id;
|
||||
|
||||
const auto& info = msg->payload();
|
||||
|
||||
if (!info.empty() && (info[0] != '-'))
|
||||
{
|
||||
oss << ": " << info;
|
||||
|
Loading…
x
Reference in New Issue
Block a user