Merge pull request #1737 from SimonFair/Enable-subvol-or-dataset-for-VMs

Update my_mkdir and VMs to use my_mkdir
This commit is contained in:
tom mortensen
2024-05-23 23:11:27 -07:00
committed by GitHub
4 changed files with 45 additions and 30 deletions
@@ -396,8 +396,8 @@ case 'disk-create':
$driver = $_REQUEST['driver'];
$size = str_replace(["KB","MB","GB","TB","PB", " ", ","], ["K","M","G","T","P", "", ""], strtoupper($_REQUEST['size']));
$dir = dirname($disk);
if (!is_dir($dir)) mkdir($dir);
#if (!is_dir($dir)) my_mkdir($dir);
#if (!is_dir($dir)) mkdir($dir);
if (!is_dir($dir)) my_mkdir($dir);
// determine the actual disk if user share is being used
$dir = transpose_user_path($dir);
#@exec("chattr +C -R ".escapeshellarg($dir)." >/dev/null");
@@ -175,10 +175,10 @@
// create folder if needed
if (!is_dir($strImgFolder)) {
mkdir($strImgFolder, 0777, true);
#my_mkdir($strImgFolder, 0777, true);
chown($strImgFolder, 'nobody');
chgrp($strImgFolder, 'users');
#mkdir($strImgFolder, 0777, true);
my_mkdir($strImgFolder, 0777, true);
#chown($strImgFolder, 'nobody');
#chgrp($strImgFolder, 'users');
}
$this->set_folder_nodatacow($strImgFolder);
@@ -192,10 +192,10 @@
// create parent folder if needed
if (!is_dir($path_parts['dirname'])) {
mkdir($path_parts['dirname'], 0777, true);
#my_mkdir($path_parts['dirname'], 0777, true);
chown($path_parts['dirname'], 'nobody');
chgrp($path_parts['dirname'], 'users');
#mkdir($path_parts['dirname'], 0777, true);
my_mkdir($path_parts['dirname'], 0777, true);
#chown($path_parts['dirname'], 'nobody');
#chgrp($path_parts['dirname'], 'users');
}
$this->set_folder_nodatacow($path_parts['dirname']);
@@ -219,10 +219,10 @@
// create folder if needed
$strImgRawLocationParent = dirname($strImgRawLocationPath);
if (!is_dir($strImgRawLocationParent)) {
mkdir($strImgRawLocationParent, 0777, true);
#my_mkdir($strImgRawLocationParent, 0777, true);
chown($strImgRawLocationParent, 'nobody');
chgrp($strImgRawLocationParent, 'users');
#mkdir($strImgRawLocationParent, 0777, true);
my_mkdir($strImgRawLocationParent, 0777, true);
#chown($strImgRawLocationParent, 'nobody');
#chgrp($strImgRawLocationParent, 'users');
}
$this->set_folder_nodatacow($strImgRawLocationParent);
@@ -1717,10 +1717,10 @@ private static $encoding = 'UTF-8';
if ($storage == "default") $clonedir = $domain_cfg['DOMAINDIR'].$clone ; else $clonedir = str_replace('/mnt/user/', "/mnt/$storage/", $domain_cfg['DOMAINDIR']).$clone;
if (!is_dir($clonedir)) {
mkdir($clonedir,0777,true);
#my_mkdir($clonedir,0777,true);
chown($clonedir, 'nobody');
chgrp($clonedir, 'users');
#mkdir($clonedir,0777,true);
my_mkdir($clonedir,0777,true);
#chown($clonedir, 'nobody');
#chgrp($clonedir, 'users');
}
write("addLog\0".htmlspecialchars("Checking for image files"));
if ($file_exists && $overwrite != "yes") { write("addLog\0".htmlspecialchars(_("New image file names exist and Overwrite is not allowed"))); return( false) ; }
+27 -12
View File
@@ -270,26 +270,41 @@ function my_preg_split($split, $text, $count=2) {
function delete_file(...$file) {
array_map('unlink',array_filter($file,'file_exists'));
}
function my_mkdir($dirname,$permissions = 0777,$recursive = false) {
$dirname = transpose_user_path($dirname);
$pathinfo = pathinfo($dirname);
$parent = $pathinfo["dirname"];
function my_mkdir($dirname,$permissions = 0777,$recursive = false,$own = "nobody",$grp = "users") {
if (is_dir($dirname)) return(false);
$parent = $dirname;
while (!is_dir($parent)){
if (!$recursive) return(false);
$pathinfo2 = pathinfo($parent);
$parent = $pathinfo2["dirname"];
}
if (strpos($dirname,'/mnt/user/')===0) {
$realdisk = trim(shell_exec("getfattr --absolute-names --only-values -n system.LOCATION ".escapeshellarg($parent)." 2>/dev/null"));
if (!empty($realdisk)) {
$dirname = str_replace('/mnt/user/', "/mnt/$realdisk/", $dirname);
$parent = str_replace('/mnt/user/', "/mnt/$realdisk/", $parent);
}
}
$fstype = trim(shell_exec(" stat -f -c '%T' $parent"));
$rtncode = false;
switch ($fstype) {
case "zfs":
switch ($fstype) {
case "zfs":
$zfsdataset = trim(shell_exec("zfs list -H -o name $parent")) ;
$rtncode=exec("zfs create $zfsdataset/{$pathinfo['filename']}");
if (!$rtncode) mkdir($dirname, $permissions, $recursive);
break;
$zfsdataset .= str_replace($parent,"",$dirname);
if ($recursive) $rtncode=exec("zfs create -p $zfsdataset");else $rtncode=exec("zfs create $zfsdataset");
if (!$rtncode) mkdir($dirname, $permissions, $recursive); else chmod($zfsdataset,$permissions);
break;
case "btrfs":
$rtncode=exec("btrfs subvolume create $dirname");
if (!$rtncode) mkdir($dirname, $permissions, $recursive);
if ($recursive) $rtncode=exec("btrfs subvolume create --parents $dirname"); else $rtncode=exec("btrfs subvolume create $dirname");
if (!$rtncode) mkdir($dirname, $permissions, $recursive); else chmod($dirname,$permissions);
break;
default:
mkdir($dirname, $permissions, $recursive);
break;
}
}
chown($dirname, $own);
chgrp($dirname, $grp);
return($rtncode);
}
function get_realvolume($path) {
if (strpos($path,"/mnt/user/",0) === 0)