Skip to content

Commit 66b9b42

Browse files
committed
Changes corresponding to u128 changes to Bytes
1 parent b322126 commit 66b9b42

File tree

16 files changed

+86
-71
lines changed

16 files changed

+86
-71
lines changed

Cargo.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ edition = "2018"
88
dbus = {version = "0.8", optional = true}
99
clap = "2"
1010
nix = "0.14"
11-
devicemapper = "0.28.0"
11+
devicemapper = { git = "https://github.com/jbaublitz/devicemapper-rs", branch = "u128-bytes" }
1212
crc = "1"
1313
byteorder = "1"
1414
chrono = "0.4"

src/dbus_api/blockdev/fetch_properties_2_0/methods.rs

+13-17
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,20 @@ fn get_properties_shared(
2727

2828
let return_message = message.method_return();
2929

30-
let return_value: HashMap<String, (bool, Variant<Box<dyn RefArg>>)> =
31-
properties
32-
.unique()
33-
.filter_map(|prop| match prop.as_str() {
34-
consts::BLOCKDEV_TOTAL_SIZE_PROP => Some((
35-
prop,
36-
result_to_tuple(blockdev_operation(
37-
m.tree,
38-
object_path.get_name(),
39-
|_, bd| {
40-
Ok((u128::from(*bd.size()) * devicemapper::SECTOR_SIZE as u128)
41-
.to_string())
42-
},
43-
)),
30+
let return_value: HashMap<String, (bool, Variant<Box<dyn RefArg>>)> = properties
31+
.unique()
32+
.filter_map(|prop| match prop.as_str() {
33+
consts::BLOCKDEV_TOTAL_SIZE_PROP => Some((
34+
prop,
35+
result_to_tuple(blockdev_operation(
36+
m.tree,
37+
object_path.get_name(),
38+
|_, bd| Ok((*bd.size()).to_string()),
4439
)),
45-
_ => None,
46-
})
47-
.collect();
40+
)),
41+
_ => None,
42+
})
43+
.collect();
4844

4945
Ok(vec![return_message.append1(return_value)])
5046
}

src/dbus_api/pool/shared.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,15 @@ pub fn get_pool_has_cache(m: &MethodInfo<MTFn<TData>, TData>) -> Result<bool, St
4949

5050
pub fn get_pool_total_size(m: &MethodInfo<MTFn<TData>, TData>) -> Result<String, String> {
5151
pool_operation(m.tree, m.path.get_name(), |(_, _, pool)| {
52-
Ok(
53-
(u128::from(*pool.total_physical_size()) * devicemapper::SECTOR_SIZE as u128)
54-
.to_string(),
55-
)
52+
Ok((*pool.total_physical_size().bytes()).to_string())
5653
})
5754
}
5855

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

src/engine/sim_engine/blockdev.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl BlockDev for SimDev {
4646
}
4747

4848
fn size(&self) -> Sectors {
49-
Bytes(IEC::Gi).sectors()
49+
Bytes(u128::from(IEC::Gi)).sectors()
5050
}
5151

5252
fn set_dbus_path(&mut self, path: MaybeDbusPath) {

src/engine/strat_engine/backstore/blockdevmgr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ impl BlockDevMgr {
373373
current_time
374374
};
375375

376-
let data_size = Bytes(metadata.len() as u64);
376+
let data_size = Bytes(metadata.len() as u128);
377377
let candidates = self
378378
.block_devs
379379
.iter_mut()

src/engine/strat_engine/backstore/devices.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::{
3434
stratis::{ErrorEnum, StratisError, StratisResult},
3535
};
3636

37-
const MIN_DEV_SIZE: Bytes = Bytes(IEC::Gi);
37+
const MIN_DEV_SIZE: Bytes = Bytes(IEC::Gi as u128);
3838

3939
// Get information that can be obtained from udev for the block device
4040
// identified by devnode. Return an error if there was an error finding the

src/engine/strat_engine/backstore/metadata/mda.rs

+26-22
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
use std::{
66
self,
77
cmp::Ordering,
8+
convert::TryInto,
89
io::{Read, Seek, SeekFrom},
10+
num::TryFromIntError,
911
};
1012

1113
use byteorder::{ByteOrder, LittleEndian};
@@ -44,7 +46,7 @@ pub struct MDARegions {
4446

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

@@ -72,11 +74,11 @@ impl MDARegions {
7274
let region_size = mda_size.region_size();
7375
let region_size_bytes = region_size.sectors().bytes();
7476
for region in 0..mda_size::NUM_MDA_REGIONS {
75-
f.seek(SeekFrom::Start(MDARegions::mda_offset(
76-
header_size,
77-
region,
78-
region_size_bytes,
79-
)))?;
77+
f.seek(SeekFrom::Start(
78+
MDARegions::mda_offset(header_size, region, region_size_bytes)
79+
.try_into()
80+
.map_err(|e: TryFromIntError| StratisError::Error(e.to_string()))?,
81+
))?;
8082
f.write_all(&hdr_buf)?;
8183
}
8284

@@ -112,11 +114,11 @@ impl MDARegions {
112114
// been corrupted, return an error.
113115
let mut load_a_region = |index: usize| -> StratisResult<Option<MDAHeader>> {
114116
let mut hdr_buf = [0u8; mda_size::_MDA_REGION_HDR_SIZE];
115-
f.seek(SeekFrom::Start(MDARegions::mda_offset(
116-
header_size,
117-
index,
118-
region_size_bytes,
119-
)))?;
117+
f.seek(SeekFrom::Start(
118+
MDARegions::mda_offset(header_size, index, region_size_bytes)
119+
.try_into()
120+
.map_err(|e: TryFromIntError| StratisError::Error(e.to_string()))?,
121+
))?;
120122
f.read_exact(&mut hdr_buf)?;
121123
Ok(MDAHeader::from_buf(&hdr_buf)?)
122124
};
@@ -159,7 +161,7 @@ impl MDARegions {
159161
));
160162
}
161163

162-
let used = Bytes(data.len() as u64);
164+
let used = Bytes(data.len() as u128);
163165
let max_available = self.max_data_size().bytes();
164166
if used > max_available {
165167
let err_msg = format!(
@@ -179,11 +181,11 @@ impl MDARegions {
179181
// Write data to a region specified by index.
180182
let region_size = self.region_size.sectors().bytes();
181183
let mut save_region = |index: usize| -> StratisResult<()> {
182-
f.seek(SeekFrom::Start(MDARegions::mda_offset(
183-
header_size,
184-
index,
185-
region_size,
186-
)))?;
184+
f.seek(SeekFrom::Start(
185+
MDARegions::mda_offset(header_size, index, region_size)
186+
.try_into()
187+
.map_err(|e: TryFromIntError| StratisError::Error(e.to_string()))?,
188+
))?;
187189
f.write_all(&hdr_buf)?;
188190
f.write_all(data)?;
189191
f.sync_all()?;
@@ -221,8 +223,10 @@ impl MDARegions {
221223
// It is an error if the metadata can not be found.
222224
let mut load_region = |index: usize| -> StratisResult<Vec<u8>> {
223225
let offset = MDARegions::mda_offset(header_size, index, region_size)
224-
+ mda_size::_MDA_REGION_HDR_SIZE as u64;
225-
f.seek(SeekFrom::Start(offset))?;
226+
+ mda_size::_MDA_REGION_HDR_SIZE as u128;
227+
f.seek(SeekFrom::Start(offset.try_into().map_err(
228+
|e: TryFromIntError| StratisError::Error(e.to_string()),
229+
)?))?;
226230
mda.load_region(f)
227231
};
228232

@@ -335,7 +339,7 @@ impl MDAHeader {
335339
assert!(secs <= std::i64::MAX as u64);
336340

337341
Some(MDAHeader {
338-
used: MetaDataSize::new(Bytes(used)),
342+
used: MetaDataSize::new(Bytes(u128::from(used))),
339343
last_updated: Utc.timestamp(secs as i64, LittleEndian::read_u32(&buf[24..28])),
340344
data_crc: LittleEndian::read_u32(&buf[4..8]),
341345
})
@@ -485,7 +489,7 @@ mod tests {
485489

486490
let header = MDAHeader {
487491
last_updated: Utc.timestamp(sec, nsec),
488-
used: MetaDataSize::new(Bytes(data.len() as u64)),
492+
used: MetaDataSize::new(Bytes(data.len() as u128)),
489493
data_crc: crc32::checksum_castagnoli(data),
490494
};
491495
let buf = header.to_buf();
@@ -507,7 +511,7 @@ mod tests {
507511

508512
let header = MDAHeader {
509513
last_updated: Utc::now(),
510-
used: MetaDataSize::new(Bytes(data.len() as u64)),
514+
used: MetaDataSize::new(Bytes(data.len() as u128)),
511515
data_crc: crc32::checksum_castagnoli(&data),
512516
};
513517
let mut buf = header.to_buf();

src/engine/strat_engine/backstore/metadata/sizes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub mod mda_size {
4848
use devicemapper::{Bytes, Sectors};
4949

5050
pub const _MDA_REGION_HDR_SIZE: usize = 32;
51-
const MDA_REGION_HDR_SIZE: Bytes = Bytes(_MDA_REGION_HDR_SIZE as u64);
51+
const MDA_REGION_HDR_SIZE: Bytes = Bytes(_MDA_REGION_HDR_SIZE as u128);
5252

5353
// The minimum size allocated for variable length metadata
5454
pub const MIN_MDA_DATA_REGION_SIZE: Bytes = Bytes(260_064);

src/engine/strat_engine/backstore/metadata/static_header.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -487,11 +487,11 @@ pub mod tests {
487487
let pool_uuid = Uuid::new_v4();
488488
let dev_uuid = Uuid::new_v4();
489489
let mda_size = MDADataSize::new(
490-
MDADataSize::default().bytes() + Bytes(u64::from(mda_size_factor * 4)),
490+
MDADataSize::default().bytes() + Bytes(u128::from(mda_size_factor * 4)),
491491
)
492492
.region_size()
493493
.mda_size();
494-
let blkdev_size = (Bytes(IEC::Mi) + Sectors(blkdev_size).bytes()).sectors();
494+
let blkdev_size = (Bytes(IEC::Mi as u128) + Sectors(blkdev_size).bytes()).sectors();
495495
StaticHeader::new(
496496
StratisIdentifiers::new(pool_uuid, dev_uuid),
497497
mda_size,

src/engine/strat_engine/device.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
// Functions for dealing with devices.
66

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

3436
match unsafe { blkgetsize64(file.as_raw_fd(), &mut val) } {
3537
Err(x) => Err(StratisError::Nix(x)),
36-
Ok(_) => Ok(Bytes(val)),
38+
Ok(_) => Ok(Bytes(u128::from(val))),
3739
}
3840
}
3941

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

85-
f.seek(SeekFrom::Start(*offset.bytes()))?;
87+
f.seek(SeekFrom::Start((*offset.bytes()).try_into().map_err(
88+
|e: TryFromIntError| StratisError::Error(e.to_string()),
89+
)?))?;
8690
for _ in 0..*length {
8791
f.write_all(buf)?;
8892
}

src/engine/strat_engine/pool.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ mod tests {
790790
let buf = &[1u8; SECTOR_SIZE];
791791

792792
let mut amount_written = Sectors(0);
793-
let buffer_length = Bytes(buffer_length).sectors();
793+
let buffer_length = Bytes(u128::from(buffer_length)).sectors();
794794
while pool.thin_pool.extend_state() == PoolExtendState::Good
795795
&& pool.thin_pool.state() == PoolState::Running
796796
{
@@ -816,7 +816,11 @@ mod tests {
816816
#[test]
817817
pub fn loop_test_add_datadevs() {
818818
loopbacked::test_with_spec(
819-
&loopbacked::DeviceLimits::Range(2, 3, Some((4u64 * Bytes(IEC::Gi)).sectors())),
819+
&loopbacked::DeviceLimits::Range(
820+
2,
821+
3,
822+
Some((4u64 * Bytes(u128::from(IEC::Gi))).sectors()),
823+
),
820824
test_add_datadevs,
821825
);
822826
}
@@ -826,8 +830,8 @@ mod tests {
826830
real::test_with_spec(
827831
&real::DeviceLimits::AtLeast(
828832
2,
829-
Some((2u64 * Bytes(IEC::Gi)).sectors()),
830-
Some((4u64 * Bytes(IEC::Gi)).sectors()),
833+
Some((2u64 * Bytes(u128::from(IEC::Gi))).sectors()),
834+
Some((4u64 * Bytes(u128::from(IEC::Gi))).sectors()),
831835
),
832836
test_add_datadevs,
833837
);

src/engine/strat_engine/tests/loopbacked.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl LoopTestDev {
3939
/// Create its backing store of specified size. The file is sparse but
4040
/// will appear to be zeroed.
4141
pub fn new(lc: &LoopControl, path: &Path, size: Option<Sectors>) -> LoopTestDev {
42-
let size = size.unwrap_or_else(|| Bytes(IEC::Gi).sectors());
42+
let size = size.unwrap_or_else(|| Bytes(u128::from(IEC::Gi)).sectors());
4343

4444
let f = OpenOptions::new()
4545
.read(true)

src/engine/strat_engine/tests/real.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ impl RealTestDev {
3333
/// Wipe initial MiB to clear metadata.
3434
pub fn new(dev: Either<PathBuf, LinearDev>) -> RealTestDev {
3535
let test_dev = RealTestDev { dev };
36-
wipe_sectors(test_dev.as_path(), Sectors(0), Bytes(IEC::Mi).sectors()).unwrap();
36+
wipe_sectors(
37+
test_dev.as_path(),
38+
Sectors(0),
39+
Bytes(u128::from(IEC::Mi)).sectors(),
40+
)
41+
.unwrap();
3742
test_dev
3843
}
3944

@@ -44,7 +49,12 @@ impl RealTestDev {
4449

4550
/// Teardown a real test dev
4651
fn teardown(self) {
47-
wipe_sectors(&self.as_path(), Sectors(0), Bytes(IEC::Mi).sectors()).unwrap();
52+
wipe_sectors(
53+
&self.as_path(),
54+
Sectors(0),
55+
Bytes(u128::from(IEC::Mi)).sectors(),
56+
)
57+
.unwrap();
4858
if let Some(mut ld) = self.dev.right() {
4959
ld.teardown(get_dm()).unwrap();
5060
}
@@ -88,7 +98,7 @@ fn get_device_runs<'a>(
8898
}
8999
};
90100

91-
let min_size = min_size.unwrap_or_else(|| Bytes(IEC::Gi).sectors());
101+
let min_size = min_size.unwrap_or_else(|| Bytes(u128::from(IEC::Gi)).sectors());
92102

93103
assert!(max_size.is_none() || Some(min_size) <= max_size);
94104

src/engine/strat_engine/thinpool/filesystem.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ pub fn fs_usage(mount_point: &Path) -> StratisResult<(Bytes, Bytes)> {
356356
stat.blocks_free() as u64,
357357
);
358358
Ok((
359-
Bytes(block_size * blocks),
360-
Bytes(block_size * (blocks - blocks_free)),
359+
Bytes(u128::from(block_size * blocks)),
360+
Bytes(u128::from(block_size * (blocks - blocks_free))),
361361
))
362362
}

0 commit comments

Comments
 (0)