Skip to content

Commit

Permalink
F OpenNebula#3244: Better mixed modes ceph/clone.ssh
Browse files Browse the repository at this point in the history
  • Loading branch information
xorel committed Jul 24, 2019
1 parent ed9d64c commit 72b2f28
Show file tree
Hide file tree
Showing 18 changed files with 699 additions and 261 deletions.
4 changes: 2 additions & 2 deletions include/VirtualMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -2035,11 +2035,11 @@ class VirtualMachine : public PoolObjectSQL
* netowrking updates.
* @param context attribute of the VM
* @param error string if any
* @param only_auto boolean to generate context only for vnets
* @param only_auto boolean to generate context only for vnets
* with NETWORK_MODE = auto
* @return 0 on success
*/
int generate_network_context(VectorAttribute * context, string& error,
int generate_network_context(VectorAttribute * context, string& error,
bool only_auto);

/**
Expand Down
2 changes: 1 addition & 1 deletion include/VirtualMachineDisk.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class VirtualMachineDisk : public VirtualMachineAttribute
/**
* Return the TM_MAD_SYSTEM attribute
*/
std::string get_tm_mad_system();
std::string get_tm_mad_system() const;

/* ---------------------------------------------------------------------- */
/* Image Manager Interface */
Expand Down
7 changes: 6 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1277,9 +1277,12 @@ TM_DUMMY_FILES="src/tm_mad/dummy/clone \
src/tm_mad/dummy/resize"

TM_CEPH_FILES="src/tm_mad/ceph/clone \
src/tm_mad/ceph/clone.ssh \
src/tm_mad/ceph/ln \
src/tm_mad/ceph/ln.ssh \
src/tm_mad/ceph/mv \
src/tm_mad/ceph/mvds \
src/tm_mad/ceph/mvds.ssh \
src/tm_mad/ceph/cpds \
src/tm_mad/ceph/premigrate \
src/tm_mad/ceph/postmigrate \
Expand All @@ -1289,11 +1292,13 @@ TM_CEPH_FILES="src/tm_mad/ceph/clone \
src/tm_mad/ceph/snap_revert \
src/tm_mad/ceph/failmigrate \
src/tm_mad/ceph/delete \
src/tm_mad/ceph/delete.ssh \
src/tm_mad/ceph/context \
src/tm_mad/ceph/mkimage \
src/tm_mad/ceph/monitor \
src/tm_mad/ceph/mkswap \
src/tm_mad/ceph/resize"
src/tm_mad/ceph/resize \
src/tm_mad/ceph/resize.ssh"

TM_DEV_FILES="src/tm_mad/dev/clone \
src/tm_mad/dev/ln \
Expand Down
79 changes: 62 additions & 17 deletions src/tm/TransferManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -420,17 +420,23 @@ int TransferManager::prolog_transfer_command(
// CLONE or LINK disk images
// -----------------------------------------------------------------

// <CLONE|LN> tm_mad fe:SOURCE host:remote_system_ds/disk.i vmid dsid
// <CLONE|LN>(.tm_mad_system) tm_mad fe:SOURCE host:remote_system_ds/disk.i vmid dsid"
if (clon == "YES")
{
xfr << "CLONE ";
xfr << "CLONE";
}
else
{
xfr << "LN ";
xfr << "LN";
}

xfr << tm_mad << " ";
std::string tsys = disk->get_tm_mad_system();
if (!tsys.empty())
{
xfr << "." << tsys;
}

xfr << " " << tm_mad << " ";

if ( source.find(":") == string::npos ) //Regular file
{
Expand Down Expand Up @@ -1121,9 +1127,16 @@ void TransferManager::epilog_transfer_command(
return;
}

//MVDS tm_mad hostname:remote_system_dir/disk.0 <fe:SOURCE|SOURCE> vmid dsid
xfr << "MVDS "
<< tm_mad << " "
//MVDS(.tm_mad_system) tm_mad hostname:remote_system_dir/disk.0 <fe:SOURCE|SOURCE> vmid dsid
xfr << "MVDS";

string tsys = disk->vector_value("TM_MAD_SYSTEM");
if (!tsys.empty())
{
xfr << "." << tsys;
}

xfr << " " << tm_mad << " "
<< host << ":" << vm->get_system_dir() << "/disk." << disk_id << " "
<< source << " "
<< vm->get_oid() << " "
Expand All @@ -1148,10 +1161,18 @@ void TransferManager::epilog_transfer_command(
vv_rc = disk->vector_value("DATASTORE_ID", ds_id_i);
}

string tm_mad_system = "";
string tsys = disk->vector_value("TM_MAD_SYSTEM");
if (!tsys.empty())
{
tm_mad_system = "." + tsys;
}

if ( !tm_mad.empty() && vv_rc == 0)
{
//DELETE tm_mad hostname:remote_system_dir/disk.i vmid ds_id
xfr << "DELETE "
//DELETE(.tm_mad_system) tm_mad hostname:remote_system_dir/disk.i vmid ds_id
xfr << "DELETE"
<< tm_mad_system << " "
<< tm_mad << " "
<< host << ":" << vm->get_system_dir() << "/disk." << disk_id << " "
<< vm->get_oid() << " "
Expand Down Expand Up @@ -1487,11 +1508,18 @@ int TransferManager::epilog_delete_commands(VirtualMachine *vm,
}
}

//DELETE tm_mad host:remote_system_dir/disk.i vmid dsid(image)
//DELETE tm_mad(.tm_mad_system) host:remote_system_dir/disk.i vmid dsid(image)
// *local* DELETE tm_mad fe:system_dir/disk.i vmid dsid(image)
// *prev* DELETE tm_mad prev_host:remote_system_dir/disk.i vmid ds_id(image)
xfr << "DELETE "
<< tm_mad << " "
xfr << "DELETE";

string tsys = (*disk)->vector_value("TM_MAD_SYSTEM");
if (!tsys.empty())
{
xfr << "." + tsys;
}

xfr << " " << tm_mad << " "
<< host << ":"
<< system_dir << "/disk." << disk_id << " "
<< vm->get_oid() << " "
Expand Down Expand Up @@ -1898,6 +1926,8 @@ void TransferManager::saveas_hot_action(int vid)
string snap_id;
string tm_mad;
string ds_id;
string tsys;
string tm_mad_system;

ostringstream os;

Expand All @@ -1906,6 +1936,7 @@ void TransferManager::saveas_hot_action(int vid)

VirtualMachine * vm;
const TransferManagerDriver * tm_md;
VirtualMachineDisk * disk;

Nebula& nd = Nebula::instance();

Expand Down Expand Up @@ -1944,9 +1975,16 @@ void TransferManager::saveas_hot_action(int vid)
goto error_file;
}

disk = vm->get_disk(disk_id);
tsys = disk->vector_value("TM_MAD_SYSTEM");
if (!tsys.empty())
{
tm_mad_system = "." + tsys;
}

//CPDS tm_mad hostname:remote_system_dir/disk.0 source snapid vmid dsid
xfr << "CPDS "
<< tm_mad << " "
xfr << "CPDS" << tm_mad_system
<< " " << tm_mad << " "
<< vm->get_hostname() << ":"
<< vm->get_system_dir() << "/disk." << disk_id << " "
<< src << " "
Expand Down Expand Up @@ -2154,9 +2192,16 @@ void TransferManager::resize_command(VirtualMachine * vm,
ds_id = disk->vector_value("DATASTORE_ID");
}

//RESIZE tm_mad host:remote_system_dir/disk.i size vmid dsid
xfr << "RESIZE "
<< tm_mad << " "
//RESIZE.(tm_mad_system) tm_mad host:remote_system_dir/disk.i size vmid dsid
xfr << "RESIZE";

string tsys = disk->vector_value("TM_MAD_SYSTEM");
if (!tsys.empty())
{
xfr << "." + tsys;
}

xfr << " " << tm_mad << " "
<< vm->get_hostname() << ":"
<< vm->get_system_dir()<< "/disk."<< disk->vector_value("DISK_ID")<< " "
<< disk->vector_value("SIZE") << " "
Expand Down
53 changes: 14 additions & 39 deletions src/tm_mad/ceph/clone
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,13 @@ done < <(onevm show -x $VM_ID| $XPATH \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CEPH_KEY \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CEPH_CONF \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SIZE \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/ORIGINAL_SIZE \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/TYPE )
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/ORIGINAL_SIZE )
CEPH_USER="${XPATH_ELEMENTS[j++]}"
CEPH_KEY="${XPATH_ELEMENTS[j++]}"
CEPH_CONF="${XPATH_ELEMENTS[j++]}"
SIZE="${XPATH_ELEMENTS[j++]}"
ORIGINAL_SIZE="${XPATH_ELEMENTS[j++]}"
TYPE="${XPATH_ELEMENTS[j++]}"
#-------------------------------------------------------------------------------
# Get Datastore information
Expand Down Expand Up @@ -117,49 +115,26 @@ if [ -n "$EC_POOL_NAME" ]; then
EC_POOL_OPT="--data-pool ${EC_POOL_NAME}"
fi
if [ "${TYPE}" = 'FILE' ]; then
ssh_make_path $DST_HOST $DST_DIR 'ssh'
CLONE_CMD=$(cat <<EOF
RBD="${RBD}"
CLONE_CMD=$(cat <<EOF
RBD="${RBD}"
$RBD info $RBD_DST >/dev/null 2>&1 && exit 0
rbd_make_snap $SRC_PATH
rbd_make_snap $SRC_PATH
set -e -o pipefail
set -e -o pipefail
if [ "\$(rbd_format $SRC_PATH)" = "2" ]; then
$RBD export "$SRC_PATH@snap" $DST_PATH
else
$RBD export $SRC_PATH $DST_PATH
fi
if [ "\$(rbd_format $SRC_PATH)" = "2" ]; then
$RBD ${EC_POOL_OPT} clone "$SRC_PATH@snap" $RBD_DST
else
$RBD copy $SRC_PATH $RBD_DST
fi
if [ -n "$ORIGINAL_SIZE" -a "$SIZE" -gt "$ORIGINAL_SIZE" ]; then
qemu-img resize ${DST_PATH} ${SIZE}M
fi
if [ -n "$ORIGINAL_SIZE" -a "$SIZE" -gt "$ORIGINAL_SIZE" ]; then
$RBD resize $RBD_DST --size $SIZE
fi
EOF
)
else
CLONE_CMD=$(cat <<EOF
RBD="${RBD}"
$RBD info $RBD_DST >/dev/null 2>&1 && exit 0
rbd_make_snap $SRC_PATH
set -e -o pipefail
if [ "\$(rbd_format $SRC_PATH)" = "2" ]; then
$RBD ${EC_POOL_OPT} clone "$SRC_PATH@snap" $RBD_DST
else
$RBD copy $SRC_PATH $RBD_DST
fi
if [ -n "$ORIGINAL_SIZE" -a "$SIZE" -gt "$ORIGINAL_SIZE" ]; then
$RBD resize $RBD_DST --size $SIZE
fi
EOF
)
fi
ssh_exec_and_log_stdin "$DST_HOST" "$CLONE_CMD" "$CEPH_UTILS" \
"Error cloning $SRC_PATH to $RBD_DST in $DST_HOST"
Expand Down
Loading

0 comments on commit 72b2f28

Please sign in to comment.