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

Issue project 52 u128 #2341

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
3 changes: 1 addition & 2 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 @@ -24,7 +24,7 @@ required-features = ["extras"]
[dependencies]
clap = "2"
nix = "0.18"
devicemapper = "0.28"
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().bytes()).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 @@ -76,18 +76,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/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub fn set_key_shared(key_fd: RawFd) -> StratisResult<SizedKeyMemory> {
ErrorEnum::Invalid,
format!(
"Provided key exceeded maximum allow length of {}",
Bytes(MAX_STRATIS_PASS_SIZE as u64)
Bytes::from(MAX_STRATIS_PASS_SIZE)
),
));
}
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 @@ -51,7 +51,7 @@ impl BlockDev for SimDev {
}

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

fn set_dbus_path(&mut self, path: MaybeDbusPath) {
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 @@ -345,7 +345,7 @@ impl BlockDevMgr {
current_time
};

let data_size = Bytes(metadata.len() as u64);
let data_size = Bytes::from(metadata.len());
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 @@ -38,7 +38,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
2 changes: 1 addition & 1 deletion src/engine/strat_engine/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ 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::from(val)),
}
}
8 changes: 4 additions & 4 deletions src/engine/strat_engine/metadata/bda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ mod tests {
/// Initialize a BDA.
/// Verify that the last update time is None.
fn empty_bda(ref sh in static_header_strategy()) {
let buf_size = convert_test!(*sh.mda_size.bda_size().sectors().bytes(), u64, usize);
let buf_size = convert_test!(*sh.mda_size.bda_size().sectors().bytes(), u128, usize);
let mut buf = Cursor::new(vec![0; buf_size]);
let bda = BDA::initialize(
&mut buf,
Expand All @@ -181,7 +181,7 @@ mod tests {
0;
convert_test!(
*sh.blkdev_size.sectors().bytes(),
u64,
u128,
usize
)
]);
Expand All @@ -202,7 +202,7 @@ mod tests {
0;
convert_test!(
*sh.blkdev_size.sectors().bytes(),
u64,
u128,
usize
)
]);
Expand Down Expand Up @@ -234,7 +234,7 @@ mod tests {
ref state in vec(num::u8::ANY, 1..100),
ref next_state in vec(num::u8::ANY, 1..100)
) {
let buf_size = convert_test!(*sh.mda_size.bda_size().sectors().bytes(), u64, usize);
let buf_size = convert_test!(*sh.mda_size.bda_size().sectors().bytes(), u128, usize);
let mut buf = Cursor::new(vec![0; buf_size]);
let mut bda = BDA::initialize(
&mut buf,
Expand Down
58 changes: 32 additions & 26 deletions src/engine/strat_engine/metadata/mda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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 +71,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(convert_int!(
MDARegions::mda_offset(header_size, region, region_size_bytes),
u128,
u64
)?))?;
f.write_all(&hdr_buf)?;
}

Expand Down Expand Up @@ -111,11 +111,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(convert_int!(
MDARegions::mda_offset(header_size, index, region_size_bytes),
u128,
u64
)?))?;
f.read_exact(&mut hdr_buf)?;
Ok(MDAHeader::from_buf(&hdr_buf)?)
};
Expand Down Expand Up @@ -158,7 +158,7 @@ impl MDARegions {
));
}

let used = Bytes(data.len() as u64);
let used = Bytes::from(data.len());
let max_available = self.max_data_size().bytes();
if used > max_available {
let err_msg = format!(
Expand All @@ -178,11 +178,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(convert_int!(
MDARegions::mda_offset(header_size, index, region_size),
u128,
u64
)?))?;
f.write_all(&hdr_buf)?;
f.write_all(data)?;
f.sync_all()?;
Expand Down Expand Up @@ -220,8 +220,8 @@ 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(convert_int!(offset, u128, u64)?))?;
mda.load_region(f)
};

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

Some(MDAHeader {
used: MetaDataSize::new(Bytes(used)),
used: MetaDataSize::new(Bytes::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 @@ -382,7 +382,10 @@ impl MDAHeader {
let mut buf = [0u8; mda_size::_MDA_REGION_HDR_SIZE];

LittleEndian::write_u32(&mut buf[4..8], self.data_crc);
LittleEndian::write_u64(&mut buf[8..16], *self.used.bytes() as u64);
LittleEndian::write_u64(
&mut buf[8..16],
convert_int!(*self.used.bytes(), u128, u64).expect("Size must fit into metadata"),
);
LittleEndian::write_u64(&mut buf[16..24], self.last_updated.timestamp() as u64);
LittleEndian::write_u32(&mut buf[24..28], self.last_updated.timestamp_subsec_nanos());
buf[28] = STRAT_REGION_HDR_VERSION;
Expand All @@ -402,7 +405,7 @@ impl MDAHeader {
where
F: Read,
{
let mut data_buf = vec![0u8; convert_int!(*self.used.bytes(), u64, usize)?];
let mut data_buf = vec![0u8; convert_int!(*self.used.bytes(), u128, usize)?];

f.read_exact(&mut data_buf)?;

Expand Down Expand Up @@ -448,8 +451,11 @@ mod tests {
/// initialized.
fn test_reading_mda_regions() {
let offset = Bytes(100);
let buf_length =
convert_test!(*(offset + MDASize::default().sectors().bytes()), u64, usize);
let buf_length = convert_test!(
*(offset + MDASize::default().sectors().bytes()),
u128,
usize
);
let mut buf = Cursor::new(vec![0; buf_length]);
assert_matches!(
MDARegions::load(offset, MDASize::default(), &mut buf),
Expand All @@ -476,7 +482,7 @@ mod tests {

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

let header = MDAHeader {
last_updated: Utc::now(),
used: MetaDataSize::new(Bytes(data.len() as u64)),
used: MetaDataSize::new(Bytes::from(data.len())),
data_crc: crc32::checksum_castagnoli(&data),
};
let mut buf = header.to_buf();
Expand Down
2 changes: 1 addition & 1 deletion src/engine/strat_engine/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
11 changes: 5 additions & 6 deletions src/engine/strat_engine/metadata/static_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,12 +502,11 @@ pub mod tests {
pub fn random_static_header(blkdev_size: u64, mda_size_factor: u32) -> StaticHeader {
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)),
)
.region_size()
.mda_size();
let blkdev_size = (Bytes(IEC::Mi) + Sectors(blkdev_size).bytes()).sectors();
let mda_size =
MDADataSize::new(MDADataSize::default().bytes() + Bytes::from(mda_size_factor * 4))
.region_size()
.mda_size();
let blkdev_size = (Bytes::from(IEC::Mi) + Sectors(blkdev_size).bytes()).sectors();
StaticHeader::new(
StratisIdentifiers::new(pool_uuid, dev_uuid),
mda_size,
Expand Down
8 changes: 4 additions & 4 deletions src/engine/strat_engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,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::from(buffer_length).sectors();
while match pool.thin_pool.state() {
Some(ThinPoolStatus::Working(working)) => {
working.summary == ThinPoolStatusSummary::Good
Expand Down Expand Up @@ -823,7 +823,7 @@ 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(Bytes::from(IEC::Gi * 4).sectors())),
test_add_datadevs,
);
}
Expand All @@ -833,8 +833,8 @@ mod tests {
real::test_with_spec(
&real::DeviceLimits::AtLeast(
2,
Some((2u64 * Bytes(IEC::Gi)).sectors()),
Some((4u64 * Bytes(IEC::Gi)).sectors()),
Some(Bytes::from(IEC::Gi * 2).sectors()),
Some(Bytes::from(IEC::Gi * 4).sectors()),
),
test_add_datadevs,
);
Expand Down
8 changes: 6 additions & 2 deletions src/engine/strat_engine/tests/loopbacked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl LoopTestDev {
/// Create its backing store of specified size. The file is sparse but
/// will appear to be zeroed.
pub fn new(lc: &LoopControl, path: &Path, size: Option<Sectors>) -> LoopTestDev {
let size = size.unwrap_or_else(|| Bytes(IEC::Gi).sectors());
let size = size.unwrap_or_else(|| Bytes::from(IEC::Gi).sectors());

let f = OpenOptions::new()
.read(true)
Expand All @@ -46,7 +46,11 @@ impl LoopTestDev {
.open(&path)
.unwrap();

nix::unistd::ftruncate(f.as_raw_fd(), *size.bytes() as nix::libc::off_t).unwrap();
nix::unistd::ftruncate(
f.as_raw_fd(),
convert_test!(*size.bytes(), u128, nix::libc::off_t),
)
.unwrap();
f.sync_all().unwrap();

let ld = lc.next_free().unwrap();
Expand Down
Loading