Skip to content

Commit d753501

Browse files
committed
Move a bunch of core modules into a core sub-module
For better encapsulation. Signed-off-by: mulhern <amulhern@redhat.com>
1 parent 7d534a5 commit d753501

20 files changed

Lines changed: 87 additions & 87 deletions

src/cachedev.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@ use std::fmt;
77
use std::path::PathBuf;
88
use std::str::FromStr;
99

10-
use crate::device::Device;
11-
use crate::deviceinfo::DeviceInfo;
12-
use crate::dm::DM;
13-
use crate::dm_options::DmOptions;
10+
use crate::core::{
11+
DataBlocks, DevId, Device, DeviceInfo, DmName, DmOptions, DmUuid, MetaBlocks, Sectors,
12+
TargetTypeBuf, DM,
13+
};
1414
use crate::lineardev::{LinearDev, LinearDevTargetParams};
1515
use crate::result::{DmError, DmResult, ErrorEnum};
1616
use crate::shared::{
1717
device_create, device_exists, device_match, get_status_line_fields,
1818
make_unexpected_value_error, parse_device, parse_value, DmDevice, TargetLine, TargetParams,
1919
TargetTable,
2020
};
21-
use crate::types::{DataBlocks, DevId, DmName, DmUuid, MetaBlocks, Sectors, TargetTypeBuf};
2221

2322
const CACHE_TARGET_NAME: &str = "cache";
2423

@@ -737,7 +736,7 @@ use std::path::Path;
737736
#[cfg(test)]
738737
use crate::consts::IEC;
739738
#[cfg(test)]
740-
use crate::device::devnode_to_devno;
739+
use crate::core::devnode_to_devno;
741740
#[cfg(test)]
742741
use crate::lineardev::LinearTargetParams;
743742
#[cfg(test)]

src/device.rs renamed to src/core/device.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ use std::{fmt, io};
1010
use libc::{dev_t, major, makedev, minor};
1111
use nix::sys::stat::SFlag;
1212

13-
use crate::errors::ErrorKind;
1413
use crate::result::{DmError, DmResult};
1514

15+
use crate::core::errors::ErrorKind;
16+
1617
/// A struct containing the device's major and minor numbers
1718
///
1819
/// Also allows conversion to/from a single 64bit dev_t value.
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
44
use std::str::from_utf8;
55

6-
use crate::device::Device;
7-
use crate::dm_flags::DmFlags;
8-
use crate::dm_ioctl as dmi;
9-
use crate::types::{DmName, DmUuid};
10-
use crate::util::slice_to_null;
6+
use crate::core::{Device, DmFlags, DmName, DmUuid};
7+
8+
use crate::core::dm_ioctl as dmi;
9+
use crate::core::util::slice_to_null;
1110

1211
/// Name max length
1312
pub const DM_NAME_LEN: usize = 128;

src/dm.rs renamed to src/core/dm.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ use std::{cmp, slice, u32};
1010
use nix::libc::c_ulong;
1111
use nix::libc::ioctl as nix_ioctl;
1212

13-
use crate::device::Device;
14-
use crate::deviceinfo::{DeviceInfo, DM_NAME_LEN, DM_UUID_LEN};
15-
use crate::dm_flags::DmFlags;
16-
use crate::dm_ioctl as dmi;
17-
use crate::dm_options::DmOptions;
18-
use crate::errors::ErrorKind;
13+
use crate::core::{
14+
DevId, Device, DeviceInfo, DmFlags, DmName, DmNameBuf, DmOptions, DmUuid, Sectors,
15+
TargetTypeBuf,
16+
};
1917
use crate::result::{DmError, DmResult};
2018

21-
use crate::types::{DevId, DmName, DmNameBuf, DmUuid, Sectors, TargetTypeBuf};
22-
use crate::util::{align_to, slice_to_null};
19+
use crate::core::deviceinfo::{DM_NAME_LEN, DM_UUID_LEN};
20+
use crate::core::dm_ioctl as dmi;
21+
use crate::core::errors::ErrorKind;
22+
use crate::core::util::{align_to, slice_to_null};
2323

2424
/// Indicator to send IOCTL to DM
2525
const DM_IOCTL: u8 = 0xfd;
@@ -723,10 +723,11 @@ impl DM {
723723
#[cfg(test)]
724724
mod tests {
725725

726-
use crate::errors::Error;
727726
use crate::result::DmError;
728727
use crate::test_lib::{test_name, test_uuid};
729728

729+
use crate::core::errors::Error;
730+
730731
use super::*;
731732

732733
#[test]

src/dm_flags.rs renamed to src/core/dm_flags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
44

5-
use crate::dm_ioctl as dmi;
5+
use crate::core::dm_ioctl as dmi;
66

77
bitflags! {
88
/// Flags used by devicemapper.

src/dm_ioctl.rs renamed to src/core/dm_ioctl.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
use std::borrow::Cow;
1111
use std::fmt;
1212

13-
use crate::device::Device;
14-
use crate::util::slice_to_null;
13+
use crate::core::Device;
14+
15+
use crate::core::util::slice_to_null;
1516

1617
pub type __s8 = ::libc::c_char;
1718
pub type __u8 = ::libc::c_uchar;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This Source Code Form is subject to the terms of the Mozilla Public
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4-
use crate::dm_flags::{DmCookie, DmFlags};
4+
use crate::core::{DmCookie, DmFlags};
55

66
/// Encapsulates options for device mapper calls
77
#[derive(Debug, Default, Clone)]

src/errors.rs renamed to src/core/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::path::PathBuf;
77

88
use nix;
99

10-
use crate::deviceinfo::DeviceInfo;
10+
use crate::core::DeviceInfo;
1111

1212
error_chain! {
1313
errors {

src/core/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
//! Modules that support handling of devicemapper ioctls at a low-level.
6+
7+
mod device;
8+
pub(self) mod deviceinfo;
9+
mod dm;
10+
mod dm_flags;
11+
pub(self) mod dm_ioctl;
12+
mod dm_options;
13+
pub mod errors;
14+
mod types;
15+
pub(self) mod util;
16+
17+
pub use self::device::{devnode_to_devno, Device};
18+
pub use self::deviceinfo::DeviceInfo;
19+
pub use self::dm::DM;
20+
pub use self::dm_flags::{DmCookie, DmFlags};
21+
pub use self::dm_options::DmOptions;
22+
pub use self::types::{
23+
Bytes, DataBlocks, DevId, DmName, DmNameBuf, DmUuid, DmUuidBuf, MetaBlocks, Sectors,
24+
TargetType, TargetTypeBuf,
25+
};

src/types.rs renamed to src/core/types.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ use std::ops::{Add, Deref, Div, Mul, Rem};
1010
use serde;
1111

1212
use crate::consts::SECTOR_SIZE;
13-
use crate::deviceinfo::{DM_NAME_LEN, DM_UUID_LEN};
14-
use crate::errors::ErrorKind;
1513
use crate::result::{DmError, DmResult};
1614

15+
use crate::core::deviceinfo::{DM_NAME_LEN, DM_UUID_LEN};
16+
use crate::core::errors::ErrorKind;
17+
1718
/// a kernel defined block size constant for any DM meta device
1819
/// a DM meta device may store cache device or thinpool device metadata
1920
/// defined in drivers/md/persistent-data/dm-space-map-metadata.h as

0 commit comments

Comments
 (0)