Simplify raw disks definition
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2025-05-30 11:15:21 +02:00
parent a3ac56f849
commit 794d16bdaa
4 changed files with 19 additions and 34 deletions

View File

@@ -13,20 +13,13 @@ enum VMDisksError {
Config(&'static str), Config(&'static str),
} }
/// Type of disk allocation
#[derive(Copy, Clone, Debug, serde::Serialize, serde::Deserialize, Eq, PartialEq)]
pub enum VMDiskAllocType {
Fixed,
Sparse,
}
/// Disk allocation type /// Disk allocation type
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[serde(tag = "format")] #[serde(tag = "format")]
pub enum VMDiskFormat { pub enum VMDiskFormat {
Raw { Raw {
/// Type of disk allocation /// Is raw file a sparse file?
alloc_type: VMDiskAllocType, is_sparse: bool,
}, },
QCow2, QCow2,
} }
@@ -61,12 +54,7 @@ impl VMFileDisk {
}, },
format: match info.format { format: match info.format {
DiskFileFormat::Raw { is_sparse } => VMDiskFormat::Raw { DiskFileFormat::Raw { is_sparse } => VMDiskFormat::Raw { is_sparse },
alloc_type: match is_sparse {
true => VMDiskAllocType::Sparse,
false => VMDiskAllocType::Fixed,
},
},
DiskFileFormat::QCow2 { .. } => VMDiskFormat::QCow2, DiskFileFormat::QCow2 { .. } => VMDiskFormat::QCow2,
_ => anyhow::bail!("Unsupported image format: {:?}", info.format), _ => anyhow::bail!("Unsupported image format: {:?}", info.format),
}, },
@@ -131,9 +119,7 @@ impl VMFileDisk {
DiskFileInfo::create( DiskFileInfo::create(
&file, &file,
match self.format { match self.format {
VMDiskFormat::Raw { alloc_type } => DiskFileFormat::Raw { VMDiskFormat::Raw { is_sparse } => DiskFileFormat::Raw { is_sparse },
is_sparse: alloc_type == VMDiskAllocType::Sparse,
},
VMDiskFormat::QCow2 => DiskFileFormat::QCow2 { VMDiskFormat::QCow2 => DiskFileFormat::QCow2 {
virtual_size: self.size, virtual_size: self.size,
}, },

View File

@@ -29,11 +29,9 @@ export interface BaseFileVMDisk {
deleteType?: "keepfile" | "deletefile"; deleteType?: "keepfile" | "deletefile";
} }
export type DiskAllocType = "Sparse" | "Fixed";
interface RawVMDisk { interface RawVMDisk {
format: "Raw"; format: "Raw";
alloc_type: DiskAllocType; is_sparse: boolean;
} }
interface QCow2Disk { interface QCow2Disk {

View File

@@ -12,7 +12,6 @@ import { ServerApi } from "../api/ServerApi";
import { VMFileDisk, VMInfo } from "../api/VMApi"; import { VMFileDisk, VMInfo } from "../api/VMApi";
import { useAlert } from "../hooks/providers/AlertDialogProvider"; import { useAlert } from "../hooks/providers/AlertDialogProvider";
import { useLoadingMessage } from "../hooks/providers/LoadingMessageProvider"; import { useLoadingMessage } from "../hooks/providers/LoadingMessageProvider";
import { useSnackbar } from "../hooks/providers/SnackbarProvider";
import { FileDiskImageWidget } from "../widgets/FileDiskImageWidget"; import { FileDiskImageWidget } from "../widgets/FileDiskImageWidget";
import { CheckboxInput } from "../widgets/forms/CheckboxInput"; import { CheckboxInput } from "../widgets/forms/CheckboxInput";
import { SelectInput } from "../widgets/forms/SelectInput"; import { SelectInput } from "../widgets/forms/SelectInput";

View File

@@ -13,13 +13,14 @@ import {
Tooltip, Tooltip,
} from "@mui/material"; } from "@mui/material";
import { filesize } from "filesize"; import { filesize } from "filesize";
import React from "react";
import { ServerApi } from "../../api/ServerApi"; import { ServerApi } from "../../api/ServerApi";
import { VMFileDisk, VMInfo, VMState } from "../../api/VMApi"; import { VMFileDisk, VMInfo, VMState } from "../../api/VMApi";
import { ConvertDiskImageDialog } from "../../dialogs/ConvertDiskImageDialog";
import { useConfirm } from "../../hooks/providers/ConfirmDialogProvider"; import { useConfirm } from "../../hooks/providers/ConfirmDialogProvider";
import { CheckboxInput } from "./CheckboxInput";
import { SelectInput } from "./SelectInput"; import { SelectInput } from "./SelectInput";
import { TextInput } from "./TextInput"; import { TextInput } from "./TextInput";
import React from "react";
import { ConvertDiskImageDialog } from "../../dialogs/ConvertDiskImageDialog";
export function VMDisksList(p: { export function VMDisksList(p: {
vm: VMInfo; vm: VMInfo;
@@ -166,7 +167,9 @@ function DiskInfo(p: {
</> </>
} }
secondary={`${filesize(p.disk.size)} - ${p.disk.format}${ secondary={`${filesize(p.disk.size)} - ${p.disk.format}${
p.disk.format == "Raw" ? " - " + p.disk.alloc_type : "" p.disk.format == "Raw"
? " - " + (p.disk.is_sparse ? "Sparse" : "Fixed")
: ""
}`} }`}
/> />
</ListItem> </ListItem>
@@ -218,21 +221,20 @@ function DiskInfo(p: {
value={p.disk.format} value={p.disk.format}
onValueChange={(v) => { onValueChange={(v) => {
p.disk.format = v as any; p.disk.format = v as any;
if (p.disk.format === "Raw") p.disk.is_sparse = true;
p.onChange?.(); p.onChange?.();
}} }}
/> />
{p.disk.format === "Raw" && ( {p.disk.format === "Raw" && (
<SelectInput <CheckboxInput
editable={true} editable
label="File allocation type" label="Sparse file"
options={[ checked={p.disk.is_sparse}
{ label: "Sparse allocation", value: "Sparse" },
{ label: "Fixed allocation", value: "Fixed" },
]}
value={p.disk.alloc_type}
onValueChange={(v) => { onValueChange={(v) => {
if (p.disk.format === "Raw") p.disk.alloc_type = v as any; if (p.disk.format === "Raw") p.disk.is_sparse = v;
p.onChange?.(); p.onChange?.();
}} }}
/> />