From fa72e8fd7f905e9eed3796d62cb6d9dddaededf4 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Wed, 25 Feb 2026 18:32:47 +0100 Subject: [PATCH] F #7373: FSaaS (File System as a Service) for OpenNebula NAME = test_ds DS_MAD = virtiofs TM_MAD = local TYPE = IMAGE_DS DISK_TYPE = FILESYSTEM oneadmin@ubuntu2204-kvm-ssh-7-0-f4a9-0:~$ cat img.txt NAME="test_fs" TYPE="FILESYSTEM" PATH="/var/tmp/sharedfs_test" PERSISTENT="YES" PERSISTENT_TYPE="SHAREABLE" DISK=[ IMAGE_ID="21", MOUNTPOINT="/mnt", TARGET="disk0_tag" ] co-authored-by: MarioRobres co-authored-by: Marco Mancini Signed-off-by: MarioRobres Signed-off-by: Marco Mancini --- include/Image.h | 34 ++--- include/VirtualMachine.h | 16 +++ include/VirtualMachineDisk.h | 11 ++ install.sh | 12 ++ share/etc/oned.conf | 6 +- src/datastore/Datastore.cc | 3 + src/datastore_mad/remotes/virtiofs/clone | 1 + src/datastore_mad/remotes/virtiofs/cp | 71 +++++++++++ src/datastore_mad/remotes/virtiofs/mkfs | 1 + src/datastore_mad/remotes/virtiofs/monitor | 24 ++++ src/datastore_mad/remotes/virtiofs/rm | 21 ++++ .../remotes/virtiofs/snap_delete | 1 + .../remotes/virtiofs/snap_flatten | 1 + .../remotes/virtiofs/snap_revert | 1 + src/datastore_mad/remotes/virtiofs/stat | 23 ++++ src/image/Image.cc | 38 +++++- src/image/ImageManagerActions.cc | 26 ++-- src/image/ImagePool.cc | 1 + .../org/opennebula/client/image/Image.java | 4 +- src/oca/python/pyone/__init__.py | 4 +- src/oca/ruby/opennebula/image.rb | 19 +-- src/rm/api/ImageAPI.cc | 10 +- src/rm/api/VirtualMachineAPI.cc | 68 ++++++++++ src/tm/TransferManager.cc | 13 ++ src/tm_mad/lib/tm_action.rb | 2 +- src/tm_mad/local/clone | 7 ++ src/vm/VirtualMachine.cc | 6 + src/vm/VirtualMachineContext.cc | 119 ++++++++++++++++++ src/vm/VirtualMachineDisk.cc | 35 +++++- src/vm/VirtualMachinePool.cc | 5 + src/vmm/LibVirtDriverKVM.cc | 47 ++++++- 31 files changed, 582 insertions(+), 48 deletions(-) create mode 120000 src/datastore_mad/remotes/virtiofs/clone create mode 100755 src/datastore_mad/remotes/virtiofs/cp create mode 120000 src/datastore_mad/remotes/virtiofs/mkfs create mode 100755 src/datastore_mad/remotes/virtiofs/monitor create mode 100755 src/datastore_mad/remotes/virtiofs/rm create mode 120000 src/datastore_mad/remotes/virtiofs/snap_delete create mode 120000 src/datastore_mad/remotes/virtiofs/snap_flatten create mode 120000 src/datastore_mad/remotes/virtiofs/snap_revert create mode 100755 src/datastore_mad/remotes/virtiofs/stat 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..c20361d34e 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -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..c0daa80827 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" @@ -377,6 +378,16 @@ public: */ void to_xml_short(std::ostringstream& oss) const; + /* ---------------------------------------------------------------------- */ + /* Disk requirements helpers */ + /* ---------------------------------------------------------------------- */ + /** + * Checks if the disk should be skipped when computing VM requirements + * + * @return true if the disk should be skipped + */ + bool skip_disk() const; + private: Snapshots * snapshots; 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 5666983372..eea08a4f72 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" ] #******************************************************************************* @@ -1260,6 +1260,10 @@ DS_MAD_CONF = [ NAME = "purefa", PERSISTENT_ONLY = "NO", MARKETPLACE_ACTIONS = "export", REQUIRED_ATTRS = "PUREFA_HOST,PUREFA_API_TOKEN,PUREFA_TARGET" ] +DS_MAD_CONF = [ + NAME = "virtiofs", REQUIRED_ATTRS = "", PERSISTENT_ONLY = "YES", + MARKETPLACE_ACTIONS = "export" +] #******************************************************************************* # MarketPlace Driver Behavior Configuration diff --git a/src/datastore/Datastore.cc b/src/datastore/Datastore.cc index e7201240cb..045eec1192 100644 --- a/src/datastore/Datastore.cc +++ b/src/datastore/Datastore.cc @@ -580,6 +580,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: @@ -602,6 +603,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: @@ -1271,6 +1273,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..d551169772 --- /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=1" +echo "FREE_MB=1" + +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..8053c0376a --- /dev/null +++ b/src/datastore_mad/remotes/virtiofs/stat @@ -0,0 +1,23 @@ +#!/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 "0" + +exit 0 diff --git a/src/image/Image.cc b/src/image/Image.cc index 3a124e687a..40745092e6 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -135,6 +135,11 @@ int Image::insert(SqlDB *db, string& error_str) } break; + case FILESYSTEM: + persistent_img = one_util::icasecmp(persistent_attr, "YES"); + erase_template_attribute("DEV_PREFIX", dev_prefix); + break; + case CDROM: // dev_prefix set based on VM chipset and use custom SAVE,CLONE case KERNEL: // Files are always non-persistent with no dev_prefix case RAMDISK: @@ -224,6 +229,19 @@ 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 + if (format.empty()) + { + format = "dir"; // default + } + else if (one_util::icasecmp(format, "dir") != 0) + { + error_str = "FORMAT for FILESYSTEM images must be 'dir'."; + goto error_common; + } + } else //CDROM, KERNEL, RAMDISK, CONTEXT { error_str = "No PATH nor SOURCE in template."; @@ -573,7 +591,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 +664,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"); } @@ -703,6 +721,10 @@ void Image::disk_attribute(VirtualMachineDisk * disk, disk_attr_type = disk_type_to_str(new_disk_type); break; + case FILESYSTEM: + disk_attr_type = disk_type_to_str(FILE_SYSTEM); + break; + default: //Other file types should not be never a DISK break; } @@ -792,6 +814,10 @@ int Image::set_type(string& _type, string& error) { type = BACKUP; } + else if ( _type == "FILESYSTEM" ) + { + type = FILESYSTEM; + } else { error = "Unknown type " + type; @@ -869,6 +895,10 @@ Image::ImageType Image::str_to_type(string& str_type) { it = BACKUP; } + else if ( str_type == "FILESYSTEM" ) + { + it = FILESYSTEM; + } return it; } @@ -979,6 +1009,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 1266074d1a..2454711bf6 100644 --- a/src/oca/python/pyone/__init__.py +++ b/src/oca/python/pyone/__init__.py @@ -65,7 +65,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 @@ -86,7 +86,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 f5f617a205..0637f9a42b 100644 --- a/src/rm/api/VirtualMachineAPI.cc +++ b/src/rm/api/VirtualMachineAPI.cc @@ -1249,6 +1249,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; } @@ -1458,6 +1459,14 @@ Request::ErrorCode VirtualMachineAPI::disk_snapshot_create(int vid, return Request::ACTION; } + if (disk->skip_disk()) + { + att.resp_msg = "Action \"disk-snapshot-create\" is not compatible with " + "disks " + disk->vector_value("TYPE"); + + return Request::ACTION; + } + /* ---------------------------------------------------------------------- */ /* Get disk information and quota usage deltas */ /* ---------------------------------------------------------------------- */ @@ -1627,6 +1636,14 @@ Request::ErrorCode VirtualMachineAPI::disk_snapshot_delete(int vid, return Request::ACTION; } + if (disk->skip_disk()) + { + att.resp_msg = "Action \"disk-snapshot-delete\" is not compatible with " + "disks " + disk->vector_value("TYPE"); + + return Request::ACTION; + } + persistent = disk->is_persistent(); disk->vector_value("IMAGE_ID", img_id); @@ -1695,6 +1712,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->skip_disk()) + { + att.resp_msg = "Action \"disk-snapshot-revert\" is not compatible with " + "disks " + disk->vector_value("TYPE"); + + return Request::ACTION; + } + } + // Authorize the request att.set_auth_op(VMActions::DISK_SNAPSHOT_REVERT_ACTION); @@ -1751,6 +1790,14 @@ Request::ErrorCode VirtualMachineAPI::disk_snapshot_rename(int vid, return Request::ACTION; } + if (disk->skip_disk()) + { + att.resp_msg = "Action \"disk-snapshot-rename\" is not compatible with " + "disks " + 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 ) @@ -1960,6 +2007,27 @@ 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; + } + + if (disk->skip_disk()) + { + att.resp_msg = "Can not detach disks " + disk->vector_value("TYPE"); + + return Request::ACTION; + } + } + auto dm = Nebula::instance().get_dm(); int rc = dm->detach(vid, disk_id, att, att.resp_msg); diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index bc9c87bec9..aa1c22e968 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -132,6 +132,19 @@ int TransferManager::prolog_transfer_command( << vm->get_ds_id() << endl; } + else if ( type == "FILESYSTEM" ) + { + const string& target = disk->vector_value("TARGET"); + + if ( target.empty() ) + { + os << "No target in FILESYSTEM disk"; + + return -1; + } + + return 0; + } else { // ----------------------------------------------------------------- diff --git a/src/tm_mad/lib/tm_action.rb b/src/tm_mad/lib/tm_action.rb index c8d24d34aa..b6df8f0b5a 100644 --- a/src/tm_mad/lib/tm_action.rb +++ b/src/tm_mad/lib/tm_action.rb @@ -461,7 +461,7 @@ module TransferManager disk_format = disk_attribute(disk_id, 'FORMAT') case disk_format - when 'raw', 'qcow2' + when 'raw', 'qcow2', 'dir' disk_format.to_sym end end diff --git a/src/tm_mad/local/clone b/src/tm_mad/local/clone index 9106d5a9e4..e0ba4e69d8 100755 --- a/src/tm_mad/local/clone +++ b/src/tm_mad/local/clone @@ -204,6 +204,13 @@ script, host = popd SCRIPT + when :dir + [<<~SCRIPT, src.host] + set -e -o pipefail + + tar -C #{src.path} -cf - . \$SRC_SNAP | \ + ssh #{dst.host} "mkdir -p #{dst.path} && tar -x#{tar_opt} - -C #{dst.path}" + SCRIPT end rc = clone.ssh(:cmds => script, diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 3356eaf773..1626303d5a 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -1669,6 +1669,12 @@ 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..78edd9e6e6 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 = +{ + {"TAG", "TARGET"}, + {"MOUNTPOINT", "MOUNTPOINT"} +}; + 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,77 @@ 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++) + { + // TODO: use VirtualMachineDisk::skip_disk() + if ( disks[i]->vector_value("TYPE") != "FILESYSTEM" ) + { + continue; + } + + parse_context_disk(DISK_CONTEXT, &tmp_context, disks[i]); + } + + string str = tmp_context.marshall(); + + if (str.empty()) + { + return 0; + } + + string parsed; + int rc = parse_template_attribute(str, parsed, error_str); + + if (rc != 0) + { + return -1; + } + + tmp_context.clear(); + tmp_context.unmarshall(parsed); + + context->merge(&tmp_context, true); + + return 0; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + static void parse_pci_context_network(const std::vector& cvars, VectorAttribute * context, const VectorAttribute * nic) { @@ -873,5 +969,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..d3157d3615 100644 --- a/src/vm/VirtualMachineDisk.cc +++ b/src/vm/VirtualMachineDisk.cc @@ -680,6 +680,23 @@ void VirtualMachineDisk::to_xml_short(std::ostringstream& oss) const oss << ""; } +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +bool VirtualMachineDisk::skip_disk() const +{ + std::string type = vector_value("TYPE"); + Image::DiskType dtype = Image::str_to_disk_type(type); + + switch (dtype) + { + case Image::FILE_SYSTEM: + return true; + default: + return false; + } +} + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -1296,6 +1313,14 @@ VirtualMachineDisk * VirtualMachineDisks::set_up_attach(int vmid, int uid, return 0; } + if ( disk->skip_disk() ) + { + error = "Can not attach disks " + disk->vector_value("TYPE"); + + delete disk; + return 0; + } + disk->set_snapshots(snap); string target = disk->vector_value("TARGET"); @@ -1709,7 +1734,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) || + disk->skip_disk()) { continue; } @@ -1755,6 +1782,7 @@ void VirtualMachineDisks::backup_disk_ids(bool do_volatile, std::vector& id if ((type == "SWAP") || (type == "CDROM") || (type == "RBD_CDROM") || + (disk->skip_disk()) || ((type == "FS") && !do_volatile)) { continue; @@ -1920,6 +1948,11 @@ int VirtualMachineDisks::check_tm_mad(const string& tm_mad, string& error) continue; } + if (disk->skip_disk()) + { + continue; + } + if ( disk->vector_value("DATASTORE_ID", ds_img_id) == 0 ) { std::string ln_target, clone_target, disk_type; diff --git a/src/vm/VirtualMachinePool.cc b/src/vm/VirtualMachinePool.cc index 21db76583e..2392604bfa 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->skip_disk()) + { + 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 c940303552..f07a21274f 100644 --- a/src/vmm/LibVirtDriverKVM.cc +++ b/src/vmm/LibVirtDriverKVM.cc @@ -1148,11 +1148,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 ) @@ -1523,6 +1518,39 @@ int LibVirtDriver::deployment_description_kvm( << "\t\t\t\n"; } + else if ( type == "FILESYSTEM" ) + { + // SharedFS filesystem - generate XML instead of + file << "\t\t\n" + << "\t\t\t\n" + << "\t\t\t\n" + << "\t\t\t\n" + << "\t\t\n"; + + // Ensure memoryBacking with memfd and shared access for virtiofs + if (mbacking.empty()) + { + std::ostringstream mboss; + mboss << "\t\n"; + mboss << "\t\t\n"; + mboss << "\t\t\n"; + mboss << "\t\n"; + mbacking = mboss.str(); + } + else + { + // mbacking already exists (e.g., from hugepages), add virtiofs elements + // Insert before the closing tag + size_t pos = mbacking.rfind("\t\n"); + if (pos != std::string::npos) + { + mbacking.insert(pos, "\t\t\n\t\t\n"); + } + } + + // Skip the rest of disk processing for SharedFS + continue; + } else { ostringstream fname; @@ -2576,6 +2604,15 @@ 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 (!mbacking.empty()) + { + file << mbacking; + } + // ------------------------------------------------------------------------ // Features // ------------------------------------------------------------------------