diff --git a/src/datastore_mad/remotes/fs/clone b/src/datastore_mad/remotes/fs/clone index 2ac4ea9fe7..257e930427 100755 --- a/src/datastore_mad/remotes/fs/clone +++ b/src/datastore_mad/remotes/fs/clone @@ -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 < 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 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 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 msg) return; error: - ostringstream oss; - oss << "Error cloning from Image " << cloning_id; - const auto& info = msg->payload(); - if (!info.empty() && (info[0] != '-')) { oss << ": " << info;