Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes corresponding to u128 changes to Bytes #1830

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build = "build.rs"
dbus = {version = "0.8", optional = true}
clap = "2"
nix = "0.14"
devicemapper = "0.28.0"
devicemapper = { git = "https://github.com/jbaublitz/devicemapper-rs", branch = "u128-bytes" }
crc = "1"
byteorder = "1"
chrono = "0.4"
Expand Down
30 changes: 13 additions & 17 deletions src/dbus_api/blockdev/fetch_properties_2_0/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,20 @@ fn get_properties_shared(

let return_message = message.method_return();

let return_value: HashMap<String, (bool, Variant<Box<dyn RefArg>>)> =
properties
.unique()
.filter_map(|prop| match prop.as_str() {
consts::BLOCKDEV_TOTAL_SIZE_PROP => Some((
prop,
result_to_tuple(blockdev_operation(
m.tree,
object_path.get_name(),
|_, bd| {
Ok((u128::from(*bd.size()) * devicemapper::SECTOR_SIZE as u128)
.to_string())
},
)),
let return_value: HashMap<String, (bool, Variant<Box<dyn RefArg>>)> = properties
.unique()
.filter_map(|prop| match prop.as_str() {
consts::BLOCKDEV_TOTAL_SIZE_PROP => Some((
prop,
result_to_tuple(blockdev_operation(
m.tree,
object_path.get_name(),
|_, bd| Ok((*bd.size()).to_string()),
)),
_ => None,
})
.collect();
)),
_ => None,
})
.collect();

Ok(vec![return_message.append1(return_value)])
}
Expand Down
7 changes: 2 additions & 5 deletions src/dbus_api/pool/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,15 @@ pub fn get_pool_has_cache(m: &MethodInfo<MTFn<TData>, TData>) -> Result<bool, St

pub fn get_pool_total_size(m: &MethodInfo<MTFn<TData>, TData>) -> Result<String, String> {
pool_operation(m.tree, m.path.get_name(), |(_, _, pool)| {
Ok(
(u128::from(*pool.total_physical_size()) * devicemapper::SECTOR_SIZE as u128)
.to_string(),
)
Ok((*pool.total_physical_size().bytes()).to_string())
})
}

pub fn get_pool_total_used(m: &MethodInfo<MTFn<TData>, TData>) -> Result<String, String> {
pool_operation(m.tree, m.path.get_name(), |(_, _, pool)| {
pool.total_physical_used()
.map_err(|e| e.to_string())
.map(|size| (u128::from(*size) * devicemapper::SECTOR_SIZE as u128).to_string())
.map(|size| (*size.bytes()).to_string())
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/engine/sim_engine/blockdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl BlockDev for SimDev {
}

fn size(&self) -> Sectors {
Bytes(IEC::Gi).sectors()
Bytes(u128::from(IEC::Gi)).sectors()
}

fn set_dbus_path(&mut self, path: MaybeDbusPath) {
Expand Down
2 changes: 1 addition & 1 deletion src/engine/sim_engine/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl KeyActions for SimKeyActions {
ErrorEnum::Invalid,
format!(
"Provided key exceeded maximum allow length of {}",
Bytes(MAX_STRATIS_PASS_SIZE as u64)
Bytes(MAX_STRATIS_PASS_SIZE as u128)
),
));
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/strat_engine/backstore/blockdevmgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl BlockDevMgr {
current_time
};

let data_size = Bytes(metadata.len() as u64);
let data_size = Bytes(metadata.len() as u128);
let candidates = self
.block_devs
.iter_mut()
Expand Down
2 changes: 1 addition & 1 deletion src/engine/strat_engine/backstore/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use crate::{
stratis::{ErrorEnum, StratisError, StratisResult},
};

const MIN_DEV_SIZE: Bytes = Bytes(IEC::Gi);
const MIN_DEV_SIZE: Bytes = Bytes(IEC::Gi as u128);

// Get information that can be obtained from udev for the block device
// identified by devnode. Return an error if there was an error finding the
Expand Down
48 changes: 26 additions & 22 deletions src/engine/strat_engine/backstore/metadata/mda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use std::{
cmp::Ordering,
convert::TryInto,
io::{Read, Seek, SeekFrom},
num::TryFromIntError,
};

use byteorder::{ByteOrder, LittleEndian};
Expand Down Expand Up @@ -43,7 +45,7 @@ pub struct MDARegions {

impl MDARegions {
/// Calculate the offset from start of device for an MDARegion.
fn mda_offset(header_size: Bytes, index: usize, per_region_size: Bytes) -> u64 {
fn mda_offset(header_size: Bytes, index: usize, per_region_size: Bytes) -> u128 {
*(header_size + per_region_size * index)
}

Expand Down Expand Up @@ -71,11 +73,11 @@ impl MDARegions {
let region_size = mda_size.region_size();
let region_size_bytes = region_size.sectors().bytes();
for region in 0..mda_size::NUM_MDA_REGIONS {
f.seek(SeekFrom::Start(MDARegions::mda_offset(
header_size,
region,
region_size_bytes,
)))?;
f.seek(SeekFrom::Start(
MDARegions::mda_offset(header_size, region, region_size_bytes)
.try_into()
.map_err(|e: TryFromIntError| StratisError::Error(e.to_string()))?,
))?;
f.write_all(&hdr_buf)?;
}

Expand Down Expand Up @@ -111,11 +113,11 @@ impl MDARegions {
// been corrupted, return an error.
let mut load_a_region = |index: usize| -> StratisResult<Option<MDAHeader>> {
let mut hdr_buf = [0u8; mda_size::_MDA_REGION_HDR_SIZE];
f.seek(SeekFrom::Start(MDARegions::mda_offset(
header_size,
index,
region_size_bytes,
)))?;
f.seek(SeekFrom::Start(
MDARegions::mda_offset(header_size, index, region_size_bytes)
.try_into()
.map_err(|e: TryFromIntError| StratisError::Error(e.to_string()))?,
))?;
f.read_exact(&mut hdr_buf)?;
Ok(MDAHeader::from_buf(&hdr_buf)?)
};
Expand Down Expand Up @@ -158,7 +160,7 @@ impl MDARegions {
));
}

let used = Bytes(data.len() as u64);
let used = Bytes(data.len() as u128);
let max_available = self.max_data_size().bytes();
if used > max_available {
let err_msg = format!(
Expand All @@ -178,11 +180,11 @@ impl MDARegions {
// Write data to a region specified by index.
let region_size = self.region_size.sectors().bytes();
let mut save_region = |index: usize| -> StratisResult<()> {
f.seek(SeekFrom::Start(MDARegions::mda_offset(
header_size,
index,
region_size,
)))?;
f.seek(SeekFrom::Start(
MDARegions::mda_offset(header_size, index, region_size)
.try_into()
.map_err(|e: TryFromIntError| StratisError::Error(e.to_string()))?,
))?;
f.write_all(&hdr_buf)?;
f.write_all(data)?;
f.sync_all()?;
Expand Down Expand Up @@ -220,8 +222,10 @@ impl MDARegions {
// It is an error if the metadata can not be found.
let mut load_region = |index: usize| -> StratisResult<Vec<u8>> {
let offset = MDARegions::mda_offset(header_size, index, region_size)
+ mda_size::_MDA_REGION_HDR_SIZE as u64;
f.seek(SeekFrom::Start(offset))?;
+ mda_size::_MDA_REGION_HDR_SIZE as u128;
f.seek(SeekFrom::Start(offset.try_into().map_err(
|e: TryFromIntError| StratisError::Error(e.to_string()),
)?))?;
mda.load_region(f)
};

Expand Down Expand Up @@ -334,7 +338,7 @@ impl MDAHeader {
assert!(secs <= std::i64::MAX as u64);

Some(MDAHeader {
used: MetaDataSize::new(Bytes(used)),
used: MetaDataSize::new(Bytes(u128::from(used))),
last_updated: Utc.timestamp(secs as i64, LittleEndian::read_u32(&buf[24..28])),
data_crc: LittleEndian::read_u32(&buf[4..8]),
})
Expand Down Expand Up @@ -484,7 +488,7 @@ mod tests {

let header = MDAHeader {
last_updated: Utc.timestamp(sec, nsec),
used: MetaDataSize::new(Bytes(data.len() as u64)),
used: MetaDataSize::new(Bytes(data.len() as u128)),
data_crc: crc32::checksum_castagnoli(data),
};
let buf = header.to_buf();
Expand All @@ -506,7 +510,7 @@ mod tests {

let header = MDAHeader {
last_updated: Utc::now(),
used: MetaDataSize::new(Bytes(data.len() as u64)),
used: MetaDataSize::new(Bytes(data.len() as u128)),
data_crc: crc32::checksum_castagnoli(&data),
};
let mut buf = header.to_buf();
Expand Down
2 changes: 1 addition & 1 deletion src/engine/strat_engine/backstore/metadata/sizes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub mod mda_size {
use devicemapper::{Bytes, Sectors};

pub const _MDA_REGION_HDR_SIZE: usize = 32;
const MDA_REGION_HDR_SIZE: Bytes = Bytes(_MDA_REGION_HDR_SIZE as u64);
const MDA_REGION_HDR_SIZE: Bytes = Bytes(_MDA_REGION_HDR_SIZE as u128);

// The minimum size allocated for variable length metadata
pub const MIN_MDA_DATA_REGION_SIZE: Bytes = Bytes(260_064);
Expand Down
4 changes: 2 additions & 2 deletions src/engine/strat_engine/backstore/metadata/static_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,11 @@ pub mod tests {
let pool_uuid = Uuid::new_v4();
let dev_uuid = Uuid::new_v4();
let mda_size = MDADataSize::new(
MDADataSize::default().bytes() + Bytes(u64::from(mda_size_factor * 4)),
MDADataSize::default().bytes() + Bytes(u128::from(mda_size_factor * 4)),
)
.region_size()
.mda_size();
let blkdev_size = (Bytes(IEC::Mi) + Sectors(blkdev_size).bytes()).sectors();
let blkdev_size = (Bytes(IEC::Mi as u128) + Sectors(blkdev_size).bytes()).sectors();
StaticHeader::new(
StratisIdentifiers::new(pool_uuid, dev_uuid),
mda_size,
Expand Down
8 changes: 6 additions & 2 deletions src/engine/strat_engine/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
// Functions for dealing with devices.

use std::{
convert::TryInto,
fs::{File, OpenOptions},
io::{self, BufWriter, Cursor, Seek, SeekFrom, Write},
num::TryFromIntError,
os::unix::prelude::AsRawFd,
path::Path,
};
Expand All @@ -33,7 +35,7 @@ pub fn blkdev_size(file: &File) -> StratisResult<Bytes> {

match unsafe { blkgetsize64(file.as_raw_fd(), &mut val) } {
Err(x) => Err(StratisError::Nix(x)),
Ok(_) => Ok(Bytes(val)),
Ok(_) => Ok(Bytes(u128::from(val))),
}
}

Expand Down Expand Up @@ -82,7 +84,9 @@ pub fn write_sectors<P: AsRef<Path>>(
let mut f =
BufWriter::with_capacity(IEC::Mi as usize, OpenOptions::new().write(true).open(path)?);

f.seek(SeekFrom::Start(*offset.bytes()))?;
f.seek(SeekFrom::Start((*offset.bytes()).try_into().map_err(
|e: TryFromIntError| StratisError::Error(e.to_string()),
)?))?;
for _ in 0..*length {
f.write_all(buf)?;
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/strat_engine/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl KeyActions for StratKeyActions {
ErrorEnum::Invalid,
format!(
"Provided key exceeded maximum allow length of {}",
Bytes(MAX_STRATIS_PASS_SIZE as u64)
Bytes(MAX_STRATIS_PASS_SIZE as u128)
),
));
}
Expand Down
12 changes: 8 additions & 4 deletions src/engine/strat_engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ mod tests {
let buf = &[1u8; SECTOR_SIZE];

let mut amount_written = Sectors(0);
let buffer_length = Bytes(buffer_length).sectors();
let buffer_length = Bytes(u128::from(buffer_length)).sectors();
while pool.thin_pool.extend_state() == PoolExtendState::Good
&& pool.thin_pool.state() == PoolState::Running
{
Expand All @@ -958,7 +958,11 @@ mod tests {
#[test]
fn loop_test_add_datadevs() {
loopbacked::test_with_spec(
&loopbacked::DeviceLimits::Range(2, 3, Some((4u64 * Bytes(IEC::Gi)).sectors())),
&loopbacked::DeviceLimits::Range(
2,
3,
Some((4u64 * Bytes(u128::from(IEC::Gi))).sectors()),
),
test_add_datadevs,
);
}
Expand All @@ -968,8 +972,8 @@ mod tests {
real::test_with_spec(
&real::DeviceLimits::AtLeast(
2,
Some((2u64 * Bytes(IEC::Gi)).sectors()),
Some((4u64 * Bytes(IEC::Gi)).sectors()),
Some((2u64 * Bytes(u128::from(IEC::Gi))).sectors()),
Some((4u64 * Bytes(u128::from(IEC::Gi))).sectors()),
),
test_add_datadevs,
);
Expand Down
Loading