diff --git a/include/Image.h b/include/Image.h index 838dc488af..92bde3b9ca 100644 --- a/include/Image.h +++ b/include/Image.h @@ -36,13 +36,14 @@ public: */ enum ImageType { - OS = 0, /** < Base OS image */ - CDROM = 1, /** < An ISO9660 image */ - DATABLOCK = 2, /** < User persistent data device */ - KERNEL = 3, /** < Kernel files */ - RAMDISK = 4, /** < Initrd files */ - CONTEXT = 5, /** < Context files */ - BACKUP = 6, /** < VM Backup reference */ + OS = 0, /** < Base OS image */ + CDROM = 1, /** < An ISO9660 image */ + DATABLOCK = 2, /** < User persistent data device */ + KERNEL = 3, /** < Kernel files */ + RAMDISK = 4, /** < Initrd files */ + CONTEXT = 5, /** < Context files */ + BACKUP = 6, /** < VM Backup reference */ + FILESYSTEM = 7, /** < Filesystem */ }; /** @@ -54,14 +55,15 @@ public: { switch (ob) { - case OS: return "OS" ; break; - case CDROM: return "CDROM" ; break; - case DATABLOCK: return "DATABLOCK" ; break; - case KERNEL: return "KERNEL" ; break; - case RAMDISK: return "RAMDISK" ; break; - case CONTEXT: return "CONTEXT" ; break; - case BACKUP: return "BACKUP" ; break; - default: return ""; + case OS: return "OS" ; break; + case CDROM: return "CDROM" ; break; + case DATABLOCK: return "DATABLOCK" ; break; + case KERNEL: return "KERNEL" ; break; + case RAMDISK: return "RAMDISK" ; break; + case CONTEXT: return "CONTEXT" ; break; + case BACKUP: return "BACKUP" ; break; + case FILESYSTEM: return "FILESYSTEM" ; break; + default: return ""; } }; @@ -88,6 +90,7 @@ public: SHEEPDOG = 7, /** < Sheepdog Block Device */ SHEEPDOG_CDROM = 8, /** < Sheepdog CDROM Device Device */ ISCSI = 9, /** < iSCSI Volume (Devices Datastore) */ + FILE_SYSTEM = 10, /** < Filesystem */ NONE = 255 /** < No disk type, error situation */ }; @@ -110,6 +113,7 @@ public: case SHEEPDOG: return "SHEEPDOG" ; break; case SHEEPDOG_CDROM: return "SHEEPDOG_CDROM" ; break; case ISCSI: return "ISCSI" ; break; + case FILE_SYSTEM: return "FILESYSTEM" ; break; default: return ""; } }; diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 03d63d8d96..319b58e86d 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -1521,9 +1521,9 @@ public: * @param disk_id of the DISK * @return 0 if the disk_id was found -1 otherwise */ - int set_attach_disk(int disk_id) + int set_attach_disk(int disk_id, std::string& error) { - return disks.set_attach(disk_id); + return disks.set_attach(disk_id, error); } // ------------------------------------------------------------------------- @@ -2293,6 +2293,22 @@ private: */ void add_pci_context(VectorAttribute * pci); + /** + * Generate the DISK related CONTEXT setions, i.e. DISK_*. This function is + * used only for disks skipped during requirements process(i.e. FILESYSTEM) + * @param context attribute of the VM + * @param error string if any + * @return 0 on success + */ + int generate_disk_context(VectorAttribute* context, std::string& error_str); + + /** + * Deletes the DISK related CONTEXT section for the given disk, i.e. + * DISK_TAG + * @param disk_id the id of the DISK + */ + void clear_disk_context(int disk_id); + /** * Generate the ONE_GATE token & url * @param context attribute of the VM diff --git a/include/VirtualMachineDisk.h b/include/VirtualMachineDisk.h index 622709647d..10462e4b50 100644 --- a/include/VirtualMachineDisk.h +++ b/include/VirtualMachineDisk.h @@ -22,6 +22,7 @@ #include #include "VirtualMachineAttribute.h" +#include "Image.h" #include "Snapshots.h" #include "NebulaUtil.h" @@ -318,6 +319,15 @@ public: void delete_younger_snapshots(int snap_id, Template& ds_quota, Template& vm_quota, bool& io, bool& vo); + /** + * Check if the disk supports snapshots + * + * @return true if the disk supports snapshots + */ + bool snapshot_support() const + { + return !is_volatile() && !is_filesystem(); + } /* ---------------------------------------------------------------------- */ /* Disk resize functions */ @@ -377,6 +387,16 @@ public: */ void to_xml_short(std::ostringstream& oss) const; + /* ---------------------------------------------------------------------- */ + /* Disk requirements helpers */ + /* ---------------------------------------------------------------------- */ + /** + * Checks if the disk is a file system + * + * @return true if the disk should be skipped + */ + bool is_filesystem() const; + private: Snapshots * snapshots; @@ -615,9 +635,10 @@ public: /** * Sets the attach attribute to the given disk * @param disk_id of the DISK + * @param error reason * @return 0 if the disk_id was found -1 otherwise */ - int set_attach(int disk_id); + int set_attach(int disk_id, std::string& error); /** * Cleans the attach attribute from the disk diff --git a/install.sh b/install.sh index 1911a80826..4274cea8c5 100755 --- a/install.sh +++ b/install.sh @@ -446,6 +446,7 @@ VAR_DIRS="$VAR_LOCATION/remotes \ $VAR_LOCATION/remotes/datastore/iscsi_libvirt \ $VAR_LOCATION/remotes/datastore/rsync \ $VAR_LOCATION/remotes/datastore/restic \ + $VAR_LOCATION/remotes/datastore/virtiofs \ $VAR_LOCATION/remotes/market \ $VAR_LOCATION/remotes/market/http \ $VAR_LOCATION/remotes/market/one \ @@ -628,6 +629,7 @@ INSTALL_FILES=( DATASTORE_DRIVER_ISCSI_SCRIPTS:$VAR_LOCATION/remotes/datastore/iscsi_libvirt DATASTORE_DRIVER_RSYNC_SCRIPTS:$VAR_LOCATION/remotes/datastore/rsync DATASTORE_DRIVER_RESTIC_SCRIPTS:$VAR_LOCATION/remotes/datastore/restic + DATASTORE_DRIVER_VIRTIOFS_SCRIPTS:$VAR_LOCATION/remotes/datastore/virtiofs DATASTORE_DRIVER_ETC_SCRIPTS:$VAR_LOCATION/remotes/etc/datastore MARKETPLACE_DRIVER_HTTP_SCRIPTS:$VAR_LOCATION/remotes/market/http @@ -1702,6 +1704,16 @@ DATASTORE_DRIVER_RESTIC_SCRIPTS="src/datastore_mad/remotes/restic/cp \ src/datastore_mad/remotes/restic/backup_cancel \ src/datastore_mad/remotes/restic/ls" +DATASTORE_DRIVER_VIRTIOFS_SCRIPTS="src/datastore_mad/remotes/virtiofs/clone \ + src/datastore_mad/remotes/virtiofs/cp \ + src/datastore_mad/remotes/virtiofs/mkfs \ + src/datastore_mad/remotes/virtiofs/monitor \ + src/datastore_mad/remotes/virtiofs/rm \ + src/datastore_mad/remotes/virtiofs/snap_delete \ + src/datastore_mad/remotes/virtiofs/snap_flatten \ + src/datastore_mad/remotes/virtiofs/snap_revert \ + src/datastore_mad/remotes/virtiofs/stat" + DATASTORE_DRIVER_ETC_SCRIPTS="src/datastore_mad/remotes/datastore.conf" #------------------------------------------------------------------------------- diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 95ad342658..03e444776d 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -558,7 +558,7 @@ TM_MAD = [ DATASTORE_MAD = [ EXECUTABLE = "one_datastore", - ARGUMENTS = "-t 15 -d dummy,fs,lvm,ceph,dev,iscsi_libvirt,restic,rsync,netapp,purefa -s dummy,lvm,shared,ssh,local,ceph,fs_lvm,fs_lvm_ssh,qcow2,netapp,purefa" + ARGUMENTS = "-t 15 -d dummy,fs,lvm,ceph,dev,iscsi_libvirt,restic,rsync,netapp,purefa,virtiofs -s dummy,lvm,shared,ssh,local,ceph,fs_lvm,fs_lvm_ssh,qcow2,netapp,purefa" ] #******************************************************************************* @@ -1039,6 +1039,8 @@ INHERIT_DATASTORE_ATTR = "PERSISTENT_SNAPSHOTS" INHERIT_IMAGE_ATTR = "DISK_TYPE" INHERIT_IMAGE_ATTR = "SERIAL" +INHERIT_IMAGE_ATTR = "MOUNT_POINT" +INHERIT_IMAGE_ATTR = "MOUNT_TAG" INHERIT_VNET_ATTR = "VLAN_TAGGED_ID" INHERIT_VNET_ATTR = "FILTER" @@ -1200,6 +1202,12 @@ TM_MAD_CONF = [ DS_MIGRATE = "NO", DS_LIVE_MIGRATE = "NO", DS_MIGRATE_SNAP = "NO" ] +TM_MAD_CONF = [ + NAME = "virtiofs", LN_TARGET = "NONE", CLONE_TARGET = "NONE", SHARED = "YES", + DRIVER = "virtiofs", DISK_TYPE = "filesystem", + DS_MIGRATE = "NO", DS_LIVE_MIGRATE = "NO", DS_MIGRATE_SNAP = "NO" +] + #******************************************************************************* # Datastore Manager Driver Behavior Configuration #******************************************************************************* @@ -1253,14 +1261,17 @@ DS_MAD_CONF = [ ] DS_MAD_CONF = [ - NAME = "netapp", PERSISTENT_ONLY = "NO", MARKETPLACE_ACTIONS = "export", + NAME = "netapp", PERSISTENT_ONLY = "NO", REQUIRED_ATTRS = "NETAPP_HOST,NETAPP_USER,NETAPP_PASS,NETAPP_AGGREGATES,NETAPP_SVM,NETAPP_IGROUP,NETAPP_TARGET" ] DS_MAD_CONF = [ - NAME = "purefa", PERSISTENT_ONLY = "NO", MARKETPLACE_ACTIONS = "export", + NAME = "purefa", PERSISTENT_ONLY = "NO", REQUIRED_ATTRS = "PUREFA_HOST,PUREFA_API_TOKEN,PUREFA_TARGET" ] +DS_MAD_CONF = [ + NAME = "virtiofs", REQUIRED_ATTRS = "", PERSISTENT_ONLY = "YES", DATASTORE_CAPACITY_CHECK = "NO" +] #******************************************************************************* # MarketPlace Driver Behavior Configuration diff --git a/src/datastore/Datastore.cc b/src/datastore/Datastore.cc index 9223286d7a..e8a1664144 100644 --- a/src/datastore/Datastore.cc +++ b/src/datastore/Datastore.cc @@ -342,6 +342,15 @@ int Datastore::set_ds_mad(const std::string &mad, std::string &error_str) goto error_conf; } + bool capacity_check; + + rc = vatt->vector_value("DATASTORE_CAPACITY_CHECK", capacity_check); + + if ( rc != -1 ) + { + replace_template_attribute("DATASTORE_CAPACITY_CHECK", capacity_check); + } + rc = vatt->vector_value("REQUIRED_ATTRS", required_attrs); if ( rc == -1 ) //No required attributes @@ -583,6 +592,7 @@ int Datastore::set_ds_disk_type(string& s_dt, string& error) case Image::RBD: case Image::GLUSTER: case Image::SHEEPDOG: + case Image::FILE_SYSTEM: break; case Image::CD_ROM: @@ -605,6 +615,7 @@ int Datastore::set_ds_disk_type(string& s_dt, string& error) case Image::FILE: case Image::RBD: case Image::BLOCK: + case Image::FILE_SYSTEM: break; case Image::GLUSTER: @@ -1118,7 +1129,7 @@ int Datastore::post_update_template(string& error_str, Template *old_tmpl) } /* ---------------------------------------------------------------------- */ - /* Verify that the template has the required attributees */ + /* Verify that the template has the required attributes */ /* ---------------------------------------------------------------------- */ if ( set_ds_mad(ds_mad, error_str) != 0 ) @@ -1274,6 +1285,7 @@ Image::DiskType Datastore::context_disk_type() const case Image::RBD_CDROM: case Image::SHEEPDOG_CDROM: case Image::GLUSTER_CDROM: + case Image::FILE_SYSTEM: break; } diff --git a/src/datastore_mad/remotes/virtiofs/clone b/src/datastore_mad/remotes/virtiofs/clone new file mode 120000 index 0000000000..9c454e8cd4 --- /dev/null +++ b/src/datastore_mad/remotes/virtiofs/clone @@ -0,0 +1 @@ +../common/not_supported.sh \ No newline at end of file diff --git a/src/datastore_mad/remotes/virtiofs/cp b/src/datastore_mad/remotes/virtiofs/cp new file mode 100755 index 0000000000..b7a5253d5a --- /dev/null +++ b/src/datastore_mad/remotes/virtiofs/cp @@ -0,0 +1,71 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2025, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +############################################################################### +# This script is used to copy or register a directory to the repository +############################################################################### + +# -------- Set up the environment to source common tools & conf ------------ + +if [ -z "${ONE_LOCATION}" ]; then + LIB_LOCATION=/usr/lib/one +else + LIB_LOCATION=$ONE_LOCATION/lib +fi + +. $LIB_LOCATION/sh/scripts_common.sh + +DRIVER_PATH=$(dirname $0) +source ${DRIVER_PATH}/../libfs.sh + +# -------- Get cp and datastore arguments from OpenNebula core ------------ + +DRV_ACTION=`cat -` +ID=$1 + +export DRV_ACTION + +UTILS_PATH="${DRIVER_PATH}/.." + +XPATH="$UTILS_PATH/xpath.rb -b $DRV_ACTION" + +unset i XPATH_ELEMENTS + +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/RESTRICTED_DIRS \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/SAFE_DIRS \ + /DS_DRIVER_ACTION_DATA/IMAGE/PATH) + +unset i + +BASE_PATH="${XPATH_ELEMENTS[i++]}" +RESTRICTED_DIRS="${XPATH_ELEMENTS[i++]}" +SAFE_DIRS="${XPATH_ELEMENTS[i++]}" +SRC="${XPATH_ELEMENTS[i++]}" + +set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" + +if [ `check_restricted $SRC` -eq 1 ]; then + log_error "Not allowed to use directories from $RESTRICTED_DIRS" + error_message "Not allowed to use directory '$SRC', check RESTRICTED_DIRS in your datastore" + exit -1 +fi + +echo "$SRC dir" diff --git a/src/datastore_mad/remotes/virtiofs/mkfs b/src/datastore_mad/remotes/virtiofs/mkfs new file mode 120000 index 0000000000..9c454e8cd4 --- /dev/null +++ b/src/datastore_mad/remotes/virtiofs/mkfs @@ -0,0 +1 @@ +../common/not_supported.sh \ No newline at end of file diff --git a/src/datastore_mad/remotes/virtiofs/monitor b/src/datastore_mad/remotes/virtiofs/monitor new file mode 100755 index 0000000000..d0a6666aad --- /dev/null +++ b/src/datastore_mad/remotes/virtiofs/monitor @@ -0,0 +1,24 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2025, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # +STDIN=`cat -` + +echo "USED_MB=0" +echo "TOTAL_MB=0" +echo "FREE_MB=0" + +exit 0 diff --git a/src/datastore_mad/remotes/virtiofs/rm b/src/datastore_mad/remotes/virtiofs/rm new file mode 100755 index 0000000000..353840e115 --- /dev/null +++ b/src/datastore_mad/remotes/virtiofs/rm @@ -0,0 +1,21 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2025, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +STDIN=`cat -` + +exit 0 diff --git a/src/datastore_mad/remotes/virtiofs/snap_delete b/src/datastore_mad/remotes/virtiofs/snap_delete new file mode 120000 index 0000000000..9c454e8cd4 --- /dev/null +++ b/src/datastore_mad/remotes/virtiofs/snap_delete @@ -0,0 +1 @@ +../common/not_supported.sh \ No newline at end of file diff --git a/src/datastore_mad/remotes/virtiofs/snap_flatten b/src/datastore_mad/remotes/virtiofs/snap_flatten new file mode 120000 index 0000000000..9c454e8cd4 --- /dev/null +++ b/src/datastore_mad/remotes/virtiofs/snap_flatten @@ -0,0 +1 @@ +../common/not_supported.sh \ No newline at end of file diff --git a/src/datastore_mad/remotes/virtiofs/snap_revert b/src/datastore_mad/remotes/virtiofs/snap_revert new file mode 120000 index 0000000000..9c454e8cd4 --- /dev/null +++ b/src/datastore_mad/remotes/virtiofs/snap_revert @@ -0,0 +1 @@ +../common/not_supported.sh \ No newline at end of file diff --git a/src/datastore_mad/remotes/virtiofs/stat b/src/datastore_mad/remotes/virtiofs/stat new file mode 100755 index 0000000000..c5a629b9cf --- /dev/null +++ b/src/datastore_mad/remotes/virtiofs/stat @@ -0,0 +1,76 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2025, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +# ------------------------------------------------------------------------------ +# Set up Environment and transfer arguments +# ------------------------------------------------------------------------------ +# +# libfs.sh & scripts_common.sh: includes tools and lib calls +# ------------------------------------------------------------------------------ + +if [ -z "${ONE_LOCATION}" ]; then + LIB_LOCATION=/usr/lib/one +else + LIB_LOCATION=$ONE_LOCATION/lib +fi + +. $LIB_LOCATION/sh/scripts_common.sh + +DRIVER_PATH=$(dirname $0) +source ${DRIVER_PATH}/../libfs.sh + +# -------- Get stat and datastore arguments from OpenNebula core ------------ + +DRV_ACTION=`cat -` +ID=$1 + +XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION" + +unset i XPATH_ELEMENTS + +while IFS= read -r -d '' element; do + XPATH_ELEMENTS[i++]="$element" +done < <($XPATH /DS_DRIVER_ACTION_DATA/IMAGE/PATH \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST) + +unset i + +SRC="${XPATH_ELEMENTS[i++]}" +BRIDGE_LIST="${XPATH_ELEMENTS[i++]}" + +# ------------------------------------------------------------------------------ +# Compute the size +# ------------------------------------------------------------------------------ + +SIZE="" + +# Try local frontend +if [ -d "${SRC}" ]; then + SIZE=$(du -sb "${SRC}" | cut -f1) +fi + +# Try a bridge host if local failed +if [ -z "$SIZE" ] && [ -n "$BRIDGE_LIST" ]; then + DST_HOST=$(get_destination_host "$ID") + + if [ -n "$DST_HOST" ]; then + SIZE=$(ssh_exec_and_log "$DST_HOST" "if [ -d '$SRC' ]; then du -sb '$SRC' | cut -f1; fi" 2>/dev/null) + fi +fi + +echo "${SIZE:-0}" diff --git a/src/dm/DispatchManagerActions.cc b/src/dm/DispatchManagerActions.cc index b1a8014e27..77b06d3dd1 100644 --- a/src/dm/DispatchManagerActions.cc +++ b/src/dm/DispatchManagerActions.cc @@ -1330,12 +1330,8 @@ int DispatchManager::detach(int vid, int disk_id, const RequestAttributes& ra, return -1; } - if ( vm->set_attach_disk(disk_id) == -1 ) + if ( vm->set_attach_disk(disk_id, error_str) == -1 ) { - oss << "Could not detach disk with DISK_ID " << disk_id - << ", it does not exist."; - error_str = oss.str(); - NebulaLog::log("DiM", Log::ERROR, error_str); return -1; diff --git a/src/image/Image.cc b/src/image/Image.cc index 3a124e687a..ab36d7e13e 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -144,6 +144,7 @@ int Image::insert(SqlDB *db, string& error_str) break; case BACKUP: + case FILESYSTEM: persistent_img = true; erase_template_attribute("DEV_PREFIX", dev_prefix); break; @@ -224,6 +225,11 @@ int Image::insert(SqlDB *db, string& error_str) } // else format in the IMAGE template } + else if (type == Image::FILESYSTEM) + { + // FILESYSTEM image must use dir format + format = "dir"; + } else //CDROM, KERNEL, RAMDISK, CONTEXT { error_str = "No PATH nor SOURCE in template."; @@ -573,7 +579,7 @@ void Image::disk_attribute(VirtualMachineDisk * disk, // DEV_PREFIX ATTRIBUTE // Note: CD's dev_prefix is set on target assigment based on VM chipset //-------------------------------------------------------------------------- - if ( dev_prefix.empty() && type != CDROM ) + if ( dev_prefix.empty() && !(type == CDROM || type == FILESYSTEM) ) { get_template_attribute("DEV_PREFIX", dev_prefix); @@ -646,7 +652,7 @@ void Image::disk_attribute(VirtualMachineDisk * disk, disk->replace("CLONE", "NO"); disk->replace("SAVE", "YES"); - if (template_ptype == "SHAREABLE" && format == "raw") + if (template_ptype == "SHAREABLE" && (format == "raw" || format == "dir")) { disk->replace("SHAREABLE", "YES"); } @@ -676,6 +682,7 @@ void Image::disk_attribute(VirtualMachineDisk * disk, { case OS: case DATABLOCK: + case FILESYSTEM: disk_attr_type = disk_type_to_str(disk_type); break; @@ -718,6 +725,46 @@ void Image::disk_attribute(VirtualMachineDisk * disk, disk->replace("TARGET", template_target); } + //-------------------------------------------------------------------------- + // MOUNT_POINT & MOUNT_TAG attributes + //-------------------------------------------------------------------------- + if (disk->is_filesystem()) + { + ostringstream oss; + + string _mount_s = disk->vector_value("MOUNT_POINT"); + + if (_mount_s.empty()) + { + get_template_attribute("MOUNT_POINT", _mount_s); + + if (_mount_s.empty()) + { + oss << "/mnt/one-fs-" << oid; + _mount_s = oss.str(); + } + + disk->replace("MOUNT_POINT", _mount_s); + } + + _mount_s = disk->vector_value("MOUNT_TAG"); + + if (_mount_s.empty()) + { + get_template_attribute("MOUNT_TAG", _mount_s); + + if (_mount_s.empty()) + { + oss.str(""); + oss << "one-tag-" << oid; + + _mount_s = oss.str(); + } + + disk->replace("MOUNT_TAG", _mount_s); + } + } + for (const auto& inherit : inherit_attrs) { if (auto va = PoolObjectSQL::get_template_attribute(inherit)) @@ -792,6 +839,10 @@ int Image::set_type(string& _type, string& error) { type = BACKUP; } + else if ( _type == "FILESYSTEM" ) + { + type = FILESYSTEM; + } else { error = "Unknown type " + type; @@ -869,6 +920,10 @@ Image::ImageType Image::str_to_type(string& str_type) { it = BACKUP; } + else if ( str_type == "FILESYSTEM" ) + { + it = FILESYSTEM; + } return it; } @@ -979,6 +1034,10 @@ Image::DiskType Image::str_to_disk_type(string& s_disk_type) { type = Image::ISCSI; } + else if (s_disk_type == "FILESYSTEM") + { + type = Image::FILE_SYSTEM; + } return type; } diff --git a/src/image/ImageManagerActions.cc b/src/image/ImageManagerActions.cc index f98c570263..f5569ab2bb 100644 --- a/src/image/ImageManagerActions.cc +++ b/src/image/ImageManagerActions.cc @@ -99,6 +99,7 @@ int ImageManager::acquire_image(int vm_id, Image *img, bool attach, string& erro case Image::OS: case Image::DATABLOCK: case Image::CDROM: + case Image::FILESYSTEM: break; case Image::KERNEL: @@ -238,6 +239,7 @@ void ImageManager::release_image(int vm_id, int iid, bool failed) case Image::OS: case Image::DATABLOCK: case Image::CDROM: + case Image::FILESYSTEM: break; case Image::KERNEL: @@ -352,8 +354,9 @@ void ImageManager::release_cloning_resource( case Image::RAMDISK: case Image::CONTEXT: case Image::BACKUP: - NebulaLog::log("ImM", Log::ERROR, "Trying to release a cloning " - "KERNEL, RAMDISK, BACKUP or CONTEXT image"); + case Image::FILESYSTEM: + NebulaLog::log("ImM", Log::ERROR, "Trying to release a cloning " + + img->type_to_str(img->get_type()) + " image"); return; } @@ -915,6 +918,11 @@ int ImageManager::stat_image(Template* img_tmpl, switch (Image::str_to_type(type_att)) { + case Image::FILESYSTEM: + res = "0"; + + return 0; + case Image::BACKUP: if ( img_tmpl->get("SIZE", res) ) { @@ -1078,6 +1086,7 @@ void ImageManager::set_image_snapshots(int iid, const Snapshots& s) case Image::CONTEXT: case Image::CDROM: case Image::BACKUP: + case Image::FILESYSTEM: return; } @@ -1131,6 +1140,7 @@ void ImageManager::set_image_size(int iid, long long size) case Image::CONTEXT: case Image::CDROM: case Image::BACKUP: + case Image::FILESYSTEM: return; } @@ -1200,8 +1210,8 @@ int ImageManager::delete_snapshot(int iid, int sid, string& error) if ( img->get_type() != Image::OS && img->get_type() != Image::DATABLOCK ) { - error = "IMAGES of type KERNEL, RAMDISK, BACKUP and CONTEXT does not " - "have snapshots."; + error = "IMAGES of type KERNEL, RAMDISK, BACKUP, FILESYSTEM and " + "CONTEXT does not have snapshots."; return -1; } @@ -1294,8 +1304,8 @@ int ImageManager::revert_snapshot(int iid, int sid, string& error) if ( img->get_type() != Image::OS && img->get_type() != Image::DATABLOCK ) { - error = "IMAGES of type KERNEL, RAMDISK, BACKUP and CONTEXT does not " - "have snapshots."; + error = "IMAGES of type KERNEL, RAMDISK, BACKUP, FILESYSTEM and " + "CONTEXT does not have snapshots."; return -1; } @@ -1390,8 +1400,8 @@ int ImageManager::flatten_snapshot(int iid, int sid, string& error) if ( img->get_type() != Image::OS && img->get_type() != Image::DATABLOCK ) { - error = "IMAGES of type KERNEL, RAMDISK, BACKUP and CONTEXT does not " - "have snapshots."; + error = "IMAGES of type KERNEL, RAMDISK, BACKUP, FILESYSTEM and " + "CONTEXT does not have snapshots."; return -1; } diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index 95454f244a..2ed1da6ab3 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -117,6 +117,7 @@ int ImagePool::allocate ( case Image::OS: case Image::DATABLOCK: case Image::CDROM: + case Image::FILESYSTEM: if ( ds_type != Datastore::IMAGE_DS ) { error_str = "Only IMAGES of type KERNEL, RAMDISK and CONTEXT can be" diff --git a/src/oca/java/src/org/opennebula/client/image/Image.java b/src/oca/java/src/org/opennebula/client/image/Image.java index 69d7fd1716..dfb28fb51c 100644 --- a/src/oca/java/src/org/opennebula/client/image/Image.java +++ b/src/oca/java/src/org/opennebula/client/image/Image.java @@ -55,10 +55,10 @@ public class Image extends PoolElement "lock", "lock"}; private static final String[] IMAGE_TYPES = - {"OS", "CDROM", "DATABLOCK", "KERNEL", "RAMDISK", "CONTEXT"}; + {"OS", "CDROM", "DATABLOCK", "KERNEL", "RAMDISK", "CONTEXT", "FILESYSTEM"}; private static final String[] SHORT_IMAGE_TYPES = - {"OS", "CD", "DB", "KL", "RD", "CX"}; + {"OS", "CD", "DB", "KL", "RD", "CX", "FS"}; /** * Creates a new Image representation. diff --git a/src/oca/python/pyone/__init__.py b/src/oca/python/pyone/__init__.py index 2c644659da..4f7689de2f 100644 --- a/src/oca/python/pyone/__init__.py +++ b/src/oca/python/pyone/__init__.py @@ -58,7 +58,7 @@ class OneInternalException(OneException): DATASTORE_TYPES = IntEnum('DATASTORE_TYPES', 'IMAGE SYSTEM FILE', start=0) DATASTORE_STATES = IntEnum('DATASTORE_STATES', 'READY DISABLED', start=0) -DISK_TYPES = IntEnum('DISK_TYPES', 'FILE CD_ROM BLOCK RBD', start=0) +DISK_TYPES = IntEnum('DISK_TYPES', 'FILE CD_ROM BLOCK RBD FILE_SYSTEM', start=0) HISTORY_ACTION = IntEnum('HISTORY_ACTION', '''none migrate live-migrate shutdown shutdown-hard undeploy undeploy-hard hold release stop @@ -79,7 +79,7 @@ IMAGE_STATES = IntEnum('IMAGE_STATES', '''INIT READY USED DISABLED LOCKED ERROR CLONE DELETE USED_PERS LOCKED_USED LOCKED_USED_PERS''', start=0) IMAGE_TYPES = IntEnum('IMAGE_TYPES', '''OS CDROM DATABLOCK KERNEL RAMDISK - CONTEXT''', start=0) + CONTEXT FILESYSTEM''', start=0) LCM_STATE = IntEnum('LCM_STATE', ''' LCM_INIT diff --git a/src/oca/ruby/opennebula/image.rb b/src/oca/ruby/opennebula/image.rb index db301423dd..041ea0d934 100644 --- a/src/oca/ruby/opennebula/image.rb +++ b/src/oca/ruby/opennebula/image.rb @@ -62,19 +62,20 @@ module OpenNebula "LOCKED_USED_PERS" => "lock" } - IMAGE_TYPES=%w{OS CDROM DATABLOCK KERNEL RAMDISK CONTEXT BACKUP} + IMAGE_TYPES=%w{OS CDROM DATABLOCK KERNEL RAMDISK CONTEXT BACKUP FILESYSTEM} SHORT_IMAGE_TYPES={ - "OS" => "OS", - "CDROM" => "CD", - "DATABLOCK" => "DB", - "KERNEL" => "KL", - "RAMDISK" => "RD", - "CONTEXT" => "CX", - "BACKUP" => "BK" + "OS" => "OS", + "CDROM" => "CD", + "DATABLOCK" => "DB", + "KERNEL" => "KL", + "RAMDISK" => "RD", + "CONTEXT" => "CX", + "BACKUP" => "BK", + "FILESYSTEM" => "FS" } - DISK_TYPES=%w{FILE CD_ROM BLOCK RBD} + DISK_TYPES=%w{FILE CD_ROM BLOCK RBD FILE_SYSTEM} # Creates an Image description with just its identifier # this method should be used to create plain Image objects. diff --git a/src/rm/api/ImageAPI.cc b/src/rm/api/ImageAPI.cc index 102ec4aa21..39f9f1cdc2 100644 --- a/src/rm/api/ImageAPI.cc +++ b/src/rm/api/ImageAPI.cc @@ -107,7 +107,10 @@ Request::ErrorCode ImageAPI::clone(int source_id, case Image::RAMDISK: case Image::CONTEXT: case Image::BACKUP: - att.resp_msg = "KERNEL, RAMDISK, BACKUP and CONTEXT cannot be cloned."; + case Image::FILESYSTEM: + string type = img->type_to_str(img->get_type()); + att.resp_msg = type + " images cannot be cloned."; + return Request::ACTION; } @@ -395,6 +398,7 @@ Request::ErrorCode ImageAPI::persistent(int oid, case Image::OS: case Image::DATABLOCK: case Image::CDROM: + case Image::FILESYSTEM: break; case Image::KERNEL: @@ -492,7 +496,9 @@ Request::ErrorCode ImageAPI::change_type(int oid, } break; case Image::BACKUP: - att.resp_msg = "Cannot change type for BACKUP images."; + case Image::FILESYSTEM: + string ctype = image->type_to_str(image->get_type()); + att.resp_msg = "Cannot change type for" + ctype + " images."; return Request::ACTION; } diff --git a/src/rm/api/VirtualMachineAPI.cc b/src/rm/api/VirtualMachineAPI.cc index 923b455c3b..466fee1c6b 100644 --- a/src/rm/api/VirtualMachineAPI.cc +++ b/src/rm/api/VirtualMachineAPI.cc @@ -889,11 +889,24 @@ Request::ErrorCode VirtualMachineAPI::migrate(int vid, return Request::ACTION; } - if (live && vm->is_pinned()) + if (live) { - att.resp_msg = "VM with a pinned NUMA topology cannot be live-migrated"; + if (vm->is_pinned()) + { + att.resp_msg = "VM with a pinned NUMA topology cannot be live-migrated"; - return Request::ACTION; + return Request::ACTION; + } + + for (auto *disk : vm->get_disks()) + { + if (disk->is_filesystem()) + { + att.resp_msg = "VM with Filesytem disks cannot be live-migrated"; + + return Request::ACTION; + } + } } // Get System DS information from current History record @@ -1256,6 +1269,7 @@ Request::ErrorCode VirtualMachineAPI::disk_save_as(int vid, case Image::RAMDISK: case Image::CONTEXT: case Image::BACKUP: + case Image::FILESYSTEM: goto error_image_type; } @@ -1383,7 +1397,7 @@ error_image: goto error_common; error_image_type: - att.resp_msg = "Cannot save_as image of type " + Image::type_to_str(type); + att.resp_msg = "Cannot save an image of type " + Image::type_to_str(type); ec = Request::INTERNAL; goto error_common; @@ -1441,7 +1455,6 @@ Request::ErrorCode VirtualMachineAPI::disk_snapshot_create(int vid, // Check request consistency (VM & disk exists, no volatile) // ------------------------------------------------------------------------ bool img_ds_quota, vm_ds_quota; - bool is_volatile; int img_id = -1; if (auto vm = vmpool->get_ro(vid)) @@ -1465,6 +1478,14 @@ Request::ErrorCode VirtualMachineAPI::disk_snapshot_create(int vid, return Request::ACTION; } + if (!disk->snapshot_support()) + { + att.resp_msg = "Cannot make snapshots on disks of type: " + + disk->vector_value("TYPE"); + + return Request::ACTION; + } + /* ---------------------------------------------------------------------- */ /* Get disk information and quota usage deltas */ /* ---------------------------------------------------------------------- */ @@ -1473,13 +1494,12 @@ Request::ErrorCode VirtualMachineAPI::disk_snapshot_create(int vid, // Snapshot accounts as another disk of same size disk->resize_quotas(ssize, ds_deltas, vm_deltas, img_ds_quota, vm_ds_quota); + if (vm->hasHistory() && !vm_deltas.empty()) { vm_deltas.add("CLUSTER_ID", vm->get_cid()); } - is_volatile = disk->is_volatile(); - disk->vector_value("IMAGE_ID", img_id); vm->get_permissions(vm_perms); @@ -1491,13 +1511,6 @@ Request::ErrorCode VirtualMachineAPI::disk_snapshot_create(int vid, return Request::NO_EXISTS; } - if (is_volatile) - { - att.resp_msg = "Cannot make snapshots on volatile disks"; - - return Request::ACTION; - } - /* ---------- Authorization and quota update requests ---------------------- */ att.set_auth_op(VMActions::DISK_SNAPSHOT_CREATE_ACTION); @@ -1634,6 +1647,14 @@ Request::ErrorCode VirtualMachineAPI::disk_snapshot_delete(int vid, return Request::ACTION; } + if (!disk->snapshot_support()) + { + att.resp_msg = "Snapshots are not supported on disks of type: " + + disk->vector_value("TYPE"); + + return Request::ACTION; + } + persistent = disk->is_persistent(); disk->vector_value("IMAGE_ID", img_id); @@ -1702,6 +1723,28 @@ Request::ErrorCode VirtualMachineAPI::disk_snapshot_revert(int vid, int snap_id, RequestAttributes& att) { + const VirtualMachineDisk * disk; + + if (auto vm = vmpool->get_ro(vid)) + { + disk = vm->get_disk(disk_id); + + if (disk == nullptr) + { + att.resp_msg = "VM disk does not exist"; + + return Request::ACTION; + } + + if (!disk->snapshot_support()) + { + att.resp_msg = "Snapshots are not supported on disks of type: " + + disk->vector_value("TYPE"); + + return Request::ACTION; + } + } + // Authorize the request att.set_auth_op(VMActions::DISK_SNAPSHOT_REVERT_ACTION); @@ -1758,6 +1801,14 @@ Request::ErrorCode VirtualMachineAPI::disk_snapshot_rename(int vid, return Request::ACTION; } + if (!disk->snapshot_support()) + { + att.resp_msg = "Snapshots are not supported on disks of type: " + + disk->vector_value("TYPE"); + + return Request::ACTION; + } + int rc = vm->rename_disk_snapshot(disk_id, snap_id, new_name, att.resp_msg); if ( rc != 0 ) @@ -1967,6 +2018,20 @@ Request::ErrorCode VirtualMachineAPI::disk_detach(int vid, return Request::NO_EXISTS; } + const VirtualMachineDisk * disk; + + if (auto vm = vmpool->get_ro(vid)) + { + disk = vm->get_disk(disk_id); + + if (disk == nullptr) + { + att.resp_msg = "VM disk does not exist"; + + return Request::ACTION; + } + } + auto dm = Nebula::instance().get_dm(); int rc = dm->detach(vid, disk_id, att, att.resp_msg); @@ -2041,6 +2106,7 @@ Request::ErrorCode VirtualMachineAPI::disk_resize(int vid, /* ------------- Get information about the disk and image --------------- */ disk->resize_quotas(size - current_size, ds_deltas, vm_deltas, img_ds_quota, vm_ds_quota); + if (vm->hasHistory() && !vm_deltas.empty()) { vm_deltas.add("CLUSTER_ID", vm->get_cid()); diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index bc9c87bec9..f532460d38 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -132,6 +132,10 @@ int TransferManager::prolog_transfer_command( << vm->get_ds_id() << endl; } + else if ( type == "FILESYSTEM" ) + { + return 0; + } else { // ----------------------------------------------------------------- @@ -562,7 +566,11 @@ void TransferManager::trigger_prolog_migr(VirtualMachine * vm) { disk_id = disk->get_disk_id(); - if ( disk->is_volatile() == true ) + if (disk->is_filesystem()) + { + continue; + } + else if (disk->is_volatile()) { tm_mad = vm_tm_mad; ds_id = vm->get_ds_id(); @@ -718,7 +726,7 @@ void TransferManager::trigger_prolog_resume(VirtualMachine * vm) { disk_id = disk->get_disk_id(); - if ( disk->is_volatile() == true ) + if ( disk->is_volatile() || disk->is_filesystem() ) { tm_mad = vm_tm_mad; ds_id = vm->get_ds_id(); @@ -938,6 +946,11 @@ void TransferManager::epilog_transfer_command( int disk_id = disk->get_disk_id(); string tm_mad_system; + if (disk->is_filesystem()) + { + return; + } + if ( one_util::toupper(save) == "YES" ) { const string& source = disk->vector_value("SOURCE"); @@ -978,7 +991,7 @@ void TransferManager::epilog_transfer_command( int ds_id_i; int vv_rc = 0; - if ( disk->is_volatile() == true ) + if (disk->is_volatile()) { tm_mad = vm->get_tm_mad(); ds_id_i = vm->get_ds_id(); @@ -1203,7 +1216,11 @@ void TransferManager::trigger_epilog_stop(VirtualMachine * vm) { disk_id = disk->get_disk_id(); - if ( disk->is_volatile() == true ) + if (disk->is_filesystem()) + { + continue; + } + else if (disk->is_volatile()) { tm_mad = vm_tm_mad; ds_id = vm->get_ds_id(); @@ -1353,7 +1370,11 @@ int TransferManager::epilog_delete_commands(VirtualMachine *vm, { disk_id = disk->get_disk_id(); - if ( disk->is_volatile() == true ) + if (disk->is_filesystem()) + { + continue; + } + else if (disk->is_volatile()) { tm_mad = vm_tm_mad; ds_id = vm_ds_id; @@ -2133,7 +2154,11 @@ void TransferManager::resize_command(VirtualMachine * vm, string tm_mad_system; string ds_id; - if ( disk->is_volatile() ) + if (disk->is_filesystem()) + { + return; + } + else if (disk->is_volatile()) { tm_mad = vm->get_tm_mad(); ds_id = std::to_string(vm->get_ds_id()); diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 3356eaf773..7e4556f826 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -1669,6 +1669,11 @@ static int get_datastore_requirements(Template *tmpl, set& ds_ids, for (int i=0; ivector_value("TYPE") == "FILESYSTEM" ) + { + continue; + } + bool is_shareable; vatts[i]->vector_value("SHAREABLE", is_shareable); shareable = shareable || is_shareable; diff --git a/src/vm/VirtualMachineContext.cc b/src/vm/VirtualMachineContext.cc index d490c1ebf8..64da11f0a3 100644 --- a/src/vm/VirtualMachineContext.cc +++ b/src/vm/VirtualMachineContext.cc @@ -72,6 +72,18 @@ const std::vector NETWORK6_CONTEXT = {"EXTERNAL", "EXTERNAL", "", false}, }; +struct DiskContextVariable +{ + std::string context_name; + std::string disk_name; +}; + +const std::vector DISK_CONTEXT = +{ + {"MOUNT_TAG", "MOUNT_TAG"}, + {"MOUNT_POINT", "MOUNT_POINT"} +}; + bool is_restricted(const string& path, const set& restricted, const set& safe) @@ -136,6 +148,7 @@ int VirtualMachine::generate_context(string &files, int &disk_id, // ------------------------------------------------------------------------- // Generate dynamic context attributes // - Network + // - Disk FS // - PCI guest address //-------------------------------------------------------------------------- int rc = generate_network_context(context, error_str, false); //no AUTO mode @@ -154,6 +167,18 @@ int VirtualMachine::generate_context(string &files, int &disk_id, return -1; } + rc = generate_disk_context(context, error_str); + + if ( rc != 0 ) + { + ostringstream oss; + + oss << "Cannot parse disk context:: " << error_str; + log("VM", Log::ERROR, oss); + + return -1; + } + vector vatts; obj_template->get("PCI", vatts); @@ -513,6 +538,56 @@ int VirtualMachine::generate_network_context(VectorAttribute* context, /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ + +static void parse_context_disk(const std::vector& cvars, + VectorAttribute * _context, VectorAttribute * disk) +{ + const string& disk_id = disk->vector_value("DISK_ID"); + + if (disk_id.empty()) + { + return; + } + + for (const auto& con : cvars) + { + ostringstream cvar; + string cval; + + cvar << "DISK" << disk_id << "_" << con.context_name; + + cval = disk->vector_value(con.disk_name); + + _context->replace(cvar.str(), cval); + } +} + +/* -------------------------------------------------------------------------- */ + +int VirtualMachine::generate_disk_context(VectorAttribute* context, + string& error_str) +{ + vector disks; + VectorAttribute tmp_context("TMP_CONTEXT"); + + int num = obj_template->get("DISK", disks); + + for (int i = 0; i < num; i++) + { + if ( disks[i]->vector_value("TYPE") != "FILESYSTEM" ) + { + continue; + } + + parse_context_disk(DISK_CONTEXT, context, disks[i]); + } + + return 0; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + static void parse_pci_context_network(const std::vector& cvars, VectorAttribute * context, const VectorAttribute * nic) { @@ -873,5 +948,28 @@ void VirtualMachine::clear_nic_alias_context(int nicid, int aliasidx) clear_context_alias_network(NETWORK6_CONTEXT, context, nicid, aliasidx); } +/* -------------------------------------------------------------------------- */ + +void VirtualMachine::clear_disk_context(int disk_id) +{ + VectorAttribute * context = obj_template->get("CONTEXT"); + + if (context == 0) + { + return; + } + + ostringstream att_name; + + for (const auto& con : DISK_CONTEXT) + { + att_name.str(""); + + att_name << "DISK" << disk_id << "_" << con.context_name; + + context->remove(att_name.str()); + } +} + /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ diff --git a/src/vm/VirtualMachineDisk.cc b/src/vm/VirtualMachineDisk.cc index f7c439ac60..b55e51043a 100644 --- a/src/vm/VirtualMachineDisk.cc +++ b/src/vm/VirtualMachineDisk.cc @@ -14,6 +14,8 @@ /* limitations under the License. */ /* -------------------------------------------------------------------------- */ +#include + #include "VirtualMachineDisk.h" #include "NebulaUtil.h" #include "Nebula.h" @@ -680,6 +682,14 @@ void VirtualMachineDisk::to_xml_short(std::ostringstream& oss) const oss << ""; } +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +bool VirtualMachineDisk::is_filesystem() const +{ + return vector_value("TYPE") == "FILESYSTEM"; +} + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -873,6 +883,8 @@ int VirtualMachineDisks::get_images(int vm_id, int uid, const std::string& tsys, std::string cdrom_dev_prefix; + std::set mount_tags; + if ( is_q35 ) { cdrom_dev_prefix = "sd"; @@ -912,6 +924,34 @@ int VirtualMachineDisks::get_images(int vm_id, int uid, const std::string& tsys, goto error_common; } + if (image_type == Image::FILESYSTEM) + { + if(std::find(acquired_images.begin(), acquired_images.end(), image_id) != acquired_images.end()) + { + error_str = "File system image can only be added once to the same VM"; + + delete disk; + + goto error_common; + } + + string mount_tag = disk->vector_value("MOUNT_TAG"); + + if (!mount_tag.empty()) + { + if (mount_tags.find(mount_tag) != mount_tags.end()) + { + error_str = "MOUNT_TAG '" + mount_tag + "' is duplicated across disks"; + + delete disk; + + goto error_common; + } + + mount_tags.insert(mount_tag); + } + } + add_attribute(disk, disk_id); if (snapshots != 0) @@ -1199,12 +1239,19 @@ void VirtualMachineDisks::clear_cloning_image_id(int iid, /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int VirtualMachineDisks::set_attach(int id) +int VirtualMachineDisks::set_attach(int id, string& error) { VirtualMachineDisk * disk = get_disk(id); if ( disk == 0 ) { + error = "Disk " + to_string(id) + " does not exist"; + return -1; + } + + if ( disk->is_filesystem() ) + { + error = "FILESYSTEM disks can not be detached"; return -1; } @@ -1296,6 +1343,14 @@ VirtualMachineDisk * VirtualMachineDisks::set_up_attach(int vmid, int uid, return 0; } + if ( disk->is_filesystem() ) + { + error = "Can not attach disks " + disk->vector_value("TYPE"); + + delete disk; + return 0; + } + disk->set_snapshots(snap); string target = disk->vector_value("TARGET"); @@ -1391,6 +1446,12 @@ int VirtualMachineDisks::set_up_resize(int disk_id, long size, string& err) return -1; } + if (disk->is_filesystem()) + { + err = "FILESYSTEM disks can not be resized"; + return -1; + } + if ( disk->vector_value("SIZE", size_prev) != 0 ) { err = "Wrong format for disk SIZE"; @@ -1709,7 +1770,9 @@ bool VirtualMachineDisks::backup_increment(bool do_volatile) one_util::toupper(type); - if ((type == "SWAP") || ((type == "FS") && !do_volatile)) + if ((type == "SWAP") || + ((type == "FS") && !do_volatile) || + (type == "FILESYSTEM")) { continue; } @@ -1755,6 +1818,7 @@ void VirtualMachineDisks::backup_disk_ids(bool do_volatile, std::vector& id if ((type == "SWAP") || (type == "CDROM") || (type == "RBD_CDROM") || + (type == "FILESYSTEM") || ((type == "FS") && !do_volatile)) { continue; @@ -1920,6 +1984,11 @@ int VirtualMachineDisks::check_tm_mad(const string& tm_mad, string& error) continue; } + if (disk->is_filesystem()) + { + continue; + } + if ( disk->vector_value("DATASTORE_ID", ds_img_id) == 0 ) { std::string ln_target, clone_target, disk_type; @@ -1948,4 +2017,3 @@ int VirtualMachineDisks::check_tm_mad(const string& tm_mad, string& error) } return 0; } - diff --git a/src/vm/VirtualMachinePool.cc b/src/vm/VirtualMachinePool.cc index 21db76583e..a1bf00c5f7 100644 --- a/src/vm/VirtualMachinePool.cc +++ b/src/vm/VirtualMachinePool.cc @@ -974,6 +974,11 @@ void VirtualMachinePool::delete_attach_disk(std::unique_ptr vm) return; } + if (disk->is_filesystem()) + { + vm->clear_disk_context(disk->get_disk_id()); + } + // skip image release if there is other disk using the same image int image_id; set image_ids; diff --git a/src/vmm/LibVirtDriverKVM.cc b/src/vmm/LibVirtDriverKVM.cc index 63a56986dc..99b39272db 100644 --- a/src/vmm/LibVirtDriverKVM.cc +++ b/src/vmm/LibVirtDriverKVM.cc @@ -303,10 +303,9 @@ static void numa_distances(std::ofstream& file, static void vtopol(ofstream& file, const VectorAttribute * topology, std::vector &nodes, std::string &numatune, - std::string &membacking) + std::string &membacking, int &hpsz_kb) { std::string ma; - int hpsz_kb = 0; if ( topology != 0 ) { @@ -411,21 +410,6 @@ static void vtopol(ofstream& file, const VectorAttribute * topology, oss << "\t\n"; numatune = oss.str(); - - if ( hpsz_kb != 0 ) - { - std::ostringstream mboss; - - mboss << "\t\n"; - mboss << "\t\t\n"; - - mboss << "\t\t\t\n"; - - mboss << "\t\t\n"; - mboss << "\t\n"; - - membacking = mboss.str(); - } } /** @@ -645,6 +629,7 @@ int LibVirtDriver::deployment_description_kvm( string gluster_host; string gluster_volume; string luks_secret; + string mount_tag; string total_bytes_sec; string total_bytes_sec_max_length; @@ -742,6 +727,7 @@ int LibVirtDriver::deployment_description_kvm( string vm_func; string vm_index; + bool is_fs = false; bool pae = false; bool acpi = false; bool apic = false; @@ -1073,6 +1059,8 @@ int LibVirtDriver::deployment_description_kvm( // ------------------------------------------------------------------------ // CPU SECTION // ------------------------------------------------------------------------ + int hpsz_kb = 0; + get_attribute(vm, host, cluster, "CPU_MODEL", "MODEL", cpu_model); get_attribute(vm, host, cluster, "CPU_MODEL", "FEATURES", cpu_feature); get_attribute(nullptr, nullptr, cluster, "EVC_MODE", cpu_evc_mode); @@ -1136,7 +1124,7 @@ int LibVirtDriver::deployment_description_kvm( << " unit='KiB'/>\n\t\t" << endl; } - vtopol(file, topology, nodes, numa_tune, mbacking); + vtopol(file, topology, nodes, numa_tune, mbacking, hpsz_kb); file << "\t\n"; } @@ -1146,11 +1134,6 @@ int LibVirtDriver::deployment_description_kvm( file << numa_tune; } - if (!mbacking.empty()) - { - file << mbacking; - } - get_attribute(vm, host, cluster, "FEATURES", "IOTHREADS", iothreads); if ( iothreads > 0 ) @@ -1267,6 +1250,8 @@ int LibVirtDriver::deployment_description_kvm( luks_secret = disk[i]->vector_value("LUKS_SECRET"); + mount_tag = disk[i]->vector_value("MOUNT_TAG"); + sheepdog_host = disk[i]->vector_value("SHEEPDOG_HOST"); total_bytes_sec = disk[i]->vector_value("TOTAL_BYTES_SEC"); @@ -1325,7 +1310,7 @@ int LibVirtDriver::deployment_description_kvm( disk[i]->vector_value_str("DISK_ID", disk_id); - if (target.empty()) + if (target.empty() && type != "FILESYSTEM") { vm->log("VMM", Log::ERROR, "Wrong target value in DISK."); return -1; @@ -1521,6 +1506,45 @@ int LibVirtDriver::deployment_description_kvm( << "\t\t\t\n"; } + else if ( type == "FILESYSTEM" ) + { + string uid_map, gid_map; + + is_fs = true; + + file << "\t\t\n" + << "\t\t\t\n" + << "\t\t\t\n" + << "\t\t\t\n"; + + if (readonly) + { + file << "\t\t\t" << endl; + } + + get_attribute(nullptr, host, cluster, "DISK", "UID_MAP", uid_map); + get_attribute(nullptr, host, cluster, "DISK", "GID_MAP", gid_map); + + if (uid_map.empty()) + { + uid_map = "9869"; + } + + if (gid_map.empty()) + { + gid_map = "9869"; + } + + file << "\t\t\t\n" + << "\t\t\t\t\n" + << "\t\t\t\t\n" + << "\t\t\t\n"; + + file << "\t\t\n"; + + // Skip the rest of disk processing for SharedFS + continue; + } else { ostringstream fname; @@ -2574,6 +2598,40 @@ int LibVirtDriver::deployment_description_kvm( file << "\t" << endl; + // ------------------------------------------------------------------------ + // Write memory backing (may have been updated by disk processing, e.g. virtiofs) + // Must be at domain level, not inside + // ------------------------------------------------------------------------ + if (hpsz_kb != 0 || is_fs) + { + std::ostringstream mboss; + + mboss << "\t\n"; + + if (hpsz_kb != 0) + { + mboss << "\t\t\n"; + mboss << "\t\t\t\n"; + mboss << "\t\t\n"; + } + else + { + mboss << "\t\t\n"; + } + + // Note: When a FileSystem disk is present MEMROY_ACCESS (if set) needs + // to be shared (set in memAccess in each NUMA node). Default to shared + // when a FileSystem disk is present. + if (is_fs) + { + mboss << "\t\t\n"; + } + + mboss << "\t\n"; + + file << mboss.str(); + } + // ------------------------------------------------------------------------ // Features // ------------------------------------------------------------------------ diff --git a/src/vmm/VirtualMachineManager.cc b/src/vmm/VirtualMachineManager.cc index 0579984487..d8bb2cbfa4 100644 --- a/src/vmm/VirtualMachineManager.cc +++ b/src/vmm/VirtualMachineManager.cc @@ -525,6 +525,15 @@ void VirtualMachineManager::trigger_save(int vid) goto error_driver; } + // Check for unsopported disks + for (auto *disk : vm->get_disks()) + { + if (disk->is_filesystem()) + { + goto error_unsupported; + } + } + // Use previous host if it is a migration if ( vm->get_lcm_state() == VirtualMachine::SAVE_MIGRATE ) { @@ -571,6 +580,10 @@ error_driver: os << "save_action, error getting driver " << vm->get_vmm_mad(); goto error_common; +error_unsupported: + os << "save_action, Filesystem disks are not supported"; + goto error_common; + error_previous_history: os << "save_action, VM has no previous history"; diff --git a/src/vmm_mad/exec/arm64/vmm_exec_kvm.conf b/src/vmm_mad/exec/arm64/vmm_exec_kvm.conf index 92a19d07db..fd22b1fa17 100644 --- a/src/vmm_mad/exec/arm64/vmm_exec_kvm.conf +++ b/src/vmm_mad/exec/arm64/vmm_exec_kvm.conf @@ -68,6 +68,8 @@ # - WRITE_IOPS_SEC_MAX # - WRITE_IOPS_SEC_MAX_LENGTH # - SIZE_IOPS_SEC +# - UID_MAP +# - GID_MAP # * NIC: # - FILTER # - MODEL @@ -114,7 +116,9 @@ FEATURES = [ DISK = [ DRIVER = "raw", CACHE = "none", - DISCARD = "unmap" + DISCARD = "unmap", + UID_MAP = "9869", + GID_MAP = "9869" ] NIC = [ diff --git a/src/vmm_mad/exec/x86_64/vmm_exec_kvm.conf b/src/vmm_mad/exec/x86_64/vmm_exec_kvm.conf index 80a6039bd8..567d3a8f7a 100644 --- a/src/vmm_mad/exec/x86_64/vmm_exec_kvm.conf +++ b/src/vmm_mad/exec/x86_64/vmm_exec_kvm.conf @@ -68,6 +68,8 @@ # - WRITE_IOPS_SEC_MAX # - WRITE_IOPS_SEC_MAX_LENGTH # - SIZE_IOPS_SEC +# - UID_MAP +# - GID_MAP # * NIC: # - FILTER # - MODEL @@ -115,7 +117,9 @@ FEATURES = [ DISK = [ DRIVER = "raw", CACHE = "none", - DISCARD = "unmap" + DISCARD = "unmap", + UID_MAP = "9869", + GID_MAP = "9869" ] NIC = [