previously the tui used `u64` internally to represent the disk size.
since the perl-based installer expects GiB as floats and that is also
what is displayed in the tui that meant a lot of converting back and
forth. it also lead to an error where the disk sizes that were set
seemed to not have been persisted, even though the sizes were
correctly set. this commit refactors the installer to convert the size
once in the beginning and then stick to `f64`.
Signed-off-by: Stefan Sterz <s.sterz@proxmox.com>
Reviewed-by: Christoph Heiss <c.heiss@proxmox.com>
Tested-by: Christoph Heiss <c.heiss@proxmox.com>
#[derive(Clone, Debug)]
pub struct LvmBootdiskOptions {
- pub total_size: u64,
- pub swap_size: Option<u64>,
- pub max_root_size: Option<u64>,
- pub max_data_size: Option<u64>,
- pub min_lvm_free: Option<u64>,
+ pub total_size: f64,
+ pub swap_size: Option<f64>,
+ pub max_root_size: Option<f64>,
+ pub max_data_size: Option<f64>,
+ pub min_lvm_free: Option<f64>,
}
impl LvmBootdiskOptions {
#[derive(Clone, Debug)]
pub struct BtrfsBootdiskOptions {
- pub disk_size: u64,
+ pub disk_size: f64,
}
impl BtrfsBootdiskOptions {
pub compress: ZfsCompressOption,
pub checksum: ZfsChecksumOption,
pub copies: usize,
- pub disk_size: u64,
+ pub disk_size: f64,
}
impl ZfsBootdiskOptions {
Btrfs(BtrfsBootdiskOptions),
}
-#[derive(Clone, Debug, Eq, PartialEq)]
+#[derive(Clone, Debug, PartialEq)]
pub struct Disk {
pub index: String,
pub path: String,
pub model: Option<String>,
- pub size: u64,
+ pub size: f64,
}
impl fmt::Display for Disk {
// FIXME: ellipsize too-long names?
write!(f, " ({model})")?;
}
- write!(
- f,
- " ({:.2} GiB)",
- (self.size as f64) / 1024. / 1024. / 1024.
- )
+ write!(f, " ({:.2} GiB)", self.size)
}
}
}
}
+impl cmp::Eq for Disk {}
+
impl cmp::PartialOrd for Disk {
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
self.index.partial_cmp(&other.index)
#[serde(serialize_with = "serialize_fstype")]
filesys: FsType,
- hdsize: u64,
+ hdsize: f64,
#[serde(skip_serializing_if = "Option::is_none")]
- swapsize: Option<u64>,
+ swapsize: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
- maxroot: Option<u64>,
+ maxroot: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
- minfree: Option<u64>,
+ minfree: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
- maxvz: Option<u64>,
+ maxvz: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
zfs_opts: Option<InstallZfsOption>,
autoreboot: options.autoreboot as usize,
filesys: options.bootdisk.fstype,
- hdsize: 0,
+ hdsize: 0.,
swapsize: None,
maxroot: None,
minfree: None,
where
D: Deserializer<'de>,
{
- let disks = <Vec<(usize, String, u64, String, u64, String)>>::deserialize(deserializer)?;
+ let disks = <Vec<(usize, String, f64, String, f64, String)>>::deserialize(deserializer)?;
Ok(disks
.into_iter()
.map(
|(index, device, size_mb, model, logical_bsize, _syspath)| Disk {
index: index.to_string(),
- size: size_mb * logical_bsize,
+ size: (size_mb * logical_bsize) / 1024. / 1024. / 1024.,
path: device,
model: (!model.is_empty()).then_some(model),
},
}
}
- pub fn content(mut self, content: u64) -> Self {
- let val = (content as f64) / 1024. / 1024. / 1024.;
-
+ pub fn content(mut self, content: f64) -> Self {
if let Some(view) = self.view.get_child_mut(0).and_then(|v| v.downcast_mut()) {
- *view = FloatEditView::new().content(val).full_width();
+ *view = FloatEditView::new().content(content).full_width();
}
self
}
- pub fn content_maybe(self, content: Option<u64>) -> Self {
+ pub fn content_maybe(self, content: Option<f64>) -> Self {
if let Some(value) = content {
self.content(value)
} else {
}
}
- pub fn max_value(mut self, max: u64) -> Self {
+ pub fn max_value(mut self, max: f64) -> Self {
if let Some(view) = self
.view
.get_child_mut(0)
.and_then(|v| v.downcast_mut::<ResizedView<FloatEditView>>())
{
- let max = (max as f64) / 1024. / 1024. / 1024.;
view.get_inner_mut().set_max_value(max);
}
self
}
- pub fn get_content(&self) -> Option<u64> {
+ pub fn get_content(&self) -> Option<f64> {
self.with_view(|v| {
v.get_child(0)?
.downcast_ref::<ResizedView<FloatEditView>>()?
.flatten()
})
.flatten()
- .map(|val| val as u64)
}
}
}
}
-impl FormViewGetValue<u64> for DiskSizeEditView {
- fn get_value(&self) -> Option<u64> {
+impl FormViewGetValue<f64> for DiskSizeEditView {
+ fn get_value(&self) -> Option<f64> {
self.get_content()
}
}