Permalink
Browse files

Merge branch 'master' of git.opennebula.org:one

  • Loading branch information...
rsmontero committed Feb 20, 2014
2 parents d1a2b20 + 2a8393b commit f01854f8d9d47f446603091f32aa2eae1d7d7a83
@@ -207,7 +207,7 @@ class LifeCycleManager : public ActionListener
void attach_success_action(int vid);
- void attach_failure_action(int vid);
+ void attach_failure_action(int vid, bool release_save_as);
void detach_success_action(int vid);
View
@@ -693,6 +693,7 @@ IMAGE_RESTRICTED_ATTR = "SOURCE"
INHERIT_DATASTORE_ATTR = "CEPH_HOST"
INHERIT_DATASTORE_ATTR = "CEPH_SECRET"
INHERIT_DATASTORE_ATTR = "CEPH_USER"
+INHERIT_DATASTORE_ATTR = "RBD_FORMAT"
INHERIT_DATASTORE_ATTR = "GLUSTER_HOST"
INHERIT_DATASTORE_ATTR = "GLUSTER_VOLUME"
View
@@ -83,22 +83,14 @@ AclManager::AclManager(
string error_str;
// Users in group USERS can create standard resources
- // @1 VM+NET+IMAGE+TEMPLATE/* CREATE #<local-zone>
+ // @1 VM+NET+IMAGE+TEMPLATE+DOCUMENT/* CREATE #<local-zone>
add_rule(AclRule::GROUP_ID |
1,
AclRule::ALL_ID |
PoolObjectSQL::VM |
PoolObjectSQL::NET |
PoolObjectSQL::IMAGE |
- PoolObjectSQL::TEMPLATE,
- AuthRequest::CREATE,
- AclRule::INDIVIDUAL_ID |
- zone_id,
- error_str);
-
- // * DOCUMENT/* CREATE #<local-zone>
- add_rule(AclRule::ALL_ID,
- AclRule::ALL_ID |
+ PoolObjectSQL::TEMPLATE |
PoolObjectSQL::DOCUMENT,
AuthRequest::CREATE,
AclRule::INDIVIDUAL_ID |
@@ -103,7 +103,7 @@ DatastorePool::DatastorePool(SqlDB * db):
GroupPool::ONEADMIN_ID,
UserPool::oneadmin_name,
GroupPool::ONEADMIN_NAME,
- 0133,
+ 0137,
ds_tmpl,
&rc,
ClusterPool::NONE_CLUSTER_ID,
@@ -137,7 +137,7 @@ DatastorePool::DatastorePool(SqlDB * db):
GroupPool::ONEADMIN_ID,
UserPool::oneadmin_name,
GroupPool::ONEADMIN_NAME,
- 0133,
+ 0137,
ds_tmpl,
&rc,
ClusterPool::NONE_CLUSTER_ID,
@@ -22,3 +22,14 @@ POOL_NAME=one
# temporarily during the create/mkfs processes. This directoy MUST exist,
# have enough space and be writeable by 'oneadmin'
STAGING_DIR=/var/tmp
+
+# Default RBD_FORMAT. By default RBD format 1 will be used. Uncomment the
+# following options to enable support for RBD 2. This value affects all the ceph
+# datastores, however it can be enabled per ceph datastore using the same
+# option in the datastore template
+# RBD_FORMAT=2
+
+# Extra arguments send to "qemu-img convert". Depending on the qemu-img version
+# it using "-O rbd" can be either recommended or may cause segfaults. Uncomment
+# the following line to add "-O rbd" to the qemu-img convert command
+# QEMU_IMG_CONVERT_ARGS="-O rbd"
@@ -54,6 +54,7 @@ done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/POOL_NAME \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/STAGING_DIR \
+ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/RBD_FORMAT \
/DS_DRIVER_ACTION_DATA/IMAGE/PATH \
/DS_DRIVER_ACTION_DATA/IMAGE/SIZE \
/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/MD5 \
@@ -69,6 +70,7 @@ SAFE_DIRS="${XPATH_ELEMENTS[i++]}"
BRIDGE_LIST="${XPATH_ELEMENTS[i++]}"
POOL_NAME="${XPATH_ELEMENTS[i++]:-$POOL_NAME}"
STAGING_DIR="${XPATH_ELEMENTS[i++]:-$STAGING_DIR}"
+RBD_FORMAT="${XPATH_ELEMENTS[i++]:-$RBD_FORMAT}"
SRC="${XPATH_ELEMENTS[i++]}"
SIZE="${XPATH_ELEMENTS[i++]}"
MD5="${XPATH_ELEMENTS[i++]}"
@@ -121,8 +123,18 @@ exec_and_log "eval $DUMP | $SSH $DST_HOST $DD of=$TMP_DST bs=64k" \
REGISTER_CMD=$(cat <<EOF
set -e
- # create rbd
- $QEMU_IMG convert $TMP_DST rbd:$RBD_SOURCE
+ if [ "$RBD_FORMAT" = "2" ]; then
+ FORMAT=\$($QEMU_IMG info $TMP_DST | grep "^file format:" | awk '{print $3}')
+
+ if [ "\$FORMAT" != "raw" ]; then
+ $QEMU_IMG convert -O raw $TMP_DST $TMP_DST.raw
+ mv $TMP_DST.raw $TMP_DST
+ fi
+
+ $RBD import --format 2 $TMP_DST $RBD_SOURCE
+ else
+ $QEMU_IMG convert $QEMU_IMG_CONVERT_ARGS $TMP_DST rbd:$RBD_SOURCE
+ fi
# remove original
$RM -f $TMP_DST
@@ -96,15 +96,19 @@ REGISTER_CMD=$(cat <<EOF
set -e
export PATH=/usr/sbin:/sbin:\$PATH
- # create and format
- $DD if=/dev/zero of=$TMP_DST bs=1 count=1 seek=${SIZE}M
- $MKFS_CMD
-
- # create rbd
- $QEMU_IMG convert $TMP_DST rbd:$RBD_SOURCE
-
- # remove original
- $RM -f $TMP_DST
+ if [ "$FSTYPE" = "raw" ]; then
+ $QEMU_IMG create rbd:$RBD_SOURCE ${SIZE}M
+ else
+ # create and format
+ $DD if=/dev/zero of=$TMP_DST bs=1 count=1 seek=${SIZE}M
+ $MKFS_CMD
+
+ # create rbd
+ $QEMU_IMG convert $QEMU_IMG_CONVERT_ARGS $TMP_DST rbd:$RBD_SOURCE
+
+ # remove original
+ $RM -f $TMP_DST
+ fi
EOF
)
@@ -356,7 +356,7 @@ void LifeCycleManager::do_action(const string &action, void * arg)
}
else if (action == "ATTACH_FAILURE")
{
- attach_failure_action(vid);
+ attach_failure_action(vid, false);
}
else if (action == "DETACH_SUCCESS")
{
View
@@ -1340,7 +1340,7 @@ void LifeCycleManager::attach_success_action(int vid)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
-void LifeCycleManager::attach_failure_action(int vid)
+void LifeCycleManager::attach_failure_action(int vid, bool release_save_as)
{
VirtualMachine * vm;
VectorAttribute * disk;
@@ -1385,6 +1385,17 @@ void LifeCycleManager::attach_failure_action(int vid)
Quotas::quota_del(Quotas::IMAGE, uid, gid, &tmpl);
imagem->release_image(oid, image_id, false);
+
+ // Release non-persistent images in the detach event
+ if (release_save_as)
+ {
+ int save_as_id;
+
+ if ( disk->vector_value("SAVE_AS", save_as_id) == 0 )
+ {
+ imagem->release_image(oid, save_as_id, false);
+ }
+ }
}
else // Volatile disk
{
@@ -1408,7 +1419,7 @@ void LifeCycleManager::attach_failure_action(int vid)
void LifeCycleManager::detach_success_action(int vid)
{
- attach_failure_action(vid);
+ attach_failure_action(vid, true);
}
/* -------------------------------------------------------------------------- */
@@ -36,7 +36,7 @@ class Group < PoolElement
SELF = -1
# Default resource ACL's for group users (create)
- GROUP_DEFAULT_ACLS = "VM+IMAGE+NET+TEMPLATE"
+ GROUP_DEFAULT_ACLS = "VM+IMAGE+NET+TEMPLATE+DOCUMENT"
ALL_CLUSTERS_IN_ZONE = 10
# Creates a Group description with just its identifier
@@ -2655,6 +2655,62 @@ function add_osTab(dialog) {
'<div class="tip">'+tr("Add support in the VM for Physical Address Extension (PAE)")+'</div>'+
'</div>'+
'</div>'+
+ '<div class="row">'+
+ '<div class="four columns">'+
+ '<label class="right inline" for="APIC">'+tr("APIC")+':</label>'+
+ '</div>'+
+ '<div class="six columns">'+
+ '<select id="APIC" name="apic">'+
+ '<option id="no_apic" name="no_apic" value=""></option>'+
+ '<option value="yes">'+tr("Yes")+'</option>'+
+ '<option value="no">'+tr("No")+'</option>'+
+ '</select>'+
+ '</div>'+
+ '<div class="two columns">'+
+ '<div class="tip">'+tr("Enables the advanced programmable IRQ management.")+'</div>'+
+ '</div>'+
+ '</div>'+
+ '<div class="row">'+
+ '<div class="four columns vm_param">'+
+ '<label class="right inline" for="HYPERV">'+tr("HYPERV")+':</label>'+
+ '</div>'+
+ '<div class="six columns">'+
+ '<select id="HYPERV" name="hyperv">'+
+ '<option id="no_hyperv" name="no_hyperv" value=""></option>'+
+ '<option value="yes">'+tr("Yes")+'</option>'+
+ '<option value="no">'+tr("No")+'</option>'+
+ '</select>'+
+ '</div>'+
+ '<div class="two columns">'+
+ '<div class="tip">'+tr("Add support in the VM for hyper-v features (HYPERV)")+'</div>'+
+ '</div>'+
+ '</div>'+
+ '<div class="row">'+
+ '<div class="four columns">'+
+ '<label class="right inline" for="LOCALTIME">'+tr("LOCALTIME")+':</label>'+
+ '</div>'+
+ '<div class="six columns">'+
+ '<select id="LOCALTIME" name="localtime">'+
+ '<option id="no_localtime" name="no_localtime" value=""></option>'+
+ '<option value="yes">'+tr("Yes")+'</option>'+
+ '<option value="no">'+tr("No")+'</option>'+
+ '</select>'+
+ '</div>'+
+ '<div class="two columns">'+
+ '<div class="tip">'+tr("The guest clock will be synchronized to the host's configured timezone when booted.")+'</div>'+
+ '</div>'+
+ '</div>'+
+ '<div class="row">'+
+ '<div class="four columns">'+
+ '<label class="right inline" for="DEVICE_MODEL">'+tr("Device model")+':</label>'+
+ '</div>'+
+ '<div class="six columns">'+
+ '<input type="text" id="DEVICE_MODEL" name="device_model"/>'+
+ '</div>'+
+ '<div class="two columns">'+
+ '<div class="tip">'+tr("Used to change the IO emulator in Xen HVM. Only XEN.")+'</div>'+
+ '</div>'+
+ '</div>'+
'</div>'+
'<div class="six columns vm_param">'+
'<div class="row">'+
View
@@ -47,11 +47,40 @@ SRC_PATH=`arg_path $SRC`
DISK_ID=$(echo $DST|awk -F. '{print $NF}')
RBD_DST="${SRC_PATH}-${VM_ID}-${DISK_ID}"
+RBD_SNAP="${VM_ID}-${DISK_ID}"
+
+#-------------------------------------------------------------------------------
+# Get Image information
+#-------------------------------------------------------------------------------
+
+XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
+
+unset i j XPATH_ELEMENTS
+
+while IFS= read -r -d '' element; do
+ XPATH_ELEMENTS[i++]="$element"
+done < <(onevm show -x $VM_ID| $XPATH \
+ /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/RBD_FORMAT)
+
+RBD_FORMAT="${XPATH_ELEMENTS[j++]}"
#-------------------------------------------------------------------------------
# Clone the image
#-------------------------------------------------------------------------------
-ssh_exec_and_log "$DST_HOST" "$RBD copy $SRC_PATH $RBD_DST" \
+CLONE_CMD=$(cat <<EOF
+ set -e
+
+ if [ "$RBD_FORMAT" = "2" ]; then
+ $RBD snap create "$SRC_PATH@$RBD_SNAP"
+ $RBD snap protect "$SRC_PATH@$RBD_SNAP"
+ $RBD clone "$SRC_PATH@$RBD_SNAP" $RBD_DST
+ else
+ $RBD copy $SRC_PATH $RBD_DST
+ fi
+EOF
+)
+
+ssh_exec_and_log "$DST_HOST" "$CLONE_CMD" \
"Error cloning $SRC_PATH to $RBD_DST in $DST_HOST"
exit 0
View
@@ -67,16 +67,19 @@ while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <(onevm show -x $VM_ID| $XPATH \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SOURCE \
- /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/PERSISTENT)
+ /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/PERSISTENT \
+ /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/RBD_FORMAT)
SRC="${XPATH_ELEMENTS[j++]}"
PERSISTENT="${XPATH_ELEMENTS[j++]}"
+RBD_FORMAT="${XPATH_ELEMENTS[j++]}"
# Exit if persistent
[ -n "$PERSISTENT" ] && exit 0
# non persistent, so the name will be "<pool>/one-<imageid>-<vmid>-<diskid>"
RBD_SRC="${SRC}-${VM_ID}-${DISK_ID}"
+RBD_SNAP="${VM_ID}-${DISK_ID}"
#-------------------------------------------------------------------------------
# Delete the device
@@ -87,7 +90,19 @@ log "Deleting $DST_PATH"
# Note that this command, as opposed to the rest of $RBD commands in this set of
# drivers, is executed in the worker node and not in the CEPH frontend.
-ssh_exec_and_log "$DST_HOST" "$RBD rm $RBD_SRC" \
+DELETE_CMD=$(cat <<EOF
+ set -e
+
+ $RBD rm $RBD_SRC
+
+ if [ "$RBD_FORMAT" = "2" ]; then
+ $RBD snap unprotect $SRC@$RBD_SNAP
+ $RBD snap rm $SRC@$RBD_SNAP
+ fi
+EOF
+)
+
+ssh_exec_and_log "$DST_HOST" "$DELETE_CMD" \
"Error deleting $RBD_SRC in $DST_HOST"
exit 0
View
@@ -59,24 +59,40 @@ while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <(onevm show -x $VM_ID| $XPATH \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SOURCE \
- /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/PERSISTENT)
+ /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/PERSISTENT \
+ /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/RBD_FORMAT)
RBD_SRC="${XPATH_ELEMENTS[j++]}"
PERSISTENT="${XPATH_ELEMENTS[j++]}"
+RBD_FORMAT="${XPATH_ELEMENTS[j++]}"
# Exit if persistent
[ -n "$PERSISTENT" ] && exit 0
# non persistent, so the name will be "<pool>/one-<imageid>-<vmid>-<diskid>"
RBD_DST="${RBD_SRC}-${VM_ID}-${DISK_ID}"
+RBD_SNAP="${VM_ID}-${DISK_ID}"
#-------------------------------------------------------------------------------
# Move the image back to the datastore
#-------------------------------------------------------------------------------
log "Dumping $RBD_DST to $DST"
-ssh_exec_and_log "$SRC_HOST" "$RBD rename $RBD_DST $DST" \
+DUMP_CMD=$(cat <<EOF
+ set -e
+
+ if [ "$RBD_FORMAT" = "2" ]; then
+ $RBD flatten $RBD_DST
+ $RBD snap unprotect $RBD_SRC@$RBD_SNAP
+ $RBD snap rm $RBD_SRC@$RBD_SNAP
+ fi
+
+ $RBD rename $RBD_DST $DST
+EOF
+)
+
+ssh_exec_and_log "$SRC_HOST" "$DUMP_CMD" \
"Error saving $RBD_DST as $DST in $SRC_HOST"
exit 0
Oops, something went wrong.

0 comments on commit f01854f

Please sign in to comment.