Struct devicemapper::DM
[−]
[src]
pub struct DM { /* fields omitted */ }
Context needed for communicating with devicemapper.
Methods
impl DM
[src]
fn new() -> DmResult<DM>
Create a new context for communicating with DM.
fn wait_for_dm()
The /dev/mapper/
fn version(&self) -> DmResult<(u32, u32, u32)>
Devicemapper version information: Major, Minor, and patchlevel versions.
fn remove_all(&self, flags: DmFlags) -> DmResult<()>
Remove all DM devices and tables. Use discouraged other than for debugging.
If DM_DEFERRED_REMOVE is set, the request will succeed for in-use devices, and they will be removed when released.
Valid flags: DM_DEFERRED_REMOVE
fn list_devices(&self) -> DmResult<Vec<(String, Device)>>
Returns a list of tuples containing DM device names and a Device, which holds their major and minor device numbers.
fn device_create(
&self,
name: &str,
uuid: Option<&str>,
flags: DmFlags
) -> DmResult<DeviceInfo>
&self,
name: &str,
uuid: Option<&str>,
flags: DmFlags
) -> DmResult<DeviceInfo>
Create a DM device. It starts out in a "suspended" state.
Valid flags: DM_READONLY, DM_PERSISTENT_DEV
Example
use devicemapper::DM; use devicemapper::consts::DmFlags; let dm = DM::new().unwrap(); // Setting a uuid is optional let dev = dm.device_create("example-dev", None, DmFlags::empty()).unwrap();
fn device_remove(&self, name: &DevId, flags: DmFlags) -> DmResult<DeviceInfo>
Remove a DM device and its mapping tables.
If DM_DEFERRED_REMOVE is set, the request for an in-use devices will succeed, and it will be removed when no longer used.
Valid flags: DM_DEFERRED_REMOVE
fn device_rename(
&self,
old_name: &str,
new_name: &str,
flags: DmFlags
) -> DmResult<DeviceInfo>
&self,
old_name: &str,
new_name: &str,
flags: DmFlags
) -> DmResult<DeviceInfo>
Change a DM device's name.
If DM_UUID is set, change the UUID instead.
Valid flags: DM_UUID
Prerequisite: old_name != new_name Note: Possibly surprisingly, returned DeviceInfo's name field contains the previous name, not the new name.
fn device_suspend(&self, name: &DevId, flags: DmFlags) -> DmResult<DeviceInfo>
Suspend or resume a DM device, depending on if DM_SUSPEND flag is set or not.
Resuming a DM device moves a table loaded into the "inactive"
slot by table_load()
into the "active" slot.
Will block until pending I/O is completed unless DM_NOFLUSH flag is given. Will freeze filesystem unless DM_SKIP_LOCKFS flags is given. Additional I/O to a suspended device will be held until it is resumed.
Valid flags: DM_SUSPEND, DM_NOFLUSH, DM_SKIP_LOCKFS
Example
use devicemapper::{DM, DevId}; use devicemapper::consts::{DmFlags, DM_SUSPEND}; let dm = DM::new().unwrap(); dm.device_suspend(&DevId::Name("example-dev"), DM_SUSPEND).unwrap();
fn device_status(&self, name: &DevId) -> DmResult<DeviceInfo>
Get DeviceInfo for a device. This is also returned by other methods, but if just the DeviceInfo is desired then this just gets it.
fn device_wait(
&self,
name: &DevId,
flags: DmFlags
) -> DmResult<(DeviceInfo, Vec<(Sectors, Sectors, String, String)>)>
&self,
name: &DevId,
flags: DmFlags
) -> DmResult<(DeviceInfo, Vec<(Sectors, Sectors, String, String)>)>
Wait for a device to report an event.
Once an event occurs, this function behaves just like
table_status
, see that function for more details.
This interface is not very friendly to monitoring multiple devices. Events are also exported via uevents, that method may be preferable.
fn table_load<T1, T2>(
&self,
name: &DevId,
targets: &[(Sectors, Sectors, T1, T2)]
) -> DmResult<DeviceInfo> where
T1: AsRef<str>,
T2: AsRef<str>,
&self,
name: &DevId,
targets: &[(Sectors, Sectors, T1, T2)]
) -> DmResult<DeviceInfo> where
T1: AsRef<str>,
T2: AsRef<str>,
Load targets for a device into its inactive table slot.
targets
is an array of (sector_start, sector_length, type, params).
params
are target-specific, please see [Linux kernel documentation]
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/ ->
Documentation/device-mapper
for more.
Example
use devicemapper::{DM, DevId, Sectors}; use devicemapper::consts::DmFlags; let dm = DM::new().unwrap(); // Create a 16MiB device (32768 512-byte sectors) that maps to /dev/sdb1 // starting 1MiB into sdb1 let table = vec![(Sectors(0), Sectors(32768), "linear", "/dev/sdb1 2048")]; dm.table_load(&DevId::Name("example-dev"), &table).unwrap();
fn table_clear(&self, name: &DevId) -> DmResult<DeviceInfo>
Clear the "inactive" table for a device.
fn table_deps(&self, dev: Device, flags: DmFlags) -> DmResult<Vec<Device>>
Query DM for which devices are referenced by the "active" table for this device.
If DM_QUERY_INACTIVE_TABLE is set, instead return for the inactive table.
Valid flags: DM_QUERY_INACTIVE_TABLE
fn table_status(
&self,
name: &DevId,
flags: DmFlags
) -> DmResult<(DeviceInfo, Vec<(Sectors, Sectors, String, String)>)>
&self,
name: &DevId,
flags: DmFlags
) -> DmResult<(DeviceInfo, Vec<(Sectors, Sectors, String, String)>)>
Return the status of all targets for a device's "active" table.
Returns DeviceInfo and a Vec of (sector_start, sector_length, type, params).
If DM_STATUS_TABLE flag is set, returns the current table value. Otherwise returns target-specific status information.
If DM_NOFLUSH is set, retrieving the target-specific status information for targets with metadata will not cause a metadata write.
If DM_QUERY_INACTIVE_TABLE is set, instead return the status of the inactive table.
Valid flags: DM_NOFLUSH, DM_STATUS_TABLE, DM_QUERY_INACTIVE_TABLE
Example
use devicemapper::{DM, DevId}; use devicemapper::consts::{DM_STATUS_TABLE, DmFlags}; let dm = DM::new().unwrap(); let res = dm.table_status(&DevId::Name("example-dev"), DM_STATUS_TABLE).unwrap(); println!("{} {:?}", res.0.name(), res.1);
fn list_versions(&self) -> DmResult<Vec<(String, u32, u32, u32)>>
Returns a list of each loaded target type with its name, and version broken into major, minor, and patchlevel.
fn target_msg(
&self,
name: &DevId,
sector: Sectors,
msg: &str
) -> DmResult<(DeviceInfo, Option<String>)>
&self,
name: &DevId,
sector: Sectors,
msg: &str
) -> DmResult<(DeviceInfo, Option<String>)>
Send a message to the target at a given sector. If sector is not needed use 0. DM-wide messages start with '@', and may return a string; targets do not.
fn depends_on(&self, dev: Device, dm_majors: &BTreeSet<u32>) -> DmResult<bool>
Recursively walk DM deps to see if dev
might be its own dependency.