Skip to content

Commit

Permalink
Move DmFlags definition into separate module
Browse files Browse the repository at this point in the history
To make dm module a bit shorter.
To restrict the scope of the clippy annotations needed to make the code
produced by the bitflags macro pass.
To avoid a circular dependency between deviceinfo and dm modules. Rust
supports circular dependencies, obviously, but too many is a sign of poor
modularity.

Signed-off-by: mulhern <amulhern@redhat.com>
  • Loading branch information
mulkieran committed Mar 15, 2018
1 parent 1cdac00 commit 755300d
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 55 deletions.
3 changes: 2 additions & 1 deletion src/cachedev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use std::str::FromStr;

use super::device::Device;
use super::deviceinfo::DeviceInfo;
use super::dm::{DM, DmFlags};
use super::dm::DM;
use super::dm_flags::DmFlags;
use super::lineardev::{LinearDev, LinearDevTargetParams};
use super::result::{DmError, DmResult, ErrorEnum};
use super::shared::{DmDevice, TargetLine, TargetParams, TargetTable, device_create, device_exists,
Expand Down
2 changes: 1 addition & 1 deletion src/deviceinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::mem::transmute;
use std::str::from_utf8;

use super::device::Device;
use super::dm::DmFlags;
use super::dm_flags::DmFlags;
use super::dm_ioctl as dmi;
use super::types::{DmName, DmUuid};
use super::util::slice_to_null;
Expand Down
48 changes: 1 addition & 47 deletions src/dm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Their scope is the whole file because the bitflags! macro generates a
// lot of stuff, and so placing the annotation right on the use of the
// bitflags! macro does not actually cover the suspicious code generated.
#![allow(redundant_field_names)]
#![allow(suspicious_arithmetic_impl)]

use std::{cmp, io, slice};
use std::fs::File;
Expand All @@ -19,6 +17,7 @@ use nix::libc::c_ulong;

use super::device::Device;
use super::deviceinfo::{DM_NAME_LEN, DM_UUID_LEN, DeviceInfo};
use super::dm_flags::DmFlags;
use super::dm_ioctl as dmi;
use super::errors::{Error, ErrorKind};
use super::result::DmResult;
Expand All @@ -39,51 +38,6 @@ const DM_VERSION_PATCHLEVEL: u32 = 0;
/// Start with a large buffer to make BUFFER_FULL rare. Libdm does this too.
const MIN_BUF_SIZE: usize = 16 * 1024;

bitflags! {
/// Flags used by devicemapper.
#[derive(Default)]
pub struct DmFlags: dmi::__u32 {
/// In: Device should be read-only.
/// Out: Device is read-only.
#[allow(identity_op)]
const DM_READONLY = (1 << 0);
/// In: Device should be suspended.
/// Out: Device is suspended.
const DM_SUSPEND = (1 << 1);
/// In: Use passed-in minor number.
const DM_PERSISTENT_DEV = (1 << 3);
/// In: STATUS command returns table info instead of status.
const DM_STATUS_TABLE = (1 << 4);
/// Out: Active table is present.
const DM_ACTIVE_PRESENT = (1 << 5);
/// Out: Inactive table is present.
const DM_INACTIVE_PRESENT = (1 << 6);
/// Out: Passed-in buffer was too small.
const DM_BUFFER_FULL = (1 << 8);
/// Obsolete.
const DM_SKIP_BDGET = (1 << 9);
/// In: Avoid freezing filesystem when suspending.
const DM_SKIP_LOCKFS = (1 << 10);
/// In: Suspend without flushing queued I/Os.
const DM_NOFLUSH = (1 << 11);
/// In: Query inactive table instead of active.
const DM_QUERY_INACTIVE_TABLE = (1 << 12);
/// Out: A uevent was generated, the caller may need to wait for it.
const DM_UEVENT_GENERATED = (1 << 13);
/// In: Rename affects UUID field, not name field.
const DM_UUID = (1 << 14);
/// In: All buffers are wiped after use. Use when handling crypto keys.
const DM_SECURE_DATA = (1 << 15);
/// Out: A message generated output data.
const DM_DATA_OUT = (1 << 16);
/// In: Do not remove in-use devices.
/// Out: Device scheduled to be removed when closed.
const DM_DEFERRED_REMOVE = (1 << 17);
/// Out: Device is suspended internally.
const DM_INTERNAL_SUSPEND = (1 << 18);
}
}

/// Context needed for communicating with devicemapper.
pub struct DM {
file: File,
Expand Down
57 changes: 57 additions & 0 deletions src/dm_flags.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

// These errors originate in bitflags! macro and are not ours to fix.
// Their scope is the whole file because the bitflags! macro generates a
// lot of stuff, and so placing the annotation right on the use of the
// bitflags! macro does not actually cover the suspicious code generated.
#![allow(redundant_field_names)]
#![allow(suspicious_arithmetic_impl)]

use super::dm_ioctl as dmi;

bitflags! {
/// Flags used by devicemapper.
#[derive(Default)]
pub struct DmFlags: dmi::__u32 {
/// In: Device should be read-only.
/// Out: Device is read-only.
#[allow(identity_op)]
const DM_READONLY = (1 << 0);
/// In: Device should be suspended.
/// Out: Device is suspended.
const DM_SUSPEND = (1 << 1);
/// In: Use passed-in minor number.
const DM_PERSISTENT_DEV = (1 << 3);
/// In: STATUS command returns table info instead of status.
const DM_STATUS_TABLE = (1 << 4);
/// Out: Active table is present.
const DM_ACTIVE_PRESENT = (1 << 5);
/// Out: Inactive table is present.
const DM_INACTIVE_PRESENT = (1 << 6);
/// Out: Passed-in buffer was too small.
const DM_BUFFER_FULL = (1 << 8);
/// Obsolete.
const DM_SKIP_BDGET = (1 << 9);
/// In: Avoid freezing filesystem when suspending.
const DM_SKIP_LOCKFS = (1 << 10);
/// In: Suspend without flushing queued I/Os.
const DM_NOFLUSH = (1 << 11);
/// In: Query inactive table instead of active.
const DM_QUERY_INACTIVE_TABLE = (1 << 12);
/// Out: A uevent was generated, the caller may need to wait for it.
const DM_UEVENT_GENERATED = (1 << 13);
/// In: Rename affects UUID field, not name field.
const DM_UUID = (1 << 14);
/// In: All buffers are wiped after use. Use when handling crypto keys.
const DM_SECURE_DATA = (1 << 15);
/// Out: A message generated output data.
const DM_DATA_OUT = (1 << 16);
/// In: Do not remove in-use devices.
/// Out: Device scheduled to be removed when closed.
const DM_DEFERRED_REMOVE = (1 << 17);
/// Out: Device is suspended internally.
const DM_INTERNAL_SUSPEND = (1 << 18);
}
}
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ mod deviceinfo;
mod device;
/// core lower level API
mod dm;
/// DM flags
mod dm_flags;
/// functionality shared between devices
mod shared;
/// error chain errors for core dm
Expand All @@ -132,9 +134,9 @@ mod loopbacked;
pub use cachedev::{CacheDev, CacheDevPerformance, CacheDevStatus, CacheDevUsage,
CacheDevWorkingStatus, MAX_CACHE_BLOCK_SIZE, MIN_CACHE_BLOCK_SIZE};
pub use consts::{IEC, SECTOR_SIZE};
pub use dm::{DM, DmFlags};

pub use device::{Device, devnode_to_devno};
pub use dm::DM;
pub use dm_flags::DmFlags;
pub use lineardev::{FlakeyTargetParams, LinearDev, LinearDevTargetParams, LinearDevTargetTable,
LinearTargetParams};
pub use result::{DmResult, DmError, ErrorEnum};
Expand Down
3 changes: 2 additions & 1 deletion src/lineardev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use std::str::FromStr;

use super::device::Device;
use super::deviceinfo::DeviceInfo;
use super::dm::{DM, DmFlags};
use super::dm::DM;
use super::dm_flags::DmFlags;
use super::result::{DmError, DmResult, ErrorEnum};
use super::shared::{DmDevice, TargetLine, TargetParams, TargetTable, device_create, device_exists,
device_match, parse_device};
Expand Down
3 changes: 2 additions & 1 deletion src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use std::str::FromStr;

use super::device::{Device, devnode_to_devno};
use super::deviceinfo::DeviceInfo;
use super::dm::{DM, DmFlags};
use super::dm::DM;
use super::dm_flags::DmFlags;
use super::result::{DmError, DmResult, ErrorEnum};
use super::types::{DevId, DmName, DmUuid, Sectors, TargetTypeBuf};

Expand Down
3 changes: 2 additions & 1 deletion src/thindev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use std::str::FromStr;

use super::device::Device;
use super::deviceinfo::DeviceInfo;
use super::dm::{DM, DmFlags};
use super::dm::DM;
use super::dm_flags::DmFlags;
use super::result::{DmError, DmResult, ErrorEnum};
use super::shared::{DmDevice, TargetLine, TargetParams, TargetTable, device_create, device_exists,
device_match, message, parse_device};
Expand Down
3 changes: 2 additions & 1 deletion src/thinpooldev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use std::str::FromStr;

use super::device::Device;
use super::deviceinfo::DeviceInfo;
use super::dm::{DM, DmFlags};
use super::dm::DM;
use super::dm_flags::DmFlags;
use super::lineardev::{LinearDev, LinearDevTargetParams};
use super::result::{DmError, DmResult, ErrorEnum};
use super::shared::{DmDevice, TargetLine, TargetParams, TargetTable, device_create, device_exists,
Expand Down

0 comments on commit 755300d

Please sign in to comment.