Process size of disks in bytes instead of megabytes
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
19ec9992be
commit
5a5450070a
@ -46,11 +46,11 @@ pub const DISK_NAME_MIN_LEN: usize = 2;
|
|||||||
/// Disk name max length
|
/// Disk name max length
|
||||||
pub const DISK_NAME_MAX_LEN: usize = 10;
|
pub const DISK_NAME_MAX_LEN: usize = 10;
|
||||||
|
|
||||||
/// Disk size min (MB)
|
/// Disk size min (B)
|
||||||
pub const DISK_SIZE_MIN: usize = 100;
|
pub const DISK_SIZE_MIN: usize = 100 * 1000 * 1000;
|
||||||
|
|
||||||
/// Disk size max (MB)
|
/// Disk size max (B)
|
||||||
pub const DISK_SIZE_MAX: usize = 1000 * 1000 * 2;
|
pub const DISK_SIZE_MAX: usize = 1000 * 1000 * 1000 * 1000 * 2;
|
||||||
|
|
||||||
/// Net nat entry comment max size
|
/// Net nat entry comment max size
|
||||||
pub const NET_NAT_COMMENT_MAX_SIZE: usize = 250;
|
pub const NET_NAT_COMMENT_MAX_SIZE: usize = 250;
|
||||||
|
@ -40,7 +40,7 @@ pub enum DiskFormat {
|
|||||||
pub struct FileDisk {
|
pub struct FileDisk {
|
||||||
/// Disk name
|
/// Disk name
|
||||||
pub name: String,
|
pub name: String,
|
||||||
/// Disk size, in megabytes
|
/// Disk size, in bytes
|
||||||
pub size: usize,
|
pub size: usize,
|
||||||
/// Disk format
|
/// Disk format
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
@ -141,8 +141,10 @@ impl FileDisk {
|
|||||||
.arg("bs=1M");
|
.arg("bs=1M");
|
||||||
|
|
||||||
match alloc_type {
|
match alloc_type {
|
||||||
DiskAllocType::Fixed => cmd.arg(format!("count={}", self.size)),
|
DiskAllocType::Fixed => cmd.arg(format!("count={}", self.size_mb())),
|
||||||
DiskAllocType::Sparse => cmd.arg(format!("seek={}", self.size)).arg("count=0"),
|
DiskAllocType::Sparse => {
|
||||||
|
cmd.arg(format!("seek={}", self.size_mb())).arg("count=0")
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
cmd.output()?
|
cmd.output()?
|
||||||
@ -154,7 +156,7 @@ impl FileDisk {
|
|||||||
.arg("-f")
|
.arg("-f")
|
||||||
.arg("qcow2")
|
.arg("qcow2")
|
||||||
.arg(file)
|
.arg(file)
|
||||||
.arg(format!("{}M", self.size));
|
.arg(format!("{}M", self.size_mb()));
|
||||||
|
|
||||||
cmd.output()?
|
cmd.output()?
|
||||||
}
|
}
|
||||||
@ -172,6 +174,11 @@ impl FileDisk {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the size of file disk in megabytes
|
||||||
|
pub fn size_mb(&self) -> usize {
|
||||||
|
self.size / (1000 * 1000)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, serde::Serialize)]
|
#[derive(Debug, serde::Serialize)]
|
||||||
@ -211,7 +218,7 @@ impl DiskFileInfo {
|
|||||||
// Determine file format
|
// Determine file format
|
||||||
let format = match ext {
|
let format = match ext {
|
||||||
"qcow2" => DiskFileFormat::QCow2 {
|
"qcow2" => DiskFileFormat::QCow2 {
|
||||||
virtual_size: qcow_virt_size(file)? / (1000 * 1000),
|
virtual_size: qcow_virt_size(file)?,
|
||||||
},
|
},
|
||||||
"raw" => DiskFileFormat::Raw {
|
"raw" => DiskFileFormat::Raw {
|
||||||
is_sparse: metadata.len() / 512 >= metadata.st_blocks(),
|
is_sparse: metadata.len() / 512 >= metadata.st_blocks(),
|
||||||
@ -226,7 +233,7 @@ impl DiskFileInfo {
|
|||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
name,
|
name,
|
||||||
file_size: metadata.len() as usize / (1000 * 1000),
|
file_size: metadata.len() as usize,
|
||||||
format,
|
format,
|
||||||
file_name: file
|
file_name: file
|
||||||
.file_name()
|
.file_name()
|
||||||
|
@ -27,7 +27,7 @@ export function VMDisksList(p: {
|
|||||||
const addNewDisk = () => {
|
const addNewDisk = () => {
|
||||||
p.vm.file_disks.push({
|
p.vm.file_disks.push({
|
||||||
format: "QCow2",
|
format: "QCow2",
|
||||||
size: 10000,
|
size: 10000 * 1000 * 1000,
|
||||||
delete: false,
|
delete: false,
|
||||||
name: `disk${p.vm.file_disks.length}`,
|
name: `disk${p.vm.file_disks.length}`,
|
||||||
new: true,
|
new: true,
|
||||||
@ -125,9 +125,9 @@ function DiskInfo(p: {
|
|||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
secondary={`${filesize(p.disk.size * 1000 * 1000)} - ${
|
secondary={`${filesize(p.disk.size)} - ${p.disk.format}${
|
||||||
p.disk.format
|
p.disk.format == "Raw" ? " - " + p.disk.alloc_type : ""
|
||||||
}${p.disk.format == "Raw" ? " - " + p.disk.alloc_type : ""}`}
|
}`}
|
||||||
/>
|
/>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
);
|
);
|
||||||
@ -153,11 +153,16 @@ function DiskInfo(p: {
|
|||||||
|
|
||||||
<TextInput
|
<TextInput
|
||||||
editable={true}
|
editable={true}
|
||||||
label="Disk size (MB)"
|
label="Disk size (GB)"
|
||||||
size={ServerApi.Config.constraints.disk_size}
|
size={{
|
||||||
value={p.disk.size.toString()}
|
min:
|
||||||
|
ServerApi.Config.constraints.disk_size.min / (1000 * 1000 * 1000),
|
||||||
|
max:
|
||||||
|
ServerApi.Config.constraints.disk_size.max / (1000 * 1000 * 1000),
|
||||||
|
}}
|
||||||
|
value={(p.disk.size / (1000 * 1000 * 1000)).toString()}
|
||||||
onValueChange={(v) => {
|
onValueChange={(v) => {
|
||||||
p.disk.size = Number(v ?? "0");
|
p.disk.size = Number(v ?? "0") * 1000 * 1000 * 1000;
|
||||||
p.onChange?.();
|
p.onChange?.();
|
||||||
}}
|
}}
|
||||||
type="number"
|
type="number"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user